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

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

house keeping in libIGCM_sys (first pass). Will ease #248

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