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

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