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

Last change on this file since 809 was 809, checked in by sdipsl, 11 years ago

Activate IGCM_sys_Chmod from DRYRUN=3 and add BoundaryFiles? list in FileToBeDeleted list at each Period.
Whitespace cleanup (from emacs macro) on libIGCM_sys_iitm.ksh
see #105

  • Property licence set to
    The following licence information concerns ONLY the libIGCM tools
    ==================================================================

    Copyright © Centre National de la Recherche Scientifique CNRS
    Commissariat à l'Énergie Atomique CEA

    libIGCM : Library for Portable Models Computation of IGCM Group.

    IGCM Group is the french IPSL Global Climate Model Group.

    This library is a set of shell scripts and functions whose purpose is
    the management of the initialization, the launch, the transfer of
    output files, the post-processing and the monitoring of datas produce
    by any numerical program on any plateforme.

    This software is governed by the CeCILL license under French law and
    abiding by the rules of distribution of free software. You can use,
    modify and/ or redistribute the software under the terms of the CeCILL
    license as circulated by CEA, CNRS and INRIA at the following URL
    "http://www.cecill.info".

    As a counterpart to the access to the source code and rights to copy,
    modify and redistribute granted by the license, users are provided only
    with a limited warranty and the software's author, the holder of the
    economic rights, and the successive licensors have only limited
    liability.

    In this respect, the user's attention is drawn to the risks associated
    with loading, using, modifying and/or developing or reproducing the
    software by the user in light of its specific status of free software,
    that may mean that it is complicated to manipulate, and that also
    therefore means that it is reserved for developers and experienced
    professionals having in-depth computer knowledge. Users are therefore
    encouraged to load and test the software's suitability as regards their
    requirements in conditions enabling the security of their systems and/or
    data to be ensured and, more generally, to use and operate it in the
    same conditions as regards security.

    The fact that you are presently reading this means that you have had
    knowledge of the CeCILL license and that you accept its terms.
  • Property svn:keywords set to Revision Author Date
