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

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

Continu to track down SpaceName?=TEST implications at IDRIS

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