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

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

broken ensemble. Tentative fix for Agathe. Ensemble are broken since r1057...
broken rebuild station due to changes in LMDZ station files. Tentative fix for Lidia.

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