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

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

On ada, IGCM_sys_PutBuffer_Out add status initialisation when copy is skipped.

  • Property svn:keywords set to Revision Author Date
File size: 64.3 KB
Line 
1#!/bin/ksh
2
3#**************************************************************
4# Author: Sébastien Denvil
5# Contact: Sebastien.Denvil__at__ipsl.jussieu.fr
6# $Revision::                                          $ Revision of last commit
7# $Author::                                            $ Author of last commit
8# $Date::                                              $ Date of last commit
9# IPSL (2006)
10#  This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC
11#
12#**************************************************************
13
14#=========================================================
15# The documentation of this file can be automatically generated
16# if you use the prefix #D- for comments to be extracted.
17# Extract with command: cat lib* | grep "^#D-" | cut -c "4-"
18#=========================================================
19
20#D-#==================================================
21#D-LibIGCM_sys for Ada
22#D-#==================================================
23#D-
24#D- This ksh library if a layer under some usefull
25#D-environment variables and shell commands.
26#D-All those definitions depend on host particularities.
27#D-It manages a stack mechanism and test validity of operations.
28#D-All function described bellow must be prefixed by IGCM_sys.
29
30#====================================================
31# libIGCM_sys PARAMETERS
32#====================================================
33
34#====================================================
35# set DEBUG_sys to true to output calls of function
36typeset -r DEBUG_sys=${DEBUG_sys:=true}
37
38#====================================================
39# Turn in dry run mode ? (sys_Put_Rest, sys_Put_Out, sys_Get)
40typeset -r DRYRUN=${DRYRUN:=0}
41
42# YOU MUST COMPILE YOUR EXE FILES FOR DRYRUN MODE !
43# -------------------------------------------------------------------------------------
44# | DRYRUN=  |  Date computations, | sys_Get    |  Exe    | sys_Put_Out; sys_Put_Rest |
45# |          |  Cp/Exe param files |            |  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#- RUN_DIR_PATH : Temporary working directory (=> TMP)
156typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=${TMPDIR}}
157
158#====================================================
159#- HOST_MPIRUN_COMMAND
160typeset -r HOST_MPIRUN_COMMAND=${HOST_MPIRUN_COMMAND:="poe"}
161
162#====================================================
163#- Max number of arguments passed to nco operator or demigration command
164UNIX_MAX_LIMIT=360
165
166#====================================================
167#- set PackDefault true on curie
168PackDefault=true
169
170#====================================================
171#- Number of core per node (max number of OpenMP task)
172NUM_COREPERNODE=8
173
174#====================================================
175#- Default number of MPI task for IPSL coupled model
176#- required for backward compatibility
177#-
178DEFAULT_NUM_PROC_OCE=5
179DEFAULT_NUM_PROC_CPL=1
180(( DEFAULT_NUM_PROC_ATM = BATCH_NUM_PROC_TOT - DEFAULT_NUM_PROC_OCE - DEFAULT_NUM_PROC_CPL ))
181DEFAULT_NUM_PROC_TOTAL=${BATCH_NUM_PROC_TOT}
182
183#D-#==================================================
184#D-function IGCM_sys_ChangeArchive
185#D-* Purpose: if SpaceName=TEST everything is stored on SCRATCHDIR
186#D-* Examples:
187#D-
188function IGCM_sys_ChangeArchive {
189  IGCM_debug_PushStack "IGCM_sys_ChangeArchive"
190
191  R_OUT=${SCRATCHDIR}/IGCM_OUT
192  R_FIG=${SCRATCHDIR}/IGCM_OUT
193
194  IGCM_debug_Print 1 "R_OUT   has been redefined = ${R_OUT}"
195  IGCM_debug_Print 1 "R_FIG   has been redefined = ${R_FIG}"
196
197  IGCM_debug_PopStack "IGCM_sys_ChangeArchive"
198}
199
200#D-#==================================================
201#D-function IGCM_sys_RshMaster
202#D-* Purpose: Connection to frontend machine.
203#D-* Examples:
204#D-
205function IGCM_sys_RshMaster {
206  IGCM_debug_PushStack "IGCM_sys_RshMaster" $@
207  /bin/ksh <<-EOF
208    export libIGCM=${libIGCM}
209    export DEBUG_debug=${DEBUG_debug}
210    . ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh
211    . ${libIGCM}/libIGCM_card/libIGCM_card.ksh
212    ${@}
213EOF
214  if [ $? -gt 0 ] ; then
215    echo "IGCM_sys_RshMaster : erreur."
216    IGCM_debug_Exit "IGCM_sys_RshMaster"
217  fi
218  IGCM_debug_PopStack "IGCM_sys_RshMaster"
219}
220
221#D-#==================================================
222#D-function IGCM_sys_RshArchive
223#D-* Purpose: Archive rsh command
224#D-* Examples:
225#D-
226function IGCM_sys_RshArchive {
227  IGCM_debug_PushStack "IGCM_sys_RshArchive" $@
228  rsh ${STOREHOST} exec /bin/ksh <<-EOF
229    ${@}
230EOF
231  if [ $? -gt 0 ] ; then
232    echo "IGCM_sys_RshArchive : erreur."
233    IGCM_debug_Exit "IGCM_sys_RshArchive"
234  fi
235  IGCM_debug_PopStack "IGCM_sys_RshArchive"
236}
237
238#D-#==================================================
239#D-function IGCM_sys_RshPost
240#D-* Purpose: Post-process rsh command
241#D-* Examples:
242#D-
243function IGCM_sys_RshPost {
244  IGCM_debug_PushStack "IGCM_sys_RshPost" $@
245  if ( $DEBUG_sys ) ; then
246    echo "IGCM_sys_RshPost :" $@
247  fi
248
249  # keep standard input to keep it for postpone if ulam don't answer
250  cat >/tmp/tmp_IGCM_sys_RshPost_$$_${LOGNAME}
251
252  /bin/ksh </tmp/tmp_IGCM_sys_RshPost_$$_${LOGNAME}
253  if [ $? -gt 0 ] ; then
254    echo "IGCM_sys_RshPost : erreur."
255    IGCM_debug_Exit "IGCM_sys_RshPost"
256  fi
257  # delete temporary file
258  \rm /tmp/tmp_IGCM_sys_RshPost_$$_${LOGNAME}
259
260  IGCM_debug_PopStack "IGCM_sys_RshPost"
261}
262
263#D-#==================================================
264#D-function IGCM_sys_SendMail
265#D-* Purpose: Send mail when simulation is over
266#D-* Examples:
267#D-
268function IGCM_sys_SendMail {
269  IGCM_debug_PushStack "IGCM_sys_SendMail" $@
270  if ( $DEBUG_sys ) ; then
271    echo "IGCM_sys_SendMail :" $@
272  fi
273
274  if ( ${ExitFlag} ) ; then
275    status=failed
276  else
277    status=completed
278  fi
279
280  cat  << END_MAIL > job_end.mail
281Dear ${LOGIN},
282
283  Simulation ${config_UserChoices_JobName} is ${status} on supercomputer `hostname`.
284  Job started : ${DateBegin}
285  Job ended   : ${DateEnd}
286  Output files are available in ${R_SAVE}
287  Files to be rebuild are temporarily available in ${REBUILD_DIR}
288  Pre-packed files are temporarily available in ${R_BUFR}
289  Script files, Script Outputs and Debug files (if necessary) are available in ${SUBMIT_DIR}
290END_MAIL
291
292  if [ ! -z ${config_UserChoices_MailName} ] ; then
293    mail -s "${config_UserChoices_JobName} ${status}" ${config_UserChoices_MailName} <  job_end.mail
294  elif [ -f ~/.forward ] ; then
295    mail -s "${config_UserChoices_JobName} ${status}" $( cat ~/.forward ) < job_end.mail
296  else
297    mail -s "${config_UserChoices_JobName} ${status}" ${USER} < job_end.mail
298  fi
299
300  sleep 10
301  rm -f job_end.mail
302
303  if [ $? -gt 0 ] ; then
304    echo "IGCM_sys_SendMail : erreur."
305    IGCM_debug_Exit "IGCM_sys_SendMail"
306  fi
307  IGCM_debug_PopStack "IGCM_sys_SendMail"
308}
309
310#D-#==================================================
311#D-function IGCM_sys_Mkdir
312#D-* Purpose: Master locale mkdir command
313#D-* Examples:
314#D-
315function IGCM_sys_Mkdir {
316  IGCM_debug_PushStack "IGCM_sys_Mkdir" $@
317  if ( $DEBUG_sys ) ; then
318    echo "IGCM_sys_Mkdir :" $@
319  fi
320  if [ ! -d ${1} ]; then
321    \mkdir -p $1
322    if [ $? -gt 0 ] ; then
323      echo "IGCM_sys_Mkdir : erreur."
324      IGCM_debug_Exit "IGCM_sys_Mkdir"
325    fi
326  fi
327  # vérification :
328  if [ ! -d ${1} ] ; then
329    echo "IGCM_sys_Mkdir : erreur."
330    IGCM_debug_Exit "IGCM_sys_Mkdir"
331  fi
332  IGCM_debug_PopStack "IGCM_sys_Mkdir"
333}
334
335#D-#==================================================
336#D-function IGCM_sys_MkdirArchive
337#D-* Purpose: Mkdir on Archive
338#D-* Examples:
339#D-
340function IGCM_sys_MkdirArchive {
341  IGCM_debug_PushStack "IGCM_sys_MkdirArchive" $@
342  if ( $DEBUG_sys ) ; then
343    echo "IGCM_sys_MkdirArchive :" $@
344  fi
345  #- creation de repertoire sur le serveur fichier
346  rsh ${STOREHOST} -n mkdir -p $1
347
348  if [ $? -gt 0 ] ; then
349    echo "IGCM_sys_MkdirArchive : erreur."
350    IGCM_debug_Exit "IGCM_sys_MkdirArchive"
351  fi
352  IGCM_debug_PopStack "IGCM_sys_MkdirArchive"
353}
354
355#D-#==================================================
356#D-function IGCM_sys_MkdirWork
357#D-* Purpose: Mkdir on Work
358#D-* Examples:
359#D-
360function IGCM_sys_MkdirWork {
361  IGCM_debug_PushStack "IGCM_sys_MkdirWork" $@
362  if ( $DEBUG_sys ) ; then
363    echo "IGCM_sys_MkdirWork :" $@
364  fi
365  #- creation de repertoire sur le serveur fichier
366  if [ ! -d ${1} ]; then
367    \mkdir -p $1
368    if [ $? -gt 0 ] ; then
369      echo "IGCM_sys_MkdirWork : erreur."
370      IGCM_debug_Exit "IGCM_sys_MkdirWork"
371    fi
372  fi
373  IGCM_debug_PopStack "IGCM_sys_MkdirWork"
374}
375
376#D-#==================================================
377#D-function IGCM_sys_Cd
378#D-* Purpose: master cd command
379#D-* Examples:
380#D-
381function IGCM_sys_Cd {
382  IGCM_debug_PushStack "IGCM_sys_Cd" $@
383  if ( $DEBUG_sys ) ; then
384    echo "IGCM_sys_Cd :" $@
385  fi
386  \cd $1
387  if [ $? -gt 0 ] ; then
388    echo "IGCM_sys_Cd : erreur."
389    IGCM_debug_Exit "IGCM_sys_Cd"
390  fi
391  IGCM_debug_PopStack "IGCM_sys_Cd"
392}
393
394#D-#==================================================
395#D-function IGCM_sys_Chmod
396#D-* Purpose: Chmod
397#D-* Examples:
398#D-
399function IGCM_sys_Chmod {
400  IGCM_debug_PushStack "IGCM_sys_Chmod" -- $@
401  if ( $DEBUG_sys ) ; then
402    echo "IGCM_sys_Chmod :" $@
403  fi
404  if [ $DRYRUN -le 1 ]; then
405    \chmod $@
406    if [ $? -gt 0 ] ; then
407      echo "IGCM_sys_Chmod : erreur."
408      IGCM_debug_Exit "IGCM_sys_Chmod"
409    fi
410  else
411    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
412  fi
413  IGCM_debug_PopStack "IGCM_sys_Chmod"
414}
415
416#D-#==================================================
417#D-function IGCM_sys_FileSize
418#D-* Purpose: Filesize
419#D-* Examples:
420#D-
421function IGCM_sys_FileSize {
422  IGCM_debug_PushStack "IGCM_sys_FileSize" $@
423
424  typeset sizeF
425  set +A sizeF -- $( ls -la ${1} )
426  if [ $? -gt 0 ] ; then
427    IGCM_debug_Exit "IGCM_sys_FileSize"
428  fi
429  eval ${2}=${sizeF[4]}
430
431  IGCM_debug_PopStack "IGCM_sys_FileSize"
432}
433
434#D-#==================================================
435#D-function IGCM_sys_TestDir
436#D-* Purpose: Test Directory that must exists
437#D-* Examples:
438#D-
439function IGCM_sys_TestDir {
440  IGCM_debug_PushStack "IGCM_sys_TestDir" $@
441  if ( $DEBUG_sys ) ; then
442    echo "IGCM_sys_TestDir :" $@
443  fi
444  typeset ExistFlag
445  ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
446  IGCM_debug_PopStack "IGCM_sys_TestDir"
447
448  return ${ExistFlag}
449}
450
451#D-#==================================================
452#D-function IGCM_sys_TestDirArchive
453#D-* Purpose: Test Directory that must exists on Archive
454#D-* Examples:
455#D-
456function IGCM_sys_TestDirArchive {
457  IGCM_debug_PushStack "IGCM_sys_TestDirArchive" $@
458  if ( $DEBUG_sys ) ; then
459    echo "IGCM_sys_TestDirArchive :" $@
460  fi
461  typeset ExistFlag
462  ExistFlag=$( IGCM_sys_RshArchive "[ -d $1 ] && echo 0 || echo 1" )
463  IGCM_debug_PopStack "IGCM_sys_TestDirArchive"
464
465  return ${ExistFlag}
466}
467
468#D-#==================================================
469#D-function IGCM_sys_IsFileArchived
470#D-* Purpose: Test file that must NOT EXISTS on Archive
471#D-* Examples:
472#D-
473function IGCM_sys_IsFileArchived {
474  IGCM_debug_PushStack "IGCM_sys_IsFileArchived" $@
475  if ( $DEBUG_sys ) ; then
476    echo "IGCM_sys_IsFileArchived :" $@
477  fi
478  typeset IsArchivedFlag
479  IsArchivedFlag=$( [ X$( echo $1 | grep ^\/u\/rech ) != X ] && echo 0 || echo 1 )
480  IGCM_debug_PopStack "IGCM_sys_IsFileArchived"
481
482  return ${IsArchivedFlag}
483}
484
485#D-#==================================================
486#D-function IGCM_sys_TestFileArchive
487#D-* Purpose: Test file that must NOT EXISTS on Archive
488#D-* Examples:
489#D-
490function IGCM_sys_TestFileArchive {
491  IGCM_debug_PushStack "IGCM_sys_TestFileArchive" $@
492  typeset ExistFlag
493  ExistFlag=$( IGCM_sys_RshArchive "[ -f $1 ] && echo 0 || echo 1" )
494  IGCM_debug_PopStack "IGCM_sys_TestFileArchive"
495
496  return ${ExistFlag}
497}
498
499#D-#==================================================
500#D-function IGCM_sys_TestFileBuffer
501#D-* Purpose: Test file that must NOT EXISTS on Buffer
502#D-* Examples:
503#D-
504function IGCM_sys_TestFileBuffer {
505  IGCM_debug_PushStack "IGCM_sys_TestFileBuffer" $@
506  typeset ExistFlag
507  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
508  IGCM_debug_PopStack "IGCM_sys_TestFileBuffer"
509
510  return ${ExistFlag}
511}
512
513#D-#==================================================
514#D-function IGCM_sys_CountFileArchive
515#D-* Purpose: Count files on Archive filesystem
516#D-* Examples:
517#D-
518function IGCM_sys_CountFileArchive {
519  IGCM_debug_PushStack "IGCM_sys_CountFileArchive" $@
520  IGCM_sys_RshArchive "ls ${@} 2>/dev/null | wc -l"
521  if [ $? -gt 0 ] ; then
522    echo "IGCM_sys_CountFileArchive : erreur."
523  fi
524  IGCM_debug_PopStack "IGCM_sys_CountFileArchive"
525}
526
527#D-#==================================================
528#D-function IGCM_sys_CountFileBuffer
529#D-* Purpose: Count files on Scratch filesystem
530#D-* Examples:
531#D-
532function IGCM_sys_CountFileBuffer {
533  IGCM_debug_PushStack "IGCM_sys_CountFileBuffer" $@
534  ls ${@} 2>/dev/null | wc -l
535  if [ $? -gt 0 ] ; then
536    echo "IGCM_sys_CountFileBuffer : erreur."
537  fi
538  IGCM_debug_PopStack "IGCM_sys_CountFileBuffer"
539}
540
541#D-#==================================================
542#D-function IGCM_sys_Tree
543#D-* Purpose: Tree directories with files on ${ARCHIVE}
544#D-* Examples: IGCM_sys_Tree ${R_IN} ${R_OUT}
545#D-
546function IGCM_sys_Tree {
547  IGCM_debug_PushStack "IGCM_sys_Tree" $@
548  if ( $DEBUG_sys ) ; then
549    echo "IGCM_sys_Tree :" $@
550  fi
551
552  \mfls -r $@
553
554  IGCM_debug_PopStack "IGCM_sys_Tree"
555}
556
557#D-#==================================================
558#D-function IGCM_sys_Tar
559#D-* Purpose: master tar command
560#D-* Examples:
561#D-
562function IGCM_sys_Tar {
563  IGCM_debug_PushStack "IGCM_sys_Tar" $@
564  if ( $DEBUG_sys ) ; then
565    echo "IGCM_sys_Tar :" $@
566  fi
567  \tar cf $@
568  if [ $? -gt 0 ] ; then
569    echo "IGCM_sys_Tar : erreur."
570    IGCM_debug_Exit "IGCM_sys_Tar"
571  fi
572  IGCM_debug_PopStack "IGCM_sys_Tar"
573}
574
575#D-#==================================================
576#D-function IGCM_sys_UnTar
577#D-* Purpose: master un-tar command
578#D-* Examples:
579#D-
580function IGCM_sys_UnTar {
581  IGCM_debug_PushStack "IGCM_sys_UnTar" $@
582  if ( $DEBUG_sys ) ; then
583    echo "IGCM_sys_UnTar :" $@
584  fi
585  \tar xvf $1
586  if [ $? -gt 0 ] ; then
587    echo "IGCM_sys_UnTar : erreur."
588    IGCM_debug_Exit "IGCM_sys_UnTar"
589  fi
590  IGCM_debug_PopStack "IGCM_sys_UnTar"
591}
592
593#D-#==================================================
594#D-function IGCM_sys_Qsub
595#D-* Purpose: Qsub new job
596#D-* Examples:
597#D-
598function IGCM_sys_Qsub {
599  IGCM_debug_PushStack "IGCM_sys_Qsub" $@
600
601  typeset ERROR
602  ERROR=0
603
604  if ( $DEBUG_sys ) ; then
605    echo "IGCM_sys_Qsub :" $@
606  fi
607  # We have to change output/error file
608  [ ${#@} = 1 ] &&  REP_FOR_JOB=${SUBMIT_DIR}
609  [ ${#@} = 2 ] &&  REP_FOR_JOB=${2}
610  sed -e "s:\# \@ output *= .*:\# \@ output = ${Script_Output}:" \
611      -e "s:\# \@ error *= .*:\# \@ error = ${Script_Output}:"   \
612      $1 > ${REP_FOR_JOB}/JOB_FOR_IGCM
613  cd $REP_FOR_JOB ; /usr/bin/llsubmit JOB_FOR_IGCM ; ERROR=$? ; cd - ;
614
615  if [ ${ERROR} -gt 0 ] ; then
616    echo "IGCM_sys_Qsub : erreur $@"
617    IGCM_debug_Exit "IGCM_sys_Qsub"
618  else
619    IGCM_sys_Rm ${REP_FOR_JOB}/JOB_FOR_IGCM
620  fi
621  IGCM_debug_PopStack "IGCM_sys_Qsub"
622}
623
624#D-#==================================================
625#D-function IGCM_sys_QsubPost
626#D-* Purpose: Qsub new job on scalaire
627#D-* Examples:
628#D-
629function IGCM_sys_QsubPost {
630  IGCM_debug_PushStack "IGCM_sys_QsubPost" $@
631
632  typeset ERROR
633  ERROR=0
634
635  if ( $DEBUG_sys ) ; then
636    echo "IGCM_sys_QsubPost :" $@
637  fi
638  # We have to change output/error file
639  [ ${#@} = 1 ] &&  REP_FOR_JOB=${POST_DIR}
640  [ ${#@} = 2 ] &&  REP_FOR_JOB=${2}
641
642  sed -e "s:\# \@ output *= .*:\# \@ output = ${Script_Post_Output}.out:" \
643      -e "s:\# \@ error *= .*:\# \@ error = ${Script_Post_Output}.out:"   \
644      ${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        status=0
1251        skip=true
1252      else
1253        IGCM_debug_Print 2 "$1 and $2 are not the same file, we force the copy"
1254        skip=false
1255      fi
1256    fi
1257    #
1258    if ( [ X${exist} = Xtrue ] && [ X${skip} = Xfalse ] ) ; then
1259      IGCM_sys_Chmod u+w $2
1260    fi
1261
1262    if [ X${skip} = Xfalse ] ; then
1263      i=0
1264      while [ $i -lt $NB_ESSAI ] ; do
1265        # USUAL WAY
1266        \cp $1 $2 > out_rsync 2>&1
1267        status=$?
1268        if [ ${status} -gt 0 ]; then
1269          IGCM_debug_Print 2 "IGCM_sys_PutBuffer_Out : cp failed error code ${status} ${i}/${NB_ESSAI}"
1270          IGCM_debug_Print 2 "IGCM_sys_PutBuffer_Out : sleep ${DELAI} seconds and try again."
1271          [ -f ${2} ] && ls -l ${2}
1272          [ -f ${2}/${1} ] && ls -l ${2}/${1}
1273          sleep $DELAI
1274        else
1275          break
1276        fi
1277        (( i = i + 1 ))
1278      done
1279    fi
1280
1281    if [ ${status} -gt 0 ] ; then
1282      echo "IGCM_sys_PutBuffer_Out : error."
1283      [ -f ${2} ] && ls -l ${2}
1284      [ -f ${2}/${1} ] && ls -l ${2}/${1}
1285      cat out_rsync
1286      IGCM_debug_Exit "IGCM_sys_PutBuffer_Out"
1287    else
1288
1289      if [ X${JobType} = XRUN ] ; then
1290        if [ X${3} = X ] ; then
1291          [ -f ${2} ] && IGCM_sys_Chmod 444 ${2}
1292          [ -f ${2}/${1} ] && IGCM_sys_Chmod 444 ${2}/${1}
1293        fi
1294      fi
1295
1296      \rm out_rsync
1297    fi
1298  else
1299    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1300  fi
1301  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1302  return 0
1303}
1304
1305#D-#==================================================
1306#D-function IGCM_sys_Get
1307#D-* Purpose: Get a file from ${ARCHIVE}
1308#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
1309#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
1310function IGCM_sys_Get {
1311  IGCM_debug_PushStack "IGCM_sys_Get" $@
1312
1313  typeset DEST status dm_liste
1314
1315  if ( $DEBUG_sys ) ; then
1316    echo "IGCM_sys_Get :" $@
1317  fi
1318  if [ $DRYRUN -le 2 ]; then
1319    if [ X${1} = X'/l' ] ; then
1320      # test if the first file is present in the old computation :
1321      eval set +A dm_liste \${${2}}
1322    else
1323      dm_liste=${1}
1324    fi
1325    eval DEST=\${${#}}
1326
1327    # test if the (first) file is present in the old computation :
1328    IGCM_sys_TestFileArchive ${dm_liste[0]}
1329    status=$?
1330    if [ ${status} -gt 0 ] ; then
1331      echo "IGCM_sys_Get, ERROR : regular file ${dm_liste[0]} DOES NOT EXIST ."
1332      IGCM_debug_Exit "IGCM_sys_Get"
1333      return
1334    fi
1335
1336    #USUAL WAY
1337    mfget ${dm_liste[*]} ${DEST} > out_rsync 2>&1
1338    status=$?
1339
1340#       #RSYNC WITH NETWORK RSH CALL
1341#       echo ${RSYNC} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} > out_rsync 2>&1
1342#       ${RSYNC} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} >> out_rsync 2>&1
1343
1344#       #RSYNC WITH NFS USE
1345#       echo ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} > out_rsync 2>&1
1346#       ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} >> out_rsync 2>&1
1347
1348#       status=$?
1349#       IGCM_sys_Rsync_out $status
1350
1351#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1352#       (( status=status+$? ))
1353
1354    if [ ${status} -gt 0 ] ; then
1355      echo "IGCM_sys_Get : copy error."
1356      cat out_rsync
1357      IGCM_debug_Exit "IGCM_sys_Get"
1358    else
1359      \rm out_rsync
1360    fi
1361  else
1362    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1363  fi
1364  IGCM_debug_PopStack "IGCM_sys_Get"
1365}
1366
1367#D-#==================================================
1368#D-function IGCM_sys_GetBuffer
1369#D-* Purpose: Get a file from ${SCRATCHDIR}
1370#D-* Examples: IGCM_sys_GetBuffer myfile /destpath/myfile_with_PREFIX
1371#D-            IGCM_sys_GetBuffer /l Array_contain_myfiles /destpath/
1372function IGCM_sys_GetBuffer {
1373  IGCM_debug_PushStack "IGCM_sys_GetBuffer" $@
1374
1375  typeset DEST buf_liste target file_work
1376  typeset NB_ESSAI DELAI status i
1377
1378  if ( $DEBUG_sys ) ; then
1379    echo "IGCM_sys_GetBuffer :" $@
1380  fi
1381
1382  # number of tentative
1383  NB_ESSAI=3
1384  # time delay between tentative
1385  DELAI=2
1386
1387  if [ $DRYRUN -le 2 ]; then
1388    if [ X${1} = X'/l' ] ; then
1389      # test if the first file is present in the old computation :
1390      eval set +A buf_liste \${${2}}
1391    else
1392      eval set +A buf_liste ${1}
1393    fi
1394    eval DEST=\${${#}}
1395
1396    #USUAL WAY
1397    if [ X${1} = X'/l' ] ; then
1398      for target in ${buf_liste[*]} ; do
1399        local_file=$( basename ${target} )
1400        i=0
1401        while [ $i -lt $NB_ESSAI ] ; do
1402          \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1403          status=$?
1404          if [ ${status} -gt 0 ]; then
1405            IGCM_debug_Print 2 "IGCM_sys_GetBuffer : cp failed error code ${status} ${i}/${NB_ESSAI}"
1406            IGCM_debug_Print 2 "IGCM_sys_GetBuffer : sleep ${DELAI} seconds and try again."
1407            sleep $DELAI
1408          else
1409            break
1410          fi
1411          (( i = i + 1 ))
1412        done
1413        if [ ${status} -gt 0 ] ; then
1414          echo "IGCM_sys_Get : error"
1415          cat out_rsync
1416          \rm out_rsync
1417          IGCM_debug_Exit "IGCM_sys_GetBuffer"
1418        else
1419          \rm out_rsync
1420        fi
1421      done
1422    else
1423      i=0
1424      while [ $i -lt $NB_ESSAI ] ; do
1425        \cp ${buf_liste} ${DEST} >> out_rsync 2>&1
1426        status=$?
1427        if [ ${status} -gt 0 ]; then
1428          IGCM_debug_Print 2 "IGCM_sys_GetBuffer : cp failed error code ${status} ${i}/${NB_ESSAI}"
1429          IGCM_debug_Print 2 "IGCM_sys_GetBuffer : sleep ${DELAI} seconds and try again."
1430          sleep $DELAI
1431        else
1432          break
1433        fi
1434        (( i = i + 1 ))
1435      done
1436      if [ ${status} -gt 0 ] ; then
1437        echo "IGCM_sys_Get : error"
1438        cat out_rsync
1439        \rm out_rsync
1440        IGCM_debug_Exit "IGCM_sys_GetBuffer"
1441      else
1442        \rm out_rsync
1443      fi
1444    fi
1445  else
1446    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1447  fi
1448  IGCM_debug_PopStack "IGCM_sys_GetBuffer"
1449}
1450
1451#D-#==================================================
1452#D-function IGCM_sys_GetDate_FichWork
1453#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
1454#D-* Examples:
1455#D-
1456function IGCM_sys_GetDate_FichWork {
1457  IGCM_debug_PushStack "IGCM_sys_FichWork" $@
1458  if ( $DEBUG_sys ) ; then
1459    echo "IGCM_sys_GetDate_FichWork :" $@
1460  fi
1461  typeset dateF
1462  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1463  eval ${2}=${dateF[5]}
1464
1465  # donne la date filesys d'un fichier sur la machine work
1466  IGCM_debug_PopStack "IGCM_sys_FichWork"
1467}
1468
1469#D-#==================================================
1470#D-function IGCM_sys_GetDate_FichArchive
1471#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
1472#D-* Examples:
1473#D-
1474function IGCM_sys_GetDate_FichArchive {
1475  IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
1476  if ( $DEBUG_sys ) ; then
1477    echo "IGCM_sys_GetDate_FichArchive :" $@
1478  fi
1479  typeset dateF
1480  set +A dateF -- $( rsh ${STOREHOST} -n ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1481  eval ${2}=${dateF[5]}
1482
1483  IGCM_debug_PopStack "IGCM_sys_FichArchive"
1484}
1485
1486#D-#==================================================
1487#D-function IGCM_sys_Put_Dods
1488#D-* Purpose: Put $(ARCHIVE) files on DODS internet protocole.
1489#D-* Examples:
1490#D-
1491function IGCM_sys_Put_Dods {
1492  IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
1493  if ( $DEBUG_sys ) ; then
1494    echo "IGCM_sys_Put_Dods :" $@
1495  fi
1496  if [ $DRYRUN = 0 ]; then
1497    # We take our time on that
1498    sleep 10
1499    IGCM_sys_TestDirArchive ${R_SAVE}/${1}
1500    if [ $? != 0 ] ; then
1501      echo "WARNING : IGCM_sys_Put_Dods ${R_SAVE}/${1} DOES NOT EXIST ."
1502      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1503      return
1504    fi
1505
1506    typeset status
1507    #
1508    rsh gaya exec /bin/ksh <<EOF
1509          cd ${R_SAVE}
1510          /usr/local/bin/dods_rm DODS/pub/${LOGIN}/${R_DODS}/${1} > /dev/null 2>&1
1511          /bin/chmod -R u+w ${R_SAVE}/${1}
1512          /usr/local/bin/dods_cp ${1} DODS/pub/${LOGIN}/${R_DODS} > /dev/null 2>&1
1513          /bin/chmod -R +rX ${R_SAVE}/${1}
1514          /bin/chmod -R u+w ${R_SAVE}/${1}
1515EOF
1516    status=$?
1517
1518    if [ ${status} -gt 0 ] ; then
1519      echo "IGCM_sys_Put_Dods : error."
1520      IGCM_debug_Exit "IGCM_sys_Put_Dods"
1521    fi
1522  else
1523    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1524  fi
1525  IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1526}
1527
1528##############################################################
1529# REBUILD OPERATOR
1530
1531function IGCM_sys_rebuild {
1532  IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1533  if ( $DEBUG_sys ) ; then
1534    echo "IGCM_sys_rebuild :" $@
1535  fi
1536
1537  typeset NB_ESSAI DELAI status i firstArg
1538  # number of tentative
1539  NB_ESSAI=3
1540  # time delay between tentative
1541  DELAI=2
1542
1543  i=0
1544  while [ $i -lt $NB_ESSAI ] ; do
1545    /smphome/rech/psl/rpsl035/bin/rebuild -f -o $@ > out_rsync 2>&1
1546    status=$?
1547    if [ ${status} -gt 0 ] ; then
1548      IGCM_debug_Print 2 "IGCM_sys_rebuild : error code ${status}"
1549      cat out_rsync
1550      \rm out_rsync
1551      IGCM_debug_Print 2 "IGCM_sys_rebuild : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1552      firstArg=${1}
1553      \rm ${firstArg}
1554      sleep $DELAI
1555    else
1556      \rm out_rsync
1557      break
1558    fi
1559    (( i = i + 1 ))
1560  done
1561
1562  if [ ${status} -gt 0 ] ; then
1563    echo "IGCM_sys_rebuild : rebuild error code is ${status}"
1564    IGCM_debug_Exit "rebuild"
1565  fi
1566
1567  IGCM_debug_PopStack "IGCM_sys_rebuild"
1568}
1569
1570function IGCM_sys_rebuild_station {
1571  IGCM_debug_PushStack "IGCM_sys_rebuild_station" -- $@
1572  typeset i list_opt file_in file_out prefix_invert list_invert
1573  if ( $DEBUG_sys ) ; then
1574    echo "IGCM_sys_rebuild_station :" $@
1575  fi
1576  list_opt=$@
1577
1578  # Invert Axis : t,x -> x,t
1579  #               t,pres,x -> x,t,pres
1580  # So that we can concatenate along x
1581  i=0
1582  for file_in in ${list_opt} ; do
1583    (( i = i + 1))
1584    [ ${i} = 1 ] && file_out=${file_in} && continue
1585    prefix_invert=$( basename ${file_in} .nc )
1586    IGCM_sys_ncpdq -a x,time_counter -a x,time_counter,presnivs ${file_in} ${prefix_invert}_xt.nc
1587    list_invert[${#list_invert[*]}]=${prefix_invert}_xt.nc
1588  done
1589
1590  # Concatenate
1591  IGCM_sys_ncrcat ${list_invert[*]} histstn_xt.nc
1592
1593  # Re-ivert file
1594  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x histstn_xt.nc ${file_out}
1595
1596  # Station re-ordering is too expansive to be run within libICGM
1597  # This is due to (ncpdq - nrcat - ncpdq) I/O sequence.
1598  # This re-ordering must be done "in memory" by the cmorization process
1599  # Anyway this is the best sequence using (ncpdq - nrcat - ncpdq)
1600  # BEGIN reordering
1601
1602  # Only LMDZ text output contains the exact ordering of the station.
1603  # We isolate this in the code below:
1604  #  0  38  -157.5000000000000  70.98591549295774
1605  #  0  54  27.49999999999999   67.18309859154928
1606  #  0  56  -62.50000000000001  82.39436619718309
1607  #  0  79  12.49999999999999   78.59154929577466
1608  #  0  116 -165.0000000000000  76.05633802816901
1609  #  0  117 130.0000000000000   70.98591549295774
1610  #  0  118 110.0000000000000   87.46478873239437
1611  #  1  40  4.999999999999995   51.97183098591550
1612#  typeset iStation iProc list_opt file_in file_out prefix_invert
1613#  typeset -Z4 j4
1614#  typeset -Z3 j3
1615
1616#  unset list_opt
1617#  set +A list_opt $@
1618
1619  # Filename after rebuild
1620#  file_out=${list_opt[0]}
1621  # Prefix of output files
1622#  prefix_invert=$( basename ${file_out} .nc )
1623  # Number of procs
1624#  num_proc=$( grep -i mpi_size ${PREFIX}_${Exe_Output} | wc -l )
1625
1626#  iProc=0
1627#  while [ ${iProc} -lt ${num_proc} ] ; do
1628    # Array containing Station as a number
1629#    unset proc_stn
1630#    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}' )
1631    # Number of stations produced by processor proc
1632#    stationLast=${#proc_stn[*]}
1633    # Proc number on 4 digits
1634#    j4=${iProc}
1635    # Init
1636#    iStation=0
1637#    while [ ${iStation} -lt ${stationLast} ] ; do
1638      # Station number on 3 digits
1639#      j3=${proc_stn[${iStation}]}
1640      # Extract station
1641      # Invert Axis : t,x -> x,t
1642      #               t,pres,x -> x,t,pres
1643      # So that we can concatenate along x
1644#      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
1645#      (( iStation = iStation + 1 ))
1646#    done
1647#    (( iProc = iProc + 1 ))
1648#  done
1649
1650  # Concatenate all station along x
1651#  IGCM_sys_ncrcat ${prefix_invert}_stn_???.nc ${prefix_invert}_xt.nc
1652
1653  # Re-invert file
1654#  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x ${prefix_invert}_xt.nc ${file_out}
1655
1656  # END reordering
1657
1658  IGCM_debug_PopStack "IGCM_sys_rebuild_station"
1659}
1660
1661############################################################
1662# Activate Running Environnment Variables
1663
1664function IGCM_sys_activ_variables {
1665  IGCM_debug_PushStack "IGCM_sys_activ_variables"
1666  if ( $DEBUG_sys ) ; then
1667    echo "IGCM_sys_activ_variables "
1668  fi
1669
1670  ulimit -s unlimited
1671
1672  IGCM_debug_PopStack "IGCM_sys_activ_variables"
1673}
1674
1675############################################################
1676# Desactivate Running Environnment Variables
1677
1678function IGCM_sys_desactiv_variables {
1679  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1680  if ( $DEBUG_sys ) ; then
1681    echo "IGCM_sys_desactiv_variables "
1682  fi
1683# --------------------------------------------------------------------
1684#D- MPI specifications
1685# --------------------------------------------------------------------
1686
1687# --------------------------------------------------------------------
1688#D- Other specifications
1689# --------------------------------------------------------------------
1690
1691  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1692}
1693
1694############################################################
1695# Build MPI/OMP scripts run file (dummy function)
1696
1697function IGCM_sys_build_run_file {
1698
1699IGCM_debug_Print 3 " dummy function : IGCM_sys_build_run_file "
1700
1701}
1702
1703############################################################
1704# Build MPI/OMP scripts
1705function IGCM_sys_build_execution_scripts
1706{
1707  IGCM_debug_PushStack "IGCM_sys_build_execution_scripts" $@
1708  if ( $DEBUG_sys ) ; then
1709    echo "IGCM_sys_build_execution_scripts " $@
1710  fi
1711
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
1737        if ( ${OK_PARA_MPI} ) ; then
1738          (( mpi_count = 1 ))
1739          until [ ${mpi_count} -gt ${comp_proc_mpi_loc} ] ; do
1740            echo "./${ExeNameOut}" >> run_file
1741            (( mpi_count = mpi_count + 1 ))
1742          done
1743        else
1744          echo "./${ExeNameOut} " >> run_file
1745        fi
1746      fi
1747    done
1748
1749# Then second loop on the components
1750
1751    for comp in ${config_ListOfComponents[*]} ; do
1752
1753      eval ExeNameIn=\${config_Executable_${comp}[0]}
1754      eval ExeNameOut=\${config_Executable_${comp}[1]}
1755
1756      # Only if we really have an executable for the component and not the coupler ie oasis:
1757      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${comp}" != "XCPL" ] ) ; then
1758
1759        eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1760        eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1761
1762        if ( ${OK_PARA_MPI} ) ; then
1763          (( mpi_count = 1 ))
1764          until [ ${mpi_count} -gt ${comp_proc_mpi_loc} ] ; do
1765            echo "./${ExeNameOut}" >> run_file
1766            (( mpi_count = mpi_count + 1 ))
1767          done
1768        else
1769            echo "./${ExeNameOut} " >> run_file
1770        fi
1771      fi
1772    done
1773
1774    EXECUTION="${HOST_MPIRUN_COMMAND} -pgmmodel mpmd -cmdfile ./run_file"
1775
1776    IGCM_sys_Chmod u+x run_file
1777    if ( $DEBUG_sys ) ; then
1778      echo "run_file contains : "
1779      cat run_file
1780    fi
1781
1782  else # Only one executable. launch it.
1783
1784    #
1785    for comp in ${config_ListOfComponents[*]} ; do
1786
1787      # Only if we really have an executable for the component :
1788      eval ExeNameOut=\${config_Executable_${comp}[1]}
1789      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${ExeNameOut}" != "Xinca.dat" ] ) ; then
1790        EXECUTION="./${ExeNameOut}"
1791      fi
1792
1793    done
1794
1795  fi
1796
1797  IGCM_debug_Print 1 "sys ada : execution command is "
1798  IGCM_debug_Print 1 "$EXECUTION"
1799
1800  IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
1801}
1802
1803############################################################
1804# Check of space available on temporary filesytems
1805function IGCM_sys_check_quota {
1806  IGCM_debug_PushStack "IGCM_sys_check_quota"
1807  if ( $DEBUG_sys ) ; then
1808    echo "IGCM_sys_check_quota "
1809  fi
1810  # Limit of quota (in %)
1811  limit_quota=90
1812  # Check of the volume
1813  volume_quota=$(quota_u -w | grep 'Quota soft' | awk '{print $5}')
1814  if [ ! X${volume_quota} = X ] ; then
1815    quota_volume=${volume_quota%%\%}
1816#    echo $quota_volume
1817    if [ ${quota_volume} -ge ${limit_quota} ] ; then
1818      IGCM_debug_Print 1 "Please, check your quota of volume on workgpfs"
1819      IGCM_debug_Print 1 "${quota_volume}% of your quota is used"
1820      IGCM_debug_Print 1 "Use the quota_u -w command to check"
1821      IGCM_debug_Print 1 "You must have more than 10% available to run"
1822      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
1823      IGCM_debug_Verif_Exit
1824    fi
1825
1826  fi
1827  IGCM_debug_PopStack "IGCM_sys_check_quota"
1828}
1829
1830#D-#==================================================
1831#D-function IGCM_sys_CountJobInQueue
1832#D-* Purpose: Check if job_name is currently
1833#D-  running or in queue
1834#D-* Examples: IGCM_sys_CountJobInQueue ${JobName} NbRun
1835#D-
1836
1837function IGCM_sys_CountJobInQueue {
1838  IGCM_debug_PushStack "IGCM_sys_CountJobInQueue"
1839  if ( $DEBUG_sys ) ; then
1840    echo "IGCM_sys_CountJobInQueue"
1841  fi
1842
1843  # Print only the full (-W) JobName (%jn)
1844  NbRun=$( llq -W -f %jn | grep -c "$1" )
1845
1846  eval ${2}=${NbRun}
1847
1848  IGCM_debug_PopStack "IGCM_sys_CountJobInQueue"
1849}
1850
1851##############################################################
1852# NCO OPERATOR
1853
1854function IGCM_sys_ncap2 {
1855  IGCM_debug_PushStack "IGCM_sys_ncap2" -- $@
1856  if ( $DEBUG_sys ) ; then
1857    echo "IGCM_sys_ncap2 :" $@
1858  fi
1859
1860  typeset NB_ESSAI DELAI status i
1861  # number of tentative
1862  NB_ESSAI=3
1863  # time delay between tentative
1864  DELAI=2
1865
1866  i=0
1867  while [ $i -lt $NB_ESSAI ] ; do
1868    ncap2 "$@" > out_rsync 2>&1
1869    status=$?
1870    if [ ${status} -gt 0 ] ; then
1871      IGCM_debug_Print 2 "IGCM_sys_ncap2 : error code ${status}"
1872      cat out_rsync
1873      \rm out_rsync
1874      IGCM_debug_Print 2 "IGCM_sys_ncap2 : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1875      sleep $DELAI
1876    else
1877      \rm out_rsync
1878      break
1879    fi
1880    (( i = i + 1 ))
1881  done
1882
1883  if [ ${status} -gt 0 ] ; then
1884      echo "IGCM_sys_ncap2 : ncap2 error"
1885      IGCM_debug_Exit "ncap2"
1886  fi
1887
1888  IGCM_debug_PopStack "IGCM_sys_ncap2"
1889}
1890
1891function IGCM_sys_ncatted {
1892  IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
1893  if ( $DEBUG_sys ) ; then
1894    echo "IGCM_sys_ncatted :" $@
1895  fi
1896
1897  typeset NB_ESSAI DELAI status i
1898  # number of tentative
1899  NB_ESSAI=3
1900  # time delay between tentative
1901  DELAI=2
1902
1903  i=0
1904  while [ $i -lt $NB_ESSAI ] ; do
1905    ncatted "$@" > out_rsync 2>&1
1906    status=$?
1907    if [ ${status} -gt 0 ] ; then
1908      IGCM_debug_Print 2 "IGCM_sys_ncatted : error code ${status}"
1909      cat out_rsync
1910      \rm out_rsync
1911      IGCM_debug_Print 2 "IGCM_sys_ncatted : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1912      sleep $DELAI
1913    else
1914      \rm out_rsync
1915      break
1916    fi
1917    (( i = i + 1 ))
1918  done
1919
1920  if [ ${status} -gt 0 ] ; then
1921      echo "IGCM_sys_ncatted : ncatted error"
1922      IGCM_debug_Exit "ncatted"
1923  fi
1924
1925  IGCM_debug_PopStack "IGCM_sys_ncatted"
1926}
1927
1928function IGCM_sys_ncbo {
1929  IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
1930  if ( $DEBUG_sys ) ; then
1931    echo "IGCM_sys_ncbo :" $@
1932  fi
1933
1934  typeset NB_ESSAI DELAI status i
1935  # number of tentative
1936  NB_ESSAI=3
1937  # time delay between tentative
1938  DELAI=2
1939
1940  i=0
1941  while [ $i -lt $NB_ESSAI ] ; do
1942    ncbo $@ > out_rsync 2>&1
1943    status=$?
1944    if [ ${status} -gt 0 ] ; then
1945      IGCM_debug_Print 2 "IGCM_sys_ncbo : error code ${status}"
1946      cat out_rsync
1947      \rm out_rsync
1948      IGCM_debug_Print 2 "IGCM_sys_ncbo : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1949      sleep $DELAI
1950    else
1951      \rm out_rsync
1952      break
1953    fi
1954    (( i = i + 1 ))
1955  done
1956
1957  if [ ${status} -gt 0 ] ; then
1958      echo "IGCM_sys_ncbo : ncbo error"
1959      IGCM_debug_Exit "ncbo"
1960  fi
1961
1962  IGCM_debug_PopStack "IGCM_sys_ncbo"
1963}
1964
1965function IGCM_sys_ncdiff {
1966  IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
1967  if ( $DEBUG_sys ) ; then
1968    echo "IGCM_sys_ncdiff :" $@
1969  fi
1970
1971  typeset NB_ESSAI DELAI status i
1972  # number of tentative
1973  NB_ESSAI=3
1974  # time delay between tentative
1975  DELAI=2
1976
1977  i=0
1978  while [ $i -lt $NB_ESSAI ] ; do
1979    ncdiff $@ > out_rsync 2>&1
1980    status=$?
1981    if [ ${status} -gt 0 ] ; then
1982      IGCM_debug_Print 2 "IGCM_sys_ncdiff : error code ${status}"
1983      cat out_rsync
1984      \rm out_rsync
1985      IGCM_debug_Print 2 "IGCM_sys_ncdiff : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1986      sleep $DELAI
1987    else
1988      \rm out_rsync
1989      break
1990    fi
1991    (( i = i + 1 ))
1992  done
1993
1994  if [ ${status} -gt 0 ] ; then
1995      echo "IGCM_sys_ncdiff : ncdiff error"
1996      IGCM_debug_Exit "ncdiff"
1997  fi
1998
1999  IGCM_debug_PopStack "IGCM_sys_ncdiff"
2000}
2001
2002function IGCM_sys_ncea {
2003  IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
2004  if ( $DEBUG_sys ) ; then
2005    echo "IGCM_sys_ncea :" $@
2006  fi
2007
2008  typeset NB_ESSAI DELAI status i
2009  # number of tentative
2010  NB_ESSAI=3
2011  # time delay between tentative
2012  DELAI=2
2013
2014  i=0
2015  while [ $i -lt $NB_ESSAI ] ; do
2016    ncea $@ > out_rsync 2>&1
2017    status=$?
2018    if [ ${status} -gt 0 ] ; then
2019      IGCM_debug_Print 2 "IGCM_sys_ncea : error code ${status}"
2020      cat out_rsync
2021      \rm out_rsync
2022      IGCM_debug_Print 2 "IGCM_sys_ncea : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2023      sleep $DELAI
2024    else
2025      \rm out_rsync
2026      break
2027    fi
2028    (( i = i + 1 ))
2029  done
2030
2031  if [ ${status} -gt 0 ] ; then
2032      echo "IGCM_sys_ncea : ncea error"
2033      IGCM_debug_Exit "ncea"
2034  fi
2035
2036  IGCM_debug_PopStack "IGCM_sys_ncea"
2037}
2038
2039function IGCM_sys_ncecat {
2040  IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
2041  if ( $DEBUG_sys ) ; then
2042    echo "IGCM_sys_ncecat :" $@
2043  fi
2044
2045  typeset NB_ESSAI DELAI status i
2046  # number of tentative
2047  NB_ESSAI=3
2048  # time delay between tentative
2049  DELAI=2
2050
2051  i=0
2052  while [ $i -lt $NB_ESSAI ] ; do
2053    ncecat $@ > out_rsync 2>&1
2054    status=$?
2055    if [ ${status} -gt 0 ] ; then
2056      IGCM_debug_Print 2 "IGCM_sys_ncecat : error code ${status}"
2057      cat out_rsync
2058      \rm out_rsync
2059      IGCM_debug_Print 2 "IGCM_sys_ncecat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2060      sleep $DELAI
2061    else
2062      \rm out_rsync
2063      break
2064    fi
2065    (( i = i + 1 ))
2066  done
2067
2068  if [ ${status} -gt 0 ] ; then
2069      echo "IGCM_sys_ncecat : ncecat error"
2070      IGCM_debug_Exit "ncecat"
2071  fi
2072
2073  IGCM_debug_PopStack "IGCM_sys_ncecat"
2074}
2075
2076function IGCM_sys_ncflint {
2077  IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
2078  if ( $DEBUG_sys ) ; then
2079    echo "IGCM_sys_ncflint :" $@
2080  fi
2081
2082  typeset NB_ESSAI DELAI status i
2083  # number of tentative
2084  NB_ESSAI=3
2085  # time delay between tentative
2086  DELAI=2
2087
2088  i=0
2089  while [ $i -lt $NB_ESSAI ] ; do
2090    ncflint $@ > out_rsync 2>&1
2091    status=$?
2092    if [ ${status} -gt 0 ] ; then
2093      IGCM_debug_Print 2 "IGCM_sys_ncflint : error code ${status}"
2094      cat out_rsync
2095      \rm out_rsync
2096      IGCM_debug_Print 2 "IGCM_sys_ncflint : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2097      sleep $DELAI
2098    else
2099      \rm out_rsync
2100      break
2101    fi
2102    (( i = i + 1 ))
2103  done
2104
2105  if [ ${status} -gt 0 ] ; then
2106      echo "IGCM_sys_ncflint : ncflint error"
2107      IGCM_debug_Exit "ncflint"
2108  fi
2109
2110  IGCM_debug_PopStack "IGCM_sys_ncflint"
2111}
2112
2113function IGCM_sys_ncks {
2114  IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
2115  if ( $DEBUG_sys ) ; then
2116    echo "IGCM_sys_ncks :" $@
2117  fi
2118
2119  typeset NB_ESSAI DELAI status i
2120  # number of tentative
2121  NB_ESSAI=3
2122  # time delay between tentative
2123  DELAI=2
2124
2125  i=0
2126  while [ $i -lt $NB_ESSAI ] ; do
2127    ncks $@ > out_rsync 2>&1
2128    status=$?
2129    if [ ${status} -gt 0 ] ; then
2130      IGCM_debug_Print 2 "IGCM_sys_ncks : error code ${status}"
2131      cat out_rsync
2132      \rm out_rsync
2133      IGCM_debug_Print 2 "IGCM_sys_ncks : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2134      sleep $DELAI
2135    else
2136      \rm out_rsync
2137      break
2138    fi
2139    (( i = i + 1 ))
2140  done
2141
2142  if [ ${status} -gt 0 ] ; then
2143      echo "IGCM_sys_ncks : ncks error"
2144      IGCM_debug_Exit "ncks"
2145  fi
2146
2147  IGCM_debug_PopStack "IGCM_sys_ncks"
2148}
2149
2150function IGCM_sys_ncpdq {
2151  IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
2152  if ( $DEBUG_sys ) ; then
2153    echo "IGCM_sys_ncpdq :" $@
2154  fi
2155
2156  typeset NB_ESSAI DELAI status i
2157  # number of tentative
2158  NB_ESSAI=3
2159  # time delay between tentative
2160  DELAI=2
2161
2162  i=0
2163  while [ $i -lt $NB_ESSAI ] ; do
2164    ncpdq $@ > out_rsync 2>&1
2165    status=$?
2166    if [ ${status} -gt 0 ] ; then
2167      IGCM_debug_Print 2 "IGCM_sys_ncpdq : error code ${status}"
2168      cat out_rsync
2169      \rm out_rsync
2170      IGCM_debug_Print 2 "IGCM_sys_ncpdq : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2171      sleep $DELAI
2172    else
2173      \rm out_rsync
2174      break
2175    fi
2176    (( i = i + 1 ))
2177  done
2178
2179  if [ ${status} -gt 0 ] ; then
2180      echo "IGCM_sys_ncpdq : ncpdq error"
2181      IGCM_debug_Exit "ncpdq"
2182  fi
2183
2184  IGCM_debug_PopStack "IGCM_sys_ncpdq"
2185}
2186
2187function IGCM_sys_ncra {
2188  IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
2189  if ( $DEBUG_sys ) ; then
2190    echo "IGCM_sys_ncra :" $@
2191  fi
2192
2193  typeset NB_ESSAI DELAI status i
2194  # number of tentative
2195  NB_ESSAI=3
2196  # time delay between tentative
2197  DELAI=2
2198
2199  i=0
2200  while [ $i -lt $NB_ESSAI ] ; do
2201    ncra $@ > out_rsync 2>&1
2202    status=$?
2203    if [ ${status} -gt 0 ] ; then
2204      IGCM_debug_Print 2 "IGCM_sys_ncra : error code ${status}"
2205      cat out_rsync
2206      \rm out_rsync
2207      IGCM_debug_Print 2 "IGCM_sys_ncra : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2208      sleep $DELAI
2209    else
2210      \rm out_rsync
2211      break
2212    fi
2213    (( i = i + 1 ))
2214  done
2215
2216  if [ ${status} -gt 0 ] ; then
2217      echo "IGCM_sys_ncra : ncra error"
2218      IGCM_debug_Exit "ncra"
2219  fi
2220
2221  IGCM_debug_PopStack "IGCM_sys_ncra"
2222}
2223
2224function IGCM_sys_ncrcat {
2225  IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
2226  if ( $DEBUG_sys ) ; then
2227    echo "IGCM_sys_ncrcat :" $@
2228  fi
2229
2230  typeset NB_ESSAI DELAI status i lastArg
2231  # number of tentative
2232  NB_ESSAI=3
2233  # time delay between tentative
2234  DELAI=2
2235
2236  i=0
2237  while [ $i -lt $NB_ESSAI ] ; do
2238    ncrcat $@ > out_rsync 2>&1
2239    status=$?
2240    if [ ${status} -gt 0 ] ; then
2241      IGCM_debug_Print 2 "IGCM_sys_ncrcat : error code ${status}"
2242      cat out_rsync
2243      \rm out_rsync
2244      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2245      sleep $DELAI
2246    elif [ ! "X$( grep "WARNING Intra-file non-monotonicity" out_rsync )" = "X" ] ; then
2247      IGCM_debug_Print 2 "IGCM_sys_ncrcat : WARNING Intra-file non-monotonicity"
2248      cat out_rsync
2249      # remove files having corrupted time axis
2250      eval lastArg=\${$#}
2251      IGCM_debug_Print 2 "IGCM_sys_ncrcat : Delete ${lastArg}"
2252      \rm ${lastArg}
2253      \rm out_rsync
2254      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2255      sleep $DELAI
2256    else
2257      \rm out_rsync
2258      break
2259    fi
2260    (( i = i + 1 ))
2261  done
2262
2263  if [ ${status} -gt 0 ] ; then
2264      echo "IGCM_sys_ncrcat : ncrcat error"
2265      #IGCM_debug_Exit "ncrcat"
2266  fi
2267
2268  IGCM_debug_PopStack "IGCM_sys_ncrcat"
2269}
2270
2271function IGCM_sys_ncrename {
2272  IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
2273  if ( $DEBUG_sys ) ; then
2274    echo "IGCM_sys_ncrename :" $@
2275  fi
2276
2277  typeset NB_ESSAI DELAI status i
2278  # number of tentative
2279  NB_ESSAI=3
2280  # time delay between tentative
2281  DELAI=2
2282
2283  i=0
2284  while [ $i -lt $NB_ESSAI ] ; do
2285    ncrename $@ > out_rsync 2>&1
2286    status=$?
2287    if [ ${status} -gt 0 ] ; then
2288      IGCM_debug_Print 2 "IGCM_sys_ncrename : error code ${status}"
2289      cat out_rsync
2290      \rm out_rsync
2291      IGCM_debug_Print 2 "IGCM_sys_ncrename : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2292      sleep $DELAI
2293    else
2294      \rm out_rsync
2295      break
2296    fi
2297    (( i = i + 1 ))
2298  done
2299
2300  if [ ${status} -gt 0 ] ; then
2301      echo "IGCM_sys_ncrename : ncrename error"
2302      IGCM_debug_Exit "ncrename"
2303  fi
2304
2305  IGCM_debug_PopStack "IGCM_sys_ncrename"
2306}
2307
2308function IGCM_sys_ncwa {
2309  IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
2310  if ( $DEBUG_sys ) ; then
2311    echo "IGCM_sys_ncwa :" $@
2312  fi
2313
2314  typeset NB_ESSAI DELAI status i
2315  # number of tentative
2316  NB_ESSAI=3
2317  # time delay between tentative
2318  DELAI=2
2319
2320  i=0
2321  while [ $i -lt $NB_ESSAI ] ; do
2322    ncwa $@ > out_rsync 2>&1
2323    status=$?
2324    if [ ${status} -gt 0 ] ; then
2325      IGCM_debug_Print 2 "IGCM_sys_ncwa : error code ${status}"
2326      cat out_rsync
2327      \rm out_rsync
2328      IGCM_debug_Print 2 "IGCM_sys_ncwa : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2329      sleep $DELAI
2330    else
2331      \rm out_rsync
2332      break
2333    fi
2334    (( i = i + 1 ))
2335  done
2336
2337  if [ ${status} -gt 0 ] ; then
2338      echo "IGCM_sys_ncwa : ncwa error"
2339      IGCM_debug_Exit "ncwa"
2340  fi
2341
2342  IGCM_debug_PopStack "IGCM_sys_ncwa"
2343}
2344
2345##############################################################
2346# CDO OPERATOR
2347
2348function IGCM_sys_cdo {
2349  IGCM_debug_PushStack "IGCM_sys_cdo" -- $@
2350  if ( $DEBUG_sys ) ; then
2351    echo "IGCM_sys_cdo :" $@
2352  fi
2353
2354  typeset status
2355
2356  \cdo $@ > out_rsync 2>&1
2357  status=$?
2358  if [ ${status} -gt 0 ] ; then
2359    echo "IGCM_sys_cdo : error code ${status}"
2360    cat out_rsync
2361    \rm out_rsync
2362    IGCM_debug_PopStack "IGCM_sys_cdo"
2363    return 1
2364  else
2365    IGCM_debug_PopStack "IGCM_sys_cdo"
2366    return 0
2367  fi
2368
2369  IGCM_debug_PopStack "IGCM_sys_cdo"
2370}
Note: See TracBrowser for help on using the repository browser.