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

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