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

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

Add ada system library. Almost running in DRYRUN mode (post process submission still experience some issues).

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