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

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