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

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

Bugfixes ada.

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