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

Last change on this file since 826 was 818, checked in by sdipsl, 11 years ago
  • Side effect of the SpaceName?=TEST behaviour implementation at IDRIS related to IGCM_sys_IsFileArchived function.

Affect only Ada and is in fact the root cause of #110

  • Property svn:keywords set to Revision Author Date
File size: 71.2 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  else
918    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
919  fi
920
921  IGCM_debug_PopStack "IGCM_sys_Mv"
922}
923
924#D-#==================================================
925#D-function IGCM_sys_Put_Dir
926#D-* Purpose: Copy a complete directory on $(ARCHIVE)
927#D-* Examples:
928#D-
929function IGCM_sys_Put_Dir {
930  IGCM_debug_PushStack "IGCM_sys_Put_Dir" $@
931  if ( $DEBUG_sys ) ; then
932    echo "IGCM_sys_Put_Dir :" $@
933  fi
934  if [ $DRYRUN = 0 ]; then
935    if [ ! -d ${1} ] ; then
936      echo "WARNING : IGCM_sys_Put_Dir ${1} DOES NOT EXIST ."
937      IGCM_debug_PopStack "IGCM_sys_Put_Dir"
938      return
939    fi
940
941    typeset status
942
943    # Only if we use rsync
944    #IGCM_sys_TestDirArchive $( dirname $2 )
945    #
946    #Command depends on targeted file system
947    DEBUG_sys=false IGCM_sys_IsFileArchived $2
948    if [ $? = 0 ] ; then
949      \rcp -r $1 ${STOREHOST}:$2 > out_rsync 2>&1
950      status=$?
951    else
952      \cp -r $1 $2 > out_rsync 2>&1
953      status=$?
954    fi
955
956    if [ ${status} -gt 0 ] ; then
957      IGCM_debug_Print 2 "IGCM_sys_Put_Dir : rcp or cp failed error code ${status}"
958      cat out_rsync
959      IGCM_debug_Exit "IGCM_sys_Put_Dir"
960    else
961      \rm out_rsync
962    fi
963  else
964    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
965  fi
966  IGCM_debug_PopStack "IGCM_sys_Put_Dir"
967}
968
969#D-#==================================================
970#D-function IGCM_sys_Get_Dir
971#D-* Purpose: Copy a complete directory from ${ARCHIVE}
972#D-* Examples:
973#D-
974function IGCM_sys_Get_Dir {
975  IGCM_debug_PushStack "IGCM_sys_Get_Dir" $@
976  if ( $DEBUG_sys ) ; then
977    echo "IGCM_sys_Get_Dir :" $@
978  fi
979  if [ $DRYRUN = 0 ]; then
980#    if [ ! -d ${1} ] ; then
981#      echo "WARNING : IGCM_sys_Get_Dir ${1} DOES NOT EXIST ."
982#      IGCM_debug_PopStack "IGCM_sys_Get_Dir"
983#      return
984#    fi
985
986    typeset NB_ESSAI DELAI status i
987    # number of tentative
988    NB_ESSAI=3
989    # time delay between tentative
990    DELAI=2
991
992    # Only if we use rsync
993    #IGCM_sys_TestDirArchive $( dirname $2 )
994    #
995    # Command depends on targeted filesystem
996    DEBUG_sys=false IGCM_sys_IsFileArchived $1
997    if [ $? = 0 ] ; then
998      # add dmget (to demigrate all offline files) to reduce time of this command :
999      IGCM_sys_RshArchive "dmfind $1 -state MIG -o -state OFL -o -state PAR | dmget -q -n"
1000      i=0
1001      while [ $i -lt $NB_ESSAI ] ; do
1002        \rcp -rp ${STOREHOST}:$1 $2 > out_rsync 2>&1
1003        status=$?
1004        if [ ${status} -gt 0 ]; then
1005          IGCM_debug_Print 2 "IGCM_sys_Get_Dir : rcp failed error code ${status} ${i}/${NB_ESSAI}"
1006          IGCM_debug_Print 2 "IGCM_sys_Get_Dir : sleep ${DELAI} seconds and try again."
1007          sleep $DELAI
1008        else
1009          break
1010        fi
1011        (( i = i + 1 ))
1012      done
1013    else
1014      \cp -rp $1 $2 > out_rsync 2>&1
1015      status=$?
1016      if [ ${status} -gt 0 ] ; then
1017        IGCM_debug_Print 2 "IGCM_sys_Get_Dir : cp failed error code ${status}"
1018        cat out_rsync
1019        IGCM_debug_Exit "IGCM_sys_Get_Dir"
1020      else
1021        \rm out_rsync
1022      fi
1023    fi
1024    if [ ${status} -gt 0 ] ; then
1025      echo "IGCM_sys_Get_Dir : error."
1026      cat out_rsync
1027      IGCM_debug_Exit "IGCM_sys_Get_Dir"
1028    else
1029      \rm out_rsync
1030    fi
1031  else
1032    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1033  fi
1034  IGCM_debug_PopStack "IGCM_sys_Get_Dir"
1035}
1036
1037#D-#==================================================
1038#D-function IGCM_sys_Get_Master
1039#D-* Purpose: Copy a complete directory from MASTER filesystem
1040#D-* Examples:
1041#D-
1042function IGCM_sys_Get_Master {
1043  IGCM_debug_PushStack "IGCM_sys_Get_Master" $@
1044  if ( $DEBUG_sys ) ; then
1045    echo "IGCM_sys_Get_Master :" $@
1046  fi
1047  if [ $DRYRUN = 0 ]; then
1048    if ( [ ! -d ${1} ] && [ ! -f ${1} ] ) ; then
1049      echo "WARNING : IGCM_sys_Get_Master ${1} DOES NOT EXIST ."
1050      IGCM_debug_PopStack "IGCM_sys_Get_Master"
1051      return
1052    fi
1053
1054    typeset NB_ESSAI DELAI status i
1055    # number of tentative
1056    NB_ESSAI=3
1057    # time delay between tentative
1058    DELAI=2
1059
1060    i=0
1061    while [ $i -lt $NB_ESSAI ] ; do
1062      \cp -urL $1 $2 > out_rsync 2>&1
1063      status=$?
1064      if [ ${status} -gt 0 ]; then
1065        IGCM_debug_Print 2 "IGCM_sys_Get_Master : cp failed error code ${status} ${i}/${NB_ESSAI}"
1066        IGCM_debug_Print 2 "IGCM_sys_Get_Master : sleep ${DELAI} seconds and try again."
1067        sleep $DELAI
1068      else
1069        break
1070      fi
1071      (( i = i + 1 ))
1072    done
1073
1074    if [ ${status} -gt 0 ] ; then
1075      echo "IGCM_sys_Get_Master : error."
1076      cat out_rsync
1077      IGCM_debug_Exit "IGCM_sys_Get_Master"
1078    else
1079      \rm out_rsync
1080    fi
1081  else
1082    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1083  fi
1084  IGCM_debug_PopStack "IGCM_sys_Get_Master"
1085}
1086
1087#====================================================
1088#- Call IGCM_sys_Mirror_libIGCM now !
1089if ( $MirrorlibIGCM ) ; then
1090  IGCM_sys_Mirror_libIGCM
1091fi
1092
1093#D-#==================================================
1094#D-function IGCM_sys_Put_Rest
1095#D-* Purpose: Put computied restarts on ${ARCHIVE}.
1096#D-           File and target directory must exist.
1097#D-* Examples:
1098#D-
1099function IGCM_sys_Put_Rest {
1100  IGCM_debug_PushStack "IGCM_sys_Put_Rest" $@
1101  if ( $DEBUG_sys ) ; then
1102    echo "IGCM_sys_Put_Rest :" $@
1103  fi
1104  if [ $DRYRUN = 0 ]; then
1105    if [ ! -f ${1} ] ; then
1106      echo "ERROR : IGCM_sys_Put_Rest ${1} DOES NOT EXIST ."
1107      IGCM_debug_Exit "IGCM_sys_Put_Rest"
1108    fi
1109
1110    typeset status
1111    #
1112    if [ X${JobType} = XRUN ] ; then
1113      IGCM_sys_Chmod 444 ${1}
1114    fi
1115    #
1116    #
1117    #Command depends on targeted file system
1118    DEBUG_sys=false IGCM_sys_IsFileArchived $2
1119    if [ $? = 0 ] ; then
1120      mfput $1 $2 > out_rsync 2>&1
1121      status=$?
1122    else
1123      IGCM_sys_MkdirArchive $( dirname $2 )
1124      \cp $1 $2 > out_rsync 2>&1
1125      status=$?
1126    fi
1127
1128#       #RSYNC WITH NETWORK RSH CALL
1129#       IGCM_sys_MkdirArchive $( dirname $2 )
1130#       echo ${RSYNC} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${RUN_DIR}/$1 ${STOREHOST}:${2} > out_rsync 2>&1
1131#       ${RSYNC} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> out_rsync 2>&1
1132
1133#       #RSYNC WITH NFS USE
1134#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
1135#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
1136
1137#       status=$?
1138#       IGCM_sys_Rsync_out $status
1139
1140#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1141#       (( status=status+$? ))
1142
1143    if [ ${status} -gt 0 ] ; then
1144      echo "IGCM_sys_Put_Rest : mfput or cp failed error code ${status}"
1145      cat out_rsync
1146      IGCM_debug_Exit "IGCM_sys_Put_Rest"
1147    else
1148      \rm out_rsync
1149    fi
1150  else
1151    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1152  fi
1153  IGCM_debug_PopStack "IGCM_sys_Put_Rest"
1154}
1155
1156#D-#==================================================
1157#D-function IGCM_sys_PutBuffer_Rest
1158#D-* Purpose: Put computied restarts on ${SCRATCHDIR}.
1159#D-           File and target directory must exist.
1160#D-* Examples:
1161#D-
1162function IGCM_sys_PutBuffer_Rest {
1163  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Rest" $@
1164  if ( $DEBUG_sys ) ; then
1165    echo "IGCM_sys_PutBuffer_Rest :" $@
1166  fi
1167  if [ $DRYRUN = 0 ]; then
1168    if [ ! -f ${1} ] ; then
1169      echo "ERROR : IGCM_sys_PutBuffer_Rest ${1} DOES NOT EXIST ."
1170      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
1171    fi
1172
1173    typeset status
1174    #
1175    if [ X${JobType} = XRUN ] ; then
1176      IGCM_sys_Chmod 444 ${1}
1177    fi
1178
1179    #
1180    # USUAL WAY
1181    \cp $1 $2 > out_rsync 2>&1
1182    status=$?
1183
1184    if [ ${status} -gt 0 ] ; then
1185      echo "IGCM_sys_PutBuffer_Rest : error code ${status}"
1186      [ -f ${2} ] && ls -l ${2}
1187      [ -f ${2}/${1} ] && ls -l ${2}/${1}
1188      cat out_rsync
1189      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
1190    else
1191      \rm out_rsync
1192    fi
1193  else
1194    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1195  fi
1196  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Rest"
1197}
1198
1199#D-#==================================================
1200#D-function IGCM_sys_PrepareTaredRestart
1201#D-* Purpose: Prepare tared restart to be access by computing job.
1202#D-* Examples:
1203#D-
1204function IGCM_sys_PrepareTaredRestart {
1205  IGCM_debug_PushStack "IGCM_sys_PrepareTaredRestart" $@
1206  if [ $DRYRUN = 0 ]; then
1207    [ ! -f $( basename $1 ) ] && DEBUG_sys=false IGCM_sys_Get $1 .
1208  else
1209    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1210  fi
1211  echo $( basename $1 )
1212  IGCM_debug_PopStack "IGCM_sys_PrepareTaredRestart"
1213}
1214
1215#D-#==================================================
1216#D-function IGCM_sys_Put_Out
1217#D-* Purpose: Copy a file on ${ARCHIVE} after having chmod it in readonly
1218#D-* Examples:
1219#D-
1220function IGCM_sys_Put_Out {
1221  IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
1222  if ( $DEBUG_sys ) ; then
1223    echo "IGCM_sys_Put_Out :" $@
1224  fi
1225
1226  typeset status
1227
1228  if [ $DRYRUN = 0 ]; then
1229    if [ ! -f ${1} ] ; then
1230      echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
1231      IGCM_debug_PopStack "IGCM_sys_Put_Out"
1232      return 1
1233    fi
1234
1235    #
1236    if [ X${JobType} = XRUN ] ; then
1237      if [ X${3} = X ] ; then
1238        IGCM_sys_Chmod 444 ${1}
1239      fi
1240    fi
1241    #
1242    #
1243    #Command depends on targeted file system
1244    DEBUG_sys=false IGCM_sys_IsFileArchived $2
1245    if [ $? = 0 ] ; then
1246      mfput $1 $2 > out_rsync 2>&1
1247      status=$?
1248    else
1249      IGCM_sys_MkdirArchive $( dirname $2 )
1250      \cp $1 $2 > out_rsync 2>&1
1251      status=$?
1252    fi
1253
1254#       #RSYNC WITH NETWORK RSH CALL
1255#       IGCM_sys_MkdirArchive $( dirname $2 )
1256#       echo ${RSYNC} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${RUN_DIR}/$1 ${STOREHOST}:${2} > out_rsync 2>&1
1257#       ${RSYNC} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> out_rsync 2>&1
1258
1259#       #RSYNC WITH NFS USE
1260#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
1261#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
1262
1263#       status=$?
1264#       IGCM_sys_Rsync_out $status
1265
1266#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1267#       (( status=status+$? ))
1268
1269    if [ ${status} -gt 0 ] ; then
1270      IGCM_debug_Print 2 "IGCM_sys_Put_Out : mfput or cp failed error code ${status}"
1271      cat out_rsync
1272      IGCM_debug_Exit "IGCM_sys_Put_Out"
1273    else
1274      \rm out_rsync
1275    fi
1276  else
1277    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1278  fi
1279  IGCM_debug_PopStack "IGCM_sys_Put_Out"
1280  return 0
1281}
1282
1283#D-#==================================================
1284#D-function IGCM_sys_PutBuffer_Out
1285#D-* Purpose: Copy a file on ${WORKDIR} after having chmod it in readonly
1286#D-* Examples:
1287#D-
1288function IGCM_sys_PutBuffer_Out {
1289  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Out" $@
1290  if ( $DEBUG_sys ) ; then
1291    echo "IGCM_sys_PutBuffer_Out :" $@
1292  fi
1293
1294  typeset NB_ESSAI DELAI status i exist skip
1295
1296  # number of tentative
1297  NB_ESSAI=3
1298  # time delay between tentative
1299  DELAI=2
1300
1301  if [ $DRYRUN = 0 ]; then
1302    if [ ! -f ${1} ] ; then
1303      echo "WARNING : IGCM_sys_PutBuffer_Out ${1} DOES NOT EXIST ."
1304      IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1305      return 1
1306    fi
1307    #
1308    IGCM_sys_Mkdir $( dirname $2 )
1309    #
1310
1311    exist=false
1312    skip=false
1313    if [ -f $2 ] ; then
1314      IGCM_debug_Print 1 "$2 already exist"
1315      exist=true
1316      if [ "X$( diff $1 $2 )" = X ] ; then
1317        IGCM_debug_Print 2 "$1 and $2 are the same file, we skip the copy"
1318        status=0
1319        skip=true
1320      else
1321        IGCM_debug_Print 2 "$1 and $2 are not the same file, we force the copy"
1322        skip=false
1323      fi
1324    fi
1325    #
1326    if ( [ X${exist} = Xtrue ] && [ X${skip} = Xfalse ] ) ; then
1327      IGCM_sys_Chmod u+w $2
1328    fi
1329
1330    if [ X${skip} = Xfalse ] ; then
1331      i=0
1332      while [ $i -lt $NB_ESSAI ] ; do
1333        # USUAL WAY
1334        \cp $1 $2 > out_rsync 2>&1
1335        status=$?
1336        if [ ${status} -gt 0 ]; then
1337          IGCM_debug_Print 2 "IGCM_sys_PutBuffer_Out : cp failed error code ${status} ${i}/${NB_ESSAI}"
1338          IGCM_debug_Print 2 "IGCM_sys_PutBuffer_Out : sleep ${DELAI} seconds and try again."
1339          [ -f ${2} ] && ls -l ${2}
1340          [ -f ${2}/${1} ] && ls -l ${2}/${1}
1341          sleep $DELAI
1342        else
1343          break
1344        fi
1345        (( i = i + 1 ))
1346      done
1347    fi
1348
1349    if [ ${status} -gt 0 ] ; then
1350      echo "IGCM_sys_PutBuffer_Out : error."
1351      [ -f ${2} ] && ls -l ${2}
1352      [ -f ${2}/${1} ] && ls -l ${2}/${1}
1353      cat out_rsync
1354      IGCM_debug_Exit "IGCM_sys_PutBuffer_Out"
1355    else
1356
1357      if [ X${JobType} = XRUN ] ; then
1358        if [ X${3} = X ] ; then
1359          [ -f ${2} ] && IGCM_sys_Chmod 444 ${2}
1360          [ -f ${2}/${1} ] && IGCM_sys_Chmod 444 ${2}/${1}
1361        fi
1362      fi
1363
1364      \rm out_rsync
1365    fi
1366  else
1367    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1368  fi
1369  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1370  return 0
1371}
1372
1373#D-#==================================================
1374#D-function IGCM_sys_Get
1375#D-* Purpose: Get a file from ${ARCHIVE}
1376#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
1377#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
1378function IGCM_sys_Get {
1379  IGCM_debug_PushStack "IGCM_sys_Get" $@
1380
1381  typeset DEST status dm_liste
1382
1383  if ( $DEBUG_sys ) ; then
1384    echo "IGCM_sys_Get :" $@
1385  fi
1386  if [ $DRYRUN -le 2 ]; then
1387    if [ X${1} = X'/l' ] ; then
1388      # test if the first file is present in the old computation :
1389      eval set +A dm_liste \${${2}}
1390    else
1391      dm_liste=${1}
1392    fi
1393    eval DEST=\${${#}}
1394
1395    # test if the (first) file is present in the old computation :
1396    DEBUG_sys=false IGCM_sys_IsFileArchived ${dm_liste[0]}
1397    if [ $? = 0 ] ; then
1398      IGCM_sys_TestFileArchive ${dm_liste[0]}
1399      status=$?
1400    else
1401      IGCM_sys_TestFileBuffer ${dm_liste[0]}
1402      status=$?
1403    fi
1404
1405    if [ ${status} -gt 0 ] ; then
1406      echo "IGCM_sys_Get, ERROR : regular file ${dm_liste[0]} DOES NOT EXIST ."
1407      IGCM_debug_Exit "IGCM_sys_Get"
1408      return
1409    fi
1410
1411    #Command depends on targeted file system
1412    DEBUG_sys=false IGCM_sys_IsFileArchived ${dm_liste[0]}
1413    if [ $? = 0 ] ; then
1414      mfget ${dm_liste[*]} ${DEST} > out_rsync 2>&1
1415      status=$?
1416    else
1417      \cp ${dm_liste[*]} ${DEST} > out_rsync 2>&1
1418      status=$?
1419    fi
1420
1421#       #RSYNC WITH NETWORK RSH CALL
1422#       echo ${RSYNC} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} > out_rsync 2>&1
1423#       ${RSYNC} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} >> out_rsync 2>&1
1424
1425#       #RSYNC WITH NFS USE
1426#       echo ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} > out_rsync 2>&1
1427#       ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} >> out_rsync 2>&1
1428
1429#       status=$?
1430#       IGCM_sys_Rsync_out $status
1431
1432#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1433#       (( status=status+$? ))
1434
1435    if [ ${status} -gt 0 ] ; then
1436      IGCM_debug_Print 2 "IGCM_sys_Get : mfget or cp failed error code ${status}"
1437      cat out_rsync
1438      IGCM_debug_Exit "IGCM_sys_Get"
1439    else
1440      \rm out_rsync
1441    fi
1442  else
1443    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1444  fi
1445  IGCM_debug_PopStack "IGCM_sys_Get"
1446}
1447
1448#D-#==================================================
1449#D-function IGCM_sys_GetBuffer
1450#D-* Purpose: Get a file from ${SCRATCHDIR}
1451#D-* Examples: IGCM_sys_GetBuffer myfile /destpath/myfile_with_PREFIX
1452#D-            IGCM_sys_GetBuffer /l Array_contain_myfiles /destpath/
1453function IGCM_sys_GetBuffer {
1454  IGCM_debug_PushStack "IGCM_sys_GetBuffer" $@
1455
1456  typeset DEST buf_liste target file_work
1457  typeset NB_ESSAI DELAI status i
1458
1459  if ( $DEBUG_sys ) ; then
1460    echo "IGCM_sys_GetBuffer :" $@
1461  fi
1462
1463  # number of tentative
1464  NB_ESSAI=3
1465  # time delay between tentative
1466  DELAI=2
1467
1468  if [ $DRYRUN -le 2 ]; then
1469    if [ X${1} = X'/l' ] ; then
1470      # test if the first file is present in the old computation :
1471      eval set +A buf_liste \${${2}}
1472    else
1473      eval set +A buf_liste ${1}
1474    fi
1475    eval DEST=\${${#}}
1476
1477    #USUAL WAY
1478    if [ X${1} = X'/l' ] ; then
1479      for target in ${buf_liste[*]} ; do
1480        local_file=$( basename ${target} )
1481        i=0
1482        while [ $i -lt $NB_ESSAI ] ; do
1483          \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1484          status=$?
1485          if [ ${status} -gt 0 ]; then
1486            IGCM_debug_Print 2 "IGCM_sys_GetBuffer : cp failed error code ${status} ${i}/${NB_ESSAI}"
1487            IGCM_debug_Print 2 "IGCM_sys_GetBuffer : sleep ${DELAI} seconds and try again."
1488            sleep $DELAI
1489          else
1490            break
1491          fi
1492          (( i = i + 1 ))
1493        done
1494        if [ ${status} -gt 0 ] ; then
1495          echo "IGCM_sys_Get : error"
1496          cat out_rsync
1497          \rm out_rsync
1498          IGCM_debug_Exit "IGCM_sys_GetBuffer"
1499        else
1500          \rm out_rsync
1501        fi
1502      done
1503    else
1504      i=0
1505      while [ $i -lt $NB_ESSAI ] ; do
1506        \cp ${buf_liste} ${DEST} >> out_rsync 2>&1
1507        status=$?
1508        if [ ${status} -gt 0 ]; then
1509          IGCM_debug_Print 2 "IGCM_sys_GetBuffer : cp failed error code ${status} ${i}/${NB_ESSAI}"
1510          IGCM_debug_Print 2 "IGCM_sys_GetBuffer : sleep ${DELAI} seconds and try again."
1511          sleep $DELAI
1512        else
1513          break
1514        fi
1515        (( i = i + 1 ))
1516      done
1517      if [ ${status} -gt 0 ] ; then
1518        echo "IGCM_sys_Get : error"
1519        cat out_rsync
1520        \rm out_rsync
1521        IGCM_debug_Exit "IGCM_sys_GetBuffer"
1522      else
1523        \rm out_rsync
1524      fi
1525    fi
1526  else
1527    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1528  fi
1529  IGCM_debug_PopStack "IGCM_sys_GetBuffer"
1530}
1531
1532#D-#==================================================
1533#D-function IGCM_sys_GetDate_FichWork
1534#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
1535#D-* Examples:
1536#D-
1537function IGCM_sys_GetDate_FichWork {
1538  IGCM_debug_PushStack "IGCM_sys_FichWork" $@
1539  if ( $DEBUG_sys ) ; then
1540    echo "IGCM_sys_GetDate_FichWork :" $@
1541  fi
1542  typeset dateF
1543  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1544  eval ${2}=${dateF[5]}
1545
1546  # donne la date filesys d'un fichier sur la machine work
1547  IGCM_debug_PopStack "IGCM_sys_FichWork"
1548}
1549
1550#D-#==================================================
1551#D-function IGCM_sys_GetDate_FichArchive
1552#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
1553#D-* Examples:
1554#D-
1555function IGCM_sys_GetDate_FichArchive {
1556  IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
1557  if ( $DEBUG_sys ) ; then
1558    echo "IGCM_sys_GetDate_FichArchive :" $@
1559  fi
1560  typeset dateF
1561  set +A dateF -- $( rsh ${STOREHOST} -n ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1562  eval ${2}=${dateF[5]}
1563
1564  IGCM_debug_PopStack "IGCM_sys_FichArchive"
1565}
1566
1567#D-#==================================================
1568#D-function IGCM_sys_Put_Dods
1569#D-* Purpose: Put $(ARCHIVE) files on DODS internet protocole.
1570#D-* Examples:
1571#D-
1572function IGCM_sys_Put_Dods {
1573  IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
1574  if ( $DEBUG_sys ) ; then
1575    echo "IGCM_sys_Put_Dods :" $@
1576  fi
1577  if [ $DRYRUN = 0 ]; then
1578    # We take our time on that
1579    sleep 10
1580    IGCM_sys_TestDirArchive ${R_SAVE}/${1}
1581    if [ $? != 0 ] ; then
1582      echo "WARNING : IGCM_sys_Put_Dods ${R_SAVE}/${1} DOES NOT EXIST ."
1583      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1584      return
1585    fi
1586
1587    typeset status
1588    #
1589    rsh gaya exec /bin/ksh <<EOF
1590          cd ${R_SAVE}
1591          /usr/local/bin/dods_rm DODS/pub/${LOGIN}/${R_DODS}/${1} > /dev/null 2>&1
1592          /bin/chmod -R u+w ${R_SAVE}/${1}
1593          /usr/local/bin/dods_cp ${1} DODS/pub/${LOGIN}/${R_DODS} > /dev/null 2>&1
1594          /bin/chmod -R +rX ${R_SAVE}/${1}
1595          /bin/chmod -R u+w ${R_SAVE}/${1}
1596EOF
1597    status=$?
1598
1599    if [ ${status} -gt 0 ] ; then
1600      echo "IGCM_sys_Put_Dods : error."
1601      IGCM_debug_Exit "IGCM_sys_Put_Dods"
1602    fi
1603  else
1604    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1605  fi
1606  IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1607}
1608
1609##############################################################
1610# REBUILD OPERATOR
1611
1612#D-#==================================================
1613#D-function IGCM_sys_rebuild
1614#D-* Purpose: rebuild parallel files
1615#D-* Examples:
1616#D-
1617function IGCM_sys_rebuild {
1618  IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1619  if ( $DEBUG_sys ) ; then
1620    echo "IGCM_sys_rebuild :" $@
1621  fi
1622
1623  typeset NB_ESSAI DELAI status i firstArg
1624  # number of tentative
1625  NB_ESSAI=3
1626  # time delay between tentative
1627  DELAI=2
1628
1629  i=0
1630  while [ $i -lt $NB_ESSAI ] ; do
1631    /smphome/rech/psl/rpsl035/bin/rebuild -f -o $@ > out_rsync 2>&1
1632    status=$?
1633    if [ ${status} -gt 0 ] ; then
1634      IGCM_debug_Print 2 "IGCM_sys_rebuild : error code ${status}"
1635      cat out_rsync
1636      \rm out_rsync
1637      IGCM_debug_Print 2 "IGCM_sys_rebuild : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1638      firstArg=${1}
1639      \rm ${firstArg}
1640      sleep $DELAI
1641    else
1642      \rm out_rsync
1643      break
1644    fi
1645    (( i = i + 1 ))
1646  done
1647
1648  if [ ${status} -gt 0 ] ; then
1649    echo "IGCM_sys_rebuild : rebuild error code is ${status}"
1650    IGCM_debug_Exit "rebuild"
1651  fi
1652
1653  IGCM_debug_PopStack "IGCM_sys_rebuild"
1654}
1655
1656#D-#==================================================
1657#D-function IGCM_sys_rebuild_station
1658#D-* Purpose: rebuild parallel files describing station
1659#D-* Examples:
1660#D-
1661function IGCM_sys_rebuild_station {
1662  IGCM_debug_PushStack "IGCM_sys_rebuild_station" -- $@
1663  typeset i list_opt file_in file_out prefix_invert list_invert
1664  if ( $DEBUG_sys ) ; then
1665    echo "IGCM_sys_rebuild_station :" $@
1666  fi
1667  list_opt=$@
1668
1669  # Invert Axis : t,x -> x,t
1670  #               t,pres,x -> x,t,pres
1671  # So that we can concatenate along x
1672  i=0
1673  for file_in in ${list_opt} ; do
1674    (( i = i + 1))
1675    [ ${i} = 1 ] && file_out=${file_in} && continue
1676    prefix_invert=$( basename ${file_in} .nc )
1677    IGCM_sys_ncpdq -a x,time_counter -a x,time_counter,presnivs ${file_in} ${prefix_invert}_xt.nc
1678    list_invert[${#list_invert[*]}]=${prefix_invert}_xt.nc
1679  done
1680
1681  # Concatenate
1682  IGCM_sys_ncrcat ${list_invert[*]} histstn_xt.nc
1683
1684  # Re-ivert file
1685  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x histstn_xt.nc ${file_out}
1686
1687  # Station re-ordering is too expansive to be run within libICGM
1688  # This is due to (ncpdq - nrcat - ncpdq) I/O sequence.
1689  # This re-ordering must be done "in memory" by the cmorization process
1690  # Anyway this is the best sequence using (ncpdq - nrcat - ncpdq)
1691  # BEGIN reordering
1692
1693  # Only LMDZ text output contains the exact ordering of the station.
1694  # We isolate this in the code below:
1695  #  0  38  -157.5000000000000  70.98591549295774
1696  #  0  54  27.49999999999999   67.18309859154928
1697  #  0  56  -62.50000000000001  82.39436619718309
1698  #  0  79  12.49999999999999   78.59154929577466
1699  #  0  116 -165.0000000000000  76.05633802816901
1700  #  0  117 130.0000000000000   70.98591549295774
1701  #  0  118 110.0000000000000   87.46478873239437
1702  #  1  40  4.999999999999995   51.97183098591550
1703#  typeset iStation iProc list_opt file_in file_out prefix_invert
1704#  typeset -Z4 j4
1705#  typeset -Z3 j3
1706
1707#  unset list_opt
1708#  set +A list_opt $@
1709
1710  # Filename after rebuild
1711#  file_out=${list_opt[0]}
1712  # Prefix of output files
1713#  prefix_invert=$( basename ${file_out} .nc )
1714  # Number of procs
1715#  num_proc=$( grep -i mpi_size ${PREFIX}_${Exe_Output} | wc -l )
1716
1717#  iProc=0
1718#  while [ ${iProc} -lt ${num_proc} ] ; do
1719    # Array containing Station as a number
1720#    unset proc_stn
1721#    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}' )
1722    # Number of stations produced by processor proc
1723#    stationLast=${#proc_stn[*]}
1724    # Proc number on 4 digits
1725#    j4=${iProc}
1726    # Init
1727#    iStation=0
1728#    while [ ${iStation} -lt ${stationLast} ] ; do
1729      # Station number on 3 digits
1730#      j3=${proc_stn[${iStation}]}
1731      # Extract station
1732      # Invert Axis : t,x -> x,t
1733      #               t,pres,x -> x,t,pres
1734      # So that we can concatenate along x
1735#      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
1736#      (( iStation = iStation + 1 ))
1737#    done
1738#    (( iProc = iProc + 1 ))
1739#  done
1740
1741  # Concatenate all station along x
1742#  IGCM_sys_ncrcat ${prefix_invert}_stn_???.nc ${prefix_invert}_xt.nc
1743
1744  # Re-invert file
1745#  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x ${prefix_invert}_xt.nc ${file_out}
1746
1747  # END reordering
1748
1749  IGCM_debug_PopStack "IGCM_sys_rebuild_station"
1750}
1751
1752############################################################
1753# Activate Running Environnment Variables
1754
1755#D-#==================================================
1756#D-function IGCM_sys_desactiv_variables
1757#D-* Purpose: set environement variables prior to execution
1758#D-* Examples:
1759#D-
1760function IGCM_sys_activ_variables {
1761  IGCM_debug_PushStack "IGCM_sys_activ_variables"
1762  if ( $DEBUG_sys ) ; then
1763    echo "IGCM_sys_activ_variables"
1764  fi
1765
1766# --------------------------------------------------------------------
1767#D- MPI specifications
1768# --------------------------------------------------------------------
1769
1770# --------------------------------------------------------------------
1771#D- Other specifications
1772# --------------------------------------------------------------------
1773
1774  ulimit -s unlimited
1775
1776## to be done only one time
1777## export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/smplocal/pub/NetCDF/4.1.3/lib:/smplocal/pub/HDF5/1.8.9/seq/lib
1778  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
1779  echo LD_LIBRARY_PATH = ${LD_LIBRARY_PATH}
1780
1781  IGCM_debug_PopStack "IGCM_sys_activ_variables"
1782}
1783
1784############################################################
1785# Desactivate Running Environnment Variables
1786
1787#D-#==================================================
1788#D-function IGCM_sys_desactiv_variables
1789#D-* Purpose: unset environement variables after execution
1790#D-* Examples:
1791#D-
1792function IGCM_sys_desactiv_variables {
1793  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1794  if ( $DEBUG_sys ) ; then
1795    echo "IGCM_sys_desactiv_variables"
1796  fi
1797# --------------------------------------------------------------------
1798#D- MPI specifications
1799# --------------------------------------------------------------------
1800
1801# --------------------------------------------------------------------
1802#D- Other specifications
1803# --------------------------------------------------------------------
1804
1805  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1806}
1807
1808############################################################
1809# Build MPI/OMP scripts run file (dummy function)
1810
1811#D-#==================================================
1812#D-function IGCM_sys_build_run_file
1813#D-* Purpose: build run file (deprecated)
1814#D-* Examples:
1815#D-
1816function IGCM_sys_build_run_file {
1817
1818  IGCM_debug_Print 3 " dummy function : IGCM_sys_build_run_file "
1819
1820}
1821
1822############################################################
1823# Build MPI/OMP scripts
1824
1825#D-#==================================================
1826#D-function IGCM_sys_build_execution_scripts
1827#D-* Purpose: build execution scripts to be launch by ${HOST_MPIRUN_COMMAND}
1828#D-* Examples:
1829#D-
1830function IGCM_sys_build_execution_scripts
1831{
1832  IGCM_debug_PushStack "IGCM_sys_build_execution_scripts" $@
1833  if ( $DEBUG_sys ) ; then
1834    echo "IGCM_sys_build_execution_scripts " $@
1835  fi
1836
1837  EXECUTION=${HOST_MPIRUN_COMMAND}
1838
1839  if ( ${OK_PARA_MPMD} ) ; then
1840
1841    if [ -f run_file ] ; then
1842      IGCM_sys_Rm -f run_file
1843    fi
1844    touch run_file
1845
1846# run_file construction
1847
1848# Then first loop on the components for the coupler ie oasis
1849
1850### the coupler ie oasis must be the first one
1851    for comp in ${config_ListOfComponents[*]} ; do
1852
1853      eval ExeNameIn=\${config_Executable_${comp}[0]}
1854      eval ExeNameOut=\${config_Executable_${comp}[1]}
1855
1856      # for CPL component only
1857      if [ "X${comp}" = "XCPL" ] ; then
1858
1859        eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1860        eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1861
1862        if ( ${OK_PARA_MPI} ) ; then
1863          (( mpi_count = 1 ))
1864          until [ ${mpi_count} -gt ${comp_proc_mpi_loc} ] ; do
1865            echo "./${ExeNameOut}" >> run_file
1866            (( mpi_count = mpi_count + 1 ))
1867          done
1868        else
1869          echo "./${ExeNameOut} " >> run_file
1870        fi
1871      fi
1872    done
1873
1874# Then second loop on the components
1875
1876    for comp in ${config_ListOfComponents[*]} ; do
1877
1878      eval ExeNameIn=\${config_Executable_${comp}[0]}
1879      eval ExeNameOut=\${config_Executable_${comp}[1]}
1880
1881      # Only if we really have an executable for the component and not the coupler ie oasis:
1882      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${comp}" != "XCPL" ] ) ; then
1883
1884        eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1885        eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1886
1887        if ( ${OK_PARA_MPI} ) ; then
1888          (( mpi_count = 1 ))
1889          until [ ${mpi_count} -gt ${comp_proc_mpi_loc} ] ; do
1890            echo "./${ExeNameOut}" >> run_file
1891            (( mpi_count = mpi_count + 1 ))
1892          done
1893        else
1894            echo "./${ExeNameOut} " >> run_file
1895        fi
1896      fi
1897    done
1898
1899    EXECUTION="${HOST_MPIRUN_COMMAND} -pgmmodel mpmd -cmdfile ./run_file"
1900
1901    IGCM_sys_Chmod u+x run_file
1902    if ( $DEBUG_sys ) ; then
1903      echo "run_file contains : "
1904      cat run_file
1905    fi
1906
1907  else # Only one executable. launch it.
1908
1909    for comp in ${config_ListOfComponents[*]} ; do
1910
1911      # Only if we really have an executable for the component :
1912      eval ExeNameOut=\${config_Executable_${comp}[1]}
1913      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${ExeNameOut}" != "Xinca.dat" ] ) ; then
1914        EXECUTION="${HOST_MPIRUN_COMMAND} ./${ExeNameOut}"
1915      fi
1916
1917    done
1918
1919  fi
1920
1921  IGCM_debug_Print 1 "sys ada : execution command is "
1922  IGCM_debug_Print 1 "$EXECUTION"
1923
1924  IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
1925}
1926
1927############################################################
1928# Check of space available on temporary filesytems.
1929
1930#D-#==================================================
1931#D-function IGCM_sys_check_quota
1932#D-* Purpose: check user quota. Stop the simulation if quota above 90%
1933#D-* Examples:
1934#D-
1935function IGCM_sys_check_quota {
1936  IGCM_debug_PushStack "IGCM_sys_check_quota"
1937  if ( $DEBUG_sys ) ; then
1938    echo "IGCM_sys_check_quota"
1939  fi
1940  # Limit of quota (in %)
1941  limit_quota=90
1942
1943  # Check of the volume
1944  volume_quota=$(quota_u -w | grep 'Quota soft' | awk '{print $5}')
1945  if [ ! X${volume_quota} = X ] ; then
1946    quota_volume=${volume_quota%%\%}
1947#    echo $quota_volume
1948    if [ ${quota_volume} -ge ${limit_quota} ] ; then
1949      IGCM_debug_Print 1 "Please, check your quota of volume on workgpfs"
1950      IGCM_debug_Print 1 "${quota_volume}% of your quota is used"
1951      IGCM_debug_Print 1 "Use the quota_u -w command to check"
1952      IGCM_debug_Print 1 "You must have more than 10% available to run"
1953      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
1954      IGCM_debug_Verif_Exit
1955    fi
1956
1957  fi
1958  IGCM_debug_PopStack "IGCM_sys_check_quota"
1959}
1960
1961#D-#==================================================
1962#D-function IGCM_sys_CountJobInQueue
1963#D-* Purpose: Check if job_name is currently
1964#D-  running or in queue
1965#D-* Examples: IGCM_sys_CountJobInQueue ${JobName} NbRun
1966#D-
1967function IGCM_sys_CountJobInQueue {
1968  IGCM_debug_PushStack "IGCM_sys_CountJobInQueue"
1969  if ( $DEBUG_sys ) ; then
1970    echo "IGCM_sys_CountJobInQueue"
1971  fi
1972
1973  # Print only the full (-W) JobName (%jn)
1974  NbRun=$( llq -W -f %jn | grep -c "$1" )
1975
1976  eval ${2}=${NbRun}
1977
1978  IGCM_debug_PopStack "IGCM_sys_CountJobInQueue"
1979}
1980
1981##############################################################
1982# NCO OPERATOR
1983
1984#D-#==================================================
1985#D-function IGCM_sys_ncap2
1986#D-* Purpose: encapsulate ncap2 call so as to manage error code and retry
1987#D-* Examples:
1988#D-
1989function IGCM_sys_ncap2 {
1990  IGCM_debug_PushStack "IGCM_sys_ncap2" -- $@
1991  if ( $DEBUG_sys ) ; then
1992    echo "IGCM_sys_ncap2 :" $@
1993  fi
1994
1995  typeset NB_ESSAI DELAI status i
1996  # number of tentative
1997  NB_ESSAI=3
1998  # time delay between tentative
1999  DELAI=2
2000
2001  i=0
2002  while [ $i -lt $NB_ESSAI ] ; do
2003    ncap2 "$@" > out_rsync 2>&1
2004    status=$?
2005    if [ ${status} -gt 0 ] ; then
2006      IGCM_debug_Print 2 "IGCM_sys_ncap2 : error code ${status}"
2007      cat out_rsync
2008      \rm out_rsync
2009      IGCM_debug_Print 2 "IGCM_sys_ncap2 : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2010      sleep $DELAI
2011    else
2012      \rm out_rsync
2013      break
2014    fi
2015    (( i = i + 1 ))
2016  done
2017
2018  if [ ${status} -gt 0 ] ; then
2019    echo "IGCM_sys_ncap2 : ncap2 error"
2020    IGCM_debug_Exit "ncap2"
2021  fi
2022
2023  IGCM_debug_PopStack "IGCM_sys_ncap2"
2024}
2025
2026#D-#==================================================
2027#D-function IGCM_sys_ncatted
2028#D-* Purpose: encapsulate ncatted call so as to manage error code and retry
2029#D-* Examples:
2030#D-
2031function IGCM_sys_ncatted {
2032  IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
2033  if ( $DEBUG_sys ) ; then
2034    echo "IGCM_sys_ncatted :" $@
2035  fi
2036
2037  typeset NB_ESSAI DELAI status i
2038  # number of tentative
2039  NB_ESSAI=3
2040  # time delay between tentative
2041  DELAI=2
2042
2043  i=0
2044  while [ $i -lt $NB_ESSAI ] ; do
2045    ncatted "$@" > out_rsync 2>&1
2046    status=$?
2047    if [ ${status} -gt 0 ] ; then
2048      IGCM_debug_Print 2 "IGCM_sys_ncatted : error code ${status}"
2049      cat out_rsync
2050      \rm out_rsync
2051      IGCM_debug_Print 2 "IGCM_sys_ncatted : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2052      sleep $DELAI
2053    else
2054      \rm out_rsync
2055      break
2056    fi
2057    (( i = i + 1 ))
2058  done
2059
2060  if [ ${status} -gt 0 ] ; then
2061    echo "IGCM_sys_ncatted : ncatted error"
2062    IGCM_debug_Exit "ncatted"
2063  fi
2064
2065  IGCM_debug_PopStack "IGCM_sys_ncatted"
2066}
2067
2068#D-#==================================================
2069#D-function IGCM_sys_ncbo
2070#D-* Purpose: encapsulate ncbo call so as to manage error code and retry
2071#D-* Examples:
2072#D-
2073function IGCM_sys_ncbo {
2074  IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
2075  if ( $DEBUG_sys ) ; then
2076    echo "IGCM_sys_ncbo :" $@
2077  fi
2078
2079  typeset NB_ESSAI DELAI status i
2080  # number of tentative
2081  NB_ESSAI=3
2082  # time delay between tentative
2083  DELAI=2
2084
2085  i=0
2086  while [ $i -lt $NB_ESSAI ] ; do
2087    ncbo $@ > out_rsync 2>&1
2088    status=$?
2089    if [ ${status} -gt 0 ] ; then
2090      IGCM_debug_Print 2 "IGCM_sys_ncbo : error code ${status}"
2091      cat out_rsync
2092      \rm out_rsync
2093      IGCM_debug_Print 2 "IGCM_sys_ncbo : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2094      sleep $DELAI
2095    else
2096      \rm out_rsync
2097      break
2098    fi
2099    (( i = i + 1 ))
2100  done
2101
2102  if [ ${status} -gt 0 ] ; then
2103    echo "IGCM_sys_ncbo : ncbo error"
2104    IGCM_debug_Exit "ncbo"
2105  fi
2106
2107  IGCM_debug_PopStack "IGCM_sys_ncbo"
2108}
2109
2110#D-#==================================================
2111#D-function IGCM_sys_ncdif
2112#D-* Purpose: encapsulate ncdiff call so as to manage error code and retry
2113#D-* Examples:
2114#D-
2115function IGCM_sys_ncdiff {
2116  IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
2117  if ( $DEBUG_sys ) ; then
2118    echo "IGCM_sys_ncdiff :" $@
2119  fi
2120
2121  typeset NB_ESSAI DELAI status i
2122  # number of tentative
2123  NB_ESSAI=3
2124  # time delay between tentative
2125  DELAI=2
2126
2127  i=0
2128  while [ $i -lt $NB_ESSAI ] ; do
2129    ncdiff $@ > out_rsync 2>&1
2130    status=$?
2131    if [ ${status} -gt 0 ] ; then
2132      IGCM_debug_Print 2 "IGCM_sys_ncdiff : error code ${status}"
2133      cat out_rsync
2134      \rm out_rsync
2135      IGCM_debug_Print 2 "IGCM_sys_ncdiff : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2136      sleep $DELAI
2137    else
2138      \rm out_rsync
2139      break
2140    fi
2141    (( i = i + 1 ))
2142  done
2143
2144  if [ ${status} -gt 0 ] ; then
2145    echo "IGCM_sys_ncdiff : ncdiff error"
2146    IGCM_debug_Exit "ncdiff"
2147  fi
2148
2149  IGCM_debug_PopStack "IGCM_sys_ncdiff"
2150}
2151
2152#D-#==================================================
2153#D-function IGCM_sys_ncea
2154#D-* Purpose: encapsulate ncea call so as to manage error code and retry
2155#D-* Examples:
2156#D-
2157function IGCM_sys_ncea {
2158  IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
2159  if ( $DEBUG_sys ) ; then
2160    echo "IGCM_sys_ncea :" $@
2161  fi
2162
2163  typeset NB_ESSAI DELAI status i
2164  # number of tentative
2165  NB_ESSAI=3
2166  # time delay between tentative
2167  DELAI=2
2168
2169  i=0
2170  while [ $i -lt $NB_ESSAI ] ; do
2171    ncea $@ > out_rsync 2>&1
2172    status=$?
2173    if [ ${status} -gt 0 ] ; then
2174      IGCM_debug_Print 2 "IGCM_sys_ncea : error code ${status}"
2175      cat out_rsync
2176      \rm out_rsync
2177      IGCM_debug_Print 2 "IGCM_sys_ncea : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2178      sleep $DELAI
2179    else
2180      \rm out_rsync
2181      break
2182    fi
2183    (( i = i + 1 ))
2184  done
2185
2186  if [ ${status} -gt 0 ] ; then
2187    echo "IGCM_sys_ncea : ncea error"
2188    IGCM_debug_Exit "ncea"
2189  fi
2190
2191  IGCM_debug_PopStack "IGCM_sys_ncea"
2192}
2193
2194#D-#==================================================
2195#D-function IGCM_sys_ncecat
2196#D-* Purpose: encapsulate ncecat call so as to manage error code and retry
2197#D-* Examples:
2198#D-
2199function IGCM_sys_ncecat {
2200  IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
2201  if ( $DEBUG_sys ) ; then
2202    echo "IGCM_sys_ncecat :" $@
2203  fi
2204
2205  typeset NB_ESSAI DELAI status i
2206  # number of tentative
2207  NB_ESSAI=3
2208  # time delay between tentative
2209  DELAI=2
2210
2211  i=0
2212  while [ $i -lt $NB_ESSAI ] ; do
2213    ncecat $@ > out_rsync 2>&1
2214    status=$?
2215    if [ ${status} -gt 0 ] ; then
2216      IGCM_debug_Print 2 "IGCM_sys_ncecat : error code ${status}"
2217      cat out_rsync
2218      \rm out_rsync
2219      IGCM_debug_Print 2 "IGCM_sys_ncecat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2220      sleep $DELAI
2221    else
2222      \rm out_rsync
2223      break
2224    fi
2225    (( i = i + 1 ))
2226  done
2227
2228  if [ ${status} -gt 0 ] ; then
2229    echo "IGCM_sys_ncecat : ncecat error"
2230    IGCM_debug_Exit "ncecat"
2231  fi
2232
2233  IGCM_debug_PopStack "IGCM_sys_ncecat"
2234}
2235
2236#D-#==================================================
2237#D-function IGCM_sys_ncflint
2238#D-* Purpose: encapsulate ncflint call so as to manage error code and retry
2239#D-* Examples:
2240#D-
2241function IGCM_sys_ncflint {
2242  IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
2243  if ( $DEBUG_sys ) ; then
2244    echo "IGCM_sys_ncflint :" $@
2245  fi
2246
2247  typeset NB_ESSAI DELAI status i
2248  # number of tentative
2249  NB_ESSAI=3
2250  # time delay between tentative
2251  DELAI=2
2252
2253  i=0
2254  while [ $i -lt $NB_ESSAI ] ; do
2255    ncflint $@ > out_rsync 2>&1
2256    status=$?
2257    if [ ${status} -gt 0 ] ; then
2258      IGCM_debug_Print 2 "IGCM_sys_ncflint : error code ${status}"
2259      cat out_rsync
2260      \rm out_rsync
2261      IGCM_debug_Print 2 "IGCM_sys_ncflint : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2262      sleep $DELAI
2263    else
2264      \rm out_rsync
2265      break
2266    fi
2267    (( i = i + 1 ))
2268  done
2269
2270  if [ ${status} -gt 0 ] ; then
2271    echo "IGCM_sys_ncflint : ncflint error"
2272    IGCM_debug_Exit "ncflint"
2273  fi
2274
2275  IGCM_debug_PopStack "IGCM_sys_ncflint"
2276}
2277
2278#D-#==================================================
2279#D-function IGCM_sys_ncks
2280#D-* Purpose: encapsulate ncks call so as to manage error code and retry
2281#D-* Examples:
2282#D-
2283function IGCM_sys_ncks {
2284  IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
2285  if ( $DEBUG_sys ) ; then
2286    echo "IGCM_sys_ncks :" $@
2287  fi
2288
2289  typeset NB_ESSAI DELAI status i
2290  # number of tentative
2291  NB_ESSAI=3
2292  # time delay between tentative
2293  DELAI=2
2294
2295  i=0
2296  while [ $i -lt $NB_ESSAI ] ; do
2297    ncks $@ > out_rsync 2>&1
2298    status=$?
2299    if [ ${status} -gt 0 ] ; then
2300      IGCM_debug_Print 2 "IGCM_sys_ncks : error code ${status}"
2301      cat out_rsync
2302      \rm out_rsync
2303      IGCM_debug_Print 2 "IGCM_sys_ncks : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2304      sleep $DELAI
2305    else
2306      \rm out_rsync
2307      break
2308    fi
2309    (( i = i + 1 ))
2310  done
2311
2312  if [ ${status} -gt 0 ] ; then
2313    echo "IGCM_sys_ncks : ncks error"
2314    IGCM_debug_Exit "ncks"
2315  fi
2316
2317  IGCM_debug_PopStack "IGCM_sys_ncks"
2318}
2319
2320#D-#==================================================
2321#D-function IGCM_sys_ncpdq
2322#D-* Purpose: encapsulate ncpdq call so as to manage error code and retry
2323#D-* Examples:
2324#D-
2325function IGCM_sys_ncpdq {
2326  IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
2327  if ( $DEBUG_sys ) ; then
2328    echo "IGCM_sys_ncpdq :" $@
2329  fi
2330
2331  typeset NB_ESSAI DELAI status i
2332  # number of tentative
2333  NB_ESSAI=3
2334  # time delay between tentative
2335  DELAI=2
2336
2337  i=0
2338  while [ $i -lt $NB_ESSAI ] ; do
2339    ncpdq $@ > out_rsync 2>&1
2340    status=$?
2341    if [ ${status} -gt 0 ] ; then
2342      IGCM_debug_Print 2 "IGCM_sys_ncpdq : error code ${status}"
2343      cat out_rsync
2344      \rm out_rsync
2345      IGCM_debug_Print 2 "IGCM_sys_ncpdq : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2346      sleep $DELAI
2347    else
2348      \rm out_rsync
2349      break
2350    fi
2351    (( i = i + 1 ))
2352  done
2353
2354  if [ ${status} -gt 0 ] ; then
2355    echo "IGCM_sys_ncpdq : ncpdq error"
2356    IGCM_debug_Exit "ncpdq"
2357  fi
2358
2359  IGCM_debug_PopStack "IGCM_sys_ncpdq"
2360}
2361
2362#D-#==================================================
2363#D-function IGCM_sys_ncra
2364#D-* Purpose: encapsulate ncra call so as to manage error code and retry
2365#D-* Examples:
2366#D-
2367function IGCM_sys_ncra {
2368  IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
2369  if ( $DEBUG_sys ) ; then
2370    echo "IGCM_sys_ncra :" $@
2371  fi
2372
2373  typeset NB_ESSAI DELAI status i
2374  # number of tentative
2375  NB_ESSAI=3
2376  # time delay between tentative
2377  DELAI=2
2378
2379  i=0
2380  while [ $i -lt $NB_ESSAI ] ; do
2381    ncra $@ > out_rsync 2>&1
2382    status=$?
2383    if [ ${status} -gt 0 ] ; then
2384      IGCM_debug_Print 2 "IGCM_sys_ncra : error code ${status}"
2385      cat out_rsync
2386      \rm out_rsync
2387      IGCM_debug_Print 2 "IGCM_sys_ncra : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2388      sleep $DELAI
2389    else
2390      \rm out_rsync
2391      break
2392    fi
2393    (( i = i + 1 ))
2394  done
2395
2396  if [ ${status} -gt 0 ] ; then
2397    echo "IGCM_sys_ncra : ncra error"
2398    IGCM_debug_Exit "ncra"
2399  fi
2400
2401  IGCM_debug_PopStack "IGCM_sys_ncra"
2402}
2403
2404#D-#==================================================
2405#D-function IGCM_sys_ncrcat
2406#D-* Purpose: encapsulate ncrcat call so as to manage error code and retry
2407#D-* Examples:
2408#D-
2409function IGCM_sys_ncrcat {
2410  IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
2411  if ( $DEBUG_sys ) ; then
2412    echo "IGCM_sys_ncrcat :" $@
2413  fi
2414
2415  typeset NB_ESSAI DELAI status i lastArg
2416  # number of tentative
2417  NB_ESSAI=3
2418  # time delay between tentative
2419  DELAI=2
2420
2421  i=0
2422  while [ $i -lt $NB_ESSAI ] ; do
2423    ncrcat $@ > out_rsync 2>&1
2424    status=$?
2425    if [ ${status} -gt 0 ] ; then
2426      IGCM_debug_Print 2 "IGCM_sys_ncrcat : error code ${status}"
2427      cat out_rsync
2428      \rm out_rsync
2429      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2430      sleep $DELAI
2431    elif [ ! "X$( grep "WARNING Intra-file non-monotonicity" out_rsync )" = "X" ] ; then
2432      IGCM_debug_Print 2 "IGCM_sys_ncrcat : WARNING Intra-file non-monotonicity"
2433      cat out_rsync
2434      # remove files having corrupted time axis
2435      eval lastArg=\${$#}
2436      IGCM_debug_Print 2 "IGCM_sys_ncrcat : Delete ${lastArg}"
2437      \rm ${lastArg}
2438      \rm out_rsync
2439      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2440      sleep $DELAI
2441    else
2442      \rm out_rsync
2443      break
2444    fi
2445    (( i = i + 1 ))
2446  done
2447
2448  if [ ${status} -gt 0 ] ; then
2449    echo "IGCM_sys_ncrcat : ncrcat error"
2450    #IGCM_debug_Exit "ncrcat"
2451  fi
2452
2453  IGCM_debug_PopStack "IGCM_sys_ncrcat"
2454}
2455
2456#D-#==================================================
2457#D-function IGCM_sys_ncrename
2458#D-* Purpose: encapsulate ncrename call so as to manage error code and retry
2459#D-* Examples:
2460#D-
2461function IGCM_sys_ncrename {
2462  IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
2463  if ( $DEBUG_sys ) ; then
2464    echo "IGCM_sys_ncrename :" $@
2465  fi
2466
2467  typeset NB_ESSAI DELAI status i
2468  # number of tentative
2469  NB_ESSAI=3
2470  # time delay between tentative
2471  DELAI=2
2472
2473  i=0
2474  while [ $i -lt $NB_ESSAI ] ; do
2475    ncrename $@ > out_rsync 2>&1
2476    status=$?
2477    if [ ${status} -gt 0 ] ; then
2478      IGCM_debug_Print 2 "IGCM_sys_ncrename : error code ${status}"
2479      cat out_rsync
2480      \rm out_rsync
2481      IGCM_debug_Print 2 "IGCM_sys_ncrename : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2482      sleep $DELAI
2483    else
2484      \rm out_rsync
2485      break
2486    fi
2487    (( i = i + 1 ))
2488  done
2489
2490  if [ ${status} -gt 0 ] ; then
2491    echo "IGCM_sys_ncrename : ncrename error"
2492    IGCM_debug_Exit "ncrename"
2493  fi
2494
2495  IGCM_debug_PopStack "IGCM_sys_ncrename"
2496}
2497
2498#D-#==================================================
2499#D-function IGCM_sys_ncwa
2500#D-* Purpose: encapsulate ncwa call so as to manage error code and retry
2501#D-* Examples:
2502#D-
2503function IGCM_sys_ncwa {
2504  IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
2505  if ( $DEBUG_sys ) ; then
2506    echo "IGCM_sys_ncwa :" $@
2507  fi
2508
2509  typeset NB_ESSAI DELAI status i
2510  # number of tentative
2511  NB_ESSAI=3
2512  # time delay between tentative
2513  DELAI=2
2514
2515  i=0
2516  while [ $i -lt $NB_ESSAI ] ; do
2517    ncwa $@ > out_rsync 2>&1
2518    status=$?
2519    if [ ${status} -gt 0 ] ; then
2520      IGCM_debug_Print 2 "IGCM_sys_ncwa : error code ${status}"
2521      cat out_rsync
2522      \rm out_rsync
2523      IGCM_debug_Print 2 "IGCM_sys_ncwa : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2524      sleep $DELAI
2525    else
2526      \rm out_rsync
2527      break
2528    fi
2529    (( i = i + 1 ))
2530  done
2531
2532  if [ ${status} -gt 0 ] ; then
2533    echo "IGCM_sys_ncwa : ncwa error"
2534    IGCM_debug_Exit "ncwa"
2535  fi
2536
2537  IGCM_debug_PopStack "IGCM_sys_ncwa"
2538}
2539
2540##############################################################
2541# CDO OPERATOR
2542
2543#D-#==================================================
2544#D-function IGCM_sys_cdo
2545#D-* Purpose: encapsulate cdo call so as to manage error code and retry
2546#D-* Examples:
2547#D-
2548function IGCM_sys_cdo {
2549  IGCM_debug_PushStack "IGCM_sys_cdo" -- $@
2550  if ( $DEBUG_sys ) ; then
2551    echo "IGCM_sys_cdo :" $@
2552  fi
2553
2554  typeset status
2555
2556  \cdo $@ > out_rsync 2>&1
2557  status=$?
2558  if [ ${status} -gt 0 ] ; then
2559    echo "IGCM_sys_cdo : error code ${status}"
2560    cat out_rsync
2561    \rm out_rsync
2562    IGCM_debug_PopStack "IGCM_sys_cdo"
2563    return 1
2564  else
2565    IGCM_debug_PopStack "IGCM_sys_cdo"
2566    return 0
2567  fi
2568
2569  IGCM_debug_PopStack "IGCM_sys_cdo"
2570}
Note: See TracBrowser for help on using the repository browser.