source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_obelix.ksh @ 968

Last change on this file since 968 was 968, checked in by jgipsl, 11 years ago

Removed readonly option for SUBMIT_DIR. RunChecker? and create_ts can not work with this option -r.

  • Property svn:keywords set to Revision Author Date
File size: 71.2 KB
RevLine 
[657]1#!/bin/ksh
[16]2
3#**************************************************************
4# Author: Sebastien Denvil, Martial Mancip, Christian Laguerre
[373]5# Contact: Martial.Mancip__at__ipsl.jussieu.fr
6# $Revision::                                          $ Revision of last commit
7# $Author::                                            $ Author of last commit
8# $Date::                                              $ Date of last commit
[16]9# IPSL (2006)
10#  This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC
[657]11#
[16]12#**************************************************************
13
14#=========================================================
15# The documentation of this file can be automatically generated
[657]16# if you use the prefix #D- for comments to be extracted.
[16]17# Extract with command: cat lib* | grep "^#D-" | cut -c "4-"
18#=========================================================
19
20#D-#==================================================
21#D-LibIGCM_sys for obelix
22#D-#==================================================
23#D-
[657]24#D- This ksh library if a layer under some usefull
[16]25#D-environment variables and shell commands.
26#D-All those definitions depend on host particularities.
27#D-It manages a stack mechanism and test validity of operations.
28#D-All function described bellow must be prefixed by IGCM_sys.
29
30#====================================================
31# libIGCM_sys PARAMETERS
32#====================================================
33
[343]34#====================================================
[16]35# set DEBUG_sys to true to output calls of function
36typeset -r DEBUG_sys=${DEBUG_sys:=true}
37
[343]38#====================================================
[16]39# Turn in dry run mode ? (sys_Put_Rest, sys_Put_Out, sys_Get)
40typeset -r DRYRUN=${DRYRUN:=0}
41
42# YOU MUST COMPILE YOUR EXE FILES FOR DRYRUN MODE !
43# -------------------------------------------------------------------------------------
44# | DRYRUN=  |  Date computations, | sys_Get    |  Exe    | sys_Put_Out; sys_Put_Rest |
[809]45# |          |  Cp/Exe/param/files |            |         |                           |
46# |          |  Chmod Qsub         |            |         |                           |
[16]47# -------------------------------------------------------------------------------------
48# |    0     |       yes           |    yes     |  yes    |      yes                  |
49# -------------------------------------------------------------------------------------
50# |    1     |       yes           |    yes     |  yes    |      no                   |
51# -------------------------------------------------------------------------------------
52# |    2     |       yes           |    yes     |  no     |      no                   |
53# -------------------------------------------------------------------------------------
54# |    3     |       yes           |    no      |  no     |      no                   |
55# -------------------------------------------------------------------------------------
56
57#=====================================================
58# Global Variables :
59#=====================================================
60# Language : "fr" or "en"
61typeset -r MYLANG="fr"
62
63#=====================================================
[657]64# Host and user names
[217]65# $hostname ou hostname
[800]66typeset  HOST=${HOST:=$( hostname )}
[16]67# $username ou whoami
[800]68typeset  LOGIN=${LOGIN:=$( whoami )}
[657]69# $hostname of the MASTER job
[742]70typeset MASTER=${MASTER:=$( hostname )}
[16]71
72#D-
73#D-#==================================================
74#D-Program used in libIGCM
75#D-#==================================================
76
[742]77# Submit command
78typeset SUBMIT=${SUBMIT:=qsub}
[16]79# rsync with path
80typeset -r RSYNC=/usr/bin/rsync
81# RSYNC_opt args to rsync
[282]82typeset -r RSYNC_opt="-va"
[657]83# ie storage filesystem
84typeset -r STOREHOST=${MASTER}
[16]85
86#====================================================
[305]87# Set environment tools (ferret, nco, cdo)
88#====================================================
[16]89. /home/users/brock/.atlas_env_asterix_ksh
90
[343]91#====================================================
[421]92# Set lf95 environment
93#====================================================
94. /usr/local/install/lf6481/bash_laheyfort_setup
95
96#====================================================
[16]97# Host specific DIRECTORIES
98#====================================================
99
100#====================================================
[657]101#- MirrorlibIGCM for frontend
102typeset -r MirrorlibIGCM=${MirrorlibIGCM:=false}
103
104#====================================================
105#- libIGCM_POST for frontend
106typeset -r libIGCM_POST=${libIGCM}
107
108#====================================================
[16]109#- R_EXE   (==> BIN_DIR = ${MODIPSL}/bin )
110typeset -r R_EXE="${MODIPSL}/bin"
111
112#====================================================
113#- SUBMIT_DIR : submission dir
[256]114if [ X${PBS_O_WORKDIR} != X ] ; then
[968]115  typeset SUBMIT_DIR=${SUBMIT_DIR:=${PBS_O_WORKDIR}}
[256]116else
[968]117  typeset SUBMIT_DIR=${SUBMIT_DIR:=${PWD}}
[256]118fi
[657]119
[16]120#====================================================
[725]121#- IN
122typeset -r R_IN=${R_IN:=/home/orchidee01/mmancip/IGCM}
123
124#====================================================
[811]125#- ARCHIVE
[800]126typeset ARCHIVE=${ARCHIVE:=/home/scratch01/${LOGIN}}
[16]127
[725]128#====================================================
129#- STORAGE (dedicated to small/medium files)
[800]130typeset STORAGE=${ARCHIVE}
[282]131
132#====================================================
[717]133#- R_OUT
[800]134typeset R_OUT=${ARCHIVE}/IGCM_OUT
[16]135
136#====================================================
[657]137#- R_FIG (hosting figures : monitoring and atlas, and/or small files)
[800]138typeset R_FIG=${STORAGE}/IGCM_OUT
[657]139
140#====================================================
141#- R_BUF (ONLY FOR double copy an scratch)
[800]142typeset -r R_BUF=${STORAGE}/IGCM_OUT
[657]143
144#====================================================
[16]145#- RUN_DIR_PATH : Temporary working directory (=> TMP)
[838]146if [ X${PBS_JOBID} != X ] ; then
147  typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=/scratch/$PBS_O_LOGNAME.$PBS_JOBID}
148else
[839]149  typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=/tmp/tmp$$}
[838]150fi
[16]151
152#====================================================
153#- HOST_MPIRUN_COMMAND
154typeset -r HOST_MPIRUN_COMMAND=${HOST_MPIRUN_COMMAND:="time mpirun"}
155
[61]156#====================================================
157#- Max number of arguments passed to nco operator or demigration command
158UNIX_MAX_LIMIT=360
159
[657]160#====================================================
161#- Number of core per node (max number of OpenMP task)
162NUM_COREPERNODE=1
163
164#====================================================
165#- Default number of MPI task for IPSL coupled model
166#- required for backward compatibility
167#-
168DEFAULT_NUM_PROC_OCE=1
169DEFAULT_NUM_PROC_CPL=1
170(( DEFAULT_NUM_PROC_ATM = BATCH_NUM_PROC_TOT - DEFAULT_NUM_PROC_OCE - DEFAULT_NUM_PROC_CPL ))
171DEFAULT_NUM_PROC_TOTAL=${BATCH_NUM_PROC_TOT}
172
[16]173#D-#==================================================
[725]174#D-function IGCM_sys_ChangeArchive
175#D-* Purpose: Just a dummy call on this machine
176#D-* Examples:
177#D-
178function IGCM_sys_ChangeArchive {
179  IGCM_debug_Print 1 " dummy function : IGCM_sys_ChangeArchive "
180}
181
182#D-#==================================================
[16]183#D-function IGCM_sys_RshMaster
[800]184#D-* Purpose: Connection to frontend machine.
[16]185#D-* Examples:
186#D-
187function IGCM_sys_RshMaster {
[657]188  IGCM_debug_PushStack "IGCM_sys_RshMaster" $@
[862]189  /bin/ksh  <<-EOF
[16]190    export libIGCM=${libIGCM}
[98]191    export DEBUG_debug=${DEBUG_debug}
[16]192    . ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh
193    . ${libIGCM}/libIGCM_card/libIGCM_card.ksh
194    ${@}
195EOF
[657]196  if [ $? -gt 0 ] ; then
197    echo "IGCM_sys_RshMaster : erreur."
198    IGCM_debug_Exit "IGCM_sys_RshMaster"
199  fi
200  IGCM_debug_PopStack "IGCM_sys_RshMaster"
[16]201}
202
203#D-#==================================================
[37]204#D-function IGCM_sys_RshArchive
205#D-* Purpose: Archive rsh command
206#D-* Examples:
207#D-
208function IGCM_sys_RshArchive {
[657]209  IGCM_debug_PushStack "IGCM_sys_RshArchive" $@
210  /bin/ksh <<-EOF
[40]211    ${@}
212EOF
[811]213  status=$?
214  if [ ${status} -gt 0 ] ; then
215    IGCM_debug_Print 2 "IGCM_sys_RshArchive : command failed error code ${status}"
[657]216    IGCM_debug_Exit "IGCM_sys_RshArchive"
217  fi
218  IGCM_debug_PopStack "IGCM_sys_RshArchive"
[37]219}
220
221#D-#==================================================
[16]222#D-function IGCM_sys_RshPost
[282]223#D-* Purpose: Post-process rsh command
[16]224#D-* Examples:
225#D-
226function IGCM_sys_RshPost {
[657]227  IGCM_debug_PushStack "IGCM_sys_RshPost" $@
228  if ( $DEBUG_sys ) ; then
229    echo "IGCM_sys_RshPost :" $@
230  fi
[800]231
232  # keep standard input (stdin) for the loop onto temporary file
233  cat >tmp_IGCM_sys_RshPost_$$
234
235# ============ FRONTEND START ============ #
236
[862]237  /bin/ksh <tmp_IGCM_sys_RshPost_$$
[657]238  if [ $? -gt 0 ] ; then
239    echo "IGCM_sys_RshPost : erreur."
240    IGCM_debug_Exit "IGCM_sys_RshPost"
241  fi
[800]242  # delete temporary file
243  \rm tmp_IGCM_sys_RshPost_$$
[657]244  IGCM_debug_PopStack "IGCM_sys_RshPost"
[16]245}
246
247#D-#==================================================
[153]248#D-function IGCM_sys_SendMail
249#D-* Purpose: Send mail when simulation is over
250#D-* Examples:
251#D-
252function IGCM_sys_SendMail {
[657]253  IGCM_debug_PushStack "IGCM_sys_SendMail" $@
254  if ( $DEBUG_sys ) ; then
255    echo "IGCM_sys_SendMail :" $@
256  fi
[153]257
[922]258  if [ X${1} = XAccounting ] ; then
259    status=Accounting
260    mailText=jobAccounting.mail
261  elif ( ${ExitFlag} ) ; then
[657]262    status=failed
[922]263    mailText=jobEnd.mail
[657]264  else
265    status=completed
[922]266    mailText=jobEnd.mail
[657]267  fi
[717]268
[922]269  # Update selected mail template
270  while read -r line; do
271    eval echo $line >> mail.txt ;
272  done < ${libIGCM}/libIGCM_sys/${mailText}
[153]273
[657]274  if [ ! -z ${config_UserChoices_MailName} ] ; then
[922]275    mailx -s "${config_UserChoices_JobName} ${status}" ${config_UserChoices_MailName} < mail.txt
[657]276  elif [ -f ~/.forward ] ; then
[922]277    mailx -s "${config_UserChoices_JobName} ${status}" $( cat ~/.forward ) < mail.txt
[657]278  fi
[153]279
[811]280  sleep 10
[922]281  rm -f mail.txt
[811]282
[657]283  IGCM_debug_PopStack "IGCM_sys_SendMail"
[153]284}
285
286#D-#==================================================
[16]287#D-function IGCM_sys_Mkdir
288#D-* Purpose: Master locale mkdir command
289#D-* Examples:
290#D-
291function IGCM_sys_Mkdir {
[657]292  IGCM_debug_PushStack "IGCM_sys_Mkdir" $@
293  if ( $DEBUG_sys ) ; then
294    echo "IGCM_sys_Mkdir :" $@
295  fi
296  if [ ! -d ${1} ]; then
297    \mkdir -p $1
298    if [ $? -gt 0 ] ; then
299      echo "IGCM_sys_Mkdir : erreur."
300      IGCM_debug_Exit "IGCM_sys_Mkdir"
[16]301    fi
[657]302  fi
[717]303  # vérification :
[657]304  if [ ! -d ${1} ] ; then
305    echo "IGCM_sys_Mkdir : erreur."
306    IGCM_debug_Exit "IGCM_sys_Mkdir"
307  fi
308  IGCM_debug_PopStack "IGCM_sys_Mkdir"
[16]309}
310
311#D-#==================================================
312#D-function IGCM_sys_MkdirArchive
313#D-* Purpose: Mkdir on Archive
314#D-* Examples:
315#D-
316function IGCM_sys_MkdirArchive {
[657]317  IGCM_debug_PushStack "IGCM_sys_MkdirArchive" $@
318  if ( $DEBUG_sys ) ; then
319    echo "IGCM_sys_MkdirArchive :" $@
320  fi
[717]321  #- creation de repertoire sur le serveur fichier
[657]322  if [ ! -d ${1} ]; then
[811]323    mkdir -p $1
324    status=$?
325
326    if [ ${status} -gt 0 ] ; then
327      IGCM_debug_Print 2 "IGCM_sys_MkdirArchive : mkdir failed error code ${status}"
[657]328      IGCM_debug_Exit "IGCM_sys_MkdirArchive"
[16]329    fi
[657]330  fi
331  IGCM_debug_PopStack "IGCM_sys_MkdirArchive"
[16]332}
333
334#D-#==================================================
335#D-function IGCM_sys_MkdirWork
336#D-* Purpose: Mkdir on Work
337#D-* Examples:
338#D-
339function IGCM_sys_MkdirWork {
[657]340  IGCM_debug_PushStack "IGCM_sys_MkdirWork" $@
341  if ( $DEBUG_sys ) ; then
342    echo "IGCM_sys_MkdirWork :" $@
343  fi
[717]344  #- creation de repertoire sur le serveur fichier
[657]345  if [ ! -d ${1} ]; then
346    \mkdir -p $1
347    if [ $? -gt 0 ] ; then
348      echo "IGCM_sys_MkdirWork : erreur."
349      IGCM_debug_Exit "IGCM_sys_MkdirWork"
[16]350    fi
[657]351  fi
352  IGCM_debug_PopStack "IGCM_sys_MkdirWork"
[16]353}
354
355#D-#==================================================
356#D-function IGCM_sys_Cd
357#D-* Purpose: master cd command
358#D-* Examples:
359#D-
360function IGCM_sys_Cd {
[657]361  IGCM_debug_PushStack "IGCM_sys_Cd" $@
362  if ( $DEBUG_sys ) ; then
363    echo "IGCM_sys_Cd :" $@
364  fi
365  \cd $1
366  if [ $? -gt 0 ] ; then
367    echo "IGCM_sys_Cd : erreur."
368    IGCM_debug_Exit "IGCM_sys_Cd"
369  fi
370  IGCM_debug_PopStack "IGCM_sys_Cd"
[16]371}
372
373#D-#==================================================
374#D-function IGCM_sys_Chmod
375#D-* Purpose: Chmod
376#D-* Examples:
377#D-
378function IGCM_sys_Chmod {
[657]379  IGCM_debug_PushStack "IGCM_sys_Chmod" -- $@
380  if ( $DEBUG_sys ) ; then
381    echo "IGCM_sys_Chmod :" $@
382  fi
[809]383  \chmod $@
384  if [ $? -gt 0 ] ; then
385    echo "IGCM_sys_Chmod : erreur."
386    IGCM_debug_Exit "IGCM_sys_Chmod"
[657]387  fi
388  IGCM_debug_PopStack "IGCM_sys_Chmod"
[16]389}
390
391#D-#==================================================
392#D-function IGCM_sys_FileSize
393#D-* Purpose: Filesize
394#D-* Examples:
395#D-
396function IGCM_sys_FileSize {
[657]397  IGCM_debug_PushStack "IGCM_sys_FileSize" $@
[16]398
[657]399  typeset sizeF
400  set +A sizeF -- $( ls -la ${1} )
401  if [ $? -gt 0 ] ; then
402    IGCM_debug_Exit "IGCM_sys_FileSize"
403  fi
404  eval ${2}=${sizeF[4]}
[16]405
[657]406  IGCM_debug_PopStack "IGCM_sys_FileSize"
[16]407}
408
409#D-#==================================================
410#D-function IGCM_sys_TestDir
411#D-* Purpose: Test Directory that must exists
412#D-* Examples:
413#D-
414function IGCM_sys_TestDir {
[657]415  IGCM_debug_PushStack "IGCM_sys_TestDir" $@
416  if ( $DEBUG_sys ) ; then
417    echo "IGCM_sys_TestDir :" $@
418  fi
419  typeset ExistFlag
420  ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
421  IGCM_debug_PopStack "IGCM_sys_TestDir"
[67]422
[657]423  return ${ExistFlag}
[16]424}
425
426#D-#==================================================
427#D-function IGCM_sys_TestDirArchive
428#D-* Purpose: Test Directory that must exists on Archive
429#D-* Examples:
430#D-
431function IGCM_sys_TestDirArchive {
[657]432  IGCM_debug_PushStack "IGCM_sys_TestDirArchive" $@
433  if ( $DEBUG_sys ) ; then
434    echo "IGCM_sys_TestDirArchive :" $@
435  fi
436  typeset ExistFlag
437  ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
438  IGCM_debug_PopStack "IGCM_sys_TestDirArchive"
439  return ${ExistFlag}
[16]440}
441
442#D-#==================================================
[800]443#D-function IGCM_sys_IsFileArchived
444#D-* Purpose: Test file that must NOT EXISTS on Archive
445#D-* Examples:
446#D-
447function IGCM_sys_IsFileArchived {
448  IGCM_debug_PushStack "IGCM_sys_IsFileArchived" $@
449  if ( $DEBUG_sys ) ; then
450    echo "IGCM_sys_IsFileArchived :" $@
451  fi
452  typeset IsArchivedFlag
453  # Never archived for this system
454  IsArchivedFlag=1
455  IGCM_debug_PopStack "IGCM_sys_IsFileArchived"
456
457  return ${IsArchivedFlag}
458}
459
460#D-#==================================================
[16]461#D-function IGCM_sys_TestFileArchive
462#D-* Purpose: Test file that must NOT EXISTS on Archive
463#D-* Examples:
464#D-
465function IGCM_sys_TestFileArchive {
[657]466  IGCM_debug_PushStack "IGCM_sys_TestFileArchive" $@
467  typeset ExistFlag
468  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
469  IGCM_debug_PopStack "IGCM_sys_TestFileArchive"
[67]470
[657]471  return ${ExistFlag}
[67]472}
473
474#D-#==================================================
[657]475#D-function IGCM_sys_TestFileBuffer
476#D-* Purpose: Test file that must NOT EXISTS on Buffer
477#D-* Examples:
478#D-
479function IGCM_sys_TestFileBuffer {
480  IGCM_debug_PushStack "IGCM_sys_TestFileBuffer" $@
481  typeset ExistFlag
482  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
483  IGCM_debug_PopStack "IGCM_sys_TestFileBuffer"
484
485  return ${ExistFlag}
486}
487
488#D-#==================================================
[67]489#D-function IGCM_sys_CountFileArchive
490#D-* Purpose: Count files on Archive filesystem
491#D-* Examples:
492#D-
493function IGCM_sys_CountFileArchive {
[657]494  IGCM_debug_PushStack "IGCM_sys_CountFileArchive" $@
495  ls ${@} 2>/dev/null | wc -l
496  if [ $? -gt 0 ] ; then
497    echo "IGCM_sys_CountFileArchive : erreur."
498  fi
499  IGCM_debug_PopStack "IGCM_sys_CountFileArchive"
[16]500}
501
502#D-#==================================================
[657]503#D-function IGCM_sys_CountFileBuffer
504#D-* Purpose: Count files on Scratch filesystem
505#D-* Examples:
506#D-
507function IGCM_sys_CountFileBuffer {
508  IGCM_debug_PushStack "IGCM_sys_CountFileBuffer" $@
509  ls ${@} 2>/dev/null | wc -l
510  if [ $? -gt 0 ] ; then
511    echo "IGCM_sys_CountFileBuffer : erreur."
512  fi
513  IGCM_debug_PopStack "IGCM_sys_CountFileBuffer"
514}
515
516#D-#==================================================
[16]517#D-function IGCM_sys_Tree
518#D-* Purpose: Tree directories with files on ${ARCHIVE}
519#D-* Examples: IGCM_sys_Tree ${R_IN} ${R_OUT}
520#D-
521function IGCM_sys_Tree {
[657]522  IGCM_debug_PushStack "IGCM_sys_Tree" $@
523  if ( $DEBUG_sys ) ; then
524    echo "IGCM_sys_Tree :" $@
525  fi
[16]526
[657]527  \tree -f $@
[16]528
[657]529  IGCM_debug_PopStack "IGCM_sys_Tree"
[16]530}
531
532#D-#==================================================
533#D-function IGCM_sys_Tar
[657]534#D-* Purpose: master tar command
[16]535#D-* Examples:
536#D-
537function IGCM_sys_Tar {
[657]538  IGCM_debug_PushStack "IGCM_sys_Tar" $@
539  if ( $DEBUG_sys ) ; then
540    echo "IGCM_sys_Tar :" $@
541  fi
542  \tar cf $@
543  if [ $? -gt 0 ] ; then
544    echo "IGCM_sys_Tar : erreur."
545    IGCM_debug_Exit "IGCM_sys_Tar"
546  fi
547  IGCM_debug_PopStack "IGCM_sys_Tar"
[16]548}
549
550#D-#==================================================
551#D-function IGCM_sys_UnTar
552#D-* Purpose: master un-tar command
553#D-* Examples:
554#D-
555function IGCM_sys_UnTar {
[657]556  IGCM_debug_PushStack "IGCM_sys_UnTar" $@
557  if ( $DEBUG_sys ) ; then
558    echo "IGCM_sys_UnTar :" $@
559  fi
560  \tar xvf $1
561  if [ $? -gt 0 ] ; then
562    echo "IGCM_sys_UnTar : erreur."
563    IGCM_debug_Exit "IGCM_sys_UnTar"
564  fi
565  IGCM_debug_PopStack "IGCM_sys_UnTar"
[16]566}
567
568#D-#==================================================
569#D-function IGCM_sys_Qsub
570#D-* Purpose: Qsub new job
571#D-* Examples:
572#D-
573function IGCM_sys_Qsub {
[657]574  IGCM_debug_PushStack "IGCM_sys_Qsub" $@
575  if ( $DEBUG_sys ) ; then
576    echo "IGCM_sys_Qsub :" $@
577  fi
[923]578  typeset options status
579  options="-o ${SUBMIT_DIR}/${Script_Output}"
[949]580  /usr/local/bin/qsub ${options} $1 > /tmp/out_command.$$ 2>&1
[811]581  status=$?
[949]582
583  cat /tmp/out_command.$$
[811]584  if [ ${status} -gt 0 ] ; then
585    IGCM_debug_Print 2 "IGCM_sys_Qsub $1 : error code ${status}"
[657]586    IGCM_debug_Exit "IGCM_sys_Qsub"
[949]587  else
588    JobID=$( gawk {'print $1'} /tmp/out_command.$$ )
[657]589  fi
590  IGCM_debug_PopStack "IGCM_sys_Qsub"
[16]591}
592
593#D-#==================================================
594#D-function IGCM_sys_QsubPost
595#D-* Purpose: Qsub new job on scalaire
596#D-* Examples:
597#D-
598function IGCM_sys_QsubPost {
[657]599  IGCM_debug_PushStack "IGCM_sys_QsubPost" $@
600  if ( $DEBUG_sys ) ; then
601    echo "IGCM_sys_QsubPost :" $@
602  fi
[923]603  typeset options status
604  options="-o ${POST_DIR}/${Script_Post_Output}.out -v ${listVarEnv}"
[949]605  /usr/local/bin/qsub ${options} ${libIGCM_POST}/$1.job > /tmp/out_command.$$ 2>&1
[811]606  status=$?
[949]607
608  cat /tmp/out_command.$$
[811]609  if [ ${status} -gt 0 ] ; then
[923]610    IGCM_debug_Print 2 "IGCM_sys_QsubPost ${options} ${libIGCM_POST}/$1.job : error code ${status}"
[657]611    IGCM_debug_Exit "IGCM_sys_QsubPost"
[949]612  else
613    JobID=$( gawk {'print $1'} /tmp/out_command.$$ )
[657]614  fi
615  IGCM_debug_PopStack "IGCM_sys_QsubPost"
[16]616}
617
618#D-*************************
[657]619#D- File transfer functions
[16]620#D-*************************
621#D-
622
623#D-#==================================================
624#D-function IGCM_sys_Rsync_out
625#D-* Purpose: treat return val of rsync
626#D-* Examples: IGCM_sys_Rsync_out out_RET_rsync
627#D-  Error values and explanations can depend on your system version.
628function IGCM_sys_Rsync_out {
[717]629  status=$1
630  if [ ! $status ] ; then
[657]631    echo "rsync error !"
632  fi
[16]633
[657]634  if [ $MYLANG = "fr" ]; then
[717]635    case $status in
[657]636    0)  return ;;
637    1)  echo "Erreur de rsync ; RERR_SYNTAX : "
638      echo "Erreur de syntaxe ou d'utilisation."
639      return;;
640    2)  echo "Erreur de rsync ; RERR_PROTOCOL : "
641      echo "Incompatibilité de protocole."
642      return;;
643    3)  echo "Erreur de rsync ; RERR_FILESELECT 3"
644      echo "Erreurs  lors  de  la  sélection des fichiers d'entrée sortie et"
645      echo "répertoires"
646      return;;
647    4)  echo "Erreur de rsync ; RERR_UNSUPPORTED"
648      echo "Action demandée non supportée : une tentative de manipulation de"
649      echo "fichiers  64-bits  sur une plate-forme qui ne les supporte pas a"
650      echo "été faite ; ou une option qui est supportée par le  client  mais"
651      echo "pas par le serveur a été spécifiée."
652      return;;
653    10) echo "Erreur de rsync ; RERR_SOCKETIO"
654      echo "Erreur dans le socket d'entrée sortie"
655      return;;
656    11) echo "Erreur de rsync ; RERR_FILEIO"
657      echo "Erreur d'entrée sortie fichier"
658      return;;
659    12) echo "Erreur de rsync ; RERR_STREAMIO"
660      echo "Erreur dans flux de donnée du protocole rsync"
661      return;;
662    13) echo "Erreur de rsync ; RERR_MESSAGEIO"
663      echo "Erreur avec les diagnostics du programme"
664      return;;
665    14) echo "Erreur de rsync ; RERR_IPC"
666      echo "Erreur dans le code IPC"
667      return;;
668    20) echo "Erreur de rsync ; RERR_SIGNAL"
669      echo "SIGUSR1 ou SIGINT reçu"
670      return;;
671    21) echo "Erreur de rsync ; RERR_WAITCHILD"
672      echo "Une erreur retournée par waitpid()"
673      return;;
674    22) echo "Erreur de rsync ; RERR_MALLOC"
675      echo "Erreur lors de l'allocation des tampons de mémoire de coeur"
676      return;;
677    23) echo ""
678      echo "Erreur fichier inexistant"
679      return;;
680    30) echo "Erreur de rsync ; RERR_TIMEOUT"
681      echo "Temps d'attente écoulé dans l'envoi/réception de données"
682      return;;
[717]683    *)  echo "Erreur de rsync : code de retour de rsync inconnu :" $status
[657]684      return;;
685    esac
686  elif [ $MYLANG = "en" ] ; then
[717]687    case $status in
[657]688    0)  return;;
689    1)  echo "rsync error : Syntax or usage error "
690      return;;
691    2)  echo "rsync error : Protocol incompatibility "
692      return;;
693    3)  echo "rsync error : Errors selecting input/output files, dirs"
694      return;;
695    4)  echo "rsync error : Requested action not supported: an attempt"
696      echo "was made to manipulate 64-bit files on a platform that cannot support"
697      echo "them; or an option was specified that is supported by the client and"
698      echo "not by the server."
699      return;;
700    5)  echo "rsync error : Error starting client-server protocol"
701      return;;
702    10) echo "rsync error : Error in socket I/O "
703      return;;
704    11) echo "rsync error : Error in file I/O "
705      return;;
706    12) echo "rsync error : Error in rsync protocol data stream "
707      return;;
708    13) echo "rsync error : Errors with program diagnostics "
709      return;;
710    14) echo "rsync error : Error in IPC code "
711      return;;
712    20) echo "rsync error : Received SIGUSR1 or SIGINT "
713      return;;
714    21) echo "rsync error : Some error returned by waitpid() "
715      return;;
716    22) echo "rsync error : Error allocating core memory buffers "
717      return;;
718    23) echo "rsync error : Partial transfer due to error"
719      return;;
720    24) echo "rsync error : Partial transfer due to vanished source files"
721      return;;
722    30) echo "rsync error : Timeout in data send/receive "
723      return;;
[717]724    *)  echo "rsync error : return code of rsync unknown :" $status
[657]725      return;;
726    esac
727  else
728    echo "unknown language $MYLANG."
729    return
730  fi
[16]731}
[657]732
[16]733#D-#==================================================
[811]734#D-function IGCM_sys_Miror_libIGCM
735#D-* Purpose: Mirror libIGCM PATH and lib to frontend
736#D-* Examples:
737#D-
738function IGCM_sys_Mirror_libIGCM {
739  IGCM_debug_PushStack "IGCM_sys_Mirror_libIGCM"
740  if ( $DEBUG_sys ) ; then
741    echo "IGCM_sys_Mirror_libIGCM"
742  fi
743
744  typeset status
745
746  mkdir -p ${HOME}/MIRROR/${PATHlibIGCM}
747
[938]748  echo ${RSYNC} ${RSYNC_opt} ${libIGCM} ${HOME}/MIRROR/${PATHlibIGCM} > /tmp/out_command.$$ 2>&1
749  ${RSYNC} ${RSYNC_opt} ${libIGCM} ${HOME}/MIRROR/${PATHlibIGCM} >> /tmp/out_command.$$ 2>&1
[811]750  status=$?
751
752  if [ ${status} -gt 0 ] ; then
753    echo "IGCM_sys_Mirror_libIGCM Warning : no libIGCM on frontend."
[938]754    cat /tmp/out_command.$$
[811]755  fi
756  IGCM_debug_PopStack "IGCM_sys_Mirror_libIGCM"
757}
758
759#D-#==================================================
[16]760#D-function IGCM_sys_Cp
761#D-* Purpose: generic cp
762#D-* Examples:
763#D-
764function IGCM_sys_Cp {
[657]765  IGCM_debug_PushStack "IGCM_sys_Cp" $@
766  if ( $DEBUG_sys ) ; then
767    echo "IGCM_sys_Cp :" $@
768  fi
[16]769
[717]770  typeset status
[16]771
[938]772  echo cp $@ > /tmp/out_command.$$ 2>&1
773  \cp $@ >> /tmp/out_command.$$ 2>&1
[717]774  status=$?
[657]775
[717]776  if [ ${status} -gt 0 ] ; then
777    echo "IGCM_sys_Cp : error code ${status}"
[938]778    cat /tmp/out_command.$$
[657]779    IGCM_debug_Exit "IGCM_sys_Cp"
780  else
[938]781    \rm /tmp/out_command.$$
[657]782  fi
783  IGCM_debug_PopStack "IGCM_sys_Cp"
[16]784}
785
786#D-#==================================================
787#D-function IGCM_sys_Rm
788#D-* Purpose: generic rm
789#D-* Examples:
790#D-
791function IGCM_sys_Rm {
[657]792  IGCM_debug_PushStack "IGCM_sys_Rm" -- $@
793  if ( $DEBUG_sys ) ; then
794    echo "IGCM_sys_Rm :" $@
795  fi
[16]796
[717]797  typeset status
[16]798
[938]799  echo rm $@ > /tmp/out_command.$$ 2>&1
800  \rm $@ >> /tmp/out_command.$$ 2>&1
[717]801  status=$?
[657]802
[717]803  if [ ${status} -gt 0 ] ; then
804    echo "IGCM_sys_Rm : error code ${status}"
[938]805    cat /tmp/out_command.$$
[657]806    IGCM_debug_Exit "IGCM_sys_Rm"
807  else
[938]808    \rm /tmp/out_command.$$
[657]809  fi
810  IGCM_debug_PopStack "IGCM_sys_Rm"
[16]811}
812
813#D-#==================================================
[203]814#D-function IGCM_sys_RmRunDir
815#D-* Purpose: rm tmpdir (dummy function most of the time batch
816#D-                      scheduler will do the job)
817#D-* Examples:
818#D-
819function IGCM_sys_RmRunDir {
[657]820  IGCM_debug_PushStack "IGCM_sys_RmRunDir" -- $@
821  if ( $DEBUG_sys ) ; then
822    echo "IGCM_sys_RmRunDir :" $@
[964]823    echo "Dummy call, let the scheduler do that."
[657]824  fi
825  IGCM_debug_PopStack "IGCM_sys_RmRunDir"
[203]826}
827
828#D-#==================================================
[16]829#D-function IGCM_sys_Mv
830#D-* Purpose: generic move
831#D-* Examples:
832#D-
833function IGCM_sys_Mv {
[657]834  IGCM_debug_PushStack "IGCM_sys_Mv" $@
835  if ( $DEBUG_sys ) ; then
836    echo "IGCM_sys_Mv :" $@
837  fi
[16]838
[657]839  if [ $DRYRUN = 0 ]; then
[16]840
[717]841    typeset status
[657]842
[938]843    echo mv $@ > /tmp/out_command.$$ 2>&1
844    \mv $@ >> /tmp/out_command.$$ 2>&1
[717]845    status=$?
[657]846
[717]847    if [ ${status} -gt 0 ] ; then
848      echo "IGCM_sys_Mv : error code ${status}"
[938]849      cat /tmp/out_command.$$
[657]850      IGCM_debug_Exit "IGCM_sys_Mv"
[173]851    else
[938]852      \rm /tmp/out_command.$$
[16]853    fi
[657]854  fi
855  IGCM_debug_PopStack "IGCM_sys_Mv"
[16]856}
857
858#D-#==================================================
859#D-function IGCM_sys_Put_Dir
860#D-* Purpose: Copy a complete directory on $(ARCHIVE)
861#D-* Examples:
862#D-
863function IGCM_sys_Put_Dir {
[657]864  IGCM_debug_PushStack "IGCM_sys_Put_Dir" $@
865  if ( $DEBUG_sys ) ; then
866    echo "IGCM_sys_Put_Dir :" $@
867  fi
868  if [ $DRYRUN = 0 ]; then
869    if [ ! -d ${1} ] ; then
870      echo "WARNING : IGCM_sys_Put_Dir ${1} DOES NOT EXIST ."
871      IGCM_debug_PopStack "IGCM_sys_Put_Dir"
872      return
[16]873    fi
874
[717]875    typeset status
[16]876
[717]877    # Only if we use rsync
878    #IGCM_sys_TestDirArchive $( dirname $2 )
879    #
880    #USUAL WAY
[938]881    \cp -r $1 $2 > /tmp/out_command.$$ 2>&1
[717]882    status=$?
[16]883
[717]884    if [ ${status} -gt 0 ] ; then
[811]885      IGCM_debug_Print 2 "IGCM_sys_Put_Dir : cp failed error code ${status}"
[938]886      cat /tmp/out_command.$$
[657]887      IGCM_debug_Exit "IGCM_sys_Put_Dir"
[16]888    else
[938]889      \rm /tmp/out_command.$$
[16]890    fi
[657]891  fi
892  IGCM_debug_PopStack "IGCM_sys_Put_Dir"
[16]893}
894
895#D-#==================================================
896#D-function IGCM_sys_Get_Dir
[717]897#D-* Purpose: Copy a complete directory from ${ARCHIVE}
[16]898#D-* Examples:
899#D-
900function IGCM_sys_Get_Dir {
[657]901  IGCM_debug_PushStack "IGCM_sys_Get_Dir" $@
902  if ( $DEBUG_sys ) ; then
903    echo "IGCM_sys_Get_Dir :" $@
904  fi
905  if [ $DRYRUN = 0 ]; then
906    if [ ! -d ${1} ] ; then
907      echo "WARNING : IGCM_sys_Get_Dir ${1} DOES NOT EXIST ."
908      IGCM_debug_PopStack "IGCM_sys_Get_Dir"
909      return
[16]910    fi
911
[717]912    typeset status
[16]913
[719]914    #USUAL WAY
[938]915    \cp -ur $1 $2 > /tmp/out_command.$$ 2>&1
[717]916    status=$?
[16]917
[717]918    if [ ${status} -gt 0 ] ; then
[811]919      IGCM_debug_Print 2 "IGCM_sys_Get_Dir : cp failed error code ${status}"
[938]920      cat /tmp/out_command.$$
[657]921      IGCM_debug_Exit "IGCM_sys_Get_Dir"
[16]922    else
[938]923      \rm /tmp/out_command.$$
[16]924    fi
[657]925  fi
926  IGCM_debug_PopStack "IGCM_sys_Get_Dir"
[16]927}
928
929#D-#==================================================
930#D-function IGCM_sys_Get_Master
931#D-* Purpose: Copy a complete directory from MASTER filesystem
932#D-* Examples:
933#D-
934function IGCM_sys_Get_Master {
[657]935  IGCM_debug_PushStack "IGCM_sys_Get_Master" $@
936  if ( $DEBUG_sys ) ; then
937    echo "IGCM_sys_Get_Master :" $@
938  fi
939  if [ $DRYRUN = 0 ]; then
940    if ( [ ! -d ${1} ] && [ ! -f ${1} ] ) ; then
941      echo "WARNING : IGCM_sys_Get_Master ${1} DOES NOT EXIST ."
942      IGCM_debug_PopStack "IGCM_sys_Get_Master"
943      return
[16]944    fi
945
[811]946    typeset NB_ESSAI DELAI status i
947    # number of tentative
948    NB_ESSAI=3
949    # time delay between tentative
950    DELAI=2
[16]951
[811]952    i=0
953    while [ $i -lt $NB_ESSAI ] ; do
[938]954      \cp -urL $1 $2 > /tmp/out_command.$$ 2>&1
[811]955      status=$?
956      if [ ${status} -gt 0 ]; then
957        IGCM_debug_Print 2 "IGCM_sys_Get_Master : cp failed error code ${status} ${i}/${NB_ESSAI}"
958        IGCM_debug_Print 2 "IGCM_sys_Get_Master : sleep ${DELAI} seconds and try again."
959        sleep $DELAI
960      else
961        break
962      fi
963      (( i = i + 1 ))
964    done
[16]965
[717]966    if [ ${status} -gt 0 ] ; then
[657]967      echo "IGCM_sys_Get_Master : error."
[938]968      cat /tmp/out_command.$$
[657]969      IGCM_debug_Exit "IGCM_sys_Get_Master"
[16]970    else
[938]971      \rm /tmp/out_command.$$
[16]972    fi
[657]973  fi
974  IGCM_debug_PopStack "IGCM_sys_Get_Master"
[16]975}
976
[811]977#====================================================
978#- Call IGCM_sys_Mirror_libIGCM now !
979if ( $MirrorlibIGCM ) ; then
980  IGCM_sys_Mirror_libIGCM
981fi
982
[16]983#D-#==================================================
984#D-function IGCM_sys_Put_Rest
[717]985#D-* Purpose: Put computied restarts on ${ARCHIVE}.
[282]986#D-           File and target directory must exist.
[16]987#D-* Examples:
988#D-
989function IGCM_sys_Put_Rest {
[657]990  IGCM_debug_PushStack "IGCM_sys_Put_Rest" $@
991  if ( $DEBUG_sys ) ; then
992    echo "IGCM_sys_Put_Rest :" $@
993  fi
994  if [ $DRYRUN = 0 ]; then
995    if [ ! -f ${1} ] ; then
996      echo "ERROR : IGCM_sys_Put_Rest ${1} DOES NOT EXIST ."
997      IGCM_debug_Exit "IGCM_sys_Put_Rest"
[16]998    fi
[717]999
1000    typeset status
1001    #
[657]1002    if [ X${JobType} = XRUN ] ; then
1003      IGCM_sys_Chmod 444 ${1}
1004    fi
[717]1005    #
[811]1006    # Only if we use rsync
1007    #IGCM_sys_MkdirArchive $( dirname $2 )
1008    #
1009    #USUAL WAY
[938]1010    \cp $1 $2 > /tmp/out_command.$$ 2>&1
[717]1011    status=$?
[16]1012
[717]1013#       #RSYNC WITH NETWORK SSH CALL
[938]1014#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > /tmp/out_command.$$ 2>&1
1015#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> /tmp/out_command.$$ 2>&1
[16]1016
[717]1017#       #RSYNC WITH NFS USE
[938]1018#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > /tmp/out_command.$$ 2>&1
1019#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> /tmp/out_command.$$ 2>&1
[16]1020
[717]1021#       status=$?
1022#       IGCM_sys_Rsync_out $status
1023
[938]1024#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk /tmp/out_command.$$
[717]1025#       (( status=status+$? ))
1026
1027    if [ ${status} -gt 0 ] ; then
1028      echo "IGCM_sys_Put_Rest : cp failed error code ${status}"
[938]1029      cat /tmp/out_command.$$
[657]1030      IGCM_debug_Exit "IGCM_sys_Put_Rest"
1031    else
[938]1032      \rm /tmp/out_command.$$
[657]1033    fi
1034  fi
1035  IGCM_debug_PopStack "IGCM_sys_Put_Rest"
1036}
[16]1037
[657]1038#D-#==================================================
1039#D-function IGCM_sys_PutBuffer_Rest
1040#D-* Purpose: Put computied restarts on ${SCRATCHDIR}.
1041#D-           File and target directory must exist.
1042#D-* Examples:
1043#D-
1044function IGCM_sys_PutBuffer_Rest {
1045  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Rest" $@
1046  if ( $DEBUG_sys ) ; then
1047    echo "IGCM_sys_PutBuffer_Rest :" $@
1048  fi
1049  if [ $DRYRUN = 0 ]; then
1050    if [ ! -f ${1} ] ; then
1051      echo "ERROR : IGCM_sys_PutBuffer_Rest ${1} DOES NOT EXIST ."
1052      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
1053    fi
[16]1054
[717]1055    typeset status
[657]1056    #
1057    if [ X${JobType} = XRUN ] ; then
1058      IGCM_sys_Chmod 444 ${1}
1059    fi
1060
1061    #
1062    # USUAL WAY
[938]1063    \cp $1 $2 > /tmp/out_command.$$ 2>&1
[717]1064    status=$?
[657]1065
[717]1066    if [ ${status} -gt 0 ] ; then
1067      echo "IGCM_sys_PutBuffer_Rest : error code ${status}"
[811]1068      [ -f ${2} ] && ls -l ${2}
1069      [ -f ${2}/${1} ] && ls -l ${2}/${1}
[938]1070      cat /tmp/out_command.$$
[657]1071      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
[16]1072    else
[938]1073      \rm /tmp/out_command.$$
[16]1074    fi
[657]1075  fi
1076  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Rest"
[16]1077}
1078
1079#D-#==================================================
[801]1080#D-function IGCM_sys_PrepareTaredRestart
1081#D-* Purpose: Prepare tared restart to be access by computing job. Identity here.
1082#D-* Examples:
1083#D-
1084function IGCM_sys_PrepareTaredRestart {
1085  IGCM_debug_PushStack "IGCM_sys_PrepareTaredRestart" $@
[918]1086
[801]1087  IGCM_debug_PopStack "IGCM_sys_PrepareTaredRestart"
1088}
1089
1090#D-#==================================================
[16]1091#D-function IGCM_sys_Put_Out
[717]1092#D-* Purpose: Copy a file on ${ARCHIVE} after having chmod it in readonly
[16]1093#D-* Examples:
1094#D-
1095function IGCM_sys_Put_Out {
[657]1096  IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
1097  if ( $DEBUG_sys ) ; then
1098    echo "IGCM_sys_Put_Out :" $@
1099  fi
[811]1100
1101  typeset status
1102
[657]1103  if [ $DRYRUN = 0 ]; then
[811]1104    if [ ! -f ${1} ] ; then
[657]1105      echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
1106      IGCM_debug_PopStack "IGCM_sys_Put_Out"
1107      return 1
[16]1108    fi
[719]1109    #
[811]1110    IGCM_sys_MkdirArchive $( dirname $2 )
1111    #
[657]1112    if [ X${JobType} = XRUN ] ; then
1113      if [ X${3} = X ] ; then
1114        IGCM_sys_Chmod 444 ${1}
1115      fi
1116    fi
[717]1117    #
[16]1118
[938]1119    echo ${RSYNC} ${RSYNC_opt} $1 $2 > /tmp/out_command.$$ 2>&1
1120    ${RSYNC} ${RSYNC_opt} $1 $2 >> /tmp/out_command.$$ 2>&1
[717]1121    status=$?
1122    IGCM_sys_Rsync_out $status
[16]1123
[938]1124    ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk /tmp/out_command.$$
[717]1125    (( status=status+$? ))
[16]1126
[717]1127    if [ ${status} -gt 0 ] ; then
[811]1128      IGCM_debug_Print 2 "IGCM_sys_Put_Out : rsync failed error code ${status}"
[938]1129      cat /tmp/out_command.$$
[657]1130      IGCM_debug_Exit "IGCM_sys_Put_Out"
[16]1131    else
[938]1132      \rm /tmp/out_command.$$
[16]1133    fi
[657]1134  fi
1135  IGCM_debug_PopStack "IGCM_sys_Put_Out"
1136  return 0
[16]1137}
1138
1139#D-#==================================================
[657]1140#D-function IGCM_sys_PutBuffer_Out
1141#D-* Purpose: Copy a file on ${SCRATCHDIR} after having chmod it in readonly
1142#D-* Examples:
1143#D-
1144function IGCM_sys_PutBuffer_Out {
1145  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Out" $@
1146  if ( $DEBUG_sys ) ; then
1147    echo "IGCM_sys_PutBuffer_Out :" $@
1148  fi
[719]1149
[811]1150  typeset NB_ESSAI DELAI status i exist skip
[719]1151
[811]1152  # number of tentative
1153  NB_ESSAI=3
1154  # time delay between tentative
1155  DELAI=2
1156
[657]1157  if [ $DRYRUN = 0 ]; then
1158    if [ ! -f ${1} ] ; then
1159      echo "WARNING : IGCM_sys_PutBuffer_Out ${1} DOES NOT EXIST ."
1160      IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1161      return 1
1162    fi
1163    #
1164    IGCM_sys_Mkdir $( dirname $2 )
1165    #
1166
[811]1167    exist=false
1168    skip=false
1169    if [ -f $2 ] ; then
1170      IGCM_debug_Print 1 "$2 already exist"
1171      exist=true
1172      if [ "X$( diff $1 $2 )" = X ] ; then
1173        IGCM_debug_Print 2 "$1 and $2 are the same file, we skip the copy"
1174        status=0
1175        skip=true
1176      else
1177        IGCM_debug_Print 2 "$1 and $2 are not the same file, we force the copy"
1178        skip=false
[657]1179      fi
1180    fi
1181    #
[811]1182    if ( [ X${exist} = Xtrue ] && [ X${skip} = Xfalse ] ) ; then
1183      IGCM_sys_Chmod u+w $2
1184    fi
[657]1185
[811]1186    if [ X${skip} = Xfalse ] ; then
1187      i=0
1188      while [ $i -lt $NB_ESSAI ] ; do
1189        # USUAL WAY
[938]1190        \cp $1 $2 > /tmp/out_command.$$ 2>&1
[811]1191        status=$?
1192        if [ ${status} -gt 0 ]; then
1193          IGCM_debug_Print 2 "IGCM_sys_PutBuffer_Out : cp failed error code ${status} ${i}/${NB_ESSAI}"
1194          IGCM_debug_Print 2 "IGCM_sys_PutBuffer_Out : sleep ${DELAI} seconds and try again."
1195          [ -f ${2} ] && ls -l ${2}
1196          [ -f ${2}/${1} ] && ls -l ${2}/${1}
1197          sleep $DELAI
1198        else
1199          break
1200        fi
1201        (( i = i + 1 ))
1202      done
1203    fi
1204
[717]1205    if [ ${status} -gt 0 ] ; then
[657]1206      echo "IGCM_sys_PutBuffer_Out : error."
[811]1207      [ -f ${2} ] && ls -l ${2}
1208      [ -f ${2}/${1} ] && ls -l ${2}/${1}
[938]1209      cat /tmp/out_command.$$
[657]1210      IGCM_debug_Exit "IGCM_sys_PutBuffer_Out"
1211    else
[811]1212
1213      if [ X${JobType} = XRUN ] ; then
1214        if [ X${3} = X ] ; then
1215          [ -f ${2} ] && IGCM_sys_Chmod 444 ${2}
1216          [ -f ${2}/${1} ] && IGCM_sys_Chmod 444 ${2}/${1}
1217        fi
1218      fi
1219
[938]1220      \rm /tmp/out_command.$$
[657]1221    fi
1222  fi
1223  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1224  return 0
1225}
1226
1227#D-#==================================================
[16]1228#D-function IGCM_sys_Get
1229#D-* Purpose: Get a file from ${ARCHIVE}
1230#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
1231#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
1232function IGCM_sys_Get {
[657]1233  IGCM_debug_PushStack "IGCM_sys_Get" $@
[16]1234
[811]1235  typeset DEST status dm_liste
[16]1236
[657]1237  if ( $DEBUG_sys ) ; then
1238    echo "IGCM_sys_Get :" $@
1239  fi
1240  if [ $DRYRUN -le 2 ]; then
1241    if [ X${1} = X'/l' ] ; then
1242      eval set +A dm_liste \${${2}}
1243    else
1244      dm_liste=${1}
[16]1245    fi
[657]1246    eval DEST=\${${#}}
[16]1247
[717]1248    # test if the (first) file is present in the old computation :
[657]1249    IGCM_sys_TestFileArchive ${dm_liste[0]}
[717]1250    status=$?
1251    if [ ${status} -gt 0 ] ; then
[657]1252      echo "IGCM_sys_Get, ERROR : regular file ${dm_liste[0]} DOES NOT EXIST ."
1253      IGCM_debug_Exit "IGCM_sys_Get"
[811]1254      return
[657]1255    fi
[16]1256
[811]1257    #USUAL WAY
[938]1258    \cp ${dm_liste[*]} ${DEST} > /tmp/out_command.$$ 2>&1
[811]1259    status=$?
[16]1260
[811]1261    if [ ${status} -gt 0 ] ; then
1262      IGCM_debug_Print 2 "IGCM_sys_Get : cp failed error code ${status}"
[938]1263      cat /tmp/out_command.$$
[657]1264      IGCM_debug_Exit "IGCM_sys_Get"
[16]1265    else
[938]1266      \rm /tmp/out_command.$$
[16]1267    fi
[657]1268  fi
1269  IGCM_debug_PopStack "IGCM_sys_Get"
[16]1270}
1271
1272#D-#==================================================
[657]1273#D-function IGCM_sys_GetBuffer
1274#D-* Purpose: Get a file from ${SCRATCHDIR}
1275#D-* Examples: IGCM_sys_GetBuffer myfile /destpath/myfile_with_PREFIX
1276#D-            IGCM_sys_GetBuffer /l Array_contain_myfiles /destpath/
1277function IGCM_sys_GetBuffer {
1278  IGCM_debug_PushStack "IGCM_sys_GetBuffer" $@
1279
[811]1280  typeset DEST buf_liste target file_work
1281  typeset NB_ESSAI DELAI status i
[657]1282
1283  if ( $DEBUG_sys ) ; then
1284    echo "IGCM_sys_GetBuffer :" $@
1285  fi
[811]1286
1287  # number of tentative
1288  NB_ESSAI=3
1289  # time delay between tentative
1290  DELAI=2
1291
[657]1292  if [ $DRYRUN -le 2 ]; then
1293    if [ X${1} = X'/l' ] ; then
1294      eval set +A buf_liste \${${2}}
1295    else
1296      eval set +A buf_liste ${1}
1297    fi
1298    eval DEST=\${${#}}
1299
1300    #USUAL WAY
1301    if [ X${1} = X'/l' ] ; then
1302      for target in ${buf_liste[*]} ; do
1303        local_file=$( basename ${target} )
[811]1304        i=0
1305        while [ $i -lt $NB_ESSAI ] ; do
[938]1306          \cp ${target} ${DEST}/${local_file} >> /tmp/out_command.$$ 2>&1
[811]1307          status=$?
1308          if [ ${status} -gt 0 ]; then
1309            IGCM_debug_Print 2 "IGCM_sys_GetBuffer : cp failed error code ${status} ${i}/${NB_ESSAI}"
1310            IGCM_debug_Print 2 "IGCM_sys_GetBuffer : sleep ${DELAI} seconds and try again."
1311            sleep $DELAI
1312          else
1313            break
1314          fi
1315          (( i = i + 1 ))
1316        done
1317        if [ ${status} -gt 0 ] ; then
1318          echo "IGCM_sys_Get : error"
[938]1319          cat /tmp/out_command.$$
1320          \rm /tmp/out_command.$$
[811]1321          IGCM_debug_Exit "IGCM_sys_GetBuffer"
1322        else
[938]1323          \rm /tmp/out_command.$$
[811]1324        fi
[657]1325      done
1326    else
[811]1327      i=0
1328      while [ $i -lt $NB_ESSAI ] ; do
[938]1329        \cp ${buf_liste} ${DEST} >> /tmp/out_command.$$ 2>&1
[811]1330        status=$?
1331        if [ ${status} -gt 0 ]; then
1332          IGCM_debug_Print 2 "IGCM_sys_GetBuffer : cp failed error code ${status} ${i}/${NB_ESSAI}"
1333          IGCM_debug_Print 2 "IGCM_sys_GetBuffer : sleep ${DELAI} seconds and try again."
1334          sleep $DELAI
1335        else
1336          break
1337        fi
1338        (( i = i + 1 ))
1339      done
1340      if [ ${status} -gt 0 ] ; then
1341        echo "IGCM_sys_Get : error"
[938]1342        cat /tmp/out_command.$$
1343        \rm /tmp/out_command.$$
[811]1344        IGCM_debug_Exit "IGCM_sys_GetBuffer"
1345      else
[938]1346        \rm /tmp/out_command.$$
[811]1347      fi
[657]1348    fi
1349  fi
1350  IGCM_debug_PopStack "IGCM_sys_GetBuffer"
1351}
1352
1353#D-#==================================================
1354#D-function IGCM_sys_GetDate_FichWork
1355#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
1356#D-* Examples:
1357#D-
1358function IGCM_sys_GetDate_FichWork {
1359  IGCM_debug_PushStack "IGCM_sys_FichWork" $@
1360  if ( $DEBUG_sys ) ; then
1361    echo "IGCM_sys_GetDate_FichWork :" $@
1362  fi
1363  typeset dateF
1364  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1365  eval ${2}=${dateF[5]}
1366
[800]1367  # donne la date filesys d'un fichier sur la machine work
[657]1368  IGCM_debug_PopStack "IGCM_sys_FichWork"
1369}
1370
1371#D-#==================================================
1372#D-function IGCM_sys_GetDate_FichArchive
1373#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
1374#D-* Examples:
1375#D-
1376function IGCM_sys_GetDate_FichArchive {
1377  IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
1378  if ( $DEBUG_sys ) ; then
1379    echo "IGCM_sys_GetDate_FichArchive :" $@
1380  fi
1381  typeset dateF
1382  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1383  eval ${2}=${dateF[5]}
1384
1385  IGCM_debug_PopStack "IGCM_sys_FichArchive"
1386}
1387
1388#D-#==================================================
[343]1389#D-function IGCM_sys_Dods_Rm
[717]1390#D-* Purpose: DO NOTHING ! Put ${ARCHIVE} files on DODS internet protocole.
[343]1391#D-* Examples:
1392#D-
1393function IGCM_sys_Dods_Rm {
[657]1394  if ( $DEBUG_sys ) ; then
1395    echo "IGCM_sys_Dods_Rm :" $@
1396  fi
1397  return 0
[343]1398}
1399
1400#D-#==================================================
1401#D-function IGCM_sys_Dods_Cp
[717]1402#D-* Purpose: Copy $(ARCHIVE) files on DODS internet protocole.
[343]1403#D-* Examples:
1404#D-
1405function IGCM_sys_Dods_Cp {
[657]1406  if ( $DEBUG_sys ) ; then
1407    echo "IGCM_sys_Dods_Cp :" $@
1408  fi
1409  return 0
[343]1410}
1411
1412#D-#==================================================
[16]1413#D-function IGCM_sys_Put_Dods
[811]1414#D-* Purpose: Put ${ARCHIVE} files on DODS internet protocole. Dummy function here
[16]1415#D-* Examples:
1416#D-
1417function IGCM_sys_Put_Dods {
[657]1418  IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
1419  if ( $DEBUG_sys ) ; then
1420    echo "IGCM_sys_Put_Dods :" $@
1421  fi
1422  IGCM_debug_PopStack "IGCM_sys_Put_Dods"
[16]1423}
1424
[657]1425##############################################################
1426# REBUILD OPERATOR
[536]1427
[811]1428#D-#==================================================
1429#D-function IGCM_sys_rebuild
1430#D-* Purpose: rebuild parallel files
1431#D-* Examples:
1432#D-
[657]1433function IGCM_sys_rebuild {
1434  IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1435  if ( $DEBUG_sys ) ; then
1436    echo "IGCM_sys_rebuild :" $@
1437  fi
[717]1438
[811]1439  typeset NB_ESSAI DELAI status i firstArg
1440  # number of tentative
1441  NB_ESSAI=3
1442  # time delay between tentative
1443  DELAI=2
[717]1444
[811]1445  i=0
1446  while [ $i -lt $NB_ESSAI ] ; do
[938]1447    /home/users/igcmg/rebuild/bin/rebuild -f -o $@ > /tmp/out_command.$$ 2>&1
[811]1448    status=$?
1449    if [ ${status} -gt 0 ] ; then
1450      IGCM_debug_Print 2 "IGCM_sys_rebuild : error code ${status}"
[938]1451      cat /tmp/out_command.$$
1452      \rm /tmp/out_command.$$
[811]1453      IGCM_debug_Print 2 "IGCM_sys_rebuild : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1454      firstArg=${1}
1455      \rm ${firstArg}
1456      sleep $DELAI
1457    else
[938]1458      \rm /tmp/out_command.$$
[811]1459      break
1460    fi
1461    (( i = i + 1 ))
1462  done
1463
[717]1464  if [ ${status} -gt 0 ] ; then
[811]1465    echo "IGCM_sys_rebuild : rebuild error code is ${status}"
[657]1466    IGCM_debug_Exit "rebuild"
1467  fi
1468
1469  IGCM_debug_PopStack "IGCM_sys_rebuild"
[16]1470}
1471
[811]1472#D-#==================================================
1473#D-function IGCM_sys_rebuild_station
[922]1474#D-* Purpose: rebuild parallel files describing station
[811]1475#D-* Examples:
1476#D-
[697]1477function IGCM_sys_rebuild_station {
1478  IGCM_debug_PushStack "IGCM_sys_rebuild_station" -- $@
1479  typeset i list_opt file_in file_out prefix_invert list_invert
1480  if ( $DEBUG_sys ) ; then
1481    echo "IGCM_sys_rebuild_station :" $@
1482  fi
1483  list_opt=$@
1484
[800]1485  # Invert Axis : t,x -> x,t
[697]1486  #               t,pres,x -> x,t,pres
1487  # So that we can concatenate along x
1488  i=0
1489  for file_in in ${list_opt} ; do
1490    (( i = i + 1))
1491    [ ${i} = 1 ] && file_out=${file_in} && continue
1492    prefix_invert=$( basename ${file_in} .nc )
1493    IGCM_sys_ncpdq -a x,time_counter -a x,time_counter,presnivs ${file_in} ${prefix_invert}_xt.nc
1494    list_invert[${#list_invert[*]}]=${prefix_invert}_xt.nc
1495  done
1496
1497  # Concatenate
1498  IGCM_sys_ncrcat ${list_invert[*]} histstn_xt.nc
1499
1500  # Re-ivert file
1501  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x histstn_xt.nc ${file_out}
1502
[922]1503  # Station re-ordering is too expansive to be run within libIGCM
[697]1504  # This is due to (ncpdq - nrcat - ncpdq) I/O sequence.
1505  # This re-ordering must be done "in memory" by the cmorization process
1506  # Anyway this is the best sequence using (ncpdq - nrcat - ncpdq)
1507  # BEGIN reordering
1508
1509  # Only LMDZ text output contains the exact ordering of the station.
1510  # We isolate this in the code below:
1511  #  0  38  -157.5000000000000  70.98591549295774
1512  #  0  54  27.49999999999999   67.18309859154928
1513  #  0  56  -62.50000000000001  82.39436619718309
1514  #  0  79  12.49999999999999   78.59154929577466
1515  #  0  116 -165.0000000000000  76.05633802816901
1516  #  0  117 130.0000000000000   70.98591549295774
1517  #  0  118 110.0000000000000   87.46478873239437
1518  #  1  40  4.999999999999995   51.97183098591550
1519#  typeset iStation iProc list_opt file_in file_out prefix_invert
1520#  typeset -Z4 j4
1521#  typeset -Z3 j3
1522
1523#  unset list_opt
1524#  set +A list_opt $@
1525
1526  # Filename after rebuild
1527#  file_out=${list_opt[0]}
1528  # Prefix of output files
1529#  prefix_invert=$( basename ${file_out} .nc )
1530  # Number of procs
1531#  num_proc=$( grep -i mpi_size ${PREFIX}_${Exe_Output} | wc -l )
1532
1533#  iProc=0
1534#  while [ ${iProc} -lt ${num_proc} ] ; do
1535    # Array containing Station as a number
1536#    unset proc_stn
[912]1537#    set +A proc_stn $( grep "iophy_mpi rank ip lon lat  $iProc" ${PREFIX}_${Exe_Output} | sed -e "s/iophy_mpi rank ip lon lat //g" | gawk ' {print $2}' )
[697]1538    # Number of stations produced by processor proc
1539#    stationLast=${#proc_stn[*]}
1540    # Proc number on 4 digits
1541#    j4=${iProc}
1542    # Init
1543#    iStation=0
1544#    while [ ${iStation} -lt ${stationLast} ] ; do
1545      # Station number on 3 digits
1546#      j3=${proc_stn[${iStation}]}
1547      # Extract station
[800]1548      # Invert Axis : t,x -> x,t
[697]1549      #               t,pres,x -> x,t,pres
1550      # So that we can concatenate along x
1551#      IGCM_sys_ncpdq -a x,time_counter -a x,time_counter,presnivs -d x,$iStation,$iStation ${prefix_invert}_${j4}.nc ${prefix_invert}_stn_${j3}.nc
1552#      (( iStation = iStation + 1 ))
1553#    done
1554#    (( iProc = iProc + 1 ))
1555#  done
1556
1557  # Concatenate all station along x
1558#  IGCM_sys_ncrcat ${prefix_invert}_stn_???.nc ${prefix_invert}_xt.nc
1559
1560  # Re-invert file
1561#  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x ${prefix_invert}_xt.nc ${file_out}
1562
1563  # END reordering
1564
1565  IGCM_debug_PopStack "IGCM_sys_rebuild_station"
1566}
1567
[657]1568############################################################
1569# Activate Running Environnment Variables
[536]1570
[811]1571#D-#==================================================
1572#D-function IGCM_sys_desactiv_variables
1573#D-* Purpose: set environement variables prior to execution
1574#D-* Examples:
1575#D-
[657]1576function IGCM_sys_activ_variables {
1577  IGCM_debug_PushStack "IGCM_sys_activ_variables"
1578  if ( $DEBUG_sys ) ; then
1579    echo "IGCM_sys_activ_variables"
1580  fi
[811]1581
1582# --------------------------------------------------------------------
1583#D- MPI specifications
1584# --------------------------------------------------------------------
1585
1586# --------------------------------------------------------------------
1587#D- Other specifications
1588# --------------------------------------------------------------------
1589
[657]1590  IGCM_debug_PopStack "IGCM_sys_activ_variables"
[16]1591}
1592
[657]1593############################################################
1594# Desactivate Running Environnment Variables
[16]1595
[811]1596#D-#==================================================
1597#D-function IGCM_sys_desactiv_variables
1598#D-* Purpose: unset environement variables after execution
1599#D-* Examples:
1600#D-
[657]1601function IGCM_sys_desactiv_variables {
1602  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1603  if ( $DEBUG_sys ) ; then
1604    echo "IGCM_sys_desactiv_variables"
1605  fi
[811]1606# --------------------------------------------------------------------
1607#D- MPI specifications
1608# --------------------------------------------------------------------
1609
1610# --------------------------------------------------------------------
1611#D- Other specifications
1612# --------------------------------------------------------------------
1613
[657]1614  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1615}
1616
1617############################################################
[800]1618# Build MPI/OMP scripts run file (dummy function)
[657]1619
[811]1620#D-#==================================================
1621#D-function IGCM_sys_build_run_file
1622#D-* Purpose: build run file (deprecated)
1623#D-* Examples:
1624#D-
[657]1625function IGCM_sys_build_run_file {
1626
[664]1627  IGCM_debug_Print 3 " dummy function : IGCM_sys_build_run_file "
[657]1628
1629}
1630
1631############################################################
1632# Build MPI/OMP scripts
[811]1633
1634#D-#==================================================
1635#D-function IGCM_sys_build_execution_scripts
1636#D-* Purpose: build execution scripts to be launch by ${HOST_MPIRUN_COMMAND}
1637#D-* Examples:
1638#D-
[657]1639function IGCM_sys_build_execution_scripts
1640{
1641  IGCM_debug_PushStack "IGCM_sys_build_execution_scripts" $@
1642  if ( $DEBUG_sys ) ; then
1643    echo "IGCM_sys_build_execution_scripts " $@
1644  fi
1645  typeset nodes listnodes init_node start_num init_exec comp ExeNameIn ExeNameOut
1646  typeset node_num_current node_current comp_proc_mpi_loc comp_proc_omp_loc
1647  typeset num_corempi nombre_restant_node nombre_restant_comp
1648
1649  if [ ! -f ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} ]  ; then
[811]1650    IGCM_debug_Exit "IGCM_sys_obelix build_execution_scripts : Job_${config_UserChoices_JobName} don't exist in SUBMIT_DIR : ${SUBMIT_DIR} "
[657]1651  fi
1652
1653  if ( ${OK_PARA_MPMD} ) ; then
1654
1655    if [ -f run_file ] ; then
1656      IGCM_sys_Rm -f run_file
[16]1657    fi
[657]1658    touch run_file
1659
1660    if ( ${OK_PARA_OMP} ) ; then
1661
1662      #  Hosts treatment
1663
1664      ${HOST_MPIRUN_COMMAND} hostname | sort | uniq > hosts.tmp
1665
1666      i=0
1667      rm -f hosts
1668      IGCM_debug_Print 1 "sys Obelix, Hosts avaible :"
1669      for nodes in `cat hosts.tmp` ; do
1670        host[$i]=$nodes
1671        echo "${host[$i]} slots=1 max_slots=1" >> hosts
1672        IGCM_debug_Print 1 ${host[$i]}
1673        i=$((i+1))
1674      done
1675      rm -f hosts.tmp
1676
1677      listnodes=${host[*]}
1678
1679      EXECUTION="${HOST_MPIRUN_COMMAND} -hostfile hosts"
1680
1681      # Initialisation
1682
1683      init_node=y
1684      node_num_current=0
1685      start_num=0
1686      init_exec=n
1687
1688      # Test : if oasis is there, we put it at the first position
1689
1690      for comp in ${config_ListOfComponents[*]} ; do
1691
1692        if [ "X${comp}" = "XCPL" ]  ; then
1693
1694          eval ExeNameIn=\${config_Executable_${comp}[0]}
1695          eval ExeNameOut=\${config_Executable_${comp}[1]}
1696
1697          echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1698          echo ""  >> script_${ExeNameOut}.ksh
1699          #echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
1700          #echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
1701          #echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
1702          echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err"  >> script_${ExeNameOut}.ksh
1703          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1704
1705          init_node=n
1706
1707          (( nombre_restant_node = NUM_COREPERNODE - 1 ))
1708          node_num_current=0
1709          node_current=${host[${node_num_current}]}
1710
1711          EXECUTION="${EXECUTION} -H ${node_current} -np 1 ./script_${ExeNameOut}.ksh"
1712
1713          init_exec=y
1714          start_num=1
1715
1716        fi
1717
1718      done
1719
1720      # Then loop on the components (except for oasis)
1721
1722      for comp in ${config_ListOfComponents[*]} ; do
1723
1724        eval ExeNameIn=\${config_Executable_${comp}[0]}
1725        eval ExeNameOut=\${config_Executable_${comp}[1]}
1726
1727        # Only if we really have an executable for the component :
1728        if ( [ "X${ExeNameOut}" != X\"\" ] &&  [ "X${comp}" != "XCPL" ] ) ; then
1729
1730          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1731          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1732
1733          echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1734          # echo "set -vx" >> script_${ExeNameOut}.ksh
1735          echo ""  >> script_${ExeNameOut}.ksh
1736          #echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
1737          #echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
1738          #echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
1739          echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
1740          echo "(( MYMPIRANK = OMPI_COMM_WORLD_RANK - ${start_num})) " >>  script_${ExeNameOut}.ksh
1741          echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${MYMPIRANK} 2>out_${ExeNameOut}.err.\${MYMPIRANK}"  >> script_${ExeNameOut}.ksh
1742          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1743
1744          node_num=0
1745
1746          # We define the number of MPI process to be assigned for the component
1747
1748          nombre_restant_comp=${comp_proc_mpi_loc}
1749
1750          # Loop on the allocated nodes
1751
1752          for node in ${listnodes} ; do
1753
1754            # We go to the current node
1755            if [ ${node_num} = ${node_num_current} ] ; then
1756
1757              node_current=${host[${node_num_current}]}
1758
1759              # If first time on the node : initialisation
1760
1761              if [ ${init_node} = y ] ; then
1762                nombre_restant_node=${NUM_COREPERNODE}
1763              fi
1764
1765              # Test on the number of OMP threads
1766
1767              if [ ${comp_proc_omp_loc} -gt ${nombre_restant_node} ] ; then
1768                (( node_num = node_num + 1 ))
1769                node_num_current=${node_num}
1770                init_node=y
1771                continue
1772              fi
1773
1774              # Number of MPI process to assign
1775
1776              (( num_corempi = nombre_restant_node / comp_proc_omp_loc ))
1777
1778              if [ ${num_corempi} -gt ${nombre_restant_comp} ] ; then
1779                num_corempi=${nombre_restant_comp}
1780              fi
1781
1782              (( nombre_restant_node = nombre_restant_node - num_corempi * comp_proc_omp_loc ))
1783              (( nombre_restant_comp = nombre_restant_comp - num_corempi ))
1784
1785              if [ ${init_exec} = y ] ; then
1786                EXECUTION="${EXECUTION} : -H ${node_current} -np ${num_corempi} ./script_${ExeNameOut}.ksh"
1787              else
1788                EXECUTION="${EXECUTION} -H ${node_current} -np ${num_corempi} ./script_${ExeNameOut}.ksh"
1789                init_exec=y
1790              fi
1791
1792              ((  start_num = num_corempi + start_num ))
1793
1794            else
1795
1796              (( node_num = node_num + 1 ))
1797              continue
1798            fi
1799
1800            # Test on the number of core/process remaining on the node/component
1801
1802            if [ ${nombre_restant_node} = 0 ] ; then
1803              (( node_num = node_num + 1 ))
1804              node_num_current=${node_num}
1805              init_node=y
1806
1807              if [ ${nombre_restant_comp} = 0 ] ; then
1808                break 1
1809              fi
1810            else
1811
1812              node_num_current=${node_num}
1813              init_node=n
1814
1815              if [ ${nombre_restant_comp} = 0 ] ; then
1816                break 1
1817              fi
1818            fi
1819          done
1820        fi
1821      done
1822
1823    else
1824
[664]1825      # Then first loop on the components for the coupler ie oasis
[657]1826
[664]1827      ## the coupler ie oasis must be the first one
1828      for comp in ${config_ListOfComponents[*]} ; do
[657]1829
[664]1830        eval ExeNameOut=\${config_Executable_${comp}[1]}
[657]1831
1832        # for CPL component only
[664]1833        if [ "X${comp}" = "XCPL" ] ; then
1834          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1835          echo "-np ${comp_proc_mpi_loc} ./${ExeNameOut} " >> run_file
1836        fi
1837      done
[657]1838
[811]1839      # Then second loop on the components
[657]1840
[664]1841      for comp in ${config_ListOfComponents[*]} ; do
[657]1842
[664]1843        eval ExeNameOut=\${config_Executable_${comp}[1]}
[657]1844
[664]1845        # Only if we really have an executable for the component and not the coupler ie oasis:
1846        if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${comp}" != "XCPL" ] ) ; then
1847          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1848          echo "-np ${comp_proc_mpi_loc} ./${ExeNameOut}" >> run_file
1849        fi
1850      done
1851      IGCM_sys_Chmod u+x run_file
[657]1852
[664]1853      EXECUTION="${HOST_MPIRUN_COMMAND} --app ./run_file"
[657]1854
[16]1855    fi
1856
[657]1857  else # Only one executable. launch it.
1858
[664]1859    for comp in ${config_ListOfComponents[*]} ; do
[657]1860
[664]1861      # Only if we really have an executable for the component :
1862      eval ExeNameOut=\${config_Executable_${comp}[1]}
1863      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${ExeNameOut}" != "Xinca.dat" ] ) ; then
[657]1864
[664]1865        echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1866        echo ""  >> script_${ExeNameOut}.ksh
1867        if ( ${OK_PARA_OMP} ) ; then
1868          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1869          echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
1870        fi
1871        if  ( ${OK_PARA_MPI} ) ; then
1872          # Default : mpirun used if nb_proc gt 1
1873          # pour sortie out/err par process
1874          # echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${OMPI_COMM_WORLD_RANK} 2>out_${ExeNameOut}.err.\${OMPI_COMM_WORLD_RANK}"  >> script_${ExeNameOut}.ksh
1875          echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1876          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1877          EXECUTION="${HOST_MPIRUN_COMMAND} ./script_${ExeNameOut}.ksh"
1878        else
1879          # Default : mpirun is NOT used if nb_proc eq 1
1880          # pour sortie out/err par process
1881          # echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err" >> script_${ExeNameOut}.ksh
1882          echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1883          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1884          EXECUTION="time ./script_${ExeNameOut}.ksh"
1885        fi
1886      fi
1887    done
[657]1888
1889  fi
1890
[811]1891  IGCM_debug_Print 1 "sys Obelix : execution command is"
1892  IGCM_debug_Print 1 "$EXECUTION"
[657]1893
1894  IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
[16]1895}
1896
[933]1897#D-#==================================================
1898#D-function IGCM_sys_check_path
1899#D-* Purpose: check that RUN_DIR_PATH that will be removed on some machine
1900#D-* do not point to an important use directory. Stop immediately in that case.
1901#D-* Examples:
1902#D-
1903function IGCM_sys_check_path {
1904  IGCM_debug_PushStack "IGCM_sys_check_path"
1905  if ( $DEBUG_sys ) ; then
1906    echo "IGCM_sys_check_path"
1907  fi
[811]1908
[933]1909  if ( [ X${RUN_DIR_PATH} = X${HOME} ] || [ X${RUN_DIR_PATH} = X${ARCHIVE} ] ) ; then
1910    IGCM_debug_Print 1 "Variable RUN_DIR_PATH is pointing to an important directory : ${RUN_DIR_PATH}"
1911    IGCM_debug_Print 1 "Please check the RUN_DIR_PATH definition in your Job : Job_${config_UserChoices_JobName}"
[936]1912    IGCM_debug_Exit "This will stop the job"
[933]1913  fi
1914  IGCM_debug_PopStack "IGCM_sys_check_path"
1915}
1916
[811]1917#D-#==================================================
1918#D-function IGCM_sys_check_quota. Dummy call here
1919#D-* Purpose: check user quota. Stop the simulation if quota above 90%
1920#D-* Examples:
1921#D-
[657]1922function IGCM_sys_check_quota {
1923  IGCM_debug_PushStack "IGCM_sys_check_quota"
1924  if ( $DEBUG_sys ) ; then
1925    echo "IGCM_sys_check_quota"
1926  fi
1927  IGCM_debug_PopStack "IGCM_sys_check_quota"
1928}
1929
[811]1930#D-#==================================================
1931#D-function IGCM_sys_CountJobInQueue
1932#D-* Purpose: Check if job_name is currently
1933#D-  running or in queue
1934#D-* Examples: IGCM_sys_CountJobInQueue ${JobName} NbRun
1935#D-
1936function IGCM_sys_CountJobInQueue {
1937  IGCM_debug_PushStack "IGCM_sys_CountJobInQueue"
1938  if ( $DEBUG_sys ) ; then
1939    echo "IGCM_sys_CountJobInQueue"
1940  fi
1941  IGCM_debug_PopStack "IGCM_sys_CountJobInQueue"
1942}
1943
[16]1944##############################################################
1945# NCO OPERATOR
1946
[811]1947#D-#==================================================
1948#D-function IGCM_sys_ncap2
1949#D-* Purpose: encapsulate ncap2 call so as to manage error code and retry
1950#D-* Examples:
1951#D-
[377]1952function IGCM_sys_ncap2 {
[657]1953  IGCM_debug_PushStack "IGCM_sys_ncap2" -- $@
1954  if ( $DEBUG_sys ) ; then
1955    echo "IGCM_sys_ncap2 :" $@
1956  fi
[714]1957
1958  typeset NB_ESSAI DELAI status i
1959  # number of tentative
1960  NB_ESSAI=3
1961  # time delay between tentative
1962  DELAI=2
1963
1964  i=0
1965  while [ $i -lt $NB_ESSAI ] ; do
[938]1966    ncap2 "$@" > /tmp/out_command.$$ 2>&1
[714]1967    status=$?
1968    if [ ${status} -gt 0 ] ; then
1969      IGCM_debug_Print 2 "IGCM_sys_ncap2 : error code ${status}"
[938]1970      cat /tmp/out_command.$$
1971      \rm /tmp/out_command.$$
[714]1972      IGCM_debug_Print 2 "IGCM_sys_ncap2 : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
[800]1973      sleep $DELAI
[714]1974    else
[938]1975      \rm /tmp/out_command.$$
[714]1976      break
1977    fi
1978    (( i = i + 1 ))
1979  done
1980
1981  if [ ${status} -gt 0 ] ; then
[811]1982    echo "IGCM_sys_ncap2 : ncap2 error"
1983    IGCM_debug_Exit "ncap2"
[657]1984  fi
[16]1985
[657]1986  IGCM_debug_PopStack "IGCM_sys_ncap2"
[16]1987}
1988
[811]1989#D-#==================================================
1990#D-function IGCM_sys_ncatted
1991#D-* Purpose: encapsulate ncatted call so as to manage error code and retry
1992#D-* Examples:
1993#D-
[375]1994function IGCM_sys_ncatted {
[657]1995  IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
1996  if ( $DEBUG_sys ) ; then
1997    echo "IGCM_sys_ncatted :" $@
1998  fi
[714]1999
2000  typeset NB_ESSAI DELAI status i
2001  # number of tentative
2002  NB_ESSAI=3
2003  # time delay between tentative
2004  DELAI=2
2005
2006  i=0
2007  while [ $i -lt $NB_ESSAI ] ; do
[938]2008    ncatted "$@" > /tmp/out_command.$$ 2>&1
[714]2009    status=$?
2010    if [ ${status} -gt 0 ] ; then
2011      IGCM_debug_Print 2 "IGCM_sys_ncatted : error code ${status}"
[938]2012      cat /tmp/out_command.$$
2013      \rm /tmp/out_command.$$
[714]2014      IGCM_debug_Print 2 "IGCM_sys_ncatted : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
[800]2015      sleep $DELAI
[714]2016    else
[938]2017      \rm /tmp/out_command.$$
[714]2018      break
2019    fi
2020    (( i = i + 1 ))
2021  done
2022
2023  if [ ${status} -gt 0 ] ; then
[811]2024    echo "IGCM_sys_ncatted : ncatted error"
2025    IGCM_debug_Exit "ncatted"
[657]2026  fi
[16]2027
[657]2028  IGCM_debug_PopStack "IGCM_sys_ncatted"
[375]2029}
[16]2030
[811]2031#D-#==================================================
2032#D-function IGCM_sys_ncbo
2033#D-* Purpose: encapsulate ncbo call so as to manage error code and retry
2034#D-* Examples:
2035#D-
[16]2036function IGCM_sys_ncbo {
[657]2037  IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
2038  if ( $DEBUG_sys ) ; then
2039    echo "IGCM_sys_ncbo :" $@
2040  fi
[714]2041
2042  typeset NB_ESSAI DELAI status i
2043  # number of tentative
2044  NB_ESSAI=3
2045  # time delay between tentative
2046  DELAI=2
2047
2048  i=0
2049  while [ $i -lt $NB_ESSAI ] ; do
[938]2050    ncbo $@ > /tmp/out_command.$$ 2>&1
[714]2051    status=$?
2052    if [ ${status} -gt 0 ] ; then
2053      IGCM_debug_Print 2 "IGCM_sys_ncbo : error code ${status}"
[938]2054      cat /tmp/out_command.$$
2055      \rm /tmp/out_command.$$
[714]2056      IGCM_debug_Print 2 "IGCM_sys_ncbo : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
[800]2057      sleep $DELAI
[714]2058    else
[938]2059      \rm /tmp/out_command.$$
[714]2060      break
2061    fi
2062    (( i = i + 1 ))
2063  done
2064
2065  if [ ${status} -gt 0 ] ; then
[811]2066    echo "IGCM_sys_ncbo : ncbo error"
2067    IGCM_debug_Exit "ncbo"
[657]2068  fi
[16]2069
[657]2070  IGCM_debug_PopStack "IGCM_sys_ncbo"
[16]2071}
2072
[811]2073#D-#==================================================
2074#D-function IGCM_sys_ncdif
2075#D-* Purpose: encapsulate ncdiff call so as to manage error code and retry
2076#D-* Examples:
2077#D-
[16]2078function IGCM_sys_ncdiff {
[657]2079  IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
2080  if ( $DEBUG_sys ) ; then
2081    echo "IGCM_sys_ncdiff :" $@
2082  fi
[714]2083
2084  typeset NB_ESSAI DELAI status i
2085  # number of tentative
2086  NB_ESSAI=3
2087  # time delay between tentative
2088  DELAI=2
2089
2090  i=0
2091  while [ $i -lt $NB_ESSAI ] ; do
[938]2092    ncdiff $@ > /tmp/out_command.$$ 2>&1
[714]2093    status=$?
2094    if [ ${status} -gt 0 ] ; then
2095      IGCM_debug_Print 2 "IGCM_sys_ncdiff : error code ${status}"
[938]2096      cat /tmp/out_command.$$
2097      \rm /tmp/out_command.$$
[714]2098      IGCM_debug_Print 2 "IGCM_sys_ncdiff : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
[800]2099      sleep $DELAI
[714]2100    else
[938]2101      \rm /tmp/out_command.$$
[714]2102      break
2103    fi
2104    (( i = i + 1 ))
2105  done
2106
2107  if [ ${status} -gt 0 ] ; then
[811]2108    echo "IGCM_sys_ncdiff : ncdiff error"
2109    IGCM_debug_Exit "ncdiff"
[657]2110  fi
[16]2111
[657]2112  IGCM_debug_PopStack "IGCM_sys_ncdiff"
[16]2113}
2114
[811]2115#D-#==================================================
2116#D-function IGCM_sys_ncea
2117#D-* Purpose: encapsulate ncea call so as to manage error code and retry
2118#D-* Examples:
2119#D-
[16]2120function IGCM_sys_ncea {
[657]2121  IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
2122  if ( $DEBUG_sys ) ; then
2123    echo "IGCM_sys_ncea :" $@
2124  fi
[714]2125
2126  typeset NB_ESSAI DELAI status i
2127  # number of tentative
2128  NB_ESSAI=3
2129  # time delay between tentative
2130  DELAI=2
2131
2132  i=0
2133  while [ $i -lt $NB_ESSAI ] ; do
[938]2134    ncea $@ > /tmp/out_command.$$ 2>&1
[714]2135    status=$?
2136    if [ ${status} -gt 0 ] ; then
2137      IGCM_debug_Print 2 "IGCM_sys_ncea : error code ${status}"
[938]2138      cat /tmp/out_command.$$
2139      \rm /tmp/out_command.$$
[714]2140      IGCM_debug_Print 2 "IGCM_sys_ncea : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
[800]2141      sleep $DELAI
[714]2142    else
[938]2143      \rm /tmp/out_command.$$
[714]2144      break
2145    fi
2146    (( i = i + 1 ))
2147  done
2148
2149  if [ ${status} -gt 0 ] ; then
[811]2150    echo "IGCM_sys_ncea : ncea error"
2151    IGCM_debug_Exit "ncea"
[657]2152  fi
[16]2153
[657]2154  IGCM_debug_PopStack "IGCM_sys_ncea"
[16]2155}
2156
[811]2157#D-#==================================================
2158#D-function IGCM_sys_ncecat
2159#D-* Purpose: encapsulate ncecat call so as to manage error code and retry
2160#D-* Examples:
2161#D-
[16]2162function IGCM_sys_ncecat {
[657]2163  IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
2164  if ( $DEBUG_sys ) ; then
2165    echo "IGCM_sys_ncecat :" $@
2166  fi
[714]2167
2168  typeset NB_ESSAI DELAI status i
2169  # number of tentative
2170  NB_ESSAI=3
2171  # time delay between tentative
2172  DELAI=2
2173
2174  i=0
2175  while [ $i -lt $NB_ESSAI ] ; do
[938]2176    ncecat $@ > /tmp/out_command.$$ 2>&1
[714]2177    status=$?
2178    if [ ${status} -gt 0 ] ; then
2179      IGCM_debug_Print 2 "IGCM_sys_ncecat : error code ${status}"
[938]2180      cat /tmp/out_command.$$
2181      \rm /tmp/out_command.$$
[714]2182      IGCM_debug_Print 2 "IGCM_sys_ncecat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
[800]2183      sleep $DELAI
[714]2184    else
[938]2185      \rm /tmp/out_command.$$
[714]2186      break
2187    fi
2188    (( i = i + 1 ))
2189  done
2190
2191  if [ ${status} -gt 0 ] ; then
[811]2192    echo "IGCM_sys_ncecat : ncecat error"
2193    IGCM_debug_Exit "ncecat"
[657]2194  fi
[16]2195
[657]2196  IGCM_debug_PopStack "IGCM_sys_ncecat"
[16]2197}
2198
[811]2199#D-#==================================================
2200#D-function IGCM_sys_ncflint
2201#D-* Purpose: encapsulate ncflint call so as to manage error code and retry
2202#D-* Examples:
2203#D-
[16]2204function IGCM_sys_ncflint {
[657]2205  IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
2206  if ( $DEBUG_sys ) ; then
2207    echo "IGCM_sys_ncflint :" $@
2208  fi
[714]2209
2210  typeset NB_ESSAI DELAI status i
2211  # number of tentative
2212  NB_ESSAI=3
2213  # time delay between tentative
2214  DELAI=2
2215
2216  i=0
2217  while [ $i -lt $NB_ESSAI ] ; do
[938]2218    ncflint $@ > /tmp/out_command.$$ 2>&1
[714]2219    status=$?
2220    if [ ${status} -gt 0 ] ; then
2221      IGCM_debug_Print 2 "IGCM_sys_ncflint : error code ${status}"
[938]2222      cat /tmp/out_command.$$
2223      \rm /tmp/out_command.$$
[714]2224      IGCM_debug_Print 2 "IGCM_sys_ncflint : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
[800]2225      sleep $DELAI
[714]2226    else
[938]2227      \rm /tmp/out_command.$$
[714]2228      break
2229    fi
2230    (( i = i + 1 ))
2231  done
2232
2233  if [ ${status} -gt 0 ] ; then
[811]2234    echo "IGCM_sys_ncflint : ncflint error"
2235    IGCM_debug_Exit "ncflint"
[657]2236  fi
[16]2237
[657]2238  IGCM_debug_PopStack "IGCM_sys_ncflint"
[16]2239}
2240
[811]2241#D-#==================================================
2242#D-function IGCM_sys_ncks
2243#D-* Purpose: encapsulate ncks call so as to manage error code and retry
2244#D-* Examples:
2245#D-
[16]2246function IGCM_sys_ncks {
[657]2247  IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
2248  if ( $DEBUG_sys ) ; then
2249    echo "IGCM_sys_ncks :" $@
2250  fi
[714]2251
2252  typeset NB_ESSAI DELAI status i
2253  # number of tentative
2254  NB_ESSAI=3
2255  # time delay between tentative
2256  DELAI=2
2257
2258  i=0
2259  while [ $i -lt $NB_ESSAI ] ; do
[938]2260    ncks $@ > /tmp/out_command.$$ 2>&1
[714]2261    status=$?
2262    if [ ${status} -gt 0 ] ; then
2263      IGCM_debug_Print 2 "IGCM_sys_ncks : error code ${status}"
[938]2264      cat /tmp/out_command.$$
2265      \rm /tmp/out_command.$$
[714]2266      IGCM_debug_Print 2 "IGCM_sys_ncks : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
[800]2267      sleep $DELAI
[714]2268    else
[938]2269      \rm /tmp/out_command.$$
[714]2270      break
2271    fi
2272    (( i = i + 1 ))
2273  done
2274
2275  if [ ${status} -gt 0 ] ; then
[811]2276    echo "IGCM_sys_ncks : ncks error"
2277    IGCM_debug_Exit "ncks"
[657]2278  fi
[16]2279
[657]2280  IGCM_debug_PopStack "IGCM_sys_ncks"
[16]2281}
2282
[811]2283#D-#==================================================
2284#D-function IGCM_sys_ncpdq
2285#D-* Purpose: encapsulate ncpdq call so as to manage error code and retry
2286#D-* Examples:
2287#D-
[16]2288function IGCM_sys_ncpdq {
[657]2289  IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
2290  if ( $DEBUG_sys ) ; then
2291    echo "IGCM_sys_ncpdq :" $@
2292  fi
[714]2293
2294  typeset NB_ESSAI DELAI status i
2295  # number of tentative
2296  NB_ESSAI=3
2297  # time delay between tentative
2298  DELAI=2
2299
2300  i=0
2301  while [ $i -lt $NB_ESSAI ] ; do
[938]2302    ncpdq $@ > /tmp/out_command.$$ 2>&1
[714]2303    status=$?
2304    if [ ${status} -gt 0 ] ; then
2305      IGCM_debug_Print 2 "IGCM_sys_ncpdq : error code ${status}"
[938]2306      cat /tmp/out_command.$$
2307      \rm /tmp/out_command.$$
[714]2308      IGCM_debug_Print 2 "IGCM_sys_ncpdq : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
[800]2309      sleep $DELAI
[714]2310    else
[938]2311      \rm /tmp/out_command.$$
[714]2312      break
2313    fi
2314    (( i = i + 1 ))
2315  done
2316
2317  if [ ${status} -gt 0 ] ; then
[811]2318    echo "IGCM_sys_ncpdq : ncpdq error"
2319    IGCM_debug_Exit "ncpdq"
[657]2320  fi
[16]2321
[657]2322  IGCM_debug_PopStack "IGCM_sys_ncpdq"
[16]2323}
2324
[811]2325#D-#==================================================
2326#D-function IGCM_sys_ncra
2327#D-* Purpose: encapsulate ncra call so as to manage error code and retry
2328#D-* Examples:
2329#D-
[16]2330function IGCM_sys_ncra {
[657]2331  IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
2332  if ( $DEBUG_sys ) ; then
2333    echo "IGCM_sys_ncra :" $@
2334  fi
[714]2335
2336  typeset NB_ESSAI DELAI status i
2337  # number of tentative
2338  NB_ESSAI=3
2339  # time delay between tentative
2340  DELAI=2
2341
2342  i=0
2343  while [ $i -lt $NB_ESSAI ] ; do
[938]2344    ncra $@ > /tmp/out_command.$$ 2>&1
[714]2345    status=$?
2346    if [ ${status} -gt 0 ] ; then
2347      IGCM_debug_Print 2 "IGCM_sys_ncra : error code ${status}"
[938]2348      cat /tmp/out_command.$$
2349      \rm /tmp/out_command.$$
[714]2350      IGCM_debug_Print 2 "IGCM_sys_ncra : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
[800]2351      sleep $DELAI
[714]2352    else
[938]2353      \rm /tmp/out_command.$$
[714]2354      break
2355    fi
2356    (( i = i + 1 ))
2357  done
2358
2359  if [ ${status} -gt 0 ] ; then
[811]2360    echo "IGCM_sys_ncra : ncra error"
2361    IGCM_debug_Exit "ncra"
[657]2362  fi
[16]2363
[657]2364  IGCM_debug_PopStack "IGCM_sys_ncra"
[16]2365}
2366
[811]2367#D-#==================================================
2368#D-function IGCM_sys_ncrcat
2369#D-* Purpose: encapsulate ncrcat call so as to manage error code and retry
2370#D-* Examples:
2371#D-
[16]2372function IGCM_sys_ncrcat {
[657]2373  IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
2374  if ( $DEBUG_sys ) ; then
2375    echo "IGCM_sys_ncrcat :" $@
2376  fi
[714]2377
[811]2378  typeset NB_ESSAI DELAI status i lastArg
[714]2379  # number of tentative
2380  NB_ESSAI=3
2381  # time delay between tentative
2382  DELAI=2
2383
2384  i=0
2385  while [ $i -lt $NB_ESSAI ] ; do
[938]2386    ncrcat $@ > /tmp/out_command.$$ 2>&1
[714]2387    status=$?
2388    if [ ${status} -gt 0 ] ; then
2389      IGCM_debug_Print 2 "IGCM_sys_ncrcat : error code ${status}"
[938]2390      cat /tmp/out_command.$$
2391      \rm /tmp/out_command.$$
[714]2392      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
[800]2393      sleep $DELAI
[938]2394    elif [ ! "X$( grep "WARNING Intra-file non-monotonicity" /tmp/out_command.$$ )" = "X" ] ; then
[811]2395      IGCM_debug_Print 2 "IGCM_sys_ncrcat : WARNING Intra-file non-monotonicity"
[938]2396      cat /tmp/out_command.$$
[811]2397      # remove files having corrupted time axis
2398      eval lastArg=\${$#}
2399      IGCM_debug_Print 2 "IGCM_sys_ncrcat : Delete ${lastArg}"
2400      \rm ${lastArg}
[938]2401      \rm /tmp/out_command.$$
[811]2402      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2403      sleep $DELAI
[714]2404    else
[938]2405      \rm /tmp/out_command.$$
[714]2406      break
2407    fi
2408    (( i = i + 1 ))
2409  done
2410
2411  if [ ${status} -gt 0 ] ; then
[811]2412    echo "IGCM_sys_ncrcat : ncrcat error"
2413    #IGCM_debug_Exit "ncrcat"
[657]2414  fi
[16]2415
[657]2416  IGCM_debug_PopStack "IGCM_sys_ncrcat"
[16]2417}
2418
[811]2419#D-#==================================================
2420#D-function IGCM_sys_ncrename
2421#D-* Purpose: encapsulate ncrename call so as to manage error code and retry
2422#D-* Examples:
2423#D-
[16]2424function IGCM_sys_ncrename {
[657]2425  IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
2426  if ( $DEBUG_sys ) ; then
2427    echo "IGCM_sys_ncrename :" $@
2428  fi
[714]2429
2430  typeset NB_ESSAI DELAI status i
2431  # number of tentative
2432  NB_ESSAI=3
2433  # time delay between tentative
2434  DELAI=2
2435
2436  i=0
2437  while [ $i -lt $NB_ESSAI ] ; do
[938]2438    ncrename $@ > /tmp/out_command.$$ 2>&1
[714]2439    status=$?
2440    if [ ${status} -gt 0 ] ; then
2441      IGCM_debug_Print 2 "IGCM_sys_ncrename : error code ${status}"
[938]2442      cat /tmp/out_command.$$
2443      \rm /tmp/out_command.$$
[714]2444      IGCM_debug_Print 2 "IGCM_sys_ncrename : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
[800]2445      sleep $DELAI
[714]2446    else
[938]2447      \rm /tmp/out_command.$$
[714]2448      break
2449    fi
2450    (( i = i + 1 ))
2451  done
2452
2453  if [ ${status} -gt 0 ] ; then
[811]2454    echo "IGCM_sys_ncrename : ncrename error"
2455    IGCM_debug_Exit "ncrename"
[657]2456  fi
[16]2457
[657]2458  IGCM_debug_PopStack "IGCM_sys_ncrename"
[16]2459}
2460
[811]2461#D-#==================================================
2462#D-function IGCM_sys_ncwa
2463#D-* Purpose: encapsulate ncwa call so as to manage error code and retry
2464#D-* Examples:
2465#D-
[16]2466function IGCM_sys_ncwa {
[657]2467  IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
2468  if ( $DEBUG_sys ) ; then
2469    echo "IGCM_sys_ncwa :" $@
2470  fi
[714]2471
2472  typeset NB_ESSAI DELAI status i
2473  # number of tentative
2474  NB_ESSAI=3
2475  # time delay between tentative
2476  DELAI=2
2477
2478  i=0
2479  while [ $i -lt $NB_ESSAI ] ; do
[938]2480    ncwa $@ > /tmp/out_command.$$ 2>&1
[714]2481    status=$?
2482    if [ ${status} -gt 0 ] ; then
2483      IGCM_debug_Print 2 "IGCM_sys_ncwa : error code ${status}"
[938]2484      cat /tmp/out_command.$$
2485      \rm /tmp/out_command.$$
[714]2486      IGCM_debug_Print 2 "IGCM_sys_ncwa : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
[800]2487      sleep $DELAI
[714]2488    else
[938]2489      \rm /tmp/out_command.$$
[714]2490      break
2491    fi
2492    (( i = i + 1 ))
2493  done
2494
2495  if [ ${status} -gt 0 ] ; then
[811]2496    echo "IGCM_sys_ncwa : ncwa error"
2497    IGCM_debug_Exit "ncwa"
[657]2498  fi
[16]2499
[657]2500  IGCM_debug_PopStack "IGCM_sys_ncwa"
[16]2501}
2502
[284]2503##############################################################
2504# CDO OPERATOR
2505
[811]2506#D-#==================================================
2507#D-function IGCM_sys_cdo
2508#D-* Purpose: encapsulate cdo call so as to manage error code and retry
2509#D-* Examples:
2510#D-
[284]2511function IGCM_sys_cdo {
[657]2512  IGCM_debug_PushStack "IGCM_sys_cdo" -- $@
[714]2513  if ( $DEBUG_sys ) ; then
2514    echo "IGCM_sys_cdo :" $@
2515  fi
[284]2516
[714]2517  typeset status
2518
[938]2519  \cdo $@ > /tmp/out_command.$$ 2>&1
[714]2520  status=$?
2521  if [ ${status} -gt 0 ] ; then
2522    echo "IGCM_sys_cdo : error code ${status}"
[938]2523    cat /tmp/out_command.$$
2524    \rm /tmp/out_command.$$
[284]2525    IGCM_debug_PopStack "IGCM_sys_cdo"
[657]2526    return 1
2527  else
2528    IGCM_debug_PopStack "IGCM_sys_cdo"
2529    return 0
2530  fi
[284]2531
[657]2532  IGCM_debug_PopStack "IGCM_sys_cdo"
[16]2533}
Note: See TracBrowser for help on using the repository browser.