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

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