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

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

Active instrumentation #140 disturbs this kind of call
TarFileLocation?=$( IGCM_sys_PrepareTaredRestart ${TarFileFound?} )

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