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

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

house keeping in libIGCM_sys (third pass). Will ease #248 and #251

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