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

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

we want it quiet : atlas_env_ada_bash
it will disturb debug mode otherwise

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