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

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