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

Last change on this file since 1495 was 1490, checked in by jgipsl, 5 years ago

Added first version of sys_jeanzay. Still lots to do. Only case done for now is one executable mpi mode. Only create_ts done among post-treatments and only from main job (not done via TimeSeriesChecker?). Change of data project is not working (follwoing is not working when launched from job: eval $(idrenv -d ${PROJECT}) ).

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