source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_ada.ksh @ 1129

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

# Nasty hack to overcome /tmp hunting side effect on Ada ...

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