File size: 60.7 KB
Line 
1#!/bin/ksh
2
3#**************************************************************
4# Author: Sebastien Denvil, Martial Mancip
5# Contact: Martial.Mancip__at__ipsl.jussieu.fr
6# $Revision::                                          $ Revision of last commit
7# $Author::                                            $ Author of last commit
8# $Date::                                              $ Date of last commit
9# IPSL (2006)
10#  This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC
11#
12#**************************************************************
13
14#=========================================================
15# The documentation of this file can be automatically generated
16# if you use the prefix #D- for comments to be extracted.
17# Extract with command: cat lib* | grep "^#D-" | cut -c "4-"
18#=========================================================
19
20#D-#==================================================
21#D-LibIGCM_sys Default host
22#D-#==================================================
23#D-
24#D- This ksh library if a layer under some usefull
25#D-environment variables and shell commands.
26#D-All those definitions depend on host particularities.
27#D-It manages a stack mechanism and test validity of operations.
28#D-All function described bellow must be prefixed by IGCM_sys.
29
30#====================================================
31# libIGCM_sys PARAMETERS
32#====================================================
33
34#====================================================
35# set DEBUG_sys to true to output calls of function
36typeset -r DEBUG_sys=${DEBUG_sys:=true}
37
38#====================================================
39# Turn in dry run mode ? (sys_Put_Rest, sys_Put_Out, sys_Get)
40typeset -r DRYRUN=${DRYRUN:=0}
41
42# YOU MUST COMPILE YOUR EXE FILES FOR DRYRUN MODE !
43# -------------------------------------------------------------------------------------
44# | DRYRUN=  |  Date computations, | sys_Get    |  Exe    | sys_Put_Out; sys_Put_Rest |
45# |          |  Cp/Exe/param/files |            |         |                           |
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 (dedicated to large files)
118typeset -r ARCHIVE=/home/${LOGIN}
119
120#====================================================
121#- STORAGE (dedicated to small/medium files)
122typeset -r STORAGE=${ARCHIVE}
123
124#====================================================
125#- R_OUT
126typeset R_OUT=${ARCHIVE}/IGCM_OUT
127
128#====================================================
129#- R_FIG (hosting figures : monitoring and atlas, and/or small files)
130typeset R_FIG=${STORAGE}/IGCM_OUT
131
132#====================================================
133#- R_BUF (ONLY FOR double copy an scratch)
134typeset -r R_BUF=${STORAGE}/IGCM_OUT
135
136#====================================================
137#- 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
168  IGCM_debug_Print 1 " dummy function : IGCM_sys_ChangeArchive "
169
170}
171
172#D-#==================================================
173#D-function IGCM_sys_RshMaster
174#D-* Purpose: Connection to frontend machine.
175#D-* Examples:
176#D-
177function IGCM_sys_RshMaster {
178  IGCM_debug_PushStack "IGCM_sys_RshMaster" $@
179  /bin/ksh <<-EOF
180    export libIGCM=${libIGCM}
181    export DEBUG_debug=${DEBUG_debug}
182    . ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh
183    . ${libIGCM}/libIGCM_card/libIGCM_card.ksh
184    ${@}
185EOF
186  if [ $? -gt 0 ] ; then
187    echo "IGCM_sys_RshMaster : erreur."
188    IGCM_debug_Exit "IGCM_sys_RshMaster"
189  fi
190  IGCM_debug_PopStack "IGCM_sys_RshMaster"
191}
192
193#D-#==================================================
194#D-function IGCM_sys_RshArchive
195#D-* Purpose: Archive rsh command
196#D-* Examples:
197#D-
198function IGCM_sys_RshArchive {
199  IGCM_debug_PushStack "IGCM_sys_RshArchive" $@
200  /bin/ksh <<-EOF
201    ${@}
202EOF
203  if [ $? -gt 0 ] ; then
204    echo "IGCM_sys_RshArchive : erreur."
205    IGCM_debug_Exit "IGCM_sys_RshArchive"
206  fi
207  IGCM_debug_PopStack "IGCM_sys_RshArchive"
208}
209
210#D-#==================================================
211#D-function IGCM_sys_RshPost
212#D-* Purpose: Post-process rsh command
213#D-* Examples:
214#D-
215function IGCM_sys_RshPost {
216  IGCM_debug_PushStack "IGCM_sys_RshPost" $@
217  if ( $DEBUG_sys ) ; then
218    echo "IGCM_sys_RshPost :" $@
219  fi
220
221  #echo cat tmp_IGCM_sys_RshPost_$$ INITIAL
222  #cat tmp_IGCM_sys_RshPost_$$
223  # keep standard input (stdin) for the loop onto temporary file
224  cat >tmp_IGCM_sys_RshPost_$$
225
226  /bin/ksh <tmp_IGCM_sys_RshPost_$$
227  if [ $? -gt 0 ] ; then
228    echo "IGCM_sys_RshPost : erreur."
229    IGCM_debug_Exit "IGCM_sys_RshPost"
230  fi
231  # delete temporary file
232  \rm tmp_IGCM_sys_RshPost_$$
233
234  IGCM_debug_PopStack "IGCM_sys_RshPost"
235}
236
237#D-#==================================================
238#D-function IGCM_sys_SendMail
239#D-* Purpose: Send mail when simulation is over
240#D-* Examples:
241#D-
242function IGCM_sys_SendMail {
243  IGCM_debug_PushStack "IGCM_sys_SendMail" $@
244  if ( $DEBUG_sys ) ; then
245    echo "IGCM_sys_SendMail :" $@
246  fi
247
248  if ( ${ExitFlag} ) ; then
249    status=failed
250  else
251    status=completed
252  fi
253
254  cat  << END_MAIL > job_end.mail
255Dear ${LOGIN},
256
257  Simulation ${config_UserChoices_JobName} is ${status} on supercomputer `hostname`.
258  Job started : ${DateBegin}
259  Job ended   : ${DateEnd}
260  Output files are available in ${R_SAVE}
261  Files to be rebuild are temporarily available in ${REBUILD_DIR}
262  Pre-packed files are temporarily available in ${R_BUFR}
263  Script files, Script Outputs and Debug files (if necessary) are available in ${SUBMIT_DIR}
264END_MAIL
265
266  if [ ! -z ${config_UserChoices_MailName} ] ; then
267    mailx -s "${config_UserChoices_JobName} ${status}" ${config_UserChoices_MailName} <  job_end.mail
268  elif [ -f ~/.forward ] ; then
269    mailx -s "${config_UserChoices_JobName} ${status}" $( cat ~/.forward ) < job_end.mail
270  fi
271
272  if [ $? -gt 0 ] ; then
273    echo "IGCM_sys_SendMail : erreur."
274    IGCM_debug_Exit "IGCM_sys_SendMail"
275  fi
276  IGCM_debug_PopStack "IGCM_sys_SendMail"
277}
278
279#D-#==================================================
280#D-function IGCM_sys_Mkdir
281#D-* Purpose: Master locale mkdir command
282#D-* Examples:
283#D-
284function IGCM_sys_Mkdir {
285  IGCM_debug_PushStack "IGCM_sys_Mkdir" $@
286  if ( $DEBUG_sys ) ; then
287    echo "IGCM_sys_Mkdir :" $@
288  fi
289  if [ ! -d ${1} ]; then
290    \mkdir -p $1
291    if [ $? -gt 0 ] ; then
292      echo "IGCM_sys_Mkdir : erreur."
293      IGCM_debug_Exit "IGCM_sys_Mkdir"
294    fi
295  fi
296  # vérification :
297  if [ ! -d ${1} ] ; then
298    echo "IGCM_sys_Mkdir : erreur."
299    IGCM_debug_Exit "IGCM_sys_Mkdir"
300  fi
301  IGCM_debug_PopStack "IGCM_sys_Mkdir"
302}
303
304#D-#==================================================
305#D-function IGCM_sys_MkdirArchive
306#D-* Purpose: Mkdir on Archive
307#D-* Examples:
308#D-
309function IGCM_sys_MkdirArchive {
310  IGCM_debug_PushStack "IGCM_sys_MkdirArchive" $@
311  if ( $DEBUG_sys ) ; then
312    echo "IGCM_sys_MkdirArchive :" $@
313  fi
314  #- creation de repertoire sur le serveur fichier
315  if [ ! -d ${1} ]; then
316    \mkdir -p $1
317    if [ $? -gt 0 ] ; then
318      echo "IGCM_sys_MkdirArchive : erreur."
319      IGCM_debug_Exit "IGCM_sys_MkdirArchive"
320    fi
321  fi
322  IGCM_debug_PopStack "IGCM_sys_MkdirArchive"
323}
324
325#D-#==================================================
326#D-function IGCM_sys_MkdirWork
327#D-* Purpose: Mkdir on Work
328#D-* Examples:
329#D-
330function IGCM_sys_MkdirWork {
331  IGCM_debug_PushStack "IGCM_sys_MkdirWork" $@
332  if ( $DEBUG_sys ) ; then
333    echo "IGCM_sys_MkdirWork :" $@
334  fi
335  #- creation de repertoire sur le serveur fichier
336  if [ ! -d ${1} ]; then
337    \mkdir -p $1
338    if [ $? -gt 0 ] ; then
339      echo "IGCM_sys_MkdirWork : erreur."
340      IGCM_debug_Exit "IGCM_sys_MkdirWork"
341    fi
342  fi
343  IGCM_debug_PopStack "IGCM_sys_MkdirWork"
344}
345
346#D-#==================================================
347#D-function IGCM_sys_Cd
348#D-* Purpose: master cd command
349#D-* Examples:
350#D-
351function IGCM_sys_Cd {
352  IGCM_debug_PushStack "IGCM_sys_Cd" $@
353  if ( $DEBUG_sys ) ; then
354    echo "IGCM_sys_Cd :" $@
355  fi
356  \cd $1
357  if [ $? -gt 0 ] ; then
358    echo "IGCM_sys_Cd : erreur."
359    IGCM_debug_Exit "IGCM_sys_Cd"
360  fi
361  IGCM_debug_PopStack "IGCM_sys_Cd"
362}
363
364#D-#==================================================
365#D-function IGCM_sys_Chmod
366#D-* Purpose: Chmod
367#D-* Examples:
368#D-
369function IGCM_sys_Chmod {
370  IGCM_debug_PushStack "IGCM_sys_Chmod" -- $@
371  if ( $DEBUG_sys ) ; then
372    echo "IGCM_sys_Chmod :" $@
373  fi
374  \chmod $@
375  if [ $? -gt 0 ] ; then
376    echo "IGCM_sys_Chmod : erreur."
377    IGCM_debug_Exit "IGCM_sys_Chmod"
378  fi
379  IGCM_debug_PopStack "IGCM_sys_Chmod"
380}
381
382#D-#==================================================
383#D-function IGCM_sys_FileSize
384#D-* Purpose: Filesize
385#D-* Examples:
386#D-
387function IGCM_sys_FileSize {
388  IGCM_debug_PushStack "IGCM_sys_FileSize" $@
389
390  typeset sizeF
391  set +A sizeF -- $( ls -la ${1} )
392  if [ $? -gt 0 ] ; then
393    IGCM_debug_Exit "IGCM_sys_FileSize"
394  fi
395  eval ${2}=${sizeF[4]}
396
397  IGCM_debug_PopStack "IGCM_sys_FileSize"
398}
399
400#D-#==================================================
401#D-function IGCM_sys_TestDir
402#D-* Purpose: Test Directory that must exists
403#D-* Examples:
404#D-
405function IGCM_sys_TestDir {
406  IGCM_debug_PushStack "IGCM_sys_TestDir" $@
407  if ( $DEBUG_sys ) ; then
408    echo "IGCM_sys_TestDir :" $@
409  fi
410  typeset ExistFlag
411  ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
412  IGCM_debug_PopStack "IGCM_sys_TestDir"
413
414  return ${ExistFlag}
415}
416
417#D-#==================================================
418#D-function IGCM_sys_TestDirArchive
419#D-* Purpose: Test Directory that must exists on Archive
420#D-* Examples:
421#D-
422function IGCM_sys_TestDirArchive {
423  IGCM_debug_PushStack "IGCM_sys_TestDirArchive" $@
424  if ( $DEBUG_sys ) ; then
425    echo "IGCM_sys_TestDirArchive :" $@
426  fi
427  typeset ExistFlag
428  ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
429  IGCM_debug_PopStack "IGCM_sys_TestDirArchive"
430
431  return ${ExistFlag}
432}
433
434#D-#==================================================
435#D-function IGCM_sys_IsFileArchived
436#D-* Purpose: Test file that must NOT EXISTS on Archive
437#D-* Examples:
438#D-
439function IGCM_sys_IsFileArchived {
440  IGCM_debug_PushStack "IGCM_sys_IsFileArchived" $@
441  if ( $DEBUG_sys ) ; then
442    echo "IGCM_sys_IsFileArchived :" $@
443  fi
444  typeset IsArchivedFlag
445  # Never archived for this system
446  IsArchivedFlag=1
447  IGCM_debug_PopStack "IGCM_sys_IsFileArchived"
448
449  return ${IsArchivedFlag}
450}
451
452#D-#==================================================
453#D-function IGCM_sys_TestFileArchive
454#D-* Purpose: Test file that must NOT EXISTS on Archive
455#D-* Examples:
456#D-
457function IGCM_sys_TestFileArchive {
458  IGCM_debug_PushStack "IGCM_sys_TestFileArchive" $@
459  typeset ExistFlag
460  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
461  IGCM_debug_PopStack "IGCM_sys_TestFileArchive"
462
463  return ${ExistFlag}
464}
465
466#D-#==================================================
467#D-function IGCM_sys_TestFileBuffer
468#D-* Purpose: Test file that must NOT EXISTS on Buffer
469#D-* Examples:
470#D-
471function IGCM_sys_TestFileBuffer {
472  IGCM_debug_PushStack "IGCM_sys_TestFileBuffer" $@
473  typeset ExistFlag
474  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
475  IGCM_debug_PopStack "IGCM_sys_TestFileBuffer"
476
477  return ${ExistFlag}
478}
479
480#D-#==================================================
481#D-function IGCM_sys_CountFileArchive
482#D-* Purpose: Count files on Archive filesystem
483#D-* Examples:
484#D-
485function IGCM_sys_CountFileArchive {
486  IGCM_debug_PushStack "IGCM_sys_CountFileArchive" $@
487  ls ${@} 2>/dev/null | wc -l
488  if [ $? -gt 0 ] ; then
489    echo "IGCM_sys_CountFileArchive : erreur."
490  fi
491  IGCM_debug_PopStack "IGCM_sys_CountFileArchive"
492}
493
494#D-#==================================================
495#D-function IGCM_sys_CountFileBuffer
496#D-* Purpose: Count files on Scratch filesystem
497#D-* Examples:
498#D-
499function IGCM_sys_CountFileBuffer {
500  IGCM_debug_PushStack "IGCM_sys_CountFileBuffer" $@
501  ls ${@} 2>/dev/null | wc -l
502  if [ $? -gt 0 ] ; then
503    echo "IGCM_sys_CountFileBuffer : erreur."
504  fi
505  IGCM_debug_PopStack "IGCM_sys_CountFileBuffer"
506}
507
508#D-#==================================================
509#D-function IGCM_sys_Tree
510#D-* Purpose: Tree directories with files on ${ARCHIVE}
511#D-* Examples: IGCM_sys_Tree ${R_IN} ${R_OUT}
512#D-
513function IGCM_sys_Tree {
514  IGCM_debug_PushStack "IGCM_sys_Tree" $@
515  if ( $DEBUG_sys ) ; then
516    echo "IGCM_sys_Tree :" $@
517  fi
518
519  \tree -f $@
520
521  IGCM_debug_PopStack "IGCM_sys_Tree"
522}
523
524#D-#==================================================
525#D-function IGCM_sys_Tar
526#D-* Purpose: master tar command
527#D-* Examples:
528#D-
529function IGCM_sys_Tar {
530  IGCM_debug_PushStack "IGCM_sys_Tar" $@
531  if ( $DEBUG_sys ) ; then
532    echo "IGCM_sys_Tar :" $@
533  fi
534  \tar cf $@
535  if [ $? -gt 0 ] ; then
536    echo "IGCM_sys_Tar : erreur."
537    IGCM_debug_Exit "IGCM_sys_Tar"
538  fi
539  IGCM_debug_PopStack "IGCM_sys_Tar"
540}
541
542#D-#==================================================
543#D-function IGCM_sys_UnTar
544#D-* Purpose: master un-tar command
545#D-* Examples:
546#D-
547function IGCM_sys_UnTar {
548  IGCM_debug_PushStack "IGCM_sys_UnTar" $@
549  if ( $DEBUG_sys ) ; then
550    echo "IGCM_sys_UnTar :" $@
551  fi
552  \tar xvf $1
553  if [ $? -gt 0 ] ; then
554    echo "IGCM_sys_UnTar : erreur."
555    IGCM_debug_Exit "IGCM_sys_UnTar"
556  fi
557  IGCM_debug_PopStack "IGCM_sys_UnTar"
558}
559
560#D-#==================================================
561#D-function IGCM_sys_Qsub
562#D-* Purpose: Qsub new job
563#D-* Examples:
564#D-
565function IGCM_sys_Qsub {
566  IGCM_debug_PushStack "IGCM_sys_Qsub" $@
567  if ( $DEBUG_sys ) ; then
568    echo "IGCM_sys_Qsub :" $@
569  fi
570  echo "${@} > ${SUBMIT_DIR}/${Script_Output} 2>&1 &"
571  ${@} > ${SUBMIT_DIR}/${Script_Output} 2>&1 &
572  if [ $? -gt 0 ] ; then
573    echo "IGCM_sys_Qsub : erreur ${options} $1"
574    IGCM_debug_Exit "IGCM_sys_Qsub"
575  fi
576  IGCM_debug_PopStack "IGCM_sys_Qsub"
577}
578
579#D-#==================================================
580#D-function IGCM_sys_QsubPost
581#D-* Purpose: Qsub new job on scalaire
582#D-* Examples:
583#D-
584function IGCM_sys_QsubPost {
585  IGCM_debug_PushStack "IGCM_sys_QsubPost" $@
586  if ( $DEBUG_sys ) ; then
587    echo "IGCM_sys_QsubPost :" $@
588  fi
589  echo "${libIGCM_POST}/$1.job > ${POST_DIR}/$1.${PeriodDateEnd}.out 2>&1 &"
590  ${libIGCM_POST}/$1.job > ${POST_DIR}/${Script_Post_Output}.out 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  status=$1
610  if [ ! $status ] ; then
611    echo "rsync error !"
612  fi
613
614  if [ $MYLANG = "fr" ]; then
615    case $status 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 :" $status
664      return;;
665    esac
666  elif [ $MYLANG = "en" ] ; then
667    case $status 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 :" $status
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 user 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_PrepareTaredRestart
1025#D-* Purpose: Prepare tared restart to be access by computing job. Identity here.
1026#D-* Examples:
1027#D-
1028function IGCM_sys_PrepareTaredRestart {
1029  IGCM_debug_PushStack "IGCM_sys_PrepareTaredRestart" $@
1030  echo $1
1031  IGCM_debug_PopStack "IGCM_sys_PrepareTaredRestart"
1032}
1033
1034#D-#==================================================
1035#D-function IGCM_sys_Put_Out
1036#D-* Purpose: Copy a file on ${ARCHIVE} after having chmod it in readonly
1037#D-* Examples:
1038#D-
1039function IGCM_sys_Put_Out {
1040  IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
1041  if ( $DEBUG_sys ) ; then
1042    echo "IGCM_sys_Put_Out :" $@
1043  fi
1044  if [ $DRYRUN = 0 ]; then
1045    if [ -f ${1} ] ; then
1046      if [ ! -d $( dirname $2 ) ] ; then
1047        IGCM_sys_MkdirArchive $( dirname $2 )
1048      fi
1049    else
1050      echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
1051      IGCM_debug_PopStack "IGCM_sys_Put_Out"
1052      return 1
1053    fi
1054
1055    typeset RET
1056    #
1057    if [ X${JobType} = XRUN ] ; then
1058      if [ X${3} = X ] ; then
1059        IGCM_sys_Chmod 444 ${1}
1060      fi
1061    fi
1062    #
1063
1064    echo ${RSYNC} ${RSYNC_opt} $1 $2 > out_rsync 2>&1
1065    ${RSYNC} ${RSYNC_opt} $1 $2 >> out_rsync 2>&1
1066    RET=$?
1067    IGCM_sys_Rsync_out $RET
1068
1069    ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1070    (( RET=RET+$? ))
1071
1072    if [ ${RET} -gt 0 ] ; then
1073      echo "IGCM_sys_Put_Out : error."
1074      cat out_rsync
1075      IGCM_debug_Exit "IGCM_sys_Put_Out"
1076    else
1077      \rm out_rsync
1078    fi
1079  else
1080    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1081  fi
1082  IGCM_debug_PopStack "IGCM_sys_Put_Out"
1083  return 0
1084}
1085
1086#D-#==================================================
1087#D-function IGCM_sys_PutBuffer_Out
1088#D-* Purpose: Copy a file on ${SCRATCHDIR} after having chmod it in readonly
1089#D-* Examples:
1090#D-
1091function IGCM_sys_PutBuffer_Out {
1092  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Out" $@
1093  if ( $DEBUG_sys ) ; then
1094    echo "IGCM_sys_PutBuffer_Out :" $@
1095  fi
1096  if [ $DRYRUN = 0 ]; then
1097    if [ ! -f ${1} ] ; then
1098      echo "WARNING : IGCM_sys_PutBuffer_Out ${1} DOES NOT EXIST ."
1099      IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1100      return 1
1101    fi
1102    #
1103    IGCM_sys_Mkdir $( dirname $2 )
1104    #
1105    typeset RET
1106
1107    if [ X${JobType} = XRUN ] ; then
1108      if [ X${3} = X ] ; then
1109        IGCM_sys_Chmod 444 ${1}
1110      fi
1111    fi
1112    #
1113    # USUAL WAY
1114    \cp $1 $2 > out_rsync 2>&1
1115    RET=$?
1116
1117    if [ ${RET} -gt 0 ] ; then
1118      echo "IGCM_sys_PutBuffer_Out : error."
1119      cat out_rsync
1120      IGCM_debug_Exit "IGCM_sys_PutBuffer_Out"
1121    else
1122      \rm out_rsync
1123    fi
1124  else
1125    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1126  fi
1127  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1128  return 0
1129}
1130
1131#D-#==================================================
1132#D-function IGCM_sys_Get
1133#D-* Purpose: Get a file from ${ARCHIVE}
1134#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
1135#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
1136function IGCM_sys_Get {
1137  IGCM_debug_PushStack "IGCM_sys_Get" $@
1138
1139  typeset DEST RET dm_liste ifile target
1140
1141  if ( $DEBUG_sys ) ; then
1142    echo "IGCM_sys_Get :" $@
1143  fi
1144  if [ $DRYRUN -le 2 ]; then
1145    if [ X${1} = X'/l' ] ; then
1146      # test if the first file is present in the old computation :
1147      eval set +A dm_liste \${${2}}
1148    else
1149      dm_liste=${1}
1150    fi
1151    eval DEST=\${${#}}
1152
1153    # test if the (first) file is present in the old computation :
1154    IGCM_sys_TestFileArchive ${dm_liste[0]}
1155    RET=$?
1156    if [ ${RET} -gt 0 ] ; then
1157      echo "IGCM_sys_Get, ERROR : regular file ${dm_liste[0]} DOES NOT EXIST ."
1158      IGCM_debug_Exit "IGCM_sys_Get"
1159            #return
1160    fi
1161
1162    (( RET=0 ))
1163    for target in ${dm_liste[*]} ; do
1164      \cp ${target} ${DEST} >> out_rsync 2>&1
1165      (( RET=RET+$? ))
1166    done
1167
1168#       echo ${RSYNC} ${RSYNC_opt} $@ > out_rsync 2>&1
1169#       ${RSYNC} ${RSYNC_opt} $@ >> out_rsync 2>&1
1170#       RET=$?
1171#       IGCM_sys_Rsync_out $RET
1172
1173#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1174#       (( RET=RET+$? ))
1175
1176    if [ ${RET} -gt 0 ] ; then
1177      echo "IGCM_sys_Get : error"
1178      cat out_rsync
1179      \rm out_rsync
1180      IGCM_debug_Exit "IGCM_sys_Get"
1181    else
1182      \rm out_rsync
1183    fi
1184  else
1185    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1186  fi
1187  IGCM_debug_PopStack "IGCM_sys_Get"
1188}
1189
1190#D-#==================================================
1191#D-function IGCM_sys_GetBuffer
1192#D-* Purpose: Get a file from ${SCRATCHDIR}
1193#D-* Examples: IGCM_sys_GetBuffer myfile /destpath/myfile_with_PREFIX
1194#D-            IGCM_sys_GetBuffer /l Array_contain_myfiles /destpath/
1195function IGCM_sys_GetBuffer {
1196  IGCM_debug_PushStack "IGCM_sys_GetBuffer" $@
1197
1198  typeset DEST RET status buf_liste ifile target file_work
1199
1200  if ( $DEBUG_sys ) ; then
1201    echo "IGCM_sys_GetBuffer :" $@
1202  fi
1203  if [ $DRYRUN -le 2 ]; then
1204    if [ X${1} = X'/l' ] ; then
1205      # test if the first file is present in the old computation :
1206      eval set +A buf_liste \${${2}}
1207    else
1208      eval set +A buf_liste ${1}
1209    fi
1210    eval DEST=\${${#}}
1211
1212    #USUAL WAY
1213    if [ X${1} = X'/l' ] ; then
1214      (( RET=0 ))
1215      for target in ${buf_liste[*]} ; do
1216        local_file=$( basename ${target} )
1217        \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1218        (( RET = RET + $? ))
1219      done
1220    else
1221      \cp ${buf_liste} ${DEST} >> out_rsync 2>&1
1222      status=$?
1223    fi
1224
1225    if [ ${RET} -gt 0 ] ; then
1226      echo "IGCM_sys_GetBuffer : error"
1227      cat out_rsync
1228      \rm out_rsync
1229      IGCM_debug_Exit "IGCM_sys_GetBuffer"
1230    else
1231      \rm out_rsync
1232    fi
1233  else
1234    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1235  fi
1236  IGCM_debug_PopStack "IGCM_sys_GetBuffer"
1237}
1238
1239#D-#==================================================
1240#D-function IGCM_sys_GetDate_FichWork
1241#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
1242#D-* Examples:
1243#D-
1244function IGCM_sys_GetDate_FichWork {
1245  IGCM_debug_PushStack "IGCM_sys_FichWork" $@
1246  if ( $DEBUG_sys ) ; then
1247    echo "IGCM_sys_GetDate_FichWork :" $@
1248  fi
1249  typeset dateF
1250  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1251  eval ${2}=${dateF[5]}
1252
1253  # donne la date filesys d'un fichier sur la machine work
1254  IGCM_debug_PopStack "IGCM_sys_FichWork"
1255}
1256
1257#D-#==================================================
1258#D-function IGCM_sys_GetDate_FichArchive
1259#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
1260#D-* Examples:
1261#D-
1262function IGCM_sys_GetDate_FichArchive {
1263  IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
1264  if ( $DEBUG_sys ) ; then
1265    echo "IGCM_sys_GetDate_FichArchive :" $@
1266  fi
1267  typeset dateF
1268  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1269  eval ${2}=${dateF[5]}
1270
1271  IGCM_debug_PopStack "IGCM_sys_FichArchive"
1272}
1273
1274#D-#==================================================
1275#D-function IGCM_sys_Dods_Rm
1276#D-* Purpose: DO NOTHING ! Put ${ARCHIVE} files on DODS internet protocole.
1277#D-* Examples:
1278#D-
1279function IGCM_sys_Dods_Rm {
1280  if ( $DEBUG_sys ) ; then
1281    echo "IGCM_sys_Dods_Rm :" $@
1282  fi
1283  return 0
1284}
1285
1286#D-#==================================================
1287#D-function IGCM_sys_Dods_Cp
1288#D-* Purpose: Copy from $(ARCHIVE) files to /tmp/DODS for simulation of internet protocole.
1289#D-* Examples:
1290#D-
1291function IGCM_sys_Dods_Cp {
1292  if ( $DEBUG_sys ) ; then
1293    echo "IGCM_sys_Dods_Cp :" $@
1294  fi
1295  return 0
1296}
1297
1298#D-#==================================================
1299#D-function IGCM_sys_Put_Dods
1300#D-* Purpose: Put $(ARCHIVE) files on /tmp/DODS for simulation of internet protocole.
1301#D-* Examples:
1302#D-
1303function IGCM_sys_Put_Dods {
1304  IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
1305  if ( $DEBUG_sys ) ; then
1306    echo "IGCM_sys_Put_Dods :" $@
1307  fi
1308  if [ $DRYRUN = 0 ]; then
1309    RET=0
1310
1311    if [ ${RET} -gt 0 ] ; then
1312      echo "IGCM_sys_Put_Dods : error."
1313      IGCM_debug_Exit "IGCM_sys_Put_Dods"
1314    fi
1315  else
1316    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1317  fi
1318  IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1319}
1320
1321##############################################################
1322# REBUILD OPERATOR
1323
1324function IGCM_sys_rebuild {
1325  IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1326  if ( $DEBUG_sys ) ; then
1327    echo "IGCM_sys_rebuild :" $@
1328  fi
1329  rebuild -f -o $@
1330  if [ $? -gt 0 ] ; then
1331    echo "IGCM_sys_rebuild : rebuild error"
1332    IGCM_debug_Exit "rebuild"
1333  fi
1334
1335  IGCM_debug_PopStack "IGCM_sys_rebuild"
1336}
1337
1338function IGCM_sys_rebuild_station {
1339  IGCM_debug_PushStack "IGCM_sys_rebuild_station" -- $@
1340  typeset i list_opt file_in file_out prefix_invert list_invert
1341  if ( $DEBUG_sys ) ; then
1342    echo "IGCM_sys_rebuild_station :" $@
1343  fi
1344  list_opt=$@
1345
1346  # Invert Axis : t,x -> x,t
1347  #               t,pres,x -> x,t,pres
1348  # So that we can concatenate along x
1349  i=0
1350  for file_in in ${list_opt} ; do
1351    (( i = i + 1))
1352    [ ${i} = 1 ] && file_out=${file_in} && continue
1353    prefix_invert=$( basename ${file_in} .nc )
1354    IGCM_sys_ncpdq -a x,time_counter -a x,time_counter,presnivs ${file_in} ${prefix_invert}_xt.nc
1355    list_invert[${#list_invert[*]}]=${prefix_invert}_xt.nc
1356  done
1357
1358  # Concatenate
1359  IGCM_sys_ncrcat ${list_invert[*]} histstn_xt.nc
1360
1361  # Re-ivert file
1362  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x histstn_xt.nc ${file_out}
1363
1364  # Station re-ordering is too expansive to be run within libICGM
1365  # This is due to (ncpdq - nrcat - ncpdq) I/O sequence.
1366  # This re-ordering must be done "in memory" by the cmorization process
1367  # Anyway this is the best sequence using (ncpdq - nrcat - ncpdq)
1368  # BEGIN reordering
1369
1370  # Only LMDZ text output contains the exact ordering of the station.
1371  # We isolate this in the code below:
1372  #  0  38  -157.5000000000000  70.98591549295774
1373  #  0  54  27.49999999999999   67.18309859154928
1374  #  0  56  -62.50000000000001  82.39436619718309
1375  #  0  79  12.49999999999999   78.59154929577466
1376  #  0  116 -165.0000000000000  76.05633802816901
1377  #  0  117 130.0000000000000   70.98591549295774
1378  #  0  118 110.0000000000000   87.46478873239437
1379  #  1  40  4.999999999999995   51.97183098591550
1380#  typeset iStation iProc list_opt file_in file_out prefix_invert
1381#  typeset -Z4 j4
1382#  typeset -Z3 j3
1383
1384#  unset list_opt
1385#  set +A list_opt $@
1386
1387  # Filename after rebuild
1388#  file_out=${list_opt[0]}
1389  # Prefix of output files
1390#  prefix_invert=$( basename ${file_out} .nc )
1391  # Number of procs
1392#  num_proc=$( grep -i mpi_size ${PREFIX}_${Exe_Output} | wc -l )
1393
1394#  iProc=0
1395#  while [ ${iProc} -lt ${num_proc} ] ; do
1396    # Array containing Station as a number
1397#    unset proc_stn
1398#    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}' )
1399    # Number of stations produced by processor proc
1400#    stationLast=${#proc_stn[*]}
1401    # Proc number on 4 digits
1402#    j4=${iProc}
1403    # Init
1404#    iStation=0
1405#    while [ ${iStation} -lt ${stationLast} ] ; do
1406      # Station number on 3 digits
1407#      j3=${proc_stn[${iStation}]}
1408      # Extract station
1409      # Invert Axis : t,x -> x,t
1410      #               t,pres,x -> x,t,pres
1411      # So that we can concatenate along x
1412#      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
1413#      (( iStation = iStation + 1 ))
1414#    done
1415#    (( iProc = iProc + 1 ))
1416#  done
1417
1418  # Concatenate all station along x
1419#  IGCM_sys_ncrcat ${prefix_invert}_stn_???.nc ${prefix_invert}_xt.nc
1420
1421  # Re-invert file
1422#  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x ${prefix_invert}_xt.nc ${file_out}
1423
1424  # END reordering
1425
1426  IGCM_debug_PopStack "IGCM_sys_rebuild_station"
1427}
1428
1429############################################################
1430# Activate Running Environnment Variables
1431
1432function IGCM_sys_activ_variables {
1433  IGCM_debug_PushStack "IGCM_sys_activ_variables"
1434  if ( $DEBUG_sys ) ; then
1435    echo "IGCM_sys_activ_variables"
1436  fi
1437  IGCM_debug_PopStack "IGCM_sys_activ_variables"
1438}
1439
1440############################################################
1441# Desactivate Running Environnment Variables
1442
1443function IGCM_sys_desactiv_variables {
1444  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1445  if ( $DEBUG_sys ) ; then
1446    echo "IGCM_sys_desactiv_variables"
1447  fi
1448  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1449}
1450
1451############################################################
1452# Build MPI/OMP scripts run file (dummy function)
1453
1454function IGCM_sys_build_run_file {
1455
1456  IGCM_debug_Print 3 " dummy function : IGCM_sys_build_run_file "
1457
1458}
1459
1460############################################################
1461# Build MPI/OMP scripts
1462function IGCM_sys_build_execution_scripts
1463{
1464  IGCM_debug_PushStack "IGCM_sys_build_execution_scripts" $@
1465  if ( $DEBUG_sys ) ; then
1466    echo "IGCM_sys_build_execution_scripts " $@
1467  fi
1468  typeset nodes listnodes init_node start_num init_exec comp ExeNameIn ExeNameOut
1469  typeset node_num_current node_current comp_proc_mpi_loc comp_proc_omp_loc
1470  typeset num_corempi nombre_restant_node nombre_restant_comp
1471
1472  if [ ! -f ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} ]  ; then
1473    IGCM_debug_Exit "IGCM_sys_titane build_execution_scripts : Job_${config_UserChoices_JobName} doesn't exist in SUBMIT_DIR : ${SUBMIT_DIR} "
1474  fi
1475
1476  if ( ${OK_PARA_MPMD} ) ; then
1477
1478    if [ -f run_file ] ; then
1479      IGCM_sys_Rm -f run_file
1480    fi
1481    touch run_file
1482
1483    if ( ${OK_PARA_OMP} ) ; then
1484
1485      #  Hosts treatment
1486
1487      ${HOST_MPIRUN_COMMAND} hostname | sort | uniq > hosts.tmp
1488
1489      i=0
1490      rm -f hosts
1491      IGCM_debug_Print 1 "sys $( hostname ), Hosts avaible :"
1492      for nodes in `cat hosts.tmp` ; do
1493        host[$i]=$nodes
1494        echo "${host[$i]} slots=1 max_slots=1" >> hosts
1495        IGCM_debug_Print 1 ${host[$i]}
1496        i=$((i+1))
1497      done
1498      rm -f hosts.tmp
1499
1500      listnodes=${host[*]}
1501
1502      EXECUTION="${HOST_MPIRUN_COMMAND} -hostfile hosts"
1503
1504      # Initialisation
1505
1506      init_node=y
1507      node_num_current=0
1508      start_num=0
1509      init_exec=n
1510
1511      # Test : if oasis is there, we put it at the first position
1512
1513      for comp in ${config_ListOfComponents[*]} ; do
1514
1515        if [ "X${comp}" = "XCPL" ]  ; then
1516
1517          eval ExeNameIn=\${config_Executable_${comp}[0]}
1518          eval ExeNameOut=\${config_Executable_${comp}[1]}
1519
1520          echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1521          echo ""  >> script_${ExeNameOut}.ksh
1522          #echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
1523          #echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
1524          #echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
1525          echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err"  >> script_${ExeNameOut}.ksh
1526          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1527
1528          init_node=n
1529
1530          (( nombre_restant_node = NUM_COREPERNODE - 1 ))
1531          node_num_current=0
1532          node_current=${host[${node_num_current}]}
1533
1534          EXECUTION="${EXECUTION} -H ${node_current} -np 1 ./script_${ExeNameOut}.ksh"
1535
1536          init_exec=y
1537          start_num=1
1538
1539        fi
1540
1541      done
1542
1543      # Then loop on the components (except for oasis)
1544
1545      for comp in ${config_ListOfComponents[*]} ; do
1546
1547        eval ExeNameIn=\${config_Executable_${comp}[0]}
1548        eval ExeNameOut=\${config_Executable_${comp}[1]}
1549
1550        # Only if we really have an executable for the component :
1551        if ( [ "X${ExeNameOut}" != X\"\" ] &&  [ "X${comp}" != "XCPL" ] ) ; then
1552
1553          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1554          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1555
1556          echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1557          # echo "set -vx" >> script_${ExeNameOut}.ksh
1558          echo ""  >> script_${ExeNameOut}.ksh
1559          #echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
1560          #echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
1561          #echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
1562          echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
1563          echo "(( MYMPIRANK = OMPI_COMM_WORLD_RANK - ${start_num})) " >>  script_${ExeNameOut}.ksh
1564          echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${MYMPIRANK} 2>out_${ExeNameOut}.err.\${MYMPIRANK}"  >> script_${ExeNameOut}.ksh
1565          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1566
1567          node_num=0
1568
1569          # We define the number of MPI process to be assigned for the component
1570
1571          nombre_restant_comp=${comp_proc_mpi_loc}
1572
1573          # Loop on the allocated nodes
1574
1575          for node in ${listnodes} ; do
1576
1577            # We go to the current node
1578            if [ ${node_num} = ${node_num_current} ] ; then
1579
1580              node_current=${host[${node_num_current}]}
1581
1582              # If first time on the node : initialisation
1583
1584              if [ ${init_node} = y ] ; then
1585                nombre_restant_node=${NUM_COREPERNODE}
1586              fi
1587
1588              # Test on the number of OMP threads
1589
1590              if [ ${comp_proc_omp_loc} -gt ${nombre_restant_node} ] ; then
1591                (( node_num = node_num + 1 ))
1592                node_num_current=${node_num}
1593                init_node=y
1594                continue
1595              fi
1596
1597              # Number of MPI process to assign
1598
1599              (( num_corempi = nombre_restant_node / comp_proc_omp_loc ))
1600
1601              if [ ${num_corempi} -gt ${nombre_restant_comp} ] ; then
1602                num_corempi=${nombre_restant_comp}
1603              fi
1604
1605              (( nombre_restant_node = nombre_restant_node - num_corempi * comp_proc_omp_loc ))
1606              (( nombre_restant_comp = nombre_restant_comp - num_corempi ))
1607
1608              if [ ${init_exec} = y ] ; then
1609                EXECUTION="${EXECUTION} : -H ${node_current} -np ${num_corempi} ./script_${ExeNameOut}.ksh"
1610              else
1611                EXECUTION="${EXECUTION} -H ${node_current} -np ${num_corempi} ./script_${ExeNameOut}.ksh"
1612                init_exec=y
1613              fi
1614
1615              ((  start_num = num_corempi + start_num ))
1616
1617            else
1618
1619              (( node_num = node_num + 1 ))
1620              continue
1621            fi
1622
1623            # Test on the number of core/process remaining on the node/component
1624
1625            if [ ${nombre_restant_node} = 0 ] ; then
1626              (( node_num = node_num + 1 ))
1627              node_num_current=${node_num}
1628              init_node=y
1629
1630              if [ ${nombre_restant_comp} = 0 ] ; then
1631                break 1
1632              fi
1633            else
1634
1635              node_num_current=${node_num}
1636              init_node=n
1637
1638              if [ ${nombre_restant_comp} = 0 ] ; then
1639                break 1
1640              fi
1641            fi
1642          done
1643        fi
1644      done
1645
1646    else
1647
1648      # Then first loop on the components for the coupler ie oasis
1649
1650      ## the coupler ie oasis must be the first one
1651      for comp in ${config_ListOfComponents[*]} ; do
1652
1653        eval ExeNameOut=\${config_Executable_${comp}[1]}
1654
1655        # for CPL component only
1656        if [ "X${comp}" = "XCPL" ] ; then
1657          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1658          echo "-np ${comp_proc_mpi_loc} ./${ExeNameOut} " >> run_file
1659        fi
1660      done
1661
1662      # Then second loop on the components
1663
1664      for comp in ${config_ListOfComponents[*]} ; do
1665
1666        eval ExeNameOut=\${config_Executable_${comp}[1]}
1667
1668        # Only if we really have an executable for the component and not the coupler ie oasis:
1669        if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${comp}" != "XCPL" ] ) ; then
1670          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1671          echo "-np ${comp_proc_mpi_loc} ./${ExeNameOut}" >> run_file
1672        fi
1673      done
1674      IGCM_sys_Chmod u+x run_file
1675
1676      EXECUTION="${HOST_MPIRUN_COMMAND} --app ./run_file"
1677
1678    fi
1679
1680  else # Only one executable. launch it.
1681
1682    for comp in ${config_ListOfComponents[*]} ; do
1683
1684      # Only if we really have an executable for the component :
1685      eval ExeNameOut=\${config_Executable_${comp}[1]}
1686      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${ExeNameOut}" != "Xinca.dat" ] ) ; then
1687
1688        echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1689        echo ""  >> script_${ExeNameOut}.ksh
1690        if ( ${OK_PARA_OMP} ) ; then
1691          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1692          echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
1693        fi
1694        if  ( ${OK_PARA_MPI} ) ; then
1695          # Default : mpirun used if nb_proc gt 1
1696          # pour sortie out/err par process
1697          # echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${OMPI_COMM_WORLD_RANK} 2>out_${ExeNameOut}.err.\${OMPI_COMM_WORLD_RANK}"  >> script_${ExeNameOut}.ksh
1698          echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1699          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1700          EXECUTION="${HOST_MPIRUN_COMMAND} ./script_${ExeNameOut}.ksh"
1701        else
1702          # Default : mpirun is NOT used if nb_proc eq 1
1703          # pour sortie out/err par process
1704          # echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err" >> script_${ExeNameOut}.ksh
1705          echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1706          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1707          EXECUTION="time ./script_${ExeNameOut}.ksh"
1708        fi
1709      fi
1710    done
1711
1712  fi
1713
1714  IGCM_debug_Print 1 "sys $( hostname ) : La commande d execution est "
1715  IGCM_debug_Print 1 $EXECUTION
1716
1717  IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
1718}
1719
1720############################################################
1721# Check of space available on temporary filesytems
1722function IGCM_sys_check_quota {
1723  IGCM_debug_PushStack "IGCM_sys_check_quota"
1724  if ( $DEBUG_sys ) ; then
1725    echo "IGCM_sys_check_quota"
1726  fi
1727  IGCM_debug_PopStack "IGCM_sys_check_quota"
1728}
1729
1730##############################################################
1731# NCO OPERATOR
1732
1733function IGCM_sys_ncap2 {
1734  IGCM_debug_PushStack "IGCM_sys_ncap2" -- $@
1735  if ( $DEBUG_sys ) ; then
1736    echo "IGCM_sys_ncap2 :" $@
1737  fi
1738
1739  typeset NB_ESSAI DELAI status i
1740  # number of tentative
1741  NB_ESSAI=3
1742  # time delay between tentative
1743  DELAI=2
1744
1745  i=0
1746  while [ $i -lt $NB_ESSAI ] ; do
1747    ncap2 "$@" > out_rsync 2>&1
1748    status=$?
1749    if [ ${status} -gt 0 ] ; then
1750      IGCM_debug_Print 2 "IGCM_sys_ncap2 : error code ${status}"
1751      cat out_rsync
1752      \rm out_rsync
1753      IGCM_debug_Print 2 "IGCM_sys_ncap2 : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1754      sleep $DELAI
1755    else
1756      \rm out_rsync
1757      break
1758    fi
1759    (( i = i + 1 ))
1760  done
1761
1762  if [ ${status} -gt 0 ] ; then
1763      echo "IGCM_sys_ncap2 : ncap2 error"
1764      IGCM_debug_Exit "ncap2"
1765  fi
1766
1767  IGCM_debug_PopStack "IGCM_sys_ncap2"
1768}
1769
1770function IGCM_sys_ncatted {
1771  IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
1772  if ( $DEBUG_sys ) ; then
1773    echo "IGCM_sys_ncatted :" $@
1774  fi
1775
1776  typeset NB_ESSAI DELAI status i
1777  # number of tentative
1778  NB_ESSAI=3
1779  # time delay between tentative
1780  DELAI=2
1781
1782  i=0
1783  while [ $i -lt $NB_ESSAI ] ; do
1784    ncatted "$@" > out_rsync 2>&1
1785    status=$?
1786    if [ ${status} -gt 0 ] ; then
1787      IGCM_debug_Print 2 "IGCM_sys_ncatted : error code ${status}"
1788      cat out_rsync
1789      \rm out_rsync
1790      IGCM_debug_Print 2 "IGCM_sys_ncatted : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1791      sleep $DELAI
1792    else
1793      \rm out_rsync
1794      break
1795    fi
1796    (( i = i + 1 ))
1797  done
1798
1799  if [ ${status} -gt 0 ] ; then
1800      echo "IGCM_sys_ncatted : ncatted error"
1801      IGCM_debug_Exit "ncatted"
1802  fi
1803
1804  IGCM_debug_PopStack "IGCM_sys_ncatted"
1805}
1806
1807function IGCM_sys_ncbo {
1808  IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
1809  if ( $DEBUG_sys ) ; then
1810    echo "IGCM_sys_ncbo :" $@
1811  fi
1812
1813  typeset NB_ESSAI DELAI status i
1814  # number of tentative
1815  NB_ESSAI=3
1816  # time delay between tentative
1817  DELAI=2
1818
1819  i=0
1820  while [ $i -lt $NB_ESSAI ] ; do
1821    ncbo $@ > out_rsync 2>&1
1822    status=$?
1823    if [ ${status} -gt 0 ] ; then
1824      IGCM_debug_Print 2 "IGCM_sys_ncbo : error code ${status}"
1825      cat out_rsync
1826      \rm out_rsync
1827      IGCM_debug_Print 2 "IGCM_sys_ncbo : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1828      sleep $DELAI
1829    else
1830      \rm out_rsync
1831      break
1832    fi
1833    (( i = i + 1 ))
1834  done
1835
1836  if [ ${status} -gt 0 ] ; then
1837      echo "IGCM_sys_ncbo : ncbo error"
1838      IGCM_debug_Exit "ncbo"
1839  fi
1840
1841  IGCM_debug_PopStack "IGCM_sys_ncbo"
1842}
1843
1844function IGCM_sys_ncdiff {
1845  IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
1846  if ( $DEBUG_sys ) ; then
1847    echo "IGCM_sys_ncdiff :" $@
1848  fi
1849
1850  typeset NB_ESSAI DELAI status i
1851  # number of tentative
1852  NB_ESSAI=3
1853  # time delay between tentative
1854  DELAI=2
1855
1856  i=0
1857  while [ $i -lt $NB_ESSAI ] ; do
1858    ncdiff $@ > out_rsync 2>&1
1859    status=$?
1860    if [ ${status} -gt 0 ] ; then
1861      IGCM_debug_Print 2 "IGCM_sys_ncdiff : error code ${status}"
1862      cat out_rsync
1863      \rm out_rsync
1864      IGCM_debug_Print 2 "IGCM_sys_ncdiff : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1865      sleep $DELAI
1866    else
1867      \rm out_rsync
1868      break
1869    fi
1870    (( i = i + 1 ))
1871  done
1872
1873  if [ ${status} -gt 0 ] ; then
1874      echo "IGCM_sys_ncdiff : ncdiff error"
1875      IGCM_debug_Exit "ncdiff"
1876  fi
1877
1878  IGCM_debug_PopStack "IGCM_sys_ncdiff"
1879}
1880
1881function IGCM_sys_ncea {
1882  IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
1883  if ( $DEBUG_sys ) ; then
1884    echo "IGCM_sys_ncea :" $@
1885  fi
1886
1887  typeset NB_ESSAI DELAI status i
1888  # number of tentative
1889  NB_ESSAI=3
1890  # time delay between tentative
1891  DELAI=2
1892
1893  i=0
1894  while [ $i -lt $NB_ESSAI ] ; do
1895    ncea $@ > out_rsync 2>&1
1896    status=$?
1897    if [ ${status} -gt 0 ] ; then
1898      IGCM_debug_Print 2 "IGCM_sys_ncea : error code ${status}"
1899      cat out_rsync
1900      \rm out_rsync
1901      IGCM_debug_Print 2 "IGCM_sys_ncea : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1902      sleep $DELAI
1903    else
1904      \rm out_rsync
1905      break
1906    fi
1907    (( i = i + 1 ))
1908  done
1909
1910  if [ ${status} -gt 0 ] ; then
1911      echo "IGCM_sys_ncea : ncea error"
1912      IGCM_debug_Exit "ncea"
1913  fi
1914
1915  IGCM_debug_PopStack "IGCM_sys_ncea"
1916}
1917
1918function IGCM_sys_ncecat {
1919  IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
1920  if ( $DEBUG_sys ) ; then
1921    echo "IGCM_sys_ncecat :" $@
1922  fi
1923
1924  typeset NB_ESSAI DELAI status i
1925  # number of tentative
1926  NB_ESSAI=3
1927  # time delay between tentative
1928  DELAI=2
1929
1930  i=0
1931  while [ $i -lt $NB_ESSAI ] ; do
1932    ncecat $@ > out_rsync 2>&1
1933    status=$?
1934    if [ ${status} -gt 0 ] ; then
1935      IGCM_debug_Print 2 "IGCM_sys_ncecat : error code ${status}"
1936      cat out_rsync
1937      \rm out_rsync
1938      IGCM_debug_Print 2 "IGCM_sys_ncecat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1939      sleep $DELAI
1940    else
1941      \rm out_rsync
1942      break
1943    fi
1944    (( i = i + 1 ))
1945  done
1946
1947  if [ ${status} -gt 0 ] ; then
1948      echo "IGCM_sys_ncecat : ncecat error"
1949      IGCM_debug_Exit "ncecat"
1950  fi
1951
1952  IGCM_debug_PopStack "IGCM_sys_ncecat"
1953}
1954
1955function IGCM_sys_ncflint {
1956  IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
1957  if ( $DEBUG_sys ) ; then
1958    echo "IGCM_sys_ncflint :" $@
1959  fi
1960
1961  typeset NB_ESSAI DELAI status i
1962  # number of tentative
1963  NB_ESSAI=3
1964  # time delay between tentative
1965  DELAI=2
1966
1967  i=0
1968  while [ $i -lt $NB_ESSAI ] ; do
1969    ncflint $@ > out_rsync 2>&1
1970    status=$?
1971    if [ ${status} -gt 0 ] ; then
1972      IGCM_debug_Print 2 "IGCM_sys_ncflint : error code ${status}"
1973      cat out_rsync
1974      \rm out_rsync
1975      IGCM_debug_Print 2 "IGCM_sys_ncflint : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1976      sleep $DELAI
1977    else
1978      \rm out_rsync
1979      break
1980    fi
1981    (( i = i + 1 ))
1982  done
1983
1984  if [ ${status} -gt 0 ] ; then
1985      echo "IGCM_sys_ncflint : ncflint error"
1986      IGCM_debug_Exit "ncflint"
1987  fi
1988
1989  IGCM_debug_PopStack "IGCM_sys_ncflint"
1990}
1991
1992function IGCM_sys_ncks {
1993  IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
1994  if ( $DEBUG_sys ) ; then
1995    echo "IGCM_sys_ncks :" $@
1996  fi
1997
1998  typeset NB_ESSAI DELAI status i
1999  # number of tentative
2000  NB_ESSAI=3
2001  # time delay between tentative
2002  DELAI=2
2003
2004  i=0
2005  while [ $i -lt $NB_ESSAI ] ; do
2006    ncks $@ > out_rsync 2>&1
2007    status=$?
2008    if [ ${status} -gt 0 ] ; then
2009      IGCM_debug_Print 2 "IGCM_sys_ncks : error code ${status}"
2010      cat out_rsync
2011      \rm out_rsync
2012      IGCM_debug_Print 2 "IGCM_sys_ncks : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2013      sleep $DELAI
2014    else
2015      \rm out_rsync
2016      break
2017    fi
2018    (( i = i + 1 ))
2019  done
2020
2021  if [ ${status} -gt 0 ] ; then
2022      echo "IGCM_sys_ncks : ncks error"
2023      IGCM_debug_Exit "ncks"
2024  fi
2025
2026  IGCM_debug_PopStack "IGCM_sys_ncks"
2027}
2028
2029function IGCM_sys_ncpdq {
2030  IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
2031  if ( $DEBUG_sys ) ; then
2032    echo "IGCM_sys_ncpdq :" $@
2033  fi
2034
2035  typeset NB_ESSAI DELAI status i
2036  # number of tentative
2037  NB_ESSAI=3
2038  # time delay between tentative
2039  DELAI=2
2040
2041  i=0
2042  while [ $i -lt $NB_ESSAI ] ; do
2043    ncpdq $@ > out_rsync 2>&1
2044    status=$?
2045    if [ ${status} -gt 0 ] ; then
2046      IGCM_debug_Print 2 "IGCM_sys_ncpdq : error code ${status}"
2047      cat out_rsync
2048      \rm out_rsync
2049      IGCM_debug_Print 2 "IGCM_sys_ncpdq : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2050      sleep $DELAI
2051    else
2052      \rm out_rsync
2053      break
2054    fi
2055    (( i = i + 1 ))
2056  done
2057
2058  if [ ${status} -gt 0 ] ; then
2059      echo "IGCM_sys_ncpdq : ncpdq error"
2060      IGCM_debug_Exit "ncpdq"
2061  fi
2062
2063  IGCM_debug_PopStack "IGCM_sys_ncpdq"
2064}
2065
2066function IGCM_sys_ncra {
2067  IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
2068  if ( $DEBUG_sys ) ; then
2069    echo "IGCM_sys_ncra :" $@
2070  fi
2071
2072  typeset NB_ESSAI DELAI status i
2073  # number of tentative
2074  NB_ESSAI=3
2075  # time delay between tentative
2076  DELAI=2
2077
2078  i=0
2079  while [ $i -lt $NB_ESSAI ] ; do
2080    ncra $@ > out_rsync 2>&1
2081    status=$?
2082    if [ ${status} -gt 0 ] ; then
2083      IGCM_debug_Print 2 "IGCM_sys_ncra : error code ${status}"
2084      cat out_rsync
2085      \rm out_rsync
2086      IGCM_debug_Print 2 "IGCM_sys_ncra : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2087      sleep $DELAI
2088    else
2089      \rm out_rsync
2090      break
2091    fi
2092    (( i = i + 1 ))
2093  done
2094
2095  if [ ${status} -gt 0 ] ; then
2096      echo "IGCM_sys_ncra : ncra error"
2097      IGCM_debug_Exit "ncra"
2098  fi
2099
2100  IGCM_debug_PopStack "IGCM_sys_ncra"
2101}
2102
2103function IGCM_sys_ncrcat {
2104  IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
2105  if ( $DEBUG_sys ) ; then
2106    echo "IGCM_sys_ncrcat :" $@
2107  fi
2108
2109  typeset NB_ESSAI DELAI status i
2110  # number of tentative
2111  NB_ESSAI=3
2112  # time delay between tentative
2113  DELAI=2
2114
2115  i=0
2116  while [ $i -lt $NB_ESSAI ] ; do
2117    ncrcat $@ > out_rsync 2>&1
2118    status=$?
2119    if [ ${status} -gt 0 ] ; then
2120      IGCM_debug_Print 2 "IGCM_sys_ncrcat : error code ${status}"
2121      cat out_rsync
2122      \rm out_rsync
2123      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2124      sleep $DELAI
2125    else
2126      \rm out_rsync
2127      break
2128    fi
2129    (( i = i + 1 ))
2130  done
2131
2132  if [ ${status} -gt 0 ] ; then
2133      echo "IGCM_sys_ncrcat : ncrcat error"
2134      #IGCM_debug_Exit "ncrcat"
2135  fi
2136
2137  IGCM_debug_PopStack "IGCM_sys_ncrcat"
2138}
2139
2140function IGCM_sys_ncrename {
2141  IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
2142  if ( $DEBUG_sys ) ; then
2143    echo "IGCM_sys_ncrename :" $@
2144  fi
2145
2146  typeset NB_ESSAI DELAI status i
2147  # number of tentative
2148  NB_ESSAI=3
2149  # time delay between tentative
2150  DELAI=2
2151
2152  i=0
2153  while [ $i -lt $NB_ESSAI ] ; do
2154    ncrename $@ > out_rsync 2>&1
2155    status=$?
2156    if [ ${status} -gt 0 ] ; then
2157      IGCM_debug_Print 2 "IGCM_sys_ncrename : error code ${status}"
2158      cat out_rsync
2159      \rm out_rsync
2160      IGCM_debug_Print 2 "IGCM_sys_ncrename : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2161      sleep $DELAI
2162    else
2163      \rm out_rsync
2164      break
2165    fi
2166    (( i = i + 1 ))
2167  done
2168
2169  if [ ${status} -gt 0 ] ; then
2170      echo "IGCM_sys_ncrename : ncrename error"
2171      IGCM_debug_Exit "ncrename"
2172  fi
2173
2174  IGCM_debug_PopStack "IGCM_sys_ncrename"
2175}
2176
2177function IGCM_sys_ncwa {
2178  IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
2179  if ( $DEBUG_sys ) ; then
2180    echo "IGCM_sys_ncwa :" $@
2181  fi
2182
2183  typeset NB_ESSAI DELAI status i
2184  # number of tentative
2185  NB_ESSAI=3
2186  # time delay between tentative
2187  DELAI=2
2188
2189  i=0
2190  while [ $i -lt $NB_ESSAI ] ; do
2191    ncwa $@ > out_rsync 2>&1
2192    status=$?
2193    if [ ${status} -gt 0 ] ; then
2194      IGCM_debug_Print 2 "IGCM_sys_ncwa : error code ${status}"
2195      cat out_rsync
2196      \rm out_rsync
2197      IGCM_debug_Print 2 "IGCM_sys_ncwa : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2198      sleep $DELAI
2199    else
2200      \rm out_rsync
2201      break
2202    fi
2203    (( i = i + 1 ))
2204  done
2205
2206  if [ ${status} -gt 0 ] ; then
2207      echo "IGCM_sys_ncwa : ncwa error"
2208      IGCM_debug_Exit "ncwa"
2209  fi
2210
2211  IGCM_debug_PopStack "IGCM_sys_ncwa"
2212}
2213
2214##############################################################
2215# CDO OPERATOR
2216
2217function IGCM_sys_cdo {
2218  IGCM_debug_PushStack "IGCM_sys_cdo" -- $@
2219  if ( $DEBUG_sys ) ; then
2220    echo "IGCM_sys_cdo :" $@
2221  fi
2222
2223  typeset status
2224
2225  \cdo $@ > out_rsync 2>&1
2226  status=$?
2227  if [ ${status} -gt 0 ] ; then
2228    echo "IGCM_sys_cdo : error code ${status}"
2229    cat out_rsync
2230    \rm out_rsync
2231    IGCM_debug_PopStack "IGCM_sys_cdo"
2232    return 1
2233  else
2234    IGCM_debug_PopStack "IGCM_sys_cdo"
2235    return 0
2236  fi
2237
2238  IGCM_debug_PopStack "IGCM_sys_cdo"
2239}
Note: See TracBrowser for help on using the repository browser.