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

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