source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_ada.ksh @ 835

Last change on this file since 835 was 835, checked in by labetoulle, 11 years ago

Runchecker : add rsh access for monitoring files on Ada. See #128.

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