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

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

Bugfix for RunChecker? on Ada :
Skip the first and the last two lines of llq output when looking for running jobs (#131).

  • 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  IGCM_debug_Print 1 "set LD_LIBRARY_PATH=${LD_LIBRARY_PATH}"
1810
1811  export MP_STDOUTMODE=combined
1812  IGCM_debug_Print 1 "set MP_STDOUTMODE=${MP_STDOUTMODE}"
1813
1814  IGCM_debug_PopStack "IGCM_sys_activ_variables"
1815}
1816
1817############################################################
1818# Desactivate Running Environnment Variables
1819
1820#D-#==================================================
1821#D-function IGCM_sys_desactiv_variables
1822#D-* Purpose: unset environement variables after execution
1823#D-* Examples:
1824#D-
1825function IGCM_sys_desactiv_variables {
1826  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1827  if ( $DEBUG_sys ) ; then
1828    echo "IGCM_sys_desactiv_variables"
1829  fi
1830# --------------------------------------------------------------------
1831#D- MPI specifications
1832# --------------------------------------------------------------------
1833
1834# --------------------------------------------------------------------
1835#D- Other specifications
1836# --------------------------------------------------------------------
1837
1838  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1839}
1840
1841############################################################
1842# Build MPI/OMP scripts run file (dummy function)
1843
1844#D-#==================================================
1845#D-function IGCM_sys_build_run_file
1846#D-* Purpose: build run file (deprecated)
1847#D-* Examples:
1848#D-
1849function IGCM_sys_build_run_file {
1850
1851  IGCM_debug_Print 3 " dummy function : IGCM_sys_build_run_file "
1852
1853}
1854
1855############################################################
1856# Build MPI/OMP scripts
1857
1858#D-#==================================================
1859#D-function IGCM_sys_build_execution_scripts
1860#D-* Purpose: build execution scripts to be launch by ${HOST_MPIRUN_COMMAND}
1861#D-* Examples:
1862#D-
1863function IGCM_sys_build_execution_scripts
1864{
1865  IGCM_debug_PushStack "IGCM_sys_build_execution_scripts" $@
1866  if ( $DEBUG_sys ) ; then
1867    echo "IGCM_sys_build_execution_scripts " $@
1868  fi
1869
1870  EXECUTION=${HOST_MPIRUN_COMMAND}
1871
1872  if ( ${OK_PARA_MPMD} ) ; then
1873
1874    if [ -f run_file ] ; then
1875      IGCM_sys_Rm -f run_file
1876    fi
1877    touch run_file
1878
1879# run_file construction
1880
1881# Then first loop on the components for the coupler ie oasis
1882
1883### the coupler ie oasis must be the first one
1884    for comp in ${config_ListOfComponents[*]} ; do
1885
1886      eval ExeNameIn=\${config_Executable_${comp}[0]}
1887      eval ExeNameOut=\${config_Executable_${comp}[1]}
1888
1889      # for CPL component only
1890      if [ "X${comp}" = "XCPL" ] ; then
1891
1892        eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1893        eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1894
1895        if ( ${OK_PARA_MPI} ) ; then
1896          (( mpi_count = 1 ))
1897          until [ ${mpi_count} -gt ${comp_proc_mpi_loc} ] ; do
1898            echo "./${ExeNameOut}" >> run_file
1899            (( mpi_count = mpi_count + 1 ))
1900          done
1901        else
1902          echo "./${ExeNameOut} " >> run_file
1903        fi
1904      fi
1905    done
1906
1907# Then second loop on the components
1908
1909    for comp in ${config_ListOfComponents[*]} ; do
1910
1911      eval ExeNameIn=\${config_Executable_${comp}[0]}
1912      eval ExeNameOut=\${config_Executable_${comp}[1]}
1913
1914      # Only if we really have an executable for the component and not the coupler ie oasis:
1915      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${comp}" != "XCPL" ] ) ; then
1916
1917        eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1918        eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1919
1920        if ( ${OK_PARA_MPI} ) ; then
1921          (( mpi_count = 1 ))
1922          until [ ${mpi_count} -gt ${comp_proc_mpi_loc} ] ; do
1923            echo "./${ExeNameOut}" >> run_file
1924            (( mpi_count = mpi_count + 1 ))
1925          done
1926        else
1927            echo "./${ExeNameOut} " >> run_file
1928        fi
1929      fi
1930    done
1931
1932    EXECUTION="${HOST_MPIRUN_COMMAND} -pgmmodel mpmd -cmdfile ./run_file"
1933
1934    IGCM_sys_Chmod u+x run_file
1935    if ( $DEBUG_sys ) ; then
1936      echo "run_file contains : "
1937      cat run_file
1938    fi
1939
1940  else # Only one executable. launch it.
1941
1942    for comp in ${config_ListOfComponents[*]} ; do
1943
1944      # Only if we really have an executable for the component :
1945      eval ExeNameOut=\${config_Executable_${comp}[1]}
1946      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${ExeNameOut}" != "Xinca.dat" ] ) ; then
1947
1948        if ( ${OK_PARA_OMP} ) ; then
1949          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1950          export KMP_STACKSIZE=200m
1951          #export KMP_LIBRARY=turnaround
1952          #echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
1953          #echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
1954          #echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
1955        fi
1956
1957        EXECUTION="${HOST_MPIRUN_COMMAND} ./${ExeNameOut}"
1958      fi
1959
1960    done
1961
1962  fi
1963
1964  IGCM_debug_Print 1 "sys ada : execution command is "
1965  IGCM_debug_Print 1 "$EXECUTION"
1966
1967  IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
1968}
1969
1970#D-#==================================================
1971#D-function IGCM_sys_check_path
1972#D-* Purpose: check that RUN_DIR_PATH that will be removed on some machine
1973#D-* do not point to an important use directory. Stop immediately in that case.
1974#D-* Examples:
1975#D-
1976function IGCM_sys_check_path {
1977  IGCM_debug_PushStack "IGCM_sys_check_path"
1978  if ( $DEBUG_sys ) ; then
1979    echo "IGCM_sys_check_path"
1980  fi
1981
1982  if ( [ X${RUN_DIR_PATH} = X${HOME} ] || [ X${RUN_DIR_PATH} = X${WORKDIR} ] || [ X${RUN_DIR_PATH} = X${HOMEGAYA} ] ) ; then
1983    IGCM_debug_Print 1 "Variable RUN_DIR_PATH is pointing to an important directory : ${RUN_DIR_PATH}"
1984    IGCM_debug_Print 1 "Please check the RUN_DIR_PATH definition in your Job : Job_${config_UserChoices_JobName}"
1985    IGCM_debug_Exit "This will stop the job"
1986  fi
1987  IGCM_debug_PopStack "IGCM_sys_check_path"
1988}
1989
1990#D-#==================================================
1991#D-function IGCM_sys_check_quota
1992#D-* Purpose: check user quota. Stop the simulation if quota above 90%
1993#D-* Examples:
1994#D-
1995function IGCM_sys_check_quota {
1996  IGCM_debug_PushStack "IGCM_sys_check_quota"
1997  if ( $DEBUG_sys ) ; then
1998    echo "IGCM_sys_check_quota"
1999  fi
2000  # Limit of quota (in %)
2001  limit_quota=90
2002
2003  # Check of the volume
2004  volume_quota=$(quota_u -w 2>/dev/null| grep 'Quota soft' | gawk '{print $5}')
2005  if [ ! X${volume_quota} = X ] ; then
2006    quota_volume=${volume_quota%%\%}
2007#    echo $quota_volume
2008    if [ $(echo "${quota_volume} > ${limit_quota}" | bc) -eq 1 ] ; then
2009      IGCM_debug_Print 1 "Please, check your quota of volume on workgpfs"
2010      IGCM_debug_Print 1 "${quota_volume}% of your quota is used"
2011      IGCM_debug_Print 1 "Use the quota_u -w command to check"
2012      IGCM_debug_Print 1 "You must have more than 10% available to run"
2013      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
2014      IGCM_debug_Verif_Exit
2015    fi
2016
2017  fi
2018  IGCM_debug_PopStack "IGCM_sys_check_quota"
2019}
2020
2021#D-#==================================================
2022#D-function IGCM_sys_GetJobID
2023#D-* Purpose: Check if job_name is currently
2024#D-  running or in queue
2025#D-* Examples: IGCM_sys_GetJobID ${JobName} NbRun
2026#D-
2027function IGCM_sys_GetJobID {
2028  IGCM_debug_PushStack "IGCM_sys_GetJobID"
2029  if ( $DEBUG_sys ) ; then
2030    echo "IGCM_sys_GetJobID"
2031  fi
2032
2033  # Print only the full (-W) JobID (%id) and JobName (%jn)
2034  ID=$( llq -u $2 -W -f %id %jn | \
2035        gawk -v JobName=$1 '( $NF ~ JobName ) { print $1 }' )
2036
2037  eval ${3}=${ID}
2038
2039  IGCM_debug_PopStack "IGCM_sys_GetJobID"
2040}
2041
2042#D-#==================================================
2043#D-function IGCM_sys_CountJobInQueue
2044#D-* Purpose: Check if job_name is currently
2045#D-  running or in queue
2046#D-* Examples: IGCM_sys_CountJobInQueue ${JobName} NbRun
2047#D-
2048function IGCM_sys_CountJobInQueue {
2049  IGCM_debug_PushStack "IGCM_sys_CountJobInQueue"
2050  if ( $DEBUG_sys ) ; then
2051    echo "IGCM_sys_CountJobInQueue"
2052  fi
2053
2054  # Print only the full (-W) JobName (%jn)
2055  NbRun=$( llq -W -f %jn | grep -c "$1" )
2056
2057  eval ${2}=${NbRun}
2058
2059  IGCM_debug_PopStack "IGCM_sys_CountJobInQueue"
2060}
2061
2062#D-#==================================================
2063#D-function IGCM_sys_ListJobInQueue
2064#D-* Purpose: Check if job_name is currently
2065#D-  running or in queue
2066#D-* Examples: IGCM_sys_ListJobInQueue ${User} JobNameList
2067#D-
2068function IGCM_sys_ListJobInQueue {
2069  IGCM_debug_PushStack "IGCM_sys_ListJobInQueue"
2070  if ( $DEBUG_sys ) ; then
2071    echo "IGCM_sys_ListJobInQueue"
2072  fi
2073
2074  # With -W option, column width is as large as necessary
2075  set -A JobList $( llq -u $1 -W -f %jn | head -n -2 | tail -n +3 | \
2076                    gawk '( $1 != /TS/      && \
2077                            $1 !~ /PACK/    && \
2078                            $1 !~ /REBUILD/ && \
2079                            $1 !~ /pack/ )     \
2080                          { print $1 }' | sed -e "s/\(.*\)\.[0-9]*/\1/" )
2081
2082  eval set -A ${2} ${JobList[*]}
2083
2084  IGCM_debug_PopStack "IGCM_sys_ListJobInQueue"
2085}
2086
2087##############################################################
2088# NCO OPERATOR
2089
2090#D-#==================================================
2091#D-function IGCM_sys_ncap2
2092#D-* Purpose: encapsulate ncap2 call so as to manage error code and retry
2093#D-* Examples:
2094#D-
2095function IGCM_sys_ncap2 {
2096  IGCM_debug_PushStack "IGCM_sys_ncap2" -- $@
2097  if ( $DEBUG_sys ) ; then
2098    echo "IGCM_sys_ncap2 :" $@
2099  fi
2100
2101  typeset NB_ESSAI DELAI status i
2102  # number of tentative
2103  NB_ESSAI=3
2104  # time delay between tentative
2105  DELAI=2
2106
2107  i=0
2108  while [ $i -lt $NB_ESSAI ] ; do
2109    ncap2 "$@" > /tmp/out_command.$$ 2>&1
2110    status=$?
2111    if [ ${status} -gt 0 ] ; then
2112      IGCM_debug_Print 2 "IGCM_sys_ncap2 : error code ${status}"
2113      cat /tmp/out_command.$$
2114      \rm /tmp/out_command.$$
2115      IGCM_debug_Print 2 "IGCM_sys_ncap2 : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2116      sleep $DELAI
2117    else
2118      \rm /tmp/out_command.$$
2119      break
2120    fi
2121    (( i = i + 1 ))
2122  done
2123
2124  if [ ${status} -gt 0 ] ; then
2125    echo "IGCM_sys_ncap2 : ncap2 error"
2126    IGCM_debug_Exit "ncap2"
2127  fi
2128
2129  IGCM_debug_PopStack "IGCM_sys_ncap2"
2130}
2131
2132#D-#==================================================
2133#D-function IGCM_sys_ncatted
2134#D-* Purpose: encapsulate ncatted call so as to manage error code and retry
2135#D-* Examples:
2136#D-
2137function IGCM_sys_ncatted {
2138  IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
2139  if ( $DEBUG_sys ) ; then
2140    echo "IGCM_sys_ncatted :" $@
2141  fi
2142
2143  typeset NB_ESSAI DELAI status i
2144  # number of tentative
2145  NB_ESSAI=3
2146  # time delay between tentative
2147  DELAI=2
2148
2149  i=0
2150  while [ $i -lt $NB_ESSAI ] ; do
2151    ncatted "$@" > /tmp/out_command.$$ 2>&1
2152    status=$?
2153    if [ ${status} -gt 0 ] ; then
2154      IGCM_debug_Print 2 "IGCM_sys_ncatted : error code ${status}"
2155      cat /tmp/out_command.$$
2156      \rm /tmp/out_command.$$
2157      IGCM_debug_Print 2 "IGCM_sys_ncatted : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2158      sleep $DELAI
2159    else
2160      \rm /tmp/out_command.$$
2161      break
2162    fi
2163    (( i = i + 1 ))
2164  done
2165
2166  if [ ${status} -gt 0 ] ; then
2167    echo "IGCM_sys_ncatted : ncatted error"
2168    IGCM_debug_Exit "ncatted"
2169  fi
2170
2171  IGCM_debug_PopStack "IGCM_sys_ncatted"
2172}
2173
2174#D-#==================================================
2175#D-function IGCM_sys_ncbo
2176#D-* Purpose: encapsulate ncbo call so as to manage error code and retry
2177#D-* Examples:
2178#D-
2179function IGCM_sys_ncbo {
2180  IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
2181  if ( $DEBUG_sys ) ; then
2182    echo "IGCM_sys_ncbo :" $@
2183  fi
2184
2185  typeset NB_ESSAI DELAI status i
2186  # number of tentative
2187  NB_ESSAI=3
2188  # time delay between tentative
2189  DELAI=2
2190
2191  i=0
2192  while [ $i -lt $NB_ESSAI ] ; do
2193    ncbo $@ > /tmp/out_command.$$ 2>&1
2194    status=$?
2195    if [ ${status} -gt 0 ] ; then
2196      IGCM_debug_Print 2 "IGCM_sys_ncbo : error code ${status}"
2197      cat /tmp/out_command.$$
2198      \rm /tmp/out_command.$$
2199      IGCM_debug_Print 2 "IGCM_sys_ncbo : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2200      sleep $DELAI
2201    else
2202      \rm /tmp/out_command.$$
2203      break
2204    fi
2205    (( i = i + 1 ))
2206  done
2207
2208  if [ ${status} -gt 0 ] ; then
2209    echo "IGCM_sys_ncbo : ncbo error"
2210    IGCM_debug_Exit "ncbo"
2211  fi
2212
2213  IGCM_debug_PopStack "IGCM_sys_ncbo"
2214}
2215
2216#D-#==================================================
2217#D-function IGCM_sys_ncdif
2218#D-* Purpose: encapsulate ncdiff call so as to manage error code and retry
2219#D-* Examples:
2220#D-
2221function IGCM_sys_ncdiff {
2222  IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
2223  if ( $DEBUG_sys ) ; then
2224    echo "IGCM_sys_ncdiff :" $@
2225  fi
2226
2227  typeset NB_ESSAI DELAI status i
2228  # number of tentative
2229  NB_ESSAI=3
2230  # time delay between tentative
2231  DELAI=2
2232
2233  i=0
2234  while [ $i -lt $NB_ESSAI ] ; do
2235    ncdiff $@ > /tmp/out_command.$$ 2>&1
2236    status=$?
2237    if [ ${status} -gt 0 ] ; then
2238      IGCM_debug_Print 2 "IGCM_sys_ncdiff : error code ${status}"
2239      cat /tmp/out_command.$$
2240      \rm /tmp/out_command.$$
2241      IGCM_debug_Print 2 "IGCM_sys_ncdiff : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2242      sleep $DELAI
2243    else
2244      \rm /tmp/out_command.$$
2245      break
2246    fi
2247    (( i = i + 1 ))
2248  done
2249
2250  if [ ${status} -gt 0 ] ; then
2251    echo "IGCM_sys_ncdiff : ncdiff error"
2252    IGCM_debug_Exit "ncdiff"
2253  fi
2254
2255  IGCM_debug_PopStack "IGCM_sys_ncdiff"
2256}
2257
2258#D-#==================================================
2259#D-function IGCM_sys_ncea
2260#D-* Purpose: encapsulate ncea call so as to manage error code and retry
2261#D-* Examples:
2262#D-
2263function IGCM_sys_ncea {
2264  IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
2265  if ( $DEBUG_sys ) ; then
2266    echo "IGCM_sys_ncea :" $@
2267  fi
2268
2269  typeset NB_ESSAI DELAI status i
2270  # number of tentative
2271  NB_ESSAI=3
2272  # time delay between tentative
2273  DELAI=2
2274
2275  i=0
2276  while [ $i -lt $NB_ESSAI ] ; do
2277    ncea $@ > /tmp/out_command.$$ 2>&1
2278    status=$?
2279    if [ ${status} -gt 0 ] ; then
2280      IGCM_debug_Print 2 "IGCM_sys_ncea : error code ${status}"
2281      cat /tmp/out_command.$$
2282      \rm /tmp/out_command.$$
2283      IGCM_debug_Print 2 "IGCM_sys_ncea : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2284      sleep $DELAI
2285    else
2286      \rm /tmp/out_command.$$
2287      break
2288    fi
2289    (( i = i + 1 ))
2290  done
2291
2292  if [ ${status} -gt 0 ] ; then
2293    echo "IGCM_sys_ncea : ncea error"
2294    IGCM_debug_Exit "ncea"
2295  fi
2296
2297  IGCM_debug_PopStack "IGCM_sys_ncea"
2298}
2299
2300#D-#==================================================
2301#D-function IGCM_sys_ncecat
2302#D-* Purpose: encapsulate ncecat call so as to manage error code and retry
2303#D-* Examples:
2304#D-
2305function IGCM_sys_ncecat {
2306  IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
2307  if ( $DEBUG_sys ) ; then
2308    echo "IGCM_sys_ncecat :" $@
2309  fi
2310
2311  typeset NB_ESSAI DELAI status i
2312  # number of tentative
2313  NB_ESSAI=3
2314  # time delay between tentative
2315  DELAI=2
2316
2317  i=0
2318  while [ $i -lt $NB_ESSAI ] ; do
2319    ncecat $@ > /tmp/out_command.$$ 2>&1
2320    status=$?
2321    if [ ${status} -gt 0 ] ; then
2322      IGCM_debug_Print 2 "IGCM_sys_ncecat : error code ${status}"
2323      cat /tmp/out_command.$$
2324      \rm /tmp/out_command.$$
2325      IGCM_debug_Print 2 "IGCM_sys_ncecat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2326      sleep $DELAI
2327    else
2328      \rm /tmp/out_command.$$
2329      break
2330    fi
2331    (( i = i + 1 ))
2332  done
2333
2334  if [ ${status} -gt 0 ] ; then
2335    echo "IGCM_sys_ncecat : ncecat error"
2336    IGCM_debug_Exit "ncecat"
2337  fi
2338
2339  IGCM_debug_PopStack "IGCM_sys_ncecat"
2340}
2341
2342#D-#==================================================
2343#D-function IGCM_sys_ncflint
2344#D-* Purpose: encapsulate ncflint call so as to manage error code and retry
2345#D-* Examples:
2346#D-
2347function IGCM_sys_ncflint {
2348  IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
2349  if ( $DEBUG_sys ) ; then
2350    echo "IGCM_sys_ncflint :" $@
2351  fi
2352
2353  typeset NB_ESSAI DELAI status i
2354  # number of tentative
2355  NB_ESSAI=3
2356  # time delay between tentative
2357  DELAI=2
2358
2359  i=0
2360  while [ $i -lt $NB_ESSAI ] ; do
2361    ncflint $@ > /tmp/out_command.$$ 2>&1
2362    status=$?
2363    if [ ${status} -gt 0 ] ; then
2364      IGCM_debug_Print 2 "IGCM_sys_ncflint : error code ${status}"
2365      cat /tmp/out_command.$$
2366      \rm /tmp/out_command.$$
2367      IGCM_debug_Print 2 "IGCM_sys_ncflint : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2368      sleep $DELAI
2369    else
2370      \rm /tmp/out_command.$$
2371      break
2372    fi
2373    (( i = i + 1 ))
2374  done
2375
2376  if [ ${status} -gt 0 ] ; then
2377    echo "IGCM_sys_ncflint : ncflint error"
2378    IGCM_debug_Exit "ncflint"
2379  fi
2380
2381  IGCM_debug_PopStack "IGCM_sys_ncflint"
2382}
2383
2384#D-#==================================================
2385#D-function IGCM_sys_ncks
2386#D-* Purpose: encapsulate ncks call so as to manage error code and retry
2387#D-* Examples:
2388#D-
2389function IGCM_sys_ncks {
2390  IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
2391  if ( $DEBUG_sys ) ; then
2392    echo "IGCM_sys_ncks :" $@
2393  fi
2394
2395  typeset NB_ESSAI DELAI status i
2396  # number of tentative
2397  NB_ESSAI=3
2398  # time delay between tentative
2399  DELAI=2
2400
2401  i=0
2402  while [ $i -lt $NB_ESSAI ] ; do
2403    ncks $@ > /tmp/out_command.$$ 2>&1
2404    status=$?
2405    if [ ${status} -gt 0 ] ; then
2406      IGCM_debug_Print 2 "IGCM_sys_ncks : error code ${status}"
2407      cat /tmp/out_command.$$
2408      \rm /tmp/out_command.$$
2409      IGCM_debug_Print 2 "IGCM_sys_ncks : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2410      sleep $DELAI
2411    else
2412      \rm /tmp/out_command.$$
2413      break
2414    fi
2415    (( i = i + 1 ))
2416  done
2417
2418  if [ ${status} -gt 0 ] ; then
2419    echo "IGCM_sys_ncks : ncks error"
2420    IGCM_debug_Exit "ncks"
2421  fi
2422
2423  IGCM_debug_PopStack "IGCM_sys_ncks"
2424}
2425
2426#D-#==================================================
2427#D-function IGCM_sys_ncpdq
2428#D-* Purpose: encapsulate ncpdq call so as to manage error code and retry
2429#D-* Examples:
2430#D-
2431function IGCM_sys_ncpdq {
2432  IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
2433  if ( $DEBUG_sys ) ; then
2434    echo "IGCM_sys_ncpdq :" $@
2435  fi
2436
2437  typeset NB_ESSAI DELAI status i
2438  # number of tentative
2439  NB_ESSAI=3
2440  # time delay between tentative
2441  DELAI=2
2442
2443  i=0
2444  while [ $i -lt $NB_ESSAI ] ; do
2445    ncpdq $@ > /tmp/out_command.$$ 2>&1
2446    status=$?
2447    if [ ${status} -gt 0 ] ; then
2448      IGCM_debug_Print 2 "IGCM_sys_ncpdq : error code ${status}"
2449      cat /tmp/out_command.$$
2450      \rm /tmp/out_command.$$
2451      IGCM_debug_Print 2 "IGCM_sys_ncpdq : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2452      sleep $DELAI
2453    else
2454      \rm /tmp/out_command.$$
2455      break
2456    fi
2457    (( i = i + 1 ))
2458  done
2459
2460  if [ ${status} -gt 0 ] ; then
2461    echo "IGCM_sys_ncpdq : ncpdq error"
2462    IGCM_debug_Exit "ncpdq"
2463  fi
2464
2465  IGCM_debug_PopStack "IGCM_sys_ncpdq"
2466}
2467
2468#D-#==================================================
2469#D-function IGCM_sys_ncra
2470#D-* Purpose: encapsulate ncra call so as to manage error code and retry
2471#D-* Examples:
2472#D-
2473function IGCM_sys_ncra {
2474  IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
2475  if ( $DEBUG_sys ) ; then
2476    echo "IGCM_sys_ncra :" $@
2477  fi
2478
2479  typeset NB_ESSAI DELAI status i
2480  # number of tentative
2481  NB_ESSAI=3
2482  # time delay between tentative
2483  DELAI=2
2484
2485  i=0
2486  while [ $i -lt $NB_ESSAI ] ; do
2487    ncra $@ > /tmp/out_command.$$ 2>&1
2488    status=$?
2489    if [ ${status} -gt 0 ] ; then
2490      IGCM_debug_Print 2 "IGCM_sys_ncra : error code ${status}"
2491      cat /tmp/out_command.$$
2492      \rm /tmp/out_command.$$
2493      IGCM_debug_Print 2 "IGCM_sys_ncra : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2494      sleep $DELAI
2495    else
2496      \rm /tmp/out_command.$$
2497      break
2498    fi
2499    (( i = i + 1 ))
2500  done
2501
2502  if [ ${status} -gt 0 ] ; then
2503    echo "IGCM_sys_ncra : ncra error"
2504    IGCM_debug_Exit "ncra"
2505  fi
2506
2507  IGCM_debug_PopStack "IGCM_sys_ncra"
2508}
2509
2510#D-#==================================================
2511#D-function IGCM_sys_ncrcat
2512#D-* Purpose: encapsulate ncrcat call so as to manage error code and retry
2513#D-* Examples:
2514#D-
2515function IGCM_sys_ncrcat {
2516  IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
2517  if ( $DEBUG_sys ) ; then
2518    echo "IGCM_sys_ncrcat :" $@
2519  fi
2520
2521  typeset NB_ESSAI DELAI status i lastArg
2522  # number of tentative
2523  NB_ESSAI=3
2524  # time delay between tentative
2525  DELAI=2
2526
2527  i=0
2528  while [ $i -lt $NB_ESSAI ] ; do
2529    ncrcat $@ > /tmp/out_command.$$ 2>&1
2530    status=$?
2531    if [ ${status} -gt 0 ] ; then
2532      IGCM_debug_Print 2 "IGCM_sys_ncrcat : error code ${status}"
2533      cat /tmp/out_command.$$
2534      \rm /tmp/out_command.$$
2535      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2536      sleep $DELAI
2537    elif [ ! "X$( grep "WARNING Intra-file non-monotonicity" /tmp/out_command.$$ )" = "X" ] ; then
2538      IGCM_debug_Print 2 "IGCM_sys_ncrcat : WARNING Intra-file non-monotonicity"
2539      cat /tmp/out_command.$$
2540      # remove files having corrupted time axis
2541      eval lastArg=\${$#}
2542      IGCM_debug_Print 2 "IGCM_sys_ncrcat : Delete ${lastArg}"
2543      \rm ${lastArg}
2544      \rm /tmp/out_command.$$
2545      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2546      sleep $DELAI
2547    else
2548      \rm /tmp/out_command.$$
2549      break
2550    fi
2551    (( i = i + 1 ))
2552  done
2553
2554  if [ ${status} -gt 0 ] ; then
2555    echo "IGCM_sys_ncrcat : ncrcat error"
2556    #IGCM_debug_Exit "ncrcat"
2557  fi
2558
2559  IGCM_debug_PopStack "IGCM_sys_ncrcat"
2560}
2561
2562#D-#==================================================
2563#D-function IGCM_sys_ncrename
2564#D-* Purpose: encapsulate ncrename call so as to manage error code and retry
2565#D-* Examples:
2566#D-
2567function IGCM_sys_ncrename {
2568  IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
2569  if ( $DEBUG_sys ) ; then
2570    echo "IGCM_sys_ncrename :" $@
2571  fi
2572
2573  typeset NB_ESSAI DELAI status i
2574  # number of tentative
2575  NB_ESSAI=3
2576  # time delay between tentative
2577  DELAI=2
2578
2579  i=0
2580  while [ $i -lt $NB_ESSAI ] ; do
2581    ncrename $@ > /tmp/out_command.$$ 2>&1
2582    status=$?
2583    if [ ${status} -gt 0 ] ; then
2584      IGCM_debug_Print 2 "IGCM_sys_ncrename : error code ${status}"
2585      cat /tmp/out_command.$$
2586      \rm /tmp/out_command.$$
2587      IGCM_debug_Print 2 "IGCM_sys_ncrename : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2588      sleep $DELAI
2589    else
2590      \rm /tmp/out_command.$$
2591      break
2592    fi
2593    (( i = i + 1 ))
2594  done
2595
2596  if [ ${status} -gt 0 ] ; then
2597    echo "IGCM_sys_ncrename : ncrename error"
2598    IGCM_debug_Exit "ncrename"
2599  fi
2600
2601  IGCM_debug_PopStack "IGCM_sys_ncrename"
2602}
2603
2604#D-#==================================================
2605#D-function IGCM_sys_ncwa
2606#D-* Purpose: encapsulate ncwa call so as to manage error code and retry
2607#D-* Examples:
2608#D-
2609function IGCM_sys_ncwa {
2610  IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
2611  if ( $DEBUG_sys ) ; then
2612    echo "IGCM_sys_ncwa :" $@
2613  fi
2614
2615  typeset NB_ESSAI DELAI status i
2616  # number of tentative
2617  NB_ESSAI=3
2618  # time delay between tentative
2619  DELAI=2
2620
2621  i=0
2622  while [ $i -lt $NB_ESSAI ] ; do
2623    ncwa $@ > /tmp/out_command.$$ 2>&1
2624    status=$?
2625    if [ ${status} -gt 0 ] ; then
2626      IGCM_debug_Print 2 "IGCM_sys_ncwa : error code ${status}"
2627      cat /tmp/out_command.$$
2628      \rm /tmp/out_command.$$
2629      IGCM_debug_Print 2 "IGCM_sys_ncwa : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2630      sleep $DELAI
2631    else
2632      \rm /tmp/out_command.$$
2633      break
2634    fi
2635    (( i = i + 1 ))
2636  done
2637
2638  if [ ${status} -gt 0 ] ; then
2639    echo "IGCM_sys_ncwa : ncwa error"
2640    IGCM_debug_Exit "ncwa"
2641  fi
2642
2643  IGCM_debug_PopStack "IGCM_sys_ncwa"
2644}
2645
2646##############################################################
2647# CDO OPERATOR
2648
2649#D-#==================================================
2650#D-function IGCM_sys_cdo
2651#D-* Purpose: encapsulate cdo call so as to manage error code and retry
2652#D-* Examples:
2653#D-
2654function IGCM_sys_cdo {
2655  IGCM_debug_PushStack "IGCM_sys_cdo" -- $@
2656  if ( $DEBUG_sys ) ; then
2657    echo "IGCM_sys_cdo :" $@
2658  fi
2659
2660  typeset status
2661
2662  \cdo $@ > /tmp/out_command.$$ 2>&1
2663  status=$?
2664  if [ ${status} -gt 0 ] ; then
2665    echo "IGCM_sys_cdo : error code ${status}"
2666    cat /tmp/out_command.$$
2667    \rm /tmp/out_command.$$
2668    IGCM_debug_PopStack "IGCM_sys_cdo"
2669    return 1
2670  else
2671    IGCM_debug_PopStack "IGCM_sys_cdo"
2672    return 0
2673  fi
2674
2675  IGCM_debug_PopStack "IGCM_sys_cdo"
2676}
Note: See TracBrowser for help on using the repository browser.