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

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

Adapt to mfls recent modifications

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