source: trunk/libIGCM/libIGCM_sys/libIGCM_sys.ksh @ 1520

Last change on this file since 1520 was 1518, checked in by aclsce, 4 years ago

First import of Irene-amd specifications

  • 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: 47.2 KB
Line 
1#!/bin/ksh
2
3#**************************************************************
4# Author: Martial Mancip
5# Contact: Martial.Mancip__at__ipsl.jussieu.fr
6# $Revision::                                          $ Revision of last commit
7# $Author::                                            $ Author of last commit
8# $Date::                                              $ Date of last commit
9# IPSL (2006)
10#  This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC
11#
12#**************************************************************
13
14# bypass specific internationalization (for gawk)
15export LC_ALL="C"
16
17# By default, all libIGCM_sys save functions will protect output datas (RUN execution mode)
18# other values : DEB(ug), DEV(elopment).
19JobType=${JobType:=RUN}
20
21#====================================================
22# set PackDefault false by default
23PackDefault=false
24
25#====================================================
26# set BigBrother false by default
27BigBrother=${BigBrother:=false}
28
29#====================================================
30# set BigBrother channel (AMQP or MAIL)
31# only MAIL working at present due to firewall constraint
32BigBrotherChannel=MAIL
33
34# no need to be so verbose in checking mode
35if [ ! X${TaskType} = Xchecking ] ; then
36  echo
37  echo "===================================================="
38  echo "Where do we run ?" $( hostname )
39  uname -a
40  echo "===================================================="
41  echo
42fi
43
44if [ X${JobType} = XDEB ] ; then
45    echo "DEBUG mode : activation of 'set -vx' mode."
46    set -vx
47    DEBUG_debug=true
48    DEBUG_sys=true
49fi
50
51#====================================================
52
53case $( hostname -s ) in
54    ada*)
55        [ ! X${TaskType} = Xchecking ] && echo "Source machine dependent settings for ada Intel X-64."
56        CENTER=IDRIS
57        SYSTEM=ada
58        . ${libIGCM}/libIGCM_sys/libIGCM_sys_ada.ksh;;
59    curie*)
60        [ ! X${TaskType} = Xchecking ] && echo "Source machine dependent settings for curie Intel X-64."
61        CENTER=TGCC
62        SYSTEM=curie
63        . ${libIGCM}/libIGCM_sys/libIGCM_sys_curie.ksh;;
64    irene170|irene171|irene190|irene191|irene192|irene193)
65        [ ! X${TaskType} = Xchecking ] && echo "Source machine dependent settings for irene Intel X-64 at TGCC"
66        CENTER=TGCC
67        SYSTEM=irene
68        . ${libIGCM}/libIGCM_sys/libIGCM_sys_irene.ksh;;
69    irene172|irene173|irene194|irene195)
70               [ ! X${TaskType} = Xchecking ] && echo "Source machine dependent settings for irene AMD X-64 at TGCC"
71        CENTER=TGCC
72        SYSTEM=irene-amd
73        . ${libIGCM}/libIGCM_sys/libIGCM_sys_irene-amd.ksh;;
74    airain*)
75        [ ! X${TaskType} = Xchecking ] && echo "Source machine dependent settings for airain Intel X-64."
76        CENTER=TGCC
77        SYSTEM=curie
78        . ${libIGCM}/libIGCM_sys/libIGCM_sys_curie.ksh;;
79    asterix*|obelix*)
80        [ ! X${TaskType} = Xchecking ] && echo "Source machine dependent settings for obelix or asterix."
81        CENTER=LSCE
82        SYSTEM=lxiv8
83        . ${libIGCM}/libIGCM_sys/libIGCM_sys_obelix.ksh;;
84    ciclad*)
85        [ ! X${TaskType} = Xchecking ] && echo "Source machine dependent settings for ciclad for running at ciclad."
86        CENTER=IPSL-ciclad
87        SYSTEM=ifort_CICLAD
88        . ${libIGCM}/libIGCM_sys/libIGCM_sys_ciclad.ksh;;
89    camelot*|loholt1*|loholt2*|merlin*)
90        [ ! X${TaskType} = Xchecking ] && echo "Source machine dependent settings for ciclad for running at climserv."
91        CENTER=IPSL-climserv
92        SYSTEM=ifort_CICLAD
93        . ${libIGCM}/libIGCM_sys/libIGCM_sys_ciclad.ksh;;
94    iitm*)
95        [ ! X${TaskType} = Xchecking ] && echo "Source machine dependent settings for iitm."
96        CENTER=IITM
97        SYSTEM=iitm
98        . ${libIGCM}/libIGCM_sys/libIGCM_sys_iitm.ksh;;
99    *)
100        if [ "${SLURM_CLUSTER_NAME}" = "jean-zay" ] || [ "$( hostname -s |  cut -c "1-8"  )" = "jean-zay" ] ; then
101          [ ! X${TaskType} = Xchecking ] && echo "Source machine dependent settings for Jean-Zay Intel X-64."
102          CENTER=IDRIS
103          SYSTEM=jeanzay
104          . ${libIGCM}/libIGCM_sys/libIGCM_sys_jeanzay.ksh
105        else
106          [ ! X${TaskType} = Xchecking ] && echo "Source machine dependent settings for a default machine."
107          CENTER=DEFAULT
108          SYSTEM=default
109          . ${libIGCM}/libIGCM_sys/libIGCM_sys_default.ksh
110        fi;;
111esac
112# Set default umask (umask is 0027 on some machines : CCRT machine at least)
113umask 0022
114
115#D--------------------------------------------------------------------==
116#D-
117#D-    Define IGCM_sys functions that are common on every systems
118#D-
119#D--------------------------------------------------------------------==
120
121#D-#==================================================
122#D-function IGCM_sys_RshMaster
123#D-* Purpose: Connection to frontend machine.
124#D-* Examples:
125#D-
126function IGCM_sys_RshMaster {
127  IGCM_debug_PushStack "IGCM_sys_RshMaster" $@
128  OUTCOMMAND_PATH=${OUTCOMMAND_PATH} /bin/ksh <<-EOF
129    export libIGCM=${libIGCM}
130    export DEBUG_debug=${DEBUG_debug}
131    . ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh
132    . ${libIGCM}/libIGCM_card/libIGCM_card.ksh
133    ${@}
134EOF
135  if [ $? -gt 0 ] ; then
136    echo "IGCM_sys_RshMaster : erreur."
137    IGCM_debug_Exit "IGCM_sys_RshMaster"
138  fi
139  IGCM_debug_PopStack "IGCM_sys_RshMaster"
140}
141
142#D-#==================================================
143#D-function IGCM_sys_RshPost
144#D-* Purpose: Post-process rsh command
145#D-* Examples:
146#D-
147function IGCM_sys_RshPost {
148  IGCM_debug_PushStack "IGCM_sys_RshPost" $@
149  if ( $DEBUG_sys ) ; then
150    echo "IGCM_sys_RshPost :" $@
151  fi
152  # keep standard input (stdin) for the loop onto temporary file
153  cat >${OUTCOMMAND_PATH}/tmp_IGCM_sys_RshPost_$$_${LOGNAME}
154
155  OUTCOMMAND_PATH=${OUTCOMMAND_PATH} /bin/ksh <${OUTCOMMAND_PATH}/tmp_IGCM_sys_RshPost_$$_${LOGNAME}
156  if [ $? -gt 0 ] ; then
157    echo "IGCM_sys_RshPost : erreur."
158    IGCM_debug_Exit "IGCM_sys_RshPost"
159  fi
160  # delete temporary file
161  \rm ${OUTCOMMAND_PATH}/tmp_IGCM_sys_RshPost_$$_${LOGNAME}
162
163# ============ FRONTEND  END  ============ #
164
165# ============ CESIUM START ============ #
166#  typeset NB_ESSAI DELAI status i
167#  if [ "X$( grep rebuild_from tmp_IGCM_sys_RshPost_$$ )" != "X" ] ; then
168#    #little hack so that rebuild submission is done on titane not an cesium
169#
170#    libIGCM_POST_sed=$( echo $libIGCM_POST | sed 's/\//\\\//g' )
171#    POST_DIR_sed=$( echo ${POST_DIR} | sed 's/\//\\\//g' )
172#    sed "s/IGCM_sys_QsubPost/IGCM_sys_Qsub/g" tmp_IGCM_sys_RshPost_$$ > tmp.txt
173#    sed "s/ rebuild_fromWorkdir/ ${libIGCM_POST_sed}\/rebuild_fromWorkdir.job/g" tmp.txt > tmp_IGCM_sys_RshPost_$$
174#    sed "s/ rebuild_fromArchive/ ${libIGCM_POST_sed}\/rebuild_fromArchive.job/g" tmp_IGCM_sys_RshPost_$$ > tmp.txt
175#    sed "s/Script_Post_Output=/Script_Output=${POST_DIR_sed}\//g" tmp.txt > tmp_IGCM_sys_RshPost_$$
176#    \mv tmp.txt tmp_IGCM_sys_RshPost_$$
177#
178#    echo cat tmp_IGCM_sys_RshPost_$$ AFTER
179#    cat tmp_IGCM_sys_RshPost_$$
180#
181#    /bin/ksh <tmp_IGCM_sys_RshPost_$$
182#    if [ $? -gt 0 ] ; then
183#      echo "IGCM_sys_RshPost : erreur."
184#      IGCM_debug_Exit "IGCM_sys_RshPost"
185#    fi
186#    # delete temporary file
187#    \rm tmp_IGCM_sys_RshPost_$$
188#
189#  else
190#    # number of tentative
191#    NB_ESSAI=10
192#    # time delay between tentative
193#    DELAI=10
194#    i=0
195#    while [ $i -ne $NB_ESSAI ] ; do
196#      ssh -t titane996 ssh cesium /bin/ksh <tmp_IGCM_sys_RshPost_$$
197#      status=$?
198#      if [ ${status} -ne 0 ];
199#      then
200#        sleep $DELAI
201#      else
202#        break
203#      fi
204#      let i=$i+1
205#    done
206#    # delete temporary file
207#    \rm tmp_IGCM_sys_RshPost_$$
208#
209#    if [ ${status} -gt 0 ] ; then
210#      echo "IGCM_sys_RshPost : erreur."
211#      IGCM_debug_Exit "IGCM_sys_RshPost"
212#    fi
213#  fi
214
215# ============ CESIUM  END  ============ #
216
217  IGCM_debug_PopStack "IGCM_sys_RshPost"
218}
219
220#D-#==================================================
221#D-function IGCM_sys_SendMail
222#D-* Purpose: Send mail when simulation is over
223#D-* Examples:
224#D-
225function IGCM_sys_SendMail {
226  IGCM_debug_PushStack "IGCM_sys_SendMail" $@
227  if ( $DEBUG_sys ) ; then
228    echo "IGCM_sys_SendMail :" $@
229  fi
230
231  if [ X${1} = XAccounting ] ; then
232    status=Accounting
233    mailText=jobAccounting.mail
234  elif ( ${ExitFlag} ) ; then
235    status=failed
236    mailText=jobEnd.mail
237  else
238    status=completed
239    mailText=jobEnd.mail
240  fi
241
242  # Update selected mail template
243  while read -r line; do
244    eval echo $line >> mail.txt ;
245  done < ${libIGCM}/libIGCM_sys/${mailText}
246
247  if [ ! -z ${config_UserChoices_MailName} ] ; then
248    mail -s "${config_UserChoices_JobName} ${status}" ${config_UserChoices_MailName} < mail.txt
249  elif [ -f ~/.forward ] ; then
250    mail -s "${config_UserChoices_JobName} ${status}" $( cat ~/.forward ) < mail.txt
251  else
252    mail -s "${config_UserChoices_JobName} ${status}" ${USER} < mail.txt
253  fi
254
255  sleep 10
256  rm -f mail.txt
257
258  IGCM_debug_PopStack "IGCM_sys_SendMail"
259}
260
261#D-#==================================================
262#D-function IGCM_sys_Mkdir
263#D-* Purpose: Master locale mkdir command
264#D-* Examples:
265#D-
266function IGCM_sys_Mkdir {
267  IGCM_debug_PushStack "IGCM_sys_Mkdir" $@
268  if ( $DEBUG_sys ) ; then
269    echo "IGCM_sys_Mkdir :" $@
270  fi
271  if [ ! -d ${1} ]; then
272    \mkdir -p $1
273    if [ $? -gt 0 ] ; then
274      echo "IGCM_sys_Mkdir : erreur."
275      IGCM_debug_Exit "IGCM_sys_Mkdir"
276    fi
277  fi
278  # vérification :
279  if [ ! -d ${1} ] ; then
280    echo "IGCM_sys_Mkdir : erreur."
281    IGCM_debug_Exit "IGCM_sys_Mkdir"
282  fi
283  IGCM_debug_PopStack "IGCM_sys_Mkdir"
284}
285
286#D-#==================================================
287#D-function IGCM_sys_MkdirWork
288#D-* Purpose: Mkdir on Work
289#D-* Examples:
290#D-
291function IGCM_sys_MkdirWork {
292  IGCM_debug_PushStack "IGCM_sys_MkdirWork" $@
293  if ( $DEBUG_sys ) ; then
294    echo "IGCM_sys_MkdirWork :" $@
295  fi
296  #- creation de repertoire sur le serveur fichier
297  if [ ! -d ${1} ]; then
298    \mkdir -p $1
299    if [ $? -gt 0 ] ; then
300      echo "IGCM_sys_MkdirWork : erreur."
301      IGCM_debug_Exit "IGCM_sys_MkdirWork"
302    fi
303  fi
304  IGCM_debug_PopStack "IGCM_sys_MkdirWork"
305}
306
307#D-#==================================================
308#D-function IGCM_sys_Cd
309#D-* Purpose: master cd command
310#D-* Examples:
311#D-
312function IGCM_sys_Cd {
313  IGCM_debug_PushStack "IGCM_sys_Cd" $@
314  if ( $DEBUG_sys ) ; then
315    echo "IGCM_sys_Cd :" $@
316  fi
317  \cd $1
318  if [ $? -gt 0 ] ; then
319    echo "IGCM_sys_Cd : erreur."
320    IGCM_debug_Exit "IGCM_sys_Cd"
321  fi
322  IGCM_debug_PopStack "IGCM_sys_Cd"
323}
324
325#D-#==================================================
326#D-function IGCM_sys_Chmod
327#D-* Purpose: Chmod
328#D-* Examples:
329#D-
330function IGCM_sys_Chmod {
331  IGCM_debug_PushStack "IGCM_sys_Chmod" $@
332  if ( $DEBUG_sys ) ; then
333    echo "IGCM_sys_Chmod :" $@
334  fi
335  \chmod $@
336  if [ $? -gt 0 ] ; then
337    echo "IGCM_sys_Chmod : erreur."
338    IGCM_debug_Exit "IGCM_sys_Chmod"
339  fi
340  IGCM_debug_PopStack "IGCM_sys_Chmod"
341}
342
343#D-#==================================================
344#D-function IGCM_sys_FileSize
345#D-* Purpose: Filesize
346#D-* Examples:
347#D-
348function IGCM_sys_FileSize {
349  IGCM_debug_PushStack "IGCM_sys_FileSize" $@
350
351  typeset sizeF
352  set +A sizeF -- $( ls -la ${1} )
353  if [ $? -gt 0 ] ; then
354    IGCM_debug_Exit "IGCM_sys_FileSize"
355  fi
356  eval ${2}=${sizeF[4]}
357
358  IGCM_debug_PopStack "IGCM_sys_FileSize"
359}
360
361#D-#==================================================
362#D-function IGCM_sys_TestDir
363#D-* Purpose: Test Directory that must exists
364#D-* Examples:
365#D-
366function IGCM_sys_TestDir {
367  IGCM_debug_PushStack "IGCM_sys_TestDir" $@
368  if ( $DEBUG_sys ) ; then
369    echo "IGCM_sys_TestDir :" $@
370  fi
371  typeset ExistFlag
372  ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
373  IGCM_debug_PopStack "IGCM_sys_TestDir"
374
375  return ${ExistFlag}
376}
377
378#D-#==================================================
379#D-function IGCM_sys_TestFileBuffer
380#D-* Purpose: Test file that must NOT EXISTS on Buffer
381#D-* Examples:
382#D-
383function IGCM_sys_TestFileBuffer {
384  IGCM_debug_PushStack "IGCM_sys_TestFileBuffer" $@
385  typeset ExistFlag
386  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
387  IGCM_debug_PopStack "IGCM_sys_TestFileBuffer"
388
389  return ${ExistFlag}
390}
391
392#D-#==================================================
393#D-function IGCM_sys_CountFileBuffer
394#D-* Purpose: Count files on Scratch filesystem
395#D-* Examples:
396#D-
397function IGCM_sys_CountFileBuffer {
398  IGCM_debug_PushStack "IGCM_sys_CountFileBuffer" $@
399  ls ${@} 2>/dev/null | wc -l
400  if [ $? -gt 0 ] ; then
401    echo "IGCM_sys_CountFileBuffer : erreur."
402  fi
403  IGCM_debug_PopStack "IGCM_sys_CountFileBuffer"
404}
405
406#D-#==================================================
407#D-function IGCM_sys_Tar
408#D-* Purpose: master tar command
409#D-* Examples:
410#D-
411function IGCM_sys_Tar {
412  IGCM_debug_PushStack "IGCM_sys_Tar" $@
413  if ( $DEBUG_sys ) ; then
414    echo "IGCM_sys_Tar :" $@
415  fi
416  \tar cf $@
417  if [ $? -gt 0 ] ; then
418    echo "IGCM_sys_Tar : erreur."
419    IGCM_debug_Exit "IGCM_sys_Tar"
420  fi
421  IGCM_debug_PopStack "IGCM_sys_Tar"
422}
423
424#D-#==================================================
425#D-function IGCM_sys_UnTar
426#D-* Purpose: master un-tar command
427#D-* Examples:
428#D-
429function IGCM_sys_UnTar {
430  IGCM_debug_PushStack "IGCM_sys_UnTar" $@
431  if ( $DEBUG_sys ) ; then
432    echo "IGCM_sys_UnTar :" $@
433  fi
434  \tar xvf $1
435  if [ $? -gt 0 ] ; then
436    echo "IGCM_sys_UnTar : erreur."
437    IGCM_debug_Exit "IGCM_sys_UnTar"
438  fi
439  IGCM_debug_PopStack "IGCM_sys_UnTar"
440}
441
442#D-*************************
443#D- File transfer functions
444#D-*************************
445#D-
446
447#D-#==================================================
448#D-function IGCM_sys_Rsync_out
449#D-* Purpose: treat return val of rsync
450#D-* Examples: IGCM_sys_Rsync_out out_RET_rsync
451#D-  Error values and explanations can depend on your system version.
452function IGCM_sys_Rsync_out {
453  IGCM_debug_PushStack "IGCM_sys_Rsync_out" $@
454  if ( $DEBUG_sys ) ; then
455    echo "IGCM_sys_UnTar :" $@
456  fi
457
458  typeset status
459  status=$1
460
461  if [ ! $status ] ; then
462    IGCM_debug_Print 1 "IGCM_sys_Rsync_out need an argument"
463    IGCM_debug_PopStack "IGCM_sys_Rsync_out"
464    return
465  fi
466
467  case $status in
468  0)  ;;
469  1)  IGCM_debug_Print 1 "rsync error RERR_SYNTAX : Syntax or usage error";;
470  2)  IGCM_debug_Print 1 "rsync error RERR_PROTOCOL : Protocol incompatibility";;
471  3)  IGCM_debug_Print 1 "rsync error RERR_FILESELECT : Errors selecting input/output files, dirs";;
472  4)  IGCM_debug_Print 1 "rsync error RERR_UNSUPPORTED : Requested action not supported."
473      IGCM_debug_Print 1 "An attempt was made to manipulate 64-bit files on a platform that cannot support them"
474      IGCM_debug_Print 1 "Or an option was specified that is supported by the client and not by the server.";;
475  5)  IGCM_debug_Print 1 "rsync error  : Error starting client-server protocol";;
476  10) IGCM_debug_Print 1 "rsync error RERR_SOCKETIO : Error in socket I/O";;
477  11) IGCM_debug_Print 1 "rsync error RERR_FILEIO: Error in file I/O";;
478  12) IGCM_debug_Print 1 "rsync error RERR_STREAMIO : Error in rsync protocol data stream";;
479  13) IGCM_debug_Print 1 "rsync error RERR_MESSAGEIO : Errors with program diagnostics";;
480  14) IGCM_debug_Print 1 "rsync error RERR_IPC : Error in IPC code";;
481  20) IGCM_debug_Print 1 "rsync error RERR_SIGNAL : Received SIGUSR1 or SIGINT";;
482  21) IGCM_debug_Print 1 "rsync error RERR_WAITCHILD : Some error returned by waitpid()";;
483  22) IGCM_debug_Print 1 "rsync error RERR_MALLOC : Error allocating core memory buffers";;
484  23) IGCM_debug_Print 1 "rsync error : Partial transfer due to error";;
485  24) IGCM_debug_Print 1 "rsync error : Partial transfer due to vanished source files";;
486  30) IGCM_debug_Print 1 "rsync error : Timeout in data send/receive";;
487  *)  IGCM_debug_Print 1 "rsync error : return code of rsync unknown :" $status;;
488  esac
489
490  IGCM_debug_PopStack "IGCM_sys_Rsync_out"
491}
492
493#D-#==================================================
494#D-function IGCM_sys_Miror_libIGCM
495#D-* Purpose: Mirror libIGCM PATH and lib to frontend
496#D-* Examples:
497#D-
498function IGCM_sys_Mirror_libIGCM {
499  IGCM_debug_PushStack "IGCM_sys_Mirror_libIGCM"
500  if ( $DEBUG_sys ) ; then
501    echo "IGCM_sys_Mirror_libIGCM"
502  fi
503
504  typeset status
505
506  mkdir -p ${HOME}/MIRROR/${PATHlibIGCM}
507
508  echo ${RSYNC} ${RSYNC_opt} ${libIGCM} ${HOME}/MIRROR/${PATHlibIGCM} > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
509  ${RSYNC} ${RSYNC_opt} ${libIGCM} ${HOME}/MIRROR/${PATHlibIGCM} >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
510  status=$?
511
512  if [ ${status} -gt 0 ] ; then
513    echo "IGCM_sys_Mirror_libIGCM Warning : no libIGCM on frontend."
514    cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
515  fi
516  IGCM_debug_PopStack "IGCM_sys_Mirror_libIGCM"
517}
518
519#D-#==================================================
520#D-function IGCM_sys_Cp
521#D-* Purpose: generic cp
522#D-* Examples:
523#D-
524function IGCM_sys_Cp {
525  IGCM_debug_PushStack "IGCM_sys_Cp" $@
526  if ( $DEBUG_sys ) ; then
527    echo "IGCM_sys_Cp :" $@
528  fi
529
530  typeset status
531
532  echo cp $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
533  \cp $@ >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
534  status=$?
535
536  if [ ${status} -gt 0 ] ; then
537    echo "IGCM_sys_Cp : error code ${status}"
538    cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
539    IGCM_debug_Exit "IGCM_sys_Cp"
540  else
541    \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
542  fi
543  IGCM_debug_PopStack "IGCM_sys_Cp"
544}
545
546#D-#==================================================
547#D-function IGCM_sys_Rm
548#D-* Purpose: generic rm
549#D-* Examples:
550#D-
551function IGCM_sys_Rm {
552  IGCM_debug_PushStack "IGCM_sys_Rm" $@
553  if ( $DEBUG_sys ) ; then
554    echo "IGCM_sys_Rm :" $@
555  fi
556
557  typeset status
558
559  echo rm $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
560  \rm $@ >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
561  status=$?
562
563  if [ ${status} -gt 0 ] ; then
564    echo "IGCM_sys_Rm : error code ${status}"
565    cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
566    IGCM_debug_Exit "IGCM_sys_Rm"
567  else
568    \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
569  fi
570  IGCM_debug_PopStack "IGCM_sys_Rm"
571}
572
573#D-#==================================================
574#D-function IGCM_sys_Mv
575#D-* Purpose: generic move
576#D-* Examples:
577#D-
578function IGCM_sys_Mv {
579  IGCM_debug_PushStack "IGCM_sys_Mv" $@
580  if ( $DEBUG_sys ) ; then
581    echo "IGCM_sys_Mv :" $@
582  fi
583
584  if [ $DRYRUN = 0 ]; then
585
586    typeset status
587
588    echo mv $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
589    \mv $@ >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
590    status=$?
591
592    if [ ${status} -gt 0 ] ; then
593      echo "IGCM_sys_Mv : error code ${status}"
594      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
595      IGCM_debug_Exit "IGCM_sys_Mv"
596    else
597      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
598    fi
599  fi
600  IGCM_debug_PopStack "IGCM_sys_Mv"
601}
602
603#D-#==================================================
604#D-function IGCM_sys_Get_Master
605#D-* Purpose: Copy a complete directory from MASTER filesystem
606#D-* Examples:
607#D-
608function IGCM_sys_Get_Master {
609  IGCM_debug_PushStack "IGCM_sys_Get_Master" $@
610  if ( $DEBUG_sys ) ; then
611    echo "IGCM_sys_Get_Master :" $@
612  fi
613  if [ $DRYRUN = 0 ]; then
614    if ( [ ! -d ${1} ] && [ ! -f ${1} ] ) ; then
615      echo "WARNING : IGCM_sys_Get_Master ${1} DOES NOT EXIST ."
616      IGCM_debug_PopStack "IGCM_sys_Get_Master"
617      return
618    fi
619
620    typeset NB_ESSAI DELAI status i
621    # number of tentative
622    NB_ESSAI=3
623    # time delay between tentative
624    DELAI=2
625
626    i=0
627    while [ $i -lt $NB_ESSAI ] ; do
628      \cp -urL $1 $2 > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
629      status=$?
630      if [ ${status} -gt 0 ]; then
631        IGCM_debug_Print 2 "IGCM_sys_Get_Master : cp failed error code ${status} ${i}/${NB_ESSAI}"
632        IGCM_debug_Print 2 "IGCM_sys_Get_Master : sleep ${DELAI} seconds and try again."
633        sleep $DELAI
634      else
635        break
636      fi
637      (( i = i + 1 ))
638    done
639
640    if [ ${status} -gt 0 ] ; then
641      echo "IGCM_sys_Get_Master : error."
642      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
643      IGCM_debug_Exit "IGCM_sys_Get_Master"
644    else
645      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
646    fi
647  fi
648  IGCM_debug_PopStack "IGCM_sys_Get_Master"
649}
650
651#====================================================
652#- Call IGCM_sys_Mirror_libIGCM now !
653if ( $MirrorlibIGCM ) ; then
654  IGCM_sys_Mirror_libIGCM
655fi
656
657#D-#==================================================
658#D-function IGCM_sys_PutBuffer_Rest
659#D-* Purpose: Put computied restarts on ${SCRATCHDIR}.
660#D-           File and target directory must exist.
661#D-* Examples:
662#D-
663function IGCM_sys_PutBuffer_Rest {
664  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Rest" $@
665  if ( $DEBUG_sys ) ; then
666    echo "IGCM_sys_PutBuffer_Rest :" $@
667  fi
668  if [ $DRYRUN = 0 ]; then
669    if [ ! -f ${1} ] ; then
670      echo "ERROR : IGCM_sys_PutBuffer_Rest ${1} DOES NOT EXIST ."
671      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
672    fi
673
674    typeset status
675    #
676    # USUAL WAY
677    \cp $1 $2 > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
678    status=$?
679
680    if [ ${status} -gt 0 ] ; then
681      echo "IGCM_sys_PutBuffer_Rest : error code ${status}"
682      [ -f ${2} ] && ls -l ${2}
683      [ -f ${2}/${1} ] && ls -l ${2}/${1}
684      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
685      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
686    else
687
688      if [ X${JobType} = XRUN ] ; then
689        [ -f ${2} ] && IGCM_sys_Chmod 444 ${2}
690        [ -f ${2}/${1} ] && IGCM_sys_Chmod 444 ${2}/${1}
691      fi
692
693      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
694    fi
695  fi
696  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Rest"
697}
698
699#D-#==================================================
700#D-function IGCM_sys_PrepareTaredRestart
701#D-* Purpose: Prepare tared restart to be access by computing job.
702#D-* Examples:
703#D-
704function IGCM_sys_PrepareTaredRestart {
705  IGCM_debug_PushStack "IGCM_sys_PrepareTaredRestart" $@
706  if [ $DRYRUN = 0 ]; then
707    [ ! -f $( basename $1 ) ] && IGCM_sys_Get $1 .
708  fi
709  IGCM_debug_PopStack "IGCM_sys_PrepareTaredRestart"
710}
711
712#D-#==================================================
713#D-function IGCM_sys_PutBuffer_Out
714#D-* Purpose: Copy a file on the buffer filesystem after having chmod it in readonly
715#D-* Examples:
716#D-
717function IGCM_sys_PutBuffer_Out {
718  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Out" $@
719  if ( $DEBUG_sys ) ; then
720    echo "IGCM_sys_PutBuffer_Out :" $@
721  fi
722
723  typeset NB_ESSAI DELAI status i exist skip
724  typeset fileDeviceNumberInHex directoryDeviceNumberInHex
725
726  # number of tentative
727  NB_ESSAI=3
728  # time delay between tentative
729  DELAI=2
730
731  if [ $DRYRUN = 0 ]; then
732    if [ ! -f ${1} ] ; then
733      echo "WARNING : IGCM_sys_PutBuffer_Out ${1} DOES NOT EXIST ."
734      IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
735      return 1
736    fi
737    #
738    IGCM_sys_Mkdir $( dirname $2 )
739    #
740
741    exist=false
742    skip=false
743    if [ -f $2 ] ; then
744      IGCM_debug_Print 1 "$2 already exist"
745      exist=true
746      if [ "X$( diff $1 $2 )" = X ] ; then
747        IGCM_debug_Print 2 "$1 and $2 are the same file, we skip the copy"
748        status=0
749        skip=true
750      else
751        IGCM_debug_Print 2 "$1 and $2 are not the same file, we force the copy"
752        skip=false
753      fi
754    fi
755    #
756    if ( [ X${exist} = Xtrue ] && [ X${skip} = Xfalse ] ) ; then
757      IGCM_sys_Chmod u+w $2
758    fi
759
760    if [ X${skip} = Xfalse ] ; then
761      i=0
762      while [ $i -lt $NB_ESSAI ] ; do
763        # Identify file system
764        fileDeviceNumberInHex=$( stat -c %d $1 )
765        status=$?
766        if [ ${status} -gt 0 ] ; then
767          IGCM_debug_Exit "IGCM_sys_PutBuffer_Out"
768        fi
769        # Identify file system
770        directoryDeviceNumberInHex=$( stat -c %d $( dirname $2 ) )
771        status=$?
772        if [ ${status} -gt 0 ] ; then
773          IGCM_debug_Exit "IGCM_sys_PutBuffer_Out"
774        fi
775
776        if [ ${fileDeviceNumberInHex} -ne ${directoryDeviceNumberInHex} ] ; then
777          # They are not on the same device. USUAL WAY
778          \cp $1 $2 > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
779          status=$?
780        else
781          # They are on the same device. USUAL WAY
782          \mv $1 $2 > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
783          status=$?
784        fi
785        if [ ${status} -gt 0 ]; then
786          IGCM_debug_Print 2 "IGCM_sys_PutBuffer_Out : cp failed error code ${status} ${i}/${NB_ESSAI}"
787          IGCM_debug_Print 2 "IGCM_sys_PutBuffer_Out : sleep ${DELAI} seconds and try again."
788          [ -f ${2} ] && ls -l ${2}
789          [ -f ${2}/${1} ] && ls -l ${2}/${1}
790          sleep $DELAI
791        else
792          break
793        fi
794        (( i = i + 1 ))
795      done
796    fi
797
798    if [ ${status} -gt 0 ] ; then
799      echo "IGCM_sys_PutBuffer_Out : error."
800      [ -f ${2} ] && ls -l ${2}
801      [ -f ${2}/${1} ] && ls -l ${2}/${1}
802      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
803      IGCM_debug_Exit "IGCM_sys_PutBuffer_Out"
804    else
805
806      if [ X${JobType} = XRUN ] ; then
807        if [ X${3} = X ] ; then
808          [ -f ${2} ] && IGCM_sys_Chmod 444 ${2}
809          [ -f ${2}/${1} ] && IGCM_sys_Chmod 444 ${2}/${1}
810        fi
811      fi
812
813      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
814    fi
815  fi
816  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
817  return 0
818}
819
820#D-#==================================================
821#D-function IGCM_sys_GetBuffer
822#D-* Purpose: Get a file from ${SCRATCHDIR}
823#D-* Examples: IGCM_sys_GetBuffer myfile /destpath/myfile_with_PREFIX
824#D-            IGCM_sys_GetBuffer /l Array_contain_myfiles /destpath/
825function IGCM_sys_GetBuffer {
826  IGCM_debug_PushStack "IGCM_sys_GetBuffer" $@
827
828  typeset DEST buf_liste target file_work
829  typeset NB_ESSAI DELAI status i
830
831  if ( $DEBUG_sys ) ; then
832    echo "IGCM_sys_GetBuffer :" $@
833  fi
834
835  # number of tentative
836  NB_ESSAI=3
837  # time delay between tentative
838  DELAI=2
839
840  if [ $DRYRUN -le 2 ]; then
841    if [ X${1} = X'/l' ] ; then
842      eval set +A buf_liste \${${2}}
843    else
844      eval set +A buf_liste ${1}
845    fi
846    eval DEST=\${${#}}
847
848    #USUAL WAY
849    if [ X${1} = X'/l' ] ; then
850      for target in ${buf_liste[*]} ; do
851        local_file=$( basename ${target} )
852        i=0
853        while [ $i -lt $NB_ESSAI ] ; do
854          \cp ${target} ${DEST}/${local_file} >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
855          status=$?
856          if [ ${status} -gt 0 ]; then
857            IGCM_debug_Print 2 "IGCM_sys_GetBuffer : cp failed error code ${status} ${i}/${NB_ESSAI}"
858            IGCM_debug_Print 2 "IGCM_sys_GetBuffer : sleep ${DELAI} seconds and try again."
859            sleep $DELAI
860          else
861            break
862          fi
863          (( i = i + 1 ))
864        done
865        if [ ${status} -gt 0 ] ; then
866          echo "IGCM_sys_Get : error"
867          cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
868          \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
869          IGCM_debug_Exit "IGCM_sys_GetBuffer"
870        else
871          \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
872        fi
873      done
874    else
875      i=0
876      while [ $i -lt $NB_ESSAI ] ; do
877        \cp ${buf_liste} ${DEST} >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
878        status=$?
879        if [ ${status} -gt 0 ]; then
880          IGCM_debug_Print 2 "IGCM_sys_GetBuffer : cp failed error code ${status} ${i}/${NB_ESSAI}"
881          IGCM_debug_Print 2 "IGCM_sys_GetBuffer : sleep ${DELAI} seconds and try again."
882          sleep $DELAI
883        else
884          break
885        fi
886        (( i = i + 1 ))
887      done
888      if [ ${status} -gt 0 ] ; then
889        echo "IGCM_sys_Get : error"
890        cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
891        \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
892        IGCM_debug_Exit "IGCM_sys_GetBuffer"
893      else
894        \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
895      fi
896    fi
897  fi
898  IGCM_debug_PopStack "IGCM_sys_GetBuffer"
899}
900
901#D-#==================================================
902#D-function IGCM_sys_GetDate_FichWork
903#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
904#D-* Examples:
905#D-
906function IGCM_sys_GetDate_FichWork {
907  IGCM_debug_PushStack "IGCM_sys_GetDate_FichWork" $@
908  if ( $DEBUG_sys ) ; then
909    echo "IGCM_sys_GetDate_FichWork :" $@
910  fi
911
912  if [ $# -ge 3 ] ; then
913    mode=$3
914    TimeStyle=$4
915  else
916    mode="default"
917    TimeStyle="%Y%m%d%H%M%S"
918  fi
919
920  typeset dateF
921  set +A dateF -- $( ls -l --full-time --time-style=+"${TimeStyle}" ${1} )
922
923  case $mode in
924    "default")
925      eval ${2}=${dateF[5]}
926      ;;
927    "SplitFields")
928      eval ${2}="${dateF[5]}\ ${dateF[6]}"
929      ;;
930  esac
931
932  # donne la date filesys d'un fichier sur la machine work
933  IGCM_debug_PopStack "IGCM_sys_GetDate_FichWork"
934}
935
936#D-#==================================================
937#D-function IGCM_sys_rebuild
938#D-* Purpose: rebuild parallel files
939#D-* Examples:
940#D-
941function IGCM_sys_rebuild {
942  IGCM_debug_PushStack "IGCM_sys_rebuild" $@
943  if ( $DEBUG_sys ) ; then
944    echo "IGCM_sys_rebuild :" $@
945  fi
946
947  typeset NB_ESSAI DELAI status i firstArg
948  # number of tentative
949  NB_ESSAI=3
950  # time delay between tentative
951  DELAI=2
952
953  i=0
954  while [ $i -lt $NB_ESSAI ] ; do
955    rebuild -f -o $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
956    status=$?
957    if [ ${status} -gt 0 ] ; then
958      IGCM_debug_Print 2 "IGCM_sys_rebuild : error code ${status}"
959      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
960      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
961      IGCM_debug_Print 2 "IGCM_sys_rebuild : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
962      firstArg=${1}
963      \rm ${firstArg}
964      sleep $DELAI
965    else
966      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
967      break
968    fi
969    (( i = i + 1 ))
970  done
971
972  if [ ${status} -gt 0 ] ; then
973    echo "IGCM_sys_rebuild : rebuild error code is ${status}"
974    IGCM_debug_Exit "rebuild"
975  fi
976
977  IGCM_debug_PopStack "IGCM_sys_rebuild"
978}
979
980#D-#==================================================
981#D-function IGCM_sys_rebuild_station
982#D-* Purpose: rebuild parallel files describing station
983#D-* Examples:
984#D-
985function IGCM_sys_rebuild_station {
986  IGCM_debug_PushStack "IGCM_sys_rebuild_station" $@
987  typeset i list_opt file_in file_out prefix_invert list_invert
988  if ( $DEBUG_sys ) ; then
989    echo "IGCM_sys_rebuild_station :" $@
990  fi
991
992  # Station re-ordering is too expansive to be run within libIGCM
993  # This is due to (ncpdq - nrcat - ncpdq) I/O sequence.
994  # This re-ordering must be done "in memory" by the cmorization process
995
996  # Only LMDZ text output contains the exact ordering of the station.
997  # We isolate this in the code below:
998  #  0  38  -157.5000000000000  70.98591549295774
999  #  0  54  27.49999999999999   67.18309859154928
1000  #  0  56  -62.50000000000001  82.39436619718309
1001  #  0  79  12.49999999999999   78.59154929577466
1002  #  0  116 -165.0000000000000  76.05633802816901
1003  #  0  117 130.0000000000000   70.98591549295774
1004  #  0  118 110.0000000000000   87.46478873239437
1005  #  1  40  4.999999999999995   51.97183098591550
1006
1007  list_opt=$@
1008
1009  # Invert Axis : t,x -> x,t
1010  #               t,pres,x -> x,t,pres
1011  # So that we can concatenate along x
1012  i=0
1013  for file_in in ${list_opt} ; do
1014    (( i = i + 1))
1015    [ ${i} = 1 ] && file_out=${file_in} && continue
1016    # detect time counter and do the job only if present
1017    var_unlim=$(ncdump -h ${file_in} | grep UNLIMITED | cut -d ' ' -f 1 | sed -e 's/^[ \t]*//' -e 's/[ \t]*$//')
1018    if [ X${var_unlim} = Xtime_counter ] ; then
1019      prefix_invert=$( basename ${file_in} .nc )
1020      IGCM_sys_ncpdq -a x,time_counter -a x,time_counter,presnivs ${file_in} ${prefix_invert}_xt.nc
1021      list_invert[${#list_invert[*]}]=${prefix_invert}_xt.nc
1022    fi
1023  done
1024
1025  # Concatenate
1026  IGCM_sys_ncrcat ${list_invert[*]} histstn_xt.nc
1027
1028  # Re-ivert file
1029  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x histstn_xt.nc ${file_out}
1030
1031  IGCM_debug_PopStack "IGCM_sys_rebuild_station"
1032}
1033
1034##############################################################
1035# NCO OPERATOR
1036
1037#D-#==================================================
1038#D-function IGCM_sys_ncap2
1039#D-* Purpose: encapsulate ncap2 call so as to manage error code and retry
1040#D-* Examples:
1041#D-
1042function IGCM_sys_ncap2 {
1043  IGCM_debug_PushStack "IGCM_sys_ncap2" $@
1044  if ( $DEBUG_sys ) ; then
1045    echo "IGCM_sys_ncap2 :" $@
1046  fi
1047
1048  typeset NB_ESSAI DELAI status i
1049  # number of tentative
1050  NB_ESSAI=3
1051  # time delay between tentative
1052  DELAI=2
1053
1054  i=0
1055  while [ $i -lt $NB_ESSAI ] ; do
1056    ncap2 -C --buffer_size 838860800 "$@" > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
1057    status=$?
1058    if [ ${status} -gt 0 ] ; then
1059      IGCM_debug_Print 2 "IGCM_sys_ncap2 : error code ${status}"
1060      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1061      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1062      IGCM_debug_Print 2 "IGCM_sys_ncap2 : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1063      sleep $DELAI
1064    else
1065      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1066      break
1067    fi
1068    (( i = i + 1 ))
1069  done
1070
1071  if [ ${status} -gt 0 ] ; then
1072    echo "IGCM_sys_ncap2 : ncap2 error"
1073    IGCM_debug_Exit "ncap2"
1074  fi
1075
1076  IGCM_debug_PopStack "IGCM_sys_ncap2"
1077}
1078
1079#D-#==================================================
1080#D-function IGCM_sys_ncatted
1081#D-* Purpose: encapsulate ncatted call so as to manage error code and retry
1082#D-* Examples:
1083#D-
1084function IGCM_sys_ncatted {
1085  IGCM_debug_PushStack "IGCM_sys_ncatted" $@
1086  if ( $DEBUG_sys ) ; then
1087    echo "IGCM_sys_ncatted :" $@
1088  fi
1089
1090  typeset NB_ESSAI DELAI status i
1091  # number of tentative
1092  NB_ESSAI=3
1093  # time delay between tentative
1094  DELAI=2
1095
1096  i=0
1097  while [ $i -lt $NB_ESSAI ] ; do
1098    ncatted "$@" > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
1099    status=$?
1100    if [ ${status} -gt 0 ] ; then
1101      IGCM_debug_Print 2 "IGCM_sys_ncatted : error code ${status}"
1102      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1103      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1104      IGCM_debug_Print 2 "IGCM_sys_ncatted : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1105      sleep $DELAI
1106    else
1107      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1108      break
1109    fi
1110    (( i = i + 1 ))
1111  done
1112
1113  if [ ${status} -gt 0 ] ; then
1114    echo "IGCM_sys_ncatted : ncatted error"
1115    IGCM_debug_Exit "ncatted"
1116  fi
1117
1118  IGCM_debug_PopStack "IGCM_sys_ncatted"
1119}
1120
1121#D-#==================================================
1122#D-function IGCM_sys_ncbo
1123#D-* Purpose: encapsulate ncbo call so as to manage error code and retry
1124#D-* Examples:
1125#D-
1126function IGCM_sys_ncbo {
1127  IGCM_debug_PushStack "IGCM_sys_ncbo" $@
1128  if ( $DEBUG_sys ) ; then
1129    echo "IGCM_sys_ncbo :" $@
1130  fi
1131
1132  typeset NB_ESSAI DELAI status i
1133  # number of tentative
1134  NB_ESSAI=3
1135  # time delay between tentative
1136  DELAI=2
1137
1138  i=0
1139  while [ $i -lt $NB_ESSAI ] ; do
1140    ncbo -C --buffer_size 838860800 $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
1141    status=$?
1142    if [ ${status} -gt 0 ] ; then
1143      IGCM_debug_Print 2 "IGCM_sys_ncbo : error code ${status}"
1144      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1145      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1146      IGCM_debug_Print 2 "IGCM_sys_ncbo : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1147      sleep $DELAI
1148    else
1149      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1150      break
1151    fi
1152    (( i = i + 1 ))
1153  done
1154
1155  if [ ${status} -gt 0 ] ; then
1156    echo "IGCM_sys_ncbo : ncbo error"
1157    IGCM_debug_Exit "ncbo"
1158  fi
1159
1160  IGCM_debug_PopStack "IGCM_sys_ncbo"
1161}
1162
1163#D-#==================================================
1164#D-function IGCM_sys_ncdif
1165#D-* Purpose: encapsulate ncdiff call so as to manage error code and retry
1166#D-* Examples:
1167#D-
1168function IGCM_sys_ncdiff {
1169  IGCM_debug_PushStack "IGCM_sys_ncdiff" $@
1170  if ( $DEBUG_sys ) ; then
1171    echo "IGCM_sys_ncdiff :" $@
1172  fi
1173
1174  typeset NB_ESSAI DELAI status i
1175  # number of tentative
1176  NB_ESSAI=3
1177  # time delay between tentative
1178  DELAI=2
1179
1180  i=0
1181  while [ $i -lt $NB_ESSAI ] ; do
1182    ncdiff -C --buffer_size 838860800 $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
1183    status=$?
1184    if [ ${status} -gt 0 ] ; then
1185      IGCM_debug_Print 2 "IGCM_sys_ncdiff : error code ${status}"
1186      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1187      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1188      IGCM_debug_Print 2 "IGCM_sys_ncdiff : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1189      sleep $DELAI
1190    else
1191      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1192      break
1193    fi
1194    (( i = i + 1 ))
1195  done
1196
1197  if [ ${status} -gt 0 ] ; then
1198    echo "IGCM_sys_ncdiff : ncdiff error"
1199    IGCM_debug_Exit "ncdiff"
1200  fi
1201
1202  IGCM_debug_PopStack "IGCM_sys_ncdiff"
1203}
1204
1205#D-#==================================================
1206#D-function IGCM_sys_ncea
1207#D-* Purpose: encapsulate ncea call so as to manage error code and retry
1208#D-* Examples:
1209#D-
1210function IGCM_sys_ncea {
1211  IGCM_debug_PushStack "IGCM_sys_ncea" $@
1212  if ( $DEBUG_sys ) ; then
1213    echo "IGCM_sys_ncea :" $@
1214  fi
1215
1216  typeset NB_ESSAI DELAI status i
1217  # number of tentative
1218  NB_ESSAI=3
1219  # time delay between tentative
1220  DELAI=2
1221
1222  i=0
1223  while [ $i -lt $NB_ESSAI ] ; do
1224    ncea -C --buffer_size 838860800 $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
1225    status=$?
1226    if [ ${status} -gt 0 ] ; then
1227      IGCM_debug_Print 2 "IGCM_sys_ncea : error code ${status}"
1228      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1229      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1230      IGCM_debug_Print 2 "IGCM_sys_ncea : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1231      sleep $DELAI
1232    else
1233      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1234      break
1235    fi
1236    (( i = i + 1 ))
1237  done
1238
1239  if [ ${status} -gt 0 ] ; then
1240    echo "IGCM_sys_ncea : ncea error"
1241    IGCM_debug_Exit "ncea"
1242  fi
1243
1244  IGCM_debug_PopStack "IGCM_sys_ncea"
1245}
1246
1247#D-#==================================================
1248#D-function IGCM_sys_ncecat
1249#D-* Purpose: encapsulate ncecat call so as to manage error code and retry
1250#D-* Examples:
1251#D-
1252function IGCM_sys_ncecat {
1253  IGCM_debug_PushStack "IGCM_sys_ncecat" $@
1254  if ( $DEBUG_sys ) ; then
1255    echo "IGCM_sys_ncecat :" $@
1256  fi
1257
1258  typeset NB_ESSAI DELAI status i
1259  # number of tentative
1260  NB_ESSAI=3
1261  # time delay between tentative
1262  DELAI=2
1263
1264  i=0
1265  while [ $i -lt $NB_ESSAI ] ; do
1266    ncecat -C --buffer_size 838860800 $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
1267    status=$?
1268    if [ ${status} -gt 0 ] ; then
1269      IGCM_debug_Print 2 "IGCM_sys_ncecat : error code ${status}"
1270      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1271      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1272      IGCM_debug_Print 2 "IGCM_sys_ncecat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1273      sleep $DELAI
1274    else
1275      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1276      break
1277    fi
1278    (( i = i + 1 ))
1279  done
1280
1281  if [ ${status} -gt 0 ] ; then
1282    echo "IGCM_sys_ncecat : ncecat error"
1283    IGCM_debug_Exit "ncecat"
1284  fi
1285
1286  IGCM_debug_PopStack "IGCM_sys_ncecat"
1287}
1288
1289#D-#==================================================
1290#D-function IGCM_sys_ncflint
1291#D-* Purpose: encapsulate ncflint call so as to manage error code and retry
1292#D-* Examples:
1293#D-
1294function IGCM_sys_ncflint {
1295  IGCM_debug_PushStack "IGCM_sys_ncflint" $@
1296  if ( $DEBUG_sys ) ; then
1297    echo "IGCM_sys_ncflint :" $@
1298  fi
1299
1300  typeset NB_ESSAI DELAI status i
1301  # number of tentative
1302  NB_ESSAI=3
1303  # time delay between tentative
1304  DELAI=2
1305
1306  i=0
1307  while [ $i -lt $NB_ESSAI ] ; do
1308    ncflint -C --buffer_size 838860800 $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
1309    status=$?
1310    if [ ${status} -gt 0 ] ; then
1311      IGCM_debug_Print 2 "IGCM_sys_ncflint : error code ${status}"
1312      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1313      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1314      IGCM_debug_Print 2 "IGCM_sys_ncflint : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1315      sleep $DELAI
1316    else
1317      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1318      break
1319    fi
1320    (( i = i + 1 ))
1321  done
1322
1323  if [ ${status} -gt 0 ] ; then
1324    echo "IGCM_sys_ncflint : ncflint error"
1325    IGCM_debug_Exit "ncflint"
1326  fi
1327
1328  IGCM_debug_PopStack "IGCM_sys_ncflint"
1329}
1330
1331#D-#==================================================
1332#D-function IGCM_sys_ncks
1333#D-* Purpose: encapsulate ncks call so as to manage error code and retry
1334#D-* Examples:
1335#D-
1336function IGCM_sys_ncks {
1337  IGCM_debug_PushStack "IGCM_sys_ncks" $@
1338  if ( $DEBUG_sys ) ; then
1339    echo "IGCM_sys_ncks :" $@
1340  fi
1341
1342  typeset NB_ESSAI DELAI status i
1343  # number of tentative
1344  NB_ESSAI=3
1345  # time delay between tentative
1346  DELAI=2
1347
1348  i=0
1349  while [ $i -lt $NB_ESSAI ] ; do
1350    ncks -C --buffer_size 838860800 $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
1351    status=$?
1352    if [ ${status} -gt 0 ] ; then
1353      IGCM_debug_Print 2 "IGCM_sys_ncks : error code ${status}"
1354      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1355      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1356      IGCM_debug_Print 2 "IGCM_sys_ncks : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1357      sleep $DELAI
1358    else
1359      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1360      break
1361    fi
1362    (( i = i + 1 ))
1363  done
1364
1365  if [ ${status} -gt 0 ] ; then
1366    echo "IGCM_sys_ncks : ncks error"
1367    IGCM_debug_Exit "ncks"
1368  fi
1369
1370  IGCM_debug_PopStack "IGCM_sys_ncks"
1371}
1372
1373#D-#==================================================
1374#D-function IGCM_sys_ncpdq
1375#D-* Purpose: encapsulate ncpdq call so as to manage error code and retry
1376#D-* Examples:
1377#D-
1378function IGCM_sys_ncpdq {
1379  IGCM_debug_PushStack "IGCM_sys_ncpdq" $@
1380  if ( $DEBUG_sys ) ; then
1381    echo "IGCM_sys_ncpdq :" $@
1382  fi
1383
1384  typeset NB_ESSAI DELAI status i
1385  # number of tentative
1386  NB_ESSAI=3
1387  # time delay between tentative
1388  DELAI=2
1389
1390  i=0
1391  while [ $i -lt $NB_ESSAI ] ; do
1392    ncpdq -C --buffer_size 838860800 $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
1393    status=$?
1394    if [ ${status} -gt 0 ] ; then
1395      IGCM_debug_Print 2 "IGCM_sys_ncpdq : error code ${status}"
1396      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1397      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1398      IGCM_debug_Print 2 "IGCM_sys_ncpdq : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1399      sleep $DELAI
1400    else
1401      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1402      break
1403    fi
1404    (( i = i + 1 ))
1405  done
1406
1407  if [ ${status} -gt 0 ] ; then
1408    echo "IGCM_sys_ncpdq : ncpdq error"
1409    IGCM_debug_Exit "ncpdq"
1410  fi
1411
1412  IGCM_debug_PopStack "IGCM_sys_ncpdq"
1413}
1414
1415#D-#==================================================
1416#D-function IGCM_sys_ncra
1417#D-* Purpose: encapsulate ncra call so as to manage error code and retry
1418#D-* Examples:
1419#D-
1420function IGCM_sys_ncra {
1421  IGCM_debug_PushStack "IGCM_sys_ncra" $@
1422  if ( $DEBUG_sys ) ; then
1423    echo "IGCM_sys_ncra :" $@
1424  fi
1425
1426  typeset NB_ESSAI DELAI status i
1427  # number of tentative
1428  NB_ESSAI=3
1429  # time delay between tentative
1430  DELAI=2
1431
1432  i=0
1433  while [ $i -lt $NB_ESSAI ] ; do
1434    ncra -C --buffer_size 838860800 $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
1435    status=$?
1436    if [ ${status} -gt 0 ] ; then
1437      IGCM_debug_Print 2 "IGCM_sys_ncra : error code ${status}"
1438      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1439      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1440      IGCM_debug_Print 2 "IGCM_sys_ncra : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1441      sleep $DELAI
1442    else
1443      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1444      break
1445    fi
1446    (( i = i + 1 ))
1447  done
1448
1449  if [ ${status} -gt 0 ] ; then
1450    echo "IGCM_sys_ncra : ncra error"
1451    IGCM_debug_Exit "ncra"
1452  fi
1453
1454  IGCM_debug_PopStack "IGCM_sys_ncra"
1455}
1456
1457#D-#==================================================
1458#D-function IGCM_sys_ncrcat
1459#D-* Purpose: encapsulate ncrcat call so as to manage error code and retry
1460#D-* Examples:
1461#D-
1462function IGCM_sys_ncrcat {
1463  IGCM_debug_PushStack "IGCM_sys_ncrcat" $@
1464  if ( $DEBUG_sys ) ; then
1465    echo "IGCM_sys_ncrcat :" $@
1466  fi
1467
1468  typeset NB_ESSAI DELAI status i lastArg
1469  # number of tentative
1470  NB_ESSAI=3
1471  # time delay between tentative
1472  DELAI=2
1473
1474  i=0
1475  while [ $i -lt $NB_ESSAI ] ; do
1476    ncrcat -C --buffer_size 838860800 $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
1477    status=$?
1478    if [ ${status} -gt 0 ] ; then
1479      IGCM_debug_Print 2 "IGCM_sys_ncrcat : error code ${status}"
1480      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1481      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1482      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1483      sleep $DELAI
1484    elif ( [ ! "X$( grep "WARNING Intra-file non-monotonicity" ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ )" = "X" ] && [ X${config_Post_IgnoreNonMonotonic} = XFALSE ] ) ; then
1485      IGCM_debug_Print 2 "IGCM_sys_ncrcat : WARNING Intra-file non-monotonicity"
1486      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1487      # remove files having corrupted time axis
1488      eval lastArg=\${$#}
1489      IGCM_debug_Print 2 "Remove files having corrupted time axis"
1490      IGCM_debug_Print 2 "IGCM_sys_ncrcat : Delete ${lastArg}"
1491      \rm ${lastArg}
1492      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1493      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1494      sleep $DELAI
1495    else
1496      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1497      break
1498    fi
1499    (( i = i + 1 ))
1500  done
1501
1502  # Special case for spinup with cyclic time axis: change attribute calendar to none
1503  if [ X${config_Post_IgnoreNonMonotonic} = XTRUE ] ; then
1504      eval lastArg=\${$#}
1505      echo "IGCM_sys_ncrcat : change attribute calendar to none in file:" ${lastArg}
1506      IGCM_sys_ncatted -a calendar,time_counter,m,c,none ${lastArg}
1507  fi
1508
1509  if [ ${status} -gt 0 ] ; then
1510    echo "IGCM_sys_ncrcat : ncrcat error"
1511    #IGCM_debug_Exit "ncrcat"
1512  fi
1513
1514  IGCM_debug_PopStack "IGCM_sys_ncrcat"
1515}
1516
1517#D-#==================================================
1518#D-function IGCM_sys_ncrename
1519#D-* Purpose: encapsulate ncrename call so as to manage error code and retry
1520#D-* Examples:
1521#D-
1522function IGCM_sys_ncrename {
1523  IGCM_debug_PushStack "IGCM_sys_ncrename" $@
1524  if ( $DEBUG_sys ) ; then
1525    echo "IGCM_sys_ncrename :" $@
1526  fi
1527
1528  typeset NB_ESSAI DELAI status i
1529  # number of tentative
1530  NB_ESSAI=3
1531  # time delay between tentative
1532  DELAI=2
1533
1534  i=0
1535  while [ $i -lt $NB_ESSAI ] ; do
1536    ncrename $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
1537    status=$?
1538    if [ ${status} -gt 0 ] ; then
1539      IGCM_debug_Print 2 "IGCM_sys_ncrename : error code ${status}"
1540      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1541      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1542      IGCM_debug_Print 2 "IGCM_sys_ncrename : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1543      sleep $DELAI
1544    else
1545      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1546      break
1547    fi
1548    (( i = i + 1 ))
1549  done
1550
1551  if [ ${status} -gt 0 ] ; then
1552    echo "IGCM_sys_ncrename : ncrename error"
1553    IGCM_debug_Exit "ncrename"
1554  fi
1555
1556  IGCM_debug_PopStack "IGCM_sys_ncrename"
1557}
1558
1559#D-#==================================================
1560#D-function IGCM_sys_ncwa
1561#D-* Purpose: encapsulate ncwa call so as to manage error code and retry
1562#D-* Examples:
1563#D-
1564function IGCM_sys_ncwa {
1565  IGCM_debug_PushStack "IGCM_sys_ncwa" $@
1566  if ( $DEBUG_sys ) ; then
1567    echo "IGCM_sys_ncwa :" $@
1568  fi
1569
1570  typeset NB_ESSAI DELAI status i
1571  # number of tentative
1572  NB_ESSAI=3
1573  # time delay between tentative
1574  DELAI=2
1575
1576  i=0
1577  while [ $i -lt $NB_ESSAI ] ; do
1578    ncwa -C --buffer_size 838860800 $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
1579    status=$?
1580    if [ ${status} -gt 0 ] ; then
1581      IGCM_debug_Print 2 "IGCM_sys_ncwa : error code ${status}"
1582      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1583      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1584      IGCM_debug_Print 2 "IGCM_sys_ncwa : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1585      sleep $DELAI
1586    else
1587      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1588      break
1589    fi
1590    (( i = i + 1 ))
1591  done
1592
1593  if [ ${status} -gt 0 ] ; then
1594    echo "IGCM_sys_ncwa : ncwa error"
1595    IGCM_debug_Exit "ncwa"
1596  fi
1597
1598  IGCM_debug_PopStack "IGCM_sys_ncwa"
1599}
1600
1601##############################################################
1602# CDO OPERATOR
1603
1604#D-#==================================================
1605#D-function IGCM_sys_cdo
1606#D-* Purpose: encapsulate cdo call so as to manage error code and retry
1607#D-* Examples:
1608#D-
1609function IGCM_sys_cdo {
1610  IGCM_debug_PushStack "IGCM_sys_cdo" $@
1611  if ( $DEBUG_sys ) ; then
1612    echo "IGCM_sys_cdo :" $@
1613  fi
1614
1615  typeset status
1616
1617  \cdo $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
1618  status=$?
1619  if [ ${status} -gt 0 ] ; then
1620    echo "IGCM_sys_cdo : error code ${status}"
1621    cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1622    \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1623    IGCM_debug_PopStack "IGCM_sys_cdo"
1624    return 1
1625  else
1626    IGCM_debug_PopStack "IGCM_sys_cdo"
1627    return 0
1628  fi
1629
1630  IGCM_debug_PopStack "IGCM_sys_cdo"
1631}
1632
1633#
Note: See TracBrowser for help on using the repository browser.