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

Last change on this file since 832 was 828, checked in by sdipsl, 11 years ago
  • Stack file management must be kept in libIGCM_debug
  • Property svn:keywords set to Revision Author Date
File size: 69.7 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  fi
860  IGCM_debug_PopStack "IGCM_sys_Mv"
[16]861}
862
863#D-#==================================================
864#D-function IGCM_sys_Put_Dir
865#D-* Purpose: Copy a complete directory on $(ARCHIVE)
866#D-* Examples:
867#D-
868function IGCM_sys_Put_Dir {
[657]869  IGCM_debug_PushStack "IGCM_sys_Put_Dir" $@
870  if ( $DEBUG_sys ) ; then
871    echo "IGCM_sys_Put_Dir :" $@
872  fi
873  if [ $DRYRUN = 0 ]; then
874    if [ ! -d ${1} ] ; then
875      echo "WARNING : IGCM_sys_Put_Dir ${1} DOES NOT EXIST ."
876      IGCM_debug_PopStack "IGCM_sys_Put_Dir"
877      return
[16]878    fi
879
[717]880    typeset status
[16]881
[717]882    # Only if we use rsync
883    #IGCM_sys_TestDirArchive $( dirname $2 )
884    #
885    #USUAL WAY
886    \cp -r $1 $2 > out_rsync 2>&1
887    status=$?
[16]888
[717]889    if [ ${status} -gt 0 ] ; then
[811]890      IGCM_debug_Print 2 "IGCM_sys_Put_Dir : cp failed error code ${status}"
[657]891      cat out_rsync
892      IGCM_debug_Exit "IGCM_sys_Put_Dir"
[16]893    else
[717]894      \rm out_rsync
[16]895    fi
[657]896  fi
897  IGCM_debug_PopStack "IGCM_sys_Put_Dir"
[16]898}
899
900#D-#==================================================
901#D-function IGCM_sys_Get_Dir
[717]902#D-* Purpose: Copy a complete directory from ${ARCHIVE}
[16]903#D-* Examples:
904#D-
905function IGCM_sys_Get_Dir {
[657]906  IGCM_debug_PushStack "IGCM_sys_Get_Dir" $@
907  if ( $DEBUG_sys ) ; then
908    echo "IGCM_sys_Get_Dir :" $@
909  fi
910  if [ $DRYRUN = 0 ]; then
911    if [ ! -d ${1} ] ; then
912      echo "WARNING : IGCM_sys_Get_Dir ${1} DOES NOT EXIST ."
913      IGCM_debug_PopStack "IGCM_sys_Get_Dir"
914      return
[16]915    fi
916
[717]917    typeset status
[16]918
[719]919    #USUAL WAY
[811]920    \cp -ur $1 $2 > out_rsync 2>&1
[717]921    status=$?
[16]922
[717]923    if [ ${status} -gt 0 ] ; then
[811]924      IGCM_debug_Print 2 "IGCM_sys_Get_Dir : cp failed error code ${status}"
[657]925      cat out_rsync
926      IGCM_debug_Exit "IGCM_sys_Get_Dir"
[16]927    else
[717]928      \rm out_rsync
[16]929    fi
[657]930  fi
931  IGCM_debug_PopStack "IGCM_sys_Get_Dir"
[16]932}
933
934#D-#==================================================
935#D-function IGCM_sys_Get_Master
936#D-* Purpose: Copy a complete directory from MASTER filesystem
937#D-* Examples:
938#D-
939function IGCM_sys_Get_Master {
[657]940  IGCM_debug_PushStack "IGCM_sys_Get_Master" $@
941  if ( $DEBUG_sys ) ; then
942    echo "IGCM_sys_Get_Master :" $@
943  fi
944  if [ $DRYRUN = 0 ]; then
945    if ( [ ! -d ${1} ] && [ ! -f ${1} ] ) ; then
946      echo "WARNING : IGCM_sys_Get_Master ${1} DOES NOT EXIST ."
947      IGCM_debug_PopStack "IGCM_sys_Get_Master"
948      return
[16]949    fi
950
[811]951    typeset NB_ESSAI DELAI status i
952    # number of tentative
953    NB_ESSAI=3
954    # time delay between tentative
955    DELAI=2
[16]956
[811]957    i=0
958    while [ $i -lt $NB_ESSAI ] ; do
959      \cp -urL $1 $2 > out_rsync 2>&1
960      status=$?
961      if [ ${status} -gt 0 ]; then
962        IGCM_debug_Print 2 "IGCM_sys_Get_Master : cp failed error code ${status} ${i}/${NB_ESSAI}"
963        IGCM_debug_Print 2 "IGCM_sys_Get_Master : sleep ${DELAI} seconds and try again."
964        sleep $DELAI
965      else
966        break
967      fi
968      (( i = i + 1 ))
969    done
[16]970
[717]971    if [ ${status} -gt 0 ] ; then
[657]972      echo "IGCM_sys_Get_Master : error."
973      cat out_rsync
974      IGCM_debug_Exit "IGCM_sys_Get_Master"
[16]975    else
[811]976      \rm out_rsync
[16]977    fi
[657]978  fi
979  IGCM_debug_PopStack "IGCM_sys_Get_Master"
[16]980}
981
[811]982#====================================================
983#- Call IGCM_sys_Mirror_libIGCM now !
984if ( $MirrorlibIGCM ) ; then
985  IGCM_sys_Mirror_libIGCM
986fi
987
[16]988#D-#==================================================
989#D-function IGCM_sys_Put_Rest
[717]990#D-* Purpose: Put computied restarts on ${ARCHIVE}.
[282]991#D-           File and target directory must exist.
[16]992#D-* Examples:
993#D-
994function IGCM_sys_Put_Rest {
[657]995  IGCM_debug_PushStack "IGCM_sys_Put_Rest" $@
996  if ( $DEBUG_sys ) ; then
997    echo "IGCM_sys_Put_Rest :" $@
998  fi
999  if [ $DRYRUN = 0 ]; then
1000    if [ ! -f ${1} ] ; then
1001      echo "ERROR : IGCM_sys_Put_Rest ${1} DOES NOT EXIST ."
1002      IGCM_debug_Exit "IGCM_sys_Put_Rest"
[16]1003    fi
[717]1004
1005    typeset status
1006    #
[657]1007    if [ X${JobType} = XRUN ] ; then
1008      IGCM_sys_Chmod 444 ${1}
1009    fi
[717]1010    #
[811]1011    # Only if we use rsync
1012    #IGCM_sys_MkdirArchive $( dirname $2 )
1013    #
1014    #USUAL WAY
[717]1015    \cp $1 $2 > out_rsync 2>&1
1016    status=$?
[16]1017
[717]1018#       #RSYNC WITH NETWORK SSH CALL
1019#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > out_rsync 2>&1
1020#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> out_rsync 2>&1
[16]1021
[717]1022#       #RSYNC WITH NFS USE
1023#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
1024#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
[16]1025
[717]1026#       status=$?
1027#       IGCM_sys_Rsync_out $status
1028
1029#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1030#       (( status=status+$? ))
1031
1032    if [ ${status} -gt 0 ] ; then
1033      echo "IGCM_sys_Put_Rest : cp failed error code ${status}"
[657]1034      cat out_rsync
1035      IGCM_debug_Exit "IGCM_sys_Put_Rest"
1036    else
[717]1037      \rm out_rsync
[657]1038    fi
1039  fi
1040  IGCM_debug_PopStack "IGCM_sys_Put_Rest"
1041}
[16]1042
[657]1043#D-#==================================================
1044#D-function IGCM_sys_PutBuffer_Rest
1045#D-* Purpose: Put computied restarts on ${SCRATCHDIR}.
1046#D-           File and target directory must exist.
1047#D-* Examples:
1048#D-
1049function IGCM_sys_PutBuffer_Rest {
1050  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Rest" $@
1051  if ( $DEBUG_sys ) ; then
1052    echo "IGCM_sys_PutBuffer_Rest :" $@
1053  fi
1054  if [ $DRYRUN = 0 ]; then
1055    if [ ! -f ${1} ] ; then
1056      echo "ERROR : IGCM_sys_PutBuffer_Rest ${1} DOES NOT EXIST ."
1057      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
1058    fi
[16]1059
[717]1060    typeset status
[657]1061    #
1062    if [ X${JobType} = XRUN ] ; then
1063      IGCM_sys_Chmod 444 ${1}
1064    fi
1065
1066    #
1067    # USUAL WAY
1068    \cp $1 $2 > out_rsync 2>&1
[717]1069    status=$?
[657]1070
[717]1071    if [ ${status} -gt 0 ] ; then
1072      echo "IGCM_sys_PutBuffer_Rest : error code ${status}"
[811]1073      [ -f ${2} ] && ls -l ${2}
1074      [ -f ${2}/${1} ] && ls -l ${2}/${1}
[657]1075      cat out_rsync
1076      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
[16]1077    else
[657]1078      \rm out_rsync
[16]1079    fi
[657]1080  fi
1081  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Rest"
[16]1082}
1083
1084#D-#==================================================
[801]1085#D-function IGCM_sys_PrepareTaredRestart
1086#D-* Purpose: Prepare tared restart to be access by computing job. Identity here.
1087#D-* Examples:
1088#D-
1089function IGCM_sys_PrepareTaredRestart {
1090  IGCM_debug_PushStack "IGCM_sys_PrepareTaredRestart" $@
1091  echo $1
1092  IGCM_debug_PopStack "IGCM_sys_PrepareTaredRestart"
1093}
1094
1095#D-#==================================================
[16]1096#D-function IGCM_sys_Put_Out
[717]1097#D-* Purpose: Copy a file on ${ARCHIVE} after having chmod it in readonly
[16]1098#D-* Examples:
1099#D-
1100function IGCM_sys_Put_Out {
[657]1101  IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
1102  if ( $DEBUG_sys ) ; then
1103    echo "IGCM_sys_Put_Out :" $@
1104  fi
[811]1105
1106  typeset status
1107
[657]1108  if [ $DRYRUN = 0 ]; then
[811]1109    if [ ! -f ${1} ] ; then
[657]1110      echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
1111      IGCM_debug_PopStack "IGCM_sys_Put_Out"
1112      return 1
[16]1113    fi
[719]1114    #
[811]1115    IGCM_sys_MkdirArchive $( dirname $2 )
1116    #
[657]1117    if [ X${JobType} = XRUN ] ; then
1118      if [ X${3} = X ] ; then
1119        IGCM_sys_Chmod 444 ${1}
1120      fi
1121    fi
[717]1122    #
[16]1123
[657]1124    echo ${RSYNC} ${RSYNC_opt} $1 $2 > out_rsync 2>&1
1125    ${RSYNC} ${RSYNC_opt} $1 $2 >> out_rsync 2>&1
[717]1126    status=$?
1127    IGCM_sys_Rsync_out $status
[16]1128
[657]1129    ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
[717]1130    (( status=status+$? ))
[16]1131
[717]1132    if [ ${status} -gt 0 ] ; then
[811]1133      IGCM_debug_Print 2 "IGCM_sys_Put_Out : rsync failed error code ${status}"
[657]1134      cat out_rsync
1135      IGCM_debug_Exit "IGCM_sys_Put_Out"
[16]1136    else
[717]1137      \rm out_rsync
[16]1138    fi
[657]1139  fi
1140  IGCM_debug_PopStack "IGCM_sys_Put_Out"
1141  return 0
[16]1142}
1143
1144#D-#==================================================
[657]1145#D-function IGCM_sys_PutBuffer_Out
1146#D-* Purpose: Copy a file on ${SCRATCHDIR} after having chmod it in readonly
1147#D-* Examples:
1148#D-
1149function IGCM_sys_PutBuffer_Out {
1150  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Out" $@
1151  if ( $DEBUG_sys ) ; then
1152    echo "IGCM_sys_PutBuffer_Out :" $@
1153  fi
[719]1154
[811]1155  typeset NB_ESSAI DELAI status i exist skip
[719]1156
[811]1157  # number of tentative
1158  NB_ESSAI=3
1159  # time delay between tentative
1160  DELAI=2
1161
[657]1162  if [ $DRYRUN = 0 ]; then
1163    if [ ! -f ${1} ] ; then
1164      echo "WARNING : IGCM_sys_PutBuffer_Out ${1} DOES NOT EXIST ."
1165      IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1166      return 1
1167    fi
1168    #
1169    IGCM_sys_Mkdir $( dirname $2 )
1170    #
1171
[811]1172    exist=false
1173    skip=false
1174    if [ -f $2 ] ; then
1175      IGCM_debug_Print 1 "$2 already exist"
1176      exist=true
1177      if [ "X$( diff $1 $2 )" = X ] ; then
1178        IGCM_debug_Print 2 "$1 and $2 are the same file, we skip the copy"
1179        status=0
1180        skip=true
1181      else
1182        IGCM_debug_Print 2 "$1 and $2 are not the same file, we force the copy"
1183        skip=false
[657]1184      fi
1185    fi
1186    #
[811]1187    if ( [ X${exist} = Xtrue ] && [ X${skip} = Xfalse ] ) ; then
1188      IGCM_sys_Chmod u+w $2
1189    fi
[657]1190
[811]1191    if [ X${skip} = Xfalse ] ; then
1192      i=0
1193      while [ $i -lt $NB_ESSAI ] ; do
1194        # USUAL WAY
1195        \cp $1 $2 > out_rsync 2>&1
1196        status=$?
1197        if [ ${status} -gt 0 ]; then
1198          IGCM_debug_Print 2 "IGCM_sys_PutBuffer_Out : cp failed error code ${status} ${i}/${NB_ESSAI}"
1199          IGCM_debug_Print 2 "IGCM_sys_PutBuffer_Out : sleep ${DELAI} seconds and try again."
1200          [ -f ${2} ] && ls -l ${2}
1201          [ -f ${2}/${1} ] && ls -l ${2}/${1}
1202          sleep $DELAI
1203        else
1204          break
1205        fi
1206        (( i = i + 1 ))
1207      done
1208    fi
1209
[717]1210    if [ ${status} -gt 0 ] ; then
[657]1211      echo "IGCM_sys_PutBuffer_Out : error."
[811]1212      [ -f ${2} ] && ls -l ${2}
1213      [ -f ${2}/${1} ] && ls -l ${2}/${1}
[657]1214      cat out_rsync
1215      IGCM_debug_Exit "IGCM_sys_PutBuffer_Out"
1216    else
[811]1217
1218      if [ X${JobType} = XRUN ] ; then
1219        if [ X${3} = X ] ; then
1220          [ -f ${2} ] && IGCM_sys_Chmod 444 ${2}
1221          [ -f ${2}/${1} ] && IGCM_sys_Chmod 444 ${2}/${1}
1222        fi
1223      fi
1224
[657]1225      \rm out_rsync
1226    fi
1227  fi
1228  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1229  return 0
1230}
1231
1232#D-#==================================================
[16]1233#D-function IGCM_sys_Get
1234#D-* Purpose: Get a file from ${ARCHIVE}
1235#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
1236#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
1237function IGCM_sys_Get {
[657]1238  IGCM_debug_PushStack "IGCM_sys_Get" $@
[16]1239
[811]1240  typeset DEST status dm_liste
[16]1241
[657]1242  if ( $DEBUG_sys ) ; then
1243    echo "IGCM_sys_Get :" $@
1244  fi
1245  if [ $DRYRUN -le 2 ]; then
1246    if [ X${1} = X'/l' ] ; then
[717]1247      # test if the first file is present in the old computation :
[657]1248      eval set +A dm_liste \${${2}}
1249    else
1250      dm_liste=${1}
[16]1251    fi
[657]1252    eval DEST=\${${#}}
[16]1253
[717]1254    # test if the (first) file is present in the old computation :
[657]1255    IGCM_sys_TestFileArchive ${dm_liste[0]}
[717]1256    status=$?
1257    if [ ${status} -gt 0 ] ; then
[657]1258      echo "IGCM_sys_Get, ERROR : regular file ${dm_liste[0]} DOES NOT EXIST ."
1259      IGCM_debug_Exit "IGCM_sys_Get"
[811]1260      return
[657]1261    fi
[16]1262
[811]1263    #USUAL WAY
1264    \cp ${dm_liste[*]} ${DEST} > out_rsync 2>&1
1265    status=$?
[16]1266
[811]1267    if [ ${status} -gt 0 ] ; then
1268      IGCM_debug_Print 2 "IGCM_sys_Get : cp failed error code ${status}"
[657]1269      cat out_rsync
1270      IGCM_debug_Exit "IGCM_sys_Get"
[16]1271    else
[717]1272      \rm out_rsync
[16]1273    fi
[657]1274  fi
1275  IGCM_debug_PopStack "IGCM_sys_Get"
[16]1276}
1277
1278#D-#==================================================
[657]1279#D-function IGCM_sys_GetBuffer
1280#D-* Purpose: Get a file from ${SCRATCHDIR}
1281#D-* Examples: IGCM_sys_GetBuffer myfile /destpath/myfile_with_PREFIX
1282#D-            IGCM_sys_GetBuffer /l Array_contain_myfiles /destpath/
1283function IGCM_sys_GetBuffer {
1284  IGCM_debug_PushStack "IGCM_sys_GetBuffer" $@
1285
[811]1286  typeset DEST buf_liste target file_work
1287  typeset NB_ESSAI DELAI status i
[657]1288
1289  if ( $DEBUG_sys ) ; then
1290    echo "IGCM_sys_GetBuffer :" $@
1291  fi
[811]1292
1293  # number of tentative
1294  NB_ESSAI=3
1295  # time delay between tentative
1296  DELAI=2
1297
[657]1298  if [ $DRYRUN -le 2 ]; then
1299    if [ X${1} = X'/l' ] ; then
1300      # test if the first file is present in the old computation :
1301      eval set +A buf_liste \${${2}}
1302    else
1303      eval set +A buf_liste ${1}
1304    fi
1305    eval DEST=\${${#}}
1306
1307    #USUAL WAY
1308    if [ X${1} = X'/l' ] ; then
1309      for target in ${buf_liste[*]} ; do
1310        local_file=$( basename ${target} )
[811]1311        i=0
1312        while [ $i -lt $NB_ESSAI ] ; do
1313          \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1314          status=$?
1315          if [ ${status} -gt 0 ]; then
1316            IGCM_debug_Print 2 "IGCM_sys_GetBuffer : cp failed error code ${status} ${i}/${NB_ESSAI}"
1317            IGCM_debug_Print 2 "IGCM_sys_GetBuffer : sleep ${DELAI} seconds and try again."
1318            sleep $DELAI
1319          else
1320            break
1321          fi
1322          (( i = i + 1 ))
1323        done
1324        if [ ${status} -gt 0 ] ; then
1325          echo "IGCM_sys_Get : error"
1326          cat out_rsync
1327          \rm out_rsync
1328          IGCM_debug_Exit "IGCM_sys_GetBuffer"
1329        else
1330          \rm out_rsync
1331        fi
[657]1332      done
1333    else
[811]1334      i=0
1335      while [ $i -lt $NB_ESSAI ] ; do
1336        \cp ${buf_liste} ${DEST} >> out_rsync 2>&1
1337        status=$?
1338        if [ ${status} -gt 0 ]; then
1339          IGCM_debug_Print 2 "IGCM_sys_GetBuffer : cp failed error code ${status} ${i}/${NB_ESSAI}"
1340          IGCM_debug_Print 2 "IGCM_sys_GetBuffer : sleep ${DELAI} seconds and try again."
1341          sleep $DELAI
1342        else
1343          break
1344        fi
1345        (( i = i + 1 ))
1346      done
1347      if [ ${status} -gt 0 ] ; then
1348        echo "IGCM_sys_Get : error"
1349        cat out_rsync
1350        \rm out_rsync
1351        IGCM_debug_Exit "IGCM_sys_GetBuffer"
1352      else
1353        \rm out_rsync
1354      fi
[657]1355    fi
1356  fi
1357  IGCM_debug_PopStack "IGCM_sys_GetBuffer"
1358}
1359
1360#D-#==================================================
1361#D-function IGCM_sys_GetDate_FichWork
1362#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
1363#D-* Examples:
1364#D-
1365function IGCM_sys_GetDate_FichWork {
1366  IGCM_debug_PushStack "IGCM_sys_FichWork" $@
1367  if ( $DEBUG_sys ) ; then
1368    echo "IGCM_sys_GetDate_FichWork :" $@
1369  fi
1370  typeset dateF
1371  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1372  eval ${2}=${dateF[5]}
1373
[800]1374  # donne la date filesys d'un fichier sur la machine work
[657]1375  IGCM_debug_PopStack "IGCM_sys_FichWork"
1376}
1377
1378#D-#==================================================
1379#D-function IGCM_sys_GetDate_FichArchive
1380#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
1381#D-* Examples:
1382#D-
1383function IGCM_sys_GetDate_FichArchive {
1384  IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
1385  if ( $DEBUG_sys ) ; then
1386    echo "IGCM_sys_GetDate_FichArchive :" $@
1387  fi
1388  typeset dateF
1389  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1390  eval ${2}=${dateF[5]}
1391
1392  IGCM_debug_PopStack "IGCM_sys_FichArchive"
1393}
1394
1395#D-#==================================================
[343]1396#D-function IGCM_sys_Dods_Rm
[717]1397#D-* Purpose: DO NOTHING ! Put ${ARCHIVE} files on DODS internet protocole.
[343]1398#D-* Examples:
1399#D-
1400function IGCM_sys_Dods_Rm {
[657]1401  if ( $DEBUG_sys ) ; then
1402    echo "IGCM_sys_Dods_Rm :" $@
1403  fi
1404  return 0
[343]1405}
1406
1407#D-#==================================================
1408#D-function IGCM_sys_Dods_Cp
[717]1409#D-* Purpose: Copy $(ARCHIVE) files on DODS internet protocole.
[343]1410#D-* Examples:
1411#D-
1412function IGCM_sys_Dods_Cp {
[657]1413  if ( $DEBUG_sys ) ; then
1414    echo "IGCM_sys_Dods_Cp :" $@
1415  fi
1416  return 0
[343]1417}
1418
1419#D-#==================================================
[16]1420#D-function IGCM_sys_Put_Dods
[811]1421#D-* Purpose: Put ${ARCHIVE} files on DODS internet protocole. Dummy function here
[16]1422#D-* Examples:
1423#D-
1424function IGCM_sys_Put_Dods {
[657]1425  IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
1426  if ( $DEBUG_sys ) ; then
1427    echo "IGCM_sys_Put_Dods :" $@
1428  fi
1429  IGCM_debug_PopStack "IGCM_sys_Put_Dods"
[16]1430}
1431
[657]1432##############################################################
1433# REBUILD OPERATOR
[536]1434
[811]1435#D-#==================================================
1436#D-function IGCM_sys_rebuild
1437#D-* Purpose: rebuild parallel files
1438#D-* Examples:
1439#D-
[657]1440function IGCM_sys_rebuild {
1441  IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1442  if ( $DEBUG_sys ) ; then
1443    echo "IGCM_sys_rebuild :" $@
1444  fi
[717]1445
[811]1446  typeset NB_ESSAI DELAI status i firstArg
1447  # number of tentative
1448  NB_ESSAI=3
1449  # time delay between tentative
1450  DELAI=2
[717]1451
[811]1452  i=0
1453  while [ $i -lt $NB_ESSAI ] ; do
1454    /home/users/igcmg/rebuild/bin/rebuild -f -o $@ > out_rsync 2>&1
1455    status=$?
1456    if [ ${status} -gt 0 ] ; then
1457      IGCM_debug_Print 2 "IGCM_sys_rebuild : error code ${status}"
1458      cat out_rsync
1459      \rm out_rsync
1460      IGCM_debug_Print 2 "IGCM_sys_rebuild : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1461      firstArg=${1}
1462      \rm ${firstArg}
1463      sleep $DELAI
1464    else
1465      \rm out_rsync
1466      break
1467    fi
1468    (( i = i + 1 ))
1469  done
1470
[717]1471  if [ ${status} -gt 0 ] ; then
[811]1472    echo "IGCM_sys_rebuild : rebuild error code is ${status}"
[657]1473    IGCM_debug_Exit "rebuild"
1474  fi
1475
1476  IGCM_debug_PopStack "IGCM_sys_rebuild"
[16]1477}
1478
[811]1479#D-#==================================================
1480#D-function IGCM_sys_rebuild_station
1481#D-* Purpose: rebuild parallel files describing station
1482#D-* Examples:
1483#D-
[697]1484function IGCM_sys_rebuild_station {
1485  IGCM_debug_PushStack "IGCM_sys_rebuild_station" -- $@
1486  typeset i list_opt file_in file_out prefix_invert list_invert
1487  if ( $DEBUG_sys ) ; then
1488    echo "IGCM_sys_rebuild_station :" $@
1489  fi
1490  list_opt=$@
1491
[800]1492  # Invert Axis : t,x -> x,t
[697]1493  #               t,pres,x -> x,t,pres
1494  # So that we can concatenate along x
1495  i=0
1496  for file_in in ${list_opt} ; do
1497    (( i = i + 1))
1498    [ ${i} = 1 ] && file_out=${file_in} && continue
1499    prefix_invert=$( basename ${file_in} .nc )
1500    IGCM_sys_ncpdq -a x,time_counter -a x,time_counter,presnivs ${file_in} ${prefix_invert}_xt.nc
1501    list_invert[${#list_invert[*]}]=${prefix_invert}_xt.nc
1502  done
1503
1504  # Concatenate
1505  IGCM_sys_ncrcat ${list_invert[*]} histstn_xt.nc
1506
1507  # Re-ivert file
1508  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x histstn_xt.nc ${file_out}
1509
1510  # Station re-ordering is too expansive to be run within libICGM
1511  # This is due to (ncpdq - nrcat - ncpdq) I/O sequence.
1512  # This re-ordering must be done "in memory" by the cmorization process
1513  # Anyway this is the best sequence using (ncpdq - nrcat - ncpdq)
1514  # BEGIN reordering
1515
1516  # Only LMDZ text output contains the exact ordering of the station.
1517  # We isolate this in the code below:
1518  #  0  38  -157.5000000000000  70.98591549295774
1519  #  0  54  27.49999999999999   67.18309859154928
1520  #  0  56  -62.50000000000001  82.39436619718309
1521  #  0  79  12.49999999999999   78.59154929577466
1522  #  0  116 -165.0000000000000  76.05633802816901
1523  #  0  117 130.0000000000000   70.98591549295774
1524  #  0  118 110.0000000000000   87.46478873239437
1525  #  1  40  4.999999999999995   51.97183098591550
1526#  typeset iStation iProc list_opt file_in file_out prefix_invert
1527#  typeset -Z4 j4
1528#  typeset -Z3 j3
1529
1530#  unset list_opt
1531#  set +A list_opt $@
1532
1533  # Filename after rebuild
1534#  file_out=${list_opt[0]}
1535  # Prefix of output files
1536#  prefix_invert=$( basename ${file_out} .nc )
1537  # Number of procs
1538#  num_proc=$( grep -i mpi_size ${PREFIX}_${Exe_Output} | wc -l )
1539
1540#  iProc=0
1541#  while [ ${iProc} -lt ${num_proc} ] ; do
1542    # Array containing Station as a number
1543#    unset proc_stn
1544#    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}' )
1545    # Number of stations produced by processor proc
1546#    stationLast=${#proc_stn[*]}
1547    # Proc number on 4 digits
1548#    j4=${iProc}
1549    # Init
1550#    iStation=0
1551#    while [ ${iStation} -lt ${stationLast} ] ; do
1552      # Station number on 3 digits
1553#      j3=${proc_stn[${iStation}]}
1554      # Extract station
[800]1555      # Invert Axis : t,x -> x,t
[697]1556      #               t,pres,x -> x,t,pres
1557      # So that we can concatenate along x
1558#      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
1559#      (( iStation = iStation + 1 ))
1560#    done
1561#    (( iProc = iProc + 1 ))
1562#  done
1563
1564  # Concatenate all station along x
1565#  IGCM_sys_ncrcat ${prefix_invert}_stn_???.nc ${prefix_invert}_xt.nc
1566
1567  # Re-invert file
1568#  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x ${prefix_invert}_xt.nc ${file_out}
1569
1570  # END reordering
1571
1572  IGCM_debug_PopStack "IGCM_sys_rebuild_station"
1573}
1574
[657]1575############################################################
1576# Activate Running Environnment Variables
[536]1577
[811]1578#D-#==================================================
1579#D-function IGCM_sys_desactiv_variables
1580#D-* Purpose: set environement variables prior to execution
1581#D-* Examples:
1582#D-
[657]1583function IGCM_sys_activ_variables {
1584  IGCM_debug_PushStack "IGCM_sys_activ_variables"
1585  if ( $DEBUG_sys ) ; then
1586    echo "IGCM_sys_activ_variables"
1587  fi
[811]1588
1589# --------------------------------------------------------------------
1590#D- MPI specifications
1591# --------------------------------------------------------------------
1592
1593# --------------------------------------------------------------------
1594#D- Other specifications
1595# --------------------------------------------------------------------
1596
[657]1597  IGCM_debug_PopStack "IGCM_sys_activ_variables"
[16]1598}
1599
[657]1600############################################################
1601# Desactivate Running Environnment Variables
[16]1602
[811]1603#D-#==================================================
1604#D-function IGCM_sys_desactiv_variables
1605#D-* Purpose: unset environement variables after execution
1606#D-* Examples:
1607#D-
[657]1608function IGCM_sys_desactiv_variables {
1609  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1610  if ( $DEBUG_sys ) ; then
1611    echo "IGCM_sys_desactiv_variables"
1612  fi
[811]1613# --------------------------------------------------------------------
1614#D- MPI specifications
1615# --------------------------------------------------------------------
1616
1617# --------------------------------------------------------------------
1618#D- Other specifications
1619# --------------------------------------------------------------------
1620
[657]1621  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1622}
1623
1624############################################################
[800]1625# Build MPI/OMP scripts run file (dummy function)
[657]1626
[811]1627#D-#==================================================
1628#D-function IGCM_sys_build_run_file
1629#D-* Purpose: build run file (deprecated)
1630#D-* Examples:
1631#D-
[657]1632function IGCM_sys_build_run_file {
1633
[664]1634  IGCM_debug_Print 3 " dummy function : IGCM_sys_build_run_file "
[657]1635
1636}
1637
1638############################################################
1639# Build MPI/OMP scripts
[811]1640
1641#D-#==================================================
1642#D-function IGCM_sys_build_execution_scripts
1643#D-* Purpose: build execution scripts to be launch by ${HOST_MPIRUN_COMMAND}
1644#D-* Examples:
1645#D-
[657]1646function IGCM_sys_build_execution_scripts
1647{
1648  IGCM_debug_PushStack "IGCM_sys_build_execution_scripts" $@
1649  if ( $DEBUG_sys ) ; then
1650    echo "IGCM_sys_build_execution_scripts " $@
1651  fi
1652  typeset nodes listnodes init_node start_num init_exec comp ExeNameIn ExeNameOut
1653  typeset node_num_current node_current comp_proc_mpi_loc comp_proc_omp_loc
1654  typeset num_corempi nombre_restant_node nombre_restant_comp
1655
1656  if [ ! -f ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} ]  ; then
[811]1657    IGCM_debug_Exit "IGCM_sys_obelix build_execution_scripts : Job_${config_UserChoices_JobName} don't exist in SUBMIT_DIR : ${SUBMIT_DIR} "
[657]1658  fi
1659
1660  if ( ${OK_PARA_MPMD} ) ; then
1661
1662    if [ -f run_file ] ; then
1663      IGCM_sys_Rm -f run_file
[16]1664    fi
[657]1665    touch run_file
1666
1667    if ( ${OK_PARA_OMP} ) ; then
1668
1669      #  Hosts treatment
1670
1671      ${HOST_MPIRUN_COMMAND} hostname | sort | uniq > hosts.tmp
1672
1673      i=0
1674      rm -f hosts
1675      IGCM_debug_Print 1 "sys Obelix, Hosts avaible :"
1676      for nodes in `cat hosts.tmp` ; do
1677        host[$i]=$nodes
1678        echo "${host[$i]} slots=1 max_slots=1" >> hosts
1679        IGCM_debug_Print 1 ${host[$i]}
1680        i=$((i+1))
1681      done
1682      rm -f hosts.tmp
1683
1684      listnodes=${host[*]}
1685
1686      EXECUTION="${HOST_MPIRUN_COMMAND} -hostfile hosts"
1687
1688      # Initialisation
1689
1690      init_node=y
1691      node_num_current=0
1692      start_num=0
1693      init_exec=n
1694
1695      # Test : if oasis is there, we put it at the first position
1696
1697      for comp in ${config_ListOfComponents[*]} ; do
1698
1699        if [ "X${comp}" = "XCPL" ]  ; then
1700
1701          eval ExeNameIn=\${config_Executable_${comp}[0]}
1702          eval ExeNameOut=\${config_Executable_${comp}[1]}
1703
1704          echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1705          echo ""  >> script_${ExeNameOut}.ksh
1706          #echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
1707          #echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
1708          #echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
1709          echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err"  >> script_${ExeNameOut}.ksh
1710          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1711
1712          init_node=n
1713
1714          (( nombre_restant_node = NUM_COREPERNODE - 1 ))
1715          node_num_current=0
1716          node_current=${host[${node_num_current}]}
1717
1718          EXECUTION="${EXECUTION} -H ${node_current} -np 1 ./script_${ExeNameOut}.ksh"
1719
1720          init_exec=y
1721          start_num=1
1722
1723        fi
1724
1725      done
1726
1727      # Then loop on the components (except for oasis)
1728
1729      for comp in ${config_ListOfComponents[*]} ; do
1730
1731        eval ExeNameIn=\${config_Executable_${comp}[0]}
1732        eval ExeNameOut=\${config_Executable_${comp}[1]}
1733
1734        # Only if we really have an executable for the component :
1735        if ( [ "X${ExeNameOut}" != X\"\" ] &&  [ "X${comp}" != "XCPL" ] ) ; then
1736
1737          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1738          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1739
1740          echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1741          # echo "set -vx" >> script_${ExeNameOut}.ksh
1742          echo ""  >> script_${ExeNameOut}.ksh
1743          #echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
1744          #echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
1745          #echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
1746          echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
1747          echo "(( MYMPIRANK = OMPI_COMM_WORLD_RANK - ${start_num})) " >>  script_${ExeNameOut}.ksh
1748          echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${MYMPIRANK} 2>out_${ExeNameOut}.err.\${MYMPIRANK}"  >> script_${ExeNameOut}.ksh
1749          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1750
1751          node_num=0
1752
1753          # We define the number of MPI process to be assigned for the component
1754
1755          nombre_restant_comp=${comp_proc_mpi_loc}
1756
1757          # Loop on the allocated nodes
1758
1759          for node in ${listnodes} ; do
1760
1761            # We go to the current node
1762            if [ ${node_num} = ${node_num_current} ] ; then
1763
1764              node_current=${host[${node_num_current}]}
1765
1766              # If first time on the node : initialisation
1767
1768              if [ ${init_node} = y ] ; then
1769                nombre_restant_node=${NUM_COREPERNODE}
1770              fi
1771
1772              # Test on the number of OMP threads
1773
1774              if [ ${comp_proc_omp_loc} -gt ${nombre_restant_node} ] ; then
1775                (( node_num = node_num + 1 ))
1776                node_num_current=${node_num}
1777                init_node=y
1778                continue
1779              fi
1780
1781              # Number of MPI process to assign
1782
1783              (( num_corempi = nombre_restant_node / comp_proc_omp_loc ))
1784
1785              if [ ${num_corempi} -gt ${nombre_restant_comp} ] ; then
1786                num_corempi=${nombre_restant_comp}
1787              fi
1788
1789              (( nombre_restant_node = nombre_restant_node - num_corempi * comp_proc_omp_loc ))
1790              (( nombre_restant_comp = nombre_restant_comp - num_corempi ))
1791
1792              if [ ${init_exec} = y ] ; then
1793                EXECUTION="${EXECUTION} : -H ${node_current} -np ${num_corempi} ./script_${ExeNameOut}.ksh"
1794              else
1795                EXECUTION="${EXECUTION} -H ${node_current} -np ${num_corempi} ./script_${ExeNameOut}.ksh"
1796                init_exec=y
1797              fi
1798
1799              ((  start_num = num_corempi + start_num ))
1800
1801            else
1802
1803              (( node_num = node_num + 1 ))
1804              continue
1805            fi
1806
1807            # Test on the number of core/process remaining on the node/component
1808
1809            if [ ${nombre_restant_node} = 0 ] ; then
1810              (( node_num = node_num + 1 ))
1811              node_num_current=${node_num}
1812              init_node=y
1813
1814              if [ ${nombre_restant_comp} = 0 ] ; then
1815                break 1
1816              fi
1817            else
1818
1819              node_num_current=${node_num}
1820              init_node=n
1821
1822              if [ ${nombre_restant_comp} = 0 ] ; then
1823                break 1
1824              fi
1825            fi
1826          done
1827        fi
1828      done
1829
1830    else
1831
[664]1832      # Then first loop on the components for the coupler ie oasis
[657]1833
[664]1834      ## the coupler ie oasis must be the first one
1835      for comp in ${config_ListOfComponents[*]} ; do
[657]1836
[664]1837        eval ExeNameOut=\${config_Executable_${comp}[1]}
[657]1838
1839        # for CPL component only
[664]1840        if [ "X${comp}" = "XCPL" ] ; then
1841          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1842          echo "-np ${comp_proc_mpi_loc} ./${ExeNameOut} " >> run_file
1843        fi
1844      done
[657]1845
[811]1846      # Then second loop on the components
[657]1847
[664]1848      for comp in ${config_ListOfComponents[*]} ; do
[657]1849
[664]1850        eval ExeNameOut=\${config_Executable_${comp}[1]}
[657]1851
[664]1852        # Only if we really have an executable for the component and not the coupler ie oasis:
1853        if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${comp}" != "XCPL" ] ) ; then
1854          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1855          echo "-np ${comp_proc_mpi_loc} ./${ExeNameOut}" >> run_file
1856        fi
1857      done
1858      IGCM_sys_Chmod u+x run_file
[657]1859
[664]1860      EXECUTION="${HOST_MPIRUN_COMMAND} --app ./run_file"
[657]1861
[16]1862    fi
1863
[657]1864  else # Only one executable. launch it.
1865
[664]1866    for comp in ${config_ListOfComponents[*]} ; do
[657]1867
[664]1868      # Only if we really have an executable for the component :
1869      eval ExeNameOut=\${config_Executable_${comp}[1]}
1870      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${ExeNameOut}" != "Xinca.dat" ] ) ; then
[657]1871
[664]1872        echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1873        echo ""  >> script_${ExeNameOut}.ksh
1874        if ( ${OK_PARA_OMP} ) ; then
1875          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1876          echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
1877        fi
1878        if  ( ${OK_PARA_MPI} ) ; then
1879          # Default : mpirun used if nb_proc gt 1
1880          # pour sortie out/err par process
1881          # echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${OMPI_COMM_WORLD_RANK} 2>out_${ExeNameOut}.err.\${OMPI_COMM_WORLD_RANK}"  >> script_${ExeNameOut}.ksh
1882          echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1883          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1884          EXECUTION="${HOST_MPIRUN_COMMAND} ./script_${ExeNameOut}.ksh"
1885        else
1886          # Default : mpirun is NOT used if nb_proc eq 1
1887          # pour sortie out/err par process
1888          # echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err" >> script_${ExeNameOut}.ksh
1889          echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1890          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1891          EXECUTION="time ./script_${ExeNameOut}.ksh"
1892        fi
1893      fi
1894    done
[657]1895
1896  fi
1897
[811]1898  IGCM_debug_Print 1 "sys Obelix : execution command is"
1899  IGCM_debug_Print 1 "$EXECUTION"
[657]1900
1901  IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
[16]1902}
1903
[657]1904############################################################
[811]1905# Check of space available on temporary filesytems. Dummy function here
1906
1907#D-#==================================================
1908#D-function IGCM_sys_check_quota. Dummy call here
1909#D-* Purpose: check user quota. Stop the simulation if quota above 90%
1910#D-* Examples:
1911#D-
[657]1912function IGCM_sys_check_quota {
1913  IGCM_debug_PushStack "IGCM_sys_check_quota"
1914  if ( $DEBUG_sys ) ; then
1915    echo "IGCM_sys_check_quota"
1916  fi
1917  IGCM_debug_PopStack "IGCM_sys_check_quota"
1918}
1919
[811]1920#D-#==================================================
1921#D-function IGCM_sys_CountJobInQueue
1922#D-* Purpose: Check if job_name is currently
1923#D-  running or in queue
1924#D-* Examples: IGCM_sys_CountJobInQueue ${JobName} NbRun
1925#D-
1926function IGCM_sys_CountJobInQueue {
1927  IGCM_debug_PushStack "IGCM_sys_CountJobInQueue"
1928  if ( $DEBUG_sys ) ; then
1929    echo "IGCM_sys_CountJobInQueue"
1930  fi
1931  IGCM_debug_PopStack "IGCM_sys_CountJobInQueue"
1932}
1933
[16]1934##############################################################
1935# NCO OPERATOR
1936
[811]1937#D-#==================================================
1938#D-function IGCM_sys_ncap2
1939#D-* Purpose: encapsulate ncap2 call so as to manage error code and retry
1940#D-* Examples:
1941#D-
[377]1942function IGCM_sys_ncap2 {
[657]1943  IGCM_debug_PushStack "IGCM_sys_ncap2" -- $@
1944  if ( $DEBUG_sys ) ; then
1945    echo "IGCM_sys_ncap2 :" $@
1946  fi
[714]1947
1948  typeset NB_ESSAI DELAI status i
1949  # number of tentative
1950  NB_ESSAI=3
1951  # time delay between tentative
1952  DELAI=2
1953
1954  i=0
1955  while [ $i -lt $NB_ESSAI ] ; do
1956    ncap2 "$@" > out_rsync 2>&1
1957    status=$?
1958    if [ ${status} -gt 0 ] ; then
1959      IGCM_debug_Print 2 "IGCM_sys_ncap2 : error code ${status}"
1960      cat out_rsync
1961      \rm out_rsync
1962      IGCM_debug_Print 2 "IGCM_sys_ncap2 : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
[800]1963      sleep $DELAI
[714]1964    else
1965      \rm out_rsync
1966      break
1967    fi
1968    (( i = i + 1 ))
1969  done
1970
1971  if [ ${status} -gt 0 ] ; then
[811]1972    echo "IGCM_sys_ncap2 : ncap2 error"
1973    IGCM_debug_Exit "ncap2"
[657]1974  fi
[16]1975
[657]1976  IGCM_debug_PopStack "IGCM_sys_ncap2"
[16]1977}
1978
[811]1979#D-#==================================================
1980#D-function IGCM_sys_ncatted
1981#D-* Purpose: encapsulate ncatted call so as to manage error code and retry
1982#D-* Examples:
1983#D-
[375]1984function IGCM_sys_ncatted {
[657]1985  IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
1986  if ( $DEBUG_sys ) ; then
1987    echo "IGCM_sys_ncatted :" $@
1988  fi
[714]1989
1990  typeset NB_ESSAI DELAI status i
1991  # number of tentative
1992  NB_ESSAI=3
1993  # time delay between tentative
1994  DELAI=2
1995
1996  i=0
1997  while [ $i -lt $NB_ESSAI ] ; do
1998    ncatted "$@" > out_rsync 2>&1
1999    status=$?
2000    if [ ${status} -gt 0 ] ; then
2001      IGCM_debug_Print 2 "IGCM_sys_ncatted : error code ${status}"
2002      cat out_rsync
2003      \rm out_rsync
2004      IGCM_debug_Print 2 "IGCM_sys_ncatted : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
[800]2005      sleep $DELAI
[714]2006    else
2007      \rm out_rsync
2008      break
2009    fi
2010    (( i = i + 1 ))
2011  done
2012
2013  if [ ${status} -gt 0 ] ; then
[811]2014    echo "IGCM_sys_ncatted : ncatted error"
2015    IGCM_debug_Exit "ncatted"
[657]2016  fi
[16]2017
[657]2018  IGCM_debug_PopStack "IGCM_sys_ncatted"
[375]2019}
[16]2020
[811]2021#D-#==================================================
2022#D-function IGCM_sys_ncbo
2023#D-* Purpose: encapsulate ncbo call so as to manage error code and retry
2024#D-* Examples:
2025#D-
[16]2026function IGCM_sys_ncbo {
[657]2027  IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
2028  if ( $DEBUG_sys ) ; then
2029    echo "IGCM_sys_ncbo :" $@
2030  fi
[714]2031
2032  typeset NB_ESSAI DELAI status i
2033  # number of tentative
2034  NB_ESSAI=3
2035  # time delay between tentative
2036  DELAI=2
2037
2038  i=0
2039  while [ $i -lt $NB_ESSAI ] ; do
2040    ncbo $@ > out_rsync 2>&1
2041    status=$?
2042    if [ ${status} -gt 0 ] ; then
2043      IGCM_debug_Print 2 "IGCM_sys_ncbo : error code ${status}"
2044      cat out_rsync
2045      \rm out_rsync
2046      IGCM_debug_Print 2 "IGCM_sys_ncbo : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
[800]2047      sleep $DELAI
[714]2048    else
2049      \rm out_rsync
2050      break
2051    fi
2052    (( i = i + 1 ))
2053  done
2054
2055  if [ ${status} -gt 0 ] ; then
[811]2056    echo "IGCM_sys_ncbo : ncbo error"
2057    IGCM_debug_Exit "ncbo"
[657]2058  fi
[16]2059
[657]2060  IGCM_debug_PopStack "IGCM_sys_ncbo"
[16]2061}
2062
[811]2063#D-#==================================================
2064#D-function IGCM_sys_ncdif
2065#D-* Purpose: encapsulate ncdiff call so as to manage error code and retry
2066#D-* Examples:
2067#D-
[16]2068function IGCM_sys_ncdiff {
[657]2069  IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
2070  if ( $DEBUG_sys ) ; then
2071    echo "IGCM_sys_ncdiff :" $@
2072  fi
[714]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    ncdiff $@ > out_rsync 2>&1
2083    status=$?
2084    if [ ${status} -gt 0 ] ; then
2085      IGCM_debug_Print 2 "IGCM_sys_ncdiff : error code ${status}"
2086      cat out_rsync
2087      \rm out_rsync
2088      IGCM_debug_Print 2 "IGCM_sys_ncdiff : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
[800]2089      sleep $DELAI
[714]2090    else
2091      \rm out_rsync
2092      break
2093    fi
2094    (( i = i + 1 ))
2095  done
2096
2097  if [ ${status} -gt 0 ] ; then
[811]2098    echo "IGCM_sys_ncdiff : ncdiff error"
2099    IGCM_debug_Exit "ncdiff"
[657]2100  fi
[16]2101
[657]2102  IGCM_debug_PopStack "IGCM_sys_ncdiff"
[16]2103}
2104
[811]2105#D-#==================================================
2106#D-function IGCM_sys_ncea
2107#D-* Purpose: encapsulate ncea call so as to manage error code and retry
2108#D-* Examples:
2109#D-
[16]2110function IGCM_sys_ncea {
[657]2111  IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
2112  if ( $DEBUG_sys ) ; then
2113    echo "IGCM_sys_ncea :" $@
2114  fi
[714]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    ncea $@ > out_rsync 2>&1
2125    status=$?
2126    if [ ${status} -gt 0 ] ; then
2127      IGCM_debug_Print 2 "IGCM_sys_ncea : error code ${status}"
2128      cat out_rsync
2129      \rm out_rsync
2130      IGCM_debug_Print 2 "IGCM_sys_ncea : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
[800]2131      sleep $DELAI
[714]2132    else
2133      \rm out_rsync
2134      break
2135    fi
2136    (( i = i + 1 ))
2137  done
2138
2139  if [ ${status} -gt 0 ] ; then
[811]2140    echo "IGCM_sys_ncea : ncea error"
2141    IGCM_debug_Exit "ncea"
[657]2142  fi
[16]2143
[657]2144  IGCM_debug_PopStack "IGCM_sys_ncea"
[16]2145}
2146
[811]2147#D-#==================================================
2148#D-function IGCM_sys_ncecat
2149#D-* Purpose: encapsulate ncecat call so as to manage error code and retry
2150#D-* Examples:
2151#D-
[16]2152function IGCM_sys_ncecat {
[657]2153  IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
2154  if ( $DEBUG_sys ) ; then
2155    echo "IGCM_sys_ncecat :" $@
2156  fi
[714]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    ncecat $@ > out_rsync 2>&1
2167    status=$?
2168    if [ ${status} -gt 0 ] ; then
2169      IGCM_debug_Print 2 "IGCM_sys_ncecat : error code ${status}"
2170      cat out_rsync
2171      \rm out_rsync
2172      IGCM_debug_Print 2 "IGCM_sys_ncecat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
[800]2173      sleep $DELAI
[714]2174    else
2175      \rm out_rsync
2176      break
2177    fi
2178    (( i = i + 1 ))
2179  done
2180
2181  if [ ${status} -gt 0 ] ; then
[811]2182    echo "IGCM_sys_ncecat : ncecat error"
2183    IGCM_debug_Exit "ncecat"
[657]2184  fi
[16]2185
[657]2186  IGCM_debug_PopStack "IGCM_sys_ncecat"
[16]2187}
2188
[811]2189#D-#==================================================
2190#D-function IGCM_sys_ncflint
2191#D-* Purpose: encapsulate ncflint call so as to manage error code and retry
2192#D-* Examples:
2193#D-
[16]2194function IGCM_sys_ncflint {
[657]2195  IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
2196  if ( $DEBUG_sys ) ; then
2197    echo "IGCM_sys_ncflint :" $@
2198  fi
[714]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    ncflint $@ > out_rsync 2>&1
2209    status=$?
2210    if [ ${status} -gt 0 ] ; then
2211      IGCM_debug_Print 2 "IGCM_sys_ncflint : error code ${status}"
2212      cat out_rsync
2213      \rm out_rsync
2214      IGCM_debug_Print 2 "IGCM_sys_ncflint : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
[800]2215      sleep $DELAI
[714]2216    else
2217      \rm out_rsync
2218      break
2219    fi
2220    (( i = i + 1 ))
2221  done
2222
2223  if [ ${status} -gt 0 ] ; then
[811]2224    echo "IGCM_sys_ncflint : ncflint error"
2225    IGCM_debug_Exit "ncflint"
[657]2226  fi
[16]2227
[657]2228  IGCM_debug_PopStack "IGCM_sys_ncflint"
[16]2229}
2230
[811]2231#D-#==================================================
2232#D-function IGCM_sys_ncks
2233#D-* Purpose: encapsulate ncks call so as to manage error code and retry
2234#D-* Examples:
2235#D-
[16]2236function IGCM_sys_ncks {
[657]2237  IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
2238  if ( $DEBUG_sys ) ; then
2239    echo "IGCM_sys_ncks :" $@
2240  fi
[714]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    ncks $@ > out_rsync 2>&1
2251    status=$?
2252    if [ ${status} -gt 0 ] ; then
2253      IGCM_debug_Print 2 "IGCM_sys_ncks : error code ${status}"
2254      cat out_rsync
2255      \rm out_rsync
2256      IGCM_debug_Print 2 "IGCM_sys_ncks : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
[800]2257      sleep $DELAI
[714]2258    else
2259      \rm out_rsync
2260      break
2261    fi
2262    (( i = i + 1 ))
2263  done
2264
2265  if [ ${status} -gt 0 ] ; then
[811]2266    echo "IGCM_sys_ncks : ncks error"
2267    IGCM_debug_Exit "ncks"
[657]2268  fi
[16]2269
[657]2270  IGCM_debug_PopStack "IGCM_sys_ncks"
[16]2271}
2272
[811]2273#D-#==================================================
2274#D-function IGCM_sys_ncpdq
2275#D-* Purpose: encapsulate ncpdq call so as to manage error code and retry
2276#D-* Examples:
2277#D-
[16]2278function IGCM_sys_ncpdq {
[657]2279  IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
2280  if ( $DEBUG_sys ) ; then
2281    echo "IGCM_sys_ncpdq :" $@
2282  fi
[714]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    ncpdq $@ > out_rsync 2>&1
2293    status=$?
2294    if [ ${status} -gt 0 ] ; then
2295      IGCM_debug_Print 2 "IGCM_sys_ncpdq : error code ${status}"
2296      cat out_rsync
2297      \rm out_rsync
2298      IGCM_debug_Print 2 "IGCM_sys_ncpdq : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
[800]2299      sleep $DELAI
[714]2300    else
2301      \rm out_rsync
2302      break
2303    fi
2304    (( i = i + 1 ))
2305  done
2306
2307  if [ ${status} -gt 0 ] ; then
[811]2308    echo "IGCM_sys_ncpdq : ncpdq error"
2309    IGCM_debug_Exit "ncpdq"
[657]2310  fi
[16]2311
[657]2312  IGCM_debug_PopStack "IGCM_sys_ncpdq"
[16]2313}
2314
[811]2315#D-#==================================================
2316#D-function IGCM_sys_ncra
2317#D-* Purpose: encapsulate ncra call so as to manage error code and retry
2318#D-* Examples:
2319#D-
[16]2320function IGCM_sys_ncra {
[657]2321  IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
2322  if ( $DEBUG_sys ) ; then
2323    echo "IGCM_sys_ncra :" $@
2324  fi
[714]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    ncra $@ > out_rsync 2>&1
2335    status=$?
2336    if [ ${status} -gt 0 ] ; then
2337      IGCM_debug_Print 2 "IGCM_sys_ncra : error code ${status}"
2338      cat out_rsync
2339      \rm out_rsync
2340      IGCM_debug_Print 2 "IGCM_sys_ncra : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
[800]2341      sleep $DELAI
[714]2342    else
2343      \rm out_rsync
2344      break
2345    fi
2346    (( i = i + 1 ))
2347  done
2348
2349  if [ ${status} -gt 0 ] ; then
[811]2350    echo "IGCM_sys_ncra : ncra error"
2351    IGCM_debug_Exit "ncra"
[657]2352  fi
[16]2353
[657]2354  IGCM_debug_PopStack "IGCM_sys_ncra"
[16]2355}
2356
[811]2357#D-#==================================================
2358#D-function IGCM_sys_ncrcat
2359#D-* Purpose: encapsulate ncrcat call so as to manage error code and retry
2360#D-* Examples:
2361#D-
[16]2362function IGCM_sys_ncrcat {
[657]2363  IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
2364  if ( $DEBUG_sys ) ; then
2365    echo "IGCM_sys_ncrcat :" $@
2366  fi
[714]2367
[811]2368  typeset NB_ESSAI DELAI status i lastArg
[714]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    ncrcat $@ > out_rsync 2>&1
2377    status=$?
2378    if [ ${status} -gt 0 ] ; then
2379      IGCM_debug_Print 2 "IGCM_sys_ncrcat : error code ${status}"
2380      cat out_rsync
2381      \rm out_rsync
2382      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
[800]2383      sleep $DELAI
[811]2384    elif [ ! "X$( grep "WARNING Intra-file non-monotonicity" out_rsync )" = "X" ] ; then
2385      IGCM_debug_Print 2 "IGCM_sys_ncrcat : WARNING Intra-file non-monotonicity"
2386      cat out_rsync
2387      # remove files having corrupted time axis
2388      eval lastArg=\${$#}
2389      IGCM_debug_Print 2 "IGCM_sys_ncrcat : Delete ${lastArg}"
2390      \rm ${lastArg}
2391      \rm out_rsync
2392      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2393      sleep $DELAI
[714]2394    else
2395      \rm out_rsync
2396      break
2397    fi
2398    (( i = i + 1 ))
2399  done
2400
2401  if [ ${status} -gt 0 ] ; then
[811]2402    echo "IGCM_sys_ncrcat : ncrcat error"
2403    #IGCM_debug_Exit "ncrcat"
[657]2404  fi
[16]2405
[657]2406  IGCM_debug_PopStack "IGCM_sys_ncrcat"
[16]2407}
2408
[811]2409#D-#==================================================
2410#D-function IGCM_sys_ncrename
2411#D-* Purpose: encapsulate ncrename call so as to manage error code and retry
2412#D-* Examples:
2413#D-
[16]2414function IGCM_sys_ncrename {
[657]2415  IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
2416  if ( $DEBUG_sys ) ; then
2417    echo "IGCM_sys_ncrename :" $@
2418  fi
[714]2419
2420  typeset NB_ESSAI DELAI status i
2421  # number of tentative
2422  NB_ESSAI=3
2423  # time delay between tentative
2424  DELAI=2
2425
2426  i=0
2427  while [ $i -lt $NB_ESSAI ] ; do
2428    ncrename $@ > out_rsync 2>&1
2429    status=$?
2430    if [ ${status} -gt 0 ] ; then
2431      IGCM_debug_Print 2 "IGCM_sys_ncrename : error code ${status}"
2432      cat out_rsync
2433      \rm out_rsync
2434      IGCM_debug_Print 2 "IGCM_sys_ncrename : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
[800]2435      sleep $DELAI
[714]2436    else
2437      \rm out_rsync
2438      break
2439    fi
2440    (( i = i + 1 ))
2441  done
2442
2443  if [ ${status} -gt 0 ] ; then
[811]2444    echo "IGCM_sys_ncrename : ncrename error"
2445    IGCM_debug_Exit "ncrename"
[657]2446  fi
[16]2447
[657]2448  IGCM_debug_PopStack "IGCM_sys_ncrename"
[16]2449}
2450
[811]2451#D-#==================================================
2452#D-function IGCM_sys_ncwa
2453#D-* Purpose: encapsulate ncwa call so as to manage error code and retry
2454#D-* Examples:
2455#D-
[16]2456function IGCM_sys_ncwa {
[657]2457  IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
2458  if ( $DEBUG_sys ) ; then
2459    echo "IGCM_sys_ncwa :" $@
2460  fi
[714]2461
2462  typeset NB_ESSAI DELAI status i
2463  # number of tentative
2464  NB_ESSAI=3
2465  # time delay between tentative
2466  DELAI=2
2467
2468  i=0
2469  while [ $i -lt $NB_ESSAI ] ; do
2470    ncwa $@ > out_rsync 2>&1
2471    status=$?
2472    if [ ${status} -gt 0 ] ; then
2473      IGCM_debug_Print 2 "IGCM_sys_ncwa : error code ${status}"
2474      cat out_rsync
2475      \rm out_rsync
2476      IGCM_debug_Print 2 "IGCM_sys_ncwa : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
[800]2477      sleep $DELAI
[714]2478    else
2479      \rm out_rsync
2480      break
2481    fi
2482    (( i = i + 1 ))
2483  done
2484
2485  if [ ${status} -gt 0 ] ; then
[811]2486    echo "IGCM_sys_ncwa : ncwa error"
2487    IGCM_debug_Exit "ncwa"
[657]2488  fi
[16]2489
[657]2490  IGCM_debug_PopStack "IGCM_sys_ncwa"
[16]2491}
2492
[284]2493##############################################################
2494# CDO OPERATOR
2495
[811]2496#D-#==================================================
2497#D-function IGCM_sys_cdo
2498#D-* Purpose: encapsulate cdo call so as to manage error code and retry
2499#D-* Examples:
2500#D-
[284]2501function IGCM_sys_cdo {
[657]2502  IGCM_debug_PushStack "IGCM_sys_cdo" -- $@
[714]2503  if ( $DEBUG_sys ) ; then
2504    echo "IGCM_sys_cdo :" $@
2505  fi
[284]2506
[714]2507  typeset status
2508
2509  \cdo $@ > out_rsync 2>&1
2510  status=$?
2511  if [ ${status} -gt 0 ] ; then
2512    echo "IGCM_sys_cdo : error code ${status}"
2513    cat out_rsync
2514    \rm out_rsync
[284]2515    IGCM_debug_PopStack "IGCM_sys_cdo"
[657]2516    return 1
2517  else
2518    IGCM_debug_PopStack "IGCM_sys_cdo"
2519    return 0
2520  fi
[284]2521
[657]2522  IGCM_debug_PopStack "IGCM_sys_cdo"
[16]2523}
Note: See TracBrowser for help on using the repository browser.