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

Last change on this file since 1446 was 1432, checked in by jgipsl, 6 years ago

Added first version of sys_irene copied from sys_curie.
Tested as far without post-treatement only with SpaceName?=TEST. As far, only tested with LMDZOR and ORCHIDEE offline without post-processing, only at scratchdir.
c
ccc_mprun mode is default at irene.

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