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

Last change on this file since 1204 was 1204, checked in by sdipsl, 9 years ago
  • 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.0 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
703  # number of tentative
704  NB_ESSAI=3
705  # time delay between tentative
706  DELAI=2
707
708  if [ $DRYRUN = 0 ]; then
709    if [ ! -f ${1} ] ; then
710      echo "WARNING : IGCM_sys_PutBuffer_Out ${1} DOES NOT EXIST ."
711      IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
712      return 1
713    fi
714    #
715    IGCM_sys_Mkdir $( dirname $2 )
716    #
717
718    exist=false
719    skip=false
720    if [ -f $2 ] ; then
721      IGCM_debug_Print 1 "$2 already exist"
722      exist=true
723      if [ "X$( diff $1 $2 )" = X ] ; then
724        IGCM_debug_Print 2 "$1 and $2 are the same file, we skip the copy"
725        status=0
726        skip=true
727      else
728        IGCM_debug_Print 2 "$1 and $2 are not the same file, we force the copy"
729        skip=false
730      fi
731    fi
732    #
733    if ( [ X${exist} = Xtrue ] && [ X${skip} = Xfalse ] ) ; then
734      IGCM_sys_Chmod u+w $2
735    fi
736
737    if [ X${skip} = Xfalse ] ; then
738      i=0
739      while [ $i -lt $NB_ESSAI ] ; do
740        if [ $( stat -c %d $1 ) -ne $( stat -c %d $( dirname $2 ) ) ] ; then
741          # USUAL WAY
742          \cp $1 $2 > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
743          status=$?
744        else
745          # NOT SO USUAL WAY
746          \mv $1 $2 > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
747          status=$?
748        fi
749        if [ ${status} -gt 0 ]; then
750          IGCM_debug_Print 2 "IGCM_sys_PutBuffer_Out : cp failed error code ${status} ${i}/${NB_ESSAI}"
751          IGCM_debug_Print 2 "IGCM_sys_PutBuffer_Out : sleep ${DELAI} seconds and try again."
752          [ -f ${2} ] && ls -l ${2}
753          [ -f ${2}/${1} ] && ls -l ${2}/${1}
754          sleep $DELAI
755        else
756          break
757        fi
758        (( i = i + 1 ))
759      done
760    fi
761
762    if [ ${status} -gt 0 ] ; then
763      echo "IGCM_sys_PutBuffer_Out : error."
764      [ -f ${2} ] && ls -l ${2}
765      [ -f ${2}/${1} ] && ls -l ${2}/${1}
766      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
767      IGCM_debug_Exit "IGCM_sys_PutBuffer_Out"
768    else
769
770      if [ X${JobType} = XRUN ] ; then
771        if [ X${3} = X ] ; then
772          [ -f ${2} ] && IGCM_sys_Chmod 444 ${2}
773          [ -f ${2}/${1} ] && IGCM_sys_Chmod 444 ${2}/${1}
774        fi
775      fi
776
777      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
778    fi
779  fi
780  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
781  return 0
782}
783
784#D-#==================================================
785#D-function IGCM_sys_GetBuffer
786#D-* Purpose: Get a file from ${SCRATCHDIR}
787#D-* Examples: IGCM_sys_GetBuffer myfile /destpath/myfile_with_PREFIX
788#D-            IGCM_sys_GetBuffer /l Array_contain_myfiles /destpath/
789function IGCM_sys_GetBuffer {
790  IGCM_debug_PushStack "IGCM_sys_GetBuffer" $@
791
792  typeset DEST buf_liste target file_work
793  typeset NB_ESSAI DELAI status i
794
795  if ( $DEBUG_sys ) ; then
796    echo "IGCM_sys_GetBuffer :" $@
797  fi
798
799  # number of tentative
800  NB_ESSAI=3
801  # time delay between tentative
802  DELAI=2
803
804  if [ $DRYRUN -le 2 ]; then
805    if [ X${1} = X'/l' ] ; then
806      eval set +A buf_liste \${${2}}
807    else
808      eval set +A buf_liste ${1}
809    fi
810    eval DEST=\${${#}}
811
812    #USUAL WAY
813    if [ X${1} = X'/l' ] ; then
814      for target in ${buf_liste[*]} ; do
815        local_file=$( basename ${target} )
816        i=0
817        while [ $i -lt $NB_ESSAI ] ; do
818          \cp ${target} ${DEST}/${local_file} >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
819          status=$?
820          if [ ${status} -gt 0 ]; then
821            IGCM_debug_Print 2 "IGCM_sys_GetBuffer : cp failed error code ${status} ${i}/${NB_ESSAI}"
822            IGCM_debug_Print 2 "IGCM_sys_GetBuffer : sleep ${DELAI} seconds and try again."
823            sleep $DELAI
824          else
825            break
826          fi
827          (( i = i + 1 ))
828        done
829        if [ ${status} -gt 0 ] ; then
830          echo "IGCM_sys_Get : error"
831          cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
832          \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
833          IGCM_debug_Exit "IGCM_sys_GetBuffer"
834        else
835          \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
836        fi
837      done
838    else
839      i=0
840      while [ $i -lt $NB_ESSAI ] ; do
841        \cp ${buf_liste} ${DEST} >> ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
842        status=$?
843        if [ ${status} -gt 0 ]; then
844          IGCM_debug_Print 2 "IGCM_sys_GetBuffer : cp failed error code ${status} ${i}/${NB_ESSAI}"
845          IGCM_debug_Print 2 "IGCM_sys_GetBuffer : sleep ${DELAI} seconds and try again."
846          sleep $DELAI
847        else
848          break
849        fi
850        (( i = i + 1 ))
851      done
852      if [ ${status} -gt 0 ] ; then
853        echo "IGCM_sys_Get : error"
854        cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
855        \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
856        IGCM_debug_Exit "IGCM_sys_GetBuffer"
857      else
858        \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
859      fi
860    fi
861  fi
862  IGCM_debug_PopStack "IGCM_sys_GetBuffer"
863}
864
865#D-#==================================================
866#D-function IGCM_sys_GetDate_FichWork
867#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
868#D-* Examples:
869#D-
870function IGCM_sys_GetDate_FichWork {
871  IGCM_debug_PushStack "IGCM_sys_GetDate_FichWork" $@
872  if ( $DEBUG_sys ) ; then
873    echo "IGCM_sys_GetDate_FichWork :" $@
874  fi
875
876  if [ $# -ge 3 ] ; then
877    mode=$3
878    TimeStyle=$4
879  else
880    mode="default"
881    TimeStyle="%Y%m%d%H%M%S"
882  fi
883
884  typeset dateF
885  set +A dateF -- $( ls -l --full-time --time-style=+"${TimeStyle}" ${1} )
886
887  case $mode in
888    "default")
889      eval ${2}=${dateF[5]}
890      ;;
891    "SplitFields")
892      eval ${2}="${dateF[5]}\ ${dateF[6]}"
893      ;;
894  esac
895
896  # donne la date filesys d'un fichier sur la machine work
897  IGCM_debug_PopStack "IGCM_sys_GetDate_FichWork"
898}
899
900#D-#==================================================
901#D-function IGCM_sys_rebuild
902#D-* Purpose: rebuild parallel files
903#D-* Examples:
904#D-
905function IGCM_sys_rebuild {
906  IGCM_debug_PushStack "IGCM_sys_rebuild" $@
907  if ( $DEBUG_sys ) ; then
908    echo "IGCM_sys_rebuild :" $@
909  fi
910
911  typeset NB_ESSAI DELAI status i firstArg
912  # number of tentative
913  NB_ESSAI=3
914  # time delay between tentative
915  DELAI=2
916
917  i=0
918  while [ $i -lt $NB_ESSAI ] ; do
919    rebuild -f -o $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
920    status=$?
921    if [ ${status} -gt 0 ] ; then
922      IGCM_debug_Print 2 "IGCM_sys_rebuild : error code ${status}"
923      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
924      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
925      IGCM_debug_Print 2 "IGCM_sys_rebuild : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
926      firstArg=${1}
927      \rm ${firstArg}
928      sleep $DELAI
929    else
930      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
931      break
932    fi
933    (( i = i + 1 ))
934  done
935
936  if [ ${status} -gt 0 ] ; then
937    echo "IGCM_sys_rebuild : rebuild error code is ${status}"
938    IGCM_debug_Exit "rebuild"
939  fi
940
941  IGCM_debug_PopStack "IGCM_sys_rebuild"
942}
943
944#D-#==================================================
945#D-function IGCM_sys_rebuild_station
946#D-* Purpose: rebuild parallel files describing station
947#D-* Examples:
948#D-
949function IGCM_sys_rebuild_station {
950  IGCM_debug_PushStack "IGCM_sys_rebuild_station" $@
951  typeset i list_opt file_in file_out prefix_invert list_invert
952  if ( $DEBUG_sys ) ; then
953    echo "IGCM_sys_rebuild_station :" $@
954  fi
955
956  # Station re-ordering is too expansive to be run within libIGCM
957  # This is due to (ncpdq - nrcat - ncpdq) I/O sequence.
958  # This re-ordering must be done "in memory" by the cmorization process
959
960  # Only LMDZ text output contains the exact ordering of the station.
961  # We isolate this in the code below:
962  #  0  38  -157.5000000000000  70.98591549295774
963  #  0  54  27.49999999999999   67.18309859154928
964  #  0  56  -62.50000000000001  82.39436619718309
965  #  0  79  12.49999999999999   78.59154929577466
966  #  0  116 -165.0000000000000  76.05633802816901
967  #  0  117 130.0000000000000   70.98591549295774
968  #  0  118 110.0000000000000   87.46478873239437
969  #  1  40  4.999999999999995   51.97183098591550
970
971  list_opt=$@
972
973  # Invert Axis : t,x -> x,t
974  #               t,pres,x -> x,t,pres
975  # So that we can concatenate along x
976  i=0
977  for file_in in ${list_opt} ; do
978    (( i = i + 1))
979    [ ${i} = 1 ] && file_out=${file_in} && continue
980    # detect time counter and do the job only if present
981    var_unlim=$(ncdump -h ${file_in} | grep UNLIMITED | cut -d ' ' -f 1 | sed -e 's/^[ \t]*//' -e 's/[ \t]*$//')
982    if [ X${var_unlim} = Xtime_counter ] ; then
983      prefix_invert=$( basename ${file_in} .nc )
984      IGCM_sys_ncpdq -a x,time_counter -a x,time_counter,presnivs ${file_in} ${prefix_invert}_xt.nc
985      list_invert[${#list_invert[*]}]=${prefix_invert}_xt.nc
986    fi
987  done
988
989  # Concatenate
990  IGCM_sys_ncrcat ${list_invert[*]} histstn_xt.nc
991
992  # Re-ivert file
993  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x histstn_xt.nc ${file_out}
994
995  IGCM_debug_PopStack "IGCM_sys_rebuild_station"
996}
997
998##############################################################
999# NCO OPERATOR
1000
1001#D-#==================================================
1002#D-function IGCM_sys_ncap2
1003#D-* Purpose: encapsulate ncap2 call so as to manage error code and retry
1004#D-* Examples:
1005#D-
1006function IGCM_sys_ncap2 {
1007  IGCM_debug_PushStack "IGCM_sys_ncap2" $@
1008  if ( $DEBUG_sys ) ; then
1009    echo "IGCM_sys_ncap2 :" $@
1010  fi
1011
1012  typeset NB_ESSAI DELAI status i
1013  # number of tentative
1014  NB_ESSAI=3
1015  # time delay between tentative
1016  DELAI=2
1017
1018  i=0
1019  while [ $i -lt $NB_ESSAI ] ; do
1020    ncap2 -C --buffer_size 838860800 "$@" > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
1021    status=$?
1022    if [ ${status} -gt 0 ] ; then
1023      IGCM_debug_Print 2 "IGCM_sys_ncap2 : error code ${status}"
1024      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1025      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1026      IGCM_debug_Print 2 "IGCM_sys_ncap2 : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1027      sleep $DELAI
1028    else
1029      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1030      break
1031    fi
1032    (( i = i + 1 ))
1033  done
1034
1035  if [ ${status} -gt 0 ] ; then
1036    echo "IGCM_sys_ncap2 : ncap2 error"
1037    IGCM_debug_Exit "ncap2"
1038  fi
1039
1040  IGCM_debug_PopStack "IGCM_sys_ncap2"
1041}
1042
1043#D-#==================================================
1044#D-function IGCM_sys_ncatted
1045#D-* Purpose: encapsulate ncatted call so as to manage error code and retry
1046#D-* Examples:
1047#D-
1048function IGCM_sys_ncatted {
1049  IGCM_debug_PushStack "IGCM_sys_ncatted" $@
1050  if ( $DEBUG_sys ) ; then
1051    echo "IGCM_sys_ncatted :" $@
1052  fi
1053
1054  typeset NB_ESSAI DELAI status i
1055  # number of tentative
1056  NB_ESSAI=3
1057  # time delay between tentative
1058  DELAI=2
1059
1060  i=0
1061  while [ $i -lt $NB_ESSAI ] ; do
1062    ncatted "$@" > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
1063    status=$?
1064    if [ ${status} -gt 0 ] ; then
1065      IGCM_debug_Print 2 "IGCM_sys_ncatted : error code ${status}"
1066      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1067      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1068      IGCM_debug_Print 2 "IGCM_sys_ncatted : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1069      sleep $DELAI
1070    else
1071      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1072      break
1073    fi
1074    (( i = i + 1 ))
1075  done
1076
1077  if [ ${status} -gt 0 ] ; then
1078    echo "IGCM_sys_ncatted : ncatted error"
1079    IGCM_debug_Exit "ncatted"
1080  fi
1081
1082  IGCM_debug_PopStack "IGCM_sys_ncatted"
1083}
1084
1085#D-#==================================================
1086#D-function IGCM_sys_ncbo
1087#D-* Purpose: encapsulate ncbo call so as to manage error code and retry
1088#D-* Examples:
1089#D-
1090function IGCM_sys_ncbo {
1091  IGCM_debug_PushStack "IGCM_sys_ncbo" $@
1092  if ( $DEBUG_sys ) ; then
1093    echo "IGCM_sys_ncbo :" $@
1094  fi
1095
1096  typeset NB_ESSAI DELAI status i
1097  # number of tentative
1098  NB_ESSAI=3
1099  # time delay between tentative
1100  DELAI=2
1101
1102  i=0
1103  while [ $i -lt $NB_ESSAI ] ; do
1104    ncbo -C --buffer_size 838860800 $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
1105    status=$?
1106    if [ ${status} -gt 0 ] ; then
1107      IGCM_debug_Print 2 "IGCM_sys_ncbo : error code ${status}"
1108      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1109      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1110      IGCM_debug_Print 2 "IGCM_sys_ncbo : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1111      sleep $DELAI
1112    else
1113      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1114      break
1115    fi
1116    (( i = i + 1 ))
1117  done
1118
1119  if [ ${status} -gt 0 ] ; then
1120    echo "IGCM_sys_ncbo : ncbo error"
1121    IGCM_debug_Exit "ncbo"
1122  fi
1123
1124  IGCM_debug_PopStack "IGCM_sys_ncbo"
1125}
1126
1127#D-#==================================================
1128#D-function IGCM_sys_ncdif
1129#D-* Purpose: encapsulate ncdiff call so as to manage error code and retry
1130#D-* Examples:
1131#D-
1132function IGCM_sys_ncdiff {
1133  IGCM_debug_PushStack "IGCM_sys_ncdiff" $@
1134  if ( $DEBUG_sys ) ; then
1135    echo "IGCM_sys_ncdiff :" $@
1136  fi
1137
1138  typeset NB_ESSAI DELAI status i
1139  # number of tentative
1140  NB_ESSAI=3
1141  # time delay between tentative
1142  DELAI=2
1143
1144  i=0
1145  while [ $i -lt $NB_ESSAI ] ; do
1146    ncdiff -C --buffer_size 838860800 $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
1147    status=$?
1148    if [ ${status} -gt 0 ] ; then
1149      IGCM_debug_Print 2 "IGCM_sys_ncdiff : error code ${status}"
1150      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1151      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1152      IGCM_debug_Print 2 "IGCM_sys_ncdiff : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1153      sleep $DELAI
1154    else
1155      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1156      break
1157    fi
1158    (( i = i + 1 ))
1159  done
1160
1161  if [ ${status} -gt 0 ] ; then
1162    echo "IGCM_sys_ncdiff : ncdiff error"
1163    IGCM_debug_Exit "ncdiff"
1164  fi
1165
1166  IGCM_debug_PopStack "IGCM_sys_ncdiff"
1167}
1168
1169#D-#==================================================
1170#D-function IGCM_sys_ncea
1171#D-* Purpose: encapsulate ncea call so as to manage error code and retry
1172#D-* Examples:
1173#D-
1174function IGCM_sys_ncea {
1175  IGCM_debug_PushStack "IGCM_sys_ncea" $@
1176  if ( $DEBUG_sys ) ; then
1177    echo "IGCM_sys_ncea :" $@
1178  fi
1179
1180  typeset NB_ESSAI DELAI status i
1181  # number of tentative
1182  NB_ESSAI=3
1183  # time delay between tentative
1184  DELAI=2
1185
1186  i=0
1187  while [ $i -lt $NB_ESSAI ] ; do
1188    ncea -C --buffer_size 838860800 $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
1189    status=$?
1190    if [ ${status} -gt 0 ] ; then
1191      IGCM_debug_Print 2 "IGCM_sys_ncea : error code ${status}"
1192      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1193      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1194      IGCM_debug_Print 2 "IGCM_sys_ncea : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1195      sleep $DELAI
1196    else
1197      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1198      break
1199    fi
1200    (( i = i + 1 ))
1201  done
1202
1203  if [ ${status} -gt 0 ] ; then
1204    echo "IGCM_sys_ncea : ncea error"
1205    IGCM_debug_Exit "ncea"
1206  fi
1207
1208  IGCM_debug_PopStack "IGCM_sys_ncea"
1209}
1210
1211#D-#==================================================
1212#D-function IGCM_sys_ncecat
1213#D-* Purpose: encapsulate ncecat call so as to manage error code and retry
1214#D-* Examples:
1215#D-
1216function IGCM_sys_ncecat {
1217  IGCM_debug_PushStack "IGCM_sys_ncecat" $@
1218  if ( $DEBUG_sys ) ; then
1219    echo "IGCM_sys_ncecat :" $@
1220  fi
1221
1222  typeset NB_ESSAI DELAI status i
1223  # number of tentative
1224  NB_ESSAI=3
1225  # time delay between tentative
1226  DELAI=2
1227
1228  i=0
1229  while [ $i -lt $NB_ESSAI ] ; do
1230    ncecat -C --buffer_size 838860800 $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
1231    status=$?
1232    if [ ${status} -gt 0 ] ; then
1233      IGCM_debug_Print 2 "IGCM_sys_ncecat : error code ${status}"
1234      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1235      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1236      IGCM_debug_Print 2 "IGCM_sys_ncecat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1237      sleep $DELAI
1238    else
1239      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1240      break
1241    fi
1242    (( i = i + 1 ))
1243  done
1244
1245  if [ ${status} -gt 0 ] ; then
1246    echo "IGCM_sys_ncecat : ncecat error"
1247    IGCM_debug_Exit "ncecat"
1248  fi
1249
1250  IGCM_debug_PopStack "IGCM_sys_ncecat"
1251}
1252
1253#D-#==================================================
1254#D-function IGCM_sys_ncflint
1255#D-* Purpose: encapsulate ncflint call so as to manage error code and retry
1256#D-* Examples:
1257#D-
1258function IGCM_sys_ncflint {
1259  IGCM_debug_PushStack "IGCM_sys_ncflint" $@
1260  if ( $DEBUG_sys ) ; then
1261    echo "IGCM_sys_ncflint :" $@
1262  fi
1263
1264  typeset NB_ESSAI DELAI status i
1265  # number of tentative
1266  NB_ESSAI=3
1267  # time delay between tentative
1268  DELAI=2
1269
1270  i=0
1271  while [ $i -lt $NB_ESSAI ] ; do
1272    ncflint -C --buffer_size 838860800 $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
1273    status=$?
1274    if [ ${status} -gt 0 ] ; then
1275      IGCM_debug_Print 2 "IGCM_sys_ncflint : error code ${status}"
1276      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1277      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1278      IGCM_debug_Print 2 "IGCM_sys_ncflint : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1279      sleep $DELAI
1280    else
1281      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1282      break
1283    fi
1284    (( i = i + 1 ))
1285  done
1286
1287  if [ ${status} -gt 0 ] ; then
1288    echo "IGCM_sys_ncflint : ncflint error"
1289    IGCM_debug_Exit "ncflint"
1290  fi
1291
1292  IGCM_debug_PopStack "IGCM_sys_ncflint"
1293}
1294
1295#D-#==================================================
1296#D-function IGCM_sys_ncks
1297#D-* Purpose: encapsulate ncks call so as to manage error code and retry
1298#D-* Examples:
1299#D-
1300function IGCM_sys_ncks {
1301  IGCM_debug_PushStack "IGCM_sys_ncks" $@
1302  if ( $DEBUG_sys ) ; then
1303    echo "IGCM_sys_ncks :" $@
1304  fi
1305
1306  typeset NB_ESSAI DELAI status i
1307  # number of tentative
1308  NB_ESSAI=3
1309  # time delay between tentative
1310  DELAI=2
1311
1312  i=0
1313  while [ $i -lt $NB_ESSAI ] ; do
1314    ncks -C --buffer_size 838860800 $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
1315    status=$?
1316    if [ ${status} -gt 0 ] ; then
1317      IGCM_debug_Print 2 "IGCM_sys_ncks : error code ${status}"
1318      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1319      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1320      IGCM_debug_Print 2 "IGCM_sys_ncks : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1321      sleep $DELAI
1322    else
1323      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1324      break
1325    fi
1326    (( i = i + 1 ))
1327  done
1328
1329  if [ ${status} -gt 0 ] ; then
1330    echo "IGCM_sys_ncks : ncks error"
1331    IGCM_debug_Exit "ncks"
1332  fi
1333
1334  IGCM_debug_PopStack "IGCM_sys_ncks"
1335}
1336
1337#D-#==================================================
1338#D-function IGCM_sys_ncpdq
1339#D-* Purpose: encapsulate ncpdq call so as to manage error code and retry
1340#D-* Examples:
1341#D-
1342function IGCM_sys_ncpdq {
1343  IGCM_debug_PushStack "IGCM_sys_ncpdq" $@
1344  if ( $DEBUG_sys ) ; then
1345    echo "IGCM_sys_ncpdq :" $@
1346  fi
1347
1348  typeset NB_ESSAI DELAI status i
1349  # number of tentative
1350  NB_ESSAI=3
1351  # time delay between tentative
1352  DELAI=2
1353
1354  i=0
1355  while [ $i -lt $NB_ESSAI ] ; do
1356    ncpdq -C --buffer_size 838860800 $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
1357    status=$?
1358    if [ ${status} -gt 0 ] ; then
1359      IGCM_debug_Print 2 "IGCM_sys_ncpdq : error code ${status}"
1360      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1361      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1362      IGCM_debug_Print 2 "IGCM_sys_ncpdq : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1363      sleep $DELAI
1364    else
1365      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1366      break
1367    fi
1368    (( i = i + 1 ))
1369  done
1370
1371  if [ ${status} -gt 0 ] ; then
1372    echo "IGCM_sys_ncpdq : ncpdq error"
1373    IGCM_debug_Exit "ncpdq"
1374  fi
1375
1376  IGCM_debug_PopStack "IGCM_sys_ncpdq"
1377}
1378
1379#D-#==================================================
1380#D-function IGCM_sys_ncra
1381#D-* Purpose: encapsulate ncra call so as to manage error code and retry
1382#D-* Examples:
1383#D-
1384function IGCM_sys_ncra {
1385  IGCM_debug_PushStack "IGCM_sys_ncra" $@
1386  if ( $DEBUG_sys ) ; then
1387    echo "IGCM_sys_ncra :" $@
1388  fi
1389
1390  typeset NB_ESSAI DELAI status i
1391  # number of tentative
1392  NB_ESSAI=3
1393  # time delay between tentative
1394  DELAI=2
1395
1396  i=0
1397  while [ $i -lt $NB_ESSAI ] ; do
1398    ncra -C --buffer_size 838860800 $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
1399    status=$?
1400    if [ ${status} -gt 0 ] ; then
1401      IGCM_debug_Print 2 "IGCM_sys_ncra : error code ${status}"
1402      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1403      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1404      IGCM_debug_Print 2 "IGCM_sys_ncra : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1405      sleep $DELAI
1406    else
1407      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1408      break
1409    fi
1410    (( i = i + 1 ))
1411  done
1412
1413  if [ ${status} -gt 0 ] ; then
1414    echo "IGCM_sys_ncra : ncra error"
1415    IGCM_debug_Exit "ncra"
1416  fi
1417
1418  IGCM_debug_PopStack "IGCM_sys_ncra"
1419}
1420
1421#D-#==================================================
1422#D-function IGCM_sys_ncrcat
1423#D-* Purpose: encapsulate ncrcat call so as to manage error code and retry
1424#D-* Examples:
1425#D-
1426function IGCM_sys_ncrcat {
1427  IGCM_debug_PushStack "IGCM_sys_ncrcat" $@
1428  if ( $DEBUG_sys ) ; then
1429    echo "IGCM_sys_ncrcat :" $@
1430  fi
1431
1432  typeset NB_ESSAI DELAI status i lastArg
1433  # number of tentative
1434  NB_ESSAI=3
1435  # time delay between tentative
1436  DELAI=2
1437
1438  i=0
1439  while [ $i -lt $NB_ESSAI ] ; do
1440    ncrcat -C --buffer_size 838860800 $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
1441    status=$?
1442    if [ ${status} -gt 0 ] ; then
1443      IGCM_debug_Print 2 "IGCM_sys_ncrcat : error code ${status}"
1444      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1445      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1446      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1447      sleep $DELAI
1448    elif ( [ ! "X$( grep "WARNING Intra-file non-monotonicity" ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ )" = "X" ] && [ X${config_Post_IgnoreNonMonotonic} = XFALSE ] ) ; then
1449      IGCM_debug_Print 2 "IGCM_sys_ncrcat : WARNING Intra-file non-monotonicity"
1450      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1451      # remove files having corrupted time axis
1452      eval lastArg=\${$#}
1453      IGCM_debug_Print 2 "Remove files having corrupted time axis"
1454      IGCM_debug_Print 2 "IGCM_sys_ncrcat : Delete ${lastArg}"
1455      \rm ${lastArg}
1456      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1457      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1458      sleep $DELAI
1459    else
1460      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1461      break
1462    fi
1463    (( i = i + 1 ))
1464  done
1465
1466  if [ ${status} -gt 0 ] ; then
1467    echo "IGCM_sys_ncrcat : ncrcat error"
1468    #IGCM_debug_Exit "ncrcat"
1469  fi
1470
1471  IGCM_debug_PopStack "IGCM_sys_ncrcat"
1472}
1473
1474#D-#==================================================
1475#D-function IGCM_sys_ncrename
1476#D-* Purpose: encapsulate ncrename call so as to manage error code and retry
1477#D-* Examples:
1478#D-
1479function IGCM_sys_ncrename {
1480  IGCM_debug_PushStack "IGCM_sys_ncrename" $@
1481  if ( $DEBUG_sys ) ; then
1482    echo "IGCM_sys_ncrename :" $@
1483  fi
1484
1485  typeset NB_ESSAI DELAI status i
1486  # number of tentative
1487  NB_ESSAI=3
1488  # time delay between tentative
1489  DELAI=2
1490
1491  i=0
1492  while [ $i -lt $NB_ESSAI ] ; do
1493    ncrename $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
1494    status=$?
1495    if [ ${status} -gt 0 ] ; then
1496      IGCM_debug_Print 2 "IGCM_sys_ncrename : error code ${status}"
1497      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1498      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1499      IGCM_debug_Print 2 "IGCM_sys_ncrename : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1500      sleep $DELAI
1501    else
1502      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1503      break
1504    fi
1505    (( i = i + 1 ))
1506  done
1507
1508  if [ ${status} -gt 0 ] ; then
1509    echo "IGCM_sys_ncrename : ncrename error"
1510    IGCM_debug_Exit "ncrename"
1511  fi
1512
1513  IGCM_debug_PopStack "IGCM_sys_ncrename"
1514}
1515
1516#D-#==================================================
1517#D-function IGCM_sys_ncwa
1518#D-* Purpose: encapsulate ncwa call so as to manage error code and retry
1519#D-* Examples:
1520#D-
1521function IGCM_sys_ncwa {
1522  IGCM_debug_PushStack "IGCM_sys_ncwa" $@
1523  if ( $DEBUG_sys ) ; then
1524    echo "IGCM_sys_ncwa :" $@
1525  fi
1526
1527  typeset NB_ESSAI DELAI status i
1528  # number of tentative
1529  NB_ESSAI=3
1530  # time delay between tentative
1531  DELAI=2
1532
1533  i=0
1534  while [ $i -lt $NB_ESSAI ] ; do
1535    ncwa -C --buffer_size 838860800 $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
1536    status=$?
1537    if [ ${status} -gt 0 ] ; then
1538      IGCM_debug_Print 2 "IGCM_sys_ncwa : error code ${status}"
1539      cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1540      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1541      IGCM_debug_Print 2 "IGCM_sys_ncwa : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1542      sleep $DELAI
1543    else
1544      \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1545      break
1546    fi
1547    (( i = i + 1 ))
1548  done
1549
1550  if [ ${status} -gt 0 ] ; then
1551    echo "IGCM_sys_ncwa : ncwa error"
1552    IGCM_debug_Exit "ncwa"
1553  fi
1554
1555  IGCM_debug_PopStack "IGCM_sys_ncwa"
1556}
1557
1558##############################################################
1559# CDO OPERATOR
1560
1561#D-#==================================================
1562#D-function IGCM_sys_cdo
1563#D-* Purpose: encapsulate cdo call so as to manage error code and retry
1564#D-* Examples:
1565#D-
1566function IGCM_sys_cdo {
1567  IGCM_debug_PushStack "IGCM_sys_cdo" $@
1568  if ( $DEBUG_sys ) ; then
1569    echo "IGCM_sys_cdo :" $@
1570  fi
1571
1572  typeset status
1573
1574  \cdo $@ > ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$ 2>&1
1575  status=$?
1576  if [ ${status} -gt 0 ] ; then
1577    echo "IGCM_sys_cdo : error code ${status}"
1578    cat ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1579    \rm ${OUTCOMMAND_PATH}/out_command_${LOGIN}.$$
1580    IGCM_debug_PopStack "IGCM_sys_cdo"
1581    return 1
1582  else
1583    IGCM_debug_PopStack "IGCM_sys_cdo"
1584    return 0
1585  fi
1586
1587  IGCM_debug_PopStack "IGCM_sys_cdo"
1588}
1589
1590#
Note: See TracBrowser for help on using the repository browser.