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

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

Bugfix in ada lib when settings meaningfull output filenames. DRYRUN is OK.
LD_LIBRARY_PATH not in place yet

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