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

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