#!/bin/ksh #************************************************************** # Author: Sebastien Denvil, Martial Mancip # Contact: Sebastien.Denvil@ipsl.jussieu.fr Martial.Mancip@ipsl.jussieu.fr # $Date$ # $Author$ # $Revision$ # IPSL (2006) # This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC # History: # Modification: # #************************************************************** #======================================================================== function IGCM_comp_Initialize { IGCM_debug_PushStack "IGCM_comp_Initialize" # Debug Print : echo IGCM_debug_Print 1 "IGCM_comp_Initialize :" echo typeset comp compname comptagname CompatibilityTag auxprint card_UserChoices first_option i j for comp in ${config_ListOfComponents[*]} ; do # Debug Print IGCM_debug_Print 1 ${comp} # Define component IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/config.card ListOfComponents ${comp} eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1 eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1 # Read libIGCM compatibility version in ${compname}.card card=${SUBMIT_DIR}/COMP/${compname}.card IGCM_card_DefineVariableFromOption ${card} Compatibility libIGCM eval CompatibilityTag=\${${compname}_Compatibility_libIGCM} > /dev/null 2>&1 if [ ! "${CompatibilityTag}" = "${libIGCM_CurrentTag}" ] ; then IGCM_debug_Exit "${compname}.card is not compatible with libIGCM version ${libIGCM_CurrentTag} see libIGCM FAQ http://wiki.ipsl.jussieu.fr/wiki_ipsl/IGCMG/libIGCM/DocUtilisateur/FAQ ." fi # Manage component executable IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/config.card Executable ${comp} # Read component Write Frequency in config.card IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} WriteFrequency # Debug Print : eval auxprint=\${config_${comp}_WriteFrequency} IGCM_debug_Print 1 "Write frequency for ${compname} : ${auxprint} " #2> /dev/null # Debug Print : IGCM_debug_Print 1 "Initialize following component library :" IGCM_debug_Print 1 ${SUBMIT_DIR}/COMP/${compname}.driver IGCM_debug_Print 3 "With tag : ${comptagname}" # Source component library . ${SUBMIT_DIR}/COMP/${compname}.driver # Debug Print IGCM_debug_Print 3 "Initialize ${comp} output directory." # Define Dirs eval R_OUT_${comp}=${R_SAVE}/${comp} eval IGCM_sys_MkdirArchive \${R_OUT_${comp}} eval R_OUT_${comp}_O=\${R_OUT_${comp}}/Output eval IGCM_sys_MkdirArchive \${R_OUT_${comp}_O} eval R_OUT_${comp}_R=\${R_OUT_${comp}}/Restart eval IGCM_sys_MkdirArchive \${R_OUT_${comp}_R} eval R_OUT_${comp}_D=\${R_OUT_${comp}}/Debug eval IGCM_sys_MkdirArchive \${R_OUT_${comp}_D} eval R_OUT_${comp}_O_I=\${R_OUT_${comp}_O}/INS eval R_OUT_${comp}_O_H=\${R_OUT_${comp}_O}/HF eval R_OUT_${comp}_O_D=\${R_OUT_${comp}_O}/DA eval R_OUT_${comp}_O_M=\${R_OUT_${comp}_O}/MO eval R_OUT_${comp}_O_Y=\${R_OUT_${comp}_O}/YE # Read UserChoices section of component card IGCM_debug_Print 1 "DefineArrayFromSection : ${compname}_UserChoices ${card}" IGCM_card_DefineArrayFromSection ${card} UserChoices eval first_option=\${${compname}_UserChoices[0]} > /dev/null 2>&1 if [ X${first_option} != X"Error:" ] ; then eval IGCM_debug_Print 2 "${compname}_UserChoices_Options:" \${${compname}_UserChoices[*]} if [ X${card_UserChoices[0]} != X ] ; then unset card_UserChoices fi eval set +A card_UserChoices -- \${${compname}_UserChoices[*]} > /dev/null 2>&1 typeset option for option in ${card_UserChoices[*]} ; do IGCM_card_DefineVariableFromOption ${card} UserChoices ${option} eval IGCM_debug_Print 3 "${compname}_UserChoices_values: ${option} \${card_UserChoices_${option}}" done fi # Read and Build Output File stuff IGCM_debug_Print 1 "DefineArrayFromOption : ${compname}_OutputFiles ${card}" IGCM_card_DefineArrayFromOption ${card} OutputFiles List ListFilesName=${compname}_OutputFiles_List eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1 # if [ X${FileName0} != X${NULL_STR} ] ; then # #IGCM_debug_Print 1 "Component : ${compname}" # # INITIALISATION # eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1 i=2 # until [ $i -ge $NbFiles ]; do # eval flag_post=\${${ListFilesName}[$i]} > /dev/null 2>&1 # if [ X${flag_post} != XNONE ] ; then # # First of all # IGCM_card_DefineArrayFromSection ${card} ${flag_post} # # Seasonal case : If option Seasonal is not found (old cards) put SEASONAL ON by default # # variable option allready typeset above for option in $( eval echo \${${compname}_${flag_post}[*]} ) ; do if [ ${option} = Seasonal ] ; then FoundSeasonal=true IGCM_card_DefineVariableFromOption ${card} ${flag_post} Seasonal fi done # if [ ! X${FoundSeasonal} = Xtrue ] ; then eval ${compname}_${flag_post}_Seasonal=ON fi # if [ $( eval echo \${${compname}_${flag_post}_Seasonal} ) = ON ] ; then Seasonal=true fi # Dimension = vide si vieille card. IGCM_card_DefineArrayFromOption ${card} ${flag_post} TimeSeriesVars IGCM_card_DefineArrayFromOption ${card} ${flag_post} Patches if [ X"$( eval echo \${${compname}_${flag_post}_TimeSeriesVars[*]} )" = X"Option not found ${flag_post}" ] ; then # New TimeSeriesVar description, with 2D, 3D and associate ChunckJob. ListDimension[0]=2D ListDimension[1]=3D TimeSeries=false iLoop=${#ListDimension[*]} j=0 until [ $j -ge ${iLoop} ]; do Dimension=${ListDimension[${j}]} IGCM_card_DefineArrayFromOption ${card} ${flag_post} TimeSeriesVars${Dimension} IGCM_card_DefineVariableFromOption ${card} ${flag_post} ChunckJob${Dimension} # # Time series WITHOUT chunk # if [ ! $( eval echo \${${compname}_${flag_post}_TimeSeriesVars${Dimension}} ) = ${NULL_STR} ] ; then if [ $( eval echo \${${compname}_${flag_post}_ChunckJob${Dimension}} ) = NONE ] ; then IGCM_debug_Print 3 "${Dimension} time series activated for ${flag_post} according to ${card}" eval TimeSeries${Dimension}=true fi fi # # Time series WITH chunk # if [ ! $( eval echo \${${compname}_${flag_post}_TimeSeriesVars${Dimension}} ) = ${NULL_STR} ] ; then chunck_size=$( eval echo \${${compname}_${flag_post}_ChunckJob${Dimension}} ) if [ ! ${chunck_size} = NONE ] && [ ! ${chunck_size} = OFF ] ; then IGCM_debug_Print 3 "${Dimension} time series activated with chunck for ${flag_post} according to ${card}" eval TimeSeriesChunck${Dimension}=true eval set +A CHUNCK${Dimension}_COMP \${CHUNCK${Dimension}_COMP[*]} ${comp} eval set +A CHUNCK${Dimension}_FLAG \${CHUNCK${Dimension}_FLAG[*]} ${i} eval set +A CHUNCK${Dimension}_SIZE \${CHUNCK${Dimension}_SIZE[*]} ${chunck_size} fi fi (( j=j+1 )) done else ListDimension[0]="" TimeSeries=true TimeSeries2D=false TimeSeries3D=false TimeSeriesChunck2D=false TimeSeriesChunck3D=false fi fi (( i=i+3 )) done fi # Debug Print IGCM_debug_Print 3 "Initialize ${compname} with driver." # INIT component ${comp}_Initialize echo done echo "-----" echo IGCM_debug_Print 1 "DefineArrayFromOption : ListOfComponents" IGCM_debug_PrintVariables 3 config_ListOfComponents IGCM_debug_PopStack "IGCM_comp_Initialize" } #======================================================================= function IGCM_comp_PrepareDeletedFiles { IGCM_debug_PushStack "IGCM_comp_PrepareDeletedFiles" $@ if [ X${2} != X. ] ; then eval FileToBeDeleted[${#FileToBeDeleted[@]}]=$( basename ${2} ) > /dev/null 2>&1 else eval FileToBeDeleted[${#FileToBeDeleted[@]}]=$( basename ${1} ) > /dev/null 2>&1 fi IGCM_debug_PopStack "IGCM_comp_PrepareDeletedFiles" } #======================================================================= function IGCM_comp_GetInputInitialStateFiles { IGCM_debug_PushStack "IGCM_comp_GetInputInitialStateFiles" # Debug Print : echo IGCM_debug_Print 1 "IGCM_comp_GetInputInitialStateFiles :" echo # Only the first time step need InitialStateFiles # otherwise it's BoundaryConditions if ( ${FirstInitialize} ) ; then typeset comp compname comptagname card ListFilesName FileName0 NbFiles i i_ typeset file_in_ file_in file_out_ file_out do_init for comp in ${config_ListOfComponents[*]} ; do # Initialize do_init="y" # Do we need to bring initial state file for this component if [ "${config_Restarts_OverRule}" = "y" ] ; then eval do_init="n" else # Read component Restarts parameters IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} Restart eval do_start=\${config_${comp}_Restart} > /dev/null 2>&1 if [ "${do_start}" = "y" ] ; then do_init="n" else do_init="y" fi fi if [ "${do_init}" = "y" ] ; then # Define component eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1 eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1 # Debug Print : IGCM_debug_Print 3 "Initialisation files ${compname}" card=${SUBMIT_DIR}/COMP/${compname}.card IGCM_card_DefineArrayFromOption ${card} InitialStateFiles List ListFilesName=${compname}_InitialStateFiles_List eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1 if [ X${FileName0} != X${NULL_STR} ] ; then eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1 (( i=0 )) until [ $i -ge $NbFiles ]; do eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1 eval file_in=${file_in_} (( i_ = i+1 )) eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1 eval file_out=${file_out_} IGCM_sys_Get ${file_in} ${file_out} #IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out} (( i=i+2 )) done fi fi done fi IGCM_debug_PopStack "IGCM_comp_GetInputInitialStateFiles" } #======================================================================= # Definition of Smooth modulo function # usage : # IGCM_SmoothModulo StringModulo value # # StringModulo : A string of min max and modulo like definition of Scilab vectors. # [min]:[modulo:][max] # where : # [] value are optionnals; # empty min equal 1 # empty max equal infinity # modulo not given or empty equal 1 # empty string or just ':' equal always. # # value : the value to test with the definition # # return : true(1)/false(0) function IGCM_SmoothModulo { IGCM_debug_PushStack "IGCM_SmoothModulo" typeset defVector ModValue eval set +A defVector -- $( echo "${1}" | \ gawk -F ':' '{print ($1 == "" ? 1 : $1) " " (NF==3 ? ($2 == "" ? 1 : $2) : 1) " " (NF==3 ? ($3 == "" ? -1 : $3) : ($2 == "" ? -1 : $2))}' ) # Test limits : # ${defVector[0]} <= ${2} <= ${defVector[2]} # or ${defVector[2]} == -1 if ( [ ${2} -ge ${defVector[0]} ] && \ ( [ ${2} -le ${defVector[2]} ] || \ [ ${defVector[2]} -lt 0 ] ) ) ; then # Test modulo ModValue=$( expr \( ${2} - ${defVector[0]} \) % ${defVector[1]} ) if [ ${ModValue} -eq 0 ] ; then echo true IGCM_debug_PopStack "IGCM_SmoothModulo" return 1 else echo false IGCM_debug_PopStack "IGCM_SmoothModulo" return 0 fi else echo false IGCM_debug_PopStack "IGCM_SmoothModulo" return 0 fi } #======================================================================= function IGCM_comp_GetInputSmoothFiles { IGCM_debug_PushStack "IGCM_comp_GetInputSmoothFiles" # Debug Print : echo IGCM_debug_Print 1 "IGCM_comp_GetInputSmoothFiles :" echo typeset comp compname comptagname card ListFilesName FileName0 NbFiles i i_ i__ typeset file_in_ file_in file_out_ file_out ret SmoothDef for comp in ${config_ListOfComponents[*]} ; do echo "-----" # Define component eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1 eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1 # Debug Print : IGCM_debug_Print 3 "Smooth files ${compname}" card=${SUBMIT_DIR}/COMP/${compname}.card IGCM_card_DefineArrayFromOption ${card} SmoothFiles List ListFilesName=${compname}_SmoothFiles_List eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1 if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != X"Section" ] ) ; then eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1 (( i=0 )) until [ $i -ge $NbFiles ]; do eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1 eval file_in=${file_in_} (( i_ = i+1 )) eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1 eval file_out=${file_out_} # define CumulPeriod definition for this file (( i__ = i+2 )) eval SmoothDef=\${${ListFilesName}[$i__]} IGCM_debug_Print 3 " ${file_in} ${SmoothDef}" eval ret=$( IGCM_SmoothModulo ${SmoothDef} ${CumulPeriod} ) if ( [ X${ret} = Xtrue ] || [ ${Period} -eq 1 ] ) ; then IGCM_sys_Get ${file_in} ${file_out} #IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out} fi (( i=i+3 )) done fi done IGCM_debug_PopStack "IGCM_comp_GetInputSmoothFiles" } #======================================================================= function IGCM_comp_GetInputBoundaryFiles { IGCM_debug_PushStack "IGCM_comp_GetInputBoundaryFiles" # Debug Print : echo IGCM_debug_Print 1 "IGCM_comp_GetInputBoundaryFiles :" echo typeset comp compname comptagname card ListFilesName FileName0 NbFiles i i_ typeset file_in_ file_in file_out_ file_out if [ ${Period} = 1 ]; then ListFixBoundary=" " fi for comp in ${config_ListOfComponents[*]} ; do echo "-----" # Define component eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1 eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1 # Debug Print : IGCM_debug_Print 3 "Boundary files ${compname}" card=${SUBMIT_DIR}/COMP/${compname}.card IGCM_card_DefineArrayFromOption ${card} BoundaryFiles List ListFilesName=${compname}_BoundaryFiles_List eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1 if [ X${FileName0} != X${NULL_STR} ] ; then eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1 (( i=0 )) until [ $i -ge $NbFiles ]; do eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1 eval file_in=${file_in_} (( i_ = i+1 )) eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1 eval file_out=${file_out_} IGCM_sys_Get ${file_in} ${file_out} IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out} (( i=i+2 )) done fi # Get non deleted files if [ ${Period} = 1 ]; then IGCM_card_DefineArrayFromOption ${card} BoundaryFiles ListNonDel ListFilesName=${compname}_BoundaryFiles_ListNonDel eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1 if [ X${FileName0} != X${NULL_STR} ] ; then eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1 (( i=0 )) until [ $i -ge $NbFiles ]; do eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1 eval file_in=${file_in_} (( i_ = i+1 )) eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1 eval file_out=${file_out_} IGCM_sys_Get ${file_in} ${file_out} if [ X${file_out} != X. ] ; then ListFixBoundary=${ListFixBoundary}" "${file_out} else ListFixBoundary=${ListFixBoundary}" "$( basename ${file_in} ) fi (( i=i+2 )) done fi fi done IGCM_debug_PopStack "IGCM_comp_GetInputBoundaryFiles" } #======================================================================= function IGCM_comp_DelFixeBoundaryFiles { IGCM_debug_PushStack "IGCM_comp_DelFixeBoundaryFiles" # Debug Print : echo IGCM_debug_Print 1 "IGCM_comp_DelFixeBoundaryFiles :" echo ls -l ${ListFixBoundary} rm -f ${ListFixBoundary} IGCM_debug_PopStack "IGCM_comp_DelFixeBoundaryFiles" } #======================================================================= function IGCM_comp_GetInputParametersFiles { IGCM_debug_PushStack "IGCM_comp_GetInputParametersFiles" # Debug Print : echo IGCM_debug_Print 1 "IGCM_comp_GetInputParametersFiles :" echo typeset comp compname comptagname card ListFilesName FileName0 NbFiles i i_ file_in file_out for comp in ${config_ListOfComponents[*]} ; do # Define component eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1 eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1 # Debug Print : IGCM_debug_Print 3 "Parameters ${compname}" card=${SUBMIT_DIR}/COMP/${compname}.card IGCM_card_DefineArrayFromOption ${card} ParametersFiles List ListFilesName=${compname}_ParametersFiles_List eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1 if [ X${FileName0} != X${NULL_STR} ] ; then eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1 (( i=0 )) until [ $i -ge $NbFiles ]; do eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1 eval file_in=${file_in_} (( i_ = i+1 )) eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1 eval file_out=${file_out_} IGCM_sys_Cp ${file_in} ${file_out} IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out} (( i=i+2 )) done fi done IGCM_debug_PopStack "IGCM_comp_GetInputParametersFiles" } #======================================================================= function IGCM_comp_GetInputRestartFiles { IGCM_debug_PushStack "IGCM_comp_GetInputRestartFiles" # Debug Print : echo IGCM_debug_Print 1 "IGCM_comp_GetInputRestartFiles :" echo typeset Date_tmp Date_r Path_r do_start CompOldName Path_temp typeset comp compname comptagname card ListFilesName FileName0 NbFiles i i_ typeset file_in file_out file_in_ file_out_ file_in_Name typeset -Z4 j4 for comp in ${config_ListOfComponents[*]} ; do # Define component eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1 eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1 # card=${SUBMIT_DIR}/COMP/${compname}.card # IGCM_card_DefineArrayFromOption ${card} RestartFiles List ListFilesName=${compname}_RestartFiles_List eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1 # Debug Print : IGCM_debug_Print 3 "restart ${compname}" if ( ${FirstInitialize} ) ; then if [ "${config_Restarts_OverRule}" = "y" ] ; then eval config_${comp}_Restart="y" eval config_${comp}_RestartDate=${config_Restarts_RestartDate} eval config_${comp}_RestartJobName=${config_Restarts_RestartJobName} eval config_${comp}_RestartPath=${config_Restarts_RestartPath} eval do_start=\${config_${comp}_Restart} > /dev/null 2>&1 eval CompOldName=${comp} else # Read component Restarts parameters IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} Restart eval do_start=\${config_${comp}_Restart} > /dev/null 2>&1 if [ "${do_start}" = "y" ] ; then IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} RestartDate IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} RestartJobName IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} RestartPath else eval config_${comp}_RestartDate=-1 eval config_${comp}_RestartJobName=${NULL_STR} eval config_${comp}_RestartPath=${NULL_STR} fi IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card ${comp} OldName eval CompOldName=\${config_${comp}_OldName} if [ X${CompOldName} = X ] ; then eval CompOldName=${comp} fi fi if [ "${do_start}" = "y" ] ; then if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != XNONE ] ) ; then eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1 (( i=1 )) until [ $i -gt $NbFiles ]; do eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1 eval file_in=${file_in_} (( i_ = i+1 )) eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1 eval file_out=${file_out_} eval Date_tmp=\${config_${comp}_RestartDate} Date_r=$( IGCM_date_ConvertFormatToGregorian ${Date_tmp} ) eval Path_r=\${config_${comp}_RestartPath}/\${config_${comp}_RestartJobName}/${CompOldName}/Restart eval file_in_Name=\${config_${comp}_RestartJobName}_${Date_r}_${file_in} generic_restart_file_name_in=$( basename ${file_in_Name} .nc ) generic_restart_file_name_out=$( basename ${file_out} .nc ) eval Path_temp=\${Path_r}/${generic_restart_file_name_in} nb_restart_file=$(IGCM_sys_CountFileArchive ${Path_temp}_????.nc) if [ ${nb_restart_file} -gt 1 ] ; then j=0 until [ $j -ge $nb_restart_file ]; do j4=${j} eval IGCM_sys_Get ${Path_r}/${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_out}_${j4}.nc #IGCM_comp_PrepareDeletedFiles ${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_out}_${j4}.nc #eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${generic_restart_file_name_out}_${j4}.nc" > /dev/null 2>&1 (( j=j+1 )) done else eval IGCM_sys_Get ${Path_r}/${file_in_Name} ${file_out} #IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out} fi (( i=i+3 )) done else if [ X${FileName0} != XNONE ] ; then IGCM_debug_Exit "IGCM_comp_GetInputRestartFiles : No file in list for ${compname}." else IGCM_debug_Print 1 "IGCM_comp_GetInputRestartFiles : NONE specified in Restart List ${compname}." fi fi fi elif [ ${Period} -eq 1 ] ; then # if not FirstInitialize and first loop of this job # Restore Restarts files #----------------------- if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != XNONE ] ) ; then eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1 (( i=1 )) until [ $i -gt $NbFiles ]; do eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1 eval file_in=${file_in_} (( i_ = i+1 )) eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1 eval file_out=${file_out_} file_in_Name=${run_Configuration_OldPrefix}_${file_in} generic_restart_file_name_in=$( basename ${file_in_Name} .nc ) generic_restart_file_name_out=$( basename ${file_out} .nc ) eval Path_temp=\${R_OUT_${comp}_R}/${generic_restart_file_name_in} nb_restart_file=$(IGCM_sys_CountFileArchive ${Path_temp}_????.nc) if [ ${nb_restart_file} -gt 1 ] ; then j=0 until [ $j -ge $nb_restart_file ]; do j4=${j} eval IGCM_sys_Get \${R_OUT_${comp}_R}/${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_out}_${j4}.nc #IGCM_comp_PrepareDeletedFiles ${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_out}_${j4}.nc #eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${generic_restart_file_name_out}_${j4}.nc" > /dev/null 2>&1 (( j=j+1 )) done else eval IGCM_sys_Get \${R_OUT_${comp}_R}/${file_in_Name} ${file_out} #IGCM_comp_PrepareDeletedFiles ${file_in} ${file_out} fi (( i=i+3 )) done else if [ X${FileName0} != XNONE ] ; then IGCM_debug_Exit "IGCM_comp_GetInputRestartFiles : No file in list for ${compname}." else IGCM_debug_Print 1 "IGCM_comp_GetInputRestartFiles : NONE specified in Restart List ${compname}." fi fi fi done IGCM_sys_Chmod u+rw * IGCM_debug_PopStack "IGCM_comp_GetInputRestartFiles" } #======================================================================= function IGCM_comp_PeriodStart { IGCM_debug_PushStack "IGCM_comp_PeriodStart" # Debug Print : echo IGCM_debug_Print 1 "IGCM_comp_PeriodStart :" echo typeset ExeNameIn ExeNameOut typeset comp compname comptagname for comp in ${config_ListOfComponents[*]} ; do # Define component eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1 eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1 # Copy executable for this component eval ExeNameIn=\${config_Executable_${comp}[0]} eval ExeNameOut=\${config_Executable_${comp}[1]} # Debug Print IGCM_debug_Print 3 "PeriodStart ${compname} Driver Function (if any)." # UPDATE component ${comp}_PeriodStart 2> /dev/null done IGCM_debug_PopStack "IGCM_comp_PeriodStart" } #======================================================================= function IGCM_comp_Update { IGCM_debug_PushStack "IGCM_comp_Update" # Debug Print : echo IGCM_debug_Print 1 "IGCM_comp_Update :" echo typeset ExeNameIn ExeNameOut typeset comp compname comptagname for comp in ${config_ListOfComponents[*]} ; do # Define component eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1 eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1 # Copy executable for this component eval ExeNameIn=\${config_Executable_${comp}[0]} eval ExeNameOut=\${config_Executable_${comp}[1]} # If missing executable then stop! #if [ ! X${ExeNameIn} = X ] && [ ! -f ${R_EXE}/${ExeNameIn} ] ; then # IGCM_debug_Exit "IGCM_comp_Update missing executable ${ExeNameIn}" #fi if [ ${Period} -eq 1 ] && [ -f ${R_EXE}/${ExeNameIn} ] ; then eval IGCM_sys_Cp ${R_EXE}/${ExeNameIn} ${ExeNameOut} if [ -f ${RUN_DIR}/${ExeNameOut} ] ; then eval IGCM_sys_Chmod +rx ${RUN_DIR}/${ExeNameOut} fi elif [ -f ${R_EXE}/${ExeNameIn} ] && [ ! -f ${RUN_DIR}/${ExeNameOut} ] ; then eval IGCM_sys_Cp ${R_EXE}/${ExeNameIn} ${ExeNameOut} if [ -f ${RUN_DIR}/${ExeNameOut} ] ; then eval IGCM_sys_Chmod +rx ${RUN_DIR}/${ExeNameOut} fi fi # Debug Print IGCM_debug_Print 3 "Update ${compname} Parameter Files." # UPDATE component ${comp}_Update done IGCM_debug_PopStack "IGCM_comp_Update" } #======================================================================= function IGCM_comp_Finalize { IGCM_debug_PushStack "IGCM_comp_Finalize" # Debug Print : echo IGCM_debug_Print 1 "IGCM_comp_Finalize :" echo typeset ListTextName TextName0 typeset comp compname comptagname card ListFilesName FileName0 NbFiles SaveOnArchive typeset i i_ file_in file_in_ file_out file_out_ file_outin file_outin_ generic_file_name nb_rebuild_file typeset -Z4 j4 for comp in ${config_ListOfComponents[*]} ; do # Define component eval compname=\${config_ListOfComponents_${comp}[0]} > /dev/null 2>&1 eval comptagname=\${config_ListOfComponents_${comp}[1]} > /dev/null 2>&1 # Debug Print IGCM_debug_Print 1 "Finalize ${compname} component." # FINALIZE component ${comp}_Finalize card=${SUBMIT_DIR}/COMP/${compname}.card # Save Restarts files #-------------------- IGCM_card_DefineArrayFromOption ${card} RestartFiles List ListFilesName=${compname}_RestartFiles_List eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1 if ( [ X${FileName0} != X${NULL_STR} ] && [ X${FileName0} != XNONE ] ) ; then eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1 (( i=0 )) until [ $i -ge $NbFiles ]; do eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1 eval file_in=${file_in_} (( i_ = i+1 )) eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1 eval file_out=${file_out_} (( i_ = i+2 )) eval file_outin_=\${${ListFilesName}[$i_]} > /dev/null 2>&1 eval file_outin=${file_outin_} generic_restart_file_name_in=$( basename ${file_in} .nc ) generic_restart_file_name_out=$( basename ${config_UserChoices_JobName}_${PeriodDateEnd}_${file_out} .nc ) generic_restart_file_name_outin=$( basename ${file_outin} .nc ) nb_restart_file=$( ls ${generic_restart_file_name_in}_????.nc 2>/dev/null | wc -l ) if [ ${nb_restart_file} -gt 1 ] ; then j=0 until [ $j -ge $nb_restart_file ]; do j4=${j} eval IGCM_sys_Put_Rest ${generic_restart_file_name_in}_${j4}.nc \${R_OUT_${comp}_R}/${generic_restart_file_name_out}_${j4}.nc [ ! ${file_in} = ${file_outin} ] && IGCM_sys_Mv ${generic_restart_file_name_in}_${j4}.nc ${generic_restart_file_name_outin}_${j4}.nc #eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${generic_restart_file_name_in}_${j4}.nc" > /dev/null 2>&1 (( j=j+1 )) done else eval IGCM_sys_Put_Rest ${file_in} \${R_OUT_${comp}_R}/${config_UserChoices_JobName}_${PeriodDateEnd}_${file_out} [ ! ${file_in} = ${file_outin} ] && IGCM_sys_Mv ${file_in} ${file_outin} #eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_in}" > /dev/null 2>&1 fi (( i=i+3 )) done else if [ X${FileName0} != XNONE ] ; then IGCM_debug_Exit "IGCM_comp_Finalize : No file in restart list for ${compname}." else IGCM_debug_Print 1 "IGCM_comp_Finalize : NONE specified in Restart List ${compname}." fi fi # Save Output files #------------------ IGCM_card_DefineArrayFromOption ${card} OutputFiles List ListFilesName=${compname}_OutputFiles_List eval FileName0=\${${ListFilesName}[0]} > /dev/null 2>&1 if [ X${FileName0} != X${NULL_STR} ] ; then eval NbFiles=\${#${ListFilesName}[@]} > /dev/null 2>&1 (( i=0 )) until [ $i -ge $NbFiles ]; do SaveOnArchive=true eval file_in_=\${${ListFilesName}[$i]} > /dev/null 2>&1 eval file_in=${file_in_} (( i_ = i+1 )) eval file_out_=\${${ListFilesName}[$i_]} > /dev/null 2>&1 eval file_out=${file_out_} (( i_ = i+2 )) eval flag_post=\${${ListFilesName}[$i_]} > /dev/null 2>&1 # generic_file_name=$( basename ${file_in} .nc ) nb_rebuild_file=$( ls | grep "^${generic_file_name}[_0-9]*.nc" | wc -l ) # if ( [ ${nb_rebuild_file} -eq 1 ] && [ -f ${generic_file_name}_0000.nc ] ) ; then IGCM_debug_Print 2 "Parallelism with 1 process. Rebuilding ${file_in} not needed" IGCM_sys_Mv ${generic_file_name}_0000.nc ${file_in} elif [ ${nb_rebuild_file} -gt 1 ] ; then IGCM_debug_Print 2 "Parallelism detected rebuilding ${file_in} is needed" if ( [ X${config_Post_RebuildFrequency} = X${NULL_STR} ] || [ X${config_Post_RebuildFrequency} = XNONE ] ) ; then IGCM_debug_Print 2 "Rebuilding ${file_in} online" IGCM_sys_rebuild ${file_in} ${generic_file_name}_*.nc else IGCM_debug_Print 2 "Preparing offline rebuild for ${file_in}" [ ! -d ${RUN_DIR}/REBUILD_${PeriodDateBegin} ] && IGCM_sys_Mkdir ${RUN_DIR}/REBUILD_${PeriodDateBegin} IGCM_sys_Mv ${generic_file_name}_????.nc ${RUN_DIR}/REBUILD_${PeriodDateBegin} # Prepare headers for the shell dedicated to offline rebuild if [ ! -f ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh ] ; then if [ $DRYRUN -le 1 ]; then echo \#!/bin/ksh > ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh echo function IGCM_FlushRebuild >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh echo { >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh echo IGCM_debug_PushStack "IGCM_FlushRebuild" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh echo echo >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh echo IGCM_debug_Print 1 "IGCM_FlushRebuild" >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh echo echo >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh fi fi # Prepare the shell dedicated to offline rebuild if [ $DRYRUN -le 1 ]; then echo IGCM_sys_rebuild ${file_in} ${generic_file_name}_*.nc >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh echo IGCM_debug_Verif_Exit >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh fi # # Load Patch we need to apply and apply if [ $DRYRUN -le 1 ]; then if [ X$( eval echo \${${compname}_${flag_post}_Patches[0]} ) != X${NULL_STR} ]; then for Patch in $( eval echo \${${compname}_${flag_post}_Patches[*]} ); do echo . ${libIGCM_POST}/libIGCM_post/IGCM_${Patch}.ksh >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh echo IGCM_${Patch} ${file_in} >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh done fi fi # if [ $DRYRUN -le 1 ]; then echo IGCM_sys_Put_Out ${file_in} ${file_out} >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh echo IGCM_debug_Verif_Exit >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh echo IGCM_sys_Rm ${generic_file_name}_*.nc >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh fi SaveOnArchive=false fi fi # if [ ${SaveOnArchive} = true ] ; then # # If we need to apply a patch we use TMP DIRECTORY before ARCHIVING if asynchronous rebuild is on # if ( [ ! X$( eval echo \${${compname}_${flag_post}_Patches[0]} ) = X${NULL_STR} ] && [ ! X${config_Post_RebuildFrequency} = X ] && [ ! X${config_Post_RebuildFrequency} = XNONE ] ) ; then if [ -f ${file_in} ] ; then IGCM_sys_Mv ${file_in} ${RUN_DIR}/REBUILD_${PeriodDateBegin} eval FileToBeDeleted[${#FileToBeDeleted[@]}]=REBUILD_${PeriodDateBegin}/${file_in} > /dev/null 2>&1 # if [ $DRYRUN -le 1 ]; then for Patch in $( eval echo \${${compname}_${flag_post}_Patches[*]} ); do echo . ${libIGCM_POST}/libIGCM_post/IGCM_${Patch}.ksh >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh echo IGCM_${Patch} ${file_in} >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh done # echo IGCM_sys_Put_Out ${file_in} ${file_out} >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh echo IGCM_debug_Verif_Exit >> ${RUN_DIR}/REBUILD_${PeriodDateBegin}/rebuild.ksh # fi fi else IGCM_sys_Put_Out ${file_in} ${file_out} [ $? -eq 0 ] && eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_in}" > /dev/null 2>&1 if [ ${nb_rebuild_file} -gt 1 ] ; then for DelFile in $( ls | grep "${generic_file_name}[_0-9]*.nc" ) ; do eval FileToBeDeleted[${#FileToBeDeleted[@]}]=${DelFile} > /dev/null 2>&1 done fi fi fi (( i=i+3 )) done fi # Save Output Text files of models #--------------------------------- IGCM_card_DefineArrayFromOption ${card} OutputText List ListTextName=${compname}_OutputText_List eval TextName0=\${${ListTextName}[0]} > /dev/null 2>&1 if [ X${TextName0} != X${NULL_STR} ] ; then eval NbFiles=\${#${ListTextName}[@]} > /dev/null 2>&1 (( i=0 )) until [ $i -eq $NbFiles ]; do eval file_in=\${${ListTextName}[$i]} > /dev/null 2>&1 (( i=i+1 )) nb_text_file=$( ls ${file_in}* 2>/dev/null | wc -l ) if [ ${nb_text_file} -gt 1 ] ; then list_file=$( ls ${file_in}* ) for file in ${list_file} do eval IGCM_sys_Put_Out ${file} \${R_OUT_${comp}_D}/${PREFIX}_${file} eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file}" > /dev/null 2>&1 done else if ( [ -f ${file_in}_0000 ] || [ -f ${file_in}0 ] ) ; then eval IGCM_sys_Mv ${file_in}* ${file_in} fi eval IGCM_sys_Put_Out ${file_in} \${R_OUT_${comp}_D}/${PREFIX}_${file_in} [ $? -eq 0 ] && eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${file_in}" > /dev/null 2>&1 fi done fi done IGCM_debug_PopStack "IGCM_comp_Finalize" }