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

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

RunChecker? : add JobID to output (#169).

  • Property svn:keywords set to Revision Author Date
File size: 75.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 > /tmp/out_command.$$ 2>&1 ; status=$? ; cd - ;
655
656  cat /tmp/out_command.$$
657  if [ ${status} -gt 0 ] ; then
658    IGCM_debug_Print 2 "IGCM_sys_Qsub $1 : error code ${status}"
659    IGCM_debug_Exit "IGCM_sys_Qsub"
660  else
661    JobID=$( gawk {'print $4'} /tmp/out_command.$$ | tail -1 | sed -e s/\"//g )
662    IGCM_sys_Rm ${REP_FOR_JOB}/JOB_FOR_IGCM
663  fi
664  IGCM_debug_PopStack "IGCM_sys_Qsub"
665}
666
667#D-#==================================================
668#D-function IGCM_sys_QsubPost
669#D-* Purpose: Qsub new job on scalaire
670#D-* Examples:
671#D-
672function IGCM_sys_QsubPost {
673  IGCM_debug_PushStack "IGCM_sys_QsubPost" $@
674
675  typeset status
676
677  if ( $DEBUG_sys ) ; then
678    echo "IGCM_sys_QsubPost :" $@
679  fi
680  # We have to change output/error file
681  [ ${#@} = 1 ] &&  REP_FOR_JOB=${POST_DIR}
682  [ ${#@} = 2 ] &&  REP_FOR_JOB=${2}
683
684  sed -e "s:\# \@ output *= .*:\# \@ output = ${Script_Post_Output}.out:" \
685      -e "s:\# \@ error *= .*:\# \@ error = ${Script_Post_Output}.out:"   \
686      ${libIGCM_POST}/$1.job > ${REP_FOR_JOB}/JOB_FOR_IGCM_$$
687
688  cd $REP_FOR_JOB ; /usr/bin/llsubmit JOB_FOR_IGCM_$$ > /tmp/out_command.$$ 2>&1 ; status=$? ; cd - ;
689
690  cat /tmp/out_command.$$
691  if [ ${status} -gt 0 ] ; then
692    IGCM_debug_Print 2 "IGCM_sys_QsubPost $1 : error code ${status}"
693    IGCM_debug_Exit "IGCM_sys_QsubPost"
694  else
695    JobID=$( gawk {'print $4'} /tmp/out_command.$$ | tail -1 | sed -e s/\"//g )
696    IGCM_sys_Rm ${REP_FOR_JOB}/JOB_FOR_IGCM_$$
697  fi
698  IGCM_debug_PopStack "IGCM_sys_QsubPost"
699}
700
701#D-*************************
702#D- File transfer functions
703#D-*************************
704#D-
705
706#D-#==================================================
707#D-function IGCM_sys_Rsync_out
708#D-* Purpose: treat return val of rsync
709#D-* Examples: IGCM_sys_Rsync_out out_RET_rsync
710#D-  Error values and explanations can depend on your system version.
711function IGCM_sys_Rsync_out {
712  status=$1
713  if [ ! $status ] ; then
714    echo "rsync error !"
715  fi
716
717  if [ $MYLANG = "fr" ]; then
718    case $status in
719    0)  return ;;
720    1)  echo "Erreur de rsync ; RERR_SYNTAX : "
721      echo "Erreur de syntaxe ou d'utilisation."
722      return;;
723    2)  echo "Erreur de rsync ; RERR_PROTOCOL : "
724      echo "Incompatibilité de protocole."
725      return;;
726    3)  echo "Erreur de rsync ; RERR_FILESELECT 3"
727      echo "Erreurs  lors  de  la  sélection des fichiers d'entrée sortie et"
728      echo "répertoires"
729      return;;
730    4)  echo "Erreur de rsync ; RERR_UNSUPPORTED"
731      echo "Action demandée non supportée : une tentative de manipulation de"
732      echo "fichiers  64-bits  sur une plate-forme qui ne les supporte pas a"
733      echo "été faite ; ou une option qui est supportée par le  client  mais"
734      echo "pas par le serveur a été spécifiée."
735      return;;
736    10) echo "Erreur de rsync ; RERR_SOCKETIO"
737      echo "Erreur dans le socket d'entrée sortie"
738      return;;
739    11) echo "Erreur de rsync ; RERR_FILEIO"
740      echo "Erreur d'entrée sortie fichier"
741      return;;
742    12) echo "Erreur de rsync ; RERR_STREAMIO"
743      echo "Erreur dans flux de donnée du protocole rsync"
744      return;;
745    13) echo "Erreur de rsync ; RERR_MESSAGEIO"
746      echo "Erreur avec les diagnostics du programme"
747      return;;
748    14) echo "Erreur de rsync ; RERR_IPC"
749      echo "Erreur dans le code IPC"
750      return;;
751    20) echo "Erreur de rsync ; RERR_SIGNAL"
752      echo "SIGUSR1 ou SIGINT reçu"
753      return;;
754    21) echo "Erreur de rsync ; RERR_WAITCHILD"
755      echo "Une erreur retournée par waitpid()"
756      return;;
757    22) echo "Erreur de rsync ; RERR_MALLOC"
758      echo "Erreur lors de l'allocation des tampons de mémoire de coeur"
759      return;;
760    23) echo ""
761      echo "Erreur fichier inexistant"
762      return;;
763    30) echo "Erreur de rsync ; RERR_TIMEOUT"
764      echo "Temps d'attente écoulé dans l'envoi/réception de données"
765      return;;
766    *)  echo "Erreur de rsync : code de retour de rsync inconnu :" $status
767      return;;
768    esac
769  elif [ $MYLANG = "en" ] ; then
770    case $status in
771    0)  return;;
772    1)  echo "rsync error : Syntax or usage error "
773      return;;
774    2)  echo "rsync error : Protocol incompatibility "
775      return;;
776    3)  echo "rsync error : Errors selecting input/output files, dirs"
777      return;;
778    4)  echo "rsync error : Requested action not supported: an attempt"
779      echo "was made to manipulate 64-bit files on a platform that cannot support"
780      echo "them; or an option was specified that is supported by the client and"
781      echo "not by the server."
782      return;;
783    5)  echo "rsync error : Error starting client-server protocol"
784      return;;
785    10) echo "rsync error : Error in socket I/O "
786      return;;
787    11) echo "rsync error : Error in file I/O "
788      return;;
789    12) echo "rsync error : Error in rsync protocol data stream "
790      return;;
791    13) echo "rsync error : Errors with program diagnostics "
792      return;;
793    14) echo "rsync error : Error in IPC code "
794      return;;
795    20) echo "rsync error : Received SIGUSR1 or SIGINT "
796      return;;
797    21) echo "rsync error : Some error returned by waitpid() "
798      return;;
799    22) echo "rsync error : Error allocating core memory buffers "
800      return;;
801    23) echo "rsync error : Partial transfer due to error"
802      return;;
803    24) echo "rsync error : Partial transfer due to vanished source files"
804      return;;
805    30) echo "rsync error : Timeout in data send/receive "
806      return;;
807    *)  echo "rsync error : return code of rsync unknown :" $status
808      return;;
809    esac
810  else
811    echo "unknown language $MYLANG."
812    return
813  fi
814}
815
816#D-#==================================================
817#D-function IGCM_sys_Miror_libIGCM
818#D-* Purpose: Mirror libIGCM PATH and lib to frontend
819#D-* Examples:
820#D-
821function IGCM_sys_Mirror_libIGCM {
822  IGCM_debug_PushStack "IGCM_sys_Mirror_libIGCM"
823  if ( $DEBUG_sys ) ; then
824    echo "IGCM_sys_Mirror_libIGCM"
825  fi
826
827  typeset status
828
829  mkdir -p ${HOME}/MIRROR/${PATHlibIGCM}
830
831  echo ${RSYNC} ${RSYNC_opt} ${libIGCM} ${HOME}/MIRROR/${PATHlibIGCM} > /tmp/out_command.$$ 2>&1
832  ${RSYNC} ${RSYNC_opt} ${libIGCM} ${HOME}/MIRROR/${PATHlibIGCM} >> /tmp/out_command.$$ 2>&1
833  status=$?
834
835  if [ ${status} -gt 0 ] ; then
836    echo "IGCM_sys_Mirror_libIGCM Warning : no libIGCM on frontend."
837    cat /tmp/out_command.$$
838  fi
839  IGCM_debug_PopStack "IGCM_sys_Mirror_libIGCM"
840}
841
842#D-#==================================================
843#D-function IGCM_sys_Cp
844#D-* Purpose: generic cp
845#D-* Examples:
846#D-
847function IGCM_sys_Cp {
848  IGCM_debug_PushStack "IGCM_sys_Cp" $@
849  if ( $DEBUG_sys ) ; then
850    echo "IGCM_sys_Cp :" $@
851  fi
852
853  typeset status
854
855  echo cp $@ > /tmp/out_command.$$ 2>&1
856  \cp $@ >> /tmp/out_command.$$ 2>&1
857  status=$?
858
859  if [ ${status} -gt 0 ] ; then
860    echo "IGCM_sys_Cp : error code ${status}"
861    cat /tmp/out_command.$$
862    IGCM_debug_Exit "IGCM_sys_Cp"
863  else
864    \rm /tmp/out_command.$$
865  fi
866  IGCM_debug_PopStack "IGCM_sys_Cp"
867}
868
869#D-#==================================================
870#D-function IGCM_sys_Rm
871#D-* Purpose: generic rm
872#D-* Examples:
873#D-
874function IGCM_sys_Rm {
875  IGCM_debug_PushStack "IGCM_sys_Rm" -- $@
876  if ( $DEBUG_sys ) ; then
877    echo "IGCM_sys_Rm :" $@
878  fi
879
880  typeset status
881
882  echo rm $@ > /tmp/out_command.$$ 2>&1
883  \rm $@ >> /tmp/out_command.$$ 2>&1
884  status=$?
885
886  if [ ${status} -gt 0 ] ; then
887    echo "IGCM_sys_Rm : error code ${status}"
888    cat /tmp/out_command.$$
889    IGCM_debug_Exit "IGCM_sys_Rm"
890  else
891    \rm /tmp/out_command.$$
892  fi
893  IGCM_debug_PopStack "IGCM_sys_Rm"
894}
895
896#D-#==================================================
897#D-function IGCM_sys_RmRunDir
898#D-* Purpose: rm tmpdir (dummy function most of the time batch
899#D-                      scheduler will do the job)
900#D-* Examples:
901#D-
902function IGCM_sys_RmRunDir {
903  IGCM_debug_PushStack "IGCM_sys_RmRunDir" -- $@
904  if ( $DEBUG_sys ) ; then
905    echo "IGCM_sys_RmRunDir :" $@
906    echo "Dummy call, let the scheduler do that."
907  fi
908  IGCM_debug_PopStack "IGCM_sys_RmRunDir"
909}
910
911#D-#==================================================
912#D-function IGCM_sys_Mv
913#D-* Purpose: generic move
914#D-* Examples:
915#D-
916function IGCM_sys_Mv {
917  IGCM_debug_PushStack "IGCM_sys_Mv" $@
918  if ( $DEBUG_sys ) ; then
919    echo "IGCM_sys_Mv :" $@
920  fi
921
922  if [ $DRYRUN = 0 ]; then
923
924    typeset status
925
926    echo mv $@ > /tmp/out_command.$$ 2>&1
927    \mv $@ >> /tmp/out_command.$$ 2>&1
928    status=$?
929
930    if [ ${status} -gt 0 ] ; then
931      echo "IGCM_sys_Mv : error code ${status}"
932      cat /tmp/out_command.$$
933      IGCM_debug_Exit "IGCM_sys_Mv"
934    else
935      \rm /tmp/out_command.$$
936    fi
937  fi
938
939  IGCM_debug_PopStack "IGCM_sys_Mv"
940}
941
942#D-#==================================================
943#D-function IGCM_sys_Put_Dir
944#D-* Purpose: Copy a complete directory on $(ARCHIVE)
945#D-* Examples:
946#D-
947function IGCM_sys_Put_Dir {
948  IGCM_debug_PushStack "IGCM_sys_Put_Dir" $@
949  if ( $DEBUG_sys ) ; then
950    echo "IGCM_sys_Put_Dir :" $@
951  fi
952  if [ $DRYRUN = 0 ]; then
953    if [ ! -d ${1} ] ; then
954      echo "WARNING : IGCM_sys_Put_Dir ${1} DOES NOT EXIST ."
955      IGCM_debug_PopStack "IGCM_sys_Put_Dir"
956      return
957    fi
958
959    typeset status
960
961    # Only if we use rsync
962    #IGCM_sys_TestDirArchive $( dirname $2 )
963    #
964    #Command depends on targeted file system
965    DEBUG_sys=false IGCM_sys_IsFileArchived $2
966    if [ $? = 0 ] ; then
967      \rcp -r $1 ${STOREHOST}:$2 > /tmp/out_command.$$ 2>&1
968      status=$?
969    else
970      \cp -r $1 $2 > /tmp/out_command.$$ 2>&1
971      status=$?
972    fi
973
974    if [ ${status} -gt 0 ] ; then
975      IGCM_debug_Print 2 "IGCM_sys_Put_Dir : rcp or cp failed error code ${status}"
976      cat /tmp/out_command.$$
977      IGCM_debug_Exit "IGCM_sys_Put_Dir"
978    else
979      \rm /tmp/out_command.$$
980    fi
981  fi
982  IGCM_debug_PopStack "IGCM_sys_Put_Dir"
983}
984
985#D-#==================================================
986#D-function IGCM_sys_Get_Dir
987#D-* Purpose: Copy a complete directory from ${ARCHIVE}
988#D-* Examples:
989#D-
990function IGCM_sys_Get_Dir {
991  IGCM_debug_PushStack "IGCM_sys_Get_Dir" $@
992  if ( $DEBUG_sys ) ; then
993    echo "IGCM_sys_Get_Dir :" $@
994  fi
995  if [ $DRYRUN = 0 ]; then
996#    if [ ! -d ${1} ] ; then
997#      echo "WARNING : IGCM_sys_Get_Dir ${1} DOES NOT EXIST ."
998#      IGCM_debug_PopStack "IGCM_sys_Get_Dir"
999#      return
1000#    fi
1001
1002    typeset NB_ESSAI DELAI status i
1003    # number of tentative
1004    NB_ESSAI=3
1005    # time delay between tentative
1006    DELAI=2
1007
1008    # Only if we use rsync
1009    #IGCM_sys_TestDirArchive $( dirname $2 )
1010    #
1011    # Command depends on targeted filesystem
1012    DEBUG_sys=false IGCM_sys_IsFileArchived $1
1013    if [ $? = 0 ] ; then
1014      # add dmget (to demigrate all offline files) to reduce time of this command :
1015      IGCM_sys_RshArchive "dmfind $1 -state MIG -o -state OFL -o -state PAR | dmget -q -n"
1016      i=0
1017      while [ $i -lt $NB_ESSAI ] ; do
1018        \rcp -rp ${STOREHOST}:$1 $2 > /tmp/out_command.$$ 2>&1
1019        status=$?
1020        if [ ${status} -gt 0 ]; then
1021          IGCM_debug_Print 2 "IGCM_sys_Get_Dir : rcp failed error code ${status} ${i}/${NB_ESSAI}"
1022          IGCM_debug_Print 2 "IGCM_sys_Get_Dir : sleep ${DELAI} seconds and try again."
1023          sleep $DELAI
1024        else
1025          break
1026        fi
1027        (( i = i + 1 ))
1028      done
1029    else
1030      \cp -rp $1 $2 > /tmp/out_command.$$ 2>&1
1031      status=$?
1032      if [ ${status} -gt 0 ] ; then
1033        IGCM_debug_Print 2 "IGCM_sys_Get_Dir : cp failed error code ${status}"
1034        cat /tmp/out_command.$$
1035        IGCM_debug_Exit "IGCM_sys_Get_Dir"
1036      else
1037        \rm /tmp/out_command.$$
1038      fi
1039    fi
1040    if [ ${status} -gt 0 ] ; then
1041      echo "IGCM_sys_Get_Dir : error."
1042      cat /tmp/out_command.$$
1043      IGCM_debug_Exit "IGCM_sys_Get_Dir"
1044    else
1045      \rm /tmp/out_command.$$
1046    fi
1047  fi
1048  IGCM_debug_PopStack "IGCM_sys_Get_Dir"
1049}
1050
1051#D-#==================================================
1052#D-function IGCM_sys_Get_Master
1053#D-* Purpose: Copy a complete directory from MASTER filesystem
1054#D-* Examples:
1055#D-
1056function IGCM_sys_Get_Master {
1057  IGCM_debug_PushStack "IGCM_sys_Get_Master" $@
1058  if ( $DEBUG_sys ) ; then
1059    echo "IGCM_sys_Get_Master :" $@
1060  fi
1061  if [ $DRYRUN = 0 ]; then
1062    if ( [ ! -d ${1} ] && [ ! -f ${1} ] ) ; then
1063      echo "WARNING : IGCM_sys_Get_Master ${1} DOES NOT EXIST ."
1064      IGCM_debug_PopStack "IGCM_sys_Get_Master"
1065      return
1066    fi
1067
1068    typeset NB_ESSAI DELAI status i
1069    # number of tentative
1070    NB_ESSAI=3
1071    # time delay between tentative
1072    DELAI=2
1073
1074    i=0
1075    while [ $i -lt $NB_ESSAI ] ; do
1076      \cp -urL $1 $2 > /tmp/out_command.$$ 2>&1
1077      status=$?
1078      if [ ${status} -gt 0 ]; then
1079        IGCM_debug_Print 2 "IGCM_sys_Get_Master : cp failed error code ${status} ${i}/${NB_ESSAI}"
1080        IGCM_debug_Print 2 "IGCM_sys_Get_Master : sleep ${DELAI} seconds and try again."
1081        sleep $DELAI
1082      else
1083        break
1084      fi
1085      (( i = i + 1 ))
1086    done
1087
1088    if [ ${status} -gt 0 ] ; then
1089      echo "IGCM_sys_Get_Master : error."
1090      cat /tmp/out_command.$$
1091      IGCM_debug_Exit "IGCM_sys_Get_Master"
1092    else
1093      \rm /tmp/out_command.$$
1094    fi
1095  fi
1096  IGCM_debug_PopStack "IGCM_sys_Get_Master"
1097}
1098
1099#====================================================
1100#- Call IGCM_sys_Mirror_libIGCM now !
1101if ( $MirrorlibIGCM ) ; then
1102  IGCM_sys_Mirror_libIGCM
1103fi
1104
1105#D-#==================================================
1106#D-function IGCM_sys_Put_Rest
1107#D-* Purpose: Put computied restarts on ${ARCHIVE}.
1108#D-           File and target directory must exist.
1109#D-* Examples:
1110#D-
1111function IGCM_sys_Put_Rest {
1112  IGCM_debug_PushStack "IGCM_sys_Put_Rest" $@
1113  if ( $DEBUG_sys ) ; then
1114    echo "IGCM_sys_Put_Rest :" $@
1115  fi
1116  if [ $DRYRUN = 0 ]; then
1117    if [ ! -f ${1} ] ; then
1118      echo "ERROR : IGCM_sys_Put_Rest ${1} DOES NOT EXIST ."
1119      IGCM_debug_Exit "IGCM_sys_Put_Rest"
1120    fi
1121
1122    typeset status
1123    #
1124    if [ X${JobType} = XRUN ] ; then
1125      IGCM_sys_Chmod 444 ${1}
1126    fi
1127    #
1128    #
1129    #Command depends on targeted file system
1130    DEBUG_sys=false IGCM_sys_IsFileArchived $2
1131    if [ $? = 0 ] ; then
1132      mfput $1 $2 > /tmp/out_command.$$ 2>&1
1133      status=$?
1134    else
1135      IGCM_sys_MkdirArchive $( dirname $2 )
1136      \cp $1 $2 > /tmp/out_command.$$ 2>&1
1137      status=$?
1138    fi
1139
1140#       #RSYNC WITH NETWORK RSH CALL
1141#       IGCM_sys_MkdirArchive $( dirname $2 )
1142#       echo ${RSYNC} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${RUN_DIR}/$1 ${STOREHOST}:${2} > /tmp/out_command.$$ 2>&1
1143#       ${RSYNC} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> /tmp/out_command.$$ 2>&1
1144
1145#       #RSYNC WITH NFS USE
1146#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > /tmp/out_command.$$ 2>&1
1147#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> /tmp/out_command.$$ 2>&1
1148
1149#       status=$?
1150#       IGCM_sys_Rsync_out $status
1151
1152#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk /tmp/out_command.$$
1153#       (( status=status+$? ))
1154
1155    if [ ${status} -gt 0 ] ; then
1156      echo "IGCM_sys_Put_Rest : mfput or cp failed error code ${status}"
1157      cat /tmp/out_command.$$
1158      IGCM_debug_Exit "IGCM_sys_Put_Rest"
1159    else
1160      \rm /tmp/out_command.$$
1161    fi
1162  fi
1163  IGCM_debug_PopStack "IGCM_sys_Put_Rest"
1164}
1165
1166#D-#==================================================
1167#D-function IGCM_sys_PutBuffer_Rest
1168#D-* Purpose: Put computied restarts on ${SCRATCHDIR}.
1169#D-           File and target directory must exist.
1170#D-* Examples:
1171#D-
1172function IGCM_sys_PutBuffer_Rest {
1173  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Rest" $@
1174  if ( $DEBUG_sys ) ; then
1175    echo "IGCM_sys_PutBuffer_Rest :" $@
1176  fi
1177  if [ $DRYRUN = 0 ]; then
1178    if [ ! -f ${1} ] ; then
1179      echo "ERROR : IGCM_sys_PutBuffer_Rest ${1} DOES NOT EXIST ."
1180      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
1181    fi
1182
1183    typeset status
1184    #
1185    if [ X${JobType} = XRUN ] ; then
1186      IGCM_sys_Chmod 444 ${1}
1187    fi
1188
1189    #
1190    # USUAL WAY
1191    \cp $1 $2 > /tmp/out_command.$$ 2>&1
1192    status=$?
1193
1194    if [ ${status} -gt 0 ] ; then
1195      echo "IGCM_sys_PutBuffer_Rest : error code ${status}"
1196      [ -f ${2} ] && ls -l ${2}
1197      [ -f ${2}/${1} ] && ls -l ${2}/${1}
1198      cat /tmp/out_command.$$
1199      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
1200    else
1201      \rm /tmp/out_command.$$
1202    fi
1203  fi
1204  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Rest"
1205}
1206
1207#D-#==================================================
1208#D-function IGCM_sys_PrepareTaredRestart
1209#D-* Purpose: Prepare tared restart to be access by computing job.
1210#D-* Examples:
1211#D-
1212function IGCM_sys_PrepareTaredRestart {
1213  IGCM_debug_PushStack "IGCM_sys_PrepareTaredRestart" $@
1214  if [ $DRYRUN = 0 ]; then
1215    [ ! -f $( basename $1 ) ] && IGCM_sys_Get $1 .
1216  fi
1217  IGCM_debug_PopStack "IGCM_sys_PrepareTaredRestart"
1218}
1219
1220#D-#==================================================
1221#D-function IGCM_sys_Put_Out
1222#D-* Purpose: Copy a file on ${ARCHIVE} after having chmod it in readonly
1223#D-* Examples:
1224#D-
1225function IGCM_sys_Put_Out {
1226  IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
1227  if ( $DEBUG_sys ) ; then
1228    echo "IGCM_sys_Put_Out :" $@
1229  fi
1230
1231  typeset status
1232
1233  if [ $DRYRUN = 0 ]; then
1234    if [ ! -f ${1} ] ; then
1235      echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
1236      IGCM_debug_PopStack "IGCM_sys_Put_Out"
1237      return 1
1238    fi
1239
1240    #
1241    if [ X${JobType} = XRUN ] ; then
1242      if [ X${3} = X ] ; then
1243        IGCM_sys_Chmod 444 ${1}
1244      fi
1245    fi
1246    #
1247    #
1248    #Command depends on targeted file system
1249    DEBUG_sys=false IGCM_sys_IsFileArchived $2
1250    if [ $? = 0 ] ; then
1251      mfput $1 $2 > /tmp/out_command.$$ 2>&1
1252      status=$?
1253    else
1254      IGCM_sys_MkdirArchive $( dirname $2 )
1255      \cp $1 $2 > /tmp/out_command.$$ 2>&1
1256      status=$?
1257    fi
1258
1259#       #RSYNC WITH NETWORK RSH CALL
1260#       IGCM_sys_MkdirArchive $( dirname $2 )
1261#       echo ${RSYNC} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${RUN_DIR}/$1 ${STOREHOST}:${2} > /tmp/out_command.$$ 2>&1
1262#       ${RSYNC} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> /tmp/out_command.$$ 2>&1
1263
1264#       #RSYNC WITH NFS USE
1265#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > /tmp/out_command.$$ 2>&1
1266#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> /tmp/out_command.$$ 2>&1
1267
1268#       status=$?
1269#       IGCM_sys_Rsync_out $status
1270
1271#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk /tmp/out_command.$$
1272#       (( status=status+$? ))
1273
1274    if [ ${status} -gt 0 ] ; then
1275      IGCM_debug_Print 2 "IGCM_sys_Put_Out : mfput or cp failed error code ${status}"
1276      cat /tmp/out_command.$$
1277      IGCM_debug_Exit "IGCM_sys_Put_Out"
1278    else
1279      \rm /tmp/out_command.$$
1280    fi
1281  fi
1282  IGCM_debug_PopStack "IGCM_sys_Put_Out"
1283  return 0
1284}
1285
1286#D-#==================================================
1287#D-function IGCM_sys_PutBuffer_Out
1288#D-* Purpose: Copy a file on ${WORKDIR} after having chmod it in readonly
1289#D-* Examples:
1290#D-
1291function IGCM_sys_PutBuffer_Out {
1292  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Out" $@
1293  if ( $DEBUG_sys ) ; then
1294    echo "IGCM_sys_PutBuffer_Out :" $@
1295  fi
1296
1297  typeset NB_ESSAI DELAI status i exist skip
1298
1299  # number of tentative
1300  NB_ESSAI=3
1301  # time delay between tentative
1302  DELAI=2
1303
1304  if [ $DRYRUN = 0 ]; then
1305    if [ ! -f ${1} ] ; then
1306      echo "WARNING : IGCM_sys_PutBuffer_Out ${1} DOES NOT EXIST ."
1307      IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1308      return 1
1309    fi
1310    #
1311    IGCM_sys_Mkdir $( dirname $2 )
1312    #
1313
1314    exist=false
1315    skip=false
1316    if [ -f $2 ] ; then
1317      IGCM_debug_Print 1 "$2 already exist"
1318      exist=true
1319      if [ "X$( diff $1 $2 )" = X ] ; then
1320        IGCM_debug_Print 2 "$1 and $2 are the same file, we skip the copy"
1321        status=0
1322        skip=true
1323      else
1324        IGCM_debug_Print 2 "$1 and $2 are not the same file, we force the copy"
1325        skip=false
1326      fi
1327    fi
1328    #
1329    if ( [ X${exist} = Xtrue ] && [ X${skip} = Xfalse ] ) ; then
1330      IGCM_sys_Chmod u+w $2
1331    fi
1332
1333    if [ X${skip} = Xfalse ] ; then
1334      i=0
1335      while [ $i -lt $NB_ESSAI ] ; do
1336        # USUAL WAY
1337        \cp $1 $2 > /tmp/out_command.$$ 2>&1
1338        status=$?
1339        if [ ${status} -gt 0 ]; then
1340          IGCM_debug_Print 2 "IGCM_sys_PutBuffer_Out : cp failed error code ${status} ${i}/${NB_ESSAI}"
1341          IGCM_debug_Print 2 "IGCM_sys_PutBuffer_Out : sleep ${DELAI} seconds and try again."
1342          [ -f ${2} ] && ls -l ${2}
1343          [ -f ${2}/${1} ] && ls -l ${2}/${1}
1344          sleep $DELAI
1345        else
1346          break
1347        fi
1348        (( i = i + 1 ))
1349      done
1350    fi
1351
1352    if [ ${status} -gt 0 ] ; then
1353      echo "IGCM_sys_PutBuffer_Out : error."
1354      [ -f ${2} ] && ls -l ${2}
1355      [ -f ${2}/${1} ] && ls -l ${2}/${1}
1356      cat /tmp/out_command.$$
1357      IGCM_debug_Exit "IGCM_sys_PutBuffer_Out"
1358    else
1359
1360      if [ X${JobType} = XRUN ] ; then
1361        if [ X${3} = X ] ; then
1362          [ -f ${2} ] && IGCM_sys_Chmod 444 ${2}
1363          [ -f ${2}/${1} ] && IGCM_sys_Chmod 444 ${2}/${1}
1364        fi
1365      fi
1366
1367      \rm /tmp/out_command.$$
1368    fi
1369  fi
1370  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1371  return 0
1372}
1373
1374#D-#==================================================
1375#D-function IGCM_sys_Get
1376#D-* Purpose: Get a file from ${ARCHIVE}
1377#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
1378#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
1379function IGCM_sys_Get {
1380  IGCM_debug_PushStack "IGCM_sys_Get" $@
1381
1382  typeset DEST status dm_liste
1383
1384  if ( $DEBUG_sys ) ; then
1385    echo "IGCM_sys_Get :" $@
1386  fi
1387  if [ $DRYRUN -le 2 ]; then
1388    if [ X${1} = X'/l' ] ; then
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} > /tmp/out_command.$$ 2>&1
1415      status=$?
1416    else
1417      \cp ${dm_liste[*]} ${DEST} > /tmp/out_command.$$ 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} > /tmp/out_command.$$ 2>&1
1423#       ${RSYNC} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} >> /tmp/out_command.$$ 2>&1
1424
1425#       #RSYNC WITH NFS USE
1426#       echo ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} > /tmp/out_command.$$ 2>&1
1427#       ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} >> /tmp/out_command.$$ 2>&1
1428
1429#       status=$?
1430#       IGCM_sys_Rsync_out $status
1431
1432#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk /tmp/out_command.$$
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 /tmp/out_command.$$
1438      IGCM_debug_Exit "IGCM_sys_Get"
1439    else
1440      \rm /tmp/out_command.$$
1441    fi
1442  fi
1443  IGCM_debug_PopStack "IGCM_sys_Get"
1444}
1445
1446#D-#==================================================
1447#D-function IGCM_sys_GetBuffer
1448#D-* Purpose: Get a file from ${SCRATCHDIR}
1449#D-* Examples: IGCM_sys_GetBuffer myfile /destpath/myfile_with_PREFIX
1450#D-            IGCM_sys_GetBuffer /l Array_contain_myfiles /destpath/
1451function IGCM_sys_GetBuffer {
1452  IGCM_debug_PushStack "IGCM_sys_GetBuffer" $@
1453
1454  typeset DEST buf_liste target file_work
1455  typeset NB_ESSAI DELAI status i
1456
1457  if ( $DEBUG_sys ) ; then
1458    echo "IGCM_sys_GetBuffer :" $@
1459  fi
1460
1461  # number of tentative
1462  NB_ESSAI=3
1463  # time delay between tentative
1464  DELAI=2
1465
1466  if [ $DRYRUN -le 2 ]; then
1467    if [ X${1} = X'/l' ] ; then
1468      eval set +A buf_liste \${${2}}
1469    else
1470      eval set +A buf_liste ${1}
1471    fi
1472    eval DEST=\${${#}}
1473
1474    #USUAL WAY
1475    if [ X${1} = X'/l' ] ; then
1476      for target in ${buf_liste[*]} ; do
1477        local_file=$( basename ${target} )
1478        i=0
1479        while [ $i -lt $NB_ESSAI ] ; do
1480          \cp ${target} ${DEST}/${local_file} >> /tmp/out_command.$$ 2>&1
1481          status=$?
1482          if [ ${status} -gt 0 ]; then
1483            IGCM_debug_Print 2 "IGCM_sys_GetBuffer : cp failed error code ${status} ${i}/${NB_ESSAI}"
1484            IGCM_debug_Print 2 "IGCM_sys_GetBuffer : sleep ${DELAI} seconds and try again."
1485            sleep $DELAI
1486          else
1487            break
1488          fi
1489          (( i = i + 1 ))
1490        done
1491        if [ ${status} -gt 0 ] ; then
1492          echo "IGCM_sys_Get : error"
1493          cat /tmp/out_command.$$
1494          \rm /tmp/out_command.$$
1495          IGCM_debug_Exit "IGCM_sys_GetBuffer"
1496        else
1497          \rm /tmp/out_command.$$
1498        fi
1499      done
1500    else
1501      i=0
1502      while [ $i -lt $NB_ESSAI ] ; do
1503        \cp ${buf_liste} ${DEST} >> /tmp/out_command.$$ 2>&1
1504        status=$?
1505        if [ ${status} -gt 0 ]; then
1506          IGCM_debug_Print 2 "IGCM_sys_GetBuffer : cp failed error code ${status} ${i}/${NB_ESSAI}"
1507          IGCM_debug_Print 2 "IGCM_sys_GetBuffer : sleep ${DELAI} seconds and try again."
1508          sleep $DELAI
1509        else
1510          break
1511        fi
1512        (( i = i + 1 ))
1513      done
1514      if [ ${status} -gt 0 ] ; then
1515        echo "IGCM_sys_Get : error"
1516        cat /tmp/out_command.$$
1517        \rm /tmp/out_command.$$
1518        IGCM_debug_Exit "IGCM_sys_GetBuffer"
1519      else
1520        \rm /tmp/out_command.$$
1521      fi
1522    fi
1523  fi
1524  IGCM_debug_PopStack "IGCM_sys_GetBuffer"
1525}
1526
1527#D-#==================================================
1528#D-function IGCM_sys_GetDate_FichWork
1529#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
1530#D-* Examples:
1531#D-
1532function IGCM_sys_GetDate_FichWork {
1533  IGCM_debug_PushStack "IGCM_sys_FichWork" $@
1534  if ( $DEBUG_sys ) ; then
1535    echo "IGCM_sys_GetDate_FichWork :" $@
1536  fi
1537
1538  if [ $# -ge 3 ] ; then
1539    mode=$3
1540    TimeStyle=$4
1541  else
1542    mode="default"
1543    TimeStyle="%Y%m%d%H%M%S"
1544  fi
1545
1546  typeset dateF
1547  set +A dateF -- $( ls -l --full-time --time-style=+"${TimeStyle}" ${1} )
1548
1549  case $mode in
1550    "default")
1551      eval ${2}=${dateF[5]}
1552      ;;
1553    "SplitFields")
1554      eval ${2}="${dateF[5]}\ ${dateF[6]}"
1555      ;;
1556  esac
1557
1558
1559  # donne la date filesys d'un fichier sur la machine work
1560  IGCM_debug_PopStack "IGCM_sys_FichWork"
1561}
1562
1563#D-#==================================================
1564#D-function IGCM_sys_GetDate_FichArchive
1565#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
1566#D-* Examples:
1567#D-
1568function IGCM_sys_GetDate_FichArchive {
1569  IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
1570  if ( $DEBUG_sys ) ; then
1571    echo "IGCM_sys_GetDate_FichArchive :" $@
1572  fi
1573  typeset dateF
1574  set +A dateF -- $( rsh ${STOREHOST} -n ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1575  eval ${2}=${dateF[5]}
1576
1577  IGCM_debug_PopStack "IGCM_sys_FichArchive"
1578}
1579
1580#D-#==================================================
1581#D-function IGCM_sys_GetDate_Monitoring
1582#D-* Purpose: get the last year for which the monitoring has been computed
1583#D-* Examples:
1584#D-
1585function IGCM_sys_GetDate_Monitoring {
1586  IGCM_debug_PushStack "IGCM_sys_GetDate_Monitoring" $@
1587  if ( $DEBUG_sys ) ; then
1588    echo "IGCM_sys_GetDate_Monitoring :" $@
1589  fi
1590
1591  IGCM_sys_Cd /tmp
1592  IGCM_sys_Get ${1} .
1593  eval ${2}=$( cdo showyear $( basename ${1} ) 2> /dev/null | gawk '{ print $NF }' )
1594  IGCM_sys_Cd -
1595
1596  IGCM_debug_PopStack "IGCM_sys_GetDate_Monitoring"
1597}
1598
1599#D-#==================================================
1600#D-function IGCM_sys_Put_Dods
1601#D-* Purpose: Put $(ARCHIVE) files on DODS internet protocole.
1602#D-* Examples:
1603#D-
1604function IGCM_sys_Put_Dods {
1605  IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
1606  if ( $DEBUG_sys ) ; then
1607    echo "IGCM_sys_Put_Dods :" $@
1608  fi
1609  if [ $DRYRUN = 0 ]; then
1610    # We take our time on that
1611    sleep 10
1612    IGCM_sys_TestDirArchive ${R_SAVE}/${1}
1613    if [ $? != 0 ] ; then
1614      echo "WARNING : IGCM_sys_Put_Dods ${R_SAVE}/${1} DOES NOT EXIST ."
1615      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1616      return
1617    fi
1618
1619    typeset status
1620    #
1621    rsh gaya exec /bin/ksh <<EOF
1622          cd ${R_SAVE}
1623          /usr/local/bin/dods_rm DODS/pub/${LOGIN}/${R_DODS}/${1} > /dev/null 2>&1
1624          /bin/chmod -R u+w ${R_SAVE}/${1}
1625          /usr/local/bin/dods_cp ${1} DODS/pub/${LOGIN}/${R_DODS} > /dev/null 2>&1
1626          /bin/chmod -R +rX ${R_SAVE}/${1}
1627          /bin/chmod -R u+w ${R_SAVE}/${1}
1628EOF
1629    status=$?
1630
1631    if [ ${status} -gt 0 ] ; then
1632      echo "IGCM_sys_Put_Dods : error."
1633      IGCM_debug_Exit "IGCM_sys_Put_Dods"
1634    fi
1635  fi
1636  IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1637}
1638
1639##############################################################
1640# REBUILD OPERATOR
1641
1642#D-#==================================================
1643#D-function IGCM_sys_rebuild
1644#D-* Purpose: rebuild parallel files
1645#D-* Examples:
1646#D-
1647function IGCM_sys_rebuild {
1648  IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1649  if ( $DEBUG_sys ) ; then
1650    echo "IGCM_sys_rebuild :" $@
1651  fi
1652
1653  typeset NB_ESSAI DELAI status i firstArg
1654  # number of tentative
1655  NB_ESSAI=3
1656  # time delay between tentative
1657  DELAI=2
1658
1659  i=0
1660  while [ $i -lt $NB_ESSAI ] ; do
1661    /smphome/rech/psl/rpsl035/bin/rebuild -f -o $@ > /tmp/out_command.$$ 2>&1
1662    status=$?
1663    if [ ${status} -gt 0 ] ; then
1664      IGCM_debug_Print 2 "IGCM_sys_rebuild : error code ${status}"
1665      cat /tmp/out_command.$$
1666      \rm /tmp/out_command.$$
1667      IGCM_debug_Print 2 "IGCM_sys_rebuild : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1668      firstArg=${1}
1669      \rm ${firstArg}
1670      sleep $DELAI
1671    else
1672      \rm /tmp/out_command.$$
1673      break
1674    fi
1675    (( i = i + 1 ))
1676  done
1677
1678  if [ ${status} -gt 0 ] ; then
1679    echo "IGCM_sys_rebuild : rebuild error code is ${status}"
1680    IGCM_debug_Exit "rebuild"
1681  fi
1682
1683  IGCM_debug_PopStack "IGCM_sys_rebuild"
1684}
1685
1686#D-#==================================================
1687#D-function IGCM_sys_rebuild_station
1688#D-* Purpose: rebuild parallel files describing station
1689#D-* Examples:
1690#D-
1691function IGCM_sys_rebuild_station {
1692  IGCM_debug_PushStack "IGCM_sys_rebuild_station" -- $@
1693  typeset i list_opt file_in file_out prefix_invert list_invert
1694  if ( $DEBUG_sys ) ; then
1695    echo "IGCM_sys_rebuild_station :" $@
1696  fi
1697  list_opt=$@
1698
1699  # Invert Axis : t,x -> x,t
1700  #               t,pres,x -> x,t,pres
1701  # So that we can concatenate along x
1702  i=0
1703  for file_in in ${list_opt} ; do
1704    (( i = i + 1))
1705    [ ${i} = 1 ] && file_out=${file_in} && continue
1706    prefix_invert=$( basename ${file_in} .nc )
1707    IGCM_sys_ncpdq -a x,time_counter -a x,time_counter,presnivs ${file_in} ${prefix_invert}_xt.nc
1708    list_invert[${#list_invert[*]}]=${prefix_invert}_xt.nc
1709  done
1710
1711  # Concatenate
1712  IGCM_sys_ncrcat ${list_invert[*]} histstn_xt.nc
1713
1714  # Re-ivert file
1715  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x histstn_xt.nc ${file_out}
1716
1717  # Station re-ordering is too expansive to be run within libIGCM
1718  # This is due to (ncpdq - nrcat - ncpdq) I/O sequence.
1719  # This re-ordering must be done "in memory" by the cmorization process
1720  # Anyway this is the best sequence using (ncpdq - nrcat - ncpdq)
1721  # BEGIN reordering
1722
1723  # Only LMDZ text output contains the exact ordering of the station.
1724  # We isolate this in the code below:
1725  #  0  38  -157.5000000000000  70.98591549295774
1726  #  0  54  27.49999999999999   67.18309859154928
1727  #  0  56  -62.50000000000001  82.39436619718309
1728  #  0  79  12.49999999999999   78.59154929577466
1729  #  0  116 -165.0000000000000  76.05633802816901
1730  #  0  117 130.0000000000000   70.98591549295774
1731  #  0  118 110.0000000000000   87.46478873239437
1732  #  1  40  4.999999999999995   51.97183098591550
1733#  typeset iStation iProc list_opt file_in file_out prefix_invert
1734#  typeset -Z4 j4
1735#  typeset -Z3 j3
1736
1737#  unset list_opt
1738#  set +A list_opt $@
1739
1740  # Filename after rebuild
1741#  file_out=${list_opt[0]}
1742  # Prefix of output files
1743#  prefix_invert=$( basename ${file_out} .nc )
1744  # Number of procs
1745#  num_proc=$( grep -i mpi_size ${PREFIX}_${Exe_Output} | wc -l )
1746
1747#  iProc=0
1748#  while [ ${iProc} -lt ${num_proc} ] ; do
1749    # Array containing Station as a number
1750#    unset proc_stn
1751#    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}' )
1752    # Number of stations produced by processor proc
1753#    stationLast=${#proc_stn[*]}
1754    # Proc number on 4 digits
1755#    j4=${iProc}
1756    # Init
1757#    iStation=0
1758#    while [ ${iStation} -lt ${stationLast} ] ; do
1759      # Station number on 3 digits
1760#      j3=${proc_stn[${iStation}]}
1761      # Extract station
1762      # Invert Axis : t,x -> x,t
1763      #               t,pres,x -> x,t,pres
1764      # So that we can concatenate along x
1765#      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
1766#      (( iStation = iStation + 1 ))
1767#    done
1768#    (( iProc = iProc + 1 ))
1769#  done
1770
1771  # Concatenate all station along x
1772#  IGCM_sys_ncrcat ${prefix_invert}_stn_???.nc ${prefix_invert}_xt.nc
1773
1774  # Re-invert file
1775#  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x ${prefix_invert}_xt.nc ${file_out}
1776
1777  # END reordering
1778
1779  IGCM_debug_PopStack "IGCM_sys_rebuild_station"
1780}
1781
1782############################################################
1783# Activate Running Environnment Variables
1784
1785#D-#==================================================
1786#D-function IGCM_sys_desactiv_variables
1787#D-* Purpose: set environement variables prior to execution
1788#D-* Examples:
1789#D-
1790function IGCM_sys_activ_variables {
1791  IGCM_debug_PushStack "IGCM_sys_activ_variables"
1792  if ( $DEBUG_sys ) ; then
1793    echo "IGCM_sys_activ_variables"
1794  fi
1795
1796# --------------------------------------------------------------------
1797#D- MPI specifications
1798# --------------------------------------------------------------------
1799
1800# --------------------------------------------------------------------
1801#D- Other specifications
1802# --------------------------------------------------------------------
1803
1804  ulimit -s unlimited
1805
1806## to be done only one time
1807## export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/smplocal/pub/NetCDF/4.1.3/lib:/smplocal/pub/HDF5/1.8.9/seq/lib
1808  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
1809  echo LD_LIBRARY_PATH = ${LD_LIBRARY_PATH}
1810
1811  IGCM_debug_PopStack "IGCM_sys_activ_variables"
1812}
1813
1814############################################################
1815# Desactivate Running Environnment Variables
1816
1817#D-#==================================================
1818#D-function IGCM_sys_desactiv_variables
1819#D-* Purpose: unset environement variables after execution
1820#D-* Examples:
1821#D-
1822function IGCM_sys_desactiv_variables {
1823  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1824  if ( $DEBUG_sys ) ; then
1825    echo "IGCM_sys_desactiv_variables"
1826  fi
1827# --------------------------------------------------------------------
1828#D- MPI specifications
1829# --------------------------------------------------------------------
1830
1831# --------------------------------------------------------------------
1832#D- Other specifications
1833# --------------------------------------------------------------------
1834
1835  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1836}
1837
1838############################################################
1839# Build MPI/OMP scripts run file (dummy function)
1840
1841#D-#==================================================
1842#D-function IGCM_sys_build_run_file
1843#D-* Purpose: build run file (deprecated)
1844#D-* Examples:
1845#D-
1846function IGCM_sys_build_run_file {
1847
1848  IGCM_debug_Print 3 " dummy function : IGCM_sys_build_run_file "
1849
1850}
1851
1852############################################################
1853# Build MPI/OMP scripts
1854
1855#D-#==================================================
1856#D-function IGCM_sys_build_execution_scripts
1857#D-* Purpose: build execution scripts to be launch by ${HOST_MPIRUN_COMMAND}
1858#D-* Examples:
1859#D-
1860function IGCM_sys_build_execution_scripts
1861{
1862  IGCM_debug_PushStack "IGCM_sys_build_execution_scripts" $@
1863  if ( $DEBUG_sys ) ; then
1864    echo "IGCM_sys_build_execution_scripts " $@
1865  fi
1866
1867  EXECUTION=${HOST_MPIRUN_COMMAND}
1868
1869  if ( ${OK_PARA_MPMD} ) ; then
1870
1871    if [ -f run_file ] ; then
1872      IGCM_sys_Rm -f run_file
1873    fi
1874    touch run_file
1875
1876# run_file construction
1877
1878# Then first loop on the components for the coupler ie oasis
1879
1880### the coupler ie oasis must be the first one
1881    for comp in ${config_ListOfComponents[*]} ; do
1882
1883      eval ExeNameIn=\${config_Executable_${comp}[0]}
1884      eval ExeNameOut=\${config_Executable_${comp}[1]}
1885
1886      # for CPL component only
1887      if [ "X${comp}" = "XCPL" ] ; then
1888
1889        eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1890        eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1891
1892        if ( ${OK_PARA_MPI} ) ; then
1893          (( mpi_count = 1 ))
1894          until [ ${mpi_count} -gt ${comp_proc_mpi_loc} ] ; do
1895            echo "./${ExeNameOut}" >> run_file
1896            (( mpi_count = mpi_count + 1 ))
1897          done
1898        else
1899          echo "./${ExeNameOut} " >> run_file
1900        fi
1901      fi
1902    done
1903
1904# Then second loop on the components
1905
1906    for comp in ${config_ListOfComponents[*]} ; do
1907
1908      eval ExeNameIn=\${config_Executable_${comp}[0]}
1909      eval ExeNameOut=\${config_Executable_${comp}[1]}
1910
1911      # Only if we really have an executable for the component and not the coupler ie oasis:
1912      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${comp}" != "XCPL" ] ) ; then
1913
1914        eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1915        eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1916
1917        if ( ${OK_PARA_MPI} ) ; then
1918          (( mpi_count = 1 ))
1919          until [ ${mpi_count} -gt ${comp_proc_mpi_loc} ] ; do
1920            echo "./${ExeNameOut}" >> run_file
1921            (( mpi_count = mpi_count + 1 ))
1922          done
1923        else
1924            echo "./${ExeNameOut} " >> run_file
1925        fi
1926      fi
1927    done
1928
1929    EXECUTION="${HOST_MPIRUN_COMMAND} -pgmmodel mpmd -cmdfile ./run_file"
1930
1931    IGCM_sys_Chmod u+x run_file
1932    if ( $DEBUG_sys ) ; then
1933      echo "run_file contains : "
1934      cat run_file
1935    fi
1936
1937  else # Only one executable. launch it.
1938
1939    for comp in ${config_ListOfComponents[*]} ; do
1940
1941      # Only if we really have an executable for the component :
1942      eval ExeNameOut=\${config_Executable_${comp}[1]}
1943      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${ExeNameOut}" != "Xinca.dat" ] ) ; then
1944
1945        if ( ${OK_PARA_OMP} ) ; then
1946          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1947          export KMP_STACKSIZE=200m
1948          #export KMP_LIBRARY=turnaround
1949          #echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
1950          #echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
1951          #echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
1952        fi
1953
1954        EXECUTION="${HOST_MPIRUN_COMMAND} ./${ExeNameOut}"
1955      fi
1956
1957    done
1958
1959  fi
1960
1961  IGCM_debug_Print 1 "sys ada : execution command is "
1962  IGCM_debug_Print 1 "$EXECUTION"
1963
1964  IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
1965}
1966
1967#D-#==================================================
1968#D-function IGCM_sys_check_path
1969#D-* Purpose: check that RUN_DIR_PATH that will be removed on some machine
1970#D-* do not point to an important use directory. Stop immediately in that case.
1971#D-* Examples:
1972#D-
1973function IGCM_sys_check_path {
1974  IGCM_debug_PushStack "IGCM_sys_check_path"
1975  if ( $DEBUG_sys ) ; then
1976    echo "IGCM_sys_check_path"
1977  fi
1978
1979  if ( [ X${RUN_DIR_PATH} = X${HOME} ] || [ X${RUN_DIR_PATH} = X${WORKDIR} ] || [ X${RUN_DIR_PATH} = X${HOMEGAYA} ] ) ; then
1980    IGCM_debug_Print 1 "Variable RUN_DIR_PATH is pointing to an important directory : ${RUN_DIR_PATH}"
1981    IGCM_debug_Print 1 "Please check the RUN_DIR_PATH definition in your Job : Job_${config_UserChoices_JobName}"
1982    IGCM_debug_Exit "This will stop the job"
1983  fi
1984  IGCM_debug_PopStack "IGCM_sys_check_path"
1985}
1986
1987#D-#==================================================
1988#D-function IGCM_sys_check_quota
1989#D-* Purpose: check user quota. Stop the simulation if quota above 90%
1990#D-* Examples:
1991#D-
1992function IGCM_sys_check_quota {
1993  IGCM_debug_PushStack "IGCM_sys_check_quota"
1994  if ( $DEBUG_sys ) ; then
1995    echo "IGCM_sys_check_quota"
1996  fi
1997  # Limit of quota (in %)
1998  limit_quota=90
1999
2000  # Check of the volume
2001  volume_quota=$(quota_u -w 2>/dev/null| grep 'Quota soft' | gawk '{print $5}')
2002  if [ ! X${volume_quota} = X ] ; then
2003    quota_volume=${volume_quota%%\%}
2004#    echo $quota_volume
2005    if [ $(echo "${quota_volume} > ${limit_quota}" | bc) -eq 1 ] ; then
2006      IGCM_debug_Print 1 "Please, check your quota of volume on workgpfs"
2007      IGCM_debug_Print 1 "${quota_volume}% of your quota is used"
2008      IGCM_debug_Print 1 "Use the quota_u -w command to check"
2009      IGCM_debug_Print 1 "You must have more than 10% available to run"
2010      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
2011      IGCM_debug_Verif_Exit
2012    fi
2013
2014  fi
2015  IGCM_debug_PopStack "IGCM_sys_check_quota"
2016}
2017
2018#D-#==================================================
2019#D-function IGCM_sys_GetJobID
2020#D-* Purpose: Check if job_name is currently
2021#D-  running or in queue
2022#D-* Examples: IGCM_sys_GetJobID ${JobName} NbRun
2023#D-
2024function IGCM_sys_GetJobID {
2025  IGCM_debug_PushStack "IGCM_sys_GetJobID"
2026  if ( $DEBUG_sys ) ; then
2027    echo "IGCM_sys_GetJobID"
2028  fi
2029
2030  # Print only the full (-W) JobID (%id) and JobName (%jn)
2031  ID=$( llq -u $2 -W -f %id %jn | \
2032        gawk -v JobName=$1 '( $NF ~ JobName ) { print $1 }' )
2033
2034  eval ${3}=${ID}
2035
2036  IGCM_debug_PopStack "IGCM_sys_GetJobID"
2037}
2038
2039#D-#==================================================
2040#D-function IGCM_sys_CountJobInQueue
2041#D-* Purpose: Check if job_name is currently
2042#D-  running or in queue
2043#D-* Examples: IGCM_sys_CountJobInQueue ${JobName} NbRun
2044#D-
2045function IGCM_sys_CountJobInQueue {
2046  IGCM_debug_PushStack "IGCM_sys_CountJobInQueue"
2047  if ( $DEBUG_sys ) ; then
2048    echo "IGCM_sys_CountJobInQueue"
2049  fi
2050
2051  # Print only the full (-W) JobName (%jn)
2052  NbRun=$( llq -W -f %jn | grep -c "$1" )
2053
2054  eval ${2}=${NbRun}
2055
2056  IGCM_debug_PopStack "IGCM_sys_CountJobInQueue"
2057}
2058
2059#D-#==================================================
2060#D-function IGCM_sys_ListJobInQueue
2061#D-* Purpose: Check if job_name is currently
2062#D-  running or in queue
2063#D-* Examples: IGCM_sys_ListJobInQueue ${User} JobNameList
2064#D-
2065function IGCM_sys_ListJobInQueue {
2066  IGCM_debug_PushStack "IGCM_sys_ListJobInQueue"
2067  if ( $DEBUG_sys ) ; then
2068    echo "IGCM_sys_ListJobInQueue"
2069  fi
2070
2071  # With -f option, the full job name is given in the last column
2072  set -A JobList $( llq -u $1 -W -f %jn | gawk '( $1 != /TS/      && \
2073                                                  $1 !~ /PACK/    && \
2074                                                  $1 !~ /REBUILD/ && \
2075                                                  $1 !~ /pack/ )     \
2076                                                { print $1 }' | sed -e "s/\(.*\)\.[0-9]*/\1/" )
2077
2078  eval set -A ${2} ${JobList[*]}
2079
2080  IGCM_debug_PopStack "IGCM_sys_ListJobInQueue"
2081}
2082
2083##############################################################
2084# NCO OPERATOR
2085
2086#D-#==================================================
2087#D-function IGCM_sys_ncap2
2088#D-* Purpose: encapsulate ncap2 call so as to manage error code and retry
2089#D-* Examples:
2090#D-
2091function IGCM_sys_ncap2 {
2092  IGCM_debug_PushStack "IGCM_sys_ncap2" -- $@
2093  if ( $DEBUG_sys ) ; then
2094    echo "IGCM_sys_ncap2 :" $@
2095  fi
2096
2097  typeset NB_ESSAI DELAI status i
2098  # number of tentative
2099  NB_ESSAI=3
2100  # time delay between tentative
2101  DELAI=2
2102
2103  i=0
2104  while [ $i -lt $NB_ESSAI ] ; do
2105    ncap2 "$@" > /tmp/out_command.$$ 2>&1
2106    status=$?
2107    if [ ${status} -gt 0 ] ; then
2108      IGCM_debug_Print 2 "IGCM_sys_ncap2 : error code ${status}"
2109      cat /tmp/out_command.$$
2110      \rm /tmp/out_command.$$
2111      IGCM_debug_Print 2 "IGCM_sys_ncap2 : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2112      sleep $DELAI
2113    else
2114      \rm /tmp/out_command.$$
2115      break
2116    fi
2117    (( i = i + 1 ))
2118  done
2119
2120  if [ ${status} -gt 0 ] ; then
2121    echo "IGCM_sys_ncap2 : ncap2 error"
2122    IGCM_debug_Exit "ncap2"
2123  fi
2124
2125  IGCM_debug_PopStack "IGCM_sys_ncap2"
2126}
2127
2128#D-#==================================================
2129#D-function IGCM_sys_ncatted
2130#D-* Purpose: encapsulate ncatted call so as to manage error code and retry
2131#D-* Examples:
2132#D-
2133function IGCM_sys_ncatted {
2134  IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
2135  if ( $DEBUG_sys ) ; then
2136    echo "IGCM_sys_ncatted :" $@
2137  fi
2138
2139  typeset NB_ESSAI DELAI status i
2140  # number of tentative
2141  NB_ESSAI=3
2142  # time delay between tentative
2143  DELAI=2
2144
2145  i=0
2146  while [ $i -lt $NB_ESSAI ] ; do
2147    ncatted "$@" > /tmp/out_command.$$ 2>&1
2148    status=$?
2149    if [ ${status} -gt 0 ] ; then
2150      IGCM_debug_Print 2 "IGCM_sys_ncatted : error code ${status}"
2151      cat /tmp/out_command.$$
2152      \rm /tmp/out_command.$$
2153      IGCM_debug_Print 2 "IGCM_sys_ncatted : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2154      sleep $DELAI
2155    else
2156      \rm /tmp/out_command.$$
2157      break
2158    fi
2159    (( i = i + 1 ))
2160  done
2161
2162  if [ ${status} -gt 0 ] ; then
2163    echo "IGCM_sys_ncatted : ncatted error"
2164    IGCM_debug_Exit "ncatted"
2165  fi
2166
2167  IGCM_debug_PopStack "IGCM_sys_ncatted"
2168}
2169
2170#D-#==================================================
2171#D-function IGCM_sys_ncbo
2172#D-* Purpose: encapsulate ncbo call so as to manage error code and retry
2173#D-* Examples:
2174#D-
2175function IGCM_sys_ncbo {
2176  IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
2177  if ( $DEBUG_sys ) ; then
2178    echo "IGCM_sys_ncbo :" $@
2179  fi
2180
2181  typeset NB_ESSAI DELAI status i
2182  # number of tentative
2183  NB_ESSAI=3
2184  # time delay between tentative
2185  DELAI=2
2186
2187  i=0
2188  while [ $i -lt $NB_ESSAI ] ; do
2189    ncbo $@ > /tmp/out_command.$$ 2>&1
2190    status=$?
2191    if [ ${status} -gt 0 ] ; then
2192      IGCM_debug_Print 2 "IGCM_sys_ncbo : error code ${status}"
2193      cat /tmp/out_command.$$
2194      \rm /tmp/out_command.$$
2195      IGCM_debug_Print 2 "IGCM_sys_ncbo : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2196      sleep $DELAI
2197    else
2198      \rm /tmp/out_command.$$
2199      break
2200    fi
2201    (( i = i + 1 ))
2202  done
2203
2204  if [ ${status} -gt 0 ] ; then
2205    echo "IGCM_sys_ncbo : ncbo error"
2206    IGCM_debug_Exit "ncbo"
2207  fi
2208
2209  IGCM_debug_PopStack "IGCM_sys_ncbo"
2210}
2211
2212#D-#==================================================
2213#D-function IGCM_sys_ncdif
2214#D-* Purpose: encapsulate ncdiff call so as to manage error code and retry
2215#D-* Examples:
2216#D-
2217function IGCM_sys_ncdiff {
2218  IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
2219  if ( $DEBUG_sys ) ; then
2220    echo "IGCM_sys_ncdiff :" $@
2221  fi
2222
2223  typeset NB_ESSAI DELAI status i
2224  # number of tentative
2225  NB_ESSAI=3
2226  # time delay between tentative
2227  DELAI=2
2228
2229  i=0
2230  while [ $i -lt $NB_ESSAI ] ; do
2231    ncdiff $@ > /tmp/out_command.$$ 2>&1
2232    status=$?
2233    if [ ${status} -gt 0 ] ; then
2234      IGCM_debug_Print 2 "IGCM_sys_ncdiff : error code ${status}"
2235      cat /tmp/out_command.$$
2236      \rm /tmp/out_command.$$
2237      IGCM_debug_Print 2 "IGCM_sys_ncdiff : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2238      sleep $DELAI
2239    else
2240      \rm /tmp/out_command.$$
2241      break
2242    fi
2243    (( i = i + 1 ))
2244  done
2245
2246  if [ ${status} -gt 0 ] ; then
2247    echo "IGCM_sys_ncdiff : ncdiff error"
2248    IGCM_debug_Exit "ncdiff"
2249  fi
2250
2251  IGCM_debug_PopStack "IGCM_sys_ncdiff"
2252}
2253
2254#D-#==================================================
2255#D-function IGCM_sys_ncea
2256#D-* Purpose: encapsulate ncea call so as to manage error code and retry
2257#D-* Examples:
2258#D-
2259function IGCM_sys_ncea {
2260  IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
2261  if ( $DEBUG_sys ) ; then
2262    echo "IGCM_sys_ncea :" $@
2263  fi
2264
2265  typeset NB_ESSAI DELAI status i
2266  # number of tentative
2267  NB_ESSAI=3
2268  # time delay between tentative
2269  DELAI=2
2270
2271  i=0
2272  while [ $i -lt $NB_ESSAI ] ; do
2273    ncea $@ > /tmp/out_command.$$ 2>&1
2274    status=$?
2275    if [ ${status} -gt 0 ] ; then
2276      IGCM_debug_Print 2 "IGCM_sys_ncea : error code ${status}"
2277      cat /tmp/out_command.$$
2278      \rm /tmp/out_command.$$
2279      IGCM_debug_Print 2 "IGCM_sys_ncea : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2280      sleep $DELAI
2281    else
2282      \rm /tmp/out_command.$$
2283      break
2284    fi
2285    (( i = i + 1 ))
2286  done
2287
2288  if [ ${status} -gt 0 ] ; then
2289    echo "IGCM_sys_ncea : ncea error"
2290    IGCM_debug_Exit "ncea"
2291  fi
2292
2293  IGCM_debug_PopStack "IGCM_sys_ncea"
2294}
2295
2296#D-#==================================================
2297#D-function IGCM_sys_ncecat
2298#D-* Purpose: encapsulate ncecat call so as to manage error code and retry
2299#D-* Examples:
2300#D-
2301function IGCM_sys_ncecat {
2302  IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
2303  if ( $DEBUG_sys ) ; then
2304    echo "IGCM_sys_ncecat :" $@
2305  fi
2306
2307  typeset NB_ESSAI DELAI status i
2308  # number of tentative
2309  NB_ESSAI=3
2310  # time delay between tentative
2311  DELAI=2
2312
2313  i=0
2314  while [ $i -lt $NB_ESSAI ] ; do
2315    ncecat $@ > /tmp/out_command.$$ 2>&1
2316    status=$?
2317    if [ ${status} -gt 0 ] ; then
2318      IGCM_debug_Print 2 "IGCM_sys_ncecat : error code ${status}"
2319      cat /tmp/out_command.$$
2320      \rm /tmp/out_command.$$
2321      IGCM_debug_Print 2 "IGCM_sys_ncecat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2322      sleep $DELAI
2323    else
2324      \rm /tmp/out_command.$$
2325      break
2326    fi
2327    (( i = i + 1 ))
2328  done
2329
2330  if [ ${status} -gt 0 ] ; then
2331    echo "IGCM_sys_ncecat : ncecat error"
2332    IGCM_debug_Exit "ncecat"
2333  fi
2334
2335  IGCM_debug_PopStack "IGCM_sys_ncecat"
2336}
2337
2338#D-#==================================================
2339#D-function IGCM_sys_ncflint
2340#D-* Purpose: encapsulate ncflint call so as to manage error code and retry
2341#D-* Examples:
2342#D-
2343function IGCM_sys_ncflint {
2344  IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
2345  if ( $DEBUG_sys ) ; then
2346    echo "IGCM_sys_ncflint :" $@
2347  fi
2348
2349  typeset NB_ESSAI DELAI status i
2350  # number of tentative
2351  NB_ESSAI=3
2352  # time delay between tentative
2353  DELAI=2
2354
2355  i=0
2356  while [ $i -lt $NB_ESSAI ] ; do
2357    ncflint $@ > /tmp/out_command.$$ 2>&1
2358    status=$?
2359    if [ ${status} -gt 0 ] ; then
2360      IGCM_debug_Print 2 "IGCM_sys_ncflint : error code ${status}"
2361      cat /tmp/out_command.$$
2362      \rm /tmp/out_command.$$
2363      IGCM_debug_Print 2 "IGCM_sys_ncflint : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2364      sleep $DELAI
2365    else
2366      \rm /tmp/out_command.$$
2367      break
2368    fi
2369    (( i = i + 1 ))
2370  done
2371
2372  if [ ${status} -gt 0 ] ; then
2373    echo "IGCM_sys_ncflint : ncflint error"
2374    IGCM_debug_Exit "ncflint"
2375  fi
2376
2377  IGCM_debug_PopStack "IGCM_sys_ncflint"
2378}
2379
2380#D-#==================================================
2381#D-function IGCM_sys_ncks
2382#D-* Purpose: encapsulate ncks call so as to manage error code and retry
2383#D-* Examples:
2384#D-
2385function IGCM_sys_ncks {
2386  IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
2387  if ( $DEBUG_sys ) ; then
2388    echo "IGCM_sys_ncks :" $@
2389  fi
2390
2391  typeset NB_ESSAI DELAI status i
2392  # number of tentative
2393  NB_ESSAI=3
2394  # time delay between tentative
2395  DELAI=2
2396
2397  i=0
2398  while [ $i -lt $NB_ESSAI ] ; do
2399    ncks $@ > /tmp/out_command.$$ 2>&1
2400    status=$?
2401    if [ ${status} -gt 0 ] ; then
2402      IGCM_debug_Print 2 "IGCM_sys_ncks : error code ${status}"
2403      cat /tmp/out_command.$$
2404      \rm /tmp/out_command.$$
2405      IGCM_debug_Print 2 "IGCM_sys_ncks : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2406      sleep $DELAI
2407    else
2408      \rm /tmp/out_command.$$
2409      break
2410    fi
2411    (( i = i + 1 ))
2412  done
2413
2414  if [ ${status} -gt 0 ] ; then
2415    echo "IGCM_sys_ncks : ncks error"
2416    IGCM_debug_Exit "ncks"
2417  fi
2418
2419  IGCM_debug_PopStack "IGCM_sys_ncks"
2420}
2421
2422#D-#==================================================
2423#D-function IGCM_sys_ncpdq
2424#D-* Purpose: encapsulate ncpdq call so as to manage error code and retry
2425#D-* Examples:
2426#D-
2427function IGCM_sys_ncpdq {
2428  IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
2429  if ( $DEBUG_sys ) ; then
2430    echo "IGCM_sys_ncpdq :" $@
2431  fi
2432
2433  typeset NB_ESSAI DELAI status i
2434  # number of tentative
2435  NB_ESSAI=3
2436  # time delay between tentative
2437  DELAI=2
2438
2439  i=0
2440  while [ $i -lt $NB_ESSAI ] ; do
2441    ncpdq $@ > /tmp/out_command.$$ 2>&1
2442    status=$?
2443    if [ ${status} -gt 0 ] ; then
2444      IGCM_debug_Print 2 "IGCM_sys_ncpdq : error code ${status}"
2445      cat /tmp/out_command.$$
2446      \rm /tmp/out_command.$$
2447      IGCM_debug_Print 2 "IGCM_sys_ncpdq : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2448      sleep $DELAI
2449    else
2450      \rm /tmp/out_command.$$
2451      break
2452    fi
2453    (( i = i + 1 ))
2454  done
2455
2456  if [ ${status} -gt 0 ] ; then
2457    echo "IGCM_sys_ncpdq : ncpdq error"
2458    IGCM_debug_Exit "ncpdq"
2459  fi
2460
2461  IGCM_debug_PopStack "IGCM_sys_ncpdq"
2462}
2463
2464#D-#==================================================
2465#D-function IGCM_sys_ncra
2466#D-* Purpose: encapsulate ncra call so as to manage error code and retry
2467#D-* Examples:
2468#D-
2469function IGCM_sys_ncra {
2470  IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
2471  if ( $DEBUG_sys ) ; then
2472    echo "IGCM_sys_ncra :" $@
2473  fi
2474
2475  typeset NB_ESSAI DELAI status i
2476  # number of tentative
2477  NB_ESSAI=3
2478  # time delay between tentative
2479  DELAI=2
2480
2481  i=0
2482  while [ $i -lt $NB_ESSAI ] ; do
2483    ncra $@ > /tmp/out_command.$$ 2>&1
2484    status=$?
2485    if [ ${status} -gt 0 ] ; then
2486      IGCM_debug_Print 2 "IGCM_sys_ncra : error code ${status}"
2487      cat /tmp/out_command.$$
2488      \rm /tmp/out_command.$$
2489      IGCM_debug_Print 2 "IGCM_sys_ncra : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2490      sleep $DELAI
2491    else
2492      \rm /tmp/out_command.$$
2493      break
2494    fi
2495    (( i = i + 1 ))
2496  done
2497
2498  if [ ${status} -gt 0 ] ; then
2499    echo "IGCM_sys_ncra : ncra error"
2500    IGCM_debug_Exit "ncra"
2501  fi
2502
2503  IGCM_debug_PopStack "IGCM_sys_ncra"
2504}
2505
2506#D-#==================================================
2507#D-function IGCM_sys_ncrcat
2508#D-* Purpose: encapsulate ncrcat call so as to manage error code and retry
2509#D-* Examples:
2510#D-
2511function IGCM_sys_ncrcat {
2512  IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
2513  if ( $DEBUG_sys ) ; then
2514    echo "IGCM_sys_ncrcat :" $@
2515  fi
2516
2517  typeset NB_ESSAI DELAI status i lastArg
2518  # number of tentative
2519  NB_ESSAI=3
2520  # time delay between tentative
2521  DELAI=2
2522
2523  i=0
2524  while [ $i -lt $NB_ESSAI ] ; do
2525    ncrcat $@ > /tmp/out_command.$$ 2>&1
2526    status=$?
2527    if [ ${status} -gt 0 ] ; then
2528      IGCM_debug_Print 2 "IGCM_sys_ncrcat : error code ${status}"
2529      cat /tmp/out_command.$$
2530      \rm /tmp/out_command.$$
2531      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2532      sleep $DELAI
2533    elif [ ! "X$( grep "WARNING Intra-file non-monotonicity" /tmp/out_command.$$ )" = "X" ] ; then
2534      IGCM_debug_Print 2 "IGCM_sys_ncrcat : WARNING Intra-file non-monotonicity"
2535      cat /tmp/out_command.$$
2536      # remove files having corrupted time axis
2537      eval lastArg=\${$#}
2538      IGCM_debug_Print 2 "IGCM_sys_ncrcat : Delete ${lastArg}"
2539      \rm ${lastArg}
2540      \rm /tmp/out_command.$$
2541      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2542      sleep $DELAI
2543    else
2544      \rm /tmp/out_command.$$
2545      break
2546    fi
2547    (( i = i + 1 ))
2548  done
2549
2550  if [ ${status} -gt 0 ] ; then
2551    echo "IGCM_sys_ncrcat : ncrcat error"
2552    #IGCM_debug_Exit "ncrcat"
2553  fi
2554
2555  IGCM_debug_PopStack "IGCM_sys_ncrcat"
2556}
2557
2558#D-#==================================================
2559#D-function IGCM_sys_ncrename
2560#D-* Purpose: encapsulate ncrename call so as to manage error code and retry
2561#D-* Examples:
2562#D-
2563function IGCM_sys_ncrename {
2564  IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
2565  if ( $DEBUG_sys ) ; then
2566    echo "IGCM_sys_ncrename :" $@
2567  fi
2568
2569  typeset NB_ESSAI DELAI status i
2570  # number of tentative
2571  NB_ESSAI=3
2572  # time delay between tentative
2573  DELAI=2
2574
2575  i=0
2576  while [ $i -lt $NB_ESSAI ] ; do
2577    ncrename $@ > /tmp/out_command.$$ 2>&1
2578    status=$?
2579    if [ ${status} -gt 0 ] ; then
2580      IGCM_debug_Print 2 "IGCM_sys_ncrename : error code ${status}"
2581      cat /tmp/out_command.$$
2582      \rm /tmp/out_command.$$
2583      IGCM_debug_Print 2 "IGCM_sys_ncrename : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2584      sleep $DELAI
2585    else
2586      \rm /tmp/out_command.$$
2587      break
2588    fi
2589    (( i = i + 1 ))
2590  done
2591
2592  if [ ${status} -gt 0 ] ; then
2593    echo "IGCM_sys_ncrename : ncrename error"
2594    IGCM_debug_Exit "ncrename"
2595  fi
2596
2597  IGCM_debug_PopStack "IGCM_sys_ncrename"
2598}
2599
2600#D-#==================================================
2601#D-function IGCM_sys_ncwa
2602#D-* Purpose: encapsulate ncwa call so as to manage error code and retry
2603#D-* Examples:
2604#D-
2605function IGCM_sys_ncwa {
2606  IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
2607  if ( $DEBUG_sys ) ; then
2608    echo "IGCM_sys_ncwa :" $@
2609  fi
2610
2611  typeset NB_ESSAI DELAI status i
2612  # number of tentative
2613  NB_ESSAI=3
2614  # time delay between tentative
2615  DELAI=2
2616
2617  i=0
2618  while [ $i -lt $NB_ESSAI ] ; do
2619    ncwa $@ > /tmp/out_command.$$ 2>&1
2620    status=$?
2621    if [ ${status} -gt 0 ] ; then
2622      IGCM_debug_Print 2 "IGCM_sys_ncwa : error code ${status}"
2623      cat /tmp/out_command.$$
2624      \rm /tmp/out_command.$$
2625      IGCM_debug_Print 2 "IGCM_sys_ncwa : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2626      sleep $DELAI
2627    else
2628      \rm /tmp/out_command.$$
2629      break
2630    fi
2631    (( i = i + 1 ))
2632  done
2633
2634  if [ ${status} -gt 0 ] ; then
2635    echo "IGCM_sys_ncwa : ncwa error"
2636    IGCM_debug_Exit "ncwa"
2637  fi
2638
2639  IGCM_debug_PopStack "IGCM_sys_ncwa"
2640}
2641
2642##############################################################
2643# CDO OPERATOR
2644
2645#D-#==================================================
2646#D-function IGCM_sys_cdo
2647#D-* Purpose: encapsulate cdo call so as to manage error code and retry
2648#D-* Examples:
2649#D-
2650function IGCM_sys_cdo {
2651  IGCM_debug_PushStack "IGCM_sys_cdo" -- $@
2652  if ( $DEBUG_sys ) ; then
2653    echo "IGCM_sys_cdo :" $@
2654  fi
2655
2656  typeset status
2657
2658  \cdo $@ > /tmp/out_command.$$ 2>&1
2659  status=$?
2660  if [ ${status} -gt 0 ] ; then
2661    echo "IGCM_sys_cdo : error code ${status}"
2662    cat /tmp/out_command.$$
2663    \rm /tmp/out_command.$$
2664    IGCM_debug_PopStack "IGCM_sys_cdo"
2665    return 1
2666  else
2667    IGCM_debug_PopStack "IGCM_sys_cdo"
2668    return 0
2669  fi
2670
2671  IGCM_debug_PopStack "IGCM_sys_cdo"
2672}
Note: See TracBrowser for help on using the repository browser.