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

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

Unlike mfput cp don't create parent directory

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