source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_default.ksh @ 720

Last change on this file since 720 was 717, checked in by sdipsl, 12 years ago
  • all available machine but IDRIS (will change soon) : print error code from mv, cp, ...
  • 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: 60.0 KB
Line 
1#!/bin/ksh
2
3#**************************************************************
4# Author: Sebastien Denvil, 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#=========================================================
15# The documentation of this file can be automatically generated
16# if you use the prefix #D- for comments to be extracted.
17# Extract with command: cat lib* | grep "^#D-" | cut -c "4-"
18#=========================================================
19
20#D-#==================================================
21#D-LibIGCM_sys Default host
22#D-#==================================================
23#D-
24#D- This ksh library if a layer under some usefull
25#D- environment variables and shell commands.
26#D- All those definitions depend on host particularities.
27#D- It manages a stack mechanism and test validity of operations.
28#D- All function described bellow must be prefixed by IGCM_sys.
29
30#====================================================
31# libIGCM_sys PARAMETERS
32#====================================================
33
34#====================================================
35#set DEBUG_sys to true to output calls of function
36typeset -r DEBUG_sys=${DEBUG_sys:=true}
37
38#====================================================
39# Turn in dry run mode ? (sys_Put_Rest, sys_Put_Out, sys_Get)
40typeset -r DRYRUN=${DRYRUN:=0}
41
42# YOU MUST COMPILE YOUR EXE FILES FOR DRYRUN MODE !
43# -------------------------------------------------------------------------------------
44# | DRYRUN=  |  Date computations, | sys_Get    |  Exe    | sys_Put_Out; sys_Put_Rest |
45# |          |  Cp/Exe param files |            |  Chmod  |                           |
46# |          |      Qsub           |            |         |                           |
47# -------------------------------------------------------------------------------------
48# |    0     |       yes           |    yes     |  yes    |      yes                  |
49# -------------------------------------------------------------------------------------
50# |    1     |       yes           |    yes     |  yes    |      no                   |
51# -------------------------------------------------------------------------------------
52# |    2     |       yes           |    yes     |  no     |      no                   |
53# -------------------------------------------------------------------------------------
54# |    3     |       yes           |    no      |  no     |      no                   |
55# -------------------------------------------------------------------------------------
56
57#=====================================================
58#Global Variables :
59#=====================================================
60# Language : "fr" or "en"
61typeset -r MYLANG="fr"
62
63#=====================================================
64# Host and user names
65# $hostname ou hostname
66typeset  HOST=${HOST:=$( hostname )}
67# $username ou whoami
68typeset  LOGIN=${LOGIN:=$( whoami )}
69# $hostname of the MASTER job
70typeset -r MASTER=${HOST}
71
72#D-
73#D-#==================================================
74#D-Program used in libIGCM
75#D-#==================================================
76
77# rsync with path
78typeset -r RSYNC=/usr/bin/rsync
79#RSYNC_opt args to rsync
80typeset -r RSYNC_opt="-va"
81#"-Lt -v"
82# ie storage filesystem
83typeset -r STOREHOST=${MASTER}
84
85#====================================================
86# Set environment tools (ferret, nco, cdo)
87#====================================================
88#. /home/${LOGIN}/.atlas_env_${HOST}_ksh
89
90#====================================================
91# Host specific DIRECTORIES
92#====================================================
93
94#====================================================
95#- MirrorlibIGCM for frontend
96typeset -r MirrorlibIGCM=${MirrorlibIGCM:=false}
97
98#====================================================
99#- libIGCM_POST
100typeset -r libIGCM_POST=${libIGCM}
101
102#====================================================
103#- R_EXE   (==> BIN_DIR = ${MODIPSL}/bin )
104typeset -r R_EXE="${MODIPSL}/bin"
105
106#====================================================
107#- SCRATCHDIR (=> ${R_DONNEES})
108typeset -r SCRATCHDIR=/tmp
109
110#====================================================
111#- SUBMIT_DIR : submission dir
112typeset SUBMIT_DIR=${SUBMIT_DIR:=${PWD}}
113
114#====================================================
115#- ARCHIVE (dedicated to large files)
116typeset -r ARCHIVE=/home/${LOGIN}
117
118#- ARCHIVE (dedicated to small/medium files)
119typeset -r STORAGE=${ARCHIVE}
120
121#====================================================
122#- IN
123typeset -r R_IN=${R_IN:=${ARCHIVE}/IGCM}
124
125#====================================================
126#- OUT
127IGCM_OUT=${IGCM_OUT:=IGCM_OUT}
128typeset -r R_OUT=${ARCHIVE}/${IGCM_OUT}
129
130#====================================================
131#- R_FIG (hosting figures : monitoring and atlas, and/or small files)
132typeset -r R_FIG=${STORAGE}/IGCM_OUT
133
134#====================================================
135#- R_BUF (ONLY FOR double copy an scratch)
136typeset -r R_BUF=${SCRATCHDIR}/IGCM_OUT
137
138#====================================================
139#- BIG_DIR : BIG_DIR to store files waiting for rebuild
140typeset -r BIG_DIR=${BIG_DIR:=${SCRATCHDIR}/REBUILD}
141
142#====================================================
143#- OUT_POST
144typeset -r R_OUT_POST=${R_OUT}
145
146#====================================================
147#- RUN_DIR_PATH : Temporary working directory (=> TMP)
148typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=${SCRATCHDIR}/tmp$$}
149
150#====================================================
151#- HOST_MPIRUN_COMMAND
152typeset -r HOST_MPIRUN_COMMAND=${HOST_MPIRUN_COMMAND:="time mpirun"}
153
154#=========================================================
155#- Add "time" before mpirun command
156MPIRUN_COMMAND="time "${MPIRUN_COMMAND}
157echo ${MPIRUN_COMMAND}
158
159#====================================================
160#- Max number of arguments passed to nco operator or demigration command
161UNIX_MAX_LIMIT=360
162
163#====================================================
164#- Number of core per node (max number of OpenMP task)
165NUM_COREPERNODE=1
166
167#====================================================
168#- Default number of MPI task for IPSL coupled model
169#- required for backward compatibility
170#-
171DEFAULT_NUM_PROC_OCE=1
172DEFAULT_NUM_PROC_CPL=1
173(( DEFAULT_NUM_PROC_ATM = BATCH_NUM_PROC_TOT - DEFAULT_NUM_PROC_OCE - DEFAULT_NUM_PROC_CPL ))
174DEFAULT_NUM_PROC_TOTAL=${BATCH_NUM_PROC_TOT}
175
176#D-#==================================================
177#D-function IGCM_sys_RshMaster
178#D-* Purpose: Just a fake command to wrapp
179#D-           IGCM_card call in post-treatment
180#D-           Ulam do not see brodie filesystem
181#D-           Cesium do not see all mercure filesystem
182#D-           That's why we need this hack.
183#D-* Examples:
184#D-
185function IGCM_sys_RshMaster {
186  IGCM_debug_PushStack "IGCM_sys_RshMaster" $@
187  ssh ${HOST} /bin/ksh  <<-EOF
188    export libIGCM=${libIGCM}
189    export DEBUG_debug=${DEBUG_debug}
190    . ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh
191    . ${libIGCM}/libIGCM_card/libIGCM_card.ksh
192    ${@}
193EOF
194  if [ $? -gt 0 ] ; then
195    echo "IGCM_sys_RshMaster : erreur."
196    IGCM_debug_Exit "IGCM_sys_RshMaster"
197  fi
198  IGCM_debug_PopStack "IGCM_sys_RshMaster"
199}
200
201#D-#==================================================
202#D-function IGCM_sys_RshArchive
203#D-* Purpose: Archive rsh command
204#D-* Examples:
205#D-
206function IGCM_sys_RshArchive {
207  IGCM_debug_PushStack "IGCM_sys_RshArchive" $@
208  /bin/ksh  <<-EOF
209    ${@}
210EOF
211  if [ $? -gt 0 ] ; then
212    echo "IGCM_sys_RshArchive : erreur."
213    IGCM_debug_Exit "IGCM_sys_RshArchive"
214  fi
215  IGCM_debug_PopStack "IGCM_sys_RshArchive"
216}
217
218#D-#==================================================
219#D-function IGCM_sys_RshPost
220#D-* Purpose: Post-process rsh command
221#D-* Examples:
222#D-
223(( RshPNum = 0 ))
224function IGCM_sys_RshPost {
225  IGCM_debug_PushStack "IGCM_sys_RshPost" $@
226  if ( $DEBUG_sys ) ; then
227    echo "IGCM_sys_RshPost :" $@
228  fi
229  #/bin/ksh -vx $@ > out_RshPost.${RshPNum}
230  ssh ${HOST} /bin/ksh $@ > out_RshPost.${RshPNum}
231  if [ $? -gt 0 ] ; then
232    echo "IGCM_sys_RshPost : erreur."
233    IGCM_debug_Exit "IGCM_sys_RshPost"
234  fi
235  (( RshPNum = RshPNum + 1 ))
236  IGCM_debug_PopStack "IGCM_sys_RshPost"
237}
238
239#D-#==================================================
240#D-function IGCM_sys_SendMail
241#D-* Purpose: Send mail when simulation is over
242#D-* Examples:
243#D-
244function IGCM_sys_SendMail {
245  IGCM_debug_PushStack "IGCM_sys_SendMail" $@
246  if ( $DEBUG_sys ) ; then
247    echo "IGCM_sys_SendMail :" $@
248  fi
249
250  if ( ${ExitFlag} ) ; then
251    status=failed
252  else
253    status=completed
254  fi
255  cat  << END_MAIL > job_end.mail
256Dear ${LOGIN},
257
258  Simulation ${config_UserChoices_JobName} is ${status} on supercomputer `hostname`.
259  Job started : ${DateBegin}
260  Job ended   : ${DateEnd}
261  Output files are available in ${R_SAVE}
262  Script files, Script Outputs and Debug files (if necessary) are available in ${SUBMIT_DIR}
263END_MAIL
264
265  if [ ! -z ${config_UserChoices_MailName} ] ; then
266    mailx -s "${config_UserChoices_JobName} ${status}" ${config_UserChoices_MailName} <  job_end.mail
267  elif [ -f ~/.forward ] ; then
268    mailx -s "${config_UserChoices_JobName} ${status}" $( cat ~/.forward ) < job_end.mail
269  fi
270
271  if [ $? -gt 0 ] ; then
272    echo "IGCM_sys_SendMail : erreur."
273    IGCM_debug_Exit "IGCM_sys_SendMail"
274  fi
275  IGCM_debug_PopStack "IGCM_sys_SendMail"
276}
277
278#D-#==================================================
279#D-function IGCM_sys_Mkdir
280#D-* Purpose: Master locale mkdir command
281#D-* Examples:
282#D-
283function IGCM_sys_Mkdir {
284  IGCM_debug_PushStack "IGCM_sys_Mkdir" $@
285  if ( $DEBUG_sys ) ; then
286    echo "IGCM_sys_Mkdir :" $@
287  fi
288  if [ ! -d ${1} ]; then
289    \mkdir -p $1
290    if [ $? -gt 0 ] ; then
291      echo "IGCM_sys_Mkdir : erreur."
292      IGCM_debug_Exit "IGCM_sys_Mkdir"
293    fi
294  fi
295    # vérification :
296  if [ ! -d ${1} ] ; then
297    echo "IGCM_sys_Mkdir : erreur."
298    IGCM_debug_Exit "IGCM_sys_Mkdir"
299  fi
300  IGCM_debug_PopStack "IGCM_sys_Mkdir"
301}
302
303#D-#==================================================
304#D-function IGCM_sys_MkdirArchive
305#D-* Purpose: Mkdir on Archive
306#D-* Examples:
307#D-
308function IGCM_sys_MkdirArchive {
309  IGCM_debug_PushStack "IGCM_sys_MkdirArchive" $@
310  if ( $DEBUG_sys ) ; then
311    echo "IGCM_sys_MkdirArchive :" $@
312  fi
313    #- creation de repertoire sur le serveur fichier
314  if [ ! -d ${1} ]; then
315    \mkdir -p $1
316    if [ $? -gt 0 ] ; then
317      echo "IGCM_sys_MkdirArchive : erreur."
318      IGCM_debug_Exit "IGCM_sys_MkdirArchive"
319    fi
320  fi
321  IGCM_debug_PopStack "IGCM_sys_MkdirArchive"
322}
323
324#D-#==================================================
325#D-function IGCM_sys_MkdirWork
326#D-* Purpose: Mkdir on Work
327#D-* Examples:
328#D-
329function IGCM_sys_MkdirWork {
330  IGCM_debug_PushStack "IGCM_sys_MkdirWork" $@
331  if ( $DEBUG_sys ) ; then
332    echo "IGCM_sys_MkdirWork :" $@
333  fi
334    #- creation de repertoire sur le serveur fichier
335  if [ ! -d ${1} ]; then
336    \mkdir -p $1
337    if [ $? -gt 0 ] ; then
338      echo "IGCM_sys_MkdirWork : erreur."
339      IGCM_debug_Exit "IGCM_sys_MkdirWork"
340    fi
341  fi
342  IGCM_debug_PopStack "IGCM_sys_MkdirWork"
343}
344
345#D-#==================================================
346#D-function IGCM_sys_Cd
347#D-* Purpose: master cd command
348#D-* Examples:
349#D-
350function IGCM_sys_Cd {
351  IGCM_debug_PushStack "IGCM_sys_Cd" $@
352  if ( $DEBUG_sys ) ; then
353    echo "IGCM_sys_Cd :" $@
354  fi
355  \cd $1
356  if [ $? -gt 0 ] ; then
357    echo "IGCM_sys_Cd : erreur."
358    IGCM_debug_Exit "IGCM_sys_Cd"
359  fi
360  IGCM_debug_PopStack "IGCM_sys_Cd"
361}
362
363#D-#==================================================
364#D-function IGCM_sys_Chmod
365#D-* Purpose: Chmod
366#D-* Examples:
367#D-
368function IGCM_sys_Chmod {
369  IGCM_debug_PushStack "IGCM_sys_Chmod" -- $@
370  if ( $DEBUG_sys ) ; then
371    echo "IGCM_sys_Chmod :" $@
372  fi
373  if [ $DRYRUN -le 1 ]; then
374    \chmod $@
375    if [ $? -gt 0 ] ; then
376      echo "IGCM_sys_Chmod : erreur."
377      IGCM_debug_Exit "IGCM_sys_Chmod"
378    fi
379  else
380    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
381  fi
382  IGCM_debug_PopStack "IGCM_sys_Chmod"
383}
384
385#D-#==================================================
386#D-function IGCM_sys_FileSize
387#D-* Purpose: Filesize
388#D-* Examples:
389#D-
390function IGCM_sys_FileSize {
391  IGCM_debug_PushStack "IGCM_sys_FileSize" $@
392
393  typeset sizeF
394  set +A sizeF -- $( ls -la ${1} )
395  if [ $? -gt 0 ] ; then
396    IGCM_debug_Exit "IGCM_sys_FileSize"
397  fi
398  eval ${2}=${sizeF[4]}
399
400  IGCM_debug_PopStack "IGCM_sys_FileSize"
401}
402
403#D-#==================================================
404#D-function IGCM_sys_TestDir
405#D-* Purpose: Test Directory that must exists
406#D-* Examples:
407#D-
408function IGCM_sys_TestDir {
409  IGCM_debug_PushStack "IGCM_sys_TestDir" $@
410  if ( $DEBUG_sys ) ; then
411    echo "IGCM_sys_TestDir :" $@
412  fi
413  typeset ExistFlag
414  ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
415  IGCM_debug_PopStack "IGCM_sys_TestDir"
416
417  return ${ExistFlag}
418}
419
420#D-#==================================================
421#D-function IGCM_sys_TestDirArchive
422#D-* Purpose: Test Directory that must exists on Archive
423#D-* Examples:
424#D-
425function IGCM_sys_TestDirArchive {
426  IGCM_debug_PushStack "IGCM_sys_TestDirArchive" $@
427  if ( $DEBUG_sys ) ; then
428    echo "IGCM_sys_TestDirArchive :" $@
429  fi
430  typeset ExistFlag
431  ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
432  IGCM_debug_PopStack "IGCM_sys_TestDirArchive"
433
434  return ${ExistFlag}
435}
436
437#D-#==================================================
438#D-function IGCM_sys_TestFileArchive
439#D-* Purpose: Test file that must NOT EXISTS on Archive
440#D-* Examples:
441#D-
442function IGCM_sys_TestFileArchive {
443  IGCM_debug_PushStack "IGCM_sys_TestFileArchive" $@
444  typeset ExistFlag
445  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
446  IGCM_debug_PopStack "IGCM_sys_TestFileArchive"
447
448  return ${ExistFlag}
449}
450
451#D-#==================================================
452#D-function IGCM_sys_TestFileBuffer
453#D-* Purpose: Test file that must NOT EXISTS on Buffer
454#D-* Examples:
455#D-
456function IGCM_sys_TestFileBuffer {
457  IGCM_debug_PushStack "IGCM_sys_TestFileBuffer" $@
458  typeset ExistFlag
459  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
460  IGCM_debug_PopStack "IGCM_sys_TestFileBuffer"
461
462  return ${ExistFlag}
463}
464
465#D-#==================================================
466#D-function IGCM_sys_CountFileArchive
467#D-* Purpose: Count files on Archive filesystem
468#D-* Examples:
469#D-
470function IGCM_sys_CountFileArchive {
471  IGCM_debug_PushStack "IGCM_sys_CountFileArchive" $@
472  ls ${@} 2>/dev/null | wc -l
473  if [ $? -gt 0 ] ; then
474    echo "IGCM_sys_CountFileArchive : erreur."
475  fi
476  IGCM_debug_PopStack "IGCM_sys_CountFileArchive"
477}
478
479#D-#==================================================
480#D-function IGCM_sys_CountFileBuffer
481#D-* Purpose: Count files on Scratch filesystem
482#D-* Examples:
483#D-
484function IGCM_sys_CountFileBuffer {
485  IGCM_debug_PushStack "IGCM_sys_CountFileBuffer" $@
486  ls ${@} 2>/dev/null | wc -l
487  if [ $? -gt 0 ] ; then
488    echo "IGCM_sys_CountFileBuffer : erreur."
489  fi
490  IGCM_debug_PopStack "IGCM_sys_CountFileBuffer"
491}
492
493#D-#==================================================
494#D-function IGCM_sys_Tree
495#D-* Purpose: Tree directories with files on ${ARCHIVE}
496#D-* Examples: IGCM_sys_Tree ${R_IN} ${R_OUT}
497#D-
498function IGCM_sys_Tree {
499  IGCM_debug_PushStack "IGCM_sys_Tree" $@
500  if ( $DEBUG_sys ) ; then
501    echo "IGCM_sys_Tree :" $@
502  fi
503
504  \tree -f $@
505
506  IGCM_debug_PopStack "IGCM_sys_Tree"
507}
508
509#D-#==================================================
510#D-function IGCM_sys_Tar
511#D-* Purpose: master tar command
512#D-* Examples:
513#D-
514function IGCM_sys_Tar {
515  IGCM_debug_PushStack "IGCM_sys_Tar" $@
516  if ( $DEBUG_sys ) ; then
517    echo "IGCM_sys_Tar :" $@
518  fi
519  \tar cf $@
520  if [ $? -gt 0 ] ; then
521    echo "IGCM_sys_Tar : erreur."
522    IGCM_debug_Exit "IGCM_sys_Tar"
523  fi
524  IGCM_debug_PopStack "IGCM_sys_Tar"
525}
526
527#D-#==================================================
528#D-function IGCM_sys_UnTar
529#D-* Purpose: master un-tar command
530#D-* Examples:
531#D-
532function IGCM_sys_UnTar {
533  IGCM_debug_PushStack "IGCM_sys_UnTar" $@
534  if ( $DEBUG_sys ) ; then
535    echo "IGCM_sys_UnTar :" $@
536  fi
537  \tar xvf $1
538  if [ $? -gt 0 ] ; then
539    echo "IGCM_sys_UnTar : erreur."
540    IGCM_debug_Exit "IGCM_sys_UnTar"
541  fi
542  IGCM_debug_PopStack "IGCM_sys_UnTar"
543}
544
545#D-#==================================================
546#D-function IGCM_sys_Qsub
547#D-* Purpose: Qsub new job
548#D-* Examples:
549#D-
550function IGCM_sys_Qsub {
551  IGCM_debug_PushStack "IGCM_sys_Qsub" $@
552  if ( $DEBUG_sys ) ; then
553    echo "IGCM_sys_Qsub :" $@
554  fi
555  echo "ssh -l ${LOGIN} ${HOST} ""cd ${SUBMIT_DIR} ; ${@}"" > ${Script_Output} 2>&1 &"
556  ssh -l ${LOGIN} ${HOST} "cd ${SUBMIT_DIR} ; ${@}" > ${Script_Output} 2>&1 &
557  if [ $? -gt 0 ] ; then
558    echo "IGCM_sys_Qsub : erreur."
559    IGCM_debug_Exit "IGCM_sys_Qsub"
560  fi
561  IGCM_debug_PopStack "IGCM_sys_Qsub"
562}
563
564#D-#==================================================
565#D-function IGCM_sys_QsubPost
566#D-* Purpose: Qsub new job on scalaire
567#D-* Examples:
568#D-
569function IGCM_sys_QsubPost {
570  IGCM_debug_PushStack "IGCM_sys_QsubPost" $@
571  if ( $DEBUG_sys ) ; then
572    echo "IGCM_sys_QsubPost :" $@
573  fi
574    #echo "ssh -x -l ${LOGIN} ${HOST} ${3} > ${2} 2>&1 &"
575    #    ssh -x -l ${LOGIN} ${HOST}
576  echo "${libIGCM_POST}/$1.job > ${POST_DIR}/$1.${PeriodDateEnd}.out 2>&1 &"
577  ${libIGCM_POST}/$1.job > ${POST_DIR}/${Script_Post_Output}.out 2>&1 &
578    #    ${3} > ${2} 2>&1 &
579  if [ $? -gt 0 ] ; then
580    echo "IGCM_sys_QsubPost : erreur " $@
581    IGCM_debug_Exit "IGCM_sys_QsubPost"
582  fi
583  IGCM_debug_PopStack "IGCM_sys_QsubPost"
584}
585
586#D-*************************
587#D- File transfer functions
588#D-*************************
589#D-
590
591#D-#==================================================
592#D-function IGCM_sys_Rsync_out
593#D-* Purpose: treat return val of rsync
594#D-* Examples:  IGCM_sys_Rsync_out out_RET_rsync
595#D-  Error values and explanations can depend on your system version.
596function IGCM_sys_Rsync_out {
597  RET=$1
598  if [ ! $RET ] ; then
599    echo "rsync error !"
600  fi
601
602  if [ $MYLANG = "fr" ]; then
603    case $RET in
604    0)  return ;;
605    1)  echo "Erreur de rsync ; RERR_SYNTAX : "
606      echo "Erreur de syntaxe ou d'utilisation."
607      return;;
608    2)  echo "Erreur de rsync ; RERR_PROTOCOL : "
609      echo "Incompatibilité de protocole."
610      return;;
611    3)  echo "Erreur de rsync ; RERR_FILESELECT 3"
612      echo "Erreurs  lors  de  la  sélection des fichiers d'entrée sortie et"
613      echo "répertoires"
614      return;;
615    4)  echo "Erreur de rsync ; RERR_UNSUPPORTED"
616      echo "Action demandée non supportée : une tentative de manipulation de"
617      echo "fichiers  64-bits  sur une plate-forme qui ne les supporte pas a"
618      echo "été faite ; ou une option qui est supportée par le  client  mais"
619      echo "pas par le serveur a été spécifiée."
620      return;;
621    10) echo "Erreur de rsync ; RERR_SOCKETIO"
622      echo "Erreur dans le socket d'entrée sortie"
623      return;;
624    11) echo "Erreur de rsync ; RERR_FILEIO"
625      echo "Erreur d'entrée sortie fichier"
626      return;;
627    12) echo "Erreur de rsync ; RERR_STREAMIO"
628      echo "Erreur dans flux de donnée du protocole rsync"
629      return;;
630    13) echo "Erreur de rsync ; RERR_MESSAGEIO"
631      echo "Erreur avec les diagnostics du programme"
632      return;;
633    14) echo "Erreur de rsync ; RERR_IPC"
634      echo "Erreur dans le code IPC"
635      return;;
636    20) echo "Erreur de rsync ; RERR_SIGNAL"
637      echo "SIGUSR1 ou SIGINT reçu"
638      return;;
639    21) echo "Erreur de rsync ; RERR_WAITCHILD"
640      echo "Une erreur retournée par waitpid()"
641      return;;
642    22) echo "Erreur de rsync ; RERR_MALLOC"
643      echo "Erreur lors de l'allocation des tampons de mémoire de coeur"
644      return;;
645    23) echo ""
646      echo "Erreur fichier inexistant"
647      return;;
648    30) echo "Erreur de rsync ; RERR_TIMEOUT"
649      echo "Temps d'attente écoulé dans l'envoi/réception de données"
650      return;;
651    *)  echo "Erreur de rsync : code de retour de rsync inconnu :" $RET
652      return;;
653    esac
654  elif [ $MYLANG = "en" ] ; then
655    case $RET in
656    0)  return;;
657    1)  echo "rsync error : Syntax or usage error "
658      return;;
659    2)  echo "rsync error : Protocol incompatibility "
660      return;;
661    3)  echo "rsync error : Errors selecting input/output files, dirs"
662      return;;
663    4)  echo "rsync error : Requested action not supported: an attempt"
664      echo "was made to manipulate 64-bit files on a platform that cannot support"
665      echo "them; or an option was specified that is supported by the client and"
666      echo "not by the server."
667      return;;
668    5)  echo "rsync error : Error starting client-server protocol"
669      return;;
670    10) echo "rsync error : Error in socket I/O "
671      return;;
672    11) echo "rsync error : Error in file I/O "
673      return;;
674    12) echo "rsync error : Error in rsync protocol data stream "
675      return;;
676    13) echo "rsync error : Errors with program diagnostics "
677      return;;
678    14) echo "rsync error : Error in IPC code "
679      return;;
680    20) echo "rsync error : Received SIGUSR1 or SIGINT "
681      return;;
682    21) echo "rsync error : Some error returned by waitpid() "
683      return;;
684    22) echo "rsync error : Error allocating core memory buffers "
685      return;;
686    23) echo "rsync error : Partial transfer due to error"
687      return;;
688    24) echo "rsync error : Partial transfer due to vanished source files"
689      return;;
690    30) echo "rsync error : Timeout in data send/receive "
691      return;;
692    *)  echo "rsync error : return code of rsync unknown :" $RET
693      return;;
694    esac
695  else
696    echo "unknown language $MYLANG."
697    return
698  fi
699}
700
701#D-#==================================================
702#D-function IGCM_sys_Cp
703#D-* Purpose: generic cp
704#D-* Examples:
705#D-
706function IGCM_sys_Cp {
707  IGCM_debug_PushStack "IGCM_sys_Cp" $@
708  if ( $DEBUG_sys ) ; then
709    echo "IGCM_sys_Cp :" $@
710  fi
711
712  typeset status
713
714  echo cp $@ > out_rsync 2>&1
715  \cp $@ >> out_rsync 2>&1
716  status=$?
717
718  if [ ${status} -gt 0 ] ; then
719    echo "IGCM_sys_Cp : error code ${status}"
720    cat out_rsync
721    IGCM_debug_Exit "IGCM_sys_Cp"
722  else
723    \rm out_rsync
724  fi
725  IGCM_debug_PopStack "IGCM_sys_Cp"
726}
727
728#D-#==================================================
729#D-function IGCM_sys_Rm
730#D-* Purpose: generic rm
731#D-* Examples:
732#D-
733function IGCM_sys_Rm {
734  IGCM_debug_PushStack "IGCM_sys_Rm" -- $@
735  if ( $DEBUG_sys ) ; then
736    echo "IGCM_sys_Rm :" $@
737  fi
738
739  typeset status
740
741  echo rm $@ > out_rsync 2>&1
742  \rm $@ >> out_rsync 2>&1
743  status=$?
744
745  if [ ${status} -gt 0 ] ; then
746    echo "IGCM_sys_Rm : error code ${status}"
747    cat out_rsync
748    IGCM_debug_Exit "IGCM_sys_Rm"
749  else
750    \rm out_rsync
751  fi
752  IGCM_debug_PopStack "IGCM_sys_Rm"
753}
754
755#D-#==================================================
756#D-function IGCM_sys_RmRunDir
757#D-* Purpose: rm tmpdir (dummy function most of the time batch
758#D-                      scheduler will do the job)
759#D-* Examples:
760#D-
761function IGCM_sys_RmRunDir {
762  IGCM_debug_PushStack "IGCM_sys_RmRunDir" -- $@
763  if ( $DEBUG_sys ) ; then
764    echo "IGCM_sys_RmRunDir :" $@
765    echo "Dummy call, let the scheduler do that."
766#       IGCM_sys_Rm -rf ${RUN_DIR}
767  fi
768  IGCM_debug_PopStack "IGCM_sys_RmRunDir"
769}
770
771#D-#==================================================
772#D-function IGCM_sys_Mv
773#D-* Purpose: generic move
774#D-* Examples:
775#D-
776function IGCM_sys_Mv {
777  IGCM_debug_PushStack "IGCM_sys_Mv" $@
778  if ( $DEBUG_sys ) ; then
779    echo "IGCM_sys_Mv :" $@
780  fi
781
782  if [ $DRYRUN = 0 ]; then
783
784    typeset status
785
786    echo mv $@ > out_rsync 2>&1
787    \mv $@ >> out_rsync 2>&1
788    status=$?
789
790    if [ ${status} -gt 0 ] ; then
791      echo "IGCM_sys_Mv : error code ${status}"
792      cat out_rsync
793      IGCM_debug_Exit "IGCM_sys_Mv"
794    else
795      \rm out_rsync
796    fi
797  else
798    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
799  fi
800
801  IGCM_debug_PopStack "IGCM_sys_Mv"
802}
803
804#D-#==================================================
805#D-function IGCM_sys_Put_Dir
806#D-* Purpose: Copy a complete directory on $(ARCHIVE)
807#D-* Examples:
808#D-
809function IGCM_sys_Put_Dir {
810  IGCM_debug_PushStack "IGCM_sys_Put_Dir" $@
811  if ( $DEBUG_sys ) ; then
812    echo "IGCM_sys_Put_Dir :" $@
813  fi
814  if [ $DRYRUN = 0 ]; then
815    if [ ! -d ${1} ] ; then
816      echo "WARNING : IGCM_sys_Put_Dir ${1} DOES NOT EXIST ."
817      IGCM_debug_PopStack "IGCM_sys_Put_Dir"
818      return
819    fi
820
821    typeset status
822
823    # Only if we use rsync
824    #IGCM_sys_TestDirArchive $( dirname $2 )
825    #
826    #USUAL WAY
827    \cp -r $1 $2 > out_rsync 2>&1
828    status=$?
829
830    if [ ${status} -gt 0 ] ; then
831      echo "IGCM_sys_Put_Dir : error code ${status}"
832      cat out_rsync
833      IGCM_debug_Exit "IGCM_sys_Put_Dir"
834    else
835      \rm out_rsync
836    fi
837  else
838    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
839  fi
840  IGCM_debug_PopStack "IGCM_sys_Put_Dir"
841}
842
843#D-#==================================================
844#D-function IGCM_sys_Get_Dir
845#D-* Purpose: Copy a complete directory from ${ARCHIVE}
846#D-* Examples:
847#D-
848function IGCM_sys_Get_Dir {
849  IGCM_debug_PushStack "IGCM_sys_Get_Dir" $@
850  if ( $DEBUG_sys ) ; then
851    echo "IGCM_sys_Get_Dir :" $@
852  fi
853  if [ $DRYRUN = 0 ]; then
854    if [ ! -d ${1} ] ; then
855      echo "WARNING : IGCM_sys_Get_Dir ${1} DOES NOT EXIST ."
856      IGCM_debug_PopStack "IGCM_sys_Get_Dir"
857      return
858    fi
859
860    typeset RET
861
862        #USUAL WAY
863    \cp -R $1 $2 > out_rsync 2>&1
864    RET=$?
865
866    if [ ${RET} -gt 0 ] ; then
867      echo "IGCM_sys_Get_Dir : error."
868      cat out_rsync
869      IGCM_debug_Exit "IGCM_sys_Get_Dir"
870    else
871      \rm out_rsync
872    fi
873  else
874    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
875  fi
876  IGCM_debug_PopStack "IGCM_sys_Get_Dir"
877}
878
879#D-#==================================================
880#D-function IGCM_sys_Get_Master
881#D-* Purpose: Copy a complete directory from MASTER filesystem
882#D-* Examples:
883#D-
884function IGCM_sys_Get_Master {
885  IGCM_debug_PushStack "IGCM_sys_Get_Master" $@
886  if ( $DEBUG_sys ) ; then
887    echo "IGCM_sys_Get_Master :" $@
888  fi
889  if [ $DRYRUN = 0 ]; then
890    if ( [ ! -d ${1} ] && [ ! -f ${1} ] ) ; then
891      echo "WARNING : IGCM_sys_Get_Master ${1} DOES NOT EXIST ."
892      IGCM_debug_PopStack "IGCM_sys_Get_Master"
893      return
894    fi
895
896    typeset RET
897
898        #USUAL WAY
899    cp -RL $1 $2 > out_rsync 2>&1
900    RET=$?
901
902    if [ ${RET} -gt 0 ] ; then
903      echo "IGCM_sys_Get_Master : error."
904      cat out_rsync
905      IGCM_debug_Exit "IGCM_sys_Get_Master"
906    else
907      \rm out_rsync
908    fi
909  else
910    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
911  fi
912  IGCM_debug_PopStack "IGCM_sys_Get_Master"
913}
914
915#D-#==================================================
916#D-function IGCM_sys_Put_Rest
917#D-* Purpose: Put computied restarts on ${ARCHIVE}.
918#D-           File and target directory must exist.
919#D-* Examples:
920#D-
921function IGCM_sys_Put_Rest {
922  IGCM_debug_PushStack "IGCM_sys_Put_Rest" $@
923  if ( $DEBUG_sys ) ; then
924    echo "IGCM_sys_Put_Rest :" $@
925  fi
926  if [ $DRYRUN = 0 ]; then
927    if [ ! -f ${1} ] ; then
928      echo "ERROR : IGCM_sys_Put_Rest ${1} DOES NOT EXIST ."
929      IGCM_debug_Exit "IGCM_sys_Put_Rest"
930    fi
931
932    typeset status
933    #
934    if [ X${JobType} = XRUN ] ; then
935      IGCM_sys_Chmod 444 ${1}
936    fi
937
938    #
939    # USUAL WAY
940    \cp $1 $2 > out_rsync 2>&1
941    status=$?
942
943#       #RSYNC WITH NETWORK SSH CALL
944#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > out_rsync 2>&1
945#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> out_rsync 2>&1
946
947#       #RSYNC WITH NFS USE
948#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
949#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
950
951#       status=$?
952#       IGCM_sys_Rsync_out $status
953
954#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
955#       (( status=status+$? ))
956
957    if [ ${status} -gt 0 ] ; then
958      echo "IGCM_sys_Put_Rest : cp failed error code ${status}"
959      cat out_rsync
960      IGCM_debug_Exit "IGCM_sys_Put_Rest"
961    else
962      \rm out_rsync
963    fi
964  else
965    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
966  fi
967  IGCM_debug_PopStack "IGCM_sys_Put_Rest"
968}
969
970#D-#==================================================
971#D-function IGCM_sys_PutBuffer_Rest
972#D-* Purpose: Put computied restarts on ${SCRATCHDIR}.
973#D-           File and target directory must exist.
974#D-* Examples:
975#D-
976function IGCM_sys_PutBuffer_Rest {
977  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Rest" $@
978  if ( $DEBUG_sys ) ; then
979    echo "IGCM_sys_PutBuffer_Rest :" $@
980  fi
981  if [ $DRYRUN = 0 ]; then
982    if [ ! -f ${1} ] ; then
983      echo "ERROR : IGCM_sys_PutBuffer_Rest ${1} DOES NOT EXIST ."
984      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
985    fi
986
987    typeset status
988    #
989    if [ X${JobType} = XRUN ] ; then
990      IGCM_sys_Chmod 444 ${1}
991    fi
992
993    #
994    # USUAL WAY
995    \cp $1 $2 > out_rsync 2>&1
996    status=$?
997
998    if [ ${status} -gt 0 ] ; then
999      echo "IGCM_sys_PutBuffer_Rest : error code ${status}"
1000      cat out_rsync
1001      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
1002    else
1003      \rm out_rsync
1004    fi
1005  else
1006    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1007  fi
1008  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Rest"
1009}
1010
1011#D-#==================================================
1012#D-function IGCM_sys_Put_Out
1013#D-* Purpose: Copy a file on ${ARCHIVE} after having chmod it in readonly
1014#D-* Examples:
1015#D-
1016function IGCM_sys_Put_Out {
1017  IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
1018  if ( $DEBUG_sys ) ; then
1019    echo "IGCM_sys_Put_Out :" $@
1020  fi
1021  if [ $DRYRUN = 0 ]; then
1022    if [ -f ${1} ] ; then
1023      if [ ! -d $( dirname $2 ) ] ; then
1024        IGCM_sys_MkdirArchive $( dirname $2 )
1025      fi
1026    else
1027      echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
1028      IGCM_debug_PopStack "IGCM_sys_Put_Out"
1029      return 1
1030    fi
1031
1032    typeset RET
1033        #
1034    if [ X${JobType} = XRUN ] ; then
1035      if [ X${3} = X ] ; then
1036        IGCM_sys_Chmod 444 ${1}
1037      fi
1038    fi
1039        #
1040
1041    echo ${RSYNC} ${RSYNC_opt} $1 $2 > out_rsync 2>&1
1042    ${RSYNC} ${RSYNC_opt} $1 $2 >> out_rsync 2>&1
1043    RET=$?
1044    IGCM_sys_Rsync_out $RET
1045
1046    ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1047    (( RET=RET+$? ))
1048
1049    if [ ${RET} -gt 0 ] ; then
1050      echo "IGCM_sys_Put_Out : error."
1051      cat out_rsync
1052      IGCM_debug_Exit "IGCM_sys_Put_Out"
1053    else
1054      \rm out_rsync
1055    fi
1056  else
1057    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1058  fi
1059  IGCM_debug_PopStack "IGCM_sys_Put_Out"
1060  return 0
1061}
1062
1063#D-#==================================================
1064#D-function IGCM_sys_PutBuffer_Out
1065#D-* Purpose: Copy a file on ${SCRATCHDIR} after having chmod it in readonly
1066#D-* Examples:
1067#D-
1068function IGCM_sys_PutBuffer_Out {
1069  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Out" $@
1070  if ( $DEBUG_sys ) ; then
1071    echo "IGCM_sys_PutBuffer_Out :" $@
1072  fi
1073  if [ $DRYRUN = 0 ]; then
1074    if [ ! -f ${1} ] ; then
1075      echo "WARNING : IGCM_sys_PutBuffer_Out ${1} DOES NOT EXIST ."
1076      IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1077      return 1
1078    fi
1079    #
1080    IGCM_sys_Mkdir $( dirname $2 )
1081    #
1082    typeset RET
1083
1084    if [ X${JobType} = XRUN ] ; then
1085      if [ X${3} = X ] ; then
1086        IGCM_sys_Chmod 444 ${1}
1087      fi
1088    fi
1089    #
1090    # USUAL WAY
1091    \cp $1 $2 > out_rsync 2>&1
1092    RET=$?
1093
1094    if [ ${RET} -gt 0 ] ; then
1095      echo "IGCM_sys_PutBuffer_Out : error."
1096      cat out_rsync
1097      IGCM_debug_Exit "IGCM_sys_PutBuffer_Out"
1098    else
1099      \rm out_rsync
1100    fi
1101  else
1102    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1103  fi
1104  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1105  return 0
1106}
1107
1108#D-#==================================================
1109#D-function IGCM_sys_Get
1110#D-* Purpose: Get a file from ${ARCHIVE}
1111#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
1112#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
1113function IGCM_sys_Get {
1114  IGCM_debug_PushStack "IGCM_sys_Get" $@
1115
1116  typeset DEST RET dm_liste ifile target
1117
1118  if ( $DEBUG_sys ) ; then
1119    echo "IGCM_sys_Get :" $@
1120  fi
1121  if [ $DRYRUN -le 2 ]; then
1122    if [ X${1} = X'/l' ] ; then
1123      # test if the first file is present in the old computation :
1124      eval set +A dm_liste \${${2}}
1125    else
1126      dm_liste=${1}
1127    fi
1128    eval DEST=\${${#}}
1129
1130        # test if the (first) file is present in the old computation :
1131    IGCM_sys_TestFileArchive ${dm_liste[0]}
1132    RET=$?
1133    if [ ${RET} -gt 0 ] ; then
1134      echo "IGCM_sys_Get, ERROR : regular file ${dm_liste[0]} DOES NOT EXIST ."
1135      IGCM_debug_Exit "IGCM_sys_Get"
1136            #return
1137    fi
1138
1139    (( RET=0 ))
1140    for target in ${dm_liste[*]} ; do
1141      \cp ${target} ${DEST} >> out_rsync 2>&1
1142      (( RET=RET+$? ))
1143    done
1144
1145#       echo ${RSYNC} ${RSYNC_opt} $@ > out_rsync 2>&1
1146#       ${RSYNC} ${RSYNC_opt} $@ >> out_rsync 2>&1
1147#       RET=$?
1148#       IGCM_sys_Rsync_out $RET
1149
1150#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1151#       (( RET=RET+$? ))
1152
1153    if [ ${RET} -gt 0 ] ; then
1154      echo "IGCM_sys_Get : error"
1155      cat out_rsync
1156      \rm out_rsync
1157      IGCM_debug_Exit "IGCM_sys_Get"
1158    else
1159      \rm out_rsync
1160    fi
1161  else
1162    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1163  fi
1164  IGCM_debug_PopStack "IGCM_sys_Get"
1165}
1166
1167#D-#==================================================
1168#D-function IGCM_sys_GetBuffer
1169#D-* Purpose: Get a file from ${SCRATCHDIR}
1170#D-* Examples: IGCM_sys_GetBuffer myfile /destpath/myfile_with_PREFIX
1171#D-            IGCM_sys_GetBuffer /l Array_contain_myfiles /destpath/
1172function IGCM_sys_GetBuffer {
1173  IGCM_debug_PushStack "IGCM_sys_GetBuffer" $@
1174
1175  typeset DEST RET status buf_liste ifile target file_work
1176
1177  if ( $DEBUG_sys ) ; then
1178    echo "IGCM_sys_GetBuffer :" $@
1179  fi
1180  if [ $DRYRUN -le 2 ]; then
1181    if [ X${1} = X'/l' ] ; then
1182      # test if the first file is present in the old computation :
1183      eval set +A buf_liste \${${2}}
1184    else
1185      eval set +A buf_liste ${1}
1186    fi
1187    eval DEST=\${${#}}
1188
1189    #USUAL WAY
1190    if [ X${1} = X'/l' ] ; then
1191      (( RET=0 ))
1192      for target in ${buf_liste[*]} ; do
1193        local_file=$( basename ${target} )
1194        \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1195        (( RET = RET + $? ))
1196      done
1197    else
1198      \cp ${buf_liste} ${DEST} >> out_rsync 2>&1
1199      status=$?
1200    fi
1201
1202    if [ ${RET} -gt 0 ] ; then
1203      echo "IGCM_sys_GetBuffer : error"
1204      cat out_rsync
1205      \rm out_rsync
1206      IGCM_debug_Exit "IGCM_sys_GetBuffer"
1207    else
1208      \rm out_rsync
1209    fi
1210  else
1211    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1212  fi
1213  IGCM_debug_PopStack "IGCM_sys_GetBuffer"
1214}
1215
1216#D-#==================================================
1217#D-function IGCM_sys_GetDate_FichWork
1218#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
1219#D-* Examples:
1220#D-
1221function IGCM_sys_GetDate_FichWork {
1222  IGCM_debug_PushStack "IGCM_sys_FichWork" $@
1223  if ( $DEBUG_sys ) ; then
1224    echo "IGCM_sys_GetDate_FichWork :" $@
1225  fi
1226  typeset dateF
1227  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1228  eval ${2}=${dateF[5]}
1229
1230    # donne la date filesys d'un fichier sur la machine work
1231  IGCM_debug_PopStack "IGCM_sys_FichWork"
1232}
1233
1234#D-#==================================================
1235#D-function IGCM_sys_GetDate_FichArchive
1236#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
1237#D-* Examples:
1238#D-
1239function IGCM_sys_GetDate_FichArchive {
1240  IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
1241  if ( $DEBUG_sys ) ; then
1242    echo "IGCM_sys_GetDate_FichArchive :" $@
1243  fi
1244  typeset dateF
1245  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1246  eval ${2}=${dateF[5]}
1247
1248  IGCM_debug_PopStack "IGCM_sys_FichArchive"
1249}
1250
1251#D-#==================================================
1252#D-function IGCM_sys_Dods_Rm
1253#D-* Purpose: DO NOTHING ! Put ${ARCHIVE} files on DODS internet protocole.
1254#D-* Examples:
1255#D-
1256function IGCM_sys_Dods_Rm {
1257  if ( $DEBUG_sys ) ; then
1258    echo "IGCM_sys_Dods_Rm :" $@
1259  fi
1260  return 0
1261}
1262
1263
1264#D-#==================================================
1265#D-function IGCM_sys_Dods_Cp
1266#D-* Purpose: Copy from $(ARCHIVE) files to /tmp/DODS for simulation of internet protocole.
1267#D-* Examples:
1268#D-
1269function IGCM_sys_Dods_Cp {
1270  if ( $DEBUG_sys ) ; then
1271    echo "IGCM_sys_Dods_Cp :" $@
1272  fi
1273  return 0
1274}
1275
1276#D-#==================================================
1277#D-function IGCM_sys_Put_Dods
1278#D-* Purpose: Put $(ARCHIVE) files on /tmp/DODS for simulation of internet protocole.
1279#D-* Examples:
1280#D-
1281function IGCM_sys_Put_Dods {
1282  IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
1283  if ( $DEBUG_sys ) ; then
1284    echo "IGCM_sys_Put_Dods :" $@
1285  fi
1286  if [ $DRYRUN = 0 ]; then
1287    RET=0
1288
1289    if [ ${RET} -gt 0 ] ; then
1290      echo "IGCM_sys_Put_Dods : error."
1291      IGCM_debug_Exit "IGCM_sys_Put_Dods"
1292    fi
1293  else
1294    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1295  fi
1296  IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1297}
1298
1299##############################################################
1300# REBUILD OPERATOR
1301
1302function IGCM_sys_rebuild {
1303  IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1304  if ( $DEBUG_sys ) ; then
1305    echo "IGCM_sys_rebuild :" $@
1306  fi
1307  rebuild -f -o $@
1308  if [ $? -gt 0 ] ; then
1309    echo "IGCM_sys_rebuild : rebuild error"
1310    IGCM_debug_Exit "rebuild"
1311  fi
1312
1313  IGCM_debug_PopStack "IGCM_sys_rebuild"
1314}
1315
1316function IGCM_sys_rebuild_station {
1317  IGCM_debug_PushStack "IGCM_sys_rebuild_station" -- $@
1318  typeset i list_opt file_in file_out prefix_invert list_invert
1319  if ( $DEBUG_sys ) ; then
1320    echo "IGCM_sys_rebuild_station :" $@
1321  fi
1322  list_opt=$@
1323
1324  # Invert Axis : t,x -> x,t
1325  #               t,pres,x -> x,t,pres
1326  # So that we can concatenate along x
1327  i=0
1328  for file_in in ${list_opt} ; do
1329    (( i = i + 1))
1330    [ ${i} = 1 ] && file_out=${file_in} && continue
1331    prefix_invert=$( basename ${file_in} .nc )
1332    IGCM_sys_ncpdq -a x,time_counter -a x,time_counter,presnivs ${file_in} ${prefix_invert}_xt.nc
1333    list_invert[${#list_invert[*]}]=${prefix_invert}_xt.nc
1334  done
1335
1336  # Concatenate
1337  IGCM_sys_ncrcat ${list_invert[*]} histstn_xt.nc
1338
1339  # Re-ivert file
1340  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x histstn_xt.nc ${file_out}
1341
1342  # Station re-ordering is too expansive to be run within libICGM
1343  # This is due to (ncpdq - nrcat - ncpdq) I/O sequence.
1344  # This re-ordering must be done "in memory" by the cmorization process
1345  # Anyway this is the best sequence using (ncpdq - nrcat - ncpdq)
1346  # BEGIN reordering
1347
1348  # Only LMDZ text output contains the exact ordering of the station.
1349  # We isolate this in the code below:
1350  #  0  38  -157.5000000000000  70.98591549295774
1351  #  0  54  27.49999999999999   67.18309859154928
1352  #  0  56  -62.50000000000001  82.39436619718309
1353  #  0  79  12.49999999999999   78.59154929577466
1354  #  0  116 -165.0000000000000  76.05633802816901
1355  #  0  117 130.0000000000000   70.98591549295774
1356  #  0  118 110.0000000000000   87.46478873239437
1357  #  1  40  4.999999999999995   51.97183098591550
1358#  typeset iStation iProc list_opt file_in file_out prefix_invert
1359#  typeset -Z4 j4
1360#  typeset -Z3 j3
1361
1362#  unset list_opt
1363#  set +A list_opt $@
1364
1365  # Filename after rebuild
1366#  file_out=${list_opt[0]}
1367  # Prefix of output files
1368#  prefix_invert=$( basename ${file_out} .nc )
1369  # Number of procs
1370#  num_proc=$( grep -i mpi_size ${PREFIX}_${Exe_Output} | wc -l )
1371
1372#  iProc=0
1373#  while [ ${iProc} -lt ${num_proc} ] ; do
1374    # Array containing Station as a number
1375#    unset proc_stn
1376#    set +A proc_stn $( grep "iophy_mpi rank ip lon lat  $iProc" ${PREFIX}_${Exe_Output} | sed -e "s/iophy_mpi rank ip lon lat //g" | awk ' {print $2}' )
1377    # Number of stations produced by processor proc
1378#    stationLast=${#proc_stn[*]}
1379    # Proc number on 4 digits
1380#    j4=${iProc}
1381    # Init
1382#    iStation=0
1383#    while [ ${iStation} -lt ${stationLast} ] ; do
1384      # Station number on 3 digits
1385#      j3=${proc_stn[${iStation}]}
1386      # Extract station
1387      # Invert Axis : t,x -> x,t
1388      #               t,pres,x -> x,t,pres
1389      # So that we can concatenate along x
1390#      IGCM_sys_ncpdq -a x,time_counter -a x,time_counter,presnivs -d x,$iStation,$iStation ${prefix_invert}_${j4}.nc ${prefix_invert}_stn_${j3}.nc
1391#      (( iStation = iStation + 1 ))
1392#    done
1393#    (( iProc = iProc + 1 ))
1394#  done
1395
1396  # Concatenate all station along x
1397#  IGCM_sys_ncrcat ${prefix_invert}_stn_???.nc ${prefix_invert}_xt.nc
1398
1399  # Re-invert file
1400#  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x ${prefix_invert}_xt.nc ${file_out}
1401
1402  # END reordering
1403
1404  IGCM_debug_PopStack "IGCM_sys_rebuild_station"
1405}
1406
1407############################################################
1408# Activate Running Environnment Variables
1409
1410function IGCM_sys_activ_variables {
1411  IGCM_debug_PushStack "IGCM_sys_activ_variables"
1412  if ( $DEBUG_sys ) ; then
1413    echo "IGCM_sys_activ_variables"
1414  fi
1415  IGCM_debug_PopStack "IGCM_sys_activ_variables"
1416}
1417
1418############################################################
1419# Desactivate Running Environnment Variables
1420
1421function IGCM_sys_desactiv_variables {
1422  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1423  if ( $DEBUG_sys ) ; then
1424    echo "IGCM_sys_desactiv_variables"
1425  fi
1426  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1427}
1428
1429############################################################
1430# Build run file
1431
1432function IGCM_sys_build_run_file {
1433
1434  IGCM_debug_Print 3 " dummy function : IGCM_sys_build_run_file "
1435
1436}
1437
1438############################################################
1439# Build MPI/OMP scripts
1440function IGCM_sys_build_execution_scripts
1441{
1442  IGCM_debug_PushStack "IGCM_sys_build_execution_scripts" $@
1443  if ( $DEBUG_sys ) ; then
1444    echo "IGCM_sys_build_execution_scripts " $@
1445  fi
1446  typeset nodes listnodes init_node start_num init_exec comp ExeNameIn ExeNameOut
1447  typeset node_num_current node_current comp_proc_mpi_loc comp_proc_omp_loc
1448  typeset num_corempi nombre_restant_node nombre_restant_comp
1449
1450  if [ ! -f ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} ]  ; then
1451    IGCM_debug_Exit "IGCM_sys_titane build_execution_scripts : Job_${config_UserChoices_JobName} doesn't exist in SUBMIT_DIR : ${SUBMIT_DIR} "
1452  fi
1453
1454  if ( ${OK_PARA_MPMD} ) ; then
1455
1456    if [ -f run_file ] ; then
1457      IGCM_sys_Rm -f run_file
1458    fi
1459    touch run_file
1460
1461    if ( ${OK_PARA_OMP} ) ; then
1462
1463      #  Hosts treatment
1464
1465      ${HOST_MPIRUN_COMMAND} hostname | sort | uniq > hosts.tmp
1466
1467      i=0
1468      rm -f hosts
1469      IGCM_debug_Print 1 "sys $( hostname ), Hosts avaible :"
1470      for nodes in `cat hosts.tmp` ; do
1471        host[$i]=$nodes
1472        echo "${host[$i]} slots=1 max_slots=1" >> hosts
1473        IGCM_debug_Print 1 ${host[$i]}
1474        i=$((i+1))
1475      done
1476      rm -f hosts.tmp
1477
1478      listnodes=${host[*]}
1479
1480      EXECUTION="${HOST_MPIRUN_COMMAND} -hostfile hosts"
1481
1482      # Initialisation
1483
1484      init_node=y
1485      node_num_current=0
1486      start_num=0
1487      init_exec=n
1488
1489      # Test : if oasis is there, we put it at the first position
1490
1491      for comp in ${config_ListOfComponents[*]} ; do
1492
1493        if [ "X${comp}" = "XCPL" ]  ; then
1494
1495          eval ExeNameIn=\${config_Executable_${comp}[0]}
1496          eval ExeNameOut=\${config_Executable_${comp}[1]}
1497
1498          echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1499          echo ""  >> script_${ExeNameOut}.ksh
1500          #echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
1501          #echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
1502          #echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
1503          echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err"  >> script_${ExeNameOut}.ksh
1504          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1505
1506          init_node=n
1507
1508          (( nombre_restant_node = NUM_COREPERNODE - 1 ))
1509          node_num_current=0
1510          node_current=${host[${node_num_current}]}
1511
1512          EXECUTION="${EXECUTION} -H ${node_current} -np 1 ./script_${ExeNameOut}.ksh"
1513
1514          init_exec=y
1515          start_num=1
1516
1517        fi
1518
1519      done
1520
1521      # Then loop on the components (except for oasis)
1522
1523      for comp in ${config_ListOfComponents[*]} ; do
1524
1525        eval ExeNameIn=\${config_Executable_${comp}[0]}
1526        eval ExeNameOut=\${config_Executable_${comp}[1]}
1527
1528        # Only if we really have an executable for the component :
1529        if ( [ "X${ExeNameOut}" != X\"\" ] &&  [ "X${comp}" != "XCPL" ] ) ; then
1530
1531          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1532          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1533
1534          echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1535          # echo "set -vx" >> script_${ExeNameOut}.ksh
1536          echo ""  >> script_${ExeNameOut}.ksh
1537          #echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
1538          #echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
1539          #echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
1540          echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
1541          echo "(( MYMPIRANK = OMPI_COMM_WORLD_RANK - ${start_num})) " >>  script_${ExeNameOut}.ksh
1542          echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${MYMPIRANK} 2>out_${ExeNameOut}.err.\${MYMPIRANK}"  >> script_${ExeNameOut}.ksh
1543          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1544
1545          node_num=0
1546
1547          # We define the number of MPI process to be assigned for the component
1548
1549          nombre_restant_comp=${comp_proc_mpi_loc}
1550
1551          # Loop on the allocated nodes
1552
1553          for node in ${listnodes} ; do
1554
1555            # We go to the current node
1556            if [ ${node_num} = ${node_num_current} ] ; then
1557
1558              node_current=${host[${node_num_current}]}
1559
1560              # If first time on the node : initialisation
1561
1562              if [ ${init_node} = y ] ; then
1563                nombre_restant_node=${NUM_COREPERNODE}
1564              fi
1565
1566              # Test on the number of OMP threads
1567
1568              if [ ${comp_proc_omp_loc} -gt ${nombre_restant_node} ] ; then
1569                (( node_num = node_num + 1 ))
1570                node_num_current=${node_num}
1571                init_node=y
1572                continue
1573              fi
1574
1575              # Number of MPI process to assign
1576
1577              (( num_corempi = nombre_restant_node / comp_proc_omp_loc ))
1578
1579              if [ ${num_corempi} -gt ${nombre_restant_comp} ] ; then
1580                num_corempi=${nombre_restant_comp}
1581              fi
1582
1583              (( nombre_restant_node = nombre_restant_node - num_corempi * comp_proc_omp_loc ))
1584              (( nombre_restant_comp = nombre_restant_comp - num_corempi ))
1585
1586              if [ ${init_exec} = y ] ; then
1587                EXECUTION="${EXECUTION} : -H ${node_current} -np ${num_corempi} ./script_${ExeNameOut}.ksh"
1588              else
1589                EXECUTION="${EXECUTION} -H ${node_current} -np ${num_corempi} ./script_${ExeNameOut}.ksh"
1590                init_exec=y
1591              fi
1592
1593              ((  start_num = num_corempi + start_num ))
1594
1595            else
1596
1597              (( node_num = node_num + 1 ))
1598              continue
1599            fi
1600
1601            # Test on the number of core/process remaining on the node/component
1602
1603            if [ ${nombre_restant_node} = 0 ] ; then
1604              (( node_num = node_num + 1 ))
1605              node_num_current=${node_num}
1606              init_node=y
1607
1608              if [ ${nombre_restant_comp} = 0 ] ; then
1609                break 1
1610              fi
1611            else
1612
1613              node_num_current=${node_num}
1614              init_node=n
1615
1616              if [ ${nombre_restant_comp} = 0 ] ; then
1617                break 1
1618              fi
1619            fi
1620          done
1621        fi
1622      done
1623
1624    else
1625
1626      # Then first loop on the components for the coupler ie oasis
1627
1628      ## the coupler ie oasis must be the first one
1629      for comp in ${config_ListOfComponents[*]} ; do
1630
1631        eval ExeNameOut=\${config_Executable_${comp}[1]}
1632
1633        # for CPL component only
1634        if [ "X${comp}" = "XCPL" ] ; then
1635          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1636          echo "-np ${comp_proc_mpi_loc} ./${ExeNameOut} " >> run_file
1637        fi
1638      done
1639
1640      # Then second loop on the components
1641
1642      for comp in ${config_ListOfComponents[*]} ; do
1643
1644        eval ExeNameOut=\${config_Executable_${comp}[1]}
1645
1646        # Only if we really have an executable for the component and not the coupler ie oasis:
1647        if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${comp}" != "XCPL" ] ) ; then
1648          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1649          echo "-np ${comp_proc_mpi_loc} ./${ExeNameOut}" >> run_file
1650        fi
1651      done
1652      IGCM_sys_Chmod u+x run_file
1653
1654      EXECUTION="${HOST_MPIRUN_COMMAND} --app ./run_file"
1655
1656    fi
1657
1658  else # Only one executable. launch it.
1659
1660    for comp in ${config_ListOfComponents[*]} ; do
1661
1662      # Only if we really have an executable for the component :
1663      eval ExeNameOut=\${config_Executable_${comp}[1]}
1664      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${ExeNameOut}" != "Xinca.dat" ] ) ; then
1665
1666        echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1667        echo ""  >> script_${ExeNameOut}.ksh
1668        if ( ${OK_PARA_OMP} ) ; then
1669          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1670          echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
1671        fi
1672        if  ( ${OK_PARA_MPI} ) ; then
1673          # Default : mpirun used if nb_proc gt 1
1674          # pour sortie out/err par process
1675          # echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${OMPI_COMM_WORLD_RANK} 2>out_${ExeNameOut}.err.\${OMPI_COMM_WORLD_RANK}"  >> script_${ExeNameOut}.ksh
1676          echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1677          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1678          EXECUTION="${HOST_MPIRUN_COMMAND} ./script_${ExeNameOut}.ksh"
1679        else
1680          # Default : mpirun is NOT used if nb_proc eq 1
1681          # pour sortie out/err par process
1682          # echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err" >> script_${ExeNameOut}.ksh
1683          echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1684          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1685          EXECUTION="time ./script_${ExeNameOut}.ksh"
1686        fi
1687      fi
1688    done
1689
1690  fi
1691
1692  IGCM_debug_Print 1 "sys $( hostname ) : La commande d execution est "
1693  IGCM_debug_Print 1 $EXECUTION
1694
1695  IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
1696}
1697
1698############################################################
1699# Check of space available on temporary filesytems
1700function IGCM_sys_check_quota {
1701  IGCM_debug_PushStack "IGCM_sys_check_quota"
1702  if ( $DEBUG_sys ) ; then
1703    echo "IGCM_sys_check_quota"
1704  fi
1705  IGCM_debug_PopStack "IGCM_sys_check_quota"
1706}
1707
1708##############################################################
1709# NCO OPERATOR
1710
1711function IGCM_sys_ncap2 {
1712  IGCM_debug_PushStack "IGCM_sys_ncap2" -- $@
1713  if ( $DEBUG_sys ) ; then
1714    echo "IGCM_sys_ncap2 :" $@
1715  fi
1716
1717  typeset NB_ESSAI DELAI status i
1718  # number of tentative
1719  NB_ESSAI=3
1720  # time delay between tentative
1721  DELAI=2
1722
1723  i=0
1724  while [ $i -lt $NB_ESSAI ] ; do
1725    ncap2 "$@" > out_rsync 2>&1
1726    status=$?
1727    if [ ${status} -gt 0 ] ; then
1728      IGCM_debug_Print 2 "IGCM_sys_ncap2 : error code ${status}"
1729      cat out_rsync
1730      \rm out_rsync
1731      IGCM_debug_Print 2 "IGCM_sys_ncap2 : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1732    else
1733      \rm out_rsync
1734      break
1735    fi
1736    (( i = i + 1 ))
1737  done
1738
1739  if [ ${status} -gt 0 ] ; then
1740      echo "IGCM_sys_ncap2 : ncap2 error"
1741      IGCM_debug_Exit "ncap2"
1742  fi
1743
1744  IGCM_debug_PopStack "IGCM_sys_ncap2"
1745}
1746
1747function IGCM_sys_ncatted {
1748  IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
1749  if ( $DEBUG_sys ) ; then
1750    echo "IGCM_sys_ncatted :" $@
1751  fi
1752
1753  typeset NB_ESSAI DELAI status i
1754  # number of tentative
1755  NB_ESSAI=3
1756  # time delay between tentative
1757  DELAI=2
1758
1759  i=0
1760  while [ $i -lt $NB_ESSAI ] ; do
1761    ncatted "$@" > out_rsync 2>&1
1762    status=$?
1763    if [ ${status} -gt 0 ] ; then
1764      IGCM_debug_Print 2 "IGCM_sys_ncatted : error code ${status}"
1765      cat out_rsync
1766      \rm out_rsync
1767      IGCM_debug_Print 2 "IGCM_sys_ncatted : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1768    else
1769      \rm out_rsync
1770      break
1771    fi
1772    (( i = i + 1 ))
1773  done
1774
1775  if [ ${status} -gt 0 ] ; then
1776      echo "IGCM_sys_ncatted : ncatted error"
1777      IGCM_debug_Exit "ncatted"
1778  fi
1779
1780  IGCM_debug_PopStack "IGCM_sys_ncatted"
1781}
1782
1783function IGCM_sys_ncbo {
1784  IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
1785  if ( $DEBUG_sys ) ; then
1786    echo "IGCM_sys_ncbo :" $@
1787  fi
1788
1789  typeset NB_ESSAI DELAI status i
1790  # number of tentative
1791  NB_ESSAI=3
1792  # time delay between tentative
1793  DELAI=2
1794
1795  i=0
1796  while [ $i -lt $NB_ESSAI ] ; do
1797    ncbo $@ > out_rsync 2>&1
1798    status=$?
1799    if [ ${status} -gt 0 ] ; then
1800      IGCM_debug_Print 2 "IGCM_sys_ncbo : error code ${status}"
1801      cat out_rsync
1802      \rm out_rsync
1803      IGCM_debug_Print 2 "IGCM_sys_ncbo : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1804    else
1805      \rm out_rsync
1806      break
1807    fi
1808    (( i = i + 1 ))
1809  done
1810
1811  if [ ${status} -gt 0 ] ; then
1812      echo "IGCM_sys_ncbo : ncbo error"
1813      IGCM_debug_Exit "ncbo"
1814  fi
1815
1816  IGCM_debug_PopStack "IGCM_sys_ncbo"
1817}
1818
1819function IGCM_sys_ncdiff {
1820  IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
1821  if ( $DEBUG_sys ) ; then
1822    echo "IGCM_sys_ncdiff :" $@
1823  fi
1824
1825  typeset NB_ESSAI DELAI status i
1826  # number of tentative
1827  NB_ESSAI=3
1828  # time delay between tentative
1829  DELAI=2
1830
1831  i=0
1832  while [ $i -lt $NB_ESSAI ] ; do
1833    ncdiff $@ > out_rsync 2>&1
1834    status=$?
1835    if [ ${status} -gt 0 ] ; then
1836      IGCM_debug_Print 2 "IGCM_sys_ncdiff : error code ${status}"
1837      cat out_rsync
1838      \rm out_rsync
1839      IGCM_debug_Print 2 "IGCM_sys_ncdiff : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1840    else
1841      \rm out_rsync
1842      break
1843    fi
1844    (( i = i + 1 ))
1845  done
1846
1847  if [ ${status} -gt 0 ] ; then
1848      echo "IGCM_sys_ncdiff : ncdiff error"
1849      IGCM_debug_Exit "ncdiff"
1850  fi
1851
1852  IGCM_debug_PopStack "IGCM_sys_ncdiff"
1853}
1854
1855function IGCM_sys_ncea {
1856  IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
1857  if ( $DEBUG_sys ) ; then
1858    echo "IGCM_sys_ncea :" $@
1859  fi
1860
1861  typeset NB_ESSAI DELAI status i
1862  # number of tentative
1863  NB_ESSAI=3
1864  # time delay between tentative
1865  DELAI=2
1866
1867  i=0
1868  while [ $i -lt $NB_ESSAI ] ; do
1869    ncea $@ > out_rsync 2>&1
1870    status=$?
1871    if [ ${status} -gt 0 ] ; then
1872      IGCM_debug_Print 2 "IGCM_sys_ncea : error code ${status}"
1873      cat out_rsync
1874      \rm out_rsync
1875      IGCM_debug_Print 2 "IGCM_sys_ncea : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1876    else
1877      \rm out_rsync
1878      break
1879    fi
1880    (( i = i + 1 ))
1881  done
1882
1883  if [ ${status} -gt 0 ] ; then
1884      echo "IGCM_sys_ncea : ncea error"
1885      IGCM_debug_Exit "ncea"
1886  fi
1887
1888  IGCM_debug_PopStack "IGCM_sys_ncea"
1889}
1890
1891function IGCM_sys_ncecat {
1892  IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
1893  if ( $DEBUG_sys ) ; then
1894    echo "IGCM_sys_ncecat :" $@
1895  fi
1896
1897  typeset NB_ESSAI DELAI status i
1898  # number of tentative
1899  NB_ESSAI=3
1900  # time delay between tentative
1901  DELAI=2
1902
1903  i=0
1904  while [ $i -lt $NB_ESSAI ] ; do
1905    ncecat $@ > out_rsync 2>&1
1906    status=$?
1907    if [ ${status} -gt 0 ] ; then
1908      IGCM_debug_Print 2 "IGCM_sys_ncecat : error code ${status}"
1909      cat out_rsync
1910      \rm out_rsync
1911      IGCM_debug_Print 2 "IGCM_sys_ncecat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1912    else
1913      \rm out_rsync
1914      break
1915    fi
1916    (( i = i + 1 ))
1917  done
1918
1919  if [ ${status} -gt 0 ] ; then
1920      echo "IGCM_sys_ncecat : ncecat error"
1921      IGCM_debug_Exit "ncecat"
1922  fi
1923
1924  IGCM_debug_PopStack "IGCM_sys_ncecat"
1925}
1926
1927function IGCM_sys_ncflint {
1928  IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
1929  if ( $DEBUG_sys ) ; then
1930    echo "IGCM_sys_ncflint :" $@
1931  fi
1932
1933  typeset NB_ESSAI DELAI status i
1934  # number of tentative
1935  NB_ESSAI=3
1936  # time delay between tentative
1937  DELAI=2
1938
1939  i=0
1940  while [ $i -lt $NB_ESSAI ] ; do
1941    ncflint $@ > out_rsync 2>&1
1942    status=$?
1943    if [ ${status} -gt 0 ] ; then
1944      IGCM_debug_Print 2 "IGCM_sys_ncflint : error code ${status}"
1945      cat out_rsync
1946      \rm out_rsync
1947      IGCM_debug_Print 2 "IGCM_sys_ncflint : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1948    else
1949      \rm out_rsync
1950      break
1951    fi
1952    (( i = i + 1 ))
1953  done
1954
1955  if [ ${status} -gt 0 ] ; then
1956      echo "IGCM_sys_ncflint : ncflint error"
1957      IGCM_debug_Exit "ncflint"
1958  fi
1959
1960  IGCM_debug_PopStack "IGCM_sys_ncflint"
1961}
1962
1963function IGCM_sys_ncks {
1964  IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
1965  if ( $DEBUG_sys ) ; then
1966    echo "IGCM_sys_ncks :" $@
1967  fi
1968
1969  typeset NB_ESSAI DELAI status i
1970  # number of tentative
1971  NB_ESSAI=3
1972  # time delay between tentative
1973  DELAI=2
1974
1975  i=0
1976  while [ $i -lt $NB_ESSAI ] ; do
1977    ncks $@ > out_rsync 2>&1
1978    status=$?
1979    if [ ${status} -gt 0 ] ; then
1980      IGCM_debug_Print 2 "IGCM_sys_ncks : error code ${status}"
1981      cat out_rsync
1982      \rm out_rsync
1983      IGCM_debug_Print 2 "IGCM_sys_ncks : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1984    else
1985      \rm out_rsync
1986      break
1987    fi
1988    (( i = i + 1 ))
1989  done
1990
1991  if [ ${status} -gt 0 ] ; then
1992      echo "IGCM_sys_ncks : ncks error"
1993      IGCM_debug_Exit "ncks"
1994  fi
1995
1996  IGCM_debug_PopStack "IGCM_sys_ncks"
1997}
1998
1999function IGCM_sys_ncpdq {
2000  IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
2001  if ( $DEBUG_sys ) ; then
2002    echo "IGCM_sys_ncpdq :" $@
2003  fi
2004
2005  typeset NB_ESSAI DELAI status i
2006  # number of tentative
2007  NB_ESSAI=3
2008  # time delay between tentative
2009  DELAI=2
2010
2011  i=0
2012  while [ $i -lt $NB_ESSAI ] ; do
2013    ncpdq $@ > out_rsync 2>&1
2014    status=$?
2015    if [ ${status} -gt 0 ] ; then
2016      IGCM_debug_Print 2 "IGCM_sys_ncpdq : error code ${status}"
2017      cat out_rsync
2018      \rm out_rsync
2019      IGCM_debug_Print 2 "IGCM_sys_ncpdq : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2020    else
2021      \rm out_rsync
2022      break
2023    fi
2024    (( i = i + 1 ))
2025  done
2026
2027  if [ ${status} -gt 0 ] ; then
2028      echo "IGCM_sys_ncpdq : ncpdq error"
2029      IGCM_debug_Exit "ncpdq"
2030  fi
2031
2032  IGCM_debug_PopStack "IGCM_sys_ncpdq"
2033}
2034
2035function IGCM_sys_ncra {
2036  IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
2037  if ( $DEBUG_sys ) ; then
2038    echo "IGCM_sys_ncra :" $@
2039  fi
2040
2041  typeset NB_ESSAI DELAI status i
2042  # number of tentative
2043  NB_ESSAI=3
2044  # time delay between tentative
2045  DELAI=2
2046
2047  i=0
2048  while [ $i -lt $NB_ESSAI ] ; do
2049    ncra $@ > out_rsync 2>&1
2050    status=$?
2051    if [ ${status} -gt 0 ] ; then
2052      IGCM_debug_Print 2 "IGCM_sys_ncra : error code ${status}"
2053      cat out_rsync
2054      \rm out_rsync
2055      IGCM_debug_Print 2 "IGCM_sys_ncra : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2056    else
2057      \rm out_rsync
2058      break
2059    fi
2060    (( i = i + 1 ))
2061  done
2062
2063  if [ ${status} -gt 0 ] ; then
2064      echo "IGCM_sys_ncra : ncra error"
2065      IGCM_debug_Exit "ncra"
2066  fi
2067
2068  IGCM_debug_PopStack "IGCM_sys_ncra"
2069}
2070
2071function IGCM_sys_ncrcat {
2072  IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
2073  if ( $DEBUG_sys ) ; then
2074    echo "IGCM_sys_ncrcat :" $@
2075  fi
2076
2077  typeset NB_ESSAI DELAI status i
2078  # number of tentative
2079  NB_ESSAI=3
2080  # time delay between tentative
2081  DELAI=2
2082
2083  i=0
2084  while [ $i -lt $NB_ESSAI ] ; do
2085    ncrcat $@ > out_rsync 2>&1
2086    status=$?
2087    if [ ${status} -gt 0 ] ; then
2088      IGCM_debug_Print 2 "IGCM_sys_ncrcat : error code ${status}"
2089      cat out_rsync
2090      \rm out_rsync
2091      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2092    else
2093      \rm out_rsync
2094      break
2095    fi
2096    (( i = i + 1 ))
2097  done
2098
2099  if [ ${status} -gt 0 ] ; then
2100      echo "IGCM_sys_ncrcat : ncrcat error"
2101      #IGCM_debug_Exit "ncrcat"
2102  fi
2103
2104  IGCM_debug_PopStack "IGCM_sys_ncrcat"
2105}
2106
2107function IGCM_sys_ncrename {
2108  IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
2109  if ( $DEBUG_sys ) ; then
2110    echo "IGCM_sys_ncrename :" $@
2111  fi
2112
2113  typeset NB_ESSAI DELAI status i
2114  # number of tentative
2115  NB_ESSAI=3
2116  # time delay between tentative
2117  DELAI=2
2118
2119  i=0
2120  while [ $i -lt $NB_ESSAI ] ; do
2121    ncrename $@ > out_rsync 2>&1
2122    status=$?
2123    if [ ${status} -gt 0 ] ; then
2124      IGCM_debug_Print 2 "IGCM_sys_ncrename : error code ${status}"
2125      cat out_rsync
2126      \rm out_rsync
2127      IGCM_debug_Print 2 "IGCM_sys_ncrename : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2128    else
2129      \rm out_rsync
2130      break
2131    fi
2132    (( i = i + 1 ))
2133  done
2134
2135  if [ ${status} -gt 0 ] ; then
2136      echo "IGCM_sys_ncrename : ncrename error"
2137      IGCM_debug_Exit "ncrename"
2138  fi
2139
2140  IGCM_debug_PopStack "IGCM_sys_ncrename"
2141}
2142
2143function IGCM_sys_ncwa {
2144  IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
2145  if ( $DEBUG_sys ) ; then
2146    echo "IGCM_sys_ncwa :" $@
2147  fi
2148
2149  typeset NB_ESSAI DELAI status i
2150  # number of tentative
2151  NB_ESSAI=3
2152  # time delay between tentative
2153  DELAI=2
2154
2155  i=0
2156  while [ $i -lt $NB_ESSAI ] ; do
2157    ncwa $@ > out_rsync 2>&1
2158    status=$?
2159    if [ ${status} -gt 0 ] ; then
2160      IGCM_debug_Print 2 "IGCM_sys_ncwa : error code ${status}"
2161      cat out_rsync
2162      \rm out_rsync
2163      IGCM_debug_Print 2 "IGCM_sys_ncwa : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2164    else
2165      \rm out_rsync
2166      break
2167    fi
2168    (( i = i + 1 ))
2169  done
2170
2171  if [ ${status} -gt 0 ] ; then
2172      echo "IGCM_sys_ncwa : ncwa error"
2173      IGCM_debug_Exit "ncwa"
2174  fi
2175
2176  IGCM_debug_PopStack "IGCM_sys_ncwa"
2177}
2178
2179##############################################################
2180# CDO OPERATOR
2181
2182function IGCM_sys_cdo {
2183  IGCM_debug_PushStack "IGCM_sys_cdo" -- $@
2184  if ( $DEBUG_sys ) ; then
2185    echo "IGCM_sys_cdo :" $@
2186  fi
2187
2188  typeset status
2189
2190  \cdo $@ > out_rsync 2>&1
2191  status=$?
2192  if [ ${status} -gt 0 ] ; then
2193    echo "IGCM_sys_cdo : error code ${status}"
2194    cat out_rsync
2195    \rm out_rsync
2196    IGCM_debug_PopStack "IGCM_sys_cdo"
2197    return 1
2198  else
2199    IGCM_debug_PopStack "IGCM_sys_cdo"
2200    return 0
2201  fi
2202
2203  IGCM_debug_PopStack "IGCM_sys_cdo"
2204}
Note: See TracBrowser for help on using the repository browser.