source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_iitm.ksh @ 922

Last change on this file since 922 was 922, checked in by sdipsl, 11 years ago

Once per simulation send email containing estimated consumed hours for the whole simulation and a recommended PeriodNb?

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