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

Last change on this file since 785 was 785, checked in by labetoulle, 11 years ago

Cosmetics :

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