source: tags/libIGCM_v2.8.1/libIGCM_sys/libIGCM_sys.ksh

Last change on this file was 1314, checked in by jgipsl, 8 years ago

Adapted libIGCM to run at climserv (IPSL cluster at Polytechinque). The same libIGCM_sys as for ciclad is used but some changes for the paths are done inside.

For ciclad the variable CENTER change to IPSL-ciclad to be different from the one used for climserv (IPSL-climserv).

The running queue at ciclad also changed in AA_job and some other jobs. Now the default queue is used but the old is kept in comment. This is done to have the same heading running at ciclad and climserv.

  • Property licence set to
    The following licence information concerns ONLY the libIGCM tools
    ==================================================================

    Copyright © Centre National de la Recherche Scientifique CNRS
    Commissariat à l'Énergie Atomique CEA

    libIGCM : Library for Portable Models Computation of IGCM Group.

    IGCM Group is the french IPSL Global Climate Model Group.

    This library is a set of shell scripts and functions whose purpose is
    the management of the initialization, the launch, the transfer of
    output files, the post-processing and the monitoring of datas produce
    by any numerical program on any plateforme.

    This software is governed by the CeCILL license under French law and
    abiding by the rules of distribution of free software. You can use,
    modify and/ or redistribute the software under the terms of the CeCILL
    license as circulated by CEA, CNRS and INRIA at the following URL
    "http://www.cecill.info".

    As a counterpart to the access to the source code and rights to copy,
    modify and redistribute granted by the license, users are provided only
    with a limited warranty and the software's author, the holder of the
    economic rights, and the successive licensors have only limited
    liability.

    In this respect, the user's attention is drawn to the risks associated
    with loading, using, modifying and/or developing or reproducing the
    software by the user in light of its specific status of free software,
    that may mean that it is complicated to manipulate, and that also
    therefore means that it is reserved for developers and experienced
    professionals having in-depth computer knowledge. Users are therefore
    encouraged to load and test the software's suitability as regards their
    requirements in conditions enabling the security of their systems and/or
    data to be ensured and, more generally, to use and operate it in the
    same conditions as regards security.

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