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

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

Continue adaptation to have the correct behaviour when SpaceName?=TEST

Reminder when SpaceName?=TEST everything will go in ada $WORKDIR not in gaya $HOMEGAYA

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