source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_default.ksh @ 1134

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