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

Last change on this file since 959 was 959, checked in by mafoipsl, 11 years ago

On ada, add export MP_STDOUTMODE=combined to combine multiple standard outputs in a human readable format. Tested with LMDZOR_v5 and IPSLCM5_v5 configurations on ada.

  • Property svn:keywords set to Revision Author Date
File size: 75.4 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 -f option, the full job name is given in the last column
2075  set -A JobList $( llq -u $1 -W -f %jn | gawk '( $1 != /TS/      && \
2076                                                  $1 !~ /PACK/    && \
2077                                                  $1 !~ /REBUILD/ && \
2078                                                  $1 !~ /pack/ )     \
2079                                                { print $1 }' | sed -e "s/\(.*\)\.[0-9]*/\1/" )
2080
2081  eval set -A ${2} ${JobList[*]}
2082
2083  IGCM_debug_PopStack "IGCM_sys_ListJobInQueue"
2084}
2085
2086##############################################################
2087# NCO OPERATOR
2088
2089#D-#==================================================
2090#D-function IGCM_sys_ncap2
2091#D-* Purpose: encapsulate ncap2 call so as to manage error code and retry
2092#D-* Examples:
2093#D-
2094function IGCM_sys_ncap2 {
2095  IGCM_debug_PushStack "IGCM_sys_ncap2" -- $@
2096  if ( $DEBUG_sys ) ; then
2097    echo "IGCM_sys_ncap2 :" $@
2098  fi
2099
2100  typeset NB_ESSAI DELAI status i
2101  # number of tentative
2102  NB_ESSAI=3
2103  # time delay between tentative
2104  DELAI=2
2105
2106  i=0
2107  while [ $i -lt $NB_ESSAI ] ; do
2108    ncap2 "$@" > /tmp/out_command.$$ 2>&1
2109    status=$?
2110    if [ ${status} -gt 0 ] ; then
2111      IGCM_debug_Print 2 "IGCM_sys_ncap2 : error code ${status}"
2112      cat /tmp/out_command.$$
2113      \rm /tmp/out_command.$$
2114      IGCM_debug_Print 2 "IGCM_sys_ncap2 : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2115      sleep $DELAI
2116    else
2117      \rm /tmp/out_command.$$
2118      break
2119    fi
2120    (( i = i + 1 ))
2121  done
2122
2123  if [ ${status} -gt 0 ] ; then
2124    echo "IGCM_sys_ncap2 : ncap2 error"
2125    IGCM_debug_Exit "ncap2"
2126  fi
2127
2128  IGCM_debug_PopStack "IGCM_sys_ncap2"
2129}
2130
2131#D-#==================================================
2132#D-function IGCM_sys_ncatted
2133#D-* Purpose: encapsulate ncatted call so as to manage error code and retry
2134#D-* Examples:
2135#D-
2136function IGCM_sys_ncatted {
2137  IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
2138  if ( $DEBUG_sys ) ; then
2139    echo "IGCM_sys_ncatted :" $@
2140  fi
2141
2142  typeset NB_ESSAI DELAI status i
2143  # number of tentative
2144  NB_ESSAI=3
2145  # time delay between tentative
2146  DELAI=2
2147
2148  i=0
2149  while [ $i -lt $NB_ESSAI ] ; do
2150    ncatted "$@" > /tmp/out_command.$$ 2>&1
2151    status=$?
2152    if [ ${status} -gt 0 ] ; then
2153      IGCM_debug_Print 2 "IGCM_sys_ncatted : error code ${status}"
2154      cat /tmp/out_command.$$
2155      \rm /tmp/out_command.$$
2156      IGCM_debug_Print 2 "IGCM_sys_ncatted : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2157      sleep $DELAI
2158    else
2159      \rm /tmp/out_command.$$
2160      break
2161    fi
2162    (( i = i + 1 ))
2163  done
2164
2165  if [ ${status} -gt 0 ] ; then
2166    echo "IGCM_sys_ncatted : ncatted error"
2167    IGCM_debug_Exit "ncatted"
2168  fi
2169
2170  IGCM_debug_PopStack "IGCM_sys_ncatted"
2171}
2172
2173#D-#==================================================
2174#D-function IGCM_sys_ncbo
2175#D-* Purpose: encapsulate ncbo call so as to manage error code and retry
2176#D-* Examples:
2177#D-
2178function IGCM_sys_ncbo {
2179  IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
2180  if ( $DEBUG_sys ) ; then
2181    echo "IGCM_sys_ncbo :" $@
2182  fi
2183
2184  typeset NB_ESSAI DELAI status i
2185  # number of tentative
2186  NB_ESSAI=3
2187  # time delay between tentative
2188  DELAI=2
2189
2190  i=0
2191  while [ $i -lt $NB_ESSAI ] ; do
2192    ncbo $@ > /tmp/out_command.$$ 2>&1
2193    status=$?
2194    if [ ${status} -gt 0 ] ; then
2195      IGCM_debug_Print 2 "IGCM_sys_ncbo : error code ${status}"
2196      cat /tmp/out_command.$$
2197      \rm /tmp/out_command.$$
2198      IGCM_debug_Print 2 "IGCM_sys_ncbo : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2199      sleep $DELAI
2200    else
2201      \rm /tmp/out_command.$$
2202      break
2203    fi
2204    (( i = i + 1 ))
2205  done
2206
2207  if [ ${status} -gt 0 ] ; then
2208    echo "IGCM_sys_ncbo : ncbo error"
2209    IGCM_debug_Exit "ncbo"
2210  fi
2211
2212  IGCM_debug_PopStack "IGCM_sys_ncbo"
2213}
2214
2215#D-#==================================================
2216#D-function IGCM_sys_ncdif
2217#D-* Purpose: encapsulate ncdiff call so as to manage error code and retry
2218#D-* Examples:
2219#D-
2220function IGCM_sys_ncdiff {
2221  IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
2222  if ( $DEBUG_sys ) ; then
2223    echo "IGCM_sys_ncdiff :" $@
2224  fi
2225
2226  typeset NB_ESSAI DELAI status i
2227  # number of tentative
2228  NB_ESSAI=3
2229  # time delay between tentative
2230  DELAI=2
2231
2232  i=0
2233  while [ $i -lt $NB_ESSAI ] ; do
2234    ncdiff $@ > /tmp/out_command.$$ 2>&1
2235    status=$?
2236    if [ ${status} -gt 0 ] ; then
2237      IGCM_debug_Print 2 "IGCM_sys_ncdiff : error code ${status}"
2238      cat /tmp/out_command.$$
2239      \rm /tmp/out_command.$$
2240      IGCM_debug_Print 2 "IGCM_sys_ncdiff : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2241      sleep $DELAI
2242    else
2243      \rm /tmp/out_command.$$
2244      break
2245    fi
2246    (( i = i + 1 ))
2247  done
2248
2249  if [ ${status} -gt 0 ] ; then
2250    echo "IGCM_sys_ncdiff : ncdiff error"
2251    IGCM_debug_Exit "ncdiff"
2252  fi
2253
2254  IGCM_debug_PopStack "IGCM_sys_ncdiff"
2255}
2256
2257#D-#==================================================
2258#D-function IGCM_sys_ncea
2259#D-* Purpose: encapsulate ncea call so as to manage error code and retry
2260#D-* Examples:
2261#D-
2262function IGCM_sys_ncea {
2263  IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
2264  if ( $DEBUG_sys ) ; then
2265    echo "IGCM_sys_ncea :" $@
2266  fi
2267
2268  typeset NB_ESSAI DELAI status i
2269  # number of tentative
2270  NB_ESSAI=3
2271  # time delay between tentative
2272  DELAI=2
2273
2274  i=0
2275  while [ $i -lt $NB_ESSAI ] ; do
2276    ncea $@ > /tmp/out_command.$$ 2>&1
2277    status=$?
2278    if [ ${status} -gt 0 ] ; then
2279      IGCM_debug_Print 2 "IGCM_sys_ncea : error code ${status}"
2280      cat /tmp/out_command.$$
2281      \rm /tmp/out_command.$$
2282      IGCM_debug_Print 2 "IGCM_sys_ncea : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2283      sleep $DELAI
2284    else
2285      \rm /tmp/out_command.$$
2286      break
2287    fi
2288    (( i = i + 1 ))
2289  done
2290
2291  if [ ${status} -gt 0 ] ; then
2292    echo "IGCM_sys_ncea : ncea error"
2293    IGCM_debug_Exit "ncea"
2294  fi
2295
2296  IGCM_debug_PopStack "IGCM_sys_ncea"
2297}
2298
2299#D-#==================================================
2300#D-function IGCM_sys_ncecat
2301#D-* Purpose: encapsulate ncecat call so as to manage error code and retry
2302#D-* Examples:
2303#D-
2304function IGCM_sys_ncecat {
2305  IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
2306  if ( $DEBUG_sys ) ; then
2307    echo "IGCM_sys_ncecat :" $@
2308  fi
2309
2310  typeset NB_ESSAI DELAI status i
2311  # number of tentative
2312  NB_ESSAI=3
2313  # time delay between tentative
2314  DELAI=2
2315
2316  i=0
2317  while [ $i -lt $NB_ESSAI ] ; do
2318    ncecat $@ > /tmp/out_command.$$ 2>&1
2319    status=$?
2320    if [ ${status} -gt 0 ] ; then
2321      IGCM_debug_Print 2 "IGCM_sys_ncecat : error code ${status}"
2322      cat /tmp/out_command.$$
2323      \rm /tmp/out_command.$$
2324      IGCM_debug_Print 2 "IGCM_sys_ncecat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2325      sleep $DELAI
2326    else
2327      \rm /tmp/out_command.$$
2328      break
2329    fi
2330    (( i = i + 1 ))
2331  done
2332
2333  if [ ${status} -gt 0 ] ; then
2334    echo "IGCM_sys_ncecat : ncecat error"
2335    IGCM_debug_Exit "ncecat"
2336  fi
2337
2338  IGCM_debug_PopStack "IGCM_sys_ncecat"
2339}
2340
2341#D-#==================================================
2342#D-function IGCM_sys_ncflint
2343#D-* Purpose: encapsulate ncflint call so as to manage error code and retry
2344#D-* Examples:
2345#D-
2346function IGCM_sys_ncflint {
2347  IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
2348  if ( $DEBUG_sys ) ; then
2349    echo "IGCM_sys_ncflint :" $@
2350  fi
2351
2352  typeset NB_ESSAI DELAI status i
2353  # number of tentative
2354  NB_ESSAI=3
2355  # time delay between tentative
2356  DELAI=2
2357
2358  i=0
2359  while [ $i -lt $NB_ESSAI ] ; do
2360    ncflint $@ > /tmp/out_command.$$ 2>&1
2361    status=$?
2362    if [ ${status} -gt 0 ] ; then
2363      IGCM_debug_Print 2 "IGCM_sys_ncflint : error code ${status}"
2364      cat /tmp/out_command.$$
2365      \rm /tmp/out_command.$$
2366      IGCM_debug_Print 2 "IGCM_sys_ncflint : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2367      sleep $DELAI
2368    else
2369      \rm /tmp/out_command.$$
2370      break
2371    fi
2372    (( i = i + 1 ))
2373  done
2374
2375  if [ ${status} -gt 0 ] ; then
2376    echo "IGCM_sys_ncflint : ncflint error"
2377    IGCM_debug_Exit "ncflint"
2378  fi
2379
2380  IGCM_debug_PopStack "IGCM_sys_ncflint"
2381}
2382
2383#D-#==================================================
2384#D-function IGCM_sys_ncks
2385#D-* Purpose: encapsulate ncks call so as to manage error code and retry
2386#D-* Examples:
2387#D-
2388function IGCM_sys_ncks {
2389  IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
2390  if ( $DEBUG_sys ) ; then
2391    echo "IGCM_sys_ncks :" $@
2392  fi
2393
2394  typeset NB_ESSAI DELAI status i
2395  # number of tentative
2396  NB_ESSAI=3
2397  # time delay between tentative
2398  DELAI=2
2399
2400  i=0
2401  while [ $i -lt $NB_ESSAI ] ; do
2402    ncks $@ > /tmp/out_command.$$ 2>&1
2403    status=$?
2404    if [ ${status} -gt 0 ] ; then
2405      IGCM_debug_Print 2 "IGCM_sys_ncks : error code ${status}"
2406      cat /tmp/out_command.$$
2407      \rm /tmp/out_command.$$
2408      IGCM_debug_Print 2 "IGCM_sys_ncks : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2409      sleep $DELAI
2410    else
2411      \rm /tmp/out_command.$$
2412      break
2413    fi
2414    (( i = i + 1 ))
2415  done
2416
2417  if [ ${status} -gt 0 ] ; then
2418    echo "IGCM_sys_ncks : ncks error"
2419    IGCM_debug_Exit "ncks"
2420  fi
2421
2422  IGCM_debug_PopStack "IGCM_sys_ncks"
2423}
2424
2425#D-#==================================================
2426#D-function IGCM_sys_ncpdq
2427#D-* Purpose: encapsulate ncpdq call so as to manage error code and retry
2428#D-* Examples:
2429#D-
2430function IGCM_sys_ncpdq {
2431  IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
2432  if ( $DEBUG_sys ) ; then
2433    echo "IGCM_sys_ncpdq :" $@
2434  fi
2435
2436  typeset NB_ESSAI DELAI status i
2437  # number of tentative
2438  NB_ESSAI=3
2439  # time delay between tentative
2440  DELAI=2
2441
2442  i=0
2443  while [ $i -lt $NB_ESSAI ] ; do
2444    ncpdq $@ > /tmp/out_command.$$ 2>&1
2445    status=$?
2446    if [ ${status} -gt 0 ] ; then
2447      IGCM_debug_Print 2 "IGCM_sys_ncpdq : error code ${status}"
2448      cat /tmp/out_command.$$
2449      \rm /tmp/out_command.$$
2450      IGCM_debug_Print 2 "IGCM_sys_ncpdq : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2451      sleep $DELAI
2452    else
2453      \rm /tmp/out_command.$$
2454      break
2455    fi
2456    (( i = i + 1 ))
2457  done
2458
2459  if [ ${status} -gt 0 ] ; then
2460    echo "IGCM_sys_ncpdq : ncpdq error"
2461    IGCM_debug_Exit "ncpdq"
2462  fi
2463
2464  IGCM_debug_PopStack "IGCM_sys_ncpdq"
2465}
2466
2467#D-#==================================================
2468#D-function IGCM_sys_ncra
2469#D-* Purpose: encapsulate ncra call so as to manage error code and retry
2470#D-* Examples:
2471#D-
2472function IGCM_sys_ncra {
2473  IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
2474  if ( $DEBUG_sys ) ; then
2475    echo "IGCM_sys_ncra :" $@
2476  fi
2477
2478  typeset NB_ESSAI DELAI status i
2479  # number of tentative
2480  NB_ESSAI=3
2481  # time delay between tentative
2482  DELAI=2
2483
2484  i=0
2485  while [ $i -lt $NB_ESSAI ] ; do
2486    ncra $@ > /tmp/out_command.$$ 2>&1
2487    status=$?
2488    if [ ${status} -gt 0 ] ; then
2489      IGCM_debug_Print 2 "IGCM_sys_ncra : error code ${status}"
2490      cat /tmp/out_command.$$
2491      \rm /tmp/out_command.$$
2492      IGCM_debug_Print 2 "IGCM_sys_ncra : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2493      sleep $DELAI
2494    else
2495      \rm /tmp/out_command.$$
2496      break
2497    fi
2498    (( i = i + 1 ))
2499  done
2500
2501  if [ ${status} -gt 0 ] ; then
2502    echo "IGCM_sys_ncra : ncra error"
2503    IGCM_debug_Exit "ncra"
2504  fi
2505
2506  IGCM_debug_PopStack "IGCM_sys_ncra"
2507}
2508
2509#D-#==================================================
2510#D-function IGCM_sys_ncrcat
2511#D-* Purpose: encapsulate ncrcat call so as to manage error code and retry
2512#D-* Examples:
2513#D-
2514function IGCM_sys_ncrcat {
2515  IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
2516  if ( $DEBUG_sys ) ; then
2517    echo "IGCM_sys_ncrcat :" $@
2518  fi
2519
2520  typeset NB_ESSAI DELAI status i lastArg
2521  # number of tentative
2522  NB_ESSAI=3
2523  # time delay between tentative
2524  DELAI=2
2525
2526  i=0
2527  while [ $i -lt $NB_ESSAI ] ; do
2528    ncrcat $@ > /tmp/out_command.$$ 2>&1
2529    status=$?
2530    if [ ${status} -gt 0 ] ; then
2531      IGCM_debug_Print 2 "IGCM_sys_ncrcat : error code ${status}"
2532      cat /tmp/out_command.$$
2533      \rm /tmp/out_command.$$
2534      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2535      sleep $DELAI
2536    elif [ ! "X$( grep "WARNING Intra-file non-monotonicity" /tmp/out_command.$$ )" = "X" ] ; then
2537      IGCM_debug_Print 2 "IGCM_sys_ncrcat : WARNING Intra-file non-monotonicity"
2538      cat /tmp/out_command.$$
2539      # remove files having corrupted time axis
2540      eval lastArg=\${$#}
2541      IGCM_debug_Print 2 "IGCM_sys_ncrcat : Delete ${lastArg}"
2542      \rm ${lastArg}
2543      \rm /tmp/out_command.$$
2544      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2545      sleep $DELAI
2546    else
2547      \rm /tmp/out_command.$$
2548      break
2549    fi
2550    (( i = i + 1 ))
2551  done
2552
2553  if [ ${status} -gt 0 ] ; then
2554    echo "IGCM_sys_ncrcat : ncrcat error"
2555    #IGCM_debug_Exit "ncrcat"
2556  fi
2557
2558  IGCM_debug_PopStack "IGCM_sys_ncrcat"
2559}
2560
2561#D-#==================================================
2562#D-function IGCM_sys_ncrename
2563#D-* Purpose: encapsulate ncrename call so as to manage error code and retry
2564#D-* Examples:
2565#D-
2566function IGCM_sys_ncrename {
2567  IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
2568  if ( $DEBUG_sys ) ; then
2569    echo "IGCM_sys_ncrename :" $@
2570  fi
2571
2572  typeset NB_ESSAI DELAI status i
2573  # number of tentative
2574  NB_ESSAI=3
2575  # time delay between tentative
2576  DELAI=2
2577
2578  i=0
2579  while [ $i -lt $NB_ESSAI ] ; do
2580    ncrename $@ > /tmp/out_command.$$ 2>&1
2581    status=$?
2582    if [ ${status} -gt 0 ] ; then
2583      IGCM_debug_Print 2 "IGCM_sys_ncrename : error code ${status}"
2584      cat /tmp/out_command.$$
2585      \rm /tmp/out_command.$$
2586      IGCM_debug_Print 2 "IGCM_sys_ncrename : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2587      sleep $DELAI
2588    else
2589      \rm /tmp/out_command.$$
2590      break
2591    fi
2592    (( i = i + 1 ))
2593  done
2594
2595  if [ ${status} -gt 0 ] ; then
2596    echo "IGCM_sys_ncrename : ncrename error"
2597    IGCM_debug_Exit "ncrename"
2598  fi
2599
2600  IGCM_debug_PopStack "IGCM_sys_ncrename"
2601}
2602
2603#D-#==================================================
2604#D-function IGCM_sys_ncwa
2605#D-* Purpose: encapsulate ncwa call so as to manage error code and retry
2606#D-* Examples:
2607#D-
2608function IGCM_sys_ncwa {
2609  IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
2610  if ( $DEBUG_sys ) ; then
2611    echo "IGCM_sys_ncwa :" $@
2612  fi
2613
2614  typeset NB_ESSAI DELAI status i
2615  # number of tentative
2616  NB_ESSAI=3
2617  # time delay between tentative
2618  DELAI=2
2619
2620  i=0
2621  while [ $i -lt $NB_ESSAI ] ; do
2622    ncwa $@ > /tmp/out_command.$$ 2>&1
2623    status=$?
2624    if [ ${status} -gt 0 ] ; then
2625      IGCM_debug_Print 2 "IGCM_sys_ncwa : error code ${status}"
2626      cat /tmp/out_command.$$
2627      \rm /tmp/out_command.$$
2628      IGCM_debug_Print 2 "IGCM_sys_ncwa : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2629      sleep $DELAI
2630    else
2631      \rm /tmp/out_command.$$
2632      break
2633    fi
2634    (( i = i + 1 ))
2635  done
2636
2637  if [ ${status} -gt 0 ] ; then
2638    echo "IGCM_sys_ncwa : ncwa error"
2639    IGCM_debug_Exit "ncwa"
2640  fi
2641
2642  IGCM_debug_PopStack "IGCM_sys_ncwa"
2643}
2644
2645##############################################################
2646# CDO OPERATOR
2647
2648#D-#==================================================
2649#D-function IGCM_sys_cdo
2650#D-* Purpose: encapsulate cdo call so as to manage error code and retry
2651#D-* Examples:
2652#D-
2653function IGCM_sys_cdo {
2654  IGCM_debug_PushStack "IGCM_sys_cdo" -- $@
2655  if ( $DEBUG_sys ) ; then
2656    echo "IGCM_sys_cdo :" $@
2657  fi
2658
2659  typeset status
2660
2661  \cdo $@ > /tmp/out_command.$$ 2>&1
2662  status=$?
2663  if [ ${status} -gt 0 ] ; then
2664    echo "IGCM_sys_cdo : error code ${status}"
2665    cat /tmp/out_command.$$
2666    \rm /tmp/out_command.$$
2667    IGCM_debug_PopStack "IGCM_sys_cdo"
2668    return 1
2669  else
2670    IGCM_debug_PopStack "IGCM_sys_cdo"
2671    return 0
2672  fi
2673
2674  IGCM_debug_PopStack "IGCM_sys_cdo"
2675}
Note: See TracBrowser for help on using the repository browser.