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

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