Ignore:
Timestamp:
04/01/15 14:54:34 (9 years ago)
Author:
sdipsl
Message:

house keeping in libIGCM_sys (fourth pass). Will ease #248 and #251

File:
1 edited

Legend:

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

    r1172 r1181  
    8585# Set default umask (umask is 0027 on some machines : CCRT machine at least) 
    8686umask 0022 
     87 
     88#D--------------------------------------------------------------------== 
     89#D- 
     90#D-    Define IGCM_sys functions that are common on every systems 
     91#D- 
     92#D--------------------------------------------------------------------== 
     93 
     94#D-#================================================== 
     95#D-function IGCM_sys_RshMaster 
     96#D-* Purpose: Connection to frontend machine. 
     97#D-* Examples: 
     98#D- 
     99function IGCM_sys_RshMaster { 
     100  IGCM_debug_PushStack "IGCM_sys_RshMaster" $@ 
     101  OUTCOMMAND_PATH=${OUTCOMMAND_PATH} /bin/ksh <<-EOF 
     102    export libIGCM=${libIGCM} 
     103    export DEBUG_debug=${DEBUG_debug} 
     104    . ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh 
     105    . ${libIGCM}/libIGCM_card/libIGCM_card.ksh 
     106    ${@} 
     107EOF 
     108  if [ $? -gt 0 ] ; then 
     109    echo "IGCM_sys_RshMaster : erreur." 
     110    IGCM_debug_Exit "IGCM_sys_RshMaster" 
     111  fi 
     112  IGCM_debug_PopStack "IGCM_sys_RshMaster" 
     113} 
     114 
     115#D-#================================================== 
     116#D-function IGCM_sys_RshPost 
     117#D-* Purpose: Post-process rsh command 
     118#D-* Examples: 
     119#D- 
     120function IGCM_sys_RshPost { 
     121  IGCM_debug_PushStack "IGCM_sys_RshPost" $@ 
     122  if ( $DEBUG_sys ) ; then 
     123    echo "IGCM_sys_RshPost :" $@ 
     124  fi 
     125  # keep standard input (stdin) for the loop onto temporary file 
     126  cat >${OUTCOMMAND_PATH}/tmp_IGCM_sys_RshPost_$$_${LOGNAME} 
     127 
     128  OUTCOMMAND_PATH=${OUTCOMMAND_PATH} /bin/ksh <${OUTCOMMAND_PATH}/tmp_IGCM_sys_RshPost_$$_${LOGNAME} 
     129  if [ $? -gt 0 ] ; then 
     130    echo "IGCM_sys_RshPost : erreur." 
     131    IGCM_debug_Exit "IGCM_sys_RshPost" 
     132  fi 
     133  # delete temporary file 
     134  \rm ${OUTCOMMAND_PATH}/tmp_IGCM_sys_RshPost_$$_${LOGNAME} 
     135 
     136# ============ FRONTEND  END  ============ # 
     137 
     138# ============ CESIUM START ============ # 
     139#  typeset NB_ESSAI DELAI status i 
     140#  if [ "X$( grep rebuild_from tmp_IGCM_sys_RshPost_$$ )" != "X" ] ; then 
     141#    #little hack so that rebuild submission is done on titane not an cesium 
     142# 
     143#    libIGCM_POST_sed=$( echo $libIGCM_POST | sed 's/\//\\\//g' ) 
     144#    POST_DIR_sed=$( echo ${POST_DIR} | sed 's/\//\\\//g' ) 
     145#    sed "s/IGCM_sys_QsubPost/IGCM_sys_Qsub/g" tmp_IGCM_sys_RshPost_$$ > tmp.txt 
     146#    sed "s/ rebuild_fromWorkdir/ ${libIGCM_POST_sed}\/rebuild_fromWorkdir.job/g" tmp.txt > tmp_IGCM_sys_RshPost_$$ 
     147#    sed "s/ rebuild_fromArchive/ ${libIGCM_POST_sed}\/rebuild_fromArchive.job/g" tmp_IGCM_sys_RshPost_$$ > tmp.txt 
     148#    sed "s/Script_Post_Output=/Script_Output=${POST_DIR_sed}\//g" tmp.txt > tmp_IGCM_sys_RshPost_$$ 
     149#    \mv tmp.txt tmp_IGCM_sys_RshPost_$$ 
     150# 
     151#    echo cat tmp_IGCM_sys_RshPost_$$ AFTER 
     152#    cat tmp_IGCM_sys_RshPost_$$ 
     153# 
     154#    /bin/ksh <tmp_IGCM_sys_RshPost_$$ 
     155#    if [ $? -gt 0 ] ; then 
     156#      echo "IGCM_sys_RshPost : erreur." 
     157#      IGCM_debug_Exit "IGCM_sys_RshPost" 
     158#    fi 
     159#    # delete temporary file 
     160#    \rm tmp_IGCM_sys_RshPost_$$ 
     161# 
     162#  else 
     163#    # number of tentative 
     164#    NB_ESSAI=10 
     165#    # time delay between tentative 
     166#    DELAI=10 
     167#    i=0 
     168#    while [ $i -ne $NB_ESSAI ] ; do 
     169#      ssh -t titane996 ssh cesium /bin/ksh <tmp_IGCM_sys_RshPost_$$ 
     170#      status=$? 
     171#      if [ ${status} -ne 0 ]; 
     172#      then 
     173#        sleep $DELAI 
     174#      else 
     175#        break 
     176#      fi 
     177#      let i=$i+1 
     178#    done 
     179#    # delete temporary file 
     180#    \rm tmp_IGCM_sys_RshPost_$$ 
     181# 
     182#    if [ ${status} -gt 0 ] ; then 
     183#      echo "IGCM_sys_RshPost : erreur." 
     184#      IGCM_debug_Exit "IGCM_sys_RshPost" 
     185#    fi 
     186#  fi 
     187 
     188# ============ CESIUM  END  ============ # 
     189 
     190  IGCM_debug_PopStack "IGCM_sys_RshPost" 
     191} 
     192 
     193#D-#================================================== 
     194#D-function IGCM_sys_SendMail 
     195#D-* Purpose: Send mail when simulation is over 
     196#D-* Examples: 
     197#D- 
     198function IGCM_sys_SendMail { 
     199  IGCM_debug_PushStack "IGCM_sys_SendMail" $@ 
     200  if ( $DEBUG_sys ) ; then 
     201    echo "IGCM_sys_SendMail :" $@ 
     202  fi 
     203 
     204  if [ X${1} = XAccounting ] ; then 
     205    status=Accounting 
     206    mailText=jobAccounting.mail 
     207  elif ( ${ExitFlag} ) ; then 
     208    status=failed 
     209    mailText=jobEnd.mail 
     210  else 
     211    status=completed 
     212    mailText=jobEnd.mail 
     213  fi 
     214 
     215  # Update selected mail template 
     216  while read -r line; do 
     217    eval echo $line >> mail.txt ; 
     218  done < ${libIGCM}/libIGCM_sys/${mailText} 
     219 
     220  if [ ! -z ${config_UserChoices_MailName} ] ; then 
     221    mail -s "${config_UserChoices_JobName} ${status}" ${config_UserChoices_MailName} < mail.txt 
     222  elif [ -f ~/.forward ] ; then 
     223    mail -s "${config_UserChoices_JobName} ${status}" $( cat ~/.forward ) < mail.txt 
     224  else 
     225    mail -s "${config_UserChoices_JobName} ${status}" ${USER} < mail.txt 
     226  fi 
     227 
     228  sleep 10 
     229  rm -f mail.txt 
     230 
     231  IGCM_debug_PopStack "IGCM_sys_SendMail" 
     232} 
     233 
     234#D-#================================================== 
     235#D-function IGCM_sys_Mkdir 
     236#D-* Purpose: Master locale mkdir command 
     237#D-* Examples: 
     238#D- 
     239function IGCM_sys_Mkdir { 
     240  IGCM_debug_PushStack "IGCM_sys_Mkdir" $@ 
     241  if ( $DEBUG_sys ) ; then 
     242    echo "IGCM_sys_Mkdir :" $@ 
     243  fi 
     244  if [ ! -d ${1} ]; then 
     245    \mkdir -p $1 
     246    if [ $? -gt 0 ] ; then 
     247      echo "IGCM_sys_Mkdir : erreur." 
     248      IGCM_debug_Exit "IGCM_sys_Mkdir" 
     249    fi 
     250  fi 
     251  # vérification : 
     252  if [ ! -d ${1} ] ; then 
     253    echo "IGCM_sys_Mkdir : erreur." 
     254    IGCM_debug_Exit "IGCM_sys_Mkdir" 
     255  fi 
     256  IGCM_debug_PopStack "IGCM_sys_Mkdir" 
     257} 
     258 
     259#D-#================================================== 
     260#D-function IGCM_sys_MkdirWork 
     261#D-* Purpose: Mkdir on Work 
     262#D-* Examples: 
     263#D- 
     264function IGCM_sys_MkdirWork { 
     265  IGCM_debug_PushStack "IGCM_sys_MkdirWork" $@ 
     266  if ( $DEBUG_sys ) ; then 
     267    echo "IGCM_sys_MkdirWork :" $@ 
     268  fi 
     269  #- creation de repertoire sur le serveur fichier 
     270  if [ ! -d ${1} ]; then 
     271    \mkdir -p $1 
     272    if [ $? -gt 0 ] ; then 
     273      echo "IGCM_sys_MkdirWork : erreur." 
     274      IGCM_debug_Exit "IGCM_sys_MkdirWork" 
     275    fi 
     276  fi 
     277  IGCM_debug_PopStack "IGCM_sys_MkdirWork" 
     278} 
     279 
     280#D-#================================================== 
     281#D-function IGCM_sys_Cd 
     282#D-* Purpose: master cd command 
     283#D-* Examples: 
     284#D- 
     285function IGCM_sys_Cd { 
     286  IGCM_debug_PushStack "IGCM_sys_Cd" $@ 
     287  if ( $DEBUG_sys ) ; then 
     288    echo "IGCM_sys_Cd :" $@ 
     289  fi 
     290  \cd $1 
     291  if [ $? -gt 0 ] ; then 
     292    echo "IGCM_sys_Cd : erreur." 
     293    IGCM_debug_Exit "IGCM_sys_Cd" 
     294  fi 
     295  IGCM_debug_PopStack "IGCM_sys_Cd" 
     296} 
     297 
     298#D-#================================================== 
     299#D-function IGCM_sys_Chmod 
     300#D-* Purpose: Chmod 
     301#D-* Examples: 
     302#D- 
     303function IGCM_sys_Chmod { 
     304  IGCM_debug_PushStack "IGCM_sys_Chmod" $@ 
     305  if ( $DEBUG_sys ) ; then 
     306    echo "IGCM_sys_Chmod :" $@ 
     307  fi 
     308  \chmod $@ 
     309  if [ $? -gt 0 ] ; then 
     310    echo "IGCM_sys_Chmod : erreur." 
     311    IGCM_debug_Exit "IGCM_sys_Chmod" 
     312  fi 
     313  IGCM_debug_PopStack "IGCM_sys_Chmod" 
     314} 
     315 
     316#D-#================================================== 
     317#D-function IGCM_sys_FileSize 
     318#D-* Purpose: Filesize 
     319#D-* Examples: 
     320#D- 
     321function IGCM_sys_FileSize { 
     322  IGCM_debug_PushStack "IGCM_sys_FileSize" $@ 
     323 
     324  typeset sizeF 
     325  set +A sizeF -- $( ls -la ${1} ) 
     326  if [ $? -gt 0 ] ; then 
     327    IGCM_debug_Exit "IGCM_sys_FileSize" 
     328  fi 
     329  eval ${2}=${sizeF[4]} 
     330 
     331  IGCM_debug_PopStack "IGCM_sys_FileSize" 
     332} 
     333 
     334#D-#================================================== 
     335#D-function IGCM_sys_TestDir 
     336#D-* Purpose: Test Directory that must exists 
     337#D-* Examples: 
     338#D- 
     339function IGCM_sys_TestDir { 
     340  IGCM_debug_PushStack "IGCM_sys_TestDir" $@ 
     341  if ( $DEBUG_sys ) ; then 
     342    echo "IGCM_sys_TestDir :" $@ 
     343  fi 
     344  typeset ExistFlag 
     345  ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 ) 
     346  IGCM_debug_PopStack "IGCM_sys_TestDir" 
     347 
     348  return ${ExistFlag} 
     349} 
     350 
     351#D-#================================================== 
     352#D-function IGCM_sys_TestFileBuffer 
     353#D-* Purpose: Test file that must NOT EXISTS on Buffer 
     354#D-* Examples: 
     355#D- 
     356function IGCM_sys_TestFileBuffer { 
     357  IGCM_debug_PushStack "IGCM_sys_TestFileBuffer" $@ 
     358  typeset ExistFlag 
     359  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 ) 
     360  IGCM_debug_PopStack "IGCM_sys_TestFileBuffer" 
     361 
     362  return ${ExistFlag} 
     363} 
     364 
     365#D-#================================================== 
     366#D-function IGCM_sys_CountFileBuffer 
     367#D-* Purpose: Count files on Scratch filesystem 
     368#D-* Examples: 
     369#D- 
     370function IGCM_sys_CountFileBuffer { 
     371  IGCM_debug_PushStack "IGCM_sys_CountFileBuffer" $@ 
     372  ls ${@} 2>/dev/null | wc -l 
     373  if [ $? -gt 0 ] ; then 
     374    echo "IGCM_sys_CountFileBuffer : erreur." 
     375  fi 
     376  IGCM_debug_PopStack "IGCM_sys_CountFileBuffer" 
     377} 
     378 
     379#D-#================================================== 
     380#D-function IGCM_sys_Tar 
     381#D-* Purpose: master tar command 
     382#D-* Examples: 
     383#D- 
     384function IGCM_sys_Tar { 
     385  IGCM_debug_PushStack "IGCM_sys_Tar" $@ 
     386  if ( $DEBUG_sys ) ; then 
     387    echo "IGCM_sys_Tar :" $@ 
     388  fi 
     389  \tar cf $@ 
     390  if [ $? -gt 0 ] ; then 
     391    echo "IGCM_sys_Tar : erreur." 
     392    IGCM_debug_Exit "IGCM_sys_Tar" 
     393  fi 
     394  IGCM_debug_PopStack "IGCM_sys_Tar" 
     395} 
     396 
     397#D-#================================================== 
     398#D-function IGCM_sys_UnTar 
     399#D-* Purpose: master un-tar command 
     400#D-* Examples: 
     401#D- 
     402function IGCM_sys_UnTar { 
     403  IGCM_debug_PushStack "IGCM_sys_UnTar" $@ 
     404  if ( $DEBUG_sys ) ; then 
     405    echo "IGCM_sys_UnTar :" $@ 
     406  fi 
     407  \tar xvf $1 
     408  if [ $? -gt 0 ] ; then 
     409    echo "IGCM_sys_UnTar : erreur." 
     410    IGCM_debug_Exit "IGCM_sys_UnTar" 
     411  fi 
     412  IGCM_debug_PopStack "IGCM_sys_UnTar" 
     413} 
     414 
     415#D-************************* 
     416#D- File transfer functions 
     417#D-************************* 
     418#D- 
     419 
     420#D-#================================================== 
     421#D-function IGCM_sys_Rsync_out 
     422#D-* Purpose: treat return val of rsync 
     423#D-* Examples: IGCM_sys_Rsync_out out_RET_rsync 
     424#D-  Error values and explanations can depend on your system version. 
     425function IGCM_sys_Rsync_out { 
     426  IGCM_debug_PushStack "IGCM_sys_Rsync_out" $@ 
     427  if ( $DEBUG_sys ) ; then 
     428    echo "IGCM_sys_UnTar :" $@ 
     429  fi 
     430 
     431  typeset status 
     432  status=$1 
     433 
     434  if [ ! $status ] ; then 
     435    IGCM_debug_Print 1 "IGCM_sys_Rsync_out need an argument" 
     436    IGCM_debug_PopStack "IGCM_sys_Rsync_out" 
     437    return 
     438  fi 
     439 
     440  case $status in 
     441  0)  ;; 
     442  1)  IGCM_debug_Print 1 "rsync error RERR_SYNTAX : Syntax or usage error";; 
     443  2)  IGCM_debug_Print 1 "rsync error RERR_PROTOCOL : Protocol incompatibility";; 
     444  3)  IGCM_debug_Print 1 "rsync error RERR_FILESELECT : Errors selecting input/output files, dirs";; 
     445  4)  IGCM_debug_Print 1 "rsync error RERR_UNSUPPORTED : Requested action not supported." 
     446      IGCM_debug_Print 1 "An attempt was made to manipulate 64-bit files on a platform that cannot support them" 
     447      IGCM_debug_Print 1 "Or an option was specified that is supported by the client and not by the server.";; 
     448  5)  IGCM_debug_Print 1 "rsync error  : Error starting client-server protocol";; 
     449  10) IGCM_debug_Print 1 "rsync error RERR_SOCKETIO : Error in socket I/O";; 
     450  11) IGCM_debug_Print 1 "rsync error RERR_FILEIO: Error in file I/O";; 
     451  12) IGCM_debug_Print 1 "rsync error RERR_STREAMIO : Error in rsync protocol data stream";; 
     452  13) IGCM_debug_Print 1 "rsync error RERR_MESSAGEIO : Errors with program diagnostics";; 
     453  14) IGCM_debug_Print 1 "rsync error RERR_IPC : Error in IPC code";; 
     454  20) IGCM_debug_Print 1 "rsync error RERR_SIGNAL : Received SIGUSR1 or SIGINT";; 
     455  21) IGCM_debug_Print 1 "rsync error RERR_WAITCHILD : Some error returned by waitpid()";; 
     456  22) IGCM_debug_Print 1 "rsync error RERR_MALLOC : Error allocating core memory buffers";; 
     457  23) IGCM_debug_Print 1 "rsync error : Partial transfer due to error";; 
     458  24) IGCM_debug_Print 1 "rsync error : Partial transfer due to vanished source files";; 
     459  30) IGCM_debug_Print 1 "rsync error : Timeout in data send/receive";; 
     460  *)  IGCM_debug_Print 1 "rsync error : return code of rsync unknown :" $status;; 
     461  esac 
     462 
     463  IGCM_debug_PopStack "IGCM_sys_Rsync_out" 
     464} 
     465 
     466#D-#================================================== 
     467#D-function IGCM_sys_Miror_libIGCM 
     468#D-* Purpose: Mirror libIGCM PATH and lib to frontend 
     469#D-* Examples: 
     470#D- 
     471function IGCM_sys_Mirror_libIGCM { 
     472  IGCM_debug_PushStack "IGCM_sys_Mirror_libIGCM" 
     473  if ( $DEBUG_sys ) ; then 
     474    echo "IGCM_sys_Mirror_libIGCM" 
     475  fi 
     476 
     477  typeset status 
     478 
     479  mkdir -p ${HOME}/MIRROR/${PATHlibIGCM} 
     480 
     481  echo ${RSYNC} ${RSYNC_opt} ${libIGCM} ${HOME}/MIRROR/${PATHlibIGCM} > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1 
     482  ${RSYNC} ${RSYNC_opt} ${libIGCM} ${HOME}/MIRROR/${PATHlibIGCM} >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1 
     483  status=$? 
     484 
     485  if [ ${status} -gt 0 ] ; then 
     486    echo "IGCM_sys_Mirror_libIGCM Warning : no libIGCM on frontend." 
     487    cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     488  fi 
     489  IGCM_debug_PopStack "IGCM_sys_Mirror_libIGCM" 
     490} 
     491 
     492#D-#================================================== 
     493#D-function IGCM_sys_Cp 
     494#D-* Purpose: generic cp 
     495#D-* Examples: 
     496#D- 
     497function IGCM_sys_Cp { 
     498  IGCM_debug_PushStack "IGCM_sys_Cp" $@ 
     499  if ( $DEBUG_sys ) ; then 
     500    echo "IGCM_sys_Cp :" $@ 
     501  fi 
     502 
     503  typeset status 
     504 
     505  echo cp $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1 
     506  \cp $@ >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1 
     507  status=$? 
     508 
     509  if [ ${status} -gt 0 ] ; then 
     510    echo "IGCM_sys_Cp : error code ${status}" 
     511    cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     512    IGCM_debug_Exit "IGCM_sys_Cp" 
     513  else 
     514    \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     515  fi 
     516  IGCM_debug_PopStack "IGCM_sys_Cp" 
     517} 
     518 
     519#D-#================================================== 
     520#D-function IGCM_sys_Rm 
     521#D-* Purpose: generic rm 
     522#D-* Examples: 
     523#D- 
     524function IGCM_sys_Rm { 
     525  IGCM_debug_PushStack "IGCM_sys_Rm" $@ 
     526  if ( $DEBUG_sys ) ; then 
     527    echo "IGCM_sys_Rm :" $@ 
     528  fi 
     529 
     530  typeset status 
     531 
     532  echo rm $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1 
     533  \rm $@ >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1 
     534  status=$? 
     535 
     536  if [ ${status} -gt 0 ] ; then 
     537    echo "IGCM_sys_Rm : error code ${status}" 
     538    cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     539    IGCM_debug_Exit "IGCM_sys_Rm" 
     540  else 
     541    \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     542  fi 
     543  IGCM_debug_PopStack "IGCM_sys_Rm" 
     544} 
     545 
     546#D-#================================================== 
     547#D-function IGCM_sys_Mv 
     548#D-* Purpose: generic move 
     549#D-* Examples: 
     550#D- 
     551function IGCM_sys_Mv { 
     552  IGCM_debug_PushStack "IGCM_sys_Mv" $@ 
     553  if ( $DEBUG_sys ) ; then 
     554    echo "IGCM_sys_Mv :" $@ 
     555  fi 
     556 
     557  if [ $DRYRUN = 0 ]; then 
     558 
     559    typeset status 
     560 
     561    echo mv $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1 
     562    \mv $@ >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1 
     563    status=$? 
     564 
     565    if [ ${status} -gt 0 ] ; then 
     566      echo "IGCM_sys_Mv : error code ${status}" 
     567      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     568      IGCM_debug_Exit "IGCM_sys_Mv" 
     569    else 
     570      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     571    fi 
     572  fi 
     573  IGCM_debug_PopStack "IGCM_sys_Mv" 
     574} 
     575 
     576#D-#================================================== 
     577#D-function IGCM_sys_Get_Master 
     578#D-* Purpose: Copy a complete directory from MASTER filesystem 
     579#D-* Examples: 
     580#D- 
     581function IGCM_sys_Get_Master { 
     582  IGCM_debug_PushStack "IGCM_sys_Get_Master" $@ 
     583  if ( $DEBUG_sys ) ; then 
     584    echo "IGCM_sys_Get_Master :" $@ 
     585  fi 
     586  if [ $DRYRUN = 0 ]; then 
     587    if ( [ ! -d ${1} ] && [ ! -f ${1} ] ) ; then 
     588      echo "WARNING : IGCM_sys_Get_Master ${1} DOES NOT EXIST ." 
     589      IGCM_debug_PopStack "IGCM_sys_Get_Master" 
     590      return 
     591    fi 
     592 
     593    typeset NB_ESSAI DELAI status i 
     594    # number of tentative 
     595    NB_ESSAI=3 
     596    # time delay between tentative 
     597    DELAI=2 
     598 
     599    i=0 
     600    while [ $i -lt $NB_ESSAI ] ; do 
     601      \cp -urL $1 $2 > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1 
     602      status=$? 
     603      if [ ${status} -gt 0 ]; then 
     604        IGCM_debug_Print 2 "IGCM_sys_Get_Master : cp failed error code ${status} ${i}/${NB_ESSAI}" 
     605        IGCM_debug_Print 2 "IGCM_sys_Get_Master : sleep ${DELAI} seconds and try again." 
     606        sleep $DELAI 
     607      else 
     608        break 
     609      fi 
     610      (( i = i + 1 )) 
     611    done 
     612 
     613    if [ ${status} -gt 0 ] ; then 
     614      echo "IGCM_sys_Get_Master : error." 
     615      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     616      IGCM_debug_Exit "IGCM_sys_Get_Master" 
     617    else 
     618      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     619    fi 
     620  fi 
     621  IGCM_debug_PopStack "IGCM_sys_Get_Master" 
     622} 
     623 
     624#==================================================== 
     625#- Call IGCM_sys_Mirror_libIGCM now ! 
     626if ( $MirrorlibIGCM ) ; then 
     627  IGCM_sys_Mirror_libIGCM 
     628fi 
     629 
     630#D-#================================================== 
     631#D-function IGCM_sys_PutBuffer_Rest 
     632#D-* Purpose: Put computied restarts on ${SCRATCHDIR}. 
     633#D-           File and target directory must exist. 
     634#D-* Examples: 
     635#D- 
     636function IGCM_sys_PutBuffer_Rest { 
     637  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Rest" $@ 
     638  if ( $DEBUG_sys ) ; then 
     639    echo "IGCM_sys_PutBuffer_Rest :" $@ 
     640  fi 
     641  if [ $DRYRUN = 0 ]; then 
     642    if [ ! -f ${1} ] ; then 
     643      echo "ERROR : IGCM_sys_PutBuffer_Rest ${1} DOES NOT EXIST ." 
     644      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest" 
     645    fi 
     646 
     647    typeset status 
     648    # 
     649    # USUAL WAY 
     650    \cp $1 $2 > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1 
     651    status=$? 
     652 
     653    if [ ${status} -gt 0 ] ; then 
     654      echo "IGCM_sys_PutBuffer_Rest : error code ${status}" 
     655      [ -f ${2} ] && ls -l ${2} 
     656      [ -f ${2}/${1} ] && ls -l ${2}/${1} 
     657      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     658      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest" 
     659    else 
     660 
     661      if [ X${JobType} = XRUN ] ; then 
     662        [ -f ${2} ] && IGCM_sys_Chmod 444 ${2} 
     663        [ -f ${2}/${1} ] && IGCM_sys_Chmod 444 ${2}/${1} 
     664      fi 
     665 
     666      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     667    fi 
     668  fi 
     669  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Rest" 
     670} 
     671 
     672#D-#================================================== 
     673#D-function IGCM_sys_PrepareTaredRestart 
     674#D-* Purpose: Prepare tared restart to be access by computing job. 
     675#D-* Examples: 
     676#D- 
     677function IGCM_sys_PrepareTaredRestart { 
     678  IGCM_debug_PushStack "IGCM_sys_PrepareTaredRestart" $@ 
     679  if [ $DRYRUN = 0 ]; then 
     680    [ ! -f $( basename $1 ) ] && IGCM_sys_Get $1 . 
     681  fi 
     682  IGCM_debug_PopStack "IGCM_sys_PrepareTaredRestart" 
     683} 
     684 
     685#D-#================================================== 
     686#D-function IGCM_sys_PutBuffer_Out 
     687#D-* Purpose: Copy a file on the buffer filesystem after having chmod it in readonly 
     688#D-* Examples: 
     689#D- 
     690function IGCM_sys_PutBuffer_Out { 
     691  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Out" $@ 
     692  if ( $DEBUG_sys ) ; then 
     693    echo "IGCM_sys_PutBuffer_Out :" $@ 
     694  fi 
     695 
     696  typeset NB_ESSAI DELAI status i exist skip 
     697 
     698  # number of tentative 
     699  NB_ESSAI=3 
     700  # time delay between tentative 
     701  DELAI=2 
     702 
     703  if [ $DRYRUN = 0 ]; then 
     704    if [ ! -f ${1} ] ; then 
     705      echo "WARNING : IGCM_sys_PutBuffer_Out ${1} DOES NOT EXIST ." 
     706      IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out" 
     707      return 1 
     708    fi 
     709    # 
     710    IGCM_sys_Mkdir $( dirname $2 ) 
     711    # 
     712 
     713    exist=false 
     714    skip=false 
     715    if [ -f $2 ] ; then 
     716      IGCM_debug_Print 1 "$2 already exist" 
     717      exist=true 
     718      if [ "X$( diff $1 $2 )" = X ] ; then 
     719        IGCM_debug_Print 2 "$1 and $2 are the same file, we skip the copy" 
     720        status=0 
     721        skip=true 
     722      else 
     723        IGCM_debug_Print 2 "$1 and $2 are not the same file, we force the copy" 
     724        skip=false 
     725      fi 
     726    fi 
     727    # 
     728    if ( [ X${exist} = Xtrue ] && [ X${skip} = Xfalse ] ) ; then 
     729      IGCM_sys_Chmod u+w $2 
     730    fi 
     731 
     732    if [ X${skip} = Xfalse ] ; then 
     733      i=0 
     734      while [ $i -lt $NB_ESSAI ] ; do 
     735        if [ $( stat -c %d $1 ) -ne $( stat -c %d $( dirname $2 ) ) ] ; then 
     736          # USUAL WAY 
     737          \cp $1 $2 > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1 
     738          status=$? 
     739        else 
     740          # NOT SO USUAL WAY 
     741          \mv $1 $2 > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1 
     742          status=$? 
     743        fi 
     744        if [ ${status} -gt 0 ]; then 
     745          IGCM_debug_Print 2 "IGCM_sys_PutBuffer_Out : cp failed error code ${status} ${i}/${NB_ESSAI}" 
     746          IGCM_debug_Print 2 "IGCM_sys_PutBuffer_Out : sleep ${DELAI} seconds and try again." 
     747          [ -f ${2} ] && ls -l ${2} 
     748          [ -f ${2}/${1} ] && ls -l ${2}/${1} 
     749          sleep $DELAI 
     750        else 
     751          break 
     752        fi 
     753        (( i = i + 1 )) 
     754      done 
     755    fi 
     756 
     757    if [ ${status} -gt 0 ] ; then 
     758      echo "IGCM_sys_PutBuffer_Out : error." 
     759      [ -f ${2} ] && ls -l ${2} 
     760      [ -f ${2}/${1} ] && ls -l ${2}/${1} 
     761      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     762      IGCM_debug_Exit "IGCM_sys_PutBuffer_Out" 
     763    else 
     764 
     765      if [ X${JobType} = XRUN ] ; then 
     766        if [ X${3} = X ] ; then 
     767          [ -f ${2} ] && IGCM_sys_Chmod 444 ${2} 
     768          [ -f ${2}/${1} ] && IGCM_sys_Chmod 444 ${2}/${1} 
     769        fi 
     770      fi 
     771 
     772      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     773    fi 
     774  fi 
     775  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out" 
     776  return 0 
     777} 
     778 
     779#D-#================================================== 
     780#D-function IGCM_sys_GetBuffer 
     781#D-* Purpose: Get a file from ${SCRATCHDIR} 
     782#D-* Examples: IGCM_sys_GetBuffer myfile /destpath/myfile_with_PREFIX 
     783#D-            IGCM_sys_GetBuffer /l Array_contain_myfiles /destpath/ 
     784function IGCM_sys_GetBuffer { 
     785  IGCM_debug_PushStack "IGCM_sys_GetBuffer" $@ 
     786 
     787  typeset DEST buf_liste target file_work 
     788  typeset NB_ESSAI DELAI status i 
     789 
     790  if ( $DEBUG_sys ) ; then 
     791    echo "IGCM_sys_GetBuffer :" $@ 
     792  fi 
     793 
     794  # number of tentative 
     795  NB_ESSAI=3 
     796  # time delay between tentative 
     797  DELAI=2 
     798 
     799  if [ $DRYRUN -le 2 ]; then 
     800    if [ X${1} = X'/l' ] ; then 
     801      eval set +A buf_liste \${${2}} 
     802    else 
     803      eval set +A buf_liste ${1} 
     804    fi 
     805    eval DEST=\${${#}} 
     806 
     807    #USUAL WAY 
     808    if [ X${1} = X'/l' ] ; then 
     809      for target in ${buf_liste[*]} ; do 
     810        local_file=$( basename ${target} ) 
     811        i=0 
     812        while [ $i -lt $NB_ESSAI ] ; do 
     813          \cp ${target} ${DEST}/${local_file} >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1 
     814          status=$? 
     815          if [ ${status} -gt 0 ]; then 
     816            IGCM_debug_Print 2 "IGCM_sys_GetBuffer : cp failed error code ${status} ${i}/${NB_ESSAI}" 
     817            IGCM_debug_Print 2 "IGCM_sys_GetBuffer : sleep ${DELAI} seconds and try again." 
     818            sleep $DELAI 
     819          else 
     820            break 
     821          fi 
     822          (( i = i + 1 )) 
     823        done 
     824        if [ ${status} -gt 0 ] ; then 
     825          echo "IGCM_sys_Get : error" 
     826          cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     827          \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     828          IGCM_debug_Exit "IGCM_sys_GetBuffer" 
     829        else 
     830          \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     831        fi 
     832      done 
     833    else 
     834      i=0 
     835      while [ $i -lt $NB_ESSAI ] ; do 
     836        \cp ${buf_liste} ${DEST} >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1 
     837        status=$? 
     838        if [ ${status} -gt 0 ]; then 
     839          IGCM_debug_Print 2 "IGCM_sys_GetBuffer : cp failed error code ${status} ${i}/${NB_ESSAI}" 
     840          IGCM_debug_Print 2 "IGCM_sys_GetBuffer : sleep ${DELAI} seconds and try again." 
     841          sleep $DELAI 
     842        else 
     843          break 
     844        fi 
     845        (( i = i + 1 )) 
     846      done 
     847      if [ ${status} -gt 0 ] ; then 
     848        echo "IGCM_sys_Get : error" 
     849        cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     850        \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     851        IGCM_debug_Exit "IGCM_sys_GetBuffer" 
     852      else 
     853        \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     854      fi 
     855    fi 
     856  fi 
     857  IGCM_debug_PopStack "IGCM_sys_GetBuffer" 
     858} 
     859 
     860#D-#================================================== 
     861#D-function IGCM_sys_GetDate_FichWork 
     862#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK 
     863#D-* Examples: 
     864#D- 
     865function IGCM_sys_GetDate_FichWork { 
     866  IGCM_debug_PushStack "IGCM_sys_GetDate_FichWork" $@ 
     867  if ( $DEBUG_sys ) ; then 
     868    echo "IGCM_sys_GetDate_FichWork :" $@ 
     869  fi 
     870 
     871  if [ $# -ge 3 ] ; then 
     872    mode=$3 
     873    TimeStyle=$4 
     874  else 
     875    mode="default" 
     876    TimeStyle="%Y%m%d%H%M%S" 
     877  fi 
     878 
     879  typeset dateF 
     880  set +A dateF -- $( ls -l --full-time --time-style=+"${TimeStyle}" ${1} ) 
     881 
     882  case $mode in 
     883    "default") 
     884      eval ${2}=${dateF[5]} 
     885      ;; 
     886    "SplitFields") 
     887      eval ${2}="${dateF[5]}\ ${dateF[6]}" 
     888      ;; 
     889  esac 
     890 
     891  # donne la date filesys d'un fichier sur la machine work 
     892  IGCM_debug_PopStack "IGCM_sys_GetDate_FichWork" 
     893} 
     894 
     895#D-#================================================== 
     896#D-function IGCM_sys_rebuild 
     897#D-* Purpose: rebuild parallel files 
     898#D-* Examples: 
     899#D- 
     900function IGCM_sys_rebuild { 
     901  IGCM_debug_PushStack "IGCM_sys_rebuild" $@ 
     902  if ( $DEBUG_sys ) ; then 
     903    echo "IGCM_sys_rebuild :" $@ 
     904  fi 
     905 
     906  typeset NB_ESSAI DELAI status i firstArg 
     907  # number of tentative 
     908  NB_ESSAI=3 
     909  # time delay between tentative 
     910  DELAI=2 
     911 
     912  i=0 
     913  while [ $i -lt $NB_ESSAI ] ; do 
     914    rebuild -f -o $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1 
     915    status=$? 
     916    if [ ${status} -gt 0 ] ; then 
     917      IGCM_debug_Print 2 "IGCM_sys_rebuild : error code ${status}" 
     918      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     919      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     920      IGCM_debug_Print 2 "IGCM_sys_rebuild : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again." 
     921      firstArg=${1} 
     922      \rm ${firstArg} 
     923      sleep $DELAI 
     924    else 
     925      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     926      break 
     927    fi 
     928    (( i = i + 1 )) 
     929  done 
     930 
     931  if [ ${status} -gt 0 ] ; then 
     932    echo "IGCM_sys_rebuild : rebuild error code is ${status}" 
     933    IGCM_debug_Exit "rebuild" 
     934  fi 
     935 
     936  IGCM_debug_PopStack "IGCM_sys_rebuild" 
     937} 
     938 
     939#D-#================================================== 
     940#D-function IGCM_sys_rebuild_station 
     941#D-* Purpose: rebuild parallel files describing station 
     942#D-* Examples: 
     943#D- 
     944function IGCM_sys_rebuild_station { 
     945  IGCM_debug_PushStack "IGCM_sys_rebuild_station" $@ 
     946  typeset i list_opt file_in file_out prefix_invert list_invert 
     947  if ( $DEBUG_sys ) ; then 
     948    echo "IGCM_sys_rebuild_station :" $@ 
     949  fi 
     950 
     951  # Station re-ordering is too expansive to be run within libIGCM 
     952  # This is due to (ncpdq - nrcat - ncpdq) I/O sequence. 
     953  # This re-ordering must be done "in memory" by the cmorization process 
     954 
     955  # Only LMDZ text output contains the exact ordering of the station. 
     956  # We isolate this in the code below: 
     957  #  0  38  -157.5000000000000  70.98591549295774 
     958  #  0  54  27.49999999999999   67.18309859154928 
     959  #  0  56  -62.50000000000001  82.39436619718309 
     960  #  0  79  12.49999999999999   78.59154929577466 
     961  #  0  116 -165.0000000000000  76.05633802816901 
     962  #  0  117 130.0000000000000   70.98591549295774 
     963  #  0  118 110.0000000000000   87.46478873239437 
     964  #  1  40  4.999999999999995   51.97183098591550 
     965 
     966  list_opt=$@ 
     967 
     968  # Invert Axis : t,x -> x,t 
     969  #               t,pres,x -> x,t,pres 
     970  # So that we can concatenate along x 
     971  i=0 
     972  for file_in in ${list_opt} ; do 
     973    (( i = i + 1)) 
     974    [ ${i} = 1 ] && file_out=${file_in} && continue 
     975    # detect time counter and do the job only if present 
     976    var_unlim=$(ncdump -h ${file_in} | grep UNLIMITED | cut -d ' ' -f 1 | sed -e 's/^[ \t]*//' -e 's/[ \t]*$//') 
     977    if [ X${var_unlim} = Xtime_counter ] ; then 
     978      prefix_invert=$( basename ${file_in} .nc ) 
     979      IGCM_sys_ncpdq -a x,time_counter -a x,time_counter,presnivs ${file_in} ${prefix_invert}_xt.nc 
     980      list_invert[${#list_invert[*]}]=${prefix_invert}_xt.nc 
     981    fi 
     982  done 
     983 
     984  # Concatenate 
     985  IGCM_sys_ncrcat ${list_invert[*]} histstn_xt.nc 
     986 
     987  # Re-ivert file 
     988  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x histstn_xt.nc ${file_out} 
     989 
     990  IGCM_debug_PopStack "IGCM_sys_rebuild_station" 
     991} 
     992 
     993############################################################## 
     994# NCO OPERATOR 
     995 
     996#D-#================================================== 
     997#D-function IGCM_sys_ncap2 
     998#D-* Purpose: encapsulate ncap2 call so as to manage error code and retry 
     999#D-* Examples: 
     1000#D- 
     1001function IGCM_sys_ncap2 { 
     1002  IGCM_debug_PushStack "IGCM_sys_ncap2" $@ 
     1003  if ( $DEBUG_sys ) ; then 
     1004    echo "IGCM_sys_ncap2 :" $@ 
     1005  fi 
     1006 
     1007  typeset NB_ESSAI DELAI status i 
     1008  # number of tentative 
     1009  NB_ESSAI=3 
     1010  # time delay between tentative 
     1011  DELAI=2 
     1012 
     1013  i=0 
     1014  while [ $i -lt $NB_ESSAI ] ; do 
     1015    ncap2 -C "$@" > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1 
     1016    status=$? 
     1017    if [ ${status} -gt 0 ] ; then 
     1018      IGCM_debug_Print 2 "IGCM_sys_ncap2 : error code ${status}" 
     1019      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     1020      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     1021      IGCM_debug_Print 2 "IGCM_sys_ncap2 : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again." 
     1022      sleep $DELAI 
     1023    else 
     1024      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     1025      break 
     1026    fi 
     1027    (( i = i + 1 )) 
     1028  done 
     1029 
     1030  if [ ${status} -gt 0 ] ; then 
     1031    echo "IGCM_sys_ncap2 : ncap2 error" 
     1032    IGCM_debug_Exit "ncap2" 
     1033  fi 
     1034 
     1035  IGCM_debug_PopStack "IGCM_sys_ncap2" 
     1036} 
     1037 
     1038#D-#================================================== 
     1039#D-function IGCM_sys_ncatted 
     1040#D-* Purpose: encapsulate ncatted call so as to manage error code and retry 
     1041#D-* Examples: 
     1042#D- 
     1043function IGCM_sys_ncatted { 
     1044  IGCM_debug_PushStack "IGCM_sys_ncatted" $@ 
     1045  if ( $DEBUG_sys ) ; then 
     1046    echo "IGCM_sys_ncatted :" $@ 
     1047  fi 
     1048 
     1049  typeset NB_ESSAI DELAI status i 
     1050  # number of tentative 
     1051  NB_ESSAI=3 
     1052  # time delay between tentative 
     1053  DELAI=2 
     1054 
     1055  i=0 
     1056  while [ $i -lt $NB_ESSAI ] ; do 
     1057    ncatted "$@" > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1 
     1058    status=$? 
     1059    if [ ${status} -gt 0 ] ; then 
     1060      IGCM_debug_Print 2 "IGCM_sys_ncatted : error code ${status}" 
     1061      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     1062      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     1063      IGCM_debug_Print 2 "IGCM_sys_ncatted : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again." 
     1064      sleep $DELAI 
     1065    else 
     1066      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     1067      break 
     1068    fi 
     1069    (( i = i + 1 )) 
     1070  done 
     1071 
     1072  if [ ${status} -gt 0 ] ; then 
     1073    echo "IGCM_sys_ncatted : ncatted error" 
     1074    IGCM_debug_Exit "ncatted" 
     1075  fi 
     1076 
     1077  IGCM_debug_PopStack "IGCM_sys_ncatted" 
     1078} 
     1079 
     1080#D-#================================================== 
     1081#D-function IGCM_sys_ncbo 
     1082#D-* Purpose: encapsulate ncbo call so as to manage error code and retry 
     1083#D-* Examples: 
     1084#D- 
     1085function IGCM_sys_ncbo { 
     1086  IGCM_debug_PushStack "IGCM_sys_ncbo" $@ 
     1087  if ( $DEBUG_sys ) ; then 
     1088    echo "IGCM_sys_ncbo :" $@ 
     1089  fi 
     1090 
     1091  typeset NB_ESSAI DELAI status i 
     1092  # number of tentative 
     1093  NB_ESSAI=3 
     1094  # time delay between tentative 
     1095  DELAI=2 
     1096 
     1097  i=0 
     1098  while [ $i -lt $NB_ESSAI ] ; do 
     1099    ncbo -C $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1 
     1100    status=$? 
     1101    if [ ${status} -gt 0 ] ; then 
     1102      IGCM_debug_Print 2 "IGCM_sys_ncbo : error code ${status}" 
     1103      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     1104      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     1105      IGCM_debug_Print 2 "IGCM_sys_ncbo : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again." 
     1106      sleep $DELAI 
     1107    else 
     1108      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     1109      break 
     1110    fi 
     1111    (( i = i + 1 )) 
     1112  done 
     1113 
     1114  if [ ${status} -gt 0 ] ; then 
     1115    echo "IGCM_sys_ncbo : ncbo error" 
     1116    IGCM_debug_Exit "ncbo" 
     1117  fi 
     1118 
     1119  IGCM_debug_PopStack "IGCM_sys_ncbo" 
     1120} 
     1121 
     1122#D-#================================================== 
     1123#D-function IGCM_sys_ncdif 
     1124#D-* Purpose: encapsulate ncdiff call so as to manage error code and retry 
     1125#D-* Examples: 
     1126#D- 
     1127function IGCM_sys_ncdiff { 
     1128  IGCM_debug_PushStack "IGCM_sys_ncdiff" $@ 
     1129  if ( $DEBUG_sys ) ; then 
     1130    echo "IGCM_sys_ncdiff :" $@ 
     1131  fi 
     1132 
     1133  typeset NB_ESSAI DELAI status i 
     1134  # number of tentative 
     1135  NB_ESSAI=3 
     1136  # time delay between tentative 
     1137  DELAI=2 
     1138 
     1139  i=0 
     1140  while [ $i -lt $NB_ESSAI ] ; do 
     1141    ncdiff -C $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1 
     1142    status=$? 
     1143    if [ ${status} -gt 0 ] ; then 
     1144      IGCM_debug_Print 2 "IGCM_sys_ncdiff : error code ${status}" 
     1145      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     1146      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     1147      IGCM_debug_Print 2 "IGCM_sys_ncdiff : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again." 
     1148      sleep $DELAI 
     1149    else 
     1150      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     1151      break 
     1152    fi 
     1153    (( i = i + 1 )) 
     1154  done 
     1155 
     1156  if [ ${status} -gt 0 ] ; then 
     1157    echo "IGCM_sys_ncdiff : ncdiff error" 
     1158    IGCM_debug_Exit "ncdiff" 
     1159  fi 
     1160 
     1161  IGCM_debug_PopStack "IGCM_sys_ncdiff" 
     1162} 
     1163 
     1164#D-#================================================== 
     1165#D-function IGCM_sys_ncea 
     1166#D-* Purpose: encapsulate ncea call so as to manage error code and retry 
     1167#D-* Examples: 
     1168#D- 
     1169function IGCM_sys_ncea { 
     1170  IGCM_debug_PushStack "IGCM_sys_ncea" $@ 
     1171  if ( $DEBUG_sys ) ; then 
     1172    echo "IGCM_sys_ncea :" $@ 
     1173  fi 
     1174 
     1175  typeset NB_ESSAI DELAI status i 
     1176  # number of tentative 
     1177  NB_ESSAI=3 
     1178  # time delay between tentative 
     1179  DELAI=2 
     1180 
     1181  i=0 
     1182  while [ $i -lt $NB_ESSAI ] ; do 
     1183    ncea -C $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1 
     1184    status=$? 
     1185    if [ ${status} -gt 0 ] ; then 
     1186      IGCM_debug_Print 2 "IGCM_sys_ncea : error code ${status}" 
     1187      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     1188      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     1189      IGCM_debug_Print 2 "IGCM_sys_ncea : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again." 
     1190      sleep $DELAI 
     1191    else 
     1192      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     1193      break 
     1194    fi 
     1195    (( i = i + 1 )) 
     1196  done 
     1197 
     1198  if [ ${status} -gt 0 ] ; then 
     1199    echo "IGCM_sys_ncea : ncea error" 
     1200    IGCM_debug_Exit "ncea" 
     1201  fi 
     1202 
     1203  IGCM_debug_PopStack "IGCM_sys_ncea" 
     1204} 
     1205 
     1206#D-#================================================== 
     1207#D-function IGCM_sys_ncecat 
     1208#D-* Purpose: encapsulate ncecat call so as to manage error code and retry 
     1209#D-* Examples: 
     1210#D- 
     1211function IGCM_sys_ncecat { 
     1212  IGCM_debug_PushStack "IGCM_sys_ncecat" $@ 
     1213  if ( $DEBUG_sys ) ; then 
     1214    echo "IGCM_sys_ncecat :" $@ 
     1215  fi 
     1216 
     1217  typeset NB_ESSAI DELAI status i 
     1218  # number of tentative 
     1219  NB_ESSAI=3 
     1220  # time delay between tentative 
     1221  DELAI=2 
     1222 
     1223  i=0 
     1224  while [ $i -lt $NB_ESSAI ] ; do 
     1225    ncecat -C $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1 
     1226    status=$? 
     1227    if [ ${status} -gt 0 ] ; then 
     1228      IGCM_debug_Print 2 "IGCM_sys_ncecat : error code ${status}" 
     1229      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     1230      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     1231      IGCM_debug_Print 2 "IGCM_sys_ncecat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again." 
     1232      sleep $DELAI 
     1233    else 
     1234      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     1235      break 
     1236    fi 
     1237    (( i = i + 1 )) 
     1238  done 
     1239 
     1240  if [ ${status} -gt 0 ] ; then 
     1241    echo "IGCM_sys_ncecat : ncecat error" 
     1242    IGCM_debug_Exit "ncecat" 
     1243  fi 
     1244 
     1245  IGCM_debug_PopStack "IGCM_sys_ncecat" 
     1246} 
     1247 
     1248#D-#================================================== 
     1249#D-function IGCM_sys_ncflint 
     1250#D-* Purpose: encapsulate ncflint call so as to manage error code and retry 
     1251#D-* Examples: 
     1252#D- 
     1253function IGCM_sys_ncflint { 
     1254  IGCM_debug_PushStack "IGCM_sys_ncflint" $@ 
     1255  if ( $DEBUG_sys ) ; then 
     1256    echo "IGCM_sys_ncflint :" $@ 
     1257  fi 
     1258 
     1259  typeset NB_ESSAI DELAI status i 
     1260  # number of tentative 
     1261  NB_ESSAI=3 
     1262  # time delay between tentative 
     1263  DELAI=2 
     1264 
     1265  i=0 
     1266  while [ $i -lt $NB_ESSAI ] ; do 
     1267    ncflint -C $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1 
     1268    status=$? 
     1269    if [ ${status} -gt 0 ] ; then 
     1270      IGCM_debug_Print 2 "IGCM_sys_ncflint : error code ${status}" 
     1271      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     1272      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     1273      IGCM_debug_Print 2 "IGCM_sys_ncflint : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again." 
     1274      sleep $DELAI 
     1275    else 
     1276      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     1277      break 
     1278    fi 
     1279    (( i = i + 1 )) 
     1280  done 
     1281 
     1282  if [ ${status} -gt 0 ] ; then 
     1283    echo "IGCM_sys_ncflint : ncflint error" 
     1284    IGCM_debug_Exit "ncflint" 
     1285  fi 
     1286 
     1287  IGCM_debug_PopStack "IGCM_sys_ncflint" 
     1288} 
     1289 
     1290#D-#================================================== 
     1291#D-function IGCM_sys_ncks 
     1292#D-* Purpose: encapsulate ncks call so as to manage error code and retry 
     1293#D-* Examples: 
     1294#D- 
     1295function IGCM_sys_ncks { 
     1296  IGCM_debug_PushStack "IGCM_sys_ncks" $@ 
     1297  if ( $DEBUG_sys ) ; then 
     1298    echo "IGCM_sys_ncks :" $@ 
     1299  fi 
     1300 
     1301  typeset NB_ESSAI DELAI status i 
     1302  # number of tentative 
     1303  NB_ESSAI=3 
     1304  # time delay between tentative 
     1305  DELAI=2 
     1306 
     1307  i=0 
     1308  while [ $i -lt $NB_ESSAI ] ; do 
     1309    ncks -C $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1 
     1310    status=$? 
     1311    if [ ${status} -gt 0 ] ; then 
     1312      IGCM_debug_Print 2 "IGCM_sys_ncks : error code ${status}" 
     1313      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     1314      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     1315      IGCM_debug_Print 2 "IGCM_sys_ncks : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again." 
     1316      sleep $DELAI 
     1317    else 
     1318      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     1319      break 
     1320    fi 
     1321    (( i = i + 1 )) 
     1322  done 
     1323 
     1324  if [ ${status} -gt 0 ] ; then 
     1325    echo "IGCM_sys_ncks : ncks error" 
     1326    IGCM_debug_Exit "ncks" 
     1327  fi 
     1328 
     1329  IGCM_debug_PopStack "IGCM_sys_ncks" 
     1330} 
     1331 
     1332#D-#================================================== 
     1333#D-function IGCM_sys_ncpdq 
     1334#D-* Purpose: encapsulate ncpdq call so as to manage error code and retry 
     1335#D-* Examples: 
     1336#D- 
     1337function IGCM_sys_ncpdq { 
     1338  IGCM_debug_PushStack "IGCM_sys_ncpdq" $@ 
     1339  if ( $DEBUG_sys ) ; then 
     1340    echo "IGCM_sys_ncpdq :" $@ 
     1341  fi 
     1342 
     1343  typeset NB_ESSAI DELAI status i 
     1344  # number of tentative 
     1345  NB_ESSAI=3 
     1346  # time delay between tentative 
     1347  DELAI=2 
     1348 
     1349  i=0 
     1350  while [ $i -lt $NB_ESSAI ] ; do 
     1351    ncpdq -C $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1 
     1352    status=$? 
     1353    if [ ${status} -gt 0 ] ; then 
     1354      IGCM_debug_Print 2 "IGCM_sys_ncpdq : error code ${status}" 
     1355      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     1356      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     1357      IGCM_debug_Print 2 "IGCM_sys_ncpdq : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again." 
     1358      sleep $DELAI 
     1359    else 
     1360      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     1361      break 
     1362    fi 
     1363    (( i = i + 1 )) 
     1364  done 
     1365 
     1366  if [ ${status} -gt 0 ] ; then 
     1367    echo "IGCM_sys_ncpdq : ncpdq error" 
     1368    IGCM_debug_Exit "ncpdq" 
     1369  fi 
     1370 
     1371  IGCM_debug_PopStack "IGCM_sys_ncpdq" 
     1372} 
     1373 
     1374#D-#================================================== 
     1375#D-function IGCM_sys_ncra 
     1376#D-* Purpose: encapsulate ncra call so as to manage error code and retry 
     1377#D-* Examples: 
     1378#D- 
     1379function IGCM_sys_ncra { 
     1380  IGCM_debug_PushStack "IGCM_sys_ncra" $@ 
     1381  if ( $DEBUG_sys ) ; then 
     1382    echo "IGCM_sys_ncra :" $@ 
     1383  fi 
     1384 
     1385  typeset NB_ESSAI DELAI status i 
     1386  # number of tentative 
     1387  NB_ESSAI=3 
     1388  # time delay between tentative 
     1389  DELAI=2 
     1390 
     1391  i=0 
     1392  while [ $i -lt $NB_ESSAI ] ; do 
     1393    ncra -C $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1 
     1394    status=$? 
     1395    if [ ${status} -gt 0 ] ; then 
     1396      IGCM_debug_Print 2 "IGCM_sys_ncra : error code ${status}" 
     1397      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     1398      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     1399      IGCM_debug_Print 2 "IGCM_sys_ncra : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again." 
     1400      sleep $DELAI 
     1401    else 
     1402      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     1403      break 
     1404    fi 
     1405    (( i = i + 1 )) 
     1406  done 
     1407 
     1408  if [ ${status} -gt 0 ] ; then 
     1409    echo "IGCM_sys_ncra : ncra error" 
     1410    IGCM_debug_Exit "ncra" 
     1411  fi 
     1412 
     1413  IGCM_debug_PopStack "IGCM_sys_ncra" 
     1414} 
     1415 
     1416#D-#================================================== 
     1417#D-function IGCM_sys_ncrcat 
     1418#D-* Purpose: encapsulate ncrcat call so as to manage error code and retry 
     1419#D-* Examples: 
     1420#D- 
     1421function IGCM_sys_ncrcat { 
     1422  IGCM_debug_PushStack "IGCM_sys_ncrcat" $@ 
     1423  if ( $DEBUG_sys ) ; then 
     1424    echo "IGCM_sys_ncrcat :" $@ 
     1425  fi 
     1426 
     1427  typeset NB_ESSAI DELAI status i lastArg 
     1428  # number of tentative 
     1429  NB_ESSAI=3 
     1430  # time delay between tentative 
     1431  DELAI=2 
     1432 
     1433  i=0 
     1434  while [ $i -lt $NB_ESSAI ] ; do 
     1435    ncrcat -C $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1 
     1436    status=$? 
     1437    if [ ${status} -gt 0 ] ; then 
     1438      IGCM_debug_Print 2 "IGCM_sys_ncrcat : error code ${status}" 
     1439      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     1440      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     1441      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again." 
     1442      sleep $DELAI 
     1443    elif [ ! "X$( grep "WARNING Intra-file non-monotonicity" ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ )" = "X" ] ; then 
     1444      IGCM_debug_Print 2 "IGCM_sys_ncrcat : WARNING Intra-file non-monotonicity" 
     1445      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     1446      # remove files having corrupted time axis 
     1447      eval lastArg=\${$#} 
     1448      IGCM_debug_Print 2 "IGCM_sys_ncrcat : Delete ${lastArg}" 
     1449      \rm ${lastArg} 
     1450      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     1451      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again." 
     1452      sleep $DELAI 
     1453    else 
     1454      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     1455      break 
     1456    fi 
     1457    (( i = i + 1 )) 
     1458  done 
     1459 
     1460  if [ ${status} -gt 0 ] ; then 
     1461    echo "IGCM_sys_ncrcat : ncrcat error" 
     1462    #IGCM_debug_Exit "ncrcat" 
     1463  fi 
     1464 
     1465  IGCM_debug_PopStack "IGCM_sys_ncrcat" 
     1466} 
     1467 
     1468#D-#================================================== 
     1469#D-function IGCM_sys_ncrename 
     1470#D-* Purpose: encapsulate ncrename call so as to manage error code and retry 
     1471#D-* Examples: 
     1472#D- 
     1473function IGCM_sys_ncrename { 
     1474  IGCM_debug_PushStack "IGCM_sys_ncrename" $@ 
     1475  if ( $DEBUG_sys ) ; then 
     1476    echo "IGCM_sys_ncrename :" $@ 
     1477  fi 
     1478 
     1479  typeset NB_ESSAI DELAI status i 
     1480  # number of tentative 
     1481  NB_ESSAI=3 
     1482  # time delay between tentative 
     1483  DELAI=2 
     1484 
     1485  i=0 
     1486  while [ $i -lt $NB_ESSAI ] ; do 
     1487    ncrename $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1 
     1488    status=$? 
     1489    if [ ${status} -gt 0 ] ; then 
     1490      IGCM_debug_Print 2 "IGCM_sys_ncrename : error code ${status}" 
     1491      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     1492      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     1493      IGCM_debug_Print 2 "IGCM_sys_ncrename : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again." 
     1494      sleep $DELAI 
     1495    else 
     1496      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     1497      break 
     1498    fi 
     1499    (( i = i + 1 )) 
     1500  done 
     1501 
     1502  if [ ${status} -gt 0 ] ; then 
     1503    echo "IGCM_sys_ncrename : ncrename error" 
     1504    IGCM_debug_Exit "ncrename" 
     1505  fi 
     1506 
     1507  IGCM_debug_PopStack "IGCM_sys_ncrename" 
     1508} 
     1509 
     1510#D-#================================================== 
     1511#D-function IGCM_sys_ncwa 
     1512#D-* Purpose: encapsulate ncwa call so as to manage error code and retry 
     1513#D-* Examples: 
     1514#D- 
     1515function IGCM_sys_ncwa { 
     1516  IGCM_debug_PushStack "IGCM_sys_ncwa" $@ 
     1517  if ( $DEBUG_sys ) ; then 
     1518    echo "IGCM_sys_ncwa :" $@ 
     1519  fi 
     1520 
     1521  typeset NB_ESSAI DELAI status i 
     1522  # number of tentative 
     1523  NB_ESSAI=3 
     1524  # time delay between tentative 
     1525  DELAI=2 
     1526 
     1527  i=0 
     1528  while [ $i -lt $NB_ESSAI ] ; do 
     1529    ncwa -C $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1 
     1530    status=$? 
     1531    if [ ${status} -gt 0 ] ; then 
     1532      IGCM_debug_Print 2 "IGCM_sys_ncwa : error code ${status}" 
     1533      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     1534      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     1535      IGCM_debug_Print 2 "IGCM_sys_ncwa : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again." 
     1536      sleep $DELAI 
     1537    else 
     1538      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     1539      break 
     1540    fi 
     1541    (( i = i + 1 )) 
     1542  done 
     1543 
     1544  if [ ${status} -gt 0 ] ; then 
     1545    echo "IGCM_sys_ncwa : ncwa error" 
     1546    IGCM_debug_Exit "ncwa" 
     1547  fi 
     1548 
     1549  IGCM_debug_PopStack "IGCM_sys_ncwa" 
     1550} 
     1551 
     1552############################################################## 
     1553# CDO OPERATOR 
     1554 
     1555#D-#================================================== 
     1556#D-function IGCM_sys_cdo 
     1557#D-* Purpose: encapsulate cdo call so as to manage error code and retry 
     1558#D-* Examples: 
     1559#D- 
     1560function IGCM_sys_cdo { 
     1561  IGCM_debug_PushStack "IGCM_sys_cdo" $@ 
     1562  if ( $DEBUG_sys ) ; then 
     1563    echo "IGCM_sys_cdo :" $@ 
     1564  fi 
     1565 
     1566  typeset status 
     1567 
     1568  \cdo $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1 
     1569  status=$? 
     1570  if [ ${status} -gt 0 ] ; then 
     1571    echo "IGCM_sys_cdo : error code ${status}" 
     1572    cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     1573    \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 
     1574    IGCM_debug_PopStack "IGCM_sys_cdo" 
     1575    return 1 
     1576  else 
     1577    IGCM_debug_PopStack "IGCM_sys_cdo" 
     1578    return 0 
     1579  fi 
     1580 
     1581  IGCM_debug_PopStack "IGCM_sys_cdo" 
     1582} 
     1583 
     1584#  
Note: See TracChangeset for help on using the changeset viewer.