Changeset 726


Ignore:
Timestamp:
10/18/12 11:02:36 (12 years ago)
Author:
sdipsl
Message:
  • libIGCM_config refactoring. New function : IGCM_config_CommonConfiguration
  • will ease solving #65 #85 #86 and reduce code duplication
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libIGCM/libIGCM_config/libIGCM_config.ksh

    r691 r726  
    1313 
    1414#=================================== 
    15 function IGCM_config_Initialize 
     15function IGCM_config_CommonConfiguration 
    1616{ 
    17   IGCM_debug_PushStack "IGCM_config_Initialize" 
     17  IGCM_debug_PushStack "IGCM_config_CommonConfiguration" $@ 
    1818 
    1919  # Debug Print : 
    2020  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 
     21  IGCM_debug_Print 1 "IGCM_config_CommonConfiguration" $@ 
     22 
     23  # config.card path 
     24  configPath=$1 
    5025 
    5126  #================================== 
    52  
    5327  typeset option auxprint CompatibilityTag 
     28 
     29  #================================== 
    5430  # Read libIGCM compatibility version in config.card 
    55   IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card Compatibility libIGCM 
     31  IGCM_card_DefineVariableFromOption ${configPath} Compatibility libIGCM 
    5632  eval CompatibilityTag=${config_Compatibility_libIGCM} > /dev/null 2>&1 
    5733 
     
    6238  #================================== 
    6339  # Read UserChoices section: 
    64   IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card UserChoices 
    65  
     40  echo 
     41  IGCM_debug_Print 1 "DefineArrayFromOption  : config_UserChoices" 
     42 
     43  IGCM_card_DefineArrayFromSection ${configPath} UserChoices 
    6644  for option in ${config_UserChoices[*]} ; do 
    67     IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card UserChoices ${option} 
     45    IGCM_card_DefineVariableFromOption ${configPath} UserChoices ${option} 
     46    eval auxprint=\${config_UserChoices_${option}} 
     47    IGCM_debug_Print 3 "${option} : ${auxprint}" 
    6848  done 
    69   echo 
    70   IGCM_debug_Print 1 "DefineArrayFromOption  : config_UserChoices" 
    71   # Name Space of this experience 
    72   if [ X${config_UserChoices_SpaceName} != X ] ; then 
    73     IGCM_debug_PrintVariables 3 config_UserChoices_SpaceName 
    74   fi 
    75   # Expericence class of the run 
    76   if [ X${config_UserChoices_ExperimentName} != X ] ; then 
    77     IGCM_debug_PrintVariables 3 config_UserChoices_ExperimentName 
    78   fi 
    79   IGCM_debug_PrintVariables 3 config_UserChoices_JobName 
    80   if [ 3 -le ${Verbosity} ] ; then 
    81     echo "--------------Debug3-->" "config_UserChoices_LongName=" 
    82     echo "--------------Debug3-->" \"${config_UserChoices_LongName}\" 
    83   fi 
    84   IGCM_debug_PrintVariables 3 config_UserChoices_TagName 
    85   IGCM_debug_PrintVariables 3 config_UserChoices_CalendarType 
    86   IGCM_debug_PrintVariables 3 config_UserChoices_DateBegin 
    87   IGCM_debug_PrintVariables 3 config_UserChoices_DateEnd 
    88   IGCM_debug_PrintVariables 3 config_UserChoices_PeriodLength 
    8949 
    9050  #================================== 
    9151  # Read Ensemble section: 
    92   IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card Ensemble 
    93  
     52  echo 
     53  IGCM_debug_Print 1 "DefineArrayFromOption  : config_Ensemble" 
     54 
     55  IGCM_card_DefineArrayFromSection ${configPath} Ensemble 
    9456  for option in ${config_Ensemble[*]} ; do 
    95     IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card Ensemble ${option} 
     57    IGCM_card_DefineVariableFromOption ${configPath} Ensemble ${option} 
     58    eval auxprint=\${config_Ensemble_${option}} 
     59    IGCM_debug_Print 3 "${option} : ${auxprint}" 
    9660  done 
    97  
    98   IGCM_debug_Print 1 "DefineArrayFromOption  : config_Ensemble" 
    99   if [ X${config_Ensemble_EnsembleRun} != X ] ; then 
    100     IGCM_debug_PrintVariables 3 config_Ensemble_EnsembleRun 
    101   fi 
    102   if [ X${config_Ensemble_EnsembleName} != X ] ; then 
    103     IGCM_debug_PrintVariables 3 config_Ensemble_EnsembleName 
    104   fi 
    105   if [ X${config_Ensemble_EnsembleDate} != X ] ; then 
    106     IGCM_debug_PrintVariables 3 config_Ensemble_EnsembleDate 
    107   fi 
    10861 
    10962  #================================== 
    11063  # Read Post section: 
    111   IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card Post 
    11264  echo 
    11365  IGCM_debug_Print 1 "DefineArrayFromOption : config_Post" 
    11466 
     67  IGCM_card_DefineArrayFromSection ${configPath} Post 
    11568  for option in ${config_Post[*]} ; do 
    116     IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card Post ${option} 
     69    IGCM_card_DefineVariableFromOption ${configPath} Post ${option} 
    11770    eval auxprint=\${config_Post_${option}} 
    11871    IGCM_debug_Print 3 "${option} : ${auxprint}" 
    11972  done 
    120  
    121   #================================== 
    122   # Define default value to keep compatibility with previous card: means before changes due to TGCC 
    123   if [ X${PackDefault} = Xtrue ] ; then 
    124     [ X${config_Post_PackFrequency} = X ] && config_Post_PackFrequency=${config_Post_RebuildFrequency} 
    125   else 
    126     config_Post_PackFrequency=NONE 
    127   fi 
    128  
    129   #================================== 
    130   # Read ListOfComponents section: 
    131   IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card ListOfComponents 
    132   for comp in ${config_ListOfComponents[*]} ; do 
    133     IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/config.card ListOfComponents ${comp} 
    134   done 
    135  
    136   echo 
    137   IGCM_debug_Print 1 "DefineArrayFromSection : ListOfComponents" 
    138   IGCM_debug_Print 3 ${config_ListOfComponents[*]} 
    139  
    140   NbComponents=${#config_ListOfComponents[*]} 
    141  
    142   #================================== 
    143   # Define principal executable 
    144   IGCM_card_DefineArrayFromSection   ${SUBMIT_DIR}/config.card Executable 
    145  
    146   #================================== 
    147   # Define Outputs Name 
    148   IGCM_debug_Print 2 "Define Script_Output_Prefix and Exe_Output" 
    149   eval Script_Output_Prefix=${config_UserChoices_Script_Output_Prefix:='Script_Output'} 
    150   IGCM_debug_Print 3 "Script_Output_Prefix = ${Script_Output_Prefix}" 
    151   eval Exe_Output=out_execution 
    152   IGCM_debug_Print 3 "Exe_Output           = ${Exe_Output}" 
    153  
    154   #===================================================================# 
    155   # Prepare variables available for ${COMP}.card and ${COMP}.driver   # 
    156   #             But available to any son functions                    # 
    157   #===================================================================# 
    158  
    159   # Convert yyyy-mm-dd date to gregorian yyyymmdd 
    160   DateBegin=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateBegin} ) 
    161   DateEnd=$(   IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateEnd}   ) 
    162  
    163   # Period Length In Days between DateBegin and DateEnd 
    164   (( ExperienceLengthInDays=$( IGCM_date_DaysBetweenGregorianDate ${DateEnd} ${DateBegin} )  + 1 )) 
    165   if [ ${ExperienceLengthInDays} -lt 0 ] ; then 
    166     IGCM_debug_Print 1 "Problem with dates in config.card : ${DateEnd} < ${DateBegin} ! You must check that." 
    167     IGCM_debug_Exit "IGCM_config_Initialize" " Wrong Dates." 
    168     IGCM_debug_Verif_Exit 
    169   fi 
    170  
    171   # Day and Year of Initial State (Given in julian format) 
    172   InitDay=$(( $( IGCM_date_ConvertGregorianDateToJulian $DateBegin ) % 1000 )) 
    173   InitYear=$(( $( IGCM_date_ConvertGregorianDateToJulian $DateBegin ) / 1000 )) 
    174  
    175   #================================== 
    176   # Restarts : Gerneral rule or local for each component ? 
    177   IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card Restarts 
    178  
    179   echo 
    180   IGCM_debug_Print 1 "DefineArrayFromOption : config_Restarts" 
    181  
    182   for option in ${config_Restarts[*]} ; do 
    183     IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card Restarts ${option} 
    184     eval auxprint=\${config_Restarts_${option}} 
    185     IGCM_debug_Print 3 "${option} : ${auxprint}" 
    186   done 
    187  
    188   #================================================================# 
    189   #                  Test and Prepare directories                  # 
    190   #================================================================# 
    191  
    192   # ==> 4 kinds of input files : 
    193   #     1) R_INIT  : Initial State Files   (Etat0, carteveg) 
    194   #     2) R_BC    : Boundary Conditions   (Forcages, lai) 
    195   #     3) Parameters files (allready define through ${SUBMIT_DIR}) 
    196   #     4) Restarts files   (allready define in IGCM_config_Initialize) 
    197  
    198   # Here we offer the possibility to redefine R_INIT, R_BC 
    199   # and PeriodNb through config.card 
    200   R_INIT=${config_UserChoices_R_INIT:=${R_IN}/INIT} 
    201   IGCM_debug_Print 2 "(Re)Define R_INIT, R_BC and PeriodNb" 
    202   IGCM_debug_Print 3 "R_INIT=${R_INIT}" 
    203   R_BC=${config_UserChoices_R_BC:=${R_IN}/BC} 
    204   IGCM_debug_Print 3  "R_BC=${R_BC}" 
    205   PeriodNb=${config_UserChoices_PeriodNb:=${PeriodNb}} 
    206   IGCM_debug_Print 3  "Loop in main Job with ${PeriodNb} period(s)" 
    207  
    208   # Test Archive input/output. 
    209   IGCM_sys_TestDirArchive ${ARCHIVE} 
    210   [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive" 
    211   IGCM_sys_TestDirArchive ${R_IN} 
    212   [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive" 
     73  echo 
    21374 
    21475  #==================================================== 
    215   #R_SAVE : Job output directory 
     76  # R_SAVE : Job output directory 
     77  # R_BUFR : Job output buffered directory 
     78 
    21679  if ( [ ! X${config_UserChoices_SpaceName} = X ] && [ ! X${config_UserChoices_ExperimentName} = X ] ) ; then 
    21780    FreeName=$( echo ${config_UserChoices_JobName} | sed 's/.*_//' ) 
     
    241104  fi 
    242105 
     106  IGCM_debug_PopStack "IGCM_config_CommonConfiguration" 
     107} 
     108 
     109#=================================== 
     110function IGCM_config_Initialize 
     111{ 
     112  IGCM_debug_PushStack "IGCM_config_Initialize" 
     113 
     114  # Debug Print : 
     115  echo 
     116  IGCM_debug_Print 1 "IGCM_config_Initialize" 
     117 
     118  if [ ! -r ${SUBMIT_DIR}/run.card ]; then 
     119    #================================================# 
     120    #         The file run.card doesn't exist        # 
     121    #================================================# 
     122    FirstInitialize=true 
     123    #copy initial run.card 
     124    IGCM_sys_Cp ${SUBMIT_DIR}/run.card.init ${SUBMIT_DIR}/run.card 
     125    IGCM_debug_Print 2 "run.card copied from run.card.init" 
     126  else 
     127    FirstInitialize=false 
     128    IGCM_debug_Print 2 "run.card exists" 
     129  fi 
     130 
     131  # Test modipsl tree existence. 
     132  IGCM_sys_TestDir ${MODIPSL} 
     133  [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDir" 
     134  IGCM_sys_TestDir ${libIGCM} 
     135  [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDir" 
     136  IGCM_sys_TestDir ${R_EXE} 
     137  [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDir" 
     138  IGCM_sys_TestDir ${SUBMIT_DIR} 
     139  [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDir" 
     140 
     141  if ( $DEBUG_debug ) ; then 
     142    echo "Keep trace of inital SUBMIT_DIR : " 
     143    ls -lta ${SUBMIT_DIR} 
     144  fi 
     145 
     146  #================================== 
     147  # Read libIGCM compatibility version in config.card 
     148  # Read UserChoices section 
     149  # Read Ensemble section 
     150  # Read Post section 
     151  # Define all netcdf output directories 
     152  #================================== 
     153  IGCM_config_CommonConfiguration ${SUBMIT_DIR}/config.card 
     154 
     155  #================================== 
     156  # Define default value to keep compatibility with previous card: means before changes due to TGCC 
     157  if [ X${PackDefault} = Xtrue ] ; then 
     158    # If we DO apply pack in this computing center 
     159    IGCM_debug_Print 1 "Due to pack policy OVERRULE RebuildFromArchive to NONE" 
     160    config_Post_RebuildFromArchive=NONE 
     161    if [ X${config_UserChoices_SpaceName} = XTEST ]; then 
     162      # TEST simulations will not be packed and will stay on SCRATCHDIR filesystem 
     163      IGCM_debug_Print 1 "SpaceName=TEST. OVERRULE PackFrequency to NONE" 
     164      IGCM_debug_Print 1 "SpaceName=TEST. OVERRULE destination path directories" 
     165      config_Post_PackFrequency=NONE 
     166      IGCM_sys_ChangeArchive 
     167    else 
     168      # Default to RebuildFrequency if nothing has been set up related to PackFrequency 
     169      [ X${config_Post_PackFrequency} = X ] && config_Post_PackFrequency=${config_Post_RebuildFrequency} 
     170    fi 
     171  else 
     172    # If we DO NOT apply pack in this computing center 
     173    config_Post_PackFrequency=NONE 
     174  fi 
     175 
     176  #================================== 
     177  # Read ListOfComponents section: 
     178  echo 
     179  IGCM_debug_Print 1 "DefineArrayFromSection : ListOfComponents" 
     180 
     181  IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card ListOfComponents 
     182  for comp in ${config_ListOfComponents[*]} ; do 
     183    IGCM_card_DefineArrayFromOption ${SUBMIT_DIR}/config.card ListOfComponents ${comp} 
     184  done 
     185  IGCM_debug_Print 3 ${config_ListOfComponents[*]} 
     186 
     187  #================================== 
     188  # Read Executable section: 
     189  IGCM_card_DefineArrayFromSection   ${SUBMIT_DIR}/config.card Executable 
     190 
     191  #================================== 
     192  # Read Restarts section: 
     193  # Restarts : Gerneral rule or local for each component. 
     194  echo 
     195  IGCM_debug_Print 1 "DefineArrayFromOption : config_Restarts" 
     196 
     197  IGCM_card_DefineArrayFromSection ${SUBMIT_DIR}/config.card Restarts 
     198  for option in ${config_Restarts[*]} ; do 
     199    IGCM_card_DefineVariableFromOption ${SUBMIT_DIR}/config.card Restarts ${option} 
     200    eval auxprint=\${config_Restarts_${option}} 
     201    IGCM_debug_Print 3 "${option} : ${auxprint}" 
     202  done 
     203 
     204  #================================== 
     205  # Define Job Outputs Name 
     206  echo 
     207  IGCM_debug_Print 2 "Define Script_Output_Prefix and Exe_Output" 
     208  eval Script_Output_Prefix=${config_UserChoices_Script_Output_Prefix:='Script_Output'} 
     209  IGCM_debug_Print 3 "Script_Output_Prefix = ${Script_Output_Prefix}" 
     210  eval Exe_Output=out_execution 
     211  IGCM_debug_Print 3 "Exe_Output           = ${Exe_Output}" 
     212 
     213  #===================================================================# 
     214  # Prepare variables available for ${COMP}.card and ${COMP}.driver   # 
     215  #             But available to any son functions                    # 
     216  #===================================================================# 
     217 
     218  # Convert yyyy-mm-dd date to gregorian yyyymmdd 
     219  DateBegin=$( IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateBegin} ) 
     220  DateEnd=$(   IGCM_date_ConvertFormatToGregorian ${config_UserChoices_DateEnd}   ) 
     221 
     222  # Period Length In Days between DateBegin and DateEnd 
     223  (( ExperienceLengthInDays=$( IGCM_date_DaysBetweenGregorianDate ${DateEnd} ${DateBegin} )  + 1 )) 
     224  if [ ${ExperienceLengthInDays} -lt 0 ] ; then 
     225    IGCM_debug_Print 1 "Problem with dates in config.card : ${DateEnd} < ${DateBegin} ! You must check that." 
     226    IGCM_debug_Exit "IGCM_config_Initialize" " Wrong Dates." 
     227    IGCM_debug_Verif_Exit 
     228  fi 
     229 
     230  # Day and Year of Initial State (Given in julian format) 
     231  InitDay=$(( $( IGCM_date_ConvertGregorianDateToJulian $DateBegin ) % 1000 )) 
     232  InitYear=$(( $( IGCM_date_ConvertGregorianDateToJulian $DateBegin ) / 1000 )) 
     233 
     234  #================================================================# 
     235  #                  Test and Prepare directories                  # 
     236  #================================================================# 
     237 
     238  # ==> 4 kinds of input files : 
     239  #     1) R_INIT  : Initial State Files   (Etat0, carteveg) 
     240  #     2) R_BC    : Boundary Conditions   (Forcages, lai) 
     241  #     3) Parameters files (allready define through ${SUBMIT_DIR}) 
     242  #     4) Restarts files   (allready define in IGCM_config_Initialize) 
     243 
     244  # Here we offer the possibility to redefine R_INIT, R_BC 
     245  # and PeriodNb through config.card 
     246  R_INIT=${config_UserChoices_R_INIT:=${R_IN}/INIT} 
     247  IGCM_debug_Print 2 "(Re)Define R_INIT, R_BC and PeriodNb" 
     248  IGCM_debug_Print 3 "R_INIT=${R_INIT}" 
     249  R_BC=${config_UserChoices_R_BC:=${R_IN}/BC} 
     250  IGCM_debug_Print 3  "R_BC=${R_BC}" 
     251  PeriodNb=${config_UserChoices_PeriodNb:=${PeriodNb}} 
     252  IGCM_debug_Print 3  "Loop in main Job with ${PeriodNb} period(s)" 
     253 
     254  # Test Archive input/output. 
     255  echo 
     256  IGCM_sys_TestDirArchive ${ARCHIVE} 
     257  [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive" 
     258  IGCM_sys_TestDirArchive ${R_IN} 
     259  [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive" 
     260 
    243261  if ( ${FirstInitialize} ) ; then 
    244     IGCM_sys_MkdirArchive ${R_SAVE} 
    245     IGCM_sys_Mkdir        ${R_BUFR} 
     262    IGCM_sys_MkdirArchive   ${R_SAVE} 
     263    IGCM_sys_Mkdir          ${R_BUFR} 
    246264  else 
    247265    IGCM_sys_TestDirArchive ${R_SAVE} 
Note: See TracChangeset for help on using the changeset viewer.