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

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

Continue to track down SpaceName?=TEST implications at IDRIS

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