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

Last change on this file since 714 was 714, checked in by sdipsl, 12 years ago

all machine : multiple tries over nco commands.

  • 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: 59.6 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
525  IGCM_debug_PopStack "IGCM_sys_Tar"
526}
527
528#D-#==================================================
529#D-function IGCM_sys_UnTar
530#D-* Purpose: master un-tar command
531#D-* Examples:
532#D-
533function IGCM_sys_UnTar {
534  IGCM_debug_PushStack "IGCM_sys_UnTar" $@
535  if ( $DEBUG_sys ) ; then
536    echo "IGCM_sys_UnTar :" $@
537  fi
538  \tar xvf $1
539  if [ $? -gt 0 ] ; then
540    echo "IGCM_sys_UnTar : erreur."
541    IGCM_debug_Exit "IGCM_sys_UnTar"
542  fi
543  IGCM_debug_PopStack "IGCM_sys_UnTar"
544}
545
546#D-#==================================================
547#D-function IGCM_sys_Qsub
548#D-* Purpose: Qsub new job
549#D-* Examples:
550#D-
551function IGCM_sys_Qsub {
552  IGCM_debug_PushStack "IGCM_sys_Qsub" $@
553  if ( $DEBUG_sys ) ; then
554    echo "IGCM_sys_Qsub :" $@
555  fi
556  echo "ssh -l ${LOGIN} ${HOST} ""cd ${SUBMIT_DIR} ; ${@}"" > ${Script_Output} 2>&1 &"
557  ssh -l ${LOGIN} ${HOST} "cd ${SUBMIT_DIR} ; ${@}" > ${Script_Output} 2>&1 &
558  if [ $? -gt 0 ] ; then
559    echo "IGCM_sys_Qsub : erreur."
560    IGCM_debug_Exit "IGCM_sys_Qsub"
561  fi
562  IGCM_debug_PopStack "IGCM_sys_Qsub"
563}
564
565#D-#==================================================
566#D-function IGCM_sys_QsubPost
567#D-* Purpose: Qsub new job on scalaire
568#D-* Examples:
569#D-
570function IGCM_sys_QsubPost {
571  IGCM_debug_PushStack "IGCM_sys_QsubPost" $@
572  if ( $DEBUG_sys ) ; then
573    echo "IGCM_sys_QsubPost :" $@
574  fi
575    #echo "ssh -x -l ${LOGIN} ${HOST} ${3} > ${2} 2>&1 &"
576    #    ssh -x -l ${LOGIN} ${HOST}
577  echo "${libIGCM_POST}/$1.job > ${POST_DIR}/$1.${PeriodDateEnd}.out 2>&1 &"
578  ${libIGCM_POST}/$1.job > ${POST_DIR}/${Script_Post_Output}.out 2>&1 &
579    #    ${3} > ${2} 2>&1 &
580  if [ $? -gt 0 ] ; then
581    echo "IGCM_sys_QsubPost : erreur " $@
582    IGCM_debug_Exit "IGCM_sys_QsubPost"
583  fi
584  IGCM_debug_PopStack "IGCM_sys_QsubPost"
585}
586
587#D-*************************
588#D- File transfer functions
589#D-*************************
590#D-
591
592#D-#==================================================
593#D-function IGCM_sys_Rsync_out
594#D-* Purpose: treat return val of rsync
595#D-* Examples:  IGCM_sys_Rsync_out out_RET_rsync
596#D-  Error values and explanations can depend on your system version.
597function IGCM_sys_Rsync_out {
598  RET=$1
599  if [ ! $RET ] ; then
600    echo "rsync error !"
601  fi
602
603  if [ $MYLANG = "fr" ]; then
604    case $RET in
605    0)  return ;;
606    1)  echo "Erreur de rsync ; RERR_SYNTAX : "
607      echo "Erreur de syntaxe ou d'utilisation."
608      return;;
609    2)  echo "Erreur de rsync ; RERR_PROTOCOL : "
610      echo "Incompatibilité de protocole."
611      return;;
612    3)  echo "Erreur de rsync ; RERR_FILESELECT 3"
613      echo "Erreurs  lors  de  la  sélection des fichiers d'entrée sortie et"
614      echo "répertoires"
615      return;;
616    4)  echo "Erreur de rsync ; RERR_UNSUPPORTED"
617      echo "Action demandée non supportée : une tentative de manipulation de"
618      echo "fichiers  64-bits  sur une plate-forme qui ne les supporte pas a"
619      echo "été faite ; ou une option qui est supportée par le  client  mais"
620      echo "pas par le serveur a été spécifiée."
621      return;;
622    10) echo "Erreur de rsync ; RERR_SOCKETIO"
623      echo "Erreur dans le socket d'entrée sortie"
624      return;;
625    11) echo "Erreur de rsync ; RERR_FILEIO"
626      echo "Erreur d'entrée sortie fichier"
627      return;;
628    12) echo "Erreur de rsync ; RERR_STREAMIO"
629      echo "Erreur dans flux de donnée du protocole rsync"
630      return;;
631    13) echo "Erreur de rsync ; RERR_MESSAGEIO"
632      echo "Erreur avec les diagnostics du programme"
633      return;;
634    14) echo "Erreur de rsync ; RERR_IPC"
635      echo "Erreur dans le code IPC"
636      return;;
637    20) echo "Erreur de rsync ; RERR_SIGNAL"
638      echo "SIGUSR1 ou SIGINT reçu"
639      return;;
640    21) echo "Erreur de rsync ; RERR_WAITCHILD"
641      echo "Une erreur retournée par waitpid()"
642      return;;
643    22) echo "Erreur de rsync ; RERR_MALLOC"
644      echo "Erreur lors de l'allocation des tampons de mémoire de coeur"
645      return;;
646    23) echo ""
647      echo "Erreur fichier inexistant"
648      return;;
649    30) echo "Erreur de rsync ; RERR_TIMEOUT"
650      echo "Temps d'attente écoulé dans l'envoi/réception de données"
651      return;;
652    *)  echo "Erreur de rsync : code de retour de rsync inconnu :" $RET
653      return;;
654    esac
655  elif [ $MYLANG = "en" ] ; then
656    case $RET in
657    0)  return;;
658    1)  echo "rsync error : Syntax or usage error "
659      return;;
660    2)  echo "rsync error : Protocol incompatibility "
661      return;;
662    3)  echo "rsync error : Errors selecting input/output files, dirs"
663      return;;
664    4)  echo "rsync error : Requested action not supported: an attempt"
665      echo "was made to manipulate 64-bit files on a platform that cannot support"
666      echo "them; or an option was specified that is supported by the client and"
667      echo "not by the server."
668      return;;
669    5)  echo "rsync error : Error starting client-server protocol"
670      return;;
671    10) echo "rsync error : Error in socket I/O "
672      return;;
673    11) echo "rsync error : Error in file I/O "
674      return;;
675    12) echo "rsync error : Error in rsync protocol data stream "
676      return;;
677    13) echo "rsync error : Errors with program diagnostics "
678      return;;
679    14) echo "rsync error : Error in IPC code "
680      return;;
681    20) echo "rsync error : Received SIGUSR1 or SIGINT "
682      return;;
683    21) echo "rsync error : Some error returned by waitpid() "
684      return;;
685    22) echo "rsync error : Error allocating core memory buffers "
686      return;;
687    23) echo "rsync error : Partial transfer due to error"
688      return;;
689    24) echo "rsync error : Partial transfer due to vanished source files"
690      return;;
691    30) echo "rsync error : Timeout in data send/receive "
692      return;;
693    *)  echo "rsync error : return code of rsync unknown :" $RET
694      return;;
695    esac
696  else
697    echo "unknown language $MYLANG."
698    return
699  fi
700}
701
702#D-#==================================================
703#D-function IGCM_sys_Cp
704#D-* Purpose: generic cp
705#D-* Examples:
706#D-
707function IGCM_sys_Cp {
708  IGCM_debug_PushStack "IGCM_sys_Cp" $@
709  if ( $DEBUG_sys ) ; then
710    echo "IGCM_sys_Cp :" $@
711  fi
712
713  typeset RET
714
715  echo cp --preserve=timestamps $@ > out_rsync 2>&1
716  \cp --preserve=timestamps $@ >> out_rsync 2>&1
717  RET=$?
718
719  if [ ${RET} -gt 0 ] ; then
720    echo ""
721#       echo "IGCM_sys_Cp : error."
722#       cat out_rsync
723#       IGCM_debug_Exit "IGCM_sys_Cp"
724  else
725    \rm out_rsync
726  fi
727  IGCM_debug_PopStack "IGCM_sys_Cp"
728}
729
730#D-#==================================================
731#D-function IGCM_sys_Rm
732#D-* Purpose: generic rm
733#D-* Examples:
734#D-
735function IGCM_sys_Rm {
736  IGCM_debug_PushStack "IGCM_sys_Rm" -- $@
737  if ( $DEBUG_sys ) ; then
738    echo "IGCM_sys_Rm :" $@
739  fi
740
741  typeset RET
742
743  echo rm $@ > out_rsync 2>&1
744  \rm $@ >> out_rsync 2>&1
745  RET=$?
746
747  if [ ${RET} -gt 0 ] ; then
748    echo "IGCM_sys_Rm : error."
749    cat out_rsync
750    IGCM_debug_Exit "IGCM_sys_Rm"
751  else
752    \rm out_rsync
753  fi
754  IGCM_debug_PopStack "IGCM_sys_Rm"
755}
756
757#D-#==================================================
758#D-function IGCM_sys_RmRunDir
759#D-* Purpose: rm tmpdir (dummy function most of the time batch
760#D-                      scheduler will do the job)
761#D-* Examples:
762#D-
763function IGCM_sys_RmRunDir {
764  IGCM_debug_PushStack "IGCM_sys_RmRunDir" -- $@
765  if ( $DEBUG_sys ) ; then
766    echo "IGCM_sys_RmRunDir :" $@
767    echo "Dummy call, let the scheduler do that."
768#       IGCM_sys_Rm -rf ${RUN_DIR}
769  fi
770  IGCM_debug_PopStack "IGCM_sys_RmRunDir"
771}
772
773#D-#==================================================
774#D-function IGCM_sys_Mv
775#D-* Purpose: generic move
776#D-* Examples:
777#D-
778function IGCM_sys_Mv {
779  IGCM_debug_PushStack "IGCM_sys_Mv" $@
780  if ( $DEBUG_sys ) ; then
781    echo "IGCM_sys_Mv :" $@
782  fi
783
784  if [ $DRYRUN = 0 ]; then
785
786    typeset RET
787
788    echo mv $@ > out_rsync 2>&1
789    \mv $@ >> out_rsync 2>&1
790    RET=$?
791
792    if [ ${RET} -gt 0 ] ; then
793      echo "IGCM_sys_Mv : error in mv."
794      cat out_rsync
795      IGCM_debug_Exit "IGCM_sys_Mv"
796    else
797      \rm out_rsync
798    fi
799  else
800    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
801  fi
802
803  IGCM_debug_PopStack "IGCM_sys_Mv"
804}
805
806#D-#==================================================
807#D-function IGCM_sys_Put_Dir
808#D-* Purpose: Copy a complete directory on $(ARCHIVE)
809#D-* Examples:
810#D-
811function IGCM_sys_Put_Dir {
812  IGCM_debug_PushStack "IGCM_sys_Put_Dir" $@
813  if ( $DEBUG_sys ) ; then
814    echo "IGCM_sys_Put_Dir :" $@
815  fi
816  if [ $DRYRUN = 0 ]; then
817    if [ ! -d ${1} ] ; then
818      echo "WARNING : IGCM_sys_Put_Dir ${1} DOES NOT EXIST ."
819      IGCM_debug_PopStack "IGCM_sys_Put_Dir"
820      return
821    fi
822
823    typeset RET
824
825        # Only if we use rsync
826        #IGCM_sys_TestDirArchive $( dirname $2 )
827        #
828        #USUAL WAY
829    \cp -R $1 $2 > out_rsync 2>&1
830    RET=$?
831
832    if [ ${RET} -gt 0 ] ; then
833      echo "IGCM_sys_Put_Dir : error."
834      cat out_rsync
835      IGCM_debug_Exit "IGCM_sys_Put_Dir"
836    else
837      \rm out_rsync
838    fi
839  else
840    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
841  fi
842  IGCM_debug_PopStack "IGCM_sys_Put_Dir"
843}
844
845#D-#==================================================
846#D-function IGCM_sys_Get_Dir
847#D-* Purpose: Copy a complete directory from $(ARCHIVE)
848#D-* Examples:
849#D-
850function IGCM_sys_Get_Dir {
851  IGCM_debug_PushStack "IGCM_sys_Get_Dir" $@
852  if ( $DEBUG_sys ) ; then
853    echo "IGCM_sys_Get_Dir :" $@
854  fi
855  if [ $DRYRUN = 0 ]; then
856    if [ ! -d ${1} ] ; then
857      echo "WARNING : IGCM_sys_Get_Dir ${1} DOES NOT EXIST ."
858      IGCM_debug_PopStack "IGCM_sys_Get_Dir"
859      return
860    fi
861
862    typeset RET
863
864        #USUAL WAY
865    \cp -R $1 $2 > out_rsync 2>&1
866    RET=$?
867
868    if [ ${RET} -gt 0 ] ; then
869      echo "IGCM_sys_Get_Dir : error."
870      cat out_rsync
871      IGCM_debug_Exit "IGCM_sys_Get_Dir"
872    else
873      \rm out_rsync
874    fi
875  else
876    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
877  fi
878  IGCM_debug_PopStack "IGCM_sys_Get_Dir"
879}
880
881#D-#==================================================
882#D-function IGCM_sys_Get_Master
883#D-* Purpose: Copy a complete directory from MASTER filesystem
884#D-* Examples:
885#D-
886function IGCM_sys_Get_Master {
887  IGCM_debug_PushStack "IGCM_sys_Get_Master" $@
888  if ( $DEBUG_sys ) ; then
889    echo "IGCM_sys_Get_Master :" $@
890  fi
891  if [ $DRYRUN = 0 ]; then
892    if ( [ ! -d ${1} ] && [ ! -f ${1} ] ) ; then
893      echo "WARNING : IGCM_sys_Get_Master ${1} DOES NOT EXIST ."
894      IGCM_debug_PopStack "IGCM_sys_Get_Master"
895      return
896    fi
897
898    typeset RET
899
900        #USUAL WAY
901    cp -RL $1 $2 > out_rsync 2>&1
902    RET=$?
903
904    if [ ${RET} -gt 0 ] ; then
905      echo "IGCM_sys_Get_Master : error."
906      cat out_rsync
907      IGCM_debug_Exit "IGCM_sys_Get_Master"
908    else
909      \rm out_rsync
910    fi
911  else
912    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
913  fi
914  IGCM_debug_PopStack "IGCM_sys_Get_Master"
915}
916
917#D-#==================================================
918#D-function IGCM_sys_Put_Rest
919#D-* Purpose: Put computied restarts on $(ARCHIVE).
920#D-           File and target directory must exist.
921#D-* Examples:
922#D-
923function IGCM_sys_Put_Rest {
924  IGCM_debug_PushStack "IGCM_sys_Put_Rest" $@
925  if ( $DEBUG_sys ) ; then
926    echo "IGCM_sys_Put_Rest :" $@
927  fi
928  if [ $DRYRUN = 0 ]; then
929
930    IGCM_sys_TestDirArchive $( dirname $2 )
931
932    if [ ! -f ${1} ] ; then
933      echo "ERROR : IGCM_sys_Put_Rest ${1} DOES NOT EXIST ."
934      IGCM_debug_Exit "IGCM_sys_Put_Rest"
935    fi
936    if [ X${JobType} = XRUN ] ; then
937      IGCM_sys_Chmod 444 ${1}
938    fi
939
940    typeset RET
941
942    echo ${RSYNC} ${RSYNC_opt} $1 $2 > out_rsync 2>&1
943    ${RSYNC} ${RSYNC_opt} $1 $2 >> out_rsync 2>&1
944    RET=$?
945    IGCM_sys_Rsync_out $RET
946
947    ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
948    (( RET=RET+$? ))
949
950    if [ ${RET} -gt 0 ] ; then
951      echo "IGCM_sys_Put_Rest : error."
952      cat out_rsync
953      IGCM_debug_Exit "IGCM_sys_Put_Rest"
954    else
955      \rm out_rsync
956    fi
957  else
958    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
959  fi
960  IGCM_debug_PopStack "IGCM_sys_Put_Rest"
961}
962
963#D-#==================================================
964#D-function IGCM_sys_PutBuffer_Rest
965#D-* Purpose: Put computied restarts on ${SCRATCHDIR}.
966#D-           File and target directory must exist.
967#D-* Examples:
968#D-
969function IGCM_sys_PutBuffer_Rest {
970  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Rest" $@
971  if ( $DEBUG_sys ) ; then
972    echo "IGCM_sys_PutBuffer_Rest :" $@
973  fi
974  if [ $DRYRUN = 0 ]; then
975    if [ ! -f ${1} ] ; then
976      echo "ERROR : IGCM_sys_PutBuffer_Rest ${1} DOES NOT EXIST ."
977      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
978    fi
979
980    typeset RET
981    #
982    if [ X${JobType} = XRUN ] ; then
983      IGCM_sys_Chmod 444 ${1}
984    fi
985
986    #
987    # USUAL WAY
988    \cp $1 $2 > out_rsync 2>&1
989    RET=$?
990
991    if [ ${RET} -gt 0 ] ; then
992      echo "IGCM_sys_PutBuffer_Rest : error."
993      cat out_rsync
994      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
995    else
996      \rm out_rsync
997    fi
998  else
999    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1000  fi
1001  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Rest"
1002}
1003
1004#D-#==================================================
1005#D-function IGCM_sys_Put_Out
1006#D-* Purpose: Copy a file on $(ARCHIVE) after have chmod it in readonly
1007#D-* Examples:
1008#D-
1009function IGCM_sys_Put_Out {
1010  IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
1011  if ( $DEBUG_sys ) ; then
1012    echo "IGCM_sys_Put_Out :" $@
1013  fi
1014  if [ $DRYRUN = 0 ]; then
1015    if [ -f ${1} ] ; then
1016      if [ ! -d $( dirname $2 ) ] ; then
1017        IGCM_sys_MkdirArchive $( dirname $2 )
1018      fi
1019    else
1020      echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
1021      IGCM_debug_PopStack "IGCM_sys_Put_Out"
1022      return 1
1023    fi
1024
1025    typeset RET
1026        #
1027    if [ X${JobType} = XRUN ] ; then
1028      if [ X${3} = X ] ; then
1029        IGCM_sys_Chmod 444 ${1}
1030      fi
1031    fi
1032        #
1033
1034    echo ${RSYNC} ${RSYNC_opt} $1 $2 > out_rsync 2>&1
1035    ${RSYNC} ${RSYNC_opt} $1 $2 >> out_rsync 2>&1
1036    RET=$?
1037    IGCM_sys_Rsync_out $RET
1038
1039    ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1040    (( RET=RET+$? ))
1041
1042    if [ ${RET} -gt 0 ] ; then
1043      echo "IGCM_sys_Put_Out : error."
1044      cat out_rsync
1045      IGCM_debug_Exit "IGCM_sys_Put_Out"
1046    else
1047      \rm out_rsync
1048    fi
1049  else
1050    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1051  fi
1052  IGCM_debug_PopStack "IGCM_sys_Put_Out"
1053  return 0
1054}
1055
1056#D-#==================================================
1057#D-function IGCM_sys_PutBuffer_Out
1058#D-* Purpose: Copy a file on ${SCRATCHDIR} after having chmod it in readonly
1059#D-* Examples:
1060#D-
1061function IGCM_sys_PutBuffer_Out {
1062  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Out" $@
1063  if ( $DEBUG_sys ) ; then
1064    echo "IGCM_sys_PutBuffer_Out :" $@
1065  fi
1066  if [ $DRYRUN = 0 ]; then
1067    if [ ! -f ${1} ] ; then
1068      echo "WARNING : IGCM_sys_PutBuffer_Out ${1} DOES NOT EXIST ."
1069      IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1070      return 1
1071    fi
1072    #
1073    IGCM_sys_Mkdir $( dirname $2 )
1074    #
1075    typeset RET
1076
1077    if [ X${JobType} = XRUN ] ; then
1078      if [ X${3} = X ] ; then
1079        IGCM_sys_Chmod 444 ${1}
1080      fi
1081    fi
1082    #
1083    # USUAL WAY
1084    \cp $1 $2 > out_rsync 2>&1
1085    RET=$?
1086
1087    if [ ${RET} -gt 0 ] ; then
1088      echo "IGCM_sys_PutBuffer_Out : error."
1089      cat out_rsync
1090      IGCM_debug_Exit "IGCM_sys_PutBuffer_Out"
1091    else
1092      \rm out_rsync
1093    fi
1094  else
1095    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1096  fi
1097  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1098  return 0
1099}
1100
1101#D-#==================================================
1102#D-function IGCM_sys_Get
1103#D-* Purpose: Get a file from ${ARCHIVE}
1104#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
1105#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
1106function IGCM_sys_Get {
1107  IGCM_debug_PushStack "IGCM_sys_Get" $@
1108
1109  typeset DEST RET dm_liste ifile target
1110
1111  if ( $DEBUG_sys ) ; then
1112    echo "IGCM_sys_Get :" $@
1113  fi
1114  if [ $DRYRUN -le 2 ]; then
1115    if [ X${1} = X'/l' ] ; then
1116            # test if the first file is present in the old computation :
1117      eval set +A dm_liste \${${2}}
1118    else
1119      dm_liste=${1}
1120    fi
1121    eval DEST=\${${#}}
1122
1123        # test if the (first) file is present in the old computation :
1124    IGCM_sys_TestFileArchive ${dm_liste[0]}
1125    RET=$?
1126    if [ ${RET} -gt 0 ] ; then
1127      echo "IGCM_sys_Get, ERROR : regular file ${dm_liste[0]} DOES NOT EXIST ."
1128      IGCM_debug_Exit "IGCM_sys_Get"
1129            #return
1130    fi
1131
1132    (( RET=0 ))
1133    for target in ${dm_liste[*]} ; do
1134      \cp ${target} ${DEST} >> out_rsync 2>&1
1135      (( RET=RET+$? ))
1136    done
1137
1138#       echo ${RSYNC} ${RSYNC_opt} $@ > out_rsync 2>&1
1139#       ${RSYNC} ${RSYNC_opt} $@ >> out_rsync 2>&1
1140#       RET=$?
1141#       IGCM_sys_Rsync_out $RET
1142
1143#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1144#       (( RET=RET+$? ))
1145
1146    if [ ${RET} -gt 0 ] ; then
1147      echo "IGCM_sys_Get : copy error."
1148      cat out_rsync
1149      IGCM_debug_Exit "IGCM_sys_Get"
1150    else
1151      \rm out_rsync
1152    fi
1153  else
1154    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1155  fi
1156  IGCM_debug_PopStack "IGCM_sys_Get"
1157}
1158
1159#D-#==================================================
1160#D-function IGCM_sys_GetBuffer
1161#D-* Purpose: Get a file from ${SCRATCHDIR}
1162#D-* Examples: IGCM_sys_GetBuffer myfile /destpath/myfile_with_PREFIX
1163#D-            IGCM_sys_GetBuffer /l Array_contain_myfiles /destpath/
1164function IGCM_sys_GetBuffer {
1165  IGCM_debug_PushStack "IGCM_sys_GetBuffer" $@
1166
1167  typeset DEST RET buf_liste ifile target file_work
1168
1169  if ( $DEBUG_sys ) ; then
1170    echo "IGCM_sys_GetBuffer :" $@
1171  fi
1172  if [ $DRYRUN -le 2 ]; then
1173    if [ X${1} = X'/l' ] ; then
1174      # test if the first file is present in the old computation :
1175      eval set +A buf_liste \${${2}}
1176    else
1177      eval set +A buf_liste ${1}
1178    fi
1179    eval DEST=\${${#}}
1180
1181    #USUAL WAY
1182    if [ X${1} = X'/l' ] ; then
1183      (( RET=0 ))
1184      for target in ${buf_liste[*]} ; do
1185        local_file=$( basename ${target} )
1186        \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1187        (( RET = RET + $? ))
1188      done
1189    else
1190      \cp ${buf_liste} ${DEST} >> out_rsync 2>&1
1191      RET=$?
1192    fi
1193
1194    if [ ${RET} -gt 0 ] ; then
1195      echo "IGCM_sys_GetBuffer : copy error."
1196      cat out_rsync
1197      IGCM_debug_Exit "IGCM_sys_GetBuffer"
1198    else
1199      \rm out_rsync
1200    fi
1201  else
1202    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1203  fi
1204  IGCM_debug_PopStack "IGCM_sys_GetBuffer"
1205}
1206
1207#D-#==================================================
1208#D-function IGCM_sys_GetDate_FichWork
1209#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
1210#D-* Examples:
1211#D-
1212function IGCM_sys_GetDate_FichWork {
1213  IGCM_debug_PushStack "IGCM_sys_FichWork" $@
1214  if ( $DEBUG_sys ) ; then
1215    echo "IGCM_sys_GetDate_FichWork :" $@
1216  fi
1217  typeset dateF
1218  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1219  eval ${2}=${dateF[5]}
1220
1221    # donne la date filesys d'un fichier sur la machine work
1222  IGCM_debug_PopStack "IGCM_sys_FichWork"
1223}
1224
1225#D-#==================================================
1226#D-function IGCM_sys_GetDate_FichArchive
1227#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
1228#D-* Examples:
1229#D-
1230function IGCM_sys_GetDate_FichArchive {
1231  IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
1232  if ( $DEBUG_sys ) ; then
1233    echo "IGCM_sys_GetDate_FichArchive :" $@
1234  fi
1235  typeset dateF
1236  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1237  eval ${2}=${dateF[5]}
1238
1239  IGCM_debug_PopStack "IGCM_sys_FichArchive"
1240}
1241
1242#D-#==================================================
1243#D-function IGCM_sys_Dods_Rm
1244#D-* Purpose: Suppress files in /tmp/DODS for simulation of internet protocole.
1245#D-* Examples:
1246#D-
1247function IGCM_sys_Dods_Rm {
1248  if ( $DEBUG_sys ) ; then
1249    echo "IGCM_sys_Dods_Rm :" $@
1250  fi
1251  return 0
1252}
1253
1254
1255#D-#==================================================
1256#D-function IGCM_sys_Dods_Cp
1257#D-* Purpose: Copy from $(ARCHIVE) files to /tmp/DODS for simulation of internet protocole.
1258#D-* Examples:
1259#D-
1260function IGCM_sys_Dods_Cp {
1261  if ( $DEBUG_sys ) ; then
1262    echo "IGCM_sys_Dods_Cp :" $@
1263  fi
1264  return 0
1265}
1266
1267#D-#==================================================
1268#D-function IGCM_sys_Put_Dods
1269#D-* Purpose: Put $(ARCHIVE) files on /tmp/DODS for simulation of internet protocole.
1270#D-* Examples:
1271#D-
1272function IGCM_sys_Put_Dods {
1273  IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
1274  if ( $DEBUG_sys ) ; then
1275    echo "IGCM_sys_Put_Dods :" $@
1276  fi
1277  if [ $DRYRUN = 0 ]; then
1278    RET=0
1279
1280    if [ ${RET} -gt 0 ] ; then
1281      echo "IGCM_sys_Put_Dods : error."
1282      IGCM_debug_Exit "IGCM_sys_Put_Dods"
1283    fi
1284  else
1285    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1286  fi
1287  IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1288}
1289
1290##############################################################
1291# REBUILD OPERATOR
1292
1293function IGCM_sys_rebuild {
1294  IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1295  if ( $DEBUG_sys ) ; then
1296    echo "IGCM_sys_rebuild :" $@
1297  fi
1298  rebuild -f -o $@
1299  if [ $? -gt 0 ] ; then
1300    echo "IGCM_sys_rebuild : erreur ${@}."
1301    IGCM_debug_Exit "rebuild"
1302  fi
1303
1304  IGCM_debug_PopStack "IGCM_sys_rebuild"
1305}
1306
1307function IGCM_sys_rebuild_station {
1308  IGCM_debug_PushStack "IGCM_sys_rebuild_station" -- $@
1309  typeset i list_opt file_in file_out prefix_invert list_invert
1310  if ( $DEBUG_sys ) ; then
1311    echo "IGCM_sys_rebuild_station :" $@
1312  fi
1313  list_opt=$@
1314
1315  # Invert Axis : t,x -> x,t
1316  #               t,pres,x -> x,t,pres
1317  # So that we can concatenate along x
1318  i=0
1319  for file_in in ${list_opt} ; do
1320    (( i = i + 1))
1321    [ ${i} = 1 ] && file_out=${file_in} && continue
1322    prefix_invert=$( basename ${file_in} .nc )
1323    IGCM_sys_ncpdq -a x,time_counter -a x,time_counter,presnivs ${file_in} ${prefix_invert}_xt.nc
1324    list_invert[${#list_invert[*]}]=${prefix_invert}_xt.nc
1325  done
1326
1327  # Concatenate
1328  IGCM_sys_ncrcat ${list_invert[*]} histstn_xt.nc
1329
1330  # Re-ivert file
1331  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x histstn_xt.nc ${file_out}
1332
1333  # Station re-ordering is too expansive to be run within libICGM
1334  # This is due to (ncpdq - nrcat - ncpdq) I/O sequence.
1335  # This re-ordering must be done "in memory" by the cmorization process
1336  # Anyway this is the best sequence using (ncpdq - nrcat - ncpdq)
1337  # BEGIN reordering
1338
1339  # Only LMDZ text output contains the exact ordering of the station.
1340  # We isolate this in the code below:
1341  #  0  38  -157.5000000000000  70.98591549295774
1342  #  0  54  27.49999999999999   67.18309859154928
1343  #  0  56  -62.50000000000001  82.39436619718309
1344  #  0  79  12.49999999999999   78.59154929577466
1345  #  0  116 -165.0000000000000  76.05633802816901
1346  #  0  117 130.0000000000000   70.98591549295774
1347  #  0  118 110.0000000000000   87.46478873239437
1348  #  1  40  4.999999999999995   51.97183098591550
1349#  typeset iStation iProc list_opt file_in file_out prefix_invert
1350#  typeset -Z4 j4
1351#  typeset -Z3 j3
1352
1353#  unset list_opt
1354#  set +A list_opt $@
1355
1356  # Filename after rebuild
1357#  file_out=${list_opt[0]}
1358  # Prefix of output files
1359#  prefix_invert=$( basename ${file_out} .nc )
1360  # Number of procs
1361#  num_proc=$( grep -i mpi_size ${PREFIX}_${Exe_Output} | wc -l )
1362
1363#  iProc=0
1364#  while [ ${iProc} -lt ${num_proc} ] ; do
1365    # Array containing Station as a number
1366#    unset proc_stn
1367#    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}' )
1368    # Number of stations produced by processor proc
1369#    stationLast=${#proc_stn[*]}
1370    # Proc number on 4 digits
1371#    j4=${iProc}
1372    # Init
1373#    iStation=0
1374#    while [ ${iStation} -lt ${stationLast} ] ; do
1375      # Station number on 3 digits
1376#      j3=${proc_stn[${iStation}]}
1377      # Extract station
1378      # Invert Axis : t,x -> x,t
1379      #               t,pres,x -> x,t,pres
1380      # So that we can concatenate along x
1381#      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
1382#      (( iStation = iStation + 1 ))
1383#    done
1384#    (( iProc = iProc + 1 ))
1385#  done
1386
1387  # Concatenate all station along x
1388#  IGCM_sys_ncrcat ${prefix_invert}_stn_???.nc ${prefix_invert}_xt.nc
1389
1390  # Re-invert file
1391#  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x ${prefix_invert}_xt.nc ${file_out}
1392
1393  # END reordering
1394
1395  IGCM_debug_PopStack "IGCM_sys_rebuild_station"
1396}
1397
1398############################################################
1399# Activate Running Environnment Variables
1400
1401function IGCM_sys_activ_variables {
1402  IGCM_debug_PushStack "IGCM_sys_activ_variables"
1403  if ( $DEBUG_sys ) ; then
1404    echo "IGCM_sys_activ_variables"
1405  fi
1406  IGCM_debug_PopStack "IGCM_sys_activ_variables"
1407}
1408
1409############################################################
1410# Desactivate Running Environnment Variables
1411
1412function IGCM_sys_desactiv_variables {
1413  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1414  if ( $DEBUG_sys ) ; then
1415    echo "IGCM_sys_desactiv_variables"
1416  fi
1417  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1418}
1419
1420############################################################
1421# Build run file
1422
1423function IGCM_sys_build_run_file {
1424
1425  IGCM_debug_Print 3 " dummy function : IGCM_sys_build_run_file "
1426
1427}
1428
1429############################################################
1430# Build MPI/OMP scripts
1431function IGCM_sys_build_execution_scripts
1432{
1433  IGCM_debug_PushStack "IGCM_sys_build_execution_scripts" $@
1434  if ( $DEBUG_sys ) ; then
1435    echo "IGCM_sys_build_execution_scripts " $@
1436  fi
1437  typeset nodes listnodes init_node start_num init_exec comp ExeNameIn ExeNameOut
1438  typeset node_num_current node_current comp_proc_mpi_loc comp_proc_omp_loc
1439  typeset num_corempi nombre_restant_node nombre_restant_comp
1440
1441  if [ ! -f ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} ]  ; then
1442    IGCM_debug_Exit "IGCM_sys_titane build_execution_scripts : Job_${config_UserChoices_JobName} doesn't exist in SUBMIT_DIR : ${SUBMIT_DIR} "
1443  fi
1444
1445  if ( ${OK_PARA_MPMD} ) ; then
1446
1447    if [ -f run_file ] ; then
1448      IGCM_sys_Rm -f run_file
1449    fi
1450    touch run_file
1451
1452    if ( ${OK_PARA_OMP} ) ; then
1453
1454      #  Hosts treatment
1455
1456      ${HOST_MPIRUN_COMMAND} hostname | sort | uniq > hosts.tmp
1457
1458      i=0
1459      rm -f hosts
1460      IGCM_debug_Print 1 "sys $( hostname ), Hosts avaible :"
1461      for nodes in `cat hosts.tmp` ; do
1462        host[$i]=$nodes
1463        echo "${host[$i]} slots=1 max_slots=1" >> hosts
1464        IGCM_debug_Print 1 ${host[$i]}
1465        i=$((i+1))
1466      done
1467      rm -f hosts.tmp
1468
1469      listnodes=${host[*]}
1470
1471      EXECUTION="${HOST_MPIRUN_COMMAND} -hostfile hosts"
1472
1473      # Initialisation
1474
1475      init_node=y
1476      node_num_current=0
1477      start_num=0
1478      init_exec=n
1479
1480      # Test : if oasis is there, we put it at the first position
1481
1482      for comp in ${config_ListOfComponents[*]} ; do
1483
1484        if [ "X${comp}" = "XCPL" ]  ; then
1485
1486          eval ExeNameIn=\${config_Executable_${comp}[0]}
1487          eval ExeNameOut=\${config_Executable_${comp}[1]}
1488
1489          echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1490          echo ""  >> script_${ExeNameOut}.ksh
1491          #echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
1492          #echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
1493          #echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
1494          echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err"  >> script_${ExeNameOut}.ksh
1495          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1496
1497          init_node=n
1498
1499          (( nombre_restant_node = NUM_COREPERNODE - 1 ))
1500          node_num_current=0
1501          node_current=${host[${node_num_current}]}
1502
1503          EXECUTION="${EXECUTION} -H ${node_current} -np 1 ./script_${ExeNameOut}.ksh"
1504
1505          init_exec=y
1506          start_num=1
1507
1508        fi
1509
1510      done
1511
1512      # Then loop on the components (except for oasis)
1513
1514      for comp in ${config_ListOfComponents[*]} ; do
1515
1516        eval ExeNameIn=\${config_Executable_${comp}[0]}
1517        eval ExeNameOut=\${config_Executable_${comp}[1]}
1518
1519        # Only if we really have an executable for the component :
1520        if ( [ "X${ExeNameOut}" != X\"\" ] &&  [ "X${comp}" != "XCPL" ] ) ; then
1521
1522          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1523          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1524
1525          echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1526          # echo "set -vx" >> script_${ExeNameOut}.ksh
1527          echo ""  >> script_${ExeNameOut}.ksh
1528          #echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
1529          #echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
1530          #echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
1531          echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
1532          echo "(( MYMPIRANK = OMPI_COMM_WORLD_RANK - ${start_num})) " >>  script_${ExeNameOut}.ksh
1533          echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${MYMPIRANK} 2>out_${ExeNameOut}.err.\${MYMPIRANK}"  >> script_${ExeNameOut}.ksh
1534          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1535
1536          node_num=0
1537
1538          # We define the number of MPI process to be assigned for the component
1539
1540          nombre_restant_comp=${comp_proc_mpi_loc}
1541
1542          # Loop on the allocated nodes
1543
1544          for node in ${listnodes} ; do
1545
1546            # We go to the current node
1547            if [ ${node_num} = ${node_num_current} ] ; then
1548
1549              node_current=${host[${node_num_current}]}
1550
1551              # If first time on the node : initialisation
1552
1553              if [ ${init_node} = y ] ; then
1554                nombre_restant_node=${NUM_COREPERNODE}
1555              fi
1556
1557              # Test on the number of OMP threads
1558
1559              if [ ${comp_proc_omp_loc} -gt ${nombre_restant_node} ] ; then
1560                (( node_num = node_num + 1 ))
1561                node_num_current=${node_num}
1562                init_node=y
1563                continue
1564              fi
1565
1566              # Number of MPI process to assign
1567
1568              (( num_corempi = nombre_restant_node / comp_proc_omp_loc ))
1569
1570              if [ ${num_corempi} -gt ${nombre_restant_comp} ] ; then
1571                num_corempi=${nombre_restant_comp}
1572              fi
1573
1574              (( nombre_restant_node = nombre_restant_node - num_corempi * comp_proc_omp_loc ))
1575              (( nombre_restant_comp = nombre_restant_comp - num_corempi ))
1576
1577              if [ ${init_exec} = y ] ; then
1578                EXECUTION="${EXECUTION} : -H ${node_current} -np ${num_corempi} ./script_${ExeNameOut}.ksh"
1579              else
1580                EXECUTION="${EXECUTION} -H ${node_current} -np ${num_corempi} ./script_${ExeNameOut}.ksh"
1581                init_exec=y
1582              fi
1583
1584              ((  start_num = num_corempi + start_num ))
1585
1586            else
1587
1588              (( node_num = node_num + 1 ))
1589              continue
1590            fi
1591
1592            # Test on the number of core/process remaining on the node/component
1593
1594            if [ ${nombre_restant_node} = 0 ] ; then
1595              (( node_num = node_num + 1 ))
1596              node_num_current=${node_num}
1597              init_node=y
1598
1599              if [ ${nombre_restant_comp} = 0 ] ; then
1600                break 1
1601              fi
1602            else
1603
1604              node_num_current=${node_num}
1605              init_node=n
1606
1607              if [ ${nombre_restant_comp} = 0 ] ; then
1608                break 1
1609              fi
1610            fi
1611          done
1612        fi
1613      done
1614
1615    else
1616
1617      # Then first loop on the components for the coupler ie oasis
1618
1619      ## the coupler ie oasis must be the first one
1620      for comp in ${config_ListOfComponents[*]} ; do
1621
1622        eval ExeNameOut=\${config_Executable_${comp}[1]}
1623
1624        # for CPL component only
1625        if [ "X${comp}" = "XCPL" ] ; then
1626          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1627          echo "-np ${comp_proc_mpi_loc} ./${ExeNameOut} " >> run_file
1628        fi
1629      done
1630
1631      # Then second loop on the components
1632
1633      for comp in ${config_ListOfComponents[*]} ; do
1634
1635        eval ExeNameOut=\${config_Executable_${comp}[1]}
1636
1637        # Only if we really have an executable for the component and not the coupler ie oasis:
1638        if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${comp}" != "XCPL" ] ) ; then
1639          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1640          echo "-np ${comp_proc_mpi_loc} ./${ExeNameOut}" >> run_file
1641        fi
1642      done
1643      IGCM_sys_Chmod u+x run_file
1644
1645      EXECUTION="${HOST_MPIRUN_COMMAND} --app ./run_file"
1646
1647    fi
1648
1649  else # Only one executable. launch it.
1650
1651    for comp in ${config_ListOfComponents[*]} ; do
1652
1653      # Only if we really have an executable for the component :
1654      eval ExeNameOut=\${config_Executable_${comp}[1]}
1655      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${ExeNameOut}" != "Xinca.dat" ] ) ; then
1656
1657        echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1658        echo ""  >> script_${ExeNameOut}.ksh
1659        if ( ${OK_PARA_OMP} ) ; then
1660          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1661          echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
1662        fi
1663        if  ( ${OK_PARA_MPI} ) ; then
1664          # Default : mpirun used if nb_proc gt 1
1665          # pour sortie out/err par process
1666          # echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${OMPI_COMM_WORLD_RANK} 2>out_${ExeNameOut}.err.\${OMPI_COMM_WORLD_RANK}"  >> script_${ExeNameOut}.ksh
1667          echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1668          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1669          EXECUTION="${HOST_MPIRUN_COMMAND} ./script_${ExeNameOut}.ksh"
1670        else
1671          # Default : mpirun is NOT used if nb_proc eq 1
1672          # pour sortie out/err par process
1673          # echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err" >> script_${ExeNameOut}.ksh
1674          echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1675          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1676          EXECUTION="time ./script_${ExeNameOut}.ksh"
1677        fi
1678      fi
1679    done
1680
1681  fi
1682
1683  IGCM_debug_Print 1 "sys $( hostname ) : La commande d execution est "
1684  IGCM_debug_Print 1 $EXECUTION
1685
1686  IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
1687}
1688
1689############################################################
1690# Check of space available on temporary filesytems
1691function IGCM_sys_check_quota {
1692  IGCM_debug_PushStack "IGCM_sys_check_quota"
1693  if ( $DEBUG_sys ) ; then
1694    echo "IGCM_sys_check_quota"
1695  fi
1696  IGCM_debug_PopStack "IGCM_sys_check_quota"
1697}
1698
1699##############################################################
1700# NCO OPERATOR
1701
1702
1703function IGCM_sys_ncap2 {
1704  IGCM_debug_PushStack "IGCM_sys_ncap2" -- $@
1705  if ( $DEBUG_sys ) ; then
1706    echo "IGCM_sys_ncap2 :" $@
1707  fi
1708
1709  typeset NB_ESSAI DELAI status i
1710  # number of tentative
1711  NB_ESSAI=3
1712  # time delay between tentative
1713  DELAI=2
1714
1715  i=0
1716  while [ $i -lt $NB_ESSAI ] ; do
1717    ncap2 "$@" > out_rsync 2>&1
1718    status=$?
1719    if [ ${status} -gt 0 ] ; then
1720      IGCM_debug_Print 2 "IGCM_sys_ncap2 : error code ${status}"
1721      cat out_rsync
1722      \rm out_rsync
1723      IGCM_debug_Print 2 "IGCM_sys_ncap2 : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1724    else
1725      \rm out_rsync
1726      break
1727    fi
1728    (( i = i + 1 ))
1729  done
1730
1731  if [ ${status} -gt 0 ] ; then
1732      echo "IGCM_sys_ncap2 : ncap2 error"
1733      IGCM_debug_Exit "ncap2"
1734  fi
1735
1736  IGCM_debug_PopStack "IGCM_sys_ncap2"
1737}
1738
1739function IGCM_sys_ncatted {
1740  IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
1741  if ( $DEBUG_sys ) ; then
1742    echo "IGCM_sys_ncatted :" $@
1743  fi
1744
1745  typeset NB_ESSAI DELAI status i
1746  # number of tentative
1747  NB_ESSAI=3
1748  # time delay between tentative
1749  DELAI=2
1750
1751  i=0
1752  while [ $i -lt $NB_ESSAI ] ; do
1753    ncatted "$@" > out_rsync 2>&1
1754    status=$?
1755    if [ ${status} -gt 0 ] ; then
1756      IGCM_debug_Print 2 "IGCM_sys_ncatted : error code ${status}"
1757      cat out_rsync
1758      \rm out_rsync
1759      IGCM_debug_Print 2 "IGCM_sys_ncatted : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1760    else
1761      \rm out_rsync
1762      break
1763    fi
1764    (( i = i + 1 ))
1765  done
1766
1767  if [ ${status} -gt 0 ] ; then
1768      echo "IGCM_sys_ncatted : ncatted error"
1769      IGCM_debug_Exit "ncatted"
1770  fi
1771
1772  IGCM_debug_PopStack "IGCM_sys_ncatted"
1773}
1774
1775function IGCM_sys_ncbo {
1776  IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
1777  if ( $DEBUG_sys ) ; then
1778    echo "IGCM_sys_ncbo :" $@
1779  fi
1780
1781  typeset NB_ESSAI DELAI status i
1782  # number of tentative
1783  NB_ESSAI=3
1784  # time delay between tentative
1785  DELAI=2
1786
1787  i=0
1788  while [ $i -lt $NB_ESSAI ] ; do
1789    ncbo $@ > out_rsync 2>&1
1790    status=$?
1791    if [ ${status} -gt 0 ] ; then
1792      IGCM_debug_Print 2 "IGCM_sys_ncbo : error code ${status}"
1793      cat out_rsync
1794      \rm out_rsync
1795      IGCM_debug_Print 2 "IGCM_sys_ncbo : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1796    else
1797      \rm out_rsync
1798      break
1799    fi
1800    (( i = i + 1 ))
1801  done
1802
1803  if [ ${status} -gt 0 ] ; then
1804      echo "IGCM_sys_ncbo : ncbo error"
1805      IGCM_debug_Exit "ncbo"
1806  fi
1807
1808  IGCM_debug_PopStack "IGCM_sys_ncbo"
1809}
1810
1811function IGCM_sys_ncdiff {
1812  IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
1813  if ( $DEBUG_sys ) ; then
1814    echo "IGCM_sys_ncdiff :" $@
1815  fi
1816
1817  typeset NB_ESSAI DELAI status i
1818  # number of tentative
1819  NB_ESSAI=3
1820  # time delay between tentative
1821  DELAI=2
1822
1823  i=0
1824  while [ $i -lt $NB_ESSAI ] ; do
1825    ncdiff $@ > out_rsync 2>&1
1826    status=$?
1827    if [ ${status} -gt 0 ] ; then
1828      IGCM_debug_Print 2 "IGCM_sys_ncdiff : error code ${status}"
1829      cat out_rsync
1830      \rm out_rsync
1831      IGCM_debug_Print 2 "IGCM_sys_ncdiff : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1832    else
1833      \rm out_rsync
1834      break
1835    fi
1836    (( i = i + 1 ))
1837  done
1838
1839  if [ ${status} -gt 0 ] ; then
1840      echo "IGCM_sys_ncdiff : ncdiff error"
1841      IGCM_debug_Exit "ncdiff"
1842  fi
1843
1844  IGCM_debug_PopStack "IGCM_sys_ncdiff"
1845}
1846
1847function IGCM_sys_ncea {
1848  IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
1849  if ( $DEBUG_sys ) ; then
1850    echo "IGCM_sys_ncea :" $@
1851  fi
1852
1853  typeset NB_ESSAI DELAI status i
1854  # number of tentative
1855  NB_ESSAI=3
1856  # time delay between tentative
1857  DELAI=2
1858
1859  i=0
1860  while [ $i -lt $NB_ESSAI ] ; do
1861    ncea $@ > out_rsync 2>&1
1862    status=$?
1863    if [ ${status} -gt 0 ] ; then
1864      IGCM_debug_Print 2 "IGCM_sys_ncea : error code ${status}"
1865      cat out_rsync
1866      \rm out_rsync
1867      IGCM_debug_Print 2 "IGCM_sys_ncea : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1868    else
1869      \rm out_rsync
1870      break
1871    fi
1872    (( i = i + 1 ))
1873  done
1874
1875  if [ ${status} -gt 0 ] ; then
1876      echo "IGCM_sys_ncea : ncea error"
1877      IGCM_debug_Exit "ncea"
1878  fi
1879
1880  IGCM_debug_PopStack "IGCM_sys_ncea"
1881}
1882
1883function IGCM_sys_ncecat {
1884  IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
1885  if ( $DEBUG_sys ) ; then
1886    echo "IGCM_sys_ncecat :" $@
1887  fi
1888
1889  typeset NB_ESSAI DELAI status i
1890  # number of tentative
1891  NB_ESSAI=3
1892  # time delay between tentative
1893  DELAI=2
1894
1895  i=0
1896  while [ $i -lt $NB_ESSAI ] ; do
1897    ncecat $@ > out_rsync 2>&1
1898    status=$?
1899    if [ ${status} -gt 0 ] ; then
1900      IGCM_debug_Print 2 "IGCM_sys_ncecat : error code ${status}"
1901      cat out_rsync
1902      \rm out_rsync
1903      IGCM_debug_Print 2 "IGCM_sys_ncecat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1904    else
1905      \rm out_rsync
1906      break
1907    fi
1908    (( i = i + 1 ))
1909  done
1910
1911  if [ ${status} -gt 0 ] ; then
1912      echo "IGCM_sys_ncecat : ncecat error"
1913      IGCM_debug_Exit "ncecat"
1914  fi
1915
1916  IGCM_debug_PopStack "IGCM_sys_ncecat"
1917}
1918
1919function IGCM_sys_ncflint {
1920  IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
1921  if ( $DEBUG_sys ) ; then
1922    echo "IGCM_sys_ncflint :" $@
1923  fi
1924
1925  typeset NB_ESSAI DELAI status i
1926  # number of tentative
1927  NB_ESSAI=3
1928  # time delay between tentative
1929  DELAI=2
1930
1931  i=0
1932  while [ $i -lt $NB_ESSAI ] ; do
1933    ncflint $@ > out_rsync 2>&1
1934    status=$?
1935    if [ ${status} -gt 0 ] ; then
1936      IGCM_debug_Print 2 "IGCM_sys_ncflint : error code ${status}"
1937      cat out_rsync
1938      \rm out_rsync
1939      IGCM_debug_Print 2 "IGCM_sys_ncflint : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1940    else
1941      \rm out_rsync
1942      break
1943    fi
1944    (( i = i + 1 ))
1945  done
1946
1947  if [ ${status} -gt 0 ] ; then
1948      echo "IGCM_sys_ncflint : ncflint error"
1949      IGCM_debug_Exit "ncflint"
1950  fi
1951
1952  IGCM_debug_PopStack "IGCM_sys_ncflint"
1953}
1954
1955function IGCM_sys_ncks {
1956  IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
1957  if ( $DEBUG_sys ) ; then
1958    echo "IGCM_sys_ncks :" $@
1959  fi
1960
1961  typeset NB_ESSAI DELAI status i
1962  # number of tentative
1963  NB_ESSAI=3
1964  # time delay between tentative
1965  DELAI=2
1966
1967  i=0
1968  while [ $i -lt $NB_ESSAI ] ; do
1969    ncks $@ > out_rsync 2>&1
1970    status=$?
1971    if [ ${status} -gt 0 ] ; then
1972      IGCM_debug_Print 2 "IGCM_sys_ncks : error code ${status}"
1973      cat out_rsync
1974      \rm out_rsync
1975      IGCM_debug_Print 2 "IGCM_sys_ncks : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1976    else
1977      \rm out_rsync
1978      break
1979    fi
1980    (( i = i + 1 ))
1981  done
1982
1983  if [ ${status} -gt 0 ] ; then
1984      echo "IGCM_sys_ncks : ncks error"
1985      IGCM_debug_Exit "ncks"
1986  fi
1987
1988  IGCM_debug_PopStack "IGCM_sys_ncks"
1989}
1990
1991function IGCM_sys_ncpdq {
1992  IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
1993  if ( $DEBUG_sys ) ; then
1994    echo "IGCM_sys_ncpdq :" $@
1995  fi
1996
1997  typeset NB_ESSAI DELAI status i
1998  # number of tentative
1999  NB_ESSAI=3
2000  # time delay between tentative
2001  DELAI=2
2002
2003  i=0
2004  while [ $i -lt $NB_ESSAI ] ; do
2005    ncpdq $@ > out_rsync 2>&1
2006    status=$?
2007    if [ ${status} -gt 0 ] ; then
2008      IGCM_debug_Print 2 "IGCM_sys_ncpdq : error code ${status}"
2009      cat out_rsync
2010      \rm out_rsync
2011      IGCM_debug_Print 2 "IGCM_sys_ncpdq : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2012    else
2013      \rm out_rsync
2014      break
2015    fi
2016    (( i = i + 1 ))
2017  done
2018
2019  if [ ${status} -gt 0 ] ; then
2020      echo "IGCM_sys_ncpdq : ncpdq error"
2021      IGCM_debug_Exit "ncpdq"
2022  fi
2023
2024  IGCM_debug_PopStack "IGCM_sys_ncpdq"
2025}
2026
2027function IGCM_sys_ncra {
2028  IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
2029  if ( $DEBUG_sys ) ; then
2030    echo "IGCM_sys_ncra :" $@
2031  fi
2032
2033  typeset NB_ESSAI DELAI status i
2034  # number of tentative
2035  NB_ESSAI=3
2036  # time delay between tentative
2037  DELAI=2
2038
2039  i=0
2040  while [ $i -lt $NB_ESSAI ] ; do
2041    ncra $@ > out_rsync 2>&1
2042    status=$?
2043    if [ ${status} -gt 0 ] ; then
2044      IGCM_debug_Print 2 "IGCM_sys_ncra : error code ${status}"
2045      cat out_rsync
2046      \rm out_rsync
2047      IGCM_debug_Print 2 "IGCM_sys_ncra : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2048    else
2049      \rm out_rsync
2050      break
2051    fi
2052    (( i = i + 1 ))
2053  done
2054
2055  if [ ${status} -gt 0 ] ; then
2056      echo "IGCM_sys_ncra : ncra error"
2057      IGCM_debug_Exit "ncra"
2058  fi
2059
2060  IGCM_debug_PopStack "IGCM_sys_ncra"
2061}
2062
2063function IGCM_sys_ncrcat {
2064  IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
2065  if ( $DEBUG_sys ) ; then
2066    echo "IGCM_sys_ncrcat :" $@
2067  fi
2068
2069  typeset NB_ESSAI DELAI status i
2070  # number of tentative
2071  NB_ESSAI=3
2072  # time delay between tentative
2073  DELAI=2
2074
2075  i=0
2076  while [ $i -lt $NB_ESSAI ] ; do
2077    ncrcat $@ > out_rsync 2>&1
2078    status=$?
2079    if [ ${status} -gt 0 ] ; then
2080      IGCM_debug_Print 2 "IGCM_sys_ncrcat : error code ${status}"
2081      cat out_rsync
2082      \rm out_rsync
2083      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2084    else
2085      \rm out_rsync
2086      break
2087    fi
2088    (( i = i + 1 ))
2089  done
2090
2091  if [ ${status} -gt 0 ] ; then
2092      echo "IGCM_sys_ncrcat : ncrcat error"
2093      #IGCM_debug_Exit "ncrcat"
2094  fi
2095
2096  IGCM_debug_PopStack "IGCM_sys_ncrcat"
2097}
2098
2099function IGCM_sys_ncrename {
2100  IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
2101  if ( $DEBUG_sys ) ; then
2102    echo "IGCM_sys_ncrename :" $@
2103  fi
2104
2105  typeset NB_ESSAI DELAI status i
2106  # number of tentative
2107  NB_ESSAI=3
2108  # time delay between tentative
2109  DELAI=2
2110
2111  i=0
2112  while [ $i -lt $NB_ESSAI ] ; do
2113    ncrename $@ > out_rsync 2>&1
2114    status=$?
2115    if [ ${status} -gt 0 ] ; then
2116      IGCM_debug_Print 2 "IGCM_sys_ncrename : error code ${status}"
2117      cat out_rsync
2118      \rm out_rsync
2119      IGCM_debug_Print 2 "IGCM_sys_ncrename : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2120    else
2121      \rm out_rsync
2122      break
2123    fi
2124    (( i = i + 1 ))
2125  done
2126
2127  if [ ${status} -gt 0 ] ; then
2128      echo "IGCM_sys_ncrename : ncrename error"
2129      IGCM_debug_Exit "ncrename"
2130  fi
2131
2132  IGCM_debug_PopStack "IGCM_sys_ncrename"
2133}
2134
2135function IGCM_sys_ncwa {
2136  IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
2137  if ( $DEBUG_sys ) ; then
2138    echo "IGCM_sys_ncwa :" $@
2139  fi
2140
2141  typeset NB_ESSAI DELAI status i
2142  # number of tentative
2143  NB_ESSAI=3
2144  # time delay between tentative
2145  DELAI=2
2146
2147  i=0
2148  while [ $i -lt $NB_ESSAI ] ; do
2149    ncwa $@ > out_rsync 2>&1
2150    status=$?
2151    if [ ${status} -gt 0 ] ; then
2152      IGCM_debug_Print 2 "IGCM_sys_ncwa : error code ${status}"
2153      cat out_rsync
2154      \rm out_rsync
2155      IGCM_debug_Print 2 "IGCM_sys_ncwa : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2156    else
2157      \rm out_rsync
2158      break
2159    fi
2160    (( i = i + 1 ))
2161  done
2162
2163  if [ ${status} -gt 0 ] ; then
2164      echo "IGCM_sys_ncwa : ncwa error"
2165      IGCM_debug_Exit "ncwa"
2166  fi
2167
2168  IGCM_debug_PopStack "IGCM_sys_ncwa"
2169}
2170
2171##############################################################
2172# CDO OPERATOR
2173
2174function IGCM_sys_cdo {
2175  IGCM_debug_PushStack "IGCM_sys_cdo" -- $@
2176  if ( $DEBUG_sys ) ; then
2177    echo "IGCM_sys_cdo :" $@
2178  fi
2179
2180  typeset status
2181
2182  \cdo $@ > out_rsync 2>&1
2183  status=$?
2184  if [ ${status} -gt 0 ] ; then
2185    echo "IGCM_sys_cdo : error code ${status}"
2186    cat out_rsync
2187    \rm out_rsync
2188    IGCM_debug_PopStack "IGCM_sys_cdo"
2189    return 1
2190  else
2191    IGCM_debug_PopStack "IGCM_sys_cdo"
2192    return 0
2193  fi
2194
2195  IGCM_debug_PopStack "IGCM_sys_cdo"
2196}
Note: See TracBrowser for help on using the repository browser.