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

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