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

Last change on this file since 1138 was 1131, checked in by sdipsl, 10 years ago
  • Bugfix Ada to avoid collision (permission denied getting file) between users on the front-end.
  • Add a missing function on Obelix
  • 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: 74.6 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_rebuild
1472#D-* Purpose: rebuild parallel files
1473#D-* Examples:
1474#D-
1475function IGCM_sys_rebuild {
1476  IGCM_debug_PushStack "IGCM_sys_rebuild" $@
1477  if ( $DEBUG_sys ) ; then
1478    echo "IGCM_sys_rebuild :" $@
1479  fi
1480
1481  typeset NB_ESSAI DELAI status i firstArg
1482  # number of tentative
1483  NB_ESSAI=3
1484  # time delay between tentative
1485  DELAI=2
1486
1487  i=0
1488  while [ $i -lt $NB_ESSAI ] ; do
1489    /home/users/igcmg/rebuild/bin/rebuild -f -o $@ > /tmp/out_command_${LOGIN}.$$ 2>&1
1490    status=$?
1491    if [ ${status} -gt 0 ] ; then
1492      IGCM_debug_Print 2 "IGCM_sys_rebuild : error code ${status}"
1493      cat /tmp/out_command_${LOGIN}.$$
1494      \rm /tmp/out_command_${LOGIN}.$$
1495      IGCM_debug_Print 2 "IGCM_sys_rebuild : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1496      firstArg=${1}
1497      \rm ${firstArg}
1498      sleep $DELAI
1499    else
1500      \rm /tmp/out_command_${LOGIN}.$$
1501      break
1502    fi
1503    (( i = i + 1 ))
1504  done
1505
1506  if [ ${status} -gt 0 ] ; then
1507    echo "IGCM_sys_rebuild : rebuild error code is ${status}"
1508    IGCM_debug_Exit "rebuild"
1509  fi
1510
1511  IGCM_debug_PopStack "IGCM_sys_rebuild"
1512}
1513
1514#D-#==================================================
1515#D-function IGCM_sys_rebuild_station
1516#D-* Purpose: rebuild parallel files describing station
1517#D-* Examples:
1518#D-
1519function IGCM_sys_rebuild_station {
1520  IGCM_debug_PushStack "IGCM_sys_rebuild_station" $@
1521  typeset i list_opt file_in file_out prefix_invert list_invert
1522  if ( $DEBUG_sys ) ; then
1523    echo "IGCM_sys_rebuild_station :" $@
1524  fi
1525  list_opt=$@
1526
1527  # Invert Axis : t,x -> x,t
1528  #               t,pres,x -> x,t,pres
1529  # So that we can concatenate along x
1530  i=0
1531  for file_in in ${list_opt} ; do
1532    (( i = i + 1))
1533    [ ${i} = 1 ] && file_out=${file_in} && continue
1534    # detect time counter and do the job only if present
1535    var_unlim=$(ncdump -h ${file_in} | grep UNLIMITED | cut -d ' ' -f 1)
1536    if [ X${var_unlim} = Xtime_counter ] ; then
1537      prefix_invert=$( basename ${file_in} .nc )
1538      IGCM_sys_ncpdq -a x,time_counter -a x,time_counter,presnivs ${file_in} ${prefix_invert}_xt.nc
1539      list_invert[${#list_invert[*]}]=${prefix_invert}_xt.nc
1540    fi
1541  done
1542
1543  # Concatenate
1544  IGCM_sys_ncrcat ${list_invert[*]} histstn_xt.nc
1545
1546  # Re-ivert file
1547  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x histstn_xt.nc ${file_out}
1548
1549  # Station re-ordering is too expansive to be run within libIGCM
1550  # This is due to (ncpdq - nrcat - ncpdq) I/O sequence.
1551  # This re-ordering must be done "in memory" by the cmorization process
1552  # Anyway this is the best sequence using (ncpdq - nrcat - ncpdq)
1553  # BEGIN reordering
1554
1555  # Only LMDZ text output contains the exact ordering of the station.
1556  # We isolate this in the code below:
1557  #  0  38  -157.5000000000000  70.98591549295774
1558  #  0  54  27.49999999999999   67.18309859154928
1559  #  0  56  -62.50000000000001  82.39436619718309
1560  #  0  79  12.49999999999999   78.59154929577466
1561  #  0  116 -165.0000000000000  76.05633802816901
1562  #  0  117 130.0000000000000   70.98591549295774
1563  #  0  118 110.0000000000000   87.46478873239437
1564  #  1  40  4.999999999999995   51.97183098591550
1565#  typeset iStation iProc list_opt file_in file_out prefix_invert
1566#  typeset -Z4 j4
1567#  typeset -Z3 j3
1568
1569#  unset list_opt
1570#  set +A list_opt $@
1571
1572  # Filename after rebuild
1573#  file_out=${list_opt[0]}
1574  # Prefix of output files
1575#  prefix_invert=$( basename ${file_out} .nc )
1576  # Number of procs
1577#  num_proc=$( grep -i mpi_size ${PREFIX}_${Exe_Output} | wc -l )
1578
1579#  iProc=0
1580#  while [ ${iProc} -lt ${num_proc} ] ; do
1581    # Array containing Station as a number
1582#    unset proc_stn
1583#    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}' )
1584    # Number of stations produced by processor proc
1585#    stationLast=${#proc_stn[*]}
1586    # Proc number on 4 digits
1587#    j4=${iProc}
1588    # Init
1589#    iStation=0
1590#    while [ ${iStation} -lt ${stationLast} ] ; do
1591      # Station number on 3 digits
1592#      j3=${proc_stn[${iStation}]}
1593      # Extract station
1594      # Invert Axis : t,x -> x,t
1595      #               t,pres,x -> x,t,pres
1596      # So that we can concatenate along x
1597#      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
1598#      (( iStation = iStation + 1 ))
1599#    done
1600#    (( iProc = iProc + 1 ))
1601#  done
1602
1603  # Concatenate all station along x
1604#  IGCM_sys_ncrcat ${prefix_invert}_stn_???.nc ${prefix_invert}_xt.nc
1605
1606  # Re-invert file
1607#  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x ${prefix_invert}_xt.nc ${file_out}
1608
1609  # END reordering
1610
1611  IGCM_debug_PopStack "IGCM_sys_rebuild_station"
1612}
1613
1614############################################################
1615# Activate Running Environnment Variables
1616
1617#D-#==================================================
1618#D-function IGCM_sys_desactiv_variables
1619#D-* Purpose: set environement variables prior to execution
1620#D-* Examples:
1621#D-
1622function IGCM_sys_activ_variables {
1623  IGCM_debug_PushStack "IGCM_sys_activ_variables"
1624  if ( $DEBUG_sys ) ; then
1625    echo "IGCM_sys_activ_variables"
1626  fi
1627
1628# --------------------------------------------------------------------
1629#D- MPI specifications
1630# --------------------------------------------------------------------
1631
1632# --------------------------------------------------------------------
1633#D- Other specifications
1634# --------------------------------------------------------------------
1635
1636  IGCM_debug_PopStack "IGCM_sys_activ_variables"
1637}
1638
1639############################################################
1640# Desactivate Running Environnment Variables
1641
1642#D-#==================================================
1643#D-function IGCM_sys_desactiv_variables
1644#D-* Purpose: unset environement variables after execution
1645#D-* Examples:
1646#D-
1647function IGCM_sys_desactiv_variables {
1648  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1649  if ( $DEBUG_sys ) ; then
1650    echo "IGCM_sys_desactiv_variables"
1651  fi
1652# --------------------------------------------------------------------
1653#D- MPI specifications
1654# --------------------------------------------------------------------
1655
1656# --------------------------------------------------------------------
1657#D- Other specifications
1658# --------------------------------------------------------------------
1659
1660  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1661}
1662
1663############################################################
1664# Build MPI/OMP scripts run file (dummy function)
1665
1666#D-#==================================================
1667#D-function IGCM_sys_build_run_file
1668#D-* Purpose: build run file (deprecated)
1669#D-* Examples:
1670#D-
1671function IGCM_sys_build_run_file {
1672
1673  IGCM_debug_Print 3 " dummy function : IGCM_sys_build_run_file "
1674
1675}
1676
1677############################################################
1678# Build MPI/OMP scripts
1679
1680#D-#==================================================
1681#D-function IGCM_sys_build_execution_scripts
1682#D-* Purpose: build execution scripts to be launch by ${HOST_MPIRUN_COMMAND}
1683#D-* Examples:
1684#D-
1685function IGCM_sys_build_execution_scripts
1686{
1687  IGCM_debug_PushStack "IGCM_sys_build_execution_scripts" $@
1688  if ( $DEBUG_sys ) ; then
1689    echo "IGCM_sys_build_execution_scripts " $@
1690  fi
1691  typeset nodes listnodes init_node start_num init_exec comp ExeNameIn ExeNameOut
1692  typeset node_num_current node_current comp_proc_mpi_loc comp_proc_omp_loc
1693  typeset num_corempi nombre_restant_node nombre_restant_comp
1694
1695  if [ ! -f ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} ]  ; then
1696    IGCM_debug_Exit "IGCM_sys_obelix build_execution_scripts : Job_${config_UserChoices_JobName} don't exist in SUBMIT_DIR : ${SUBMIT_DIR} "
1697  fi
1698
1699  if ( ${OK_PARA_MPMD} ) ; then
1700
1701    if [ -f run_file ] ; then
1702      IGCM_sys_Rm -f run_file
1703    fi
1704    touch run_file
1705
1706    if ( ${OK_PARA_OMP} ) ; then
1707
1708      #  Hosts treatment
1709
1710      ${HOST_MPIRUN_COMMAND} hostname | sort | uniq > hosts.tmp
1711
1712      i=0
1713      rm -f hosts
1714      IGCM_debug_Print 1 "sys Obelix, Hosts avaible :"
1715      for nodes in `cat hosts.tmp` ; do
1716        host[$i]=$nodes
1717        echo "${host[$i]} slots=1 max_slots=1" >> hosts
1718        IGCM_debug_Print 1 ${host[$i]}
1719        i=$((i+1))
1720      done
1721      rm -f hosts.tmp
1722
1723      listnodes=${host[*]}
1724
1725      EXECUTION="${HOST_MPIRUN_COMMAND} -hostfile hosts"
1726
1727      # Initialisation
1728
1729      init_node=y
1730      node_num_current=0
1731      start_num=0
1732      init_exec=n
1733
1734      # Test : if oasis is there, we put it at the first position
1735
1736      for comp in ${config_ListOfComponents[*]} ; do
1737
1738        if [ "X${comp}" = "XCPL" ]  ; then
1739
1740          eval ExeNameIn=\${config_Executable_${comp}[0]}
1741          eval ExeNameOut=\${config_Executable_${comp}[1]}
1742
1743          echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1744          echo ""  >> script_${ExeNameOut}.ksh
1745          #echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
1746          #echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
1747          #echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
1748          echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err"  >> script_${ExeNameOut}.ksh
1749          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1750
1751          init_node=n
1752
1753          (( nombre_restant_node = NUM_COREPERNODE - 1 ))
1754          node_num_current=0
1755          node_current=${host[${node_num_current}]}
1756
1757          EXECUTION="${EXECUTION} -H ${node_current} -np 1 ./script_${ExeNameOut}.ksh"
1758
1759          init_exec=y
1760          start_num=1
1761
1762        fi
1763
1764      done
1765
1766      # Then loop on the components (except for oasis)
1767
1768      for comp in ${config_ListOfComponents[*]} ; do
1769
1770        eval ExeNameIn=\${config_Executable_${comp}[0]}
1771        eval ExeNameOut=\${config_Executable_${comp}[1]}
1772
1773        # Only if we really have an executable for the component :
1774        if ( [ "X${ExeNameOut}" != X\"\" ] &&  [ "X${comp}" != "XCPL" ] ) ; then
1775
1776          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1777          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1778
1779          echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1780          # echo "set -vx" >> script_${ExeNameOut}.ksh
1781          echo ""  >> script_${ExeNameOut}.ksh
1782          #echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
1783          #echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
1784          #echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
1785          echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
1786          echo "(( MYMPIRANK = OMPI_COMM_WORLD_RANK - ${start_num})) " >>  script_${ExeNameOut}.ksh
1787          echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${MYMPIRANK} 2>out_${ExeNameOut}.err.\${MYMPIRANK}"  >> script_${ExeNameOut}.ksh
1788          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1789
1790          node_num=0
1791
1792          # We define the number of MPI process to be assigned for the component
1793
1794          nombre_restant_comp=${comp_proc_mpi_loc}
1795
1796          # Loop on the allocated nodes
1797
1798          for node in ${listnodes} ; do
1799
1800            # We go to the current node
1801            if [ ${node_num} = ${node_num_current} ] ; then
1802
1803              node_current=${host[${node_num_current}]}
1804
1805              # If first time on the node : initialisation
1806
1807              if [ ${init_node} = y ] ; then
1808                nombre_restant_node=${NUM_COREPERNODE}
1809              fi
1810
1811              # Test on the number of OMP threads
1812
1813              if [ ${comp_proc_omp_loc} -gt ${nombre_restant_node} ] ; then
1814                (( node_num = node_num + 1 ))
1815                node_num_current=${node_num}
1816                init_node=y
1817                continue
1818              fi
1819
1820              # Number of MPI process to assign
1821
1822              (( num_corempi = nombre_restant_node / comp_proc_omp_loc ))
1823
1824              if [ ${num_corempi} -gt ${nombre_restant_comp} ] ; then
1825                num_corempi=${nombre_restant_comp}
1826              fi
1827
1828              (( nombre_restant_node = nombre_restant_node - num_corempi * comp_proc_omp_loc ))
1829              (( nombre_restant_comp = nombre_restant_comp - num_corempi ))
1830
1831              if [ ${init_exec} = y ] ; then
1832                EXECUTION="${EXECUTION} : -H ${node_current} -np ${num_corempi} ./script_${ExeNameOut}.ksh"
1833              else
1834                EXECUTION="${EXECUTION} -H ${node_current} -np ${num_corempi} ./script_${ExeNameOut}.ksh"
1835                init_exec=y
1836              fi
1837
1838              ((  start_num = num_corempi + start_num ))
1839
1840            else
1841
1842              (( node_num = node_num + 1 ))
1843              continue
1844            fi
1845
1846            # Test on the number of core/process remaining on the node/component
1847
1848            if [ ${nombre_restant_node} = 0 ] ; then
1849              (( node_num = node_num + 1 ))
1850              node_num_current=${node_num}
1851              init_node=y
1852
1853              if [ ${nombre_restant_comp} = 0 ] ; then
1854                break 1
1855              fi
1856            else
1857
1858              node_num_current=${node_num}
1859              init_node=n
1860
1861              if [ ${nombre_restant_comp} = 0 ] ; then
1862                break 1
1863              fi
1864            fi
1865          done
1866        fi
1867      done
1868
1869    else
1870
1871      # Then first loop on the components for the coupler ie oasis
1872
1873      ## the coupler ie oasis must be the first one
1874      for comp in ${config_ListOfComponents[*]} ; do
1875
1876        eval ExeNameOut=\${config_Executable_${comp}[1]}
1877
1878        # for CPL component only
1879        if [ "X${comp}" = "XCPL" ] ; then
1880          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1881          echo "-np ${comp_proc_mpi_loc} ./${ExeNameOut} " >> run_file
1882        fi
1883      done
1884
1885      # Then second loop on the components
1886
1887      for comp in ${config_ListOfComponents[*]} ; do
1888
1889        eval ExeNameOut=\${config_Executable_${comp}[1]}
1890
1891        # Only if we really have an executable for the component and not the coupler ie oasis:
1892        if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${comp}" != "XCPL" ] ) ; then
1893          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1894          echo "-np ${comp_proc_mpi_loc} ./${ExeNameOut}" >> run_file
1895        fi
1896      done
1897      IGCM_sys_Chmod u+x run_file
1898
1899      EXECUTION="${HOST_MPIRUN_COMMAND} --app ./run_file"
1900
1901    fi
1902
1903  else # Only one executable. launch it.
1904
1905    for comp in ${config_ListOfComponents[*]} ; do
1906
1907      # Only if we really have an executable for the component :
1908      eval ExeNameOut=\${config_Executable_${comp}[1]}
1909      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${ExeNameOut}" != "Xinca.dat" ] ) ; then
1910
1911        echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1912        echo ""  >> script_${ExeNameOut}.ksh
1913        if ( ${OK_PARA_OMP} ) ; then
1914          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1915          echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
1916        fi
1917        if  ( ${OK_PARA_MPI} ) ; then
1918          # Default : mpirun used if nb_proc gt 1
1919          # pour sortie out/err par process
1920          # echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${OMPI_COMM_WORLD_RANK} 2>out_${ExeNameOut}.err.\${OMPI_COMM_WORLD_RANK}"  >> script_${ExeNameOut}.ksh
1921          echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1922          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1923          EXECUTION="${HOST_MPIRUN_COMMAND} ./script_${ExeNameOut}.ksh"
1924        else
1925          # Default : mpirun is NOT used if nb_proc eq 1
1926          # pour sortie out/err par process
1927          # echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err" >> script_${ExeNameOut}.ksh
1928          echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1929          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1930          EXECUTION="time ./script_${ExeNameOut}.ksh"
1931        fi
1932
1933        IGCM_debug_Print 1 "sys Obelix : script_${ExeNameOut}.ksh contains"
1934        cat script_${ExeNameOut}.ksh
1935
1936      fi
1937    done
1938
1939  fi
1940
1941  IGCM_debug_Print 1 "sys Obelix : execution command is"
1942  IGCM_debug_Print 1 "$EXECUTION"
1943
1944  IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
1945}
1946
1947#D-#==================================================
1948#D-function IGCM_sys_check_path
1949#D-* Purpose: check that RUN_DIR_PATH that will be removed on some machine
1950#D-* do not point to an important use directory. Stop immediately in that case.
1951#D-* Examples:
1952#D-
1953function IGCM_sys_check_path {
1954  IGCM_debug_PushStack "IGCM_sys_check_path"
1955  if ( $DEBUG_sys ) ; then
1956    echo "IGCM_sys_check_path"
1957  fi
1958
1959  if ( [ X${RUN_DIR_PATH} = X${HOME} ] || [ X${RUN_DIR_PATH} = X${ARCHIVE} ] ) ; then
1960    IGCM_debug_Print 1 "Variable RUN_DIR_PATH is pointing to an important directory : ${RUN_DIR_PATH}"
1961    IGCM_debug_Print 1 "Please check the RUN_DIR_PATH definition in your Job : Job_${config_UserChoices_JobName}"
1962    IGCM_debug_Exit "This will stop the job"
1963  fi
1964  IGCM_debug_PopStack "IGCM_sys_check_path"
1965}
1966
1967#D-#==================================================
1968#D-function IGCM_sys_check_quota. Dummy call here
1969#D-* Purpose: check user quota. Stop the simulation if quota above 90%
1970#D-* Examples:
1971#D-
1972function IGCM_sys_check_quota {
1973  IGCM_debug_PushStack "IGCM_sys_check_quota"
1974  if ( $DEBUG_sys ) ; then
1975    echo "IGCM_sys_check_quota"
1976  fi
1977  IGCM_debug_PopStack "IGCM_sys_check_quota"
1978}
1979
1980#D-#==================================================
1981#D-function IGCM_sys_GetJobID
1982#D-* Purpose: Check if job_name is currently
1983#D-  running or in queue
1984#D-* Examples: IGCM_sys_GetJobID ${JobName} ${TargetUsr} JobID
1985#D-
1986function IGCM_sys_GetJobID {
1987  IGCM_debug_PushStack "IGCM_sys_GetJobID"
1988  if ( $DEBUG_sys ) ; then
1989    echo "IGCM_sys_GetJobID"
1990  fi
1991
1992  # With -f option, the full job name is given in the last column
1993   ID="$( qstat -u $2 | grep -w $1 | gawk '-F ' '{print $10}' )"
1994
1995  eval ${3}=${ID}
1996  IGCM_debug_PopStack "IGCM_sys_GetJobID"
1997}
1998
1999#D-#==================================================
2000#D-function IGCM_sys_CountJobInQueue
2001#D-* Purpose: Check if job_name is currently
2002#D-  running or in queue
2003#D-* Examples: IGCM_sys_CountJobInQueue ${JobName} NbRun
2004#D-
2005function IGCM_sys_CountJobInQueue {
2006  IGCM_debug_PushStack "IGCM_sys_CountJobInQueue"
2007  if ( $DEBUG_sys ) ; then
2008    echo "IGCM_sys_CountJobInQueue"
2009  fi
2010  IGCM_debug_PopStack "IGCM_sys_CountJobInQueue"
2011}
2012
2013##############################################################
2014# NCO OPERATOR
2015
2016#D-#==================================================
2017#D-function IGCM_sys_ncap2
2018#D-* Purpose: encapsulate ncap2 call so as to manage error code and retry
2019#D-* Examples:
2020#D-
2021function IGCM_sys_ncap2 {
2022  IGCM_debug_PushStack "IGCM_sys_ncap2" $@
2023  if ( $DEBUG_sys ) ; then
2024    echo "IGCM_sys_ncap2 :" $@
2025  fi
2026
2027  typeset NB_ESSAI DELAI status i
2028  # number of tentative
2029  NB_ESSAI=3
2030  # time delay between tentative
2031  DELAI=2
2032
2033  i=0
2034  while [ $i -lt $NB_ESSAI ] ; do
2035    ncap2 -C "$@" > /tmp/out_command_${LOGIN}.$$ 2>&1
2036    status=$?
2037    if [ ${status} -gt 0 ] ; then
2038      IGCM_debug_Print 2 "IGCM_sys_ncap2 : error code ${status}"
2039      cat /tmp/out_command_${LOGIN}.$$
2040      \rm /tmp/out_command_${LOGIN}.$$
2041      IGCM_debug_Print 2 "IGCM_sys_ncap2 : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2042      sleep $DELAI
2043    else
2044      \rm /tmp/out_command_${LOGIN}.$$
2045      break
2046    fi
2047    (( i = i + 1 ))
2048  done
2049
2050  if [ ${status} -gt 0 ] ; then
2051    echo "IGCM_sys_ncap2 : ncap2 error"
2052    IGCM_debug_Exit "ncap2"
2053  fi
2054
2055  IGCM_debug_PopStack "IGCM_sys_ncap2"
2056}
2057
2058#D-#==================================================
2059#D-function IGCM_sys_ncatted
2060#D-* Purpose: encapsulate ncatted call so as to manage error code and retry
2061#D-* Examples:
2062#D-
2063function IGCM_sys_ncatted {
2064  IGCM_debug_PushStack "IGCM_sys_ncatted" $@
2065  if ( $DEBUG_sys ) ; then
2066    echo "IGCM_sys_ncatted :" $@
2067  fi
2068
2069  typeset NB_ESSAI DELAI status i
2070  # number of tentative
2071  NB_ESSAI=3
2072  # time delay between tentative
2073  DELAI=2
2074
2075  i=0
2076  while [ $i -lt $NB_ESSAI ] ; do
2077    ncatted "$@" > /tmp/out_command_${LOGIN}.$$ 2>&1
2078    status=$?
2079    if [ ${status} -gt 0 ] ; then
2080      IGCM_debug_Print 2 "IGCM_sys_ncatted : error code ${status}"
2081      cat /tmp/out_command_${LOGIN}.$$
2082      \rm /tmp/out_command_${LOGIN}.$$
2083      IGCM_debug_Print 2 "IGCM_sys_ncatted : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2084      sleep $DELAI
2085    else
2086      \rm /tmp/out_command_${LOGIN}.$$
2087      break
2088    fi
2089    (( i = i + 1 ))
2090  done
2091
2092  if [ ${status} -gt 0 ] ; then
2093    echo "IGCM_sys_ncatted : ncatted error"
2094    IGCM_debug_Exit "ncatted"
2095  fi
2096
2097  IGCM_debug_PopStack "IGCM_sys_ncatted"
2098}
2099
2100#D-#==================================================
2101#D-function IGCM_sys_ncbo
2102#D-* Purpose: encapsulate ncbo call so as to manage error code and retry
2103#D-* Examples:
2104#D-
2105function IGCM_sys_ncbo {
2106  IGCM_debug_PushStack "IGCM_sys_ncbo" $@
2107  if ( $DEBUG_sys ) ; then
2108    echo "IGCM_sys_ncbo :" $@
2109  fi
2110
2111  typeset NB_ESSAI DELAI status i
2112  # number of tentative
2113  NB_ESSAI=3
2114  # time delay between tentative
2115  DELAI=2
2116
2117  i=0
2118  while [ $i -lt $NB_ESSAI ] ; do
2119    ncbo -C $@ > /tmp/out_command_${LOGIN}.$$ 2>&1
2120    status=$?
2121    if [ ${status} -gt 0 ] ; then
2122      IGCM_debug_Print 2 "IGCM_sys_ncbo : error code ${status}"
2123      cat /tmp/out_command_${LOGIN}.$$
2124      \rm /tmp/out_command_${LOGIN}.$$
2125      IGCM_debug_Print 2 "IGCM_sys_ncbo : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2126      sleep $DELAI
2127    else
2128      \rm /tmp/out_command_${LOGIN}.$$
2129      break
2130    fi
2131    (( i = i + 1 ))
2132  done
2133
2134  if [ ${status} -gt 0 ] ; then
2135    echo "IGCM_sys_ncbo : ncbo error"
2136    IGCM_debug_Exit "ncbo"
2137  fi
2138
2139  IGCM_debug_PopStack "IGCM_sys_ncbo"
2140}
2141
2142#D-#==================================================
2143#D-function IGCM_sys_ncdif
2144#D-* Purpose: encapsulate ncdiff call so as to manage error code and retry
2145#D-* Examples:
2146#D-
2147function IGCM_sys_ncdiff {
2148  IGCM_debug_PushStack "IGCM_sys_ncdiff" $@
2149  if ( $DEBUG_sys ) ; then
2150    echo "IGCM_sys_ncdiff :" $@
2151  fi
2152
2153  typeset NB_ESSAI DELAI status i
2154  # number of tentative
2155  NB_ESSAI=3
2156  # time delay between tentative
2157  DELAI=2
2158
2159  i=0
2160  while [ $i -lt $NB_ESSAI ] ; do
2161    ncdiff -C $@ > /tmp/out_command_${LOGIN}.$$ 2>&1
2162    status=$?
2163    if [ ${status} -gt 0 ] ; then
2164      IGCM_debug_Print 2 "IGCM_sys_ncdiff : error code ${status}"
2165      cat /tmp/out_command_${LOGIN}.$$
2166      \rm /tmp/out_command_${LOGIN}.$$
2167      IGCM_debug_Print 2 "IGCM_sys_ncdiff : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2168      sleep $DELAI
2169    else
2170      \rm /tmp/out_command_${LOGIN}.$$
2171      break
2172    fi
2173    (( i = i + 1 ))
2174  done
2175
2176  if [ ${status} -gt 0 ] ; then
2177    echo "IGCM_sys_ncdiff : ncdiff error"
2178    IGCM_debug_Exit "ncdiff"
2179  fi
2180
2181  IGCM_debug_PopStack "IGCM_sys_ncdiff"
2182}
2183
2184#D-#==================================================
2185#D-function IGCM_sys_ncea
2186#D-* Purpose: encapsulate ncea call so as to manage error code and retry
2187#D-* Examples:
2188#D-
2189function IGCM_sys_ncea {
2190  IGCM_debug_PushStack "IGCM_sys_ncea" $@
2191  if ( $DEBUG_sys ) ; then
2192    echo "IGCM_sys_ncea :" $@
2193  fi
2194
2195  typeset NB_ESSAI DELAI status i
2196  # number of tentative
2197  NB_ESSAI=3
2198  # time delay between tentative
2199  DELAI=2
2200
2201  i=0
2202  while [ $i -lt $NB_ESSAI ] ; do
2203    ncea -C $@ > /tmp/out_command_${LOGIN}.$$ 2>&1
2204    status=$?
2205    if [ ${status} -gt 0 ] ; then
2206      IGCM_debug_Print 2 "IGCM_sys_ncea : error code ${status}"
2207      cat /tmp/out_command_${LOGIN}.$$
2208      \rm /tmp/out_command_${LOGIN}.$$
2209      IGCM_debug_Print 2 "IGCM_sys_ncea : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2210      sleep $DELAI
2211    else
2212      \rm /tmp/out_command_${LOGIN}.$$
2213      break
2214    fi
2215    (( i = i + 1 ))
2216  done
2217
2218  if [ ${status} -gt 0 ] ; then
2219    echo "IGCM_sys_ncea : ncea error"
2220    IGCM_debug_Exit "ncea"
2221  fi
2222
2223  IGCM_debug_PopStack "IGCM_sys_ncea"
2224}
2225
2226#D-#==================================================
2227#D-function IGCM_sys_ncecat
2228#D-* Purpose: encapsulate ncecat call so as to manage error code and retry
2229#D-* Examples:
2230#D-
2231function IGCM_sys_ncecat {
2232  IGCM_debug_PushStack "IGCM_sys_ncecat" $@
2233  if ( $DEBUG_sys ) ; then
2234    echo "IGCM_sys_ncecat :" $@
2235  fi
2236
2237  typeset NB_ESSAI DELAI status i
2238  # number of tentative
2239  NB_ESSAI=3
2240  # time delay between tentative
2241  DELAI=2
2242
2243  i=0
2244  while [ $i -lt $NB_ESSAI ] ; do
2245    ncecat -C $@ > /tmp/out_command_${LOGIN}.$$ 2>&1
2246    status=$?
2247    if [ ${status} -gt 0 ] ; then
2248      IGCM_debug_Print 2 "IGCM_sys_ncecat : error code ${status}"
2249      cat /tmp/out_command_${LOGIN}.$$
2250      \rm /tmp/out_command_${LOGIN}.$$
2251      IGCM_debug_Print 2 "IGCM_sys_ncecat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2252      sleep $DELAI
2253    else
2254      \rm /tmp/out_command_${LOGIN}.$$
2255      break
2256    fi
2257    (( i = i + 1 ))
2258  done
2259
2260  if [ ${status} -gt 0 ] ; then
2261    echo "IGCM_sys_ncecat : ncecat error"
2262    IGCM_debug_Exit "ncecat"
2263  fi
2264
2265  IGCM_debug_PopStack "IGCM_sys_ncecat"
2266}
2267
2268#D-#==================================================
2269#D-function IGCM_sys_ncflint
2270#D-* Purpose: encapsulate ncflint call so as to manage error code and retry
2271#D-* Examples:
2272#D-
2273function IGCM_sys_ncflint {
2274  IGCM_debug_PushStack "IGCM_sys_ncflint" $@
2275  if ( $DEBUG_sys ) ; then
2276    echo "IGCM_sys_ncflint :" $@
2277  fi
2278
2279  typeset NB_ESSAI DELAI status i
2280  # number of tentative
2281  NB_ESSAI=3
2282  # time delay between tentative
2283  DELAI=2
2284
2285  i=0
2286  while [ $i -lt $NB_ESSAI ] ; do
2287    ncflint -C $@ > /tmp/out_command_${LOGIN}.$$ 2>&1
2288    status=$?
2289    if [ ${status} -gt 0 ] ; then
2290      IGCM_debug_Print 2 "IGCM_sys_ncflint : error code ${status}"
2291      cat /tmp/out_command_${LOGIN}.$$
2292      \rm /tmp/out_command_${LOGIN}.$$
2293      IGCM_debug_Print 2 "IGCM_sys_ncflint : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2294      sleep $DELAI
2295    else
2296      \rm /tmp/out_command_${LOGIN}.$$
2297      break
2298    fi
2299    (( i = i + 1 ))
2300  done
2301
2302  if [ ${status} -gt 0 ] ; then
2303    echo "IGCM_sys_ncflint : ncflint error"
2304    IGCM_debug_Exit "ncflint"
2305  fi
2306
2307  IGCM_debug_PopStack "IGCM_sys_ncflint"
2308}
2309
2310#D-#==================================================
2311#D-function IGCM_sys_ncks
2312#D-* Purpose: encapsulate ncks call so as to manage error code and retry
2313#D-* Examples:
2314#D-
2315function IGCM_sys_ncks {
2316  IGCM_debug_PushStack "IGCM_sys_ncks" $@
2317  if ( $DEBUG_sys ) ; then
2318    echo "IGCM_sys_ncks :" $@
2319  fi
2320
2321  typeset NB_ESSAI DELAI status i
2322  # number of tentative
2323  NB_ESSAI=3
2324  # time delay between tentative
2325  DELAI=2
2326
2327  i=0
2328  while [ $i -lt $NB_ESSAI ] ; do
2329    ncks -C $@ > /tmp/out_command_${LOGIN}.$$ 2>&1
2330    status=$?
2331    if [ ${status} -gt 0 ] ; then
2332      IGCM_debug_Print 2 "IGCM_sys_ncks : error code ${status}"
2333      cat /tmp/out_command_${LOGIN}.$$
2334      \rm /tmp/out_command_${LOGIN}.$$
2335      IGCM_debug_Print 2 "IGCM_sys_ncks : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2336      sleep $DELAI
2337    else
2338      \rm /tmp/out_command_${LOGIN}.$$
2339      break
2340    fi
2341    (( i = i + 1 ))
2342  done
2343
2344  if [ ${status} -gt 0 ] ; then
2345    echo "IGCM_sys_ncks : ncks error"
2346    IGCM_debug_Exit "ncks"
2347  fi
2348
2349  IGCM_debug_PopStack "IGCM_sys_ncks"
2350}
2351
2352#D-#==================================================
2353#D-function IGCM_sys_ncpdq
2354#D-* Purpose: encapsulate ncpdq call so as to manage error code and retry
2355#D-* Examples:
2356#D-
2357function IGCM_sys_ncpdq {
2358  IGCM_debug_PushStack "IGCM_sys_ncpdq" $@
2359  if ( $DEBUG_sys ) ; then
2360    echo "IGCM_sys_ncpdq :" $@
2361  fi
2362
2363  typeset NB_ESSAI DELAI status i
2364  # number of tentative
2365  NB_ESSAI=3
2366  # time delay between tentative
2367  DELAI=2
2368
2369  i=0
2370  while [ $i -lt $NB_ESSAI ] ; do
2371    ncpdq -C $@ > /tmp/out_command_${LOGIN}.$$ 2>&1
2372    status=$?
2373    if [ ${status} -gt 0 ] ; then
2374      IGCM_debug_Print 2 "IGCM_sys_ncpdq : error code ${status}"
2375      cat /tmp/out_command_${LOGIN}.$$
2376      \rm /tmp/out_command_${LOGIN}.$$
2377      IGCM_debug_Print 2 "IGCM_sys_ncpdq : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2378      sleep $DELAI
2379    else
2380      \rm /tmp/out_command_${LOGIN}.$$
2381      break
2382    fi
2383    (( i = i + 1 ))
2384  done
2385
2386  if [ ${status} -gt 0 ] ; then
2387    echo "IGCM_sys_ncpdq : ncpdq error"
2388    IGCM_debug_Exit "ncpdq"
2389  fi
2390
2391  IGCM_debug_PopStack "IGCM_sys_ncpdq"
2392}
2393
2394#D-#==================================================
2395#D-function IGCM_sys_ncra
2396#D-* Purpose: encapsulate ncra call so as to manage error code and retry
2397#D-* Examples:
2398#D-
2399function IGCM_sys_ncra {
2400  IGCM_debug_PushStack "IGCM_sys_ncra" $@
2401  if ( $DEBUG_sys ) ; then
2402    echo "IGCM_sys_ncra :" $@
2403  fi
2404
2405  typeset NB_ESSAI DELAI status i
2406  # number of tentative
2407  NB_ESSAI=3
2408  # time delay between tentative
2409  DELAI=2
2410
2411  i=0
2412  while [ $i -lt $NB_ESSAI ] ; do
2413    ncra -C $@ > /tmp/out_command_${LOGIN}.$$ 2>&1
2414    status=$?
2415    if [ ${status} -gt 0 ] ; then
2416      IGCM_debug_Print 2 "IGCM_sys_ncra : error code ${status}"
2417      cat /tmp/out_command_${LOGIN}.$$
2418      \rm /tmp/out_command_${LOGIN}.$$
2419      IGCM_debug_Print 2 "IGCM_sys_ncra : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2420      sleep $DELAI
2421    else
2422      \rm /tmp/out_command_${LOGIN}.$$
2423      break
2424    fi
2425    (( i = i + 1 ))
2426  done
2427
2428  if [ ${status} -gt 0 ] ; then
2429    echo "IGCM_sys_ncra : ncra error"
2430    IGCM_debug_Exit "ncra"
2431  fi
2432
2433  IGCM_debug_PopStack "IGCM_sys_ncra"
2434}
2435
2436#D-#==================================================
2437#D-function IGCM_sys_ncrcat
2438#D-* Purpose: encapsulate ncrcat call so as to manage error code and retry
2439#D-* Examples:
2440#D-
2441function IGCM_sys_ncrcat {
2442  IGCM_debug_PushStack "IGCM_sys_ncrcat" $@
2443  if ( $DEBUG_sys ) ; then
2444    echo "IGCM_sys_ncrcat :" $@
2445  fi
2446
2447  typeset NB_ESSAI DELAI status i lastArg
2448  # number of tentative
2449  NB_ESSAI=3
2450  # time delay between tentative
2451  DELAI=2
2452
2453  i=0
2454  while [ $i -lt $NB_ESSAI ] ; do
2455    ncrcat -C $@ > /tmp/out_command_${LOGIN}.$$ 2>&1
2456    status=$?
2457    if [ ${status} -gt 0 ] ; then
2458      IGCM_debug_Print 2 "IGCM_sys_ncrcat : error code ${status}"
2459      cat /tmp/out_command_${LOGIN}.$$
2460      \rm /tmp/out_command_${LOGIN}.$$
2461      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2462      sleep $DELAI
2463    elif [ ! "X$( grep "WARNING Intra-file non-monotonicity" /tmp/out_command_${LOGIN}.$$ )" = "X" ] ; then
2464      IGCM_debug_Print 2 "IGCM_sys_ncrcat : WARNING Intra-file non-monotonicity"
2465      cat /tmp/out_command_${LOGIN}.$$
2466      # remove files having corrupted time axis
2467      eval lastArg=\${$#}
2468      IGCM_debug_Print 2 "IGCM_sys_ncrcat : Delete ${lastArg}"
2469      \rm ${lastArg}
2470      \rm /tmp/out_command_${LOGIN}.$$
2471      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2472      sleep $DELAI
2473    else
2474      \rm /tmp/out_command_${LOGIN}.$$
2475      break
2476    fi
2477    (( i = i + 1 ))
2478  done
2479
2480  if [ ${status} -gt 0 ] ; then
2481    echo "IGCM_sys_ncrcat : ncrcat error"
2482    #IGCM_debug_Exit "ncrcat"
2483  fi
2484
2485  IGCM_debug_PopStack "IGCM_sys_ncrcat"
2486}
2487
2488#D-#==================================================
2489#D-function IGCM_sys_ncrename
2490#D-* Purpose: encapsulate ncrename call so as to manage error code and retry
2491#D-* Examples:
2492#D-
2493function IGCM_sys_ncrename {
2494  IGCM_debug_PushStack "IGCM_sys_ncrename" $@
2495  if ( $DEBUG_sys ) ; then
2496    echo "IGCM_sys_ncrename :" $@
2497  fi
2498
2499  typeset NB_ESSAI DELAI status i
2500  # number of tentative
2501  NB_ESSAI=3
2502  # time delay between tentative
2503  DELAI=2
2504
2505  i=0
2506  while [ $i -lt $NB_ESSAI ] ; do
2507    ncrename $@ > /tmp/out_command_${LOGIN}.$$ 2>&1
2508    status=$?
2509    if [ ${status} -gt 0 ] ; then
2510      IGCM_debug_Print 2 "IGCM_sys_ncrename : error code ${status}"
2511      cat /tmp/out_command_${LOGIN}.$$
2512      \rm /tmp/out_command_${LOGIN}.$$
2513      IGCM_debug_Print 2 "IGCM_sys_ncrename : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2514      sleep $DELAI
2515    else
2516      \rm /tmp/out_command_${LOGIN}.$$
2517      break
2518    fi
2519    (( i = i + 1 ))
2520  done
2521
2522  if [ ${status} -gt 0 ] ; then
2523    echo "IGCM_sys_ncrename : ncrename error"
2524    IGCM_debug_Exit "ncrename"
2525  fi
2526
2527  IGCM_debug_PopStack "IGCM_sys_ncrename"
2528}
2529
2530#D-#==================================================
2531#D-function IGCM_sys_ncwa
2532#D-* Purpose: encapsulate ncwa call so as to manage error code and retry
2533#D-* Examples:
2534#D-
2535function IGCM_sys_ncwa {
2536  IGCM_debug_PushStack "IGCM_sys_ncwa" $@
2537  if ( $DEBUG_sys ) ; then
2538    echo "IGCM_sys_ncwa :" $@
2539  fi
2540
2541  typeset NB_ESSAI DELAI status i
2542  # number of tentative
2543  NB_ESSAI=3
2544  # time delay between tentative
2545  DELAI=2
2546
2547  i=0
2548  while [ $i -lt $NB_ESSAI ] ; do
2549    ncwa -C $@ > /tmp/out_command_${LOGIN}.$$ 2>&1
2550    status=$?
2551    if [ ${status} -gt 0 ] ; then
2552      IGCM_debug_Print 2 "IGCM_sys_ncwa : error code ${status}"
2553      cat /tmp/out_command_${LOGIN}.$$
2554      \rm /tmp/out_command_${LOGIN}.$$
2555      IGCM_debug_Print 2 "IGCM_sys_ncwa : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2556      sleep $DELAI
2557    else
2558      \rm /tmp/out_command_${LOGIN}.$$
2559      break
2560    fi
2561    (( i = i + 1 ))
2562  done
2563
2564  if [ ${status} -gt 0 ] ; then
2565    echo "IGCM_sys_ncwa : ncwa error"
2566    IGCM_debug_Exit "ncwa"
2567  fi
2568
2569  IGCM_debug_PopStack "IGCM_sys_ncwa"
2570}
2571
2572##############################################################
2573# CDO OPERATOR
2574
2575#D-#==================================================
2576#D-function IGCM_sys_cdo
2577#D-* Purpose: encapsulate cdo call so as to manage error code and retry
2578#D-* Examples:
2579#D-
2580function IGCM_sys_cdo {
2581  IGCM_debug_PushStack "IGCM_sys_cdo" $@
2582  if ( $DEBUG_sys ) ; then
2583    echo "IGCM_sys_cdo :" $@
2584  fi
2585
2586  typeset status
2587
2588  \cdo $@ > /tmp/out_command_${LOGIN}.$$ 2>&1
2589  status=$?
2590  if [ ${status} -gt 0 ] ; then
2591    echo "IGCM_sys_cdo : error code ${status}"
2592    cat /tmp/out_command_${LOGIN}.$$
2593    \rm /tmp/out_command_${LOGIN}.$$
2594    IGCM_debug_PopStack "IGCM_sys_cdo"
2595    return 1
2596  else
2597    IGCM_debug_PopStack "IGCM_sys_cdo"
2598    return 0
2599  fi
2600
2601  IGCM_debug_PopStack "IGCM_sys_cdo"
2602}
Note: See TracBrowser for help on using the repository browser.