Ignore:
Timestamp:
03/07/12 10:39:55 (12 years ago)
Author:
mafoipsl
Message:

First try to merge libIGCM_MPI_OpenMP branch with libIGCM trunk revision 569. Tested on vargas with PackFrequency?=NONE included into config.card.

Location:
branches/libIGCM_MPI_OpenMP
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/libIGCM_MPI_OpenMP

  • branches/libIGCM_MPI_OpenMP/libIGCM_config/libIGCM_config.ksh

    r562 r571  
    1515function IGCM_config_Initialize 
    1616{ 
    17     IGCM_debug_PushStack "IGCM_config_Initialize" 
    18  
    19     # Debug Print : 
     17  IGCM_debug_PushStack "IGCM_config_Initialize" 
     18 
     19  # Debug Print : 
     20  echo 
     21  IGCM_debug_Print 1 "IGCM_config_Initialize" 
     22 
     23  if [ ! -r ${SUBMIT_DIR}/run.card ]; then  
     24    #================================================# 
     25    #         The file run.card doesn't exist        # 
     26    #================================================# 
     27    FirstInitialize=true 
     28    #copy initial run.card 
     29    IGCM_sys_Cp ${SUBMIT_DIR}/run.card.init ${SUBMIT_DIR}/run.card 
     30    IGCM_debug_Print 2 "run.card copied from run.card.init" 
     31  else 
     32    FirstInitialize=false 
     33    IGCM_debug_Print 2 "run.card exists" 
     34  fi 
     35 
     36  # Test modipsl tree existence. 
     37  IGCM_sys_TestDir ${MODIPSL} 
     38  [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDir" 
     39  IGCM_sys_TestDir ${libIGCM} 
     40  [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDir" 
     41  IGCM_sys_TestDir ${R_EXE} 
     42  [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDir" 
     43  IGCM_sys_TestDir ${SUBMIT_DIR} 
     44  [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDir" 
     45 
     46  if ( $DEBUG_debug ) ; then 
     47    echo "Keep trace of inital SUBMIT_DIR : " 
     48    ls -lta ${SUBMIT_DIR} 
     49  fi 
     50 
     51  #================================== 
     52 
     53  typeset option auxprint CompatibilityTag 
     54  # Read libIGCM compatibility version in config.card 
     55  IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card Compatibility libIGCM 
     56  eval CompatibilityTag=${config_Compatibility_libIGCM} > /dev/null 2>&1         
     57 
     58  if [ ! "${CompatibilityTag}" = "${libIGCM_CurrentTag}" ] ; then 
     59    IGCM_debug_Exit "config.card is not compatible with libIGCM version ${libIGCM_CurrentTag} see libIGCM FAQ http://wiki.ipsl.jussieu.fr/wiki_ipsl/IGCMG/libIGCM/DocUtilisateur/FAQ ." 
     60  fi 
     61 
     62  #================================== 
     63  IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card UserChoices 
     64 
     65  for option in ${config_UserChoices[*]} ; do 
     66    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card UserChoices ${option} 
     67  done 
     68  echo 
     69  IGCM_debug_Print 1 "DefineArrayFromOption  : config_UserChoices" 
     70  # Name Space of this experience  
     71  if [ X${config_UserChoices_SpaceName} != X ] ; then 
     72    IGCM_debug_PrintVariables 3 config_UserChoices_SpaceName 
     73  fi 
     74  # Expericence class of the run 
     75  if [ X${config_UserChoices_ExperimentName} != X ] ; then 
     76    IGCM_debug_PrintVariables 3 config_UserChoices_ExperimentName 
     77  fi 
     78  IGCM_debug_PrintVariables 3 config_UserChoices_JobName 
     79  if [ 3 -le ${Verbosity} ] ; then 
     80    echo "--------------Debug3-->" "config_UserChoices_LongName=" 
     81    echo "--------------Debug3-->" \"${config_UserChoices_LongName}\" 
     82  fi 
     83  IGCM_debug_PrintVariables 3 config_UserChoices_TagName 
     84  IGCM_debug_PrintVariables 3 config_UserChoices_CalendarType 
     85  IGCM_debug_PrintVariables 3 config_UserChoices_DateBegin 
     86  IGCM_debug_PrintVariables 3 config_UserChoices_DateEnd 
     87  IGCM_debug_PrintVariables 3 config_UserChoices_PeriodLength 
     88 
     89  #================================== 
     90 
     91  IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card ListOfComponents 
     92  for comp in ${config_ListOfComponents[*]} ; do 
     93    IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/config.card ListOfComponents ${comp} 
     94  done 
     95 
     96  echo 
     97  IGCM_debug_Print 1 "DefineArrayFromSection : ListOfComponents" 
     98  IGCM_debug_Print 3 ${config_ListOfComponents[*]} 
     99 
     100  NbComponents=${#config_ListOfComponents[*]} 
     101 
     102  #================================== 
     103  # Define principal executable 
     104  IGCM_card_DefineArrayFromSection   ${SUBMIT_DIR}/config.card Executable 
     105  IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card Executable Name 
     106   
     107  #================================== 
     108  # Define Outputs Name 
     109  IGCM_debug_Print 2 "Define Script_Output_Prefix and Exe_Output" 
     110  eval Script_Output_Prefix=${config_UserChoices_Script_Output_Prefix:='Script_Output'} 
     111  IGCM_debug_Print 3 "Script_Output_Prefix = ${Script_Output_Prefix}" 
     112  eval Exe_Output=out_${config_Executable_Name} 
     113  IGCM_debug_Print 3 "Exe_Output           = ${Exe_Output}" 
     114 
     115  IGCM_card_DefineArrayFromSection   ${SUBMIT_DIR}/config.card Executable 
     116  IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card Executable Name 
     117     
     118  #================================== 
     119  # Define Outputs Name 
     120  IGCM_debug_Print 2 "Define Script_Output_Prefix and Exe_Output" 
     121  eval Script_Output_Prefix=${config_UserChoices_Script_Output_Prefix:='Script_Output'} 
     122  IGCM_debug_Print 3 "Script_Output_Prefix = ${Script_Output_Prefix}" 
     123  Exe_Output=out_execution 
     124  #================================== 
     125 
     126  #===================================================================# 
     127  # Prepare variables available for ${COMP}.card and ${COMP}.driver   # 
     128  #             But available to any son functions                    # 
     129  #===================================================================# 
     130 
     131  # Convert yyyy-mm-dd date to gregorian yyyymmdd 
     132  DateBegin=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateBegin} ) 
     133  DateEnd=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateEnd} ) 
     134 
     135  # Period Length In Days between DateBegin and DateEnd 
     136  (( ExperienceLengthInDays=$( IGCM_date_DaysBetweenGregorianDate ${DateEnd} ${DateBegin} )  + 1 )) 
     137  if [ ${ExperienceLengthInDays} -lt 0 ] ; then 
     138    IGCM_debug_Print 1 "Problem with dates in config.card : ${DateEnd} < ${DateBegin} ! You must check that." 
     139    IGCM_debug_Exit "IGCM_config_Initialize" " Wrong Dates." 
     140    IGCM_debug_Verif_Exit  
     141  fi 
     142 
     143  # Day and Year of Initial State (Given in julian format) 
     144  InitDay=$(( $( IGCM_date_ConvertGregorianDateToJulian $DateBegin ) % 1000 )) 
     145  InitYear=$(( $( IGCM_date_ConvertGregorianDateToJulian $DateBegin ) / 1000 )) 
     146 
     147  #================================== 
     148  # Restarts : Gerneral rule or local for each component ? 
     149  IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card Restarts 
     150 
     151  echo 
     152  IGCM_debug_Print 1 "DefineArrayFromOption : config_Restarts" 
     153 
     154  for option in ${config_Restarts[*]} ; do 
     155    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card Restarts ${option} 
     156    eval auxprint=\${config_Restarts_${option}} 
     157    IGCM_debug_Print 3 "${option} : ${auxprint}" 
     158  done 
     159 
     160  #================================================================# 
     161  #                  Test and Prepare directories                  # 
     162  #================================================================# 
     163 
     164  # ==> 4 kinds of input files : 
     165  #     1) R_INIT  : Initial State Files   (Etat0, carteveg) 
     166  #     2) R_BC    : Boundary Conditions   (Forcages, lai) 
     167  #     3) Parameters files (allready define through ${SUBMIT_DIR}) 
     168  #     4) Restarts files   (allready define in IGCM_config_Initialize) 
     169 
     170  # Here we offer the possibility to redefine R_INIT, R_BC 
     171  # and PeriodNb through config.card 
     172  R_INIT=${config_UserChoices_R_INIT:=${R_IN}/INIT} 
     173  IGCM_debug_Print 2 "(Re)Define R_INIT, R_BC and PeriodNb" 
     174  IGCM_debug_Print 3 "R_INIT=${R_INIT}" 
     175  R_BC=${config_UserChoices_R_BC:=${R_IN}/BC} 
     176  IGCM_debug_Print 3  "R_BC=${R_BC}" 
     177  PeriodNb=${config_UserChoices_PeriodNb:=${PeriodNb}} 
     178  IGCM_debug_Print 3  "Loop in main Job with ${PeriodNb} period(s)" 
     179 
     180  # Test Archive input/output. 
     181  IGCM_sys_TestDirArchive ${ARCHIVE} 
     182  [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive" 
     183  IGCM_sys_TestDirArchive ${R_IN} 
     184  [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive" 
     185 
     186  #==================================================== 
     187  #R_SAVE : Job output directory 
     188  if ( [ ! X${config_UserChoices_SpaceName} = X ] && [ ! X${config_UserChoices_ExperimentName} = X ] ) ; then 
     189    FreeName=$( echo ${config_UserChoices_JobName} | sed 's/.*_//' ) 
     190    R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${FreeName} 
     191    R_BUFR=${R_BUF}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${FreeName} 
     192    R_DODS=${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${FreeName} 
     193  else 
     194    R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_JobName} 
     195    R_BUFR=${R_BUF}/${config_UserChoices_TagName}/${config_UserChoices_JobName} 
     196    R_DODS=${config_UserChoices_TagName}/${config_UserChoices_JobName} 
     197  fi 
     198 
     199  if ( ${FirstInitialize} ) ; then  
     200    IGCM_sys_MkdirArchive ${R_SAVE} 
     201    IGCM_sys_Mkdir        ${R_BUFR} 
     202  else 
     203    IGCM_sys_TestDirArchive ${R_SAVE} 
     204    [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive ${R_SAVE}" 
     205 
     206    IGCM_sys_TestDir        ${R_BUFR} 
     207    [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDir ${R_BUFR}" 
     208 
     209    #Test state of run in run.card 
     210    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodState 
     211     
     212    if ( [ ${run_Configuration_PeriodState} != "Start" ] && [ ${run_Configuration_PeriodState} != "Running" ] && [ ${run_Configuration_PeriodState} != "OnQueue" ] && [ ${run_Configuration_PeriodState} != "Continue" ] ) ; then 
     213      echo  
     214      IGCM_debug_Print 1 "!! Error in run.card with PeriodState : " ${run_Configuration_PeriodState} "!!" 
     215      IGCM_debug_Print 1 "Try running ${libIGCM}/clean_month.job to fix this" 
     216      IGCM_debug_Exit 
     217      IGCM_debug_Verif_Exit 
     218    fi 
     219  fi 
     220 
     221  #================================== 
     222  # Read Post section:  
     223  IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card Post 
     224 
     225  echo 
     226  IGCM_debug_Print 1 "DefineArrayFromOption : config_Post" 
     227 
     228  for option in ${config_Post[*]} ; do 
     229    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card Post ${option} 
     230    eval auxprint=\${config_Post_${option}} 
     231    IGCM_debug_Print 3 "${option} : ${auxprint}" 
     232  done 
     233 
     234  #================================== 
     235  # Define default value to keep compatibility with previous card: means before changes due to TGCC  
     236  [ X${config_Post_PackFrequency} = X ] && config_Post_PackFrequency=${config_Post_RebuildFrequency} 
     237 
     238  #==================================================== 
     239  # Define REBUILD_DIR : where we store files needing rebuild process 
     240  if [ X${config_Post_RebuildFromArchive} = Xtrue ] ; then 
     241    REBUILD_DIR=${R_SAVE}/TMP 
     242    IGCM_sys_MkdirArchive ${REBUILD_DIR} 
     243  else 
     244    REBUILD_DIR=${BIG_DIR}/${config_UserChoices_TagName}/${config_UserChoices_JobName} 
     245    IGCM_sys_MkdirWork ${REBUILD_DIR} 
     246  fi 
     247 
     248  #==================================================== 
     249  # Experience type : DEB(ug), DEV(elopment), RUN  
     250  if [ X${JobType} != XRUN ] ; then 
    20251    echo 
    21     IGCM_debug_Print 1 "IGCM_config_Initialize" 
    22  
    23     if [ ! -r ${SUBMIT_DIR}/run.card ]; then  
    24         #================================================# 
    25         #         The file run.card doesn't exist        # 
    26         #================================================# 
    27         FirstInitialize=true 
    28         #copy initial run.card 
    29         IGCM_sys_Cp ${SUBMIT_DIR}/run.card.init ${SUBMIT_DIR}/run.card 
    30         IGCM_debug_Print 2 "run.card copied from run.card.init" 
    31     else 
    32         FirstInitialize=false 
    33         IGCM_debug_Print 2 "run.card exists" 
    34     fi 
    35  
    36     # Test modipsl tree existence. 
    37     IGCM_sys_TestDir ${MODIPSL} 
    38     [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDir" 
    39     IGCM_sys_TestDir ${libIGCM} 
    40     [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDir" 
    41     IGCM_sys_TestDir ${R_EXE} 
    42     [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDir" 
    43     IGCM_sys_TestDir ${SUBMIT_DIR} 
    44     [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDir" 
    45  
    46     if ( $DEBUG_debug ) ; then 
    47         echo "Keep trace of inital SUBMIT_DIR : " 
    48         ls -lta ${SUBMIT_DIR} 
    49     fi 
    50  
    51     #================================== 
    52  
    53     typeset option auxprint CompatibilityTag 
    54     # Read libIGCM compatibility version in config.card 
    55     IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card Compatibility libIGCM 
    56     eval CompatibilityTag=${config_Compatibility_libIGCM} > /dev/null 2>&1       
    57  
    58     if [ ! "${CompatibilityTag}" = "${libIGCM_CurrentTag}" ] ; then 
    59         IGCM_debug_Exit "config.card is not compatible with libIGCM version ${libIGCM_CurrentTag} see libIGCM FAQ http://wiki.ipsl.jussieu.fr/wiki_ipsl/IGCMG/libIGCM/DocUtilisateur/FAQ ." 
    60     fi 
    61  
    62     #================================== 
    63     IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card UserChoices 
    64  
    65     for option in ${config_UserChoices[*]} ; do 
    66         IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card UserChoices ${option} 
    67     done 
     252    echo "====================================================" 
     253    echo "libIGCM JOB is NOT in RUN type mode." 
     254    echo "!! OUTPUT files will NOT be PROTECTED !!" 
     255    echo "Be carefull : you can ERASE the result of this job !" 
     256 
     257    case ${JobType} in 
     258    DEB) 
     259      echo "DEBUG mode : activation of 'set -vx' mode." 
     260      echo "DEBUG mode : no protection for output files." 
     261      echo "DEBUG mode : if active force asynchronous rebuild frequency to PeriodLength frequency." 
     262      ;; 
     263    DEV) 
     264      echo "DEVelopment mode : no protection for output files." 
     265      echo "DEVelopment mode : if active force asynchronous rebuild frequency to PeriodLength frequency." 
     266      ;; 
     267    esac 
     268 
     269    if ( [ X${config_Post_RebuildFrequency} != XNONE ] && [ ${DRYRUN} -eq 0 ] ) ; then 
     270      if [ X${config_Post_RebuildFrequency} != X${config_UserChoices_PeriodLength} ] ; then 
     271        echo "------------" 
     272        echo "WARNING : Job is NOT in RUN mode then we will force REBUILD Frequency" 
     273        echo "          to PeriodLength : ${config_UserChoices_PeriodLength}" 
     274        echo "------------" 
     275        config_Post_RebuildFrequency=${config_UserChoices_PeriodLength} 
     276      fi 
     277    fi 
     278    echo "====================================================" 
    68279    echo 
    69     IGCM_debug_Print 1 "DefineArrayFromOption  : config_UserChoices" 
    70     # Name Space of this experience  
    71     if [ X${config_UserChoices_SpaceName} != X ] ; then 
    72         IGCM_debug_PrintVariables 3 config_UserChoices_SpaceName 
    73     fi 
    74     # Expericence class of the run 
    75     if [ X${config_UserChoices_ExperimentName} != X ] ; then 
    76         IGCM_debug_PrintVariables 3 config_UserChoices_ExperimentName 
    77     fi 
    78     IGCM_debug_PrintVariables 3 config_UserChoices_JobName 
    79     if [ 3 -le ${Verbosity} ] ; then 
    80         echo "--------------Debug3-->" "config_UserChoices_LongName=" 
    81         echo "--------------Debug3-->" \"${config_UserChoices_LongName}\" 
    82     fi 
    83     IGCM_debug_PrintVariables 3 config_UserChoices_TagName 
    84     IGCM_debug_PrintVariables 3 config_UserChoices_CalendarType 
    85     IGCM_debug_PrintVariables 3 config_UserChoices_DateBegin 
    86     IGCM_debug_PrintVariables 3 config_UserChoices_DateEnd 
    87     IGCM_debug_PrintVariables 3 config_UserChoices_PeriodLength 
    88  
    89     #================================== 
    90  
    91     IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card ListOfComponents 
    92  
    93     echo 
    94     IGCM_debug_Print 1 "DefineArrayFromSection : ListOfComponents" 
    95     IGCM_debug_Print 3 ${config_ListOfComponents[*]} 
    96  
    97     NbComponents=${#config_ListOfComponents[*]} 
    98  
    99     #================================== 
    100     # Define principal executable 
    101  
    102     IGCM_card_DefineArrayFromSection   ${SUBMIT_DIR}/config.card Executable 
    103     IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card Executable Name 
    104      
    105     #================================== 
    106     # Define Outputs Name 
    107     IGCM_debug_Print 2 "Define Script_Output_Prefix and Exe_Output" 
    108     eval Script_Output_Prefix=${config_UserChoices_Script_Output_Prefix:='Script_Output'} 
    109     IGCM_debug_Print 3 "Script_Output_Prefix = ${Script_Output_Prefix}" 
    110 #MM : obsolete ! 
    111 #    eval Exe_Output=out_${config_Executable_Name} 
    112     eval Exe_Output=out_execution 
    113 #    IGCM_debug_Print 3 "Exe_Output           = ${Exe_Output}" 
    114  
    115     #================================== 
    116  
    117     #===================================================================# 
    118     # Prepare variables available for ${COMP}.card and ${COMP}.driver   # 
    119     #             But available to any son functions                    # 
    120     #===================================================================# 
    121  
    122     # Convert yyyy-mm-dd date to gregorian yyyymmdd 
    123     DateBegin=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateBegin} ) 
    124     DateEnd=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateEnd} ) 
    125  
    126     # Period Length In Days between DateBegin and DateEnd 
    127     (( ExperienceLengthInDays=$( IGCM_date_DaysBetweenGregorianDate ${DateEnd} ${DateBegin} )  + 1 )) 
    128     if [ ${ExperienceLengthInDays} -lt 0 ] ; then 
    129         IGCM_debug_Print 1 "Problem with dates in config.card : ${DateEnd} < ${DateBegin} ! You must check that." 
    130         IGCM_debug_Exit "IGCM_config_Initialize" " Wrong Dates." 
    131         IGCM_debug_Verif_Exit  
    132     fi 
    133  
    134     # Day and Year of Initial State (Given in julian format) 
    135     InitDay=$(( $( IGCM_date_ConvertGregorianDateToJulian $DateBegin ) % 1000 )) 
    136     InitYear=$(( $( IGCM_date_ConvertGregorianDateToJulian $DateBegin ) / 1000 )) 
    137  
    138     #================================== 
    139     # Restarts : Gerneral rule or local for each component ? 
    140     IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card Restarts 
    141  
    142     echo 
    143     IGCM_debug_Print 1 "DefineArrayFromOption : config_Restarts" 
    144  
    145     for option in ${config_Restarts[*]} ; do 
    146         IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card Restarts ${option} 
    147         eval auxprint=\${config_Restarts_${option}} 
    148         IGCM_debug_Print 3 "${option} : ${auxprint}" 
    149     done 
    150  
    151     #================================================================# 
    152     #                  Test and Prepare directories                  # 
    153     #================================================================# 
    154  
    155     # ==> 4 kinds of input files : 
    156     #     1) R_INIT  : Initial State Files   (Etat0, carteveg) 
    157     #     2) R_BC    : Boundary Conditions   (Forcages, lai) 
    158     #     3) Parameters files (allready define through ${SUBMIT_DIR}) 
    159     #     4) Restarts files   (allready define in IGCM_config_Initialize) 
    160  
    161     # Here we offer the possibility to redefine R_INIT, R_BC 
    162     # and PeriodNb through config.card 
    163     R_INIT=${config_UserChoices_R_INIT:=${R_IN}/INIT} 
    164     IGCM_debug_Print 2 "(Re)Define R_INIT, R_BC and PeriodNb" 
    165     IGCM_debug_Print 3 "R_INIT=${R_INIT}" 
    166     R_BC=${config_UserChoices_R_BC:=${R_IN}/BC} 
    167     IGCM_debug_Print 3  "R_BC=${R_BC}" 
    168     PeriodNb=${config_UserChoices_PeriodNb:=${PeriodNb}} 
    169     IGCM_debug_Print 3  "Loop in main Job with ${PeriodNb} period(s)" 
    170  
    171     # Test Archive input/output. 
    172     IGCM_sys_TestDirArchive ${ARCHIVE} 
    173     [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive" 
    174     IGCM_sys_TestDirArchive ${R_IN} 
    175     [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive" 
    176  
    177     #==================================================== 
    178     #R_SAVE : Job output directory 
    179     if ( [ ! X${config_UserChoices_SpaceName} = X ] && [ ! X${config_UserChoices_ExperimentName} = X ] ) ; then 
    180         FreeName=$( echo ${config_UserChoices_JobName} | sed 's/.*_//' ) 
    181         R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${FreeName} 
    182         R_DODS=${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${FreeName} 
    183     else 
    184         R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_JobName} 
    185         R_DODS=${config_UserChoices_TagName}/${config_UserChoices_JobName} 
    186     fi 
    187  
    188     if ( ${FirstInitialize} ) ; then  
    189         IGCM_sys_MkdirArchive ${R_SAVE} 
    190     else 
    191         IGCM_sys_TestDirArchive ${R_SAVE} 
    192         [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive" 
    193         #Test state of run in run.card 
    194         IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodState 
    195          
    196         if ( [ ${run_Configuration_PeriodState} != "Start" ] && [ ${run_Configuration_PeriodState} != "Running" ] && [ ${run_Configuration_PeriodState} != "OnQueue" ] && [ ${run_Configuration_PeriodState} != "Continue" ] ) ; then 
    197             echo  
    198             IGCM_debug_Print 1 "!! Error in run.card with PeriodState : " ${run_Configuration_PeriodState} "!!" 
    199             IGCM_debug_Print 1 "Try running ${libIGCM}/clean_month.job to fix this" 
    200             IGCM_debug_Exit 
    201             IGCM_debug_Verif_Exit 
    202         fi 
    203     fi 
    204  
    205     #================================== 
    206     # Post :  
    207     IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card Post 
    208  
    209     echo 
    210     IGCM_debug_Print 1 "DefineArrayFromOption : config_Post" 
    211  
    212     for option in ${config_Post[*]} ; do 
    213         IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card Post ${option} 
    214         eval auxprint=\${config_Post_${option}} 
    215         IGCM_debug_Print 3 "${option} : ${auxprint}" 
    216     done 
    217  
    218     #==================================================== 
    219     # Define REBUILD_DIR : where we store files needing rebuild process 
    220     if [ X${config_Post_RebuildFromArchive} = Xtrue ] ; then 
    221         REBUILD_DIR=${R_SAVE}/TMP 
    222         IGCM_sys_MkdirArchive ${REBUILD_DIR} 
    223     else 
    224         REBUILD_DIR=${BIG_DIR}/${config_UserChoices_TagName}/${config_UserChoices_JobName} 
    225         IGCM_sys_MkdirWork ${REBUILD_DIR} 
    226     fi 
    227  
    228     #==================================================== 
    229     # Experience type : DEB(ug), DEV(elopment), RUN  
    230     if [ X${JobType} != XRUN ] ; then 
    231         echo 
    232         echo "====================================================" 
    233         echo "libIGCM JOB is NOT in RUN type mode." 
    234         echo "!! OUTPUT files will NOT be PROTECTED !!" 
    235         echo "Be carefull : you can ERASE the result of this job !" 
    236  
    237         case ${JobType} in 
    238             DEB) 
    239                 echo "DEBUG mode : activation of 'set -vx' mode." 
    240                 echo "DEBUG mode : no protection for output files." 
    241                 echo "DEBUG mode : if active force asynchronous rebuild frequency to PeriodLength frequency." 
    242                 ;; 
    243             DEV) 
    244                 echo "DEVelopment mode : no protection for output files." 
    245                 echo "DEVelopment mode : if active force asynchronous rebuild frequency to PeriodLength frequency." 
    246                 ;; 
    247         esac 
    248  
    249         if ( [ X${config_Post_RebuildFrequency} != XNONE ] && [ ${DRYRUN} -eq 0 ] ) ; then 
    250             if [ X${config_Post_RebuildFrequency} != X${config_UserChoices_PeriodLength} ] ; then 
    251                 echo "------------" 
    252                 echo "WARNING : Job is NOT in RUN mode then we will force REBUILD Frequency" 
    253                 echo "          to PeriodLength : ${config_UserChoices_PeriodLength}" 
    254                 echo "------------" 
    255                 config_Post_RebuildFrequency=${config_UserChoices_PeriodLength} 
    256             fi 
    257         fi 
    258         echo "====================================================" 
    259         echo 
    260     fi 
    261  
    262     #==================================================== 
    263     #R_OUT_KSH : Storage place for job output 
    264     #R_OUT_EXE : Storage place for binary used during simulation 
    265     R_OUT_KSH=${R_SAVE}/Out 
    266     R_OUT_EXE=${R_SAVE}/Exe 
    267  
    268     IGCM_debug_PopStack "IGCM_config_Initialize" 
     280  fi 
     281 
     282  #==================================================== 
     283  #R_OUT_KSH : Storage place for job output 
     284  #R_OUT_EXE : Storage place for binary used during simulation 
     285  R_OUT_KSH=${R_SAVE}/Out 
     286  R_OUT_EXE=${R_SAVE}/Exe 
     287 
     288  #==================================================== 
     289  #R_BUF_KSH : Buffer place for job output 
     290  #R_BUF_EXE : Buffer place for binary used during simulation 
     291  R_BUF_KSH=${R_BUFR}/Out 
     292  R_BUF_EXE=${R_BUFR}/Exe 
     293 
     294  IGCM_debug_PopStack "IGCM_config_Initialize" 
    269295} 
    270296 
     
    272298function IGCM_config_Analyse_PeriodLength 
    273299{ 
    274     IGCM_debug_PushStack "IGCM_config_Analyse_PeriodLength" 
    275  
    276     typeset i 
    277  
    278     # Determine number of day(s) in PeriodLength : 
    279     case ${config_UserChoices_PeriodLength} in 
    280         *Y|*y) 
    281             PeriodLengthInYears=$( echo ${config_UserChoices_PeriodLength} | sed -e 's/[yY]//' )  
    282             IGCM_debug_Print 2 "Number of years for PeriodLength : ${PeriodLengthInYears}" 
    283             PeriodLengthInDays=0 
    284             i=0 
    285             until [ $i -ge $PeriodLengthInYears ] ; do  
    286                 (( PeriodLengthInDays = PeriodLengthInDays + $( IGCM_date_DaysInYear $(( year + i )) ) ))  
    287                 (( i=i+1 ))  
    288             done  
    289             ;; 
    290         *M|*m) 
    291             PeriodLengthInMonths=$( echo ${config_UserChoices_PeriodLength} | sed -e 's/[mM]//' )  
    292             IGCM_debug_Print 2 "Number of months for PeriodLength : ${PeriodLengthInMonths}" 
    293             PeriodLengthInDays=0 
    294             i=0 
    295             until [ $i -ge $PeriodLengthInMonths ] ; do  
    296                 if [ $(( month + i )) -lt 13 ] ; then  
    297                     (( PeriodLengthInDays  = PeriodLengthInDays + $( IGCM_date_DaysInMonth $year $(( month + i )) ) ))   
    298                 else  
    299                     (( PeriodLengthInDays  = PeriodLengthInDays + $( IGCM_date_DaysInMonth $year $(( month + i - 12 )) ) ))   
    300                 fi  
    301                 (( i=i+1 ))  
    302             done  
    303             ;; 
    304         *D|*d)   
    305             PeriodLengthInMonths=0 
    306             PeriodLengthInDays=$( echo ${config_UserChoices_PeriodLength} | sed -e 's/[dD]//' );; 
    307         *)  
    308             IGCM_debug_Exit "IGCM_config_Analyse_PeriodLength " ${config_UserChoices_PeriodLength} " invalid period length : choose in *Y, *M, *D." 
    309             IGCM_debug_Verif_Exit ;; 
    310     esac 
    311  
    312     IGCM_debug_PopStack "IGCM_config_Analyse_PeriodLength" 
     300  IGCM_debug_PushStack "IGCM_config_Analyse_PeriodLength" 
     301 
     302  typeset i 
     303 
     304  # Determine number of day(s) in PeriodLength : 
     305  case ${config_UserChoices_PeriodLength} in 
     306  *Y|*y) 
     307    PeriodLengthInYears=$( echo ${config_UserChoices_PeriodLength} | sed -e 's/[yY]//' )  
     308    IGCM_debug_Print 2 "Number of years for PeriodLength : ${PeriodLengthInYears}" 
     309    PeriodLengthInDays=0 
     310    i=0 
     311    until [ $i -ge $PeriodLengthInYears ] ; do  
     312      (( PeriodLengthInDays = PeriodLengthInDays + $( IGCM_date_DaysInYear $(( year + i )) ) ))  
     313      (( i=i+1 ))  
     314    done  
     315    ;; 
     316  *M|*m) 
     317    PeriodLengthInMonths=$( echo ${config_UserChoices_PeriodLength} | sed -e 's/[mM]//' )  
     318    IGCM_debug_Print 2 "Number of months for PeriodLength : ${PeriodLengthInMonths}" 
     319    PeriodLengthInDays=0 
     320    i=0 
     321    until [ $i -ge $PeriodLengthInMonths ] ; do  
     322      if [ $(( month + i )) -lt 13 ] ; then  
     323        (( PeriodLengthInDays  = PeriodLengthInDays + $( IGCM_date_DaysInMonth $year $(( month + i )) ) ))   
     324      else  
     325        (( PeriodLengthInDays  = PeriodLengthInDays + $( IGCM_date_DaysInMonth $year $(( month + i - 12 )) ) ))   
     326      fi  
     327      (( i=i+1 ))  
     328    done  
     329    ;; 
     330  *D|*d)   
     331    PeriodLengthInMonths=0 
     332    PeriodLengthInDays=$( echo ${config_UserChoices_PeriodLength} | sed -e 's/[dD]//' );; 
     333  *)  
     334    IGCM_debug_Exit "IGCM_config_Analyse_PeriodLength " ${config_UserChoices_PeriodLength} " invalid period length : choose in *Y, *M, *D." 
     335    IGCM_debug_Verif_Exit ;; 
     336  esac 
     337 
     338  IGCM_debug_PopStack "IGCM_config_Analyse_PeriodLength" 
    313339} 
    314340 
     
    316342function IGCM_config_Check 
    317343{ 
    318     IGCM_debug_PushStack "IGCM_config_Check" 
    319  
    320     # If one of the following modulo is not zero : 
    321     # we will issue an error then explain and exit in 
    322     # AA_job IGCM_debug_Verif_Exit call before binary submission 
    323  
     344  IGCM_debug_PushStack "IGCM_config_Check" 
     345 
     346  # If one of the following modulo is not zero : 
     347  # we will issue an error then explain and exit in 
     348  # AA_job IGCM_debug_Verif_Exit call before binary submission 
     349 
     350  echo 
     351  IGCM_debug_Print 1 "IGCM_config_Check" 
     352  echo 
     353 
     354  typeset i 
     355 
     356  # Check RebuildFrequency against key frequencies : PeriodLength ; PackFrequency ; TimeSeriesFrequency ; SeasonalFrequency 
     357  if ( [ ! X${config_Post_RebuildFrequency} = X${NULL_STR} ] && [ ! X${config_Post_RebuildFrequency} = XNONE ] ) ; then 
     358    AsynchronousRebuild=true 
     359    IGCM_debug_Print 1 "Asynchronous rebuild has been activated." 
    324360    echo 
    325     IGCM_debug_Print 1 "IGCM_config_Check" 
     361    # modulo (RebuildFrequency and PeriodLength/TimeSeriesFrequency/SeasonalFrequency) must be zero 
     362    IGCM_debug_Print 1 "Check coherence between RebuildFrequency and PeriodLength" 
     363    IGCM_post_CheckModuloFrequency config_Post_RebuildFrequency config_UserChoices_PeriodLength 
     364    IGCM_debug_Print 1 "Check coherence between PackFrequency and RebuildFrequency" 
     365    IGCM_post_CheckModuloFrequency config_Post_PackFrequency config_Post_RebuildFrequency 
     366    IGCM_debug_Print 1 "Check coherence between TimeSeriesFrequency and RebuildFrequency" 
     367    IGCM_post_CheckModuloFrequency config_Post_TimeSeriesFrequency config_Post_RebuildFrequency 
     368    IGCM_debug_Print 1 "Check coherence between SeasonalFrequency and RebuildFrequency" 
     369    IGCM_post_CheckModuloFrequency config_Post_SeasonalFrequency config_Post_RebuildFrequency 
     370  else 
     371    AsynchronousRebuild=false 
     372    IGCM_debug_Print 1 "Asynchronous rebuild has not been activated" 
     373    IGCM_debug_Print 1 "Proceed with standard post-treatment pathway" 
    326374    echo 
    327  
    328     typeset i 
    329  
    330     if ( [ ! X${config_Post_RebuildFrequency} = X${NULL_STR} ] || [ ! X${config_Post_RebuildFrequency} = XNONE ] ) ; then 
    331         AsynchronousRebuild=true 
    332         IGCM_debug_Print 1 "Asynchronous rebuild has been activated." 
    333         echo 
    334         # modulo (RebuildFrequency and PeriodLength/TimeSeriesFrequency/SeasonalFrequency) must be zero 
    335         IGCM_debug_Print 1 "Check coherence between RebuildFrequency and PeriodLength" 
    336         IGCM_post_CheckModuloFrequency config_Post_RebuildFrequency config_UserChoices_PeriodLength 
    337         IGCM_debug_Print 1 "Check coherence between TimeSeriesFrequency and RebuildFrequency" 
    338         IGCM_post_CheckModuloFrequency config_Post_TimeSeriesFrequency config_Post_RebuildFrequency 
    339         IGCM_debug_Print 1 "Check coherence between SeasonalFrequency and RebuildFrequency" 
    340         IGCM_post_CheckModuloFrequency config_Post_SeasonalFrequency config_Post_RebuildFrequency 
    341     else 
    342         AsynchronousRebuild=false 
    343         IGCM_debug_Print 1 "Asynchronous rebuild has not been activated" 
    344         IGCM_debug_Print 1 "Proceed with standard post-treatment pathway" 
    345         echo 
    346         #modulo (TimeSeriesFrequency/SeasonalFrequency and PeriodLenght) must be zero 
    347         IGCM_debug_Print 1 "Check coherence between TimeSeriesFrequency and PeriodLength" 
    348         IGCM_post_CheckModuloFrequency config_Post_TimeSeriesFrequency config_UserChoices_PeriodLength 
    349         IGCM_debug_Print 1 "Check coherence between SeasonalFrequency and PeriodLength" 
    350         IGCM_post_CheckModuloFrequency config_Post_SeasonalFrequency   config_UserChoices_PeriodLength 
    351     fi 
    352  
    353     #modulo (TimeSeriesFrequency and all Chunck2D) must be zero 
    354     NbJob=${#CHUNCK2D_SIZE[@]} 
    355     i=0 
    356     until [ $i -ge $NbJob ]; do 
    357         value=${CHUNCK2D_SIZE[${i}]} 
    358         IGCM_debug_Print 1 "Check coherence between All Chunck2D frequency and TimeSeriesFrequency" 
    359         IGCM_post_CheckModuloFrequency value config_Post_TimeSeriesFrequency 
    360         case ${value} in   
    361             *Y|*y) ;;  
    362             *)  IGCM_debug_Print 1 "All ChunckJob2D frequency must be expressed in year *Y|*y in comp.card" 
    363                 IGCM_debug_Exit "This will stop the job" ;; 
    364         esac 
    365         (( i=i+1 )) 
    366     done 
    367  
    368     #modulo (TimeSeriesFrequency and all Chunck3D) must be zero 
    369     NbJob=${#CHUNCK3D_SIZE[@]} 
    370     i=0 
    371     until [ $i -ge $NbJob ]; do 
    372         value=${CHUNCK3D_SIZE[${i}]} 
    373         IGCM_debug_Print 1 "Check coherence between All Chunck3D frequency and TimeSeriesFrequency" 
    374         IGCM_post_CheckModuloFrequency value config_Post_TimeSeriesFrequency 
    375         case ${value} in   
    376             *Y|*y) ;;  
    377             *)  IGCM_debug_Print 1 "All ChunckJob3D frequency must be expressed in year *Y|*y in comp.card" 
    378                 IGCM_debug_Exit "This will stop the job" ;; 
    379         esac 
    380         (( i=i+1 )) 
    381     done 
    382  
    383     IGCM_debug_PopStack "IGCM_config_Check" 
     375    #modulo (PeriodLength and TimeSeriesFrequency/SeasonalFrequency) must be zero 
     376    IGCM_debug_Print 1 "Check coherence between TimeSeriesFrequency and PeriodLength" 
     377    IGCM_post_CheckModuloFrequency config_Post_TimeSeriesFrequency config_UserChoices_PeriodLength 
     378    IGCM_debug_Print 1 "Check coherence between SeasonalFrequency and PeriodLength" 
     379    IGCM_post_CheckModuloFrequency config_Post_SeasonalFrequency   config_UserChoices_PeriodLength 
     380  fi 
     381 
     382  # Check PackFrequency against other key frequencies  
     383  # Modulo (PackFrequency and TimeSeriesFrequency/SeasonalFrequency and PeriodLenght) must be zero 
     384  if ( [ ! X${config_Post_PackFrequency} = X${NULL_STR} ] && [ ! X${config_Post_PackFrequency} = XNONE ] ) ; then 
     385    Pack=true 
     386    # 
     387    IGCM_debug_Print 1 "Check coherence between PackFrequency and PeriodLength" 
     388    IGCM_post_CheckModuloFrequency config_Post_PackFrequency config_UserChoices_PeriodLength 
     389    IGCM_debug_Print 1 "Check coherence between TimeSeriesFrequency and PackFrequency" 
     390    IGCM_post_CheckModuloFrequency config_Post_TimeSeriesFrequency config_Post_PackFrequency 
     391    IGCM_debug_Print 1 "Check coherence between SeasonalFrequency and PackFrequency" 
     392    IGCM_post_CheckModuloFrequency config_Post_SeasonalFrequency config_Post_PackFrequency 
     393  else 
     394    Pack=false 
     395  fi 
     396 
     397  #modulo (TimeSeriesFrequency and all Chunck2D) must be zero 
     398  NbJob=${#CHUNCK2D_SIZE[@]} 
     399  i=0 
     400  until [ $i -ge $NbJob ]; do 
     401    value=${CHUNCK2D_SIZE[${i}]} 
     402    IGCM_debug_Print 1 "Check coherence between All Chunck2D frequency and TimeSeriesFrequency" 
     403    IGCM_post_CheckModuloFrequency value config_Post_TimeSeriesFrequency 
     404    case ${value} in   
     405    *Y|*y) ;;  
     406    *)  IGCM_debug_Print 1 "All ChunckJob2D frequency must be expressed in year *Y|*y in comp.card" 
     407      IGCM_debug_Exit "This will stop the job" ;; 
     408    esac 
     409    (( i=i+1 )) 
     410  done 
     411 
     412  #modulo (TimeSeriesFrequency and all Chunck3D) must be zero 
     413  NbJob=${#CHUNCK3D_SIZE[@]} 
     414  i=0 
     415  until [ $i -ge $NbJob ]; do 
     416    value=${CHUNCK3D_SIZE[${i}]} 
     417    IGCM_debug_Print 1 "Check coherence between All Chunck3D frequency and TimeSeriesFrequency" 
     418    IGCM_post_CheckModuloFrequency value config_Post_TimeSeriesFrequency 
     419    case ${value} in   
     420    *Y|*y) ;;  
     421    *)  IGCM_debug_Print 1 "All ChunckJob3D frequency must be expressed in year *Y|*y in comp.card" 
     422      IGCM_debug_Exit "This will stop the job" ;; 
     423    esac 
     424    (( i=i+1 )) 
     425  done 
     426 
     427  IGCM_debug_PopStack "IGCM_config_Check" 
    384428} 
    385429 
     
    387431function IGCM_config_PeriodStart 
    388432{ 
    389     IGCM_debug_PushStack "IGCM_config_PeriodStart" 
    390  
    391     echo 
    392     IGCM_debug_Print 1 "IGCM_config_PeriodStart" 
    393     echo 
    394  
    395     if ( ${FirstInitialize} ) ; then 
    396         #================================================# 
    397         #         Initialize date/period information     # 
    398         #================================================# 
    399  
    400         IGCM_date_GetYearMonth $DateBegin year month 
    401         year_m1=$(( year - 1 )) 
    402         year_p1=$(( year + 1 ))  
    403         IGCM_config_Analyse_PeriodLength 
    404  
    405         eval PeriodDateBegin=${DateBegin} > /dev/null 2>&1 
    406         PeriodDateEnd=$( IGCM_date_AddDaysToGregorianDate ${DateBegin} $(( ${PeriodLengthInDays} - 1 )) ) 
    407         eval CumulPeriod=1 > /dev/null 2>&1 
    408  
    409         #=================================================# 
    410         #              Write updated run.card             # 
    411         #=================================================# 
    412  
    413         #Correct run.card Configuration for this period 
    414         IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin ${PeriodDateBegin} 
    415         IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd ${PeriodDateEnd} 
    416         IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod ${CumulPeriod} 
    417         if [ X$( grep "SubmitPath" ${SUBMIT_DIR}/run.card ) != X ] ; then 
    418             IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration SubmitPath ${SUBMIT_DIR} 
    419         fi 
    420  
    421         IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "Running" 
    422   
     433  IGCM_debug_PushStack "IGCM_config_PeriodStart" 
     434 
     435  echo 
     436  IGCM_debug_Print 1 "IGCM_config_PeriodStart" 
     437  echo 
     438 
     439  if ( ${FirstInitialize} ) ; then 
     440    #================================================# 
     441    #         Initialize date/period information     # 
     442    #================================================# 
     443 
     444    IGCM_date_GetYearMonthDay $DateBegin year month day 
     445    IGCM_config_Analyse_PeriodLength 
     446 
     447    eval PeriodDateBegin=${DateBegin} > /dev/null 2>&1 
     448    PeriodDateEnd=$( IGCM_date_AddDaysToGregorianDate ${DateBegin} $(( ${PeriodLengthInDays} - 1 )) ) 
     449    eval CumulPeriod=1 > /dev/null 2>&1 
     450 
     451    #=================================================# 
     452    #              Write updated run.card             # 
     453    #=================================================# 
     454 
     455    #Correct run.card Configuration for this period 
     456    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin ${PeriodDateBegin} 
     457    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd ${PeriodDateEnd} 
     458    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod ${CumulPeriod} 
     459    if [ X$( grep "SubmitPath" ${SUBMIT_DIR}/run.card ) != X ] ; then 
     460      IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration SubmitPath ${SUBMIT_DIR} 
     461    fi 
     462 
     463    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "Running" 
     464     
     465  else 
     466    #================================================# 
     467    #         The file run.card allready exist       # 
     468    #================================================# 
     469 
     470    #Test state of run in run.card 
     471    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodState 
     472    if ( [ ${run_Configuration_PeriodState} != "Running" ] && [ ${run_Configuration_PeriodState} != "OnQueue" ] && [ ${run_Configuration_PeriodState} != "Continue" ] ) ; then 
     473      echo  
     474      IGCM_debug_Print 1 "!! Error in run.card with PeriodState : " ${run_Configuration_PeriodState} "!!" 
     475      IGCM_debug_Print 1 "Try running ${libIGCM}/clean_month.job to fix this" 
     476      echo 
     477      IGCM_debug_Exit 
     478      IGCM_debug_Verif_Exit 
     479    fi 
     480 
     481    #===================================# 
     482    #        Read updated run.card      # 
     483    #===================================# 
     484 
     485    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration OldPrefix 
     486    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin 
     487    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd 
     488    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod 
     489 
     490    PeriodDateBegin=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateBegin} ) 
     491    PeriodDateEnd=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateEnd} ) 
     492    eval CumulPeriod="${run_Configuration_CumulPeriod}" > /dev/null 2>&1 
     493 
     494    LastPeriodDateEnd=$( echo ${run_Configuration_OldPrefix} | sed -e "s/${config_UserChoices_JobName}_//" ) 
     495 
     496    typeset LastDate 
     497    set +A LastDate -- $( echo ${LastPeriodDateEnd} | sed -e "s/\([0-9]\{${dY}\}\)\([0-9]\{2\}\)\([0-9]\{2\}\)/\1 \2 \3/" ) 
     498    LastYearDateEnd=${LastDate[0]} 
     499    LastMonthDateEnd=${LastDate[1]} 
     500    LastDayDateEnd=${LastDate[2]} 
     501 
     502    if [ ${Period} = 1 ]; then 
     503      # save last Job output 
     504      typeset LastPeriod iLastPeriod Last_Script_Output_Name 
     505      (( LastPeriod=CumulPeriod-PeriodNb )) 
     506      iLastPeriod=$( printf "%06d" ${LastPeriod} ) 
     507      Last_Script_Output_Name="${Script_Output_Prefix}_${config_UserChoices_JobName}.${iLastPeriod}" 
     508      Last_run_card="run.card.${iLastPeriod}" 
     509      #eval ls -l ${SUBMIT_DIR}/${Last_Script_Output_Name} 
     510      #eval IGCM_sys_Put_Out ${SUBMIT_DIR}/${Last_Script_Output_Name} ${R_BUF_KSH}/${Last_Script_Output_Name} > /dev/null 2>&1 
     511      IGCM_debug_Print 2 "Try to save previous ksh job output" 
     512      IGCM_sys_Cd ${SUBMIT_DIR}/ 
     513      IGCM_sys_PutBuffer_Out ${Last_Script_Output_Name} ${R_BUF_KSH}/${Last_Script_Output_Name}.$$ rw 
     514 
     515      IGCM_card_CheckConflict run.card 
     516      IGCM_sys_PutBuffer_Out ${SUBMIT_DIR}/run.card ${R_BUF_KSH}/${Last_run_card}.$$ rw 
     517 
     518      IGCM_sys_Cd ${RUN_DIR} 
    423519    else 
    424         #================================================# 
    425         #         The file run.card allready exist       # 
    426         #================================================# 
    427  
    428         #Test state of run in run.card 
    429         IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodState 
    430         if ( [ ${run_Configuration_PeriodState} != "Running" ] && [ ${run_Configuration_PeriodState} != "OnQueue" ] && [ ${run_Configuration_PeriodState} != "Continue" ] ) ; then 
    431             echo  
    432             IGCM_debug_Print 1 "!! Error in run.card with PeriodState : " ${run_Configuration_PeriodState} "!!" 
    433             IGCM_debug_Print 1 "Try running ${libIGCM}/clean_month.job to fix this" 
    434             echo 
    435             IGCM_debug_Exit 
    436             IGCM_debug_Verif_Exit 
    437         fi 
    438  
    439         #===================================# 
    440         #        Read updated run.card      # 
    441         #===================================# 
    442  
    443         IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration OldPrefix 
    444         IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin 
    445         IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd 
    446         IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod 
    447  
    448         PeriodDateBegin=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateBegin} ) 
    449         PeriodDateEnd=$( IGCM_date_ConvertFormatToGregorian ${run_Configuration_PeriodDateEnd} ) 
    450         eval CumulPeriod="${run_Configuration_CumulPeriod}" > /dev/null 2>&1 
    451  
    452         LastPeriodDateEnd=$( echo ${run_Configuration_OldPrefix} | sed -e "s/${config_UserChoices_JobName}_//" ) 
    453  
    454         typeset LastDate 
    455         set +A LastDate -- $( echo ${LastPeriodDateEnd} | sed -e "s/\([0-9]\{${dY}\}\)\([0-9]\{2\}\)\([0-9]\{2\}\)/\1 \2 \3/" ) 
    456         LastYearDateEnd=${LastDate[0]} 
    457         LastMonthDateEnd=${LastDate[1]} 
    458         LastDayDateEnd=${LastDate[2]} 
    459  
    460         if [ ${Period} = 1 ]; then 
    461            # save last Job output 
    462             typeset LastPeriod iLastPeriod Last_Script_Output_Name 
    463             (( LastPeriod=CumulPeriod-PeriodNb )) 
    464             iLastPeriod=$( printf "%06d" ${LastPeriod} ) 
    465             Last_Script_Output_Name="${Script_Output_Prefix}_${config_UserChoices_JobName}.${iLastPeriod}" 
    466             Last_run_card="run.card.${iLastPeriod}" 
    467             #eval ls -l ${SUBMIT_DIR}/${Last_Script_Output_Name} 
    468             #eval IGCM_sys_Put_Out ${SUBMIT_DIR}/${Last_Script_Output_Name} ${R_OUT_KSH}/${Last_Script_Output_Name} > /dev/null 2>&1 
    469             IGCM_debug_Print 2 "Try to save previous ksh job output" 
    470             IGCM_sys_Cd ${SUBMIT_DIR}/ 
    471             IGCM_sys_Put_Out ${Last_Script_Output_Name} ${R_OUT_KSH}/${Last_Script_Output_Name}.$$ rw 
    472  
    473             IGCM_card_CheckConflict run.card 
    474             IGCM_sys_Put_Out ${SUBMIT_DIR}/run.card ${R_OUT_KSH}/${Last_run_card}.$$ rw 
    475  
    476             IGCM_sys_Cd ${RUN_DIR} 
    477         else 
    478             unset FileToBeDeleted 
    479         fi 
    480  
    481         IGCM_date_GetYearMonth $PeriodDateBegin year month 
    482         year_m1=$(( year - 1 )) 
    483         year_p1=$(( year + 1 ))  
    484         IGCM_config_Analyse_PeriodLength 
    485  
    486         IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "Running" 
    487  
    488     fi     
    489     OldPrefix=${config_UserChoices_JobName}_${PeriodDateEnd} 
    490    
    491     #===================================================================# 
    492     # Prepare variables available for ${COMP}.card and ${COMP}.driver   # 
    493     #             But available to any son functions                    # 
    494     #===================================================================# 
    495  
    496     # Period Length In Days between DateBegin and DateCurrent (at end of period == PeriodDateEnd !) 
    497     (( SimulationLengthInDays = $( IGCM_date_DaysBetweenGregorianDate ${PeriodDateEnd} ${DateBegin} ) + 1 )) 
    498  
    499     # Debug Print : 
    500     IGCM_debug_Print 1 "IGCM_config_PeriodStart : Before Execution" 
    501     IGCM_debug_Print 1 "Year of simulation      : ${year}" 
    502     IGCM_debug_Print 1 "Month of simulation     : ${month}" 
    503     IGCM_debug_Print 1 "PeriodLengthInDays      : ${PeriodLengthInDays}" 
    504     IGCM_debug_Print 1 "PeriodDateBegin         : ${PeriodDateBegin}" 
    505     IGCM_debug_Print 1 "PeriodDateEnd           : ${PeriodDateEnd}" 
    506     IGCM_debug_Print 1 "SimulationLengthInDays  : ${SimulationLengthInDays}" 
    507     IGCM_debug_Print 1 "ExperienceLengthInDays  : ${ExperienceLengthInDays}" 
    508  
    509     #================================================================# 
    510     #         Prepare variables available for comp_finalyze          # 
    511     #================================================================# 
    512  
    513     # Period for save files 
    514     eval DatesPeriod=${PeriodDateBegin}_${PeriodDateEnd} > /dev/null 2>&1 
    515  
    516     # Prefix for save files of this period 
    517     eval PREFIX=${config_UserChoices_JobName}_${DatesPeriod}  > /dev/null 2>&1 
    518  
    519     # List of files that will be deleted in RUN_DIR after run 
    520     [ -f stack ] && FileToBeDeleted[0]="stack" 
    521  
    522     # Test if the same run as already been saved : 
    523     if [ X${JobType} = XRUN ] ; then 
    524         if [ ${DRYRUN} -le 0 ] ; then 
    525             if ( IGCM_sys_TestFileArchive ${R_OUT_KSH}/${PREFIX}_${Exe_Output} ) ; then 
    526                 IGCM_debug_Exit "IGCM_config_PeriodStart" "You are currently RErunning an old job." 
    527                 IGCM_debug_Print 1 "Because of readonly permissions, you can't RErun a job when saved files" 
    528                 IGCM_debug_Print 1 " are still in the ARCHIVE directory. You must deleted those files, or " 
    529                 IGCM_debug_Print 1 " the whole ${R_SAVE} tree. See clean_month.job in ${libIGCM} directory." 
    530                 IGCM_debug_Print 1 " This exit has been initiated because at least ${R_OUT_KSH}/${PREFIX}_${Exe_Output} exists." 
    531                 IGCM_debug_Verif_Exit 
    532             fi 
    533         fi 
     520      unset FileToBeDeleted 
     521    fi 
     522 
     523    IGCM_date_GetYearMonthDay $PeriodDateBegin year month day 
     524    IGCM_config_Analyse_PeriodLength 
     525 
     526    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "Running" 
     527 
     528  fi     
     529  OldPrefix=${config_UserChoices_JobName}_${PeriodDateEnd} 
     530 
     531  # BEGIN: SHOULD GO IN A FUNCTION FROM libIGCM_date.ksh 
     532  # Compute year_m1 and year_p1 (year minus 1Y and year plus 1Y) 
     533  year_m1=$(( year - 1 )) 
     534  year_p1=$(( year + 1 ))        
     535  # Compute month_m1 (month minus 1M) 
     536  # Compute yyyymm_m1 (yyyymm minus 1M) 
     537  month_m1=$(( month - 1 )) 
     538  if [ ${month_m1} = 0 ]; then 
     539    month_m1=12 
     540    yyyymm_m1=${year_m1}12 
     541  elif [ ${month_m1} -le 9 ]; then 
     542    month_m1=0${month_m1} 
     543    yyyymm_m1=${year}${month_m1} 
     544  else 
     545    yyyymm_m1=${year}${month_m1} 
     546  fi 
     547  # Compute month_p1 (month plus 1M) 
     548  # Compute yyyymm_p1 (yyyymm plus 1M) 
     549  month_p1=$(( month + 1 )) 
     550  if [ ${month_p1} = 13 ]; then 
     551    month_p1=01 
     552    yyyymm_p1=${year_p1}01 
     553  elif [ ${month_p1} -le 9 ]; then 
     554    month_p1=0${month_p1} 
     555    yyyymm_p1=${year}${month_p1} 
     556  else 
     557    yyyymm_p1=${year}${month_p1} 
     558  fi 
     559  #IGCM_debug_Print 1 "jg 1 month_m1 = ${month_m1} month_p1 = ${month_p1} " 
     560  #IGCM_debug_Print 1 "jg 1 calculate yyyymm_m1 = ${yyyymm_m1} " 
     561  #IGCM_debug_Print 1 "jg 1 calculate yyyymm_p1 = ${yyyymm_p1} " 
     562 
     563  # END: SHOULD GO IN A FUNCTION FROM libIGCM_date.ksh 
     564 
     565  #===================================================================# 
     566  # Prepare variables available for ${COMP}.card and ${COMP}.driver   # 
     567  #             But available to any son functions                    # 
     568  #===================================================================# 
     569 
     570  # Period Length In Days between DateBegin and DateCurrent (at end of period == PeriodDateEnd !) 
     571  (( SimulationLengthInDays = $( IGCM_date_DaysBetweenGregorianDate ${PeriodDateEnd} ${DateBegin} ) + 1 )) 
     572 
     573  # Debug Print : 
     574  IGCM_debug_Print 1 "IGCM_config_PeriodStart : Before Execution" 
     575  IGCM_debug_Print 1 "Year of simulation      : ${year}" 
     576  IGCM_debug_Print 1 "Month of simulation     : ${month}" 
     577  IGCM_debug_Print 1 "PeriodLengthInDays      : ${PeriodLengthInDays}" 
     578  IGCM_debug_Print 1 "PeriodDateBegin         : ${PeriodDateBegin}" 
     579  IGCM_debug_Print 1 "PeriodDateEnd           : ${PeriodDateEnd}" 
     580  IGCM_debug_Print 1 "SimulationLengthInDays  : ${SimulationLengthInDays}" 
     581  IGCM_debug_Print 1 "ExperienceLengthInDays  : ${ExperienceLengthInDays}" 
     582 
     583  #================================================================# 
     584  #         Prepare variables available for comp_finalyze          # 
     585  #================================================================# 
     586 
     587  # Period for save files 
     588  eval DatesPeriod=${PeriodDateBegin}_${PeriodDateEnd} > /dev/null 2>&1 
     589 
     590  # Prefix for save files of this period 
     591  eval PREFIX=${config_UserChoices_JobName}_${DatesPeriod}  > /dev/null 2>&1 
     592 
     593  # List of files that will be deleted in RUN_DIR after run 
     594  [ -f stack ] && FileToBeDeleted[0]="stack" 
     595 
     596  # Test if the same run as already been saved : 
     597  if [ X${JobType} = XRUN ] ; then 
     598    if [ ${DRYRUN} -le 0 ] ; then 
     599      if ( IGCM_sys_TestFileBuffer ${R_BUF_KSH}/${PREFIX}_${Exe_Output} ) ; then 
     600        IGCM_debug_Exit "IGCM_config_PeriodStart" "You are currently RErunning an old job." 
     601        IGCM_debug_Print 1 "Because of readonly permissions, you can't RErun a job when saved files" 
     602        IGCM_debug_Print 1 " are still in the ARCHIVE directory. You must deleted those files, or " 
     603        IGCM_debug_Print 1 " the whole ${R_SAVE} tree. See clean_month.job in ${libIGCM} directory." 
     604        IGCM_debug_Print 1 " This exit has been initiated because at least ${R_BUF_KSH}/${PREFIX}_${Exe_Output} exists." 
     605        IGCM_debug_Verif_Exit 
     606      fi 
     607    fi 
     608  else 
     609    if ( IGCM_sys_TestFileBuffer ${R_BUF_KSH}/${PREFIX}_${Exe_Output} ) ; then 
     610      IGCM_debug_Print 1 "IGCM_config_PeriodStart" "RErun an old job. Allowed in DEBUG or DEV mode." 
     611    fi 
     612  fi 
     613 
     614  typeset ExeNameIn ExeNameFirst CompNameFirst 
     615  typeset comp i 
     616  typeset tempvar tempvarMPI tempvarNOD NbElts j NbExec 
     617 
     618  (( PROCESSUS_NUMBER = 0 )) 
     619  (( i=0 )) 
     620  (( NbExec=0 )) 
     621 
     622  OK_PARA_MPI=false 
     623  OK_PARA_OMP=false 
     624  OK_PARA_NOD=false 
     625  OK_PARA_MPMD=false 
     626 
     627  for comp in ${config_ListOfComponents[*]} ; do 
     628 
     629    IGCM_debug_Print 1 ${comp} 
     630 
     631    eval ExeNameIn=\${config_Executable_${comp}[0]} 
     632 
     633    # NO order in config.card for parallelized values !  
     634    # just use suffix : MPI , OMP and NOD (for number of NODes.) 
     635 
     636    # NOD is the number of NODes allocated 
     637    eval ${comp}_PROC_NOD=0 
     638 
     639    # MPI is the number of MPI processus per nodes 
     640    eval ${comp}_PROC_MPI=0 
     641 
     642    # OMP is the number of OpenMP threads per MPI processus 
     643    eval ${comp}_PROC_OMP=0 
     644         
     645    # Only if we really have an executable for the component : 
     646    if [ X${ExeNameIn} != X\"\" ] ; then 
     647 
     648      # Keep the first executable found and the first CompName 
     649      ExeNameFirst=${ExeNameIn} 
     650      CompNameFirst=${comp} 
     651 
     652      # Are we a second executable? 
     653      (( NbExec = NbExec + 1 )) 
     654 
     655      # set 1 MPI task, 1 OpenMP thread and 1 node as default 
     656      eval ${comp}_PROC_MPI=1 
     657      eval ${comp}_PROC_OMP=1 
     658      eval ${comp}_PROC_NOD=1 
     659 
     660      eval NbElts=\${#config_Executable_${comp}[@]} 
     661 
     662      if [ ${NbElts} -ge 2 ] ; then 
     663        (( j = 2 )) 
     664 
     665        while [ $j -lt ${NbElts} ] ; do  
     666          eval tempvar=\${config_Executable_${comp}[${j}]} 
     667 
     668          if [ X${tempvar} == X ] ; then 
     669            echo "Error reading MPI/OMP parameters !!!"  
     670            echo "Check your config.card."  
     671            exit 1 
     672          fi 
     673 
     674          eval IGCM_debug_Print 2 ${tempvar} 
     675 
     676          case ${tempvar} in 
     677            *[mM][pP][iI]*) 
     678               # Read MPI parameter for composante 
     679               eval ${comp}_PROC_MPI=$( echo ${tempvar} | tr '[a-z]' '[A-Z]' | sed -e "s/MPI//" ) 
     680               OK_PARA_MPI=true;; 
     681            *[oO][mM][pP]*) 
     682               # Read OMP parameter for composante 
     683               eval ${comp}_PROC_OMP=$( echo ${tempvar} | tr '[a-z]' '[A-Z]' | sed -e "s/OMP//" ) 
     684               OK_PARA_OMP=true;; 
     685            *[nN][oO][dD]*) 
     686               # Read NOD (NumBer of Nodes) parameter for composante 
     687               eval ${comp}_PROC_NOD=$( echo ${tempvar} | tr '[a-z]' '[A-Z]' | sed -e "s/NOD//" ) 
     688               OK_PARA_NOD=true 
     689               OK_PARA_MPI=true;; 
     690          esac 
     691 
     692          (( j = j + 1 )) 
     693        done 
     694 
     695      fi 
     696 
     697      eval tempvarMPI=\${${comp}_PROC_MPI} 
     698      eval tempvarNOD=\${${comp}_PROC_NOD} 
     699      eval tempvarOMP=\${${comp}_PROC_OMP} 
     700 
     701      (( PROCESSUS_NUMBER = PROCESSUS_NUMBER + tempvarMPI * tempvarNOD * tempvarOMP )) 
     702 
     703    fi 
     704 
     705    (( i=i+1 )) 
     706  done 
     707 
     708  # set MPMD mode if more than 2 executable names. 
     709  [ ${NbExec} -ge 2 ] && OK_PARA_MPMD=true 
     710 
     711  # Verification of BATCH_NUM_PROC_TOT total number of processors set in job header. 
     712  if [ X${BATCH_NUM_PROC_TOT} != X ] ; then 
     713    # BATCH_NUM_PROC_TOT is set 
     714    if ( ${OK_PARA_MPI} ) ; then 
     715      IGCM_debug_Print 1 "MPI/OMP/NOD found into config.card and BATCH_NUM_PROC_TOT = ${BATCH_NUM_PROC_TOT} " 
    534716    else 
    535         if ( IGCM_sys_TestFileArchive ${R_OUT_KSH}/${PREFIX}_${Exe_Output} ) ; then 
    536             IGCM_debug_Print 1 "IGCM_config_PeriodStart" "RErun an old job. Allowed in DEBUG or DEV mode." 
    537         fi 
    538     fi 
    539  
    540     typeset ExeNameIn ExeNameFirst CompNameFirst 
    541     typeset comp i 
    542     typeset tempvar tempvarMPI tempvarNOD NbElts j NbExec 
    543  
    544     (( PROCESSUS_NUMBER = 0 )) 
    545     (( i=0 )) 
    546     (( NbExec=0 )) 
    547  
    548     OK_PARA_MPI=false 
    549     OK_PARA_OMP=false 
    550     OK_PARA_NOD=false 
    551     OK_PARA_MPMD=false 
    552  
    553     for comp in ${config_ListOfComponents[*]} ; do 
    554  
    555         IGCM_debug_Print 1 ${comp} 
    556  
    557         eval ExeNameIn=\${config_Executable_${comp}[0]} 
    558  
    559         # NO order in config.card for parallelized values !  
    560         # just use suffix : MPI , OMP and NOD (for number of NODes.) 
    561  
    562         # NOD is the number of NODes allocated 
    563         eval ${comp}_PROC_NOD=0 
    564  
    565         # MPI is the number of MPI processus per nodes 
    566         eval ${comp}_PROC_MPI=0 
    567  
    568         # OMP is the number of OpenMP threads per MPI processus 
    569         eval ${comp}_PROC_OMP=0 
    570          
    571         # Only if we really have an executable for the component : 
    572         if [ X${ExeNameIn} != X\"\" ] ; then 
    573  
    574             # Keep the first executable found and the first CompName 
    575             ExeNameFirst=${ExeNameIn} 
    576             CompNameFirst=${comp} 
    577  
    578             # Are we a second executable? 
    579             (( NbExec = NbExec + 1 )) 
    580  
    581             # set 1 MPI task, 1 OpenMP thread and 1 node as default 
    582             eval ${comp}_PROC_MPI=1 
    583             eval ${comp}_PROC_OMP=1 
    584             eval ${comp}_PROC_NOD=1 
    585  
    586             eval NbElts=\${#config_Executable_${comp}[@]} 
    587  
    588             if [ ${NbElts} -ge 2 ] ; then 
    589                 (( j = 2 )) 
    590  
    591                 while [ $j -lt ${NbElts} ] ; do  
    592                     eval tempvar=\${config_Executable_${comp}[${j}]} 
    593  
    594                     echo  
    595 #MM BUG impossible ?! 
    596                     if [ X${tempvar} == X ] ; then 
    597                         echo "Error reading MPI/OMP parameters !!!"  
    598                         echo "Check your config.card."  
    599                     # MM : A  enlever : 
    600                         exit 1 
    601                         #break 
    602                     fi 
    603  
    604                     eval IGCM_debug_Print 2 ${tempvar} 
    605  
    606                     case ${tempvar} in 
    607                         *[mM][pP][iI]*) 
    608                             # Read MPI parameter for composante 
    609                             eval ${comp}_PROC_MPI=$( echo ${tempvar} | tr '[a-z]' '[A-Z]' | sed -e "s/MPI//" ) 
    610                             OK_PARA_MPI=true;; 
    611                         *[oO][mM][pP]*) 
    612                             # Read OMP parameter for composante 
    613                             eval ${comp}_PROC_OMP=$( echo ${tempvar} | tr '[a-z]' '[A-Z]' | sed -e "s/OMP//" ) 
    614                             OK_PARA_OMP=true;; 
    615                         *[nN][oO][dD]*) 
    616                             # Read NOD (NumBer of Nodes) parameter for composante 
    617                             eval ${comp}_PROC_NOD=$( echo ${tempvar} | tr '[a-z]' '[A-Z]' | sed -e "s/NOD//" ) 
    618                             OK_PARA_NOD=true 
    619                             OK_PARA_MPI=true;; 
    620                     esac 
    621  
    622                     (( j = j + 1 )) 
    623                 done 
    624  
    625             fi 
    626  
    627             eval tempvarMPI=\${${comp}_PROC_MPI} 
    628             eval tempvarNOD=\${${comp}_PROC_NOD} 
    629             eval tempvarOMP=\${${comp}_PROC_OMP} 
    630  
    631             (( PROCESSUS_NUMBER = PROCESSUS_NUMBER + tempvarMPI * tempvarNOD * tempvarOMP )) 
    632  
    633         fi 
    634  
    635         (( i=i+1 )) 
    636     done 
    637  
    638     # set MPMD mode if more than 2 executable names. 
    639     [ ${NbExec} -ge 2 ] && OK_PARA_MPMD=true 
    640  
    641     # Verification of BATCH_NUM_PROC_TOT total number of processors set in job header. 
    642     if [ X${BATCH_NUM_PROC_TOT} != X ] ; then 
    643         # BATCH_NUM_PROC_TOT is set 
    644         if ( ${OK_PARA_MPI} ) ; then 
    645             IGCM_debug_Print 1 "MPI/OMP/NOD fund into config.card and BATCH_NUM_PROC_TOT = ${BATCH_NUM_PROC_TOT} " 
    646         else 
    647             # with previous method. 
    648             if [ ${BATCH_NUM_PROC_TOT} -gt 1 ] ; then 
    649                 # with more than 1 proc 
    650                 if ( ${OK_PARA_MPMD} ) ; then 
    651                      # with MPMD ie CPL/oasis method 
    652                      echo "We will use default number of MPI tasks for this machine : " 
    653                      echo "${DEFAULT_NUM_PROC_OCE} for OCE; " 
    654                      echo "${DEFAULT_NUM_PROC_CPL} for CPL; " 
    655                      echo "${DEFAULT_NUM_PROC_ATM} for ATM; " 
    656                      echo "${DEFAULT_NUM_PROC_TOTAL} for the total number of processors; " 
    657                      OK_PARA_MPI=true 
    658                      CPL_PROC_MPI=${DEFAULT_NUM_PROC_CPL} 
    659                      OCE_PROC_MPI=${DEFAULT_NUM_PROC_OCE} 
    660                      ATM_PROC_MPI=${DEFAULT_NUM_PROC_ATM} 
    661                      NUM_PROC_CPL=${DEFAULT_NUM_PROC_CPL} # for backward compatibility 
    662                      NUM_PROC_OCE=${DEFAULT_NUM_PROC_OCE} # for backward compatibility 
    663                      NUM_PROC_ATM=${DEFAULT_NUM_PROC_ATM} # for backward compatibility 
    664                      PROCESSUS_NUMBER=${DEFAULT_NUM_PROC_TOTAL} 
    665                 else 
    666                      # with have only one executable 
    667                      echo "We will use ${BATCH_NUM_PROC_TOT} MPI tasks for ${CompNameFirst} : ${config_Executable_Name} " 
    668                      OK_PARA_MPI=true 
    669                      eval ${CompNameFirst}_PROC_MPI=${BATCH_NUM_PROC_TOT} 
    670                      PROCESSUS_NUMBER=${BATCH_NUM_PROC_TOT} 
    671                 fi 
    672             else  
    673                 PROCESSUS_NUMBER=1 
    674             fi 
    675         fi 
    676         # Verification with PBS parameter 
    677         if [ ${BATCH_NUM_PROC_TOT} -ne ${PROCESSUS_NUMBER} ] ; then 
    678             echo "Warning with parallelization parameters !" 
    679             echo "Job header variable BATCH_NUM_PROC_TOT = ${BATCH_NUM_PROC_TOT} " 
    680             echo "is the total number of _processors_ reserved." 
    681             echo "It is not equal to the sum of _processus_  = ${PROCESSUS_NUMBER}." 
    682             echo "We stop now." 
    683             exit 1 
     717      # with previous method. 
     718      if [ ${BATCH_NUM_PROC_TOT} -gt 1 ] ; then 
     719        # with more than 1 proc 
     720        if ( ${OK_PARA_MPMD} ) ; then 
     721          # with MPMD ie CPL/oasis method 
     722          echo "We will use default number of MPI tasks for this machine : " 
     723          echo "${DEFAULT_NUM_PROC_OCE} for OCE; " 
     724          echo "${DEFAULT_NUM_PROC_CPL} for CPL; " 
     725          echo "${DEFAULT_NUM_PROC_ATM} for ATM; " 
     726          echo "${DEFAULT_NUM_PROC_TOTAL} for the total number of processors; " 
     727          OK_PARA_MPI=true 
     728          CPL_PROC_MPI=${DEFAULT_NUM_PROC_CPL} 
     729          OCE_PROC_MPI=${DEFAULT_NUM_PROC_OCE} 
     730          ATM_PROC_MPI=${DEFAULT_NUM_PROC_ATM} 
     731          NUM_PROC_CPL=${DEFAULT_NUM_PROC_CPL} # for backward compatibility 
     732          NUM_PROC_OCE=${DEFAULT_NUM_PROC_OCE} # for backward compatibility 
     733          NUM_PROC_ATM=${DEFAULT_NUM_PROC_ATM} # for backward compatibility 
     734          PROCESSUS_NUMBER=${DEFAULT_NUM_PROC_TOTAL} 
     735        else 
     736          # with have only one executable 
     737          echo "We will use ${BATCH_NUM_PROC_TOT} MPI tasks for ${CompNameFirst} : ${config_Executable_Name} " 
     738          OK_PARA_MPI=true 
     739          eval ${CompNameFirst}_PROC_MPI=${BATCH_NUM_PROC_TOT} 
     740          PROCESSUS_NUMBER=${BATCH_NUM_PROC_TOT} 
    684741        fi 
    685  
    686     else # BATCH_NUM_PROC_TOT="" 
    687         if ( ${OK_PARA_MPI} ) ; then 
    688             echo "You have not given a value of ${BATCH_NUM_PROC_TOT} processors," 
    689             echo "but you have filled the parallel parameter in config->Executable->list." 
    690             echo "Please add BATCH_NUM_PROC_TOT variable in job header." 
    691             echo "We stop now." 
    692             exit 1 
    693         else 
    694         # sequential case ! 
    695             if [ ${PROCESSUS_NUMBER} -eq 0 ] ; then 
    696                (( PROCESSUS_NUMBER = 1 )) 
    697                echo "PROCESSUS_NUMBER is all 0 (sequential use of old definition in config->Executable->list)." 
    698                echo "We set it to 1." 
    699             fi 
    700         fi 
    701     fi 
    702  
    703     IGCM_debug_Print 1 "MPI/OMP treatment PROCESSUS_NUMBER = ${PROCESSUS_NUMBER}" 
    704  
    705 #     if ( ${OK_PARA_MPI} || ${OK_PARA_OMP} || ${OK_PARA_NOD} ) ; then 
    706     IGCM_sys_build_execution_scripts 
    707 #     fi 
    708  
    709     ExecutionFail=false 
    710  
    711     IGCM_debug_PopStack "IGCM_config_PeriodStart" 
     742      else  
     743        PROCESSUS_NUMBER=1 
     744      fi 
     745    fi 
     746    # Verification with PBS parameter 
     747    if [ ${BATCH_NUM_PROC_TOT} -ne ${PROCESSUS_NUMBER} ] ; then 
     748      echo "Warning with parallelization parameters !" 
     749      echo "Job header variable BATCH_NUM_PROC_TOT = ${BATCH_NUM_PROC_TOT} " 
     750      echo "is the total number of _processors_ reserved." 
     751      echo "It is not equal to the sum of _processus_  = ${PROCESSUS_NUMBER}." 
     752      echo "We stop now." 
     753      exit 1 
     754    fi 
     755  else # BATCH_NUM_PROC_TOT="" 
     756    if ( ${OK_PARA_MPI} ) ; then 
     757      echo "You have not given a value of ${BATCH_NUM_PROC_TOT} processors," 
     758      echo "but you have filled the parallel parameter in config->Executable->list." 
     759      echo "Please add BATCH_NUM_PROC_TOT variable in job header." 
     760      echo "We stop now." 
     761      exit 1 
     762    else 
     763      # sequential case ! 
     764      if [ ${PROCESSUS_NUMBER} -eq 0 ] ; then 
     765        (( PROCESSUS_NUMBER = 1 )) 
     766        echo "PROCESSUS_NUMBER is all 0 (sequential use of old definition in config->Executable->list)." 
     767        echo "We set it to 1." 
     768      fi 
     769    fi 
     770  fi 
     771 
     772  IGCM_debug_Print 1 "MPI/OMP treatment PROCESSUS_NUMBER = ${PROCESSUS_NUMBER}" 
     773 
     774  IGCM_sys_build_execution_scripts 
     775 
     776  ExecutionFail=false 
     777 
     778  IGCM_debug_PopStack "IGCM_config_PeriodStart" 
     779} 
     780 
     781#=================================== 
     782function IGCM_config_SaveSourceModifications 
     783{ 
     784  IGCM_debug_PushStack "IGCM_config_SaveSourceModifications" 
     785 
     786  typeset ExeOutDateMax listVarEnv 
     787  ExeOutDateMax=$1 
     788 
     789  listVarEnv="ExeOutDateMax,R_OUT_EXE,PREFIX,SUBMIT_DIR" 
     790  IGCM_sys_RshMaster "\ 
     791    . ${libIGCM}/libIGCM_sys/libIGCM_sys.ksh; \ 
     792    export ExeOutDateMax=${ExeOutDateMax};\ 
     793    export R_OUT_EXE=${R_OUT_EXE};\ 
     794    export PREFIX=${PREFIX};\ 
     795    export SUBMIT_DIR=${SUBMIT_DIR};\ 
     796    export listVarEnv=${listVarEnv};\ 
     797    Script_Output=out_SaveSourceModifications;\ 
     798    IGCM_sys_Qsub ${libIGCM}/SaveSourceModifications.job ${ExeOutDateMax} ${R_OUT_EXE} ${PREFIX} ${SUBMIT_DIR}" 
     799 
     800  IGCM_debug_PopStack "IGCM_config_SaveSourceModifications" 
    712801} 
    713802 
     
    715804function IGCM_config_PeriodEnd 
    716805{ 
    717     IGCM_debug_PushStack "IGCM_config_PeriodEnd" 
    718  
    719     echo 
    720     IGCM_debug_Print 1 "IGCM_config_PeriodEnd" 
    721     echo 
    722  
    723     #==================================# 
    724     #         Save Job output          # 
    725     #==================================# 
    726     IGCM_sys_Put_Out ${Exe_Output} ${R_OUT_KSH}/${PREFIX}_${Exe_Output} 
    727     eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${Exe_Output}" 
    728  
    729     IGCM_card_CheckConflict run.card 
    730     IGCM_sys_Put_Out ${SUBMIT_DIR}/run.card ${R_OUT_KSH}/run.card rw 
    731  
    732 if [ ${DRYRUN} -le 1 ] ; then 
     806  IGCM_debug_PushStack "IGCM_config_PeriodEnd" 
     807 
     808  echo 
     809  IGCM_debug_Print 1 "IGCM_config_PeriodEnd" 
     810  echo 
     811 
     812  #==================================# 
     813  #         Save Job output          # 
     814  #==================================# 
     815  IGCM_sys_PutBuffer_Out ${Exe_Output} ${R_BUF_KSH}/${PREFIX}_${Exe_Output} 
     816  eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${Exe_Output}" 
     817 
     818      IGCM_card_CheckConflict run.card 
     819      IGCM_sys_PutBuffer_Out ${SUBMIT_DIR}/run.card ${R_BUF_KSH}/run.card rw 
     820 
     821 
     822  if [ ${DRYRUN} -le 1 ] ; then 
    733823    IGCM_debug_Print 1 "Check components binary : size and creation date" 
    734824 
    735825    typeset LS_comp LS_bin ExeDate ExeCpuLog NextExeSize LastCompExeSize 
    736826    typeset comp i     
    737     typeset ExeNameIn ExeNameOut  
     827    typeset ExeNameIn ExeNameOut UpdateExe ExeSecDateMax 
    738828 
    739829    #==================================# 
     
    743833    (( i=0 )) 
    744834    if ( ${FirstInitialize} ) ; then 
    745         run_Log_LastExeSize="" 
    746         for comp in ${config_ListOfComponents[*]} ; do 
    747             run_Log_LastExeSize[$i]=0 
    748             (( i=i+1 )) 
    749         done 
     835      run_Log_LastExeSize="" 
     836      for comp in ${config_ListOfComponents[*]} ; do 
     837        run_Log_LastExeSize[$i]=0 
     838       (( i=i+1 )) 
     839      done 
    750840    else 
    751         IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/run.card Log LastExeSize 
     841      IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/run.card Log LastExeSize 
    752842    fi 
    753843    #==================================# 
     
    761851    NextExeSize="( " 
    762852    (( i=0 )) 
    763  
     853    UpdateExe=false 
     854    (( ExeSecDateMax = 0 )) 
    764855    for comp in ${config_ListOfComponents[*]} ; do 
    765856 
    766         IGCM_debug_Print 3 ${comp} 
    767  
    768         eval ExeNameIn=\${config_Executable_${comp}[0]} 
    769         eval ExeNameOut=\${config_Executable_${comp}[1]} 
    770         # Only if we really have an executable for the component : 
    771         if [ X${ExeNameIn} = X\"\" ] ; then 
    772             # If there is no exe file for this component 
    773             (( ExeSize=0 )) 
    774         else 
    775             eval LS_bin=${R_EXE}/${ExeNameIn} 
    776             IGCM_sys_FileSize ${LS_bin} ExeSize 
    777  
    778             set +A LS_comp -- $( LC_TIME=en_US ls -l ${LS_bin} ) 
    779             if [ X${ExeDate} = X ] ; then  
    780                 # First component exe date 
    781                 ExeDate=${comp}_${LS_comp[5]}_${LS_comp[6]} 
    782             else 
    783                 ExeDate=${ExeDate}-${comp}_${LS_comp[5]}_${LS_comp[6]} 
    784             fi 
    785             ExeDate=${ExeDate}_${LS_comp[7]} 
    786         fi 
    787  
    788         if [ ${i} -eq 0 ] ; then 
    789             # First component 
    790             NextExeSize="( "${ExeSize} 
    791         else 
    792             NextExeSize=${NextExeSize}", "${ExeSize} 
    793         fi 
    794         eval LastCompExeSize=${run_Log_LastExeSize[$i]} 
    795         (( i=i+1 )) 
    796  
    797         if [ ${ExeSize} -ne ${LastCompExeSize} ] ; then 
    798             if ( ${FirstInitialize} ) ; then 
    799                 IGCM_debug_Print 1 "Save first ${ExeNameIn} in ${R_OUT_EXE} !" 
    800             else 
    801                 IGCM_debug_Print 1 "${ExeNameIn} has changed in ${R_EXE} !" 
    802                 IGCM_debug_Print 1 "Save latest ${ExeNameIn} in ${R_OUT_EXE} !" 
    803                 eval FileToBeDeleted[${#FileToBeDeleted[@]}]=${ExeNameOut} 
    804             fi 
    805             eval IGCM_sys_Put_Out ${ExeNameOut} ${R_OUT_EXE}/${PREFIX}_${ExeNameIn} rw 
    806         fi 
     857      IGCM_debug_Print 3 ${comp} 
     858 
     859      eval ExeNameIn=\${config_Executable_${comp}[0]} 
     860      eval ExeNameOut=\${config_Executable_${comp}[1]} 
     861      # Only if we really have an executable for the component : 
     862      if [ X${ExeNameIn} = X\"\" ] ; then 
     863        # If there is no exe file for this component 
     864        (( ExeSize=0 )) 
     865      else 
     866        eval LS_bin=${R_EXE}/${ExeNameIn} 
     867        IGCM_sys_FileSize ${LS_bin} ExeSize 
     868 
     869        set +A LS_comp -- $( LC_TIME=en_US ls -l ${LS_bin} ) 
     870        if [ X${ExeDate} = X ] ; then  
     871          # First component exe date 
     872          ExeDate=${comp}_${LS_comp[5]}_${LS_comp[6]} 
     873        else 
     874          ExeDate=${ExeDate}-${comp}_${LS_comp[5]}_${LS_comp[6]} 
     875        fi 
     876        ExeDate=${ExeDate}_${LS_comp[7]} 
     877      fi 
     878 
     879      if [ ${i} -eq 0 ] ; then 
     880        # First component 
     881        NextExeSize="( "${ExeSize} 
     882      else 
     883        NextExeSize=${NextExeSize}", "${ExeSize} 
     884      fi 
     885      eval LastCompExeSize=${run_Log_LastExeSize[$i]} 
     886      (( i=i+1 )) 
     887 
     888      if [ ${ExeSize} -ne ${LastCompExeSize} ] ; then 
     889        if ( ${FirstInitialize} ) ; then 
     890          IGCM_debug_Print 1 "Save first ${ExeNameIn} in ${R_OUT_EXE} !" 
     891        else 
     892          IGCM_debug_Print 1 "${ExeNameIn} has changed in ${R_EXE} !" 
     893          IGCM_debug_Print 1 "Save latest ${ExeNameIn} in ${R_OUT_EXE} !" 
     894          eval FileToBeDeleted[${#FileToBeDeleted[@]}]=${ExeNameOut} 
     895        fi 
     896        eval IGCM_sys_Put_Out ${ExeNameOut} ${R_OUT_EXE}/${PREFIX}_${ExeNameIn} rw 
     897        UpdateExe=true 
     898 
     899        IGCM_sys_GetDate_FichWork ${LS_bin} ExeSecDate 
     900        if [ $ExeSecDateMax -lt $ExeSecDate ] ; then 
     901          ExeSecDateMax=$ExeSecDate 
     902        fi 
     903      fi 
    807904    done 
     905 
     906# SD : switch off for now 
     907#      if ( ${UpdateExe} ) ; then 
     908#       echo "Launch SaveSourceModifications." 
     909#       IGCM_config_SaveSourceModifications ${ExeSecDateMax} 
     910#      fi 
    808911 
    809912    NextExeSize=${NextExeSize}" )" 
     
    814917    RET=$? 
    815918    if [ $RET -eq 0 ] ; then 
    816             # ExeCpuLog variable contents 5 fields 
    817             echo "${CumulPeriod} ${PeriodDateBegin} ${PeriodDateEnd} ${ExeCpuLog} ${ExeDate}" |   \ 
    818             gawk '{printf("# %11d | %15s | %15s | %19s | %19s | %15.5f | %15.5f | %15.5f | %s\n", \ 
    819                               $1,$2,$3,$4,$5,$6,$7,$8,$9)}' >> ${SUBMIT_DIR}/run.card 
     919      # ExeCpuLog variable contents 5 fields 
     920      echo "${CumulPeriod} ${PeriodDateBegin} ${PeriodDateEnd} ${ExeCpuLog} ${ExeDate}" |   \ 
     921      gawk '{printf("# %11d | %15s | %15s | %19s | %19s | %15.5f | %15.5f | %15.5f | %s\n", \ 
     922            $1,$2,$3,$4,$5,$6,$7,$8,$9)}' >> ${SUBMIT_DIR}/run.card 
    820923    fi 
    821924    eval FileToBeDeleted[${#FileToBeDeleted[@]}]="${Exe_Output}_tail.txt" 
    822 fi 
    823  
    824     # All was right ? no ? then we stop. 
    825     IGCM_debug_Verif_Exit 
    826  
    827     # If all was OK, we can delete all files not necessary for next Job 
     925  
     926  fi  
     927 
     928  # All was right ? no ? then we stop. 
     929  IGCM_debug_Verif_Exit 
     930 
     931  # If all was OK, we can delete all files not necessary for next Job 
     932  echo 
     933  IGCM_debug_Print 1 "Files that will be deleted before next period-run : " 
     934 
     935  if [ ${DRYRUN} -le 2 ] ; then 
     936    for f in ${FileToBeDeleted[@]} ; do [ -f ${f} ] && ls -la $f ; [ -f ${f} ] && rm -f $f ; done 
     937  else 
     938    echo ${FileToBeDeleted[@]} 
     939  fi 
     940 
     941  #=================================================# 
     942  #         Modification of libIGCM behaviour       # 
     943  #=================================================# 
     944 
     945  # To use this function, one must copy libIGCM.card from ${libIGCM} directory 
     946  # and put it in ${SUBMIT_DIR} directory. After modifications of ${SUBMIT_DIR}/libIGCM.card, 
     947  # variables define inside [UserChanges] will be modified for next Period of libIGCM main loop.  
     948  if [ -f ${SUBMIT_DIR}/libIGCM.card ] ; then 
    828949    echo 
    829     IGCM_debug_Print 1 "Files that will be deleted before next period-run : " 
    830  
    831     if [ ${DRYRUN} -le 2 ] ; then 
    832         for f in ${FileToBeDeleted[@]} ; do [ -f ${f} ] && ls -la $f ; [ -f ${f} ] && rm -f $f ; done 
    833     else 
    834         echo ${FileToBeDeleted[@]} 
    835     fi 
    836  
    837     #=================================================# 
    838     #         Modification of libIGCM behaviour       # 
    839     #=================================================# 
    840  
    841     # To use this function, one must copy libIGCM.card from ${libIGCM} directory 
    842     # and put it in ${SUBMIT_DIR} directory. After modifications of ${SUBMIT_DIR}/libIGCM.card, 
    843     # variables define inside [UserChanges] will be modified for next Period of libIGCM main loop.  
    844     if [ -f ${SUBMIT_DIR}/libIGCM.card ] ; then 
    845         echo 
    846         echo "########################################################################" 
    847         echo "!!!                 Modification of libIGCM behaviour                !!!" 
    848         echo 
    849  
    850         IGCM_debug_Print 1 "DefineArrayFromOption  : libIGCM_UserChanges in libIGCM.card" 
    851         IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/libIGCM.card UserChanges 
    852         IGCM_debug_Print 2 "libIGCM_UserChanges" ${libIGCM_UserChanges[*]} 
    853  
    854         # Special treatments for libIGCM internals 
    855         for option in ${libIGCM_UserChanges[*]} ; do 
    856             IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/libIGCM.card UserChanges ${option} 
    857  
    858             echo "We will change : ${option}." 
    859             eval echo "Previous value : " \${${option}} 
    860             eval echo "Change to : " \${libIGCM_UserChanges_${option}} 
    861              
    862             eval ${option}=\${libIGCM_UserChanges_${option}} 
    863  
    864             case ${option} in 
    865                 config_UserChoices_DateEnd) 
    866                     IGCM_debug_PrintVariables 1 config_UserChoices_DateEnd 
    867                     DateEnd=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateEnd} ) 
    868  
    869                     # Period Length In Days between DateBegin and DateEnd 
    870                     (( ExperienceLengthInDays=$( IGCM_date_DaysBetweenGregorianDate ${DateEnd} ${DateBegin} )  + 1 )) 
    871                     if [ ${ExperienceLengthInDays} -lt 0 ] ; then 
    872                         IGCM_debug_Print 1 "Problem with dates in libIGCM.card : ${DateEnd} < ${DateBegin} ! You must check that." 
    873                         IGCM_debug_Exit "IGCM_PeriodEnd" " Wrong Dates." 
    874                         IGCM_debug_Verif_Exit  
    875                     fi 
    876                     ;; 
    877                 config_UserChoices_PeriodLength) 
    878                     IGCM_debug_Print 1  "Change config_UserChoices_PeriodLength=${config_UserChoices_PeriodLength}" 
    879                     ;; 
    880                 PeriodNb) 
    881                     IGCM_debug_Print 1  "Loop in main Job with ${PeriodNb} period(s)" 
    882                     ;; 
    883                 config_Post_RebuildFrequency) 
    884                     IGCM_debug_Print 1  "Change config_Post_RebuildFrequency=${config_Post_RebuildFrequency} : IGCM_post_Configure" 
    885                     IGCM_post_Configure 
    886                     ;; 
    887                 config_Post_TimeSeriesFrequency) 
    888                     IGCM_debug_Print 1  "Change config_Post_TimeSeriesFrequency = ${config_Post_TimeSeriesFrequency} : IGCM_post_Initialize" 
    889                     IGCM_post_Configure 
    890                     ;; 
    891                 config_Post_SeasonalFrequency) 
    892                     IGCM_debug_Print 1  "Change config_Post_SeasonalFrequency = ${config_Post_SeasonalFrequency} : IGCM_post_Initialize" 
    893                     IGCM_post_Configure 
    894                     ;; 
    895             esac 
    896         done 
    897  
    898         echo 
    899         echo "########################################################################" 
    900         echo 
    901     fi 
    902  
    903     #=================================================# 
    904     #         Determine next computed period          # 
    905     #=================================================# 
    906  
    907     PeriodDateBegin=$( IGCM_date_AddDaysToGregorianDate ${PeriodDateEnd} 1 ) 
    908     IGCM_date_GetYearMonth $PeriodDateBegin year month 
    909     year_m1=$(( year - 1 )) 
    910     year_p1=$(( year + 1 )) 
    911     IGCM_config_Analyse_PeriodLength 
    912     PeriodDateEnd=$( IGCM_date_AddDaysToGregorianDate ${PeriodDateBegin} $(( ${PeriodLengthInDays} - 1 )) ) 
    913  
    914     # Debug Print : 
     950    echo "########################################################################" 
     951    echo "!!!                 Modification of libIGCM behaviour                !!!" 
    915952    echo 
    916     IGCM_debug_Print 1 "IGCM_config_PeriodEnd : Preparing Next Execution" 
    917     IGCM_debug_Print 1 "PeriodDateBegin       : ${PeriodDateBegin}" 
    918     IGCM_debug_Print 1 "PeriodDateEnd         : ${PeriodDateEnd}" 
    919     IGCM_debug_Print 1 "PeriodLengthInDays    : ${PeriodLengthInDays}" 
    920  
    921     PeriodDateBegin=$( IGCM_date_ConvertFormatToHuman ${PeriodDateBegin} ) 
    922     PeriodDateEnd=$( IGCM_date_ConvertFormatToHuman ${PeriodDateEnd} ) 
    923  
    924     (( CumulPeriod = CumulPeriod + 1 )) 
    925  
    926     # Debug Print : 
     953 
     954    IGCM_debug_Print 1 "DefineArrayFromOption  : libIGCM_UserChanges in libIGCM.card" 
     955    IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/libIGCM.card UserChanges 
     956    IGCM_debug_Print 2 "libIGCM_UserChanges" ${libIGCM_UserChanges[*]} 
     957 
     958    # Special treatments for libIGCM internals 
     959    for option in ${libIGCM_UserChanges[*]} ; do 
     960      IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/libIGCM.card UserChanges ${option} 
     961 
     962      echo "We will change : ${option}." 
     963      eval echo "Previous value : " \${${option}} 
     964      eval echo "Change to : " \${libIGCM_UserChanges_${option}} 
     965           
     966      eval ${option}=\${libIGCM_UserChanges_${option}} 
     967 
     968      case ${option} in 
     969        config_UserChoices_DateEnd) 
     970          IGCM_debug_PrintVariables 1 config_UserChoices_DateEnd 
     971          DateEnd=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateEnd} ) 
     972 
     973          # Period Length In Days between DateBegin and DateEnd 
     974          (( ExperienceLengthInDays=$( IGCM_date_DaysBetweenGregorianDate ${DateEnd} ${DateBegin} )  + 1 )) 
     975          if [ ${ExperienceLengthInDays} -lt 0 ] ; then 
     976            IGCM_debug_Print 1 "Problem with dates in libIGCM.card : ${DateEnd} < ${DateBegin} ! You must check that." 
     977            IGCM_debug_Exit "IGCM_PeriodEnd" " Wrong Dates." 
     978            IGCM_debug_Verif_Exit  
     979          fi 
     980        ;; 
     981        config_UserChoices_PeriodLength) 
     982          IGCM_debug_Print 1  "Change config_UserChoices_PeriodLength=${config_UserChoices_PeriodLength}" 
     983        ;; 
     984        PeriodNb) 
     985          IGCM_debug_Print 1  "Loop in main Job with ${PeriodNb} period(s)" 
     986        ;; 
     987        config_Post_RebuildFrequency) 
     988          IGCM_debug_Print 1  "Change config_Post_RebuildFrequency=${config_Post_RebuildFrequency} : IGCM_post_Configure" 
     989          IGCM_post_Configure 
     990        ;; 
     991        config_Post_TimeSeriesFrequency) 
     992          IGCM_debug_Print 1  "Change config_Post_TimeSeriesFrequency = ${config_Post_TimeSeriesFrequency} : IGCM_post_Initialize" 
     993          IGCM_post_Configure 
     994        ;; 
     995        config_Post_SeasonalFrequency) 
     996        IGCM_debug_Print 1  "Change config_Post_SeasonalFrequency = ${config_Post_SeasonalFrequency} : IGCM_post_Initialize" 
     997        IGCM_post_Configure 
     998        ;; 
     999      esac 
     1000    done 
     1001 
    9271002    echo 
    928     IGCM_debug_Print 3 "PeriodDateBegin Human : ${PeriodDateBegin}" 
    929     IGCM_debug_Print 3 "PeriodDateEnd Human   : ${PeriodDateEnd}" 
    930     IGCM_debug_Print 3 "CumulPeriod           : ${CumulPeriod}" 
    931  
    932     #=================================================# 
    933     #             Write updated run.card              # 
    934     #=================================================# 
    935  
    936     IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration OldPrefix ${OldPrefix} 
    937     IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin ${PeriodDateBegin} 
    938     IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd ${PeriodDateEnd} 
    939     IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod ${CumulPeriod} 
    940  
    941     if ( ${FirstInitialize} ) ; then 
    942         # It's no more the first time 
    943         FirstInitialize=false 
    944     fi 
    945  
    946     IGCM_debug_PopStack "IGCM_config_PeriodEnd" 
     1003    echo "########################################################################" 
     1004    echo 
     1005  fi 
     1006 
     1007  #=================================================# 
     1008  #         Determine next computed period          # 
     1009  #=================================================# 
     1010 
     1011  PeriodDateBegin=$( IGCM_date_AddDaysToGregorianDate ${PeriodDateEnd} 1 ) 
     1012  IGCM_date_GetYearMonthDay $PeriodDateBegin year month day 
     1013  year_m1=$(( year - 1 )) 
     1014  year_p1=$(( year + 1 )) 
     1015  IGCM_config_Analyse_PeriodLength 
     1016  PeriodDateEnd=$( IGCM_date_AddDaysToGregorianDate ${PeriodDateBegin} $(( ${PeriodLengthInDays} - 1 )) ) 
     1017 
     1018  # Debug Print : 
     1019  echo 
     1020  IGCM_debug_Print 1 "IGCM_config_PeriodEnd : Preparing Next Execution" 
     1021  IGCM_debug_Print 1 "PeriodDateBegin       : ${PeriodDateBegin}" 
     1022  IGCM_debug_Print 1 "PeriodDateEnd         : ${PeriodDateEnd}" 
     1023  IGCM_debug_Print 1 "PeriodLengthInDays    : ${PeriodLengthInDays}" 
     1024 
     1025  PeriodDateBegin=$( IGCM_date_ConvertFormatToHuman ${PeriodDateBegin} ) 
     1026  PeriodDateEnd=$( IGCM_date_ConvertFormatToHuman ${PeriodDateEnd} ) 
     1027 
     1028  (( CumulPeriod = CumulPeriod + 1 )) 
     1029 
     1030  # Debug Print : 
     1031  echo 
     1032  IGCM_debug_Print 3 "PeriodDateBegin Human : ${PeriodDateBegin}" 
     1033  IGCM_debug_Print 3 "PeriodDateEnd Human   : ${PeriodDateEnd}" 
     1034  IGCM_debug_Print 3 "CumulPeriod           : ${CumulPeriod}" 
     1035 
     1036  #=================================================# 
     1037  #             Write updated run.card              # 
     1038  #=================================================# 
     1039 
     1040  IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration OldPrefix ${OldPrefix} 
     1041  IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateBegin ${PeriodDateBegin} 
     1042  IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodDateEnd ${PeriodDateEnd} 
     1043  IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration CumulPeriod ${CumulPeriod} 
     1044 
     1045  if ( ${FirstInitialize} ) ; then 
     1046    # It's no more the first time 
     1047    FirstInitialize=false 
     1048  fi 
     1049 
     1050  IGCM_debug_PopStack "IGCM_config_PeriodEnd" 
    9471051} 
    9481052 
     
    9501054function IGCM_config_Finalize 
    9511055{ 
    952     IGCM_debug_PushStack "IGCM_config_Finalize" 
    953  
    954     echo 
    955     IGCM_debug_Print 1 "IGCM_config_Finalize" 
    956     echo 
    957  
    958     if [ ${SimulationLengthInDays} -ge ${ExperienceLengthInDays} ] ; then 
    959         #==========================# 
    960         # End of entire simulation # 
    961         #==========================# 
    962  
    963         # Mail notification 
    964         IGCM_sys_SendMail 
    965  
    966         # 
    967         IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "Completed" 
    968         IGCM_debug_Print 1 "Normal End of computation." 
    969         if ( $DEBUG_debug ) ; then 
    970             echo 
    971             IGCM_debug_Print 1 "Your files on ${R_OUT} :" 
    972             IGCM_sys_Tree ${R_SAVE} 
    973         fi 
    974     else 
    975         #=================# 
    976         # Submit next job # 
    977         #=================# 
    978  
    979         IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "OnQueue" 
    980  
    981         # Name of next Ksh Script output : 
    982         eval Script_Output="${Script_Output_Prefix}_${config_UserChoices_JobName}.$( printf "%06d" ${CumulPeriod} )" 
    983  
    984         IGCM_debug_Print 1 "Submit next job" 
    985         # SUBMIT NEXT JOB from SUBMIT_DIR and come back in RUN_DIR 
    986         IGCM_sys_Cd ${SUBMIT_DIR} 
    987         # Keep only the 5 latest ${Script_Output_Prefix}_${config_UserChoices_JobName} 
    988         ScriptTot=$( ls ${Script_Output_Prefix}_${config_UserChoices_JobName}.?????? 2>/dev/null | wc -l ) 
    989         [ ${ScriptTot} -gt 5 ] && rm -f $( ls ${Script_Output_Prefix}_${config_UserChoices_JobName}.?????? | head -$(( ${ScriptTot} - 5 )) ) 
    990         # Submit next job and come back 
    991         IGCM_sys_Qsub ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} 
    992         IGCM_sys_Cd - 
    993     fi 
    994  
    995     # Supress Non Deleted Boundary files 
    996     if [ ${DRYRUN} -le 2 ] ; then 
    997         IGCM_comp_DelFixeBoundaryFiles 
    998         ls -la 
    999     fi 
    1000      
    1001     # Clean ${RUN_DIR}=${RUN_DIR_PATH}/${config_UserChoices_TagName}/${config_UserChoices_JobName} 
    1002     # Only for production run (No clean up in DEV or DEB mode) 
    1003     # and command sent from .. directory. 
    1004     IGCM_sys_Cd .. 
    1005     [ X${JobType} = XRUN ] && IGCM_sys_Rm -rf ${RUN_DIR} 
    1006  
    1007     IGCM_debug_PopStack "IGCM_config_Finalize" 
     1056  IGCM_debug_PushStack "IGCM_config_Finalize" 
     1057 
     1058  echo 
     1059  IGCM_debug_Print 1 "IGCM_config_Finalize" 
     1060  echo 
     1061 
     1062  if [ ${SimulationLengthInDays} -ge ${ExperienceLengthInDays} ] ; then 
     1063    #==========================# 
     1064    # End of entire simulation # 
     1065    #==========================# 
     1066 
     1067    # Mail notification 
     1068    IGCM_sys_SendMail 
     1069 
     1070    # 
     1071    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "Completed" 
     1072    IGCM_debug_Print 1 "Normal End of computation." 
     1073    if ( $DEBUG_debug ) ; then 
     1074      echo 
     1075      IGCM_debug_Print 1 "Your files on ${R_SAVE} :" 
     1076      IGCM_sys_Tree ${R_SAVE} 
     1077 
     1078      IGCM_debug_Print 1 "Your files on ${R_BUFR} :" 
     1079      IGCM_sys_Tree ${R_BUFR} 
     1080    fi 
     1081  else 
     1082    #=================# 
     1083    # Submit next job # 
     1084    #=================# 
     1085 
     1086    IGCM_card_WriteOption ${SUBMIT_DIR}/run.card Configuration PeriodState "OnQueue" 
     1087 
     1088    # Name of next Ksh Script output : 
     1089    eval Script_Output="${Script_Output_Prefix}_${config_UserChoices_JobName}.$( printf "%06d" ${CumulPeriod} )" 
     1090 
     1091    IGCM_debug_Print 1 "Submit next job" 
     1092    # SUBMIT NEXT JOB from SUBMIT_DIR and come back in RUN_DIR 
     1093    IGCM_sys_Cd ${SUBMIT_DIR} 
     1094    # Keep only the 5 latest ${Script_Output_Prefix}_${config_UserChoices_JobName} 
     1095    ScriptTot=$( ls ${Script_Output_Prefix}_${config_UserChoices_JobName}.?????? 2>/dev/null | wc -l ) 
     1096    [ ${ScriptTot} -gt 5 ] && rm -f $( ls ${Script_Output_Prefix}_${config_UserChoices_JobName}.?????? | head -$(( ${ScriptTot} - 5 )) ) 
     1097    # Submit next job and come back 
     1098    IGCM_sys_Qsub ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} 
     1099    IGCM_sys_Cd - 
     1100  fi 
     1101 
     1102  # Supress Non Deleted Boundary files 
     1103  if [ ${DRYRUN} -le 2 ] ; then 
     1104    IGCM_comp_DelFixeBoundaryFiles 
     1105    ls -la 
     1106  fi 
     1107   
     1108  # Clean ${RUN_DIR}=${RUN_DIR_PATH}/${config_UserChoices_TagName}/${config_UserChoices_JobName} 
     1109  # Only for production run (No clean up in DEV or DEB mode) 
     1110  # and command sent from .. directory. 
     1111  IGCM_sys_Cd .. 
     1112  [ X${JobType} = XRUN ] && IGCM_sys_Rm -rf ${RUN_DIR} 
     1113 
     1114  IGCM_debug_PopStack "IGCM_config_Finalize" 
    10081115} 
    10091116 
Note: See TracChangeset for help on using the changeset viewer.