source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_iitm.ksh @ 1147

Last change on this file since 1147 was 1147, checked in by sdipsl, 9 years ago

broken ensemble. Tentative fix for Agathe. Ensemble are broken since r1057...
broken rebuild station due to changes in LMDZ station files. Tentative fix for Lidia.

  • Property licence set to
    The following licence information concerns ONLY the libIGCM tools
    ==================================================================

    Copyright © Centre National de la Recherche Scientifique CNRS
    Commissariat à l'Énergie Atomique CEA

    libIGCM : Library for Portable Models Computation of IGCM Group.

    IGCM Group is the french IPSL Global Climate Model Group.

    This library is a set of shell scripts and functions whose purpose is
    the management of the initialization, the launch, the transfer of
    output files, the post-processing and the monitoring of datas produce
    by any numerical program on any plateforme.

    This software is governed by the CeCILL license under French law and
    abiding by the rules of distribution of free software. You can use,
    modify and/ or redistribute the software under the terms of the CeCILL
    license as circulated by CEA, CNRS and INRIA at the following URL
    "http://www.cecill.info".

    As a counterpart to the access to the source code and rights to copy,
    modify and redistribute granted by the license, users are provided only
    with a limited warranty and the software's author, the holder of the
    economic rights, and the successive licensors have only limited
    liability.

    In this respect, the user's attention is drawn to the risks associated
    with loading, using, modifying and/or developing or reproducing the
    software by the user in light of its specific status of free software,
    that may mean that it is complicated to manipulate, and that also
    therefore means that it is reserved for developers and experienced
    professionals having in-depth computer knowledge. Users are therefore
    encouraged to load and test the software's suitability as regards their
    requirements in conditions enabling the security of their systems and/or
    data to be ensured and, more generally, to use and operate it in the
    same conditions as regards security.

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