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

Last change on this file since 1088 was 1088, checked in by sdipsl, 10 years ago

Use --nocoords to solve #192 and the following issue.
ERROR: nco_inq_varid() reports requested variable "t_inst_02678400" is not defined in file
Due to the fact that we have several time axis sampling in one file... not CF ...

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