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

Last change on this file since 828 was 828, checked in by sdipsl, 11 years ago
  • Stack file management must be kept in libIGCM_debug
  • Property svn:keywords set to Revision Author Date
File size: 70.3 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_Put_Dods
1547#D-* Purpose: Put $(ARCHIVE) files on DODS internet protocole.
1548#D-* Examples:
1549#D-
1550function IGCM_sys_Put_Dods {
1551  IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
1552  if ( $DEBUG_sys ) ; then
1553    echo "IGCM_sys_Put_Dods :" $@
1554  fi
1555  if [ $DRYRUN = 0 ]; then
1556    # We take our time on that
1557    sleep 10
1558    IGCM_sys_TestDirArchive ${R_SAVE}/${1}
1559    if [ $? != 0 ] ; then
1560      echo "WARNING : IGCM_sys_Put_Dods ${R_SAVE}/${1} DOES NOT EXIST ."
1561      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1562      return
1563    fi
1564
1565    typeset status
1566    #
1567    rsh gaya exec /bin/ksh <<EOF
1568          cd ${R_SAVE}
1569          /usr/local/bin/dods_rm DODS/pub/${LOGIN}/${R_DODS}/${1} > /dev/null 2>&1
1570          /bin/chmod -R u+w ${R_SAVE}/${1}
1571          /usr/local/bin/dods_cp ${1} DODS/pub/${LOGIN}/${R_DODS} > /dev/null 2>&1
1572          /bin/chmod -R +rX ${R_SAVE}/${1}
1573          /bin/chmod -R u+w ${R_SAVE}/${1}
1574EOF
1575    status=$?
1576
1577    if [ ${status} -gt 0 ] ; then
1578      echo "IGCM_sys_Put_Dods : error."
1579      IGCM_debug_Exit "IGCM_sys_Put_Dods"
1580    fi
1581  fi
1582  IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1583}
1584
1585##############################################################
1586# REBUILD OPERATOR
1587
1588#D-#==================================================
1589#D-function IGCM_sys_rebuild
1590#D-* Purpose: rebuild parallel files
1591#D-* Examples:
1592#D-
1593function IGCM_sys_rebuild {
1594  IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1595  if ( $DEBUG_sys ) ; then
1596    echo "IGCM_sys_rebuild :" $@
1597  fi
1598
1599  typeset NB_ESSAI DELAI status i firstArg
1600  # number of tentative
1601  NB_ESSAI=3
1602  # time delay between tentative
1603  DELAI=2
1604
1605  i=0
1606  while [ $i -lt $NB_ESSAI ] ; do
1607    /smphome/rech/psl/rpsl035/bin/rebuild -f -o $@ > out_rsync 2>&1
1608    status=$?
1609    if [ ${status} -gt 0 ] ; then
1610      IGCM_debug_Print 2 "IGCM_sys_rebuild : error code ${status}"
1611      cat out_rsync
1612      \rm out_rsync
1613      IGCM_debug_Print 2 "IGCM_sys_rebuild : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1614      firstArg=${1}
1615      \rm ${firstArg}
1616      sleep $DELAI
1617    else
1618      \rm out_rsync
1619      break
1620    fi
1621    (( i = i + 1 ))
1622  done
1623
1624  if [ ${status} -gt 0 ] ; then
1625    echo "IGCM_sys_rebuild : rebuild error code is ${status}"
1626    IGCM_debug_Exit "rebuild"
1627  fi
1628
1629  IGCM_debug_PopStack "IGCM_sys_rebuild"
1630}
1631
1632#D-#==================================================
1633#D-function IGCM_sys_rebuild_station
1634#D-* Purpose: rebuild parallel files describing station
1635#D-* Examples:
1636#D-
1637function IGCM_sys_rebuild_station {
1638  IGCM_debug_PushStack "IGCM_sys_rebuild_station" -- $@
1639  typeset i list_opt file_in file_out prefix_invert list_invert
1640  if ( $DEBUG_sys ) ; then
1641    echo "IGCM_sys_rebuild_station :" $@
1642  fi
1643  list_opt=$@
1644
1645  # Invert Axis : t,x -> x,t
1646  #               t,pres,x -> x,t,pres
1647  # So that we can concatenate along x
1648  i=0
1649  for file_in in ${list_opt} ; do
1650    (( i = i + 1))
1651    [ ${i} = 1 ] && file_out=${file_in} && continue
1652    prefix_invert=$( basename ${file_in} .nc )
1653    IGCM_sys_ncpdq -a x,time_counter -a x,time_counter,presnivs ${file_in} ${prefix_invert}_xt.nc
1654    list_invert[${#list_invert[*]}]=${prefix_invert}_xt.nc
1655  done
1656
1657  # Concatenate
1658  IGCM_sys_ncrcat ${list_invert[*]} histstn_xt.nc
1659
1660  # Re-ivert file
1661  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x histstn_xt.nc ${file_out}
1662
1663  # Station re-ordering is too expansive to be run within libICGM
1664  # This is due to (ncpdq - nrcat - ncpdq) I/O sequence.
1665  # This re-ordering must be done "in memory" by the cmorization process
1666  # Anyway this is the best sequence using (ncpdq - nrcat - ncpdq)
1667  # BEGIN reordering
1668
1669  # Only LMDZ text output contains the exact ordering of the station.
1670  # We isolate this in the code below:
1671  #  0  38  -157.5000000000000  70.98591549295774
1672  #  0  54  27.49999999999999   67.18309859154928
1673  #  0  56  -62.50000000000001  82.39436619718309
1674  #  0  79  12.49999999999999   78.59154929577466
1675  #  0  116 -165.0000000000000  76.05633802816901
1676  #  0  117 130.0000000000000   70.98591549295774
1677  #  0  118 110.0000000000000   87.46478873239437
1678  #  1  40  4.999999999999995   51.97183098591550
1679#  typeset iStation iProc list_opt file_in file_out prefix_invert
1680#  typeset -Z4 j4
1681#  typeset -Z3 j3
1682
1683#  unset list_opt
1684#  set +A list_opt $@
1685
1686  # Filename after rebuild
1687#  file_out=${list_opt[0]}
1688  # Prefix of output files
1689#  prefix_invert=$( basename ${file_out} .nc )
1690  # Number of procs
1691#  num_proc=$( grep -i mpi_size ${PREFIX}_${Exe_Output} | wc -l )
1692
1693#  iProc=0
1694#  while [ ${iProc} -lt ${num_proc} ] ; do
1695    # Array containing Station as a number
1696#    unset proc_stn
1697#    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}' )
1698    # Number of stations produced by processor proc
1699#    stationLast=${#proc_stn[*]}
1700    # Proc number on 4 digits
1701#    j4=${iProc}
1702    # Init
1703#    iStation=0
1704#    while [ ${iStation} -lt ${stationLast} ] ; do
1705      # Station number on 3 digits
1706#      j3=${proc_stn[${iStation}]}
1707      # Extract station
1708      # Invert Axis : t,x -> x,t
1709      #               t,pres,x -> x,t,pres
1710      # So that we can concatenate along x
1711#      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
1712#      (( iStation = iStation + 1 ))
1713#    done
1714#    (( iProc = iProc + 1 ))
1715#  done
1716
1717  # Concatenate all station along x
1718#  IGCM_sys_ncrcat ${prefix_invert}_stn_???.nc ${prefix_invert}_xt.nc
1719
1720  # Re-invert file
1721#  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x ${prefix_invert}_xt.nc ${file_out}
1722
1723  # END reordering
1724
1725  IGCM_debug_PopStack "IGCM_sys_rebuild_station"
1726}
1727
1728############################################################
1729# Activate Running Environnment Variables
1730
1731#D-#==================================================
1732#D-function IGCM_sys_desactiv_variables
1733#D-* Purpose: set environement variables prior to execution
1734#D-* Examples:
1735#D-
1736function IGCM_sys_activ_variables {
1737  IGCM_debug_PushStack "IGCM_sys_activ_variables"
1738  if ( $DEBUG_sys ) ; then
1739    echo "IGCM_sys_activ_variables"
1740  fi
1741
1742# --------------------------------------------------------------------
1743#D- MPI specifications
1744# --------------------------------------------------------------------
1745
1746# --------------------------------------------------------------------
1747#D- Other specifications
1748# --------------------------------------------------------------------
1749
1750  ulimit -s unlimited
1751
1752## to be done only one time
1753## export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/smplocal/pub/NetCDF/4.1.3/lib:/smplocal/pub/HDF5/1.8.9/seq/lib
1754  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
1755  echo LD_LIBRARY_PATH = ${LD_LIBRARY_PATH}
1756
1757  IGCM_debug_PopStack "IGCM_sys_activ_variables"
1758}
1759
1760############################################################
1761# Desactivate Running Environnment Variables
1762
1763#D-#==================================================
1764#D-function IGCM_sys_desactiv_variables
1765#D-* Purpose: unset environement variables after execution
1766#D-* Examples:
1767#D-
1768function IGCM_sys_desactiv_variables {
1769  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1770  if ( $DEBUG_sys ) ; then
1771    echo "IGCM_sys_desactiv_variables"
1772  fi
1773# --------------------------------------------------------------------
1774#D- MPI specifications
1775# --------------------------------------------------------------------
1776
1777# --------------------------------------------------------------------
1778#D- Other specifications
1779# --------------------------------------------------------------------
1780
1781  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1782}
1783
1784############################################################
1785# Build MPI/OMP scripts run file (dummy function)
1786
1787#D-#==================================================
1788#D-function IGCM_sys_build_run_file
1789#D-* Purpose: build run file (deprecated)
1790#D-* Examples:
1791#D-
1792function IGCM_sys_build_run_file {
1793
1794  IGCM_debug_Print 3 " dummy function : IGCM_sys_build_run_file "
1795
1796}
1797
1798############################################################
1799# Build MPI/OMP scripts
1800
1801#D-#==================================================
1802#D-function IGCM_sys_build_execution_scripts
1803#D-* Purpose: build execution scripts to be launch by ${HOST_MPIRUN_COMMAND}
1804#D-* Examples:
1805#D-
1806function IGCM_sys_build_execution_scripts
1807{
1808  IGCM_debug_PushStack "IGCM_sys_build_execution_scripts" $@
1809  if ( $DEBUG_sys ) ; then
1810    echo "IGCM_sys_build_execution_scripts " $@
1811  fi
1812
1813  EXECUTION=${HOST_MPIRUN_COMMAND}
1814
1815  if ( ${OK_PARA_MPMD} ) ; then
1816
1817    if [ -f run_file ] ; then
1818      IGCM_sys_Rm -f run_file
1819    fi
1820    touch run_file
1821
1822# run_file construction
1823
1824# Then first loop on the components for the coupler ie oasis
1825
1826### the coupler ie oasis must be the first one
1827    for comp in ${config_ListOfComponents[*]} ; do
1828
1829      eval ExeNameIn=\${config_Executable_${comp}[0]}
1830      eval ExeNameOut=\${config_Executable_${comp}[1]}
1831
1832      # for CPL component only
1833      if [ "X${comp}" = "XCPL" ] ; then
1834
1835        eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1836        eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1837
1838        if ( ${OK_PARA_MPI} ) ; then
1839          (( mpi_count = 1 ))
1840          until [ ${mpi_count} -gt ${comp_proc_mpi_loc} ] ; do
1841            echo "./${ExeNameOut}" >> run_file
1842            (( mpi_count = mpi_count + 1 ))
1843          done
1844        else
1845          echo "./${ExeNameOut} " >> run_file
1846        fi
1847      fi
1848    done
1849
1850# Then second loop on the components
1851
1852    for comp in ${config_ListOfComponents[*]} ; do
1853
1854      eval ExeNameIn=\${config_Executable_${comp}[0]}
1855      eval ExeNameOut=\${config_Executable_${comp}[1]}
1856
1857      # Only if we really have an executable for the component and not the coupler ie oasis:
1858      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${comp}" != "XCPL" ] ) ; then
1859
1860        eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1861        eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1862
1863        if ( ${OK_PARA_MPI} ) ; then
1864          (( mpi_count = 1 ))
1865          until [ ${mpi_count} -gt ${comp_proc_mpi_loc} ] ; do
1866            echo "./${ExeNameOut}" >> run_file
1867            (( mpi_count = mpi_count + 1 ))
1868          done
1869        else
1870            echo "./${ExeNameOut} " >> run_file
1871        fi
1872      fi
1873    done
1874
1875    EXECUTION="${HOST_MPIRUN_COMMAND} -pgmmodel mpmd -cmdfile ./run_file"
1876
1877    IGCM_sys_Chmod u+x run_file
1878    if ( $DEBUG_sys ) ; then
1879      echo "run_file contains : "
1880      cat run_file
1881    fi
1882
1883  else # Only one executable. launch it.
1884
1885    for comp in ${config_ListOfComponents[*]} ; do
1886
1887      # Only if we really have an executable for the component :
1888      eval ExeNameOut=\${config_Executable_${comp}[1]}
1889      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${ExeNameOut}" != "Xinca.dat" ] ) ; then
1890        EXECUTION="${HOST_MPIRUN_COMMAND} ./${ExeNameOut}"
1891      fi
1892
1893    done
1894
1895  fi
1896
1897  IGCM_debug_Print 1 "sys ada : execution command is "
1898  IGCM_debug_Print 1 "$EXECUTION"
1899
1900  IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
1901}
1902
1903############################################################
1904# Check of space available on temporary filesytems.
1905
1906#D-#==================================================
1907#D-function IGCM_sys_check_quota
1908#D-* Purpose: check user quota. Stop the simulation if quota above 90%
1909#D-* Examples:
1910#D-
1911function IGCM_sys_check_quota {
1912  IGCM_debug_PushStack "IGCM_sys_check_quota"
1913  if ( $DEBUG_sys ) ; then
1914    echo "IGCM_sys_check_quota"
1915  fi
1916  # Limit of quota (in %)
1917  limit_quota=90
1918
1919  # Check of the volume
1920  volume_quota=$(quota_u -w | grep 'Quota soft' | awk '{print $5}')
1921  if [ ! X${volume_quota} = X ] ; then
1922    quota_volume=${volume_quota%%\%}
1923#    echo $quota_volume
1924    if [ ${quota_volume} -ge ${limit_quota} ] ; then
1925      IGCM_debug_Print 1 "Please, check your quota of volume on workgpfs"
1926      IGCM_debug_Print 1 "${quota_volume}% of your quota is used"
1927      IGCM_debug_Print 1 "Use the quota_u -w command to check"
1928      IGCM_debug_Print 1 "You must have more than 10% available to run"
1929      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
1930      IGCM_debug_Verif_Exit
1931    fi
1932
1933  fi
1934  IGCM_debug_PopStack "IGCM_sys_check_quota"
1935}
1936
1937#D-#==================================================
1938#D-function IGCM_sys_CountJobInQueue
1939#D-* Purpose: Check if job_name is currently
1940#D-  running or in queue
1941#D-* Examples: IGCM_sys_CountJobInQueue ${JobName} NbRun
1942#D-
1943function IGCM_sys_CountJobInQueue {
1944  IGCM_debug_PushStack "IGCM_sys_CountJobInQueue"
1945  if ( $DEBUG_sys ) ; then
1946    echo "IGCM_sys_CountJobInQueue"
1947  fi
1948
1949  # Print only the full (-W) JobName (%jn)
1950  NbRun=$( llq -W -f %jn | grep -c "$1" )
1951
1952  eval ${2}=${NbRun}
1953
1954  IGCM_debug_PopStack "IGCM_sys_CountJobInQueue"
1955}
1956
1957##############################################################
1958# NCO OPERATOR
1959
1960#D-#==================================================
1961#D-function IGCM_sys_ncap2
1962#D-* Purpose: encapsulate ncap2 call so as to manage error code and retry
1963#D-* Examples:
1964#D-
1965function IGCM_sys_ncap2 {
1966  IGCM_debug_PushStack "IGCM_sys_ncap2" -- $@
1967  if ( $DEBUG_sys ) ; then
1968    echo "IGCM_sys_ncap2 :" $@
1969  fi
1970
1971  typeset NB_ESSAI DELAI status i
1972  # number of tentative
1973  NB_ESSAI=3
1974  # time delay between tentative
1975  DELAI=2
1976
1977  i=0
1978  while [ $i -lt $NB_ESSAI ] ; do
1979    ncap2 "$@" > out_rsync 2>&1
1980    status=$?
1981    if [ ${status} -gt 0 ] ; then
1982      IGCM_debug_Print 2 "IGCM_sys_ncap2 : error code ${status}"
1983      cat out_rsync
1984      \rm out_rsync
1985      IGCM_debug_Print 2 "IGCM_sys_ncap2 : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1986      sleep $DELAI
1987    else
1988      \rm out_rsync
1989      break
1990    fi
1991    (( i = i + 1 ))
1992  done
1993
1994  if [ ${status} -gt 0 ] ; then
1995    echo "IGCM_sys_ncap2 : ncap2 error"
1996    IGCM_debug_Exit "ncap2"
1997  fi
1998
1999  IGCM_debug_PopStack "IGCM_sys_ncap2"
2000}
2001
2002#D-#==================================================
2003#D-function IGCM_sys_ncatted
2004#D-* Purpose: encapsulate ncatted call so as to manage error code and retry
2005#D-* Examples:
2006#D-
2007function IGCM_sys_ncatted {
2008  IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
2009  if ( $DEBUG_sys ) ; then
2010    echo "IGCM_sys_ncatted :" $@
2011  fi
2012
2013  typeset NB_ESSAI DELAI status i
2014  # number of tentative
2015  NB_ESSAI=3
2016  # time delay between tentative
2017  DELAI=2
2018
2019  i=0
2020  while [ $i -lt $NB_ESSAI ] ; do
2021    ncatted "$@" > out_rsync 2>&1
2022    status=$?
2023    if [ ${status} -gt 0 ] ; then
2024      IGCM_debug_Print 2 "IGCM_sys_ncatted : error code ${status}"
2025      cat out_rsync
2026      \rm out_rsync
2027      IGCM_debug_Print 2 "IGCM_sys_ncatted : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2028      sleep $DELAI
2029    else
2030      \rm out_rsync
2031      break
2032    fi
2033    (( i = i + 1 ))
2034  done
2035
2036  if [ ${status} -gt 0 ] ; then
2037    echo "IGCM_sys_ncatted : ncatted error"
2038    IGCM_debug_Exit "ncatted"
2039  fi
2040
2041  IGCM_debug_PopStack "IGCM_sys_ncatted"
2042}
2043
2044#D-#==================================================
2045#D-function IGCM_sys_ncbo
2046#D-* Purpose: encapsulate ncbo call so as to manage error code and retry
2047#D-* Examples:
2048#D-
2049function IGCM_sys_ncbo {
2050  IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
2051  if ( $DEBUG_sys ) ; then
2052    echo "IGCM_sys_ncbo :" $@
2053  fi
2054
2055  typeset NB_ESSAI DELAI status i
2056  # number of tentative
2057  NB_ESSAI=3
2058  # time delay between tentative
2059  DELAI=2
2060
2061  i=0
2062  while [ $i -lt $NB_ESSAI ] ; do
2063    ncbo $@ > out_rsync 2>&1
2064    status=$?
2065    if [ ${status} -gt 0 ] ; then
2066      IGCM_debug_Print 2 "IGCM_sys_ncbo : error code ${status}"
2067      cat out_rsync
2068      \rm out_rsync
2069      IGCM_debug_Print 2 "IGCM_sys_ncbo : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2070      sleep $DELAI
2071    else
2072      \rm out_rsync
2073      break
2074    fi
2075    (( i = i + 1 ))
2076  done
2077
2078  if [ ${status} -gt 0 ] ; then
2079    echo "IGCM_sys_ncbo : ncbo error"
2080    IGCM_debug_Exit "ncbo"
2081  fi
2082
2083  IGCM_debug_PopStack "IGCM_sys_ncbo"
2084}
2085
2086#D-#==================================================
2087#D-function IGCM_sys_ncdif
2088#D-* Purpose: encapsulate ncdiff call so as to manage error code and retry
2089#D-* Examples:
2090#D-
2091function IGCM_sys_ncdiff {
2092  IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
2093  if ( $DEBUG_sys ) ; then
2094    echo "IGCM_sys_ncdiff :" $@
2095  fi
2096
2097  typeset NB_ESSAI DELAI status i
2098  # number of tentative
2099  NB_ESSAI=3
2100  # time delay between tentative
2101  DELAI=2
2102
2103  i=0
2104  while [ $i -lt $NB_ESSAI ] ; do
2105    ncdiff $@ > out_rsync 2>&1
2106    status=$?
2107    if [ ${status} -gt 0 ] ; then
2108      IGCM_debug_Print 2 "IGCM_sys_ncdiff : error code ${status}"
2109      cat out_rsync
2110      \rm out_rsync
2111      IGCM_debug_Print 2 "IGCM_sys_ncdiff : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2112      sleep $DELAI
2113    else
2114      \rm out_rsync
2115      break
2116    fi
2117    (( i = i + 1 ))
2118  done
2119
2120  if [ ${status} -gt 0 ] ; then
2121    echo "IGCM_sys_ncdiff : ncdiff error"
2122    IGCM_debug_Exit "ncdiff"
2123  fi
2124
2125  IGCM_debug_PopStack "IGCM_sys_ncdiff"
2126}
2127
2128#D-#==================================================
2129#D-function IGCM_sys_ncea
2130#D-* Purpose: encapsulate ncea call so as to manage error code and retry
2131#D-* Examples:
2132#D-
2133function IGCM_sys_ncea {
2134  IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
2135  if ( $DEBUG_sys ) ; then
2136    echo "IGCM_sys_ncea :" $@
2137  fi
2138
2139  typeset NB_ESSAI DELAI status i
2140  # number of tentative
2141  NB_ESSAI=3
2142  # time delay between tentative
2143  DELAI=2
2144
2145  i=0
2146  while [ $i -lt $NB_ESSAI ] ; do
2147    ncea $@ > out_rsync 2>&1
2148    status=$?
2149    if [ ${status} -gt 0 ] ; then
2150      IGCM_debug_Print 2 "IGCM_sys_ncea : error code ${status}"
2151      cat out_rsync
2152      \rm out_rsync
2153      IGCM_debug_Print 2 "IGCM_sys_ncea : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2154      sleep $DELAI
2155    else
2156      \rm out_rsync
2157      break
2158    fi
2159    (( i = i + 1 ))
2160  done
2161
2162  if [ ${status} -gt 0 ] ; then
2163    echo "IGCM_sys_ncea : ncea error"
2164    IGCM_debug_Exit "ncea"
2165  fi
2166
2167  IGCM_debug_PopStack "IGCM_sys_ncea"
2168}
2169
2170#D-#==================================================
2171#D-function IGCM_sys_ncecat
2172#D-* Purpose: encapsulate ncecat call so as to manage error code and retry
2173#D-* Examples:
2174#D-
2175function IGCM_sys_ncecat {
2176  IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
2177  if ( $DEBUG_sys ) ; then
2178    echo "IGCM_sys_ncecat :" $@
2179  fi
2180
2181  typeset NB_ESSAI DELAI status i
2182  # number of tentative
2183  NB_ESSAI=3
2184  # time delay between tentative
2185  DELAI=2
2186
2187  i=0
2188  while [ $i -lt $NB_ESSAI ] ; do
2189    ncecat $@ > out_rsync 2>&1
2190    status=$?
2191    if [ ${status} -gt 0 ] ; then
2192      IGCM_debug_Print 2 "IGCM_sys_ncecat : error code ${status}"
2193      cat out_rsync
2194      \rm out_rsync
2195      IGCM_debug_Print 2 "IGCM_sys_ncecat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2196      sleep $DELAI
2197    else
2198      \rm out_rsync
2199      break
2200    fi
2201    (( i = i + 1 ))
2202  done
2203
2204  if [ ${status} -gt 0 ] ; then
2205    echo "IGCM_sys_ncecat : ncecat error"
2206    IGCM_debug_Exit "ncecat"
2207  fi
2208
2209  IGCM_debug_PopStack "IGCM_sys_ncecat"
2210}
2211
2212#D-#==================================================
2213#D-function IGCM_sys_ncflint
2214#D-* Purpose: encapsulate ncflint call so as to manage error code and retry
2215#D-* Examples:
2216#D-
2217function IGCM_sys_ncflint {
2218  IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
2219  if ( $DEBUG_sys ) ; then
2220    echo "IGCM_sys_ncflint :" $@
2221  fi
2222
2223  typeset NB_ESSAI DELAI status i
2224  # number of tentative
2225  NB_ESSAI=3
2226  # time delay between tentative
2227  DELAI=2
2228
2229  i=0
2230  while [ $i -lt $NB_ESSAI ] ; do
2231    ncflint $@ > out_rsync 2>&1
2232    status=$?
2233    if [ ${status} -gt 0 ] ; then
2234      IGCM_debug_Print 2 "IGCM_sys_ncflint : error code ${status}"
2235      cat out_rsync
2236      \rm out_rsync
2237      IGCM_debug_Print 2 "IGCM_sys_ncflint : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2238      sleep $DELAI
2239    else
2240      \rm out_rsync
2241      break
2242    fi
2243    (( i = i + 1 ))
2244  done
2245
2246  if [ ${status} -gt 0 ] ; then
2247    echo "IGCM_sys_ncflint : ncflint error"
2248    IGCM_debug_Exit "ncflint"
2249  fi
2250
2251  IGCM_debug_PopStack "IGCM_sys_ncflint"
2252}
2253
2254#D-#==================================================
2255#D-function IGCM_sys_ncks
2256#D-* Purpose: encapsulate ncks call so as to manage error code and retry
2257#D-* Examples:
2258#D-
2259function IGCM_sys_ncks {
2260  IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
2261  if ( $DEBUG_sys ) ; then
2262    echo "IGCM_sys_ncks :" $@
2263  fi
2264
2265  typeset NB_ESSAI DELAI status i
2266  # number of tentative
2267  NB_ESSAI=3
2268  # time delay between tentative
2269  DELAI=2
2270
2271  i=0
2272  while [ $i -lt $NB_ESSAI ] ; do
2273    ncks $@ > out_rsync 2>&1
2274    status=$?
2275    if [ ${status} -gt 0 ] ; then
2276      IGCM_debug_Print 2 "IGCM_sys_ncks : error code ${status}"
2277      cat out_rsync
2278      \rm out_rsync
2279      IGCM_debug_Print 2 "IGCM_sys_ncks : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2280      sleep $DELAI
2281    else
2282      \rm out_rsync
2283      break
2284    fi
2285    (( i = i + 1 ))
2286  done
2287
2288  if [ ${status} -gt 0 ] ; then
2289    echo "IGCM_sys_ncks : ncks error"
2290    IGCM_debug_Exit "ncks"
2291  fi
2292
2293  IGCM_debug_PopStack "IGCM_sys_ncks"
2294}
2295
2296#D-#==================================================
2297#D-function IGCM_sys_ncpdq
2298#D-* Purpose: encapsulate ncpdq call so as to manage error code and retry
2299#D-* Examples:
2300#D-
2301function IGCM_sys_ncpdq {
2302  IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
2303  if ( $DEBUG_sys ) ; then
2304    echo "IGCM_sys_ncpdq :" $@
2305  fi
2306
2307  typeset NB_ESSAI DELAI status i
2308  # number of tentative
2309  NB_ESSAI=3
2310  # time delay between tentative
2311  DELAI=2
2312
2313  i=0
2314  while [ $i -lt $NB_ESSAI ] ; do
2315    ncpdq $@ > out_rsync 2>&1
2316    status=$?
2317    if [ ${status} -gt 0 ] ; then
2318      IGCM_debug_Print 2 "IGCM_sys_ncpdq : error code ${status}"
2319      cat out_rsync
2320      \rm out_rsync
2321      IGCM_debug_Print 2 "IGCM_sys_ncpdq : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2322      sleep $DELAI
2323    else
2324      \rm out_rsync
2325      break
2326    fi
2327    (( i = i + 1 ))
2328  done
2329
2330  if [ ${status} -gt 0 ] ; then
2331    echo "IGCM_sys_ncpdq : ncpdq error"
2332    IGCM_debug_Exit "ncpdq"
2333  fi
2334
2335  IGCM_debug_PopStack "IGCM_sys_ncpdq"
2336}
2337
2338#D-#==================================================
2339#D-function IGCM_sys_ncra
2340#D-* Purpose: encapsulate ncra call so as to manage error code and retry
2341#D-* Examples:
2342#D-
2343function IGCM_sys_ncra {
2344  IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
2345  if ( $DEBUG_sys ) ; then
2346    echo "IGCM_sys_ncra :" $@
2347  fi
2348
2349  typeset NB_ESSAI DELAI status i
2350  # number of tentative
2351  NB_ESSAI=3
2352  # time delay between tentative
2353  DELAI=2
2354
2355  i=0
2356  while [ $i -lt $NB_ESSAI ] ; do
2357    ncra $@ > out_rsync 2>&1
2358    status=$?
2359    if [ ${status} -gt 0 ] ; then
2360      IGCM_debug_Print 2 "IGCM_sys_ncra : error code ${status}"
2361      cat out_rsync
2362      \rm out_rsync
2363      IGCM_debug_Print 2 "IGCM_sys_ncra : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2364      sleep $DELAI
2365    else
2366      \rm out_rsync
2367      break
2368    fi
2369    (( i = i + 1 ))
2370  done
2371
2372  if [ ${status} -gt 0 ] ; then
2373    echo "IGCM_sys_ncra : ncra error"
2374    IGCM_debug_Exit "ncra"
2375  fi
2376
2377  IGCM_debug_PopStack "IGCM_sys_ncra"
2378}
2379
2380#D-#==================================================
2381#D-function IGCM_sys_ncrcat
2382#D-* Purpose: encapsulate ncrcat call so as to manage error code and retry
2383#D-* Examples:
2384#D-
2385function IGCM_sys_ncrcat {
2386  IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
2387  if ( $DEBUG_sys ) ; then
2388    echo "IGCM_sys_ncrcat :" $@
2389  fi
2390
2391  typeset NB_ESSAI DELAI status i lastArg
2392  # number of tentative
2393  NB_ESSAI=3
2394  # time delay between tentative
2395  DELAI=2
2396
2397  i=0
2398  while [ $i -lt $NB_ESSAI ] ; do
2399    ncrcat $@ > out_rsync 2>&1
2400    status=$?
2401    if [ ${status} -gt 0 ] ; then
2402      IGCM_debug_Print 2 "IGCM_sys_ncrcat : error code ${status}"
2403      cat out_rsync
2404      \rm out_rsync
2405      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2406      sleep $DELAI
2407    elif [ ! "X$( grep "WARNING Intra-file non-monotonicity" out_rsync )" = "X" ] ; then
2408      IGCM_debug_Print 2 "IGCM_sys_ncrcat : WARNING Intra-file non-monotonicity"
2409      cat out_rsync
2410      # remove files having corrupted time axis
2411      eval lastArg=\${$#}
2412      IGCM_debug_Print 2 "IGCM_sys_ncrcat : Delete ${lastArg}"
2413      \rm ${lastArg}
2414      \rm out_rsync
2415      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2416      sleep $DELAI
2417    else
2418      \rm out_rsync
2419      break
2420    fi
2421    (( i = i + 1 ))
2422  done
2423
2424  if [ ${status} -gt 0 ] ; then
2425    echo "IGCM_sys_ncrcat : ncrcat error"
2426    #IGCM_debug_Exit "ncrcat"
2427  fi
2428
2429  IGCM_debug_PopStack "IGCM_sys_ncrcat"
2430}
2431
2432#D-#==================================================
2433#D-function IGCM_sys_ncrename
2434#D-* Purpose: encapsulate ncrename call so as to manage error code and retry
2435#D-* Examples:
2436#D-
2437function IGCM_sys_ncrename {
2438  IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
2439  if ( $DEBUG_sys ) ; then
2440    echo "IGCM_sys_ncrename :" $@
2441  fi
2442
2443  typeset NB_ESSAI DELAI status i
2444  # number of tentative
2445  NB_ESSAI=3
2446  # time delay between tentative
2447  DELAI=2
2448
2449  i=0
2450  while [ $i -lt $NB_ESSAI ] ; do
2451    ncrename $@ > out_rsync 2>&1
2452    status=$?
2453    if [ ${status} -gt 0 ] ; then
2454      IGCM_debug_Print 2 "IGCM_sys_ncrename : error code ${status}"
2455      cat out_rsync
2456      \rm out_rsync
2457      IGCM_debug_Print 2 "IGCM_sys_ncrename : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2458      sleep $DELAI
2459    else
2460      \rm out_rsync
2461      break
2462    fi
2463    (( i = i + 1 ))
2464  done
2465
2466  if [ ${status} -gt 0 ] ; then
2467    echo "IGCM_sys_ncrename : ncrename error"
2468    IGCM_debug_Exit "ncrename"
2469  fi
2470
2471  IGCM_debug_PopStack "IGCM_sys_ncrename"
2472}
2473
2474#D-#==================================================
2475#D-function IGCM_sys_ncwa
2476#D-* Purpose: encapsulate ncwa call so as to manage error code and retry
2477#D-* Examples:
2478#D-
2479function IGCM_sys_ncwa {
2480  IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
2481  if ( $DEBUG_sys ) ; then
2482    echo "IGCM_sys_ncwa :" $@
2483  fi
2484
2485  typeset NB_ESSAI DELAI status i
2486  # number of tentative
2487  NB_ESSAI=3
2488  # time delay between tentative
2489  DELAI=2
2490
2491  i=0
2492  while [ $i -lt $NB_ESSAI ] ; do
2493    ncwa $@ > out_rsync 2>&1
2494    status=$?
2495    if [ ${status} -gt 0 ] ; then
2496      IGCM_debug_Print 2 "IGCM_sys_ncwa : error code ${status}"
2497      cat out_rsync
2498      \rm out_rsync
2499      IGCM_debug_Print 2 "IGCM_sys_ncwa : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2500      sleep $DELAI
2501    else
2502      \rm out_rsync
2503      break
2504    fi
2505    (( i = i + 1 ))
2506  done
2507
2508  if [ ${status} -gt 0 ] ; then
2509    echo "IGCM_sys_ncwa : ncwa error"
2510    IGCM_debug_Exit "ncwa"
2511  fi
2512
2513  IGCM_debug_PopStack "IGCM_sys_ncwa"
2514}
2515
2516##############################################################
2517# CDO OPERATOR
2518
2519#D-#==================================================
2520#D-function IGCM_sys_cdo
2521#D-* Purpose: encapsulate cdo call so as to manage error code and retry
2522#D-* Examples:
2523#D-
2524function IGCM_sys_cdo {
2525  IGCM_debug_PushStack "IGCM_sys_cdo" -- $@
2526  if ( $DEBUG_sys ) ; then
2527    echo "IGCM_sys_cdo :" $@
2528  fi
2529
2530  typeset status
2531
2532  \cdo $@ > out_rsync 2>&1
2533  status=$?
2534  if [ ${status} -gt 0 ] ; then
2535    echo "IGCM_sys_cdo : error code ${status}"
2536    cat out_rsync
2537    \rm out_rsync
2538    IGCM_debug_PopStack "IGCM_sys_cdo"
2539    return 1
2540  else
2541    IGCM_debug_PopStack "IGCM_sys_cdo"
2542    return 0
2543  fi
2544
2545  IGCM_debug_PopStack "IGCM_sys_cdo"
2546}
Note: See TracBrowser for help on using the repository browser.