source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_obelix.ksh @ 1179

Last change on this file since 1179 was 1179, checked in by sdipsl, 9 years ago

house keeping in libIGCM_sys (second pass). Will ease #248 and #251

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