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

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

On ada delete useless rm.

  • 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  else
1208    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1209  fi
1210  IGCM_debug_PopStack "IGCM_sys_Put_Out"
1211  return 0
1212}
1213
1214#D-#==================================================
1215#D-function IGCM_sys_PutBuffer_Out
1216#D-* Purpose: Copy a file on ${WORKDIR} after having chmod it in readonly
1217#D-* Examples:
1218#D-
1219function IGCM_sys_PutBuffer_Out {
1220  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Out" $@
1221  if ( $DEBUG_sys ) ; then
1222    echo "IGCM_sys_PutBuffer_Out :" $@
1223  fi
1224
1225  typeset NB_ESSAI DELAI status i exist skip
1226
1227  # number of tentative
1228  NB_ESSAI=3
1229  # time delay between tentative
1230  DELAI=2
1231
1232  if [ $DRYRUN = 0 ]; then
1233    if [ ! -f ${1} ] ; then
1234      echo "WARNING : IGCM_sys_PutBuffer_Out ${1} DOES NOT EXIST ."
1235      IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1236      return 1
1237    fi
1238    #
1239    IGCM_sys_Mkdir $( dirname $2 )
1240    #
1241
1242    exist=false
1243    skip=false
1244    if [ -f $2 ] ; then
1245      IGCM_debug_Print 1 "$2 already exist"
1246      exist=true
1247      if [ "X$( diff $1 $2 )" = X ] ; then
1248        IGCM_debug_Print 2 "$1 and $2 are the same file, we skip the copy"
1249        status=0
1250        skip=true
1251      else
1252        IGCM_debug_Print 2 "$1 and $2 are not the same file, we force the copy"
1253        skip=false
1254      fi
1255    fi
1256    #
1257    if ( [ X${exist} = Xtrue ] && [ X${skip} = Xfalse ] ) ; then
1258      IGCM_sys_Chmod u+w $2
1259    fi
1260
1261    if [ X${skip} = Xfalse ] ; then
1262      i=0
1263      while [ $i -lt $NB_ESSAI ] ; do
1264        # USUAL WAY
1265        \cp $1 $2 > out_rsync 2>&1
1266        status=$?
1267        if [ ${status} -gt 0 ]; then
1268          IGCM_debug_Print 2 "IGCM_sys_PutBuffer_Out : cp failed error code ${status} ${i}/${NB_ESSAI}"
1269          IGCM_debug_Print 2 "IGCM_sys_PutBuffer_Out : sleep ${DELAI} seconds and try again."
1270          [ -f ${2} ] && ls -l ${2}
1271          [ -f ${2}/${1} ] && ls -l ${2}/${1}
1272          sleep $DELAI
1273        else
1274          break
1275        fi
1276        (( i = i + 1 ))
1277      done
1278    fi
1279
1280    if [ ${status} -gt 0 ] ; then
1281      echo "IGCM_sys_PutBuffer_Out : error."
1282      [ -f ${2} ] && ls -l ${2}
1283      [ -f ${2}/${1} ] && ls -l ${2}/${1}
1284      cat out_rsync
1285      IGCM_debug_Exit "IGCM_sys_PutBuffer_Out"
1286    else
1287
1288      if [ X${JobType} = XRUN ] ; then
1289        if [ X${3} = X ] ; then
1290          [ -f ${2} ] && IGCM_sys_Chmod 444 ${2}
1291          [ -f ${2}/${1} ] && IGCM_sys_Chmod 444 ${2}/${1}
1292        fi
1293      fi
1294
1295      \rm out_rsync
1296    fi
1297  else
1298    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1299  fi
1300  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1301  return 0
1302}
1303
1304#D-#==================================================
1305#D-function IGCM_sys_Get
1306#D-* Purpose: Get a file from ${ARCHIVE}
1307#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
1308#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
1309function IGCM_sys_Get {
1310  IGCM_debug_PushStack "IGCM_sys_Get" $@
1311
1312  typeset DEST status dm_liste
1313
1314  if ( $DEBUG_sys ) ; then
1315    echo "IGCM_sys_Get :" $@
1316  fi
1317  if [ $DRYRUN -le 2 ]; then
1318    if [ X${1} = X'/l' ] ; then
1319      # test if the first file is present in the old computation :
1320      eval set +A dm_liste \${${2}}
1321    else
1322      dm_liste=${1}
1323    fi
1324    eval DEST=\${${#}}
1325
1326    # test if the (first) file is present in the old computation :
1327    IGCM_sys_TestFileArchive ${dm_liste[0]}
1328    status=$?
1329    if [ ${status} -gt 0 ] ; then
1330      echo "IGCM_sys_Get, ERROR : regular file ${dm_liste[0]} DOES NOT EXIST ."
1331      IGCM_debug_Exit "IGCM_sys_Get"
1332      return
1333    fi
1334
1335    #USUAL WAY
1336    mfget ${dm_liste[*]} ${DEST} > out_rsync 2>&1
1337    status=$?
1338
1339#       #RSYNC WITH NETWORK RSH CALL
1340#       echo ${RSYNC} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} > out_rsync 2>&1
1341#       ${RSYNC} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} >> out_rsync 2>&1
1342
1343#       #RSYNC WITH NFS USE
1344#       echo ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} > out_rsync 2>&1
1345#       ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} >> out_rsync 2>&1
1346
1347#       status=$?
1348#       IGCM_sys_Rsync_out $status
1349
1350#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1351#       (( status=status+$? ))
1352
1353    if [ ${status} -gt 0 ] ; then
1354      echo "IGCM_sys_Get : copy error."
1355      cat out_rsync
1356      IGCM_debug_Exit "IGCM_sys_Get"
1357    else
1358      \rm out_rsync
1359    fi
1360  else
1361    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1362  fi
1363  IGCM_debug_PopStack "IGCM_sys_Get"
1364}
1365
1366#D-#==================================================
1367#D-function IGCM_sys_GetBuffer
1368#D-* Purpose: Get a file from ${SCRATCHDIR}
1369#D-* Examples: IGCM_sys_GetBuffer myfile /destpath/myfile_with_PREFIX
1370#D-            IGCM_sys_GetBuffer /l Array_contain_myfiles /destpath/
1371function IGCM_sys_GetBuffer {
1372  IGCM_debug_PushStack "IGCM_sys_GetBuffer" $@
1373
1374  typeset DEST buf_liste target file_work
1375  typeset NB_ESSAI DELAI status i
1376
1377  if ( $DEBUG_sys ) ; then
1378    echo "IGCM_sys_GetBuffer :" $@
1379  fi
1380
1381  # number of tentative
1382  NB_ESSAI=3
1383  # time delay between tentative
1384  DELAI=2
1385
1386  if [ $DRYRUN -le 2 ]; then
1387    if [ X${1} = X'/l' ] ; then
1388      # test if the first file is present in the old computation :
1389      eval set +A buf_liste \${${2}}
1390    else
1391      eval set +A buf_liste ${1}
1392    fi
1393    eval DEST=\${${#}}
1394
1395    #USUAL WAY
1396    if [ X${1} = X'/l' ] ; then
1397      for target in ${buf_liste[*]} ; do
1398        local_file=$( basename ${target} )
1399        i=0
1400        while [ $i -lt $NB_ESSAI ] ; do
1401          \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1402          status=$?
1403          if [ ${status} -gt 0 ]; then
1404            IGCM_debug_Print 2 "IGCM_sys_GetBuffer : cp failed error code ${status} ${i}/${NB_ESSAI}"
1405            IGCM_debug_Print 2 "IGCM_sys_GetBuffer : sleep ${DELAI} seconds and try again."
1406            sleep $DELAI
1407          else
1408            break
1409          fi
1410          (( i = i + 1 ))
1411        done
1412        if [ ${status} -gt 0 ] ; then
1413          echo "IGCM_sys_Get : error"
1414          cat out_rsync
1415          \rm out_rsync
1416          IGCM_debug_Exit "IGCM_sys_GetBuffer"
1417        else
1418          \rm out_rsync
1419        fi
1420      done
1421    else
1422      i=0
1423      while [ $i -lt $NB_ESSAI ] ; do
1424        \cp ${buf_liste} ${DEST} >> out_rsync 2>&1
1425        status=$?
1426        if [ ${status} -gt 0 ]; then
1427          IGCM_debug_Print 2 "IGCM_sys_GetBuffer : cp failed error code ${status} ${i}/${NB_ESSAI}"
1428          IGCM_debug_Print 2 "IGCM_sys_GetBuffer : sleep ${DELAI} seconds and try again."
1429          sleep $DELAI
1430        else
1431          break
1432        fi
1433        (( i = i + 1 ))
1434      done
1435      if [ ${status} -gt 0 ] ; then
1436        echo "IGCM_sys_Get : error"
1437        cat out_rsync
1438        \rm out_rsync
1439        IGCM_debug_Exit "IGCM_sys_GetBuffer"
1440      else
1441        \rm out_rsync
1442      fi
1443    fi
1444  else
1445    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1446  fi
1447  IGCM_debug_PopStack "IGCM_sys_GetBuffer"
1448}
1449
1450#D-#==================================================
1451#D-function IGCM_sys_GetDate_FichWork
1452#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
1453#D-* Examples:
1454#D-
1455function IGCM_sys_GetDate_FichWork {
1456  IGCM_debug_PushStack "IGCM_sys_FichWork" $@
1457  if ( $DEBUG_sys ) ; then
1458    echo "IGCM_sys_GetDate_FichWork :" $@
1459  fi
1460  typeset dateF
1461  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1462  eval ${2}=${dateF[5]}
1463
1464  # donne la date filesys d'un fichier sur la machine work
1465  IGCM_debug_PopStack "IGCM_sys_FichWork"
1466}
1467
1468#D-#==================================================
1469#D-function IGCM_sys_GetDate_FichArchive
1470#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
1471#D-* Examples:
1472#D-
1473function IGCM_sys_GetDate_FichArchive {
1474  IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
1475  if ( $DEBUG_sys ) ; then
1476    echo "IGCM_sys_GetDate_FichArchive :" $@
1477  fi
1478  typeset dateF
1479  set +A dateF -- $( rsh ${STOREHOST} -n ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1480  eval ${2}=${dateF[5]}
1481
1482  IGCM_debug_PopStack "IGCM_sys_FichArchive"
1483}
1484
1485#D-#==================================================
1486#D-function IGCM_sys_Put_Dods
1487#D-* Purpose: Put $(ARCHIVE) files on DODS internet protocole.
1488#D-* Examples:
1489#D-
1490function IGCM_sys_Put_Dods {
1491  IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
1492  if ( $DEBUG_sys ) ; then
1493    echo "IGCM_sys_Put_Dods :" $@
1494  fi
1495  if [ $DRYRUN = 0 ]; then
1496    # We take our time on that
1497    sleep 10
1498    IGCM_sys_TestDirArchive ${R_SAVE}/${1}
1499    if [ $? != 0 ] ; then
1500      echo "WARNING : IGCM_sys_Put_Dods ${R_SAVE}/${1} DOES NOT EXIST ."
1501      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1502      return
1503    fi
1504
1505    typeset status
1506    #
1507    rsh gaya exec /bin/ksh <<EOF
1508          cd ${R_SAVE}
1509          /usr/local/bin/dods_rm DODS/pub/${LOGIN}/${R_DODS}/${1} > /dev/null 2>&1
1510          /bin/chmod -R u+w ${R_SAVE}/${1}
1511          /usr/local/bin/dods_cp ${1} DODS/pub/${LOGIN}/${R_DODS} > /dev/null 2>&1
1512          /bin/chmod -R +rX ${R_SAVE}/${1}
1513          /bin/chmod -R u+w ${R_SAVE}/${1}
1514EOF
1515    status=$?
1516
1517    if [ ${status} -gt 0 ] ; then
1518      echo "IGCM_sys_Put_Dods : error."
1519      IGCM_debug_Exit "IGCM_sys_Put_Dods"
1520    fi
1521  else
1522    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1523  fi
1524  IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1525}
1526
1527##############################################################
1528# REBUILD OPERATOR
1529
1530function IGCM_sys_rebuild {
1531  IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1532  if ( $DEBUG_sys ) ; then
1533    echo "IGCM_sys_rebuild :" $@
1534  fi
1535
1536  typeset NB_ESSAI DELAI status i firstArg
1537  # number of tentative
1538  NB_ESSAI=3
1539  # time delay between tentative
1540  DELAI=2
1541
1542  i=0
1543  while [ $i -lt $NB_ESSAI ] ; do
1544    /smphome/rech/psl/rpsl035/bin/rebuild -f -o $@ > out_rsync 2>&1
1545    status=$?
1546    if [ ${status} -gt 0 ] ; then
1547      IGCM_debug_Print 2 "IGCM_sys_rebuild : error code ${status}"
1548      cat out_rsync
1549      \rm out_rsync
1550      IGCM_debug_Print 2 "IGCM_sys_rebuild : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1551      firstArg=${1}
1552      \rm ${firstArg}
1553      sleep $DELAI
1554    else
1555      \rm out_rsync
1556      break
1557    fi
1558    (( i = i + 1 ))
1559  done
1560
1561  if [ ${status} -gt 0 ] ; then
1562    echo "IGCM_sys_rebuild : rebuild error code is ${status}"
1563    IGCM_debug_Exit "rebuild"
1564  fi
1565
1566  IGCM_debug_PopStack "IGCM_sys_rebuild"
1567}
1568
1569function IGCM_sys_rebuild_station {
1570  IGCM_debug_PushStack "IGCM_sys_rebuild_station" -- $@
1571  typeset i list_opt file_in file_out prefix_invert list_invert
1572  if ( $DEBUG_sys ) ; then
1573    echo "IGCM_sys_rebuild_station :" $@
1574  fi
1575  list_opt=$@
1576
1577  # Invert Axis : t,x -> x,t
1578  #               t,pres,x -> x,t,pres
1579  # So that we can concatenate along x
1580  i=0
1581  for file_in in ${list_opt} ; do
1582    (( i = i + 1))
1583    [ ${i} = 1 ] && file_out=${file_in} && continue
1584    prefix_invert=$( basename ${file_in} .nc )
1585    IGCM_sys_ncpdq -a x,time_counter -a x,time_counter,presnivs ${file_in} ${prefix_invert}_xt.nc
1586    list_invert[${#list_invert[*]}]=${prefix_invert}_xt.nc
1587  done
1588
1589  # Concatenate
1590  IGCM_sys_ncrcat ${list_invert[*]} histstn_xt.nc
1591
1592  # Re-ivert file
1593  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x histstn_xt.nc ${file_out}
1594
1595  # Station re-ordering is too expansive to be run within libICGM
1596  # This is due to (ncpdq - nrcat - ncpdq) I/O sequence.
1597  # This re-ordering must be done "in memory" by the cmorization process
1598  # Anyway this is the best sequence using (ncpdq - nrcat - ncpdq)
1599  # BEGIN reordering
1600
1601  # Only LMDZ text output contains the exact ordering of the station.
1602  # We isolate this in the code below:
1603  #  0  38  -157.5000000000000  70.98591549295774
1604  #  0  54  27.49999999999999   67.18309859154928
1605  #  0  56  -62.50000000000001  82.39436619718309
1606  #  0  79  12.49999999999999   78.59154929577466
1607  #  0  116 -165.0000000000000  76.05633802816901
1608  #  0  117 130.0000000000000   70.98591549295774
1609  #  0  118 110.0000000000000   87.46478873239437
1610  #  1  40  4.999999999999995   51.97183098591550
1611#  typeset iStation iProc list_opt file_in file_out prefix_invert
1612#  typeset -Z4 j4
1613#  typeset -Z3 j3
1614
1615#  unset list_opt
1616#  set +A list_opt $@
1617
1618  # Filename after rebuild
1619#  file_out=${list_opt[0]}
1620  # Prefix of output files
1621#  prefix_invert=$( basename ${file_out} .nc )
1622  # Number of procs
1623#  num_proc=$( grep -i mpi_size ${PREFIX}_${Exe_Output} | wc -l )
1624
1625#  iProc=0
1626#  while [ ${iProc} -lt ${num_proc} ] ; do
1627    # Array containing Station as a number
1628#    unset proc_stn
1629#    set +A proc_stn $( grep "iophy_mpi rank ip lon lat  $iProc" ${PREFIX}_${Exe_Output} | sed -e "s/iophy_mpi rank ip lon lat //g" | awk ' {print $2}' )
1630    # Number of stations produced by processor proc
1631#    stationLast=${#proc_stn[*]}
1632    # Proc number on 4 digits
1633#    j4=${iProc}
1634    # Init
1635#    iStation=0
1636#    while [ ${iStation} -lt ${stationLast} ] ; do
1637      # Station number on 3 digits
1638#      j3=${proc_stn[${iStation}]}
1639      # Extract station
1640      # Invert Axis : t,x -> x,t
1641      #               t,pres,x -> x,t,pres
1642      # So that we can concatenate along x
1643#      IGCM_sys_ncpdq -a x,time_counter -a x,time_counter,presnivs -d x,$iStation,$iStation ${prefix_invert}_${j4}.nc ${prefix_invert}_stn_${j3}.nc
1644#      (( iStation = iStation + 1 ))
1645#    done
1646#    (( iProc = iProc + 1 ))
1647#  done
1648
1649  # Concatenate all station along x
1650#  IGCM_sys_ncrcat ${prefix_invert}_stn_???.nc ${prefix_invert}_xt.nc
1651
1652  # Re-invert file
1653#  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x ${prefix_invert}_xt.nc ${file_out}
1654
1655  # END reordering
1656
1657  IGCM_debug_PopStack "IGCM_sys_rebuild_station"
1658}
1659
1660############################################################
1661# Activate Running Environnment Variables
1662
1663function IGCM_sys_activ_variables {
1664  IGCM_debug_PushStack "IGCM_sys_activ_variables"
1665  if ( $DEBUG_sys ) ; then
1666    echo "IGCM_sys_activ_variables "
1667  fi
1668
1669  ulimit -s unlimited
1670
1671  IGCM_debug_PopStack "IGCM_sys_activ_variables"
1672}
1673
1674############################################################
1675# Desactivate Running Environnment Variables
1676
1677function IGCM_sys_desactiv_variables {
1678  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1679  if ( $DEBUG_sys ) ; then
1680    echo "IGCM_sys_desactiv_variables "
1681  fi
1682# --------------------------------------------------------------------
1683#D- MPI specifications
1684# --------------------------------------------------------------------
1685
1686# --------------------------------------------------------------------
1687#D- Other specifications
1688# --------------------------------------------------------------------
1689
1690  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1691}
1692
1693############################################################
1694# Build MPI/OMP scripts run file (dummy function)
1695
1696function IGCM_sys_build_run_file {
1697
1698IGCM_debug_Print 3 " dummy function : IGCM_sys_build_run_file "
1699
1700}
1701
1702############################################################
1703# Build MPI/OMP scripts
1704function IGCM_sys_build_execution_scripts
1705{
1706  IGCM_debug_PushStack "IGCM_sys_build_execution_scripts" $@
1707  if ( $DEBUG_sys ) ; then
1708    echo "IGCM_sys_build_execution_scripts " $@
1709  fi
1710
1711  EXECUTION=${HOST_MPIRUN_COMMAND}
1712
1713  if ( ${OK_PARA_MPMD} ) ; then
1714
1715    if [ -f run_file ] ; then
1716      IGCM_sys_Rm -f run_file
1717    fi
1718    touch run_file
1719
1720# run_file construction
1721
1722# Then first loop on the components for the coupler ie oasis
1723
1724### the coupler ie oasis must be the first one
1725    for comp in ${config_ListOfComponents[*]} ; do
1726
1727      eval ExeNameIn=\${config_Executable_${comp}[0]}
1728      eval ExeNameOut=\${config_Executable_${comp}[1]}
1729
1730      # for CPL component only
1731      if [ "X${comp}" = "XCPL" ] ; then
1732
1733        eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1734        eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1735
1736        if ( ${OK_PARA_MPI} ) ; then
1737          (( mpi_count = 1 ))
1738          until [ ${mpi_count} -gt ${comp_proc_mpi_loc} ] ; do
1739            echo "./${ExeNameOut}" >> run_file
1740            (( mpi_count = mpi_count + 1 ))
1741          done
1742        else
1743          echo "./${ExeNameOut} " >> run_file
1744        fi
1745      fi
1746    done
1747
1748# Then second loop on the components
1749
1750    for comp in ${config_ListOfComponents[*]} ; do
1751
1752      eval ExeNameIn=\${config_Executable_${comp}[0]}
1753      eval ExeNameOut=\${config_Executable_${comp}[1]}
1754
1755      # Only if we really have an executable for the component and not the coupler ie oasis:
1756      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${comp}" != "XCPL" ] ) ; then
1757
1758        eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1759        eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1760
1761        if ( ${OK_PARA_MPI} ) ; then
1762          (( mpi_count = 1 ))
1763          until [ ${mpi_count} -gt ${comp_proc_mpi_loc} ] ; do
1764            echo "./${ExeNameOut}" >> run_file
1765            (( mpi_count = mpi_count + 1 ))
1766          done
1767        else
1768            echo "./${ExeNameOut} " >> run_file
1769        fi
1770      fi
1771    done
1772
1773    EXECUTION="${HOST_MPIRUN_COMMAND} -pgmmodel mpmd -cmdfile ./run_file"
1774
1775    IGCM_sys_Chmod u+x run_file
1776    if ( $DEBUG_sys ) ; then
1777      echo "run_file contains : "
1778      cat run_file
1779    fi
1780
1781  else # Only one executable. launch it.
1782
1783    #
1784    for comp in ${config_ListOfComponents[*]} ; do
1785
1786      # Only if we really have an executable for the component :
1787      eval ExeNameOut=\${config_Executable_${comp}[1]}
1788      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${ExeNameOut}" != "Xinca.dat" ] ) ; then
1789        EXECUTION="./${ExeNameOut}"
1790      fi
1791
1792    done
1793
1794  fi
1795
1796  IGCM_debug_Print 1 "sys ada : execution command is "
1797  IGCM_debug_Print 1 "$EXECUTION"
1798
1799  IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
1800}
1801
1802############################################################
1803# Check of space available on temporary filesytems
1804function IGCM_sys_check_quota {
1805  IGCM_debug_PushStack "IGCM_sys_check_quota"
1806  if ( $DEBUG_sys ) ; then
1807    echo "IGCM_sys_check_quota "
1808  fi
1809  # Limit of quota (in %)
1810  limit_quota=90
1811  # Check of the volume
1812  volume_quota=$(quota_u -w | grep 'Quota soft' | awk '{print $5}')
1813  if [ ! X${volume_quota} = X ] ; then
1814    quota_volume=${volume_quota%%\%}
1815#    echo $quota_volume
1816    if [ ${quota_volume} -ge ${limit_quota} ] ; then
1817      IGCM_debug_Print 1 "Please, check your quota of volume on workgpfs"
1818      IGCM_debug_Print 1 "${quota_volume}% of your quota is used"
1819      IGCM_debug_Print 1 "Use the quota_u -w command to check"
1820      IGCM_debug_Print 1 "You must have more than 10% available to run"
1821      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
1822      IGCM_debug_Verif_Exit
1823    fi
1824
1825  fi
1826  IGCM_debug_PopStack "IGCM_sys_check_quota"
1827}
1828
1829#D-#==================================================
1830#D-function IGCM_sys_CountJobInQueue
1831#D-* Purpose: Check if job_name is currently
1832#D-  running or in queue
1833#D-* Examples: IGCM_sys_CountJobInQueue ${JobName} NbRun
1834#D-
1835
1836function IGCM_sys_CountJobInQueue {
1837  IGCM_debug_PushStack "IGCM_sys_CountJobInQueue"
1838  if ( $DEBUG_sys ) ; then
1839    echo "IGCM_sys_CountJobInQueue"
1840  fi
1841
1842  # Print only the full (-W) JobName (%jn)
1843  NbRun=$( llq -W -f %jn | grep -c "$1" )
1844
1845  eval ${2}=${NbRun}
1846
1847  IGCM_debug_PopStack "IGCM_sys_CountJobInQueue"
1848}
1849
1850##############################################################
1851# NCO OPERATOR
1852
1853function IGCM_sys_ncap2 {
1854  IGCM_debug_PushStack "IGCM_sys_ncap2" -- $@
1855  if ( $DEBUG_sys ) ; then
1856    echo "IGCM_sys_ncap2 :" $@
1857  fi
1858
1859  typeset NB_ESSAI DELAI status i
1860  # number of tentative
1861  NB_ESSAI=3
1862  # time delay between tentative
1863  DELAI=2
1864
1865  i=0
1866  while [ $i -lt $NB_ESSAI ] ; do
1867    ncap2 "$@" > out_rsync 2>&1
1868    status=$?
1869    if [ ${status} -gt 0 ] ; then
1870      IGCM_debug_Print 2 "IGCM_sys_ncap2 : error code ${status}"
1871      cat out_rsync
1872      \rm out_rsync
1873      IGCM_debug_Print 2 "IGCM_sys_ncap2 : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1874      sleep $DELAI
1875    else
1876      \rm out_rsync
1877      break
1878    fi
1879    (( i = i + 1 ))
1880  done
1881
1882  if [ ${status} -gt 0 ] ; then
1883      echo "IGCM_sys_ncap2 : ncap2 error"
1884      IGCM_debug_Exit "ncap2"
1885  fi
1886
1887  IGCM_debug_PopStack "IGCM_sys_ncap2"
1888}
1889
1890function IGCM_sys_ncatted {
1891  IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
1892  if ( $DEBUG_sys ) ; then
1893    echo "IGCM_sys_ncatted :" $@
1894  fi
1895
1896  typeset NB_ESSAI DELAI status i
1897  # number of tentative
1898  NB_ESSAI=3
1899  # time delay between tentative
1900  DELAI=2
1901
1902  i=0
1903  while [ $i -lt $NB_ESSAI ] ; do
1904    ncatted "$@" > out_rsync 2>&1
1905    status=$?
1906    if [ ${status} -gt 0 ] ; then
1907      IGCM_debug_Print 2 "IGCM_sys_ncatted : error code ${status}"
1908      cat out_rsync
1909      \rm out_rsync
1910      IGCM_debug_Print 2 "IGCM_sys_ncatted : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1911      sleep $DELAI
1912    else
1913      \rm out_rsync
1914      break
1915    fi
1916    (( i = i + 1 ))
1917  done
1918
1919  if [ ${status} -gt 0 ] ; then
1920      echo "IGCM_sys_ncatted : ncatted error"
1921      IGCM_debug_Exit "ncatted"
1922  fi
1923
1924  IGCM_debug_PopStack "IGCM_sys_ncatted"
1925}
1926
1927function IGCM_sys_ncbo {
1928  IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
1929  if ( $DEBUG_sys ) ; then
1930    echo "IGCM_sys_ncbo :" $@
1931  fi
1932
1933  typeset NB_ESSAI DELAI status i
1934  # number of tentative
1935  NB_ESSAI=3
1936  # time delay between tentative
1937  DELAI=2
1938
1939  i=0
1940  while [ $i -lt $NB_ESSAI ] ; do
1941    ncbo $@ > out_rsync 2>&1
1942    status=$?
1943    if [ ${status} -gt 0 ] ; then
1944      IGCM_debug_Print 2 "IGCM_sys_ncbo : error code ${status}"
1945      cat out_rsync
1946      \rm out_rsync
1947      IGCM_debug_Print 2 "IGCM_sys_ncbo : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1948      sleep $DELAI
1949    else
1950      \rm out_rsync
1951      break
1952    fi
1953    (( i = i + 1 ))
1954  done
1955
1956  if [ ${status} -gt 0 ] ; then
1957      echo "IGCM_sys_ncbo : ncbo error"
1958      IGCM_debug_Exit "ncbo"
1959  fi
1960
1961  IGCM_debug_PopStack "IGCM_sys_ncbo"
1962}
1963
1964function IGCM_sys_ncdiff {
1965  IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
1966  if ( $DEBUG_sys ) ; then
1967    echo "IGCM_sys_ncdiff :" $@
1968  fi
1969
1970  typeset NB_ESSAI DELAI status i
1971  # number of tentative
1972  NB_ESSAI=3
1973  # time delay between tentative
1974  DELAI=2
1975
1976  i=0
1977  while [ $i -lt $NB_ESSAI ] ; do
1978    ncdiff $@ > out_rsync 2>&1
1979    status=$?
1980    if [ ${status} -gt 0 ] ; then
1981      IGCM_debug_Print 2 "IGCM_sys_ncdiff : error code ${status}"
1982      cat out_rsync
1983      \rm out_rsync
1984      IGCM_debug_Print 2 "IGCM_sys_ncdiff : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1985      sleep $DELAI
1986    else
1987      \rm out_rsync
1988      break
1989    fi
1990    (( i = i + 1 ))
1991  done
1992
1993  if [ ${status} -gt 0 ] ; then
1994      echo "IGCM_sys_ncdiff : ncdiff error"
1995      IGCM_debug_Exit "ncdiff"
1996  fi
1997
1998  IGCM_debug_PopStack "IGCM_sys_ncdiff"
1999}
2000
2001function IGCM_sys_ncea {
2002  IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
2003  if ( $DEBUG_sys ) ; then
2004    echo "IGCM_sys_ncea :" $@
2005  fi
2006
2007  typeset NB_ESSAI DELAI status i
2008  # number of tentative
2009  NB_ESSAI=3
2010  # time delay between tentative
2011  DELAI=2
2012
2013  i=0
2014  while [ $i -lt $NB_ESSAI ] ; do
2015    ncea $@ > out_rsync 2>&1
2016    status=$?
2017    if [ ${status} -gt 0 ] ; then
2018      IGCM_debug_Print 2 "IGCM_sys_ncea : error code ${status}"
2019      cat out_rsync
2020      \rm out_rsync
2021      IGCM_debug_Print 2 "IGCM_sys_ncea : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2022      sleep $DELAI
2023    else
2024      \rm out_rsync
2025      break
2026    fi
2027    (( i = i + 1 ))
2028  done
2029
2030  if [ ${status} -gt 0 ] ; then
2031      echo "IGCM_sys_ncea : ncea error"
2032      IGCM_debug_Exit "ncea"
2033  fi
2034
2035  IGCM_debug_PopStack "IGCM_sys_ncea"
2036}
2037
2038function IGCM_sys_ncecat {
2039  IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
2040  if ( $DEBUG_sys ) ; then
2041    echo "IGCM_sys_ncecat :" $@
2042  fi
2043
2044  typeset NB_ESSAI DELAI status i
2045  # number of tentative
2046  NB_ESSAI=3
2047  # time delay between tentative
2048  DELAI=2
2049
2050  i=0
2051  while [ $i -lt $NB_ESSAI ] ; do
2052    ncecat $@ > out_rsync 2>&1
2053    status=$?
2054    if [ ${status} -gt 0 ] ; then
2055      IGCM_debug_Print 2 "IGCM_sys_ncecat : error code ${status}"
2056      cat out_rsync
2057      \rm out_rsync
2058      IGCM_debug_Print 2 "IGCM_sys_ncecat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2059      sleep $DELAI
2060    else
2061      \rm out_rsync
2062      break
2063    fi
2064    (( i = i + 1 ))
2065  done
2066
2067  if [ ${status} -gt 0 ] ; then
2068      echo "IGCM_sys_ncecat : ncecat error"
2069      IGCM_debug_Exit "ncecat"
2070  fi
2071
2072  IGCM_debug_PopStack "IGCM_sys_ncecat"
2073}
2074
2075function IGCM_sys_ncflint {
2076  IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
2077  if ( $DEBUG_sys ) ; then
2078    echo "IGCM_sys_ncflint :" $@
2079  fi
2080
2081  typeset NB_ESSAI DELAI status i
2082  # number of tentative
2083  NB_ESSAI=3
2084  # time delay between tentative
2085  DELAI=2
2086
2087  i=0
2088  while [ $i -lt $NB_ESSAI ] ; do
2089    ncflint $@ > out_rsync 2>&1
2090    status=$?
2091    if [ ${status} -gt 0 ] ; then
2092      IGCM_debug_Print 2 "IGCM_sys_ncflint : error code ${status}"
2093      cat out_rsync
2094      \rm out_rsync
2095      IGCM_debug_Print 2 "IGCM_sys_ncflint : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2096      sleep $DELAI
2097    else
2098      \rm out_rsync
2099      break
2100    fi
2101    (( i = i + 1 ))
2102  done
2103
2104  if [ ${status} -gt 0 ] ; then
2105      echo "IGCM_sys_ncflint : ncflint error"
2106      IGCM_debug_Exit "ncflint"
2107  fi
2108
2109  IGCM_debug_PopStack "IGCM_sys_ncflint"
2110}
2111
2112function IGCM_sys_ncks {
2113  IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
2114  if ( $DEBUG_sys ) ; then
2115    echo "IGCM_sys_ncks :" $@
2116  fi
2117
2118  typeset NB_ESSAI DELAI status i
2119  # number of tentative
2120  NB_ESSAI=3
2121  # time delay between tentative
2122  DELAI=2
2123
2124  i=0
2125  while [ $i -lt $NB_ESSAI ] ; do
2126    ncks $@ > out_rsync 2>&1
2127    status=$?
2128    if [ ${status} -gt 0 ] ; then
2129      IGCM_debug_Print 2 "IGCM_sys_ncks : error code ${status}"
2130      cat out_rsync
2131      \rm out_rsync
2132      IGCM_debug_Print 2 "IGCM_sys_ncks : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2133      sleep $DELAI
2134    else
2135      \rm out_rsync
2136      break
2137    fi
2138    (( i = i + 1 ))
2139  done
2140
2141  if [ ${status} -gt 0 ] ; then
2142      echo "IGCM_sys_ncks : ncks error"
2143      IGCM_debug_Exit "ncks"
2144  fi
2145
2146  IGCM_debug_PopStack "IGCM_sys_ncks"
2147}
2148
2149function IGCM_sys_ncpdq {
2150  IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
2151  if ( $DEBUG_sys ) ; then
2152    echo "IGCM_sys_ncpdq :" $@
2153  fi
2154
2155  typeset NB_ESSAI DELAI status i
2156  # number of tentative
2157  NB_ESSAI=3
2158  # time delay between tentative
2159  DELAI=2
2160
2161  i=0
2162  while [ $i -lt $NB_ESSAI ] ; do
2163    ncpdq $@ > out_rsync 2>&1
2164    status=$?
2165    if [ ${status} -gt 0 ] ; then
2166      IGCM_debug_Print 2 "IGCM_sys_ncpdq : error code ${status}"
2167      cat out_rsync
2168      \rm out_rsync
2169      IGCM_debug_Print 2 "IGCM_sys_ncpdq : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2170      sleep $DELAI
2171    else
2172      \rm out_rsync
2173      break
2174    fi
2175    (( i = i + 1 ))
2176  done
2177
2178  if [ ${status} -gt 0 ] ; then
2179      echo "IGCM_sys_ncpdq : ncpdq error"
2180      IGCM_debug_Exit "ncpdq"
2181  fi
2182
2183  IGCM_debug_PopStack "IGCM_sys_ncpdq"
2184}
2185
2186function IGCM_sys_ncra {
2187  IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
2188  if ( $DEBUG_sys ) ; then
2189    echo "IGCM_sys_ncra :" $@
2190  fi
2191
2192  typeset NB_ESSAI DELAI status i
2193  # number of tentative
2194  NB_ESSAI=3
2195  # time delay between tentative
2196  DELAI=2
2197
2198  i=0
2199  while [ $i -lt $NB_ESSAI ] ; do
2200    ncra $@ > out_rsync 2>&1
2201    status=$?
2202    if [ ${status} -gt 0 ] ; then
2203      IGCM_debug_Print 2 "IGCM_sys_ncra : error code ${status}"
2204      cat out_rsync
2205      \rm out_rsync
2206      IGCM_debug_Print 2 "IGCM_sys_ncra : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2207      sleep $DELAI
2208    else
2209      \rm out_rsync
2210      break
2211    fi
2212    (( i = i + 1 ))
2213  done
2214
2215  if [ ${status} -gt 0 ] ; then
2216      echo "IGCM_sys_ncra : ncra error"
2217      IGCM_debug_Exit "ncra"
2218  fi
2219
2220  IGCM_debug_PopStack "IGCM_sys_ncra"
2221}
2222
2223function IGCM_sys_ncrcat {
2224  IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
2225  if ( $DEBUG_sys ) ; then
2226    echo "IGCM_sys_ncrcat :" $@
2227  fi
2228
2229  typeset NB_ESSAI DELAI status i lastArg
2230  # number of tentative
2231  NB_ESSAI=3
2232  # time delay between tentative
2233  DELAI=2
2234
2235  i=0
2236  while [ $i -lt $NB_ESSAI ] ; do
2237    ncrcat $@ > out_rsync 2>&1
2238    status=$?
2239    if [ ${status} -gt 0 ] ; then
2240      IGCM_debug_Print 2 "IGCM_sys_ncrcat : error code ${status}"
2241      cat out_rsync
2242      \rm out_rsync
2243      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2244      sleep $DELAI
2245    elif [ ! "X$( grep "WARNING Intra-file non-monotonicity" out_rsync )" = "X" ] ; then
2246      IGCM_debug_Print 2 "IGCM_sys_ncrcat : WARNING Intra-file non-monotonicity"
2247      cat out_rsync
2248      # remove files having corrupted time axis
2249      eval lastArg=\${$#}
2250      IGCM_debug_Print 2 "IGCM_sys_ncrcat : Delete ${lastArg}"
2251      \rm ${lastArg}
2252      \rm out_rsync
2253      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2254      sleep $DELAI
2255    else
2256      \rm out_rsync
2257      break
2258    fi
2259    (( i = i + 1 ))
2260  done
2261
2262  if [ ${status} -gt 0 ] ; then
2263      echo "IGCM_sys_ncrcat : ncrcat error"
2264      #IGCM_debug_Exit "ncrcat"
2265  fi
2266
2267  IGCM_debug_PopStack "IGCM_sys_ncrcat"
2268}
2269
2270function IGCM_sys_ncrename {
2271  IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
2272  if ( $DEBUG_sys ) ; then
2273    echo "IGCM_sys_ncrename :" $@
2274  fi
2275
2276  typeset NB_ESSAI DELAI status i
2277  # number of tentative
2278  NB_ESSAI=3
2279  # time delay between tentative
2280  DELAI=2
2281
2282  i=0
2283  while [ $i -lt $NB_ESSAI ] ; do
2284    ncrename $@ > out_rsync 2>&1
2285    status=$?
2286    if [ ${status} -gt 0 ] ; then
2287      IGCM_debug_Print 2 "IGCM_sys_ncrename : error code ${status}"
2288      cat out_rsync
2289      \rm out_rsync
2290      IGCM_debug_Print 2 "IGCM_sys_ncrename : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2291      sleep $DELAI
2292    else
2293      \rm out_rsync
2294      break
2295    fi
2296    (( i = i + 1 ))
2297  done
2298
2299  if [ ${status} -gt 0 ] ; then
2300      echo "IGCM_sys_ncrename : ncrename error"
2301      IGCM_debug_Exit "ncrename"
2302  fi
2303
2304  IGCM_debug_PopStack "IGCM_sys_ncrename"
2305}
2306
2307function IGCM_sys_ncwa {
2308  IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
2309  if ( $DEBUG_sys ) ; then
2310    echo "IGCM_sys_ncwa :" $@
2311  fi
2312
2313  typeset NB_ESSAI DELAI status i
2314  # number of tentative
2315  NB_ESSAI=3
2316  # time delay between tentative
2317  DELAI=2
2318
2319  i=0
2320  while [ $i -lt $NB_ESSAI ] ; do
2321    ncwa $@ > out_rsync 2>&1
2322    status=$?
2323    if [ ${status} -gt 0 ] ; then
2324      IGCM_debug_Print 2 "IGCM_sys_ncwa : error code ${status}"
2325      cat out_rsync
2326      \rm out_rsync
2327      IGCM_debug_Print 2 "IGCM_sys_ncwa : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2328      sleep $DELAI
2329    else
2330      \rm out_rsync
2331      break
2332    fi
2333    (( i = i + 1 ))
2334  done
2335
2336  if [ ${status} -gt 0 ] ; then
2337      echo "IGCM_sys_ncwa : ncwa error"
2338      IGCM_debug_Exit "ncwa"
2339  fi
2340
2341  IGCM_debug_PopStack "IGCM_sys_ncwa"
2342}
2343
2344##############################################################
2345# CDO OPERATOR
2346
2347function IGCM_sys_cdo {
2348  IGCM_debug_PushStack "IGCM_sys_cdo" -- $@
2349  if ( $DEBUG_sys ) ; then
2350    echo "IGCM_sys_cdo :" $@
2351  fi
2352
2353  typeset status
2354
2355  \cdo $@ > out_rsync 2>&1
2356  status=$?
2357  if [ ${status} -gt 0 ] ; then
2358    echo "IGCM_sys_cdo : error code ${status}"
2359    cat out_rsync
2360    \rm out_rsync
2361    IGCM_debug_PopStack "IGCM_sys_cdo"
2362    return 1
2363  else
2364    IGCM_debug_PopStack "IGCM_sys_cdo"
2365    return 0
2366  fi
2367
2368  IGCM_debug_PopStack "IGCM_sys_cdo"
2369}
Note: See TracBrowser for help on using the repository browser.