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

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

Add IGCM_sys_CountJobInQueue (needed by RunChecker?) to Ada and Curie system libraries.

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