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
Line 
1#!/bin/ksh
2
3#**************************************************************
4# Author: Sebastien Denvil, Martial Mancip, Christian Laguerre
5# Contact: Martial.Mancip__at__ipsl.jussieu.fr
6# $Revision::                                          $ Revision of last commit
7# $Author::                                            $ Author of last commit
8# $Date::                                              $ Date of last commit
9# IPSL (2006)
10#  This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC
11#
12#**************************************************************
13
14#=========================================================
15# The documentation of this file can be automatically generated
16# if you use the prefix #D- for comments to be extracted.
17# Extract with command: cat lib* | grep "^#D-" | cut -c "4-"
18#=========================================================
19
20#D-#==================================================
21#D-LibIGCM_sys for obelix
22#D-#==================================================
23#D-
24#D- This ksh library if a layer under some usefull
25#D-environment variables and shell commands.
26#D-All those definitions depend on host particularities.
27#D-It manages a stack mechanism and test validity of operations.
28#D-All function described bellow must be prefixed by IGCM_sys.
29
30#====================================================
31# libIGCM_sys PARAMETERS
32#====================================================
33
34#====================================================
35# set DEBUG_sys to true to output calls of function
36typeset -r DEBUG_sys=${DEBUG_sys:=true}
37
38#====================================================
39# Turn in dry run mode ? (sys_Put_Rest, sys_Put_Out, sys_Get)
40typeset -r DRYRUN=${DRYRUN:=0}
41
42# YOU MUST COMPILE YOUR EXE FILES FOR DRYRUN MODE !
43# -------------------------------------------------------------------------------------
44# | DRYRUN=  |  Date computations, | sys_Get    |  Exe    | sys_Put_Out; sys_Put_Rest |
45# |          |  Cp/Exe/param/files |            |         |                           |
46# |          |  Chmod Qsub         |            |         |                           |
47# -------------------------------------------------------------------------------------
48# |    0     |       yes           |    yes     |  yes    |      yes                  |
49# -------------------------------------------------------------------------------------
50# |    1     |       yes           |    yes     |  yes    |      no                   |
51# -------------------------------------------------------------------------------------
52# |    2     |       yes           |    yes     |  no     |      no                   |
53# -------------------------------------------------------------------------------------
54# |    3     |       yes           |    no      |  no     |      no                   |
55# -------------------------------------------------------------------------------------
56
57#=====================================================
58# Global Variables :
59#=====================================================
60# Language : "fr" or "en"
61typeset -r MYLANG="fr"
62
63#=====================================================
64# Host and user names
65# $hostname ou hostname
66typeset  HOST=${HOST:=$( hostname )}
67# $username ou whoami
68typeset  LOGIN=${LOGIN:=$( whoami )}
69# $hostname of the MASTER job
70typeset MASTER=${MASTER:=$( hostname )}
71
72#D-
73#D-#==================================================
74#D-Program used in libIGCM
75#D-#==================================================
76
77# Submit command
78typeset SUBMIT=${SUBMIT:=qsub}
79# rsync with path
80typeset -r RSYNC=/usr/bin/rsync
81# RSYNC_opt args to rsync
82typeset -r RSYNC_opt="-va"
83# ie storage filesystem
84typeset -r STOREHOST=${MASTER}
85
86#====================================================
87# Set environment tools (ferret, nco, cdo)
88#====================================================
89. /home/users/brock/.atlas_env_asterix_ksh
90
91#====================================================
92# Set lf95 environment
93#====================================================
94. /usr/local/install/lf6481/bash_laheyfort_setup
95
96#====================================================
97# Host specific DIRECTORIES
98#====================================================
99
100#====================================================
101#- MirrorlibIGCM for frontend
102typeset -r MirrorlibIGCM=${MirrorlibIGCM:=false}
103
104#====================================================
105#- libIGCM_POST for frontend
106typeset -r libIGCM_POST=${libIGCM}
107
108#====================================================
109#- R_EXE   (==> BIN_DIR = ${MODIPSL}/bin )
110typeset -r R_EXE="${MODIPSL}/bin"
111
112#====================================================
113#- SUBMIT_DIR : submission dir
114if [ X${PBS_O_WORKDIR} != X ] ; then
115  typeset -r SUBMIT_DIR=${SUBMIT_DIR:=${PBS_O_WORKDIR}}
116else
117  typeset -r SUBMIT_DIR=${SUBMIT_DIR:=${PWD}}
118fi
119
120#====================================================
121#- IN
122typeset -r R_IN=${R_IN:=/home/orchidee01/mmancip/IGCM}
123
124#====================================================
125#- ARCHIVE
126typeset ARCHIVE=${ARCHIVE:=/home/scratch01/${LOGIN}}
127
128#====================================================
129#- STORAGE (dedicated to small/medium files)
130typeset STORAGE=${ARCHIVE}
131
132#====================================================
133#- R_OUT
134typeset R_OUT=${ARCHIVE}/IGCM_OUT
135
136#====================================================
137#- R_FIG (hosting figures : monitoring and atlas, and/or small files)
138typeset R_FIG=${STORAGE}/IGCM_OUT
139
140#====================================================
141#- R_BUF (ONLY FOR double copy an scratch)
142typeset -r R_BUF=${STORAGE}/IGCM_OUT
143
144#====================================================
145#- RUN_DIR_PATH : Temporary working directory (=> TMP)
146typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=/scratch/$PBS_O_LOGNAME.$PBS_JOBID}
147
148#====================================================
149#- HOST_MPIRUN_COMMAND
150typeset -r HOST_MPIRUN_COMMAND=${HOST_MPIRUN_COMMAND:="time mpirun"}
151
152#====================================================
153#- Max number of arguments passed to nco operator or demigration command
154UNIX_MAX_LIMIT=360
155
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
169#D-#==================================================
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-#==================================================
179#D-function IGCM_sys_RshMaster
180#D-* Purpose: Connection to frontend machine.
181#D-* Examples:
182#D-
183function IGCM_sys_RshMaster {
184  IGCM_debug_PushStack "IGCM_sys_RshMaster" $@
185  ssh obelix3 /bin/ksh  <<-EOF
186    export libIGCM=${libIGCM}
187    export DEBUG_debug=${DEBUG_debug}
188    . ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh
189    . ${libIGCM}/libIGCM_card/libIGCM_card.ksh
190    ${@}
191EOF
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"
197}
198
199#D-#==================================================
200#D-function IGCM_sys_RshArchive
201#D-* Purpose: Archive rsh command
202#D-* Examples:
203#D-
204function IGCM_sys_RshArchive {
205  IGCM_debug_PushStack "IGCM_sys_RshArchive" $@
206  /bin/ksh <<-EOF
207    ${@}
208EOF
209  status=$?
210  if [ ${status} -gt 0 ] ; then
211    IGCM_debug_Print 2 "IGCM_sys_RshArchive : command failed error code ${status}"
212    IGCM_debug_Exit "IGCM_sys_RshArchive"
213  fi
214  IGCM_debug_PopStack "IGCM_sys_RshArchive"
215}
216
217#D-#==================================================
218#D-function IGCM_sys_RshPost
219#D-* Purpose: Post-process rsh command
220#D-* Examples:
221#D-
222function IGCM_sys_RshPost {
223  IGCM_debug_PushStack "IGCM_sys_RshPost" $@
224  if ( $DEBUG_sys ) ; then
225    echo "IGCM_sys_RshPost :" $@
226  fi
227
228  # keep standard input (stdin) for the loop onto temporary file
229  cat >tmp_IGCM_sys_RshPost_$$
230
231# ============ FRONTEND START ============ #
232
233  ssh obelix3 exec /bin/ksh <tmp_IGCM_sys_RshPost_$$
234  if [ $? -gt 0 ] ; then
235    echo "IGCM_sys_RshPost : erreur."
236    IGCM_debug_Exit "IGCM_sys_RshPost"
237  fi
238  # delete temporary file
239  \rm tmp_IGCM_sys_RshPost_$$
240  IGCM_debug_PopStack "IGCM_sys_RshPost"
241}
242
243#D-#==================================================
244#D-function IGCM_sys_SendMail
245#D-* Purpose: Send mail when simulation is over
246#D-* Examples:
247#D-
248function IGCM_sys_SendMail {
249  IGCM_debug_PushStack "IGCM_sys_SendMail" $@
250  if ( $DEBUG_sys ) ; then
251    echo "IGCM_sys_SendMail :" $@
252  fi
253
254  if ( ${ExitFlag} ) ; then
255    status=failed
256  else
257    status=completed
258  fi
259
260  cat  << END_MAIL > job_end.mail
261Dear ${LOGIN},
262
263  Simulation ${config_UserChoices_JobName} is ${status} on supercomputer `hostname`.
264  Job started : ${DateBegin}
265  Job ended   : ${DateEnd}
266  Output files are available in ${R_SAVE}
267  Files to be rebuild are temporarily available in ${REBUILD_DIR}
268  Pre-packed files are temporarily available in ${R_BUFR}
269  Script files, Script Outputs and Debug files (if necessary) are available in ${SUBMIT_DIR}
270END_MAIL
271
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
277
278  sleep 10
279  rm -f job_end.mail
280
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"
286}
287
288#D-#==================================================
289#D-function IGCM_sys_Mkdir
290#D-* Purpose: Master locale mkdir command
291#D-* Examples:
292#D-
293function IGCM_sys_Mkdir {
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"
303    fi
304  fi
305  # vérification :
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"
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 {
319  IGCM_debug_PushStack "IGCM_sys_MkdirArchive" $@
320  if ( $DEBUG_sys ) ; then
321    echo "IGCM_sys_MkdirArchive :" $@
322  fi
323  #- creation de repertoire sur le serveur fichier
324  if [ ! -d ${1} ]; then
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}"
330      IGCM_debug_Exit "IGCM_sys_MkdirArchive"
331    fi
332  fi
333  IGCM_debug_PopStack "IGCM_sys_MkdirArchive"
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 {
342  IGCM_debug_PushStack "IGCM_sys_MkdirWork" $@
343  if ( $DEBUG_sys ) ; then
344    echo "IGCM_sys_MkdirWork :" $@
345  fi
346  #- creation de repertoire sur le serveur fichier
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"
352    fi
353  fi
354  IGCM_debug_PopStack "IGCM_sys_MkdirWork"
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 {
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"
373}
374
375#D-#==================================================
376#D-function IGCM_sys_Chmod
377#D-* Purpose: Chmod
378#D-* Examples:
379#D-
380function IGCM_sys_Chmod {
381  IGCM_debug_PushStack "IGCM_sys_Chmod" -- $@
382  if ( $DEBUG_sys ) ; then
383    echo "IGCM_sys_Chmod :" $@
384  fi
385  \chmod $@
386  if [ $? -gt 0 ] ; then
387    echo "IGCM_sys_Chmod : erreur."
388    IGCM_debug_Exit "IGCM_sys_Chmod"
389  fi
390  IGCM_debug_PopStack "IGCM_sys_Chmod"
391}
392
393#D-#==================================================
394#D-function IGCM_sys_FileSize
395#D-* Purpose: Filesize
396#D-* Examples:
397#D-
398function IGCM_sys_FileSize {
399  IGCM_debug_PushStack "IGCM_sys_FileSize" $@
400
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]}
407
408  IGCM_debug_PopStack "IGCM_sys_FileSize"
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 {
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"
424
425  return ${ExistFlag}
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 {
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}
442}
443
444#D-#==================================================
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-#==================================================
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 {
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"
472
473  return ${ExistFlag}
474}
475
476#D-#==================================================
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-#==================================================
491#D-function IGCM_sys_CountFileArchive
492#D-* Purpose: Count files on Archive filesystem
493#D-* Examples:
494#D-
495function IGCM_sys_CountFileArchive {
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"
502}
503
504#D-#==================================================
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-#==================================================
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 {
524  IGCM_debug_PushStack "IGCM_sys_Tree" $@
525  if ( $DEBUG_sys ) ; then
526    echo "IGCM_sys_Tree :" $@
527  fi
528
529  \tree -f $@
530
531  IGCM_debug_PopStack "IGCM_sys_Tree"
532}
533
534#D-#==================================================
535#D-function IGCM_sys_Tar
536#D-* Purpose: master tar command
537#D-* Examples:
538#D-
539function IGCM_sys_Tar {
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"
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 {
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"
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 {
576  IGCM_debug_PushStack "IGCM_sys_Qsub" $@
577  if ( $DEBUG_sys ) ; then
578    echo "IGCM_sys_Qsub :" $@
579  fi
580  typeset status
581  /usr/local/bin/qsub -q medium -o ${Script_Output} -N ${config_UserChoices_JobName}.${CumulPeriod} < $1
582  status=$?
583  if [ ${status} -gt 0 ] ; then
584    IGCM_debug_Print 2 "IGCM_sys_Qsub $1 : error code ${status}"
585    IGCM_debug_Exit "IGCM_sys_Qsub"
586  fi
587  IGCM_debug_PopStack "IGCM_sys_Qsub"
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 {
596  IGCM_debug_PushStack "IGCM_sys_QsubPost" $@
597  if ( $DEBUG_sys ) ; then
598    echo "IGCM_sys_QsubPost :" $@
599  fi
600  typeset status
601  /usr/local/bin/qsub -q medium -o ${POST_DIR}/${Script_Post_Output}.out ${libIGCM_POST}/$1.job -v ${listVarEnv}
602  status=$?
603  if [ ${status} -gt 0 ] ; then
604    IGCM_debug_Print 2 "IGCM_sys_QsubPost $1 : error code ${status}"
605    IGCM_debug_Exit "IGCM_sys_QsubPost"
606  fi
607  IGCM_debug_PopStack "IGCM_sys_QsubPost"
608}
609
610#D-*************************
611#D- File transfer functions
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 {
621  status=$1
622  if [ ! $status ] ; then
623    echo "rsync error !"
624  fi
625
626  if [ $MYLANG = "fr" ]; then
627    case $status in
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;;
675    *)  echo "Erreur de rsync : code de retour de rsync inconnu :" $status
676      return;;
677    esac
678  elif [ $MYLANG = "en" ] ; then
679    case $status in
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;;
716    *)  echo "rsync error : return code of rsync unknown :" $status
717      return;;
718    esac
719  else
720    echo "unknown language $MYLANG."
721    return
722  fi
723}
724
725#D-#==================================================
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-#==================================================
752#D-function IGCM_sys_Cp
753#D-* Purpose: generic cp
754#D-* Examples:
755#D-
756function IGCM_sys_Cp {
757  IGCM_debug_PushStack "IGCM_sys_Cp" $@
758  if ( $DEBUG_sys ) ; then
759    echo "IGCM_sys_Cp :" $@
760  fi
761
762  typeset status
763
764  echo cp $@ > out_rsync 2>&1
765  \cp $@ >> out_rsync 2>&1
766  status=$?
767
768  if [ ${status} -gt 0 ] ; then
769    echo "IGCM_sys_Cp : error code ${status}"
770    cat out_rsync
771    IGCM_debug_Exit "IGCM_sys_Cp"
772  else
773    \rm out_rsync
774  fi
775  IGCM_debug_PopStack "IGCM_sys_Cp"
776}
777
778#D-#==================================================
779#D-function IGCM_sys_Rm
780#D-* Purpose: generic rm
781#D-* Examples:
782#D-
783function IGCM_sys_Rm {
784  IGCM_debug_PushStack "IGCM_sys_Rm" -- $@
785  if ( $DEBUG_sys ) ; then
786    echo "IGCM_sys_Rm :" $@
787  fi
788
789  typeset status
790
791  echo rm $@ > out_rsync 2>&1
792  \rm $@ >> out_rsync 2>&1
793  status=$?
794
795  if [ ${status} -gt 0 ] ; then
796    echo "IGCM_sys_Rm : error code ${status}"
797    cat out_rsync
798    IGCM_debug_Exit "IGCM_sys_Rm"
799  else
800    \rm out_rsync
801  fi
802  IGCM_debug_PopStack "IGCM_sys_Rm"
803}
804
805#D-#==================================================
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 {
812  IGCM_debug_PushStack "IGCM_sys_RmRunDir" -- $@
813  if ( $DEBUG_sys ) ; then
814    echo "IGCM_sys_RmRunDir :" $@
815  fi
816
817  typeset status
818
819  echo rm $@ > out_rsync 2>&1
820  \rm $@ >> out_rsync 2>&1
821  status=$?
822
823  if [ ${status} -gt 0 ] ; then
824    echo "IGCM_sys_RmRunDir : rm error code is ${status}."
825    cat out_rsync
826    IGCM_debug_Exit "IGCM_sys_RmRunDir"
827  else
828    \rm out_rsync
829  fi
830  IGCM_debug_PopStack "IGCM_sys_RmRunDir"
831}
832
833#D-#==================================================
834#D-function IGCM_sys_Mv
835#D-* Purpose: generic move
836#D-* Examples:
837#D-
838function IGCM_sys_Mv {
839  IGCM_debug_PushStack "IGCM_sys_Mv" $@
840  if ( $DEBUG_sys ) ; then
841    echo "IGCM_sys_Mv :" $@
842  fi
843
844  if [ $DRYRUN = 0 ]; then
845
846    typeset status
847
848    echo mv $@ > out_rsync 2>&1
849    \mv $@ >> out_rsync 2>&1
850    status=$?
851
852    if [ ${status} -gt 0 ] ; then
853      echo "IGCM_sys_Mv : error code ${status}"
854      cat out_rsync
855      IGCM_debug_Exit "IGCM_sys_Mv"
856    else
857      \rm out_rsync
858    fi
859  fi
860  IGCM_debug_PopStack "IGCM_sys_Mv"
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 {
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
878    fi
879
880    typeset status
881
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=$?
888
889    if [ ${status} -gt 0 ] ; then
890      IGCM_debug_Print 2 "IGCM_sys_Put_Dir : cp failed error code ${status}"
891      cat out_rsync
892      IGCM_debug_Exit "IGCM_sys_Put_Dir"
893    else
894      \rm out_rsync
895    fi
896  fi
897  IGCM_debug_PopStack "IGCM_sys_Put_Dir"
898}
899
900#D-#==================================================
901#D-function IGCM_sys_Get_Dir
902#D-* Purpose: Copy a complete directory from ${ARCHIVE}
903#D-* Examples:
904#D-
905function IGCM_sys_Get_Dir {
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
915    fi
916
917    typeset status
918
919    #USUAL WAY
920    \cp -ur $1 $2 > out_rsync 2>&1
921    status=$?
922
923    if [ ${status} -gt 0 ] ; then
924      IGCM_debug_Print 2 "IGCM_sys_Get_Dir : cp failed error code ${status}"
925      cat out_rsync
926      IGCM_debug_Exit "IGCM_sys_Get_Dir"
927    else
928      \rm out_rsync
929    fi
930  fi
931  IGCM_debug_PopStack "IGCM_sys_Get_Dir"
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 {
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
949    fi
950
951    typeset NB_ESSAI DELAI status i
952    # number of tentative
953    NB_ESSAI=3
954    # time delay between tentative
955    DELAI=2
956
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
970
971    if [ ${status} -gt 0 ] ; then
972      echo "IGCM_sys_Get_Master : error."
973      cat out_rsync
974      IGCM_debug_Exit "IGCM_sys_Get_Master"
975    else
976      \rm out_rsync
977    fi
978  fi
979  IGCM_debug_PopStack "IGCM_sys_Get_Master"
980}
981
982#====================================================
983#- Call IGCM_sys_Mirror_libIGCM now !
984if ( $MirrorlibIGCM ) ; then
985  IGCM_sys_Mirror_libIGCM
986fi
987
988#D-#==================================================
989#D-function IGCM_sys_Put_Rest
990#D-* Purpose: Put computied restarts on ${ARCHIVE}.
991#D-           File and target directory must exist.
992#D-* Examples:
993#D-
994function IGCM_sys_Put_Rest {
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"
1003    fi
1004
1005    typeset status
1006    #
1007    if [ X${JobType} = XRUN ] ; then
1008      IGCM_sys_Chmod 444 ${1}
1009    fi
1010    #
1011    # Only if we use rsync
1012    #IGCM_sys_MkdirArchive $( dirname $2 )
1013    #
1014    #USUAL WAY
1015    \cp $1 $2 > out_rsync 2>&1
1016    status=$?
1017
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
1021
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
1025
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}"
1034      cat out_rsync
1035      IGCM_debug_Exit "IGCM_sys_Put_Rest"
1036    else
1037      \rm out_rsync
1038    fi
1039  fi
1040  IGCM_debug_PopStack "IGCM_sys_Put_Rest"
1041}
1042
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
1059
1060    typeset status
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
1069    status=$?
1070
1071    if [ ${status} -gt 0 ] ; then
1072      echo "IGCM_sys_PutBuffer_Rest : error code ${status}"
1073      [ -f ${2} ] && ls -l ${2}
1074      [ -f ${2}/${1} ] && ls -l ${2}/${1}
1075      cat out_rsync
1076      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
1077    else
1078      \rm out_rsync
1079    fi
1080  fi
1081  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Rest"
1082}
1083
1084#D-#==================================================
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-#==================================================
1096#D-function IGCM_sys_Put_Out
1097#D-* Purpose: Copy a file on ${ARCHIVE} after having chmod it in readonly
1098#D-* Examples:
1099#D-
1100function IGCM_sys_Put_Out {
1101  IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
1102  if ( $DEBUG_sys ) ; then
1103    echo "IGCM_sys_Put_Out :" $@
1104  fi
1105
1106  typeset status
1107
1108  if [ $DRYRUN = 0 ]; then
1109    if [ ! -f ${1} ] ; then
1110      echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
1111      IGCM_debug_PopStack "IGCM_sys_Put_Out"
1112      return 1
1113    fi
1114    #
1115    IGCM_sys_MkdirArchive $( dirname $2 )
1116    #
1117    if [ X${JobType} = XRUN ] ; then
1118      if [ X${3} = X ] ; then
1119        IGCM_sys_Chmod 444 ${1}
1120      fi
1121    fi
1122    #
1123
1124    echo ${RSYNC} ${RSYNC_opt} $1 $2 > out_rsync 2>&1
1125    ${RSYNC} ${RSYNC_opt} $1 $2 >> out_rsync 2>&1
1126    status=$?
1127    IGCM_sys_Rsync_out $status
1128
1129    ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1130    (( status=status+$? ))
1131
1132    if [ ${status} -gt 0 ] ; then
1133      IGCM_debug_Print 2 "IGCM_sys_Put_Out : rsync failed error code ${status}"
1134      cat out_rsync
1135      IGCM_debug_Exit "IGCM_sys_Put_Out"
1136    else
1137      \rm out_rsync
1138    fi
1139  fi
1140  IGCM_debug_PopStack "IGCM_sys_Put_Out"
1141  return 0
1142}
1143
1144#D-#==================================================
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
1154
1155  typeset NB_ESSAI DELAI status i exist skip
1156
1157  # number of tentative
1158  NB_ESSAI=3
1159  # time delay between tentative
1160  DELAI=2
1161
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
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
1184      fi
1185    fi
1186    #
1187    if ( [ X${exist} = Xtrue ] && [ X${skip} = Xfalse ] ) ; then
1188      IGCM_sys_Chmod u+w $2
1189    fi
1190
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
1210    if [ ${status} -gt 0 ] ; then
1211      echo "IGCM_sys_PutBuffer_Out : error."
1212      [ -f ${2} ] && ls -l ${2}
1213      [ -f ${2}/${1} ] && ls -l ${2}/${1}
1214      cat out_rsync
1215      IGCM_debug_Exit "IGCM_sys_PutBuffer_Out"
1216    else
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
1225      \rm out_rsync
1226    fi
1227  fi
1228  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1229  return 0
1230}
1231
1232#D-#==================================================
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 {
1238  IGCM_debug_PushStack "IGCM_sys_Get" $@
1239
1240  typeset DEST status dm_liste
1241
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
1247      # test if the first file is present in the old computation :
1248      eval set +A dm_liste \${${2}}
1249    else
1250      dm_liste=${1}
1251    fi
1252    eval DEST=\${${#}}
1253
1254    # test if the (first) file is present in the old computation :
1255    IGCM_sys_TestFileArchive ${dm_liste[0]}
1256    status=$?
1257    if [ ${status} -gt 0 ] ; then
1258      echo "IGCM_sys_Get, ERROR : regular file ${dm_liste[0]} DOES NOT EXIST ."
1259      IGCM_debug_Exit "IGCM_sys_Get"
1260      return
1261    fi
1262
1263    #USUAL WAY
1264    \cp ${dm_liste[*]} ${DEST} > out_rsync 2>&1
1265    status=$?
1266
1267    if [ ${status} -gt 0 ] ; then
1268      IGCM_debug_Print 2 "IGCM_sys_Get : cp failed error code ${status}"
1269      cat out_rsync
1270      IGCM_debug_Exit "IGCM_sys_Get"
1271    else
1272      \rm out_rsync
1273    fi
1274  fi
1275  IGCM_debug_PopStack "IGCM_sys_Get"
1276}
1277
1278#D-#==================================================
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
1286  typeset DEST buf_liste target file_work
1287  typeset NB_ESSAI DELAI status i
1288
1289  if ( $DEBUG_sys ) ; then
1290    echo "IGCM_sys_GetBuffer :" $@
1291  fi
1292
1293  # number of tentative
1294  NB_ESSAI=3
1295  # time delay between tentative
1296  DELAI=2
1297
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} )
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
1332      done
1333    else
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
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
1374  # donne la date filesys d'un fichier sur la machine work
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-#==================================================
1396#D-function IGCM_sys_Dods_Rm
1397#D-* Purpose: DO NOTHING ! Put ${ARCHIVE} files on DODS internet protocole.
1398#D-* Examples:
1399#D-
1400function IGCM_sys_Dods_Rm {
1401  if ( $DEBUG_sys ) ; then
1402    echo "IGCM_sys_Dods_Rm :" $@
1403  fi
1404  return 0
1405}
1406
1407#D-#==================================================
1408#D-function IGCM_sys_Dods_Cp
1409#D-* Purpose: Copy $(ARCHIVE) files on DODS internet protocole.
1410#D-* Examples:
1411#D-
1412function IGCM_sys_Dods_Cp {
1413  if ( $DEBUG_sys ) ; then
1414    echo "IGCM_sys_Dods_Cp :" $@
1415  fi
1416  return 0
1417}
1418
1419#D-#==================================================
1420#D-function IGCM_sys_Put_Dods
1421#D-* Purpose: Put ${ARCHIVE} files on DODS internet protocole. Dummy function here
1422#D-* Examples:
1423#D-
1424function IGCM_sys_Put_Dods {
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"
1430}
1431
1432##############################################################
1433# REBUILD OPERATOR
1434
1435#D-#==================================================
1436#D-function IGCM_sys_rebuild
1437#D-* Purpose: rebuild parallel files
1438#D-* Examples:
1439#D-
1440function IGCM_sys_rebuild {
1441  IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1442  if ( $DEBUG_sys ) ; then
1443    echo "IGCM_sys_rebuild :" $@
1444  fi
1445
1446  typeset NB_ESSAI DELAI status i firstArg
1447  # number of tentative
1448  NB_ESSAI=3
1449  # time delay between tentative
1450  DELAI=2
1451
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
1471  if [ ${status} -gt 0 ] ; then
1472    echo "IGCM_sys_rebuild : rebuild error code is ${status}"
1473    IGCM_debug_Exit "rebuild"
1474  fi
1475
1476  IGCM_debug_PopStack "IGCM_sys_rebuild"
1477}
1478
1479#D-#==================================================
1480#D-function IGCM_sys_rebuild_station
1481#D-* Purpose: rebuild parallel files describing station
1482#D-* Examples:
1483#D-
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
1492  # Invert Axis : t,x -> x,t
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
1555      # Invert Axis : t,x -> x,t
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
1575############################################################
1576# Activate Running Environnment Variables
1577
1578#D-#==================================================
1579#D-function IGCM_sys_desactiv_variables
1580#D-* Purpose: set environement variables prior to execution
1581#D-* Examples:
1582#D-
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
1588
1589# --------------------------------------------------------------------
1590#D- MPI specifications
1591# --------------------------------------------------------------------
1592
1593# --------------------------------------------------------------------
1594#D- Other specifications
1595# --------------------------------------------------------------------
1596
1597  IGCM_debug_PopStack "IGCM_sys_activ_variables"
1598}
1599
1600############################################################
1601# Desactivate Running Environnment Variables
1602
1603#D-#==================================================
1604#D-function IGCM_sys_desactiv_variables
1605#D-* Purpose: unset environement variables after execution
1606#D-* Examples:
1607#D-
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
1613# --------------------------------------------------------------------
1614#D- MPI specifications
1615# --------------------------------------------------------------------
1616
1617# --------------------------------------------------------------------
1618#D- Other specifications
1619# --------------------------------------------------------------------
1620
1621  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1622}
1623
1624############################################################
1625# Build MPI/OMP scripts run file (dummy function)
1626
1627#D-#==================================================
1628#D-function IGCM_sys_build_run_file
1629#D-* Purpose: build run file (deprecated)
1630#D-* Examples:
1631#D-
1632function IGCM_sys_build_run_file {
1633
1634  IGCM_debug_Print 3 " dummy function : IGCM_sys_build_run_file "
1635
1636}
1637
1638############################################################
1639# Build MPI/OMP scripts
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-
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
1657    IGCM_debug_Exit "IGCM_sys_obelix build_execution_scripts : Job_${config_UserChoices_JobName} don't exist in SUBMIT_DIR : ${SUBMIT_DIR} "
1658  fi
1659
1660  if ( ${OK_PARA_MPMD} ) ; then
1661
1662    if [ -f run_file ] ; then
1663      IGCM_sys_Rm -f run_file
1664    fi
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
1832      # Then first loop on the components for the coupler ie oasis
1833
1834      ## the coupler ie oasis must be the first one
1835      for comp in ${config_ListOfComponents[*]} ; do
1836
1837        eval ExeNameOut=\${config_Executable_${comp}[1]}
1838
1839        # for CPL component only
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
1845
1846      # Then second loop on the components
1847
1848      for comp in ${config_ListOfComponents[*]} ; do
1849
1850        eval ExeNameOut=\${config_Executable_${comp}[1]}
1851
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
1859
1860      EXECUTION="${HOST_MPIRUN_COMMAND} --app ./run_file"
1861
1862    fi
1863
1864  else # Only one executable. launch it.
1865
1866    for comp in ${config_ListOfComponents[*]} ; do
1867
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
1871
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
1895
1896  fi
1897
1898  IGCM_debug_Print 1 "sys Obelix : execution command is"
1899  IGCM_debug_Print 1 "$EXECUTION"
1900
1901  IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
1902}
1903
1904############################################################
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-
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
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
1934##############################################################
1935# NCO OPERATOR
1936
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-
1942function IGCM_sys_ncap2 {
1943  IGCM_debug_PushStack "IGCM_sys_ncap2" -- $@
1944  if ( $DEBUG_sys ) ; then
1945    echo "IGCM_sys_ncap2 :" $@
1946  fi
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."
1963      sleep $DELAI
1964    else
1965      \rm out_rsync
1966      break
1967    fi
1968    (( i = i + 1 ))
1969  done
1970
1971  if [ ${status} -gt 0 ] ; then
1972    echo "IGCM_sys_ncap2 : ncap2 error"
1973    IGCM_debug_Exit "ncap2"
1974  fi
1975
1976  IGCM_debug_PopStack "IGCM_sys_ncap2"
1977}
1978
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-
1984function IGCM_sys_ncatted {
1985  IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
1986  if ( $DEBUG_sys ) ; then
1987    echo "IGCM_sys_ncatted :" $@
1988  fi
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."
2005      sleep $DELAI
2006    else
2007      \rm out_rsync
2008      break
2009    fi
2010    (( i = i + 1 ))
2011  done
2012
2013  if [ ${status} -gt 0 ] ; then
2014    echo "IGCM_sys_ncatted : ncatted error"
2015    IGCM_debug_Exit "ncatted"
2016  fi
2017
2018  IGCM_debug_PopStack "IGCM_sys_ncatted"
2019}
2020
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-
2026function IGCM_sys_ncbo {
2027  IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
2028  if ( $DEBUG_sys ) ; then
2029    echo "IGCM_sys_ncbo :" $@
2030  fi
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."
2047      sleep $DELAI
2048    else
2049      \rm out_rsync
2050      break
2051    fi
2052    (( i = i + 1 ))
2053  done
2054
2055  if [ ${status} -gt 0 ] ; then
2056    echo "IGCM_sys_ncbo : ncbo error"
2057    IGCM_debug_Exit "ncbo"
2058  fi
2059
2060  IGCM_debug_PopStack "IGCM_sys_ncbo"
2061}
2062
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-
2068function IGCM_sys_ncdiff {
2069  IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
2070  if ( $DEBUG_sys ) ; then
2071    echo "IGCM_sys_ncdiff :" $@
2072  fi
2073
2074  typeset NB_ESSAI DELAI status i
2075  # number of tentative
2076  NB_ESSAI=3
2077  # time delay between tentative
2078  DELAI=2
2079
2080  i=0
2081  while [ $i -lt $NB_ESSAI ] ; do
2082    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."
2089      sleep $DELAI
2090    else
2091      \rm out_rsync
2092      break
2093    fi
2094    (( i = i + 1 ))
2095  done
2096
2097  if [ ${status} -gt 0 ] ; then
2098    echo "IGCM_sys_ncdiff : ncdiff error"
2099    IGCM_debug_Exit "ncdiff"
2100  fi
2101
2102  IGCM_debug_PopStack "IGCM_sys_ncdiff"
2103}
2104
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-
2110function IGCM_sys_ncea {
2111  IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
2112  if ( $DEBUG_sys ) ; then
2113    echo "IGCM_sys_ncea :" $@
2114  fi
2115
2116  typeset NB_ESSAI DELAI status i
2117  # number of tentative
2118  NB_ESSAI=3
2119  # time delay between tentative
2120  DELAI=2
2121
2122  i=0
2123  while [ $i -lt $NB_ESSAI ] ; do
2124    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."
2131      sleep $DELAI
2132    else
2133      \rm out_rsync
2134      break
2135    fi
2136    (( i = i + 1 ))
2137  done
2138
2139  if [ ${status} -gt 0 ] ; then
2140    echo "IGCM_sys_ncea : ncea error"
2141    IGCM_debug_Exit "ncea"
2142  fi
2143
2144  IGCM_debug_PopStack "IGCM_sys_ncea"
2145}
2146
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-
2152function IGCM_sys_ncecat {
2153  IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
2154  if ( $DEBUG_sys ) ; then
2155    echo "IGCM_sys_ncecat :" $@
2156  fi
2157
2158  typeset NB_ESSAI DELAI status i
2159  # number of tentative
2160  NB_ESSAI=3
2161  # time delay between tentative
2162  DELAI=2
2163
2164  i=0
2165  while [ $i -lt $NB_ESSAI ] ; do
2166    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."
2173      sleep $DELAI
2174    else
2175      \rm out_rsync
2176      break
2177    fi
2178    (( i = i + 1 ))
2179  done
2180
2181  if [ ${status} -gt 0 ] ; then
2182    echo "IGCM_sys_ncecat : ncecat error"
2183    IGCM_debug_Exit "ncecat"
2184  fi
2185
2186  IGCM_debug_PopStack "IGCM_sys_ncecat"
2187}
2188
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-
2194function IGCM_sys_ncflint {
2195  IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
2196  if ( $DEBUG_sys ) ; then
2197    echo "IGCM_sys_ncflint :" $@
2198  fi
2199
2200  typeset NB_ESSAI DELAI status i
2201  # number of tentative
2202  NB_ESSAI=3
2203  # time delay between tentative
2204  DELAI=2
2205
2206  i=0
2207  while [ $i -lt $NB_ESSAI ] ; do
2208    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."
2215      sleep $DELAI
2216    else
2217      \rm out_rsync
2218      break
2219    fi
2220    (( i = i + 1 ))
2221  done
2222
2223  if [ ${status} -gt 0 ] ; then
2224    echo "IGCM_sys_ncflint : ncflint error"
2225    IGCM_debug_Exit "ncflint"
2226  fi
2227
2228  IGCM_debug_PopStack "IGCM_sys_ncflint"
2229}
2230
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-
2236function IGCM_sys_ncks {
2237  IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
2238  if ( $DEBUG_sys ) ; then
2239    echo "IGCM_sys_ncks :" $@
2240  fi
2241
2242  typeset NB_ESSAI DELAI status i
2243  # number of tentative
2244  NB_ESSAI=3
2245  # time delay between tentative
2246  DELAI=2
2247
2248  i=0
2249  while [ $i -lt $NB_ESSAI ] ; do
2250    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."
2257      sleep $DELAI
2258    else
2259      \rm out_rsync
2260      break
2261    fi
2262    (( i = i + 1 ))
2263  done
2264
2265  if [ ${status} -gt 0 ] ; then
2266    echo "IGCM_sys_ncks : ncks error"
2267    IGCM_debug_Exit "ncks"
2268  fi
2269
2270  IGCM_debug_PopStack "IGCM_sys_ncks"
2271}
2272
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-
2278function IGCM_sys_ncpdq {
2279  IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
2280  if ( $DEBUG_sys ) ; then
2281    echo "IGCM_sys_ncpdq :" $@
2282  fi
2283
2284  typeset NB_ESSAI DELAI status i
2285  # number of tentative
2286  NB_ESSAI=3
2287  # time delay between tentative
2288  DELAI=2
2289
2290  i=0
2291  while [ $i -lt $NB_ESSAI ] ; do
2292    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."
2299      sleep $DELAI
2300    else
2301      \rm out_rsync
2302      break
2303    fi
2304    (( i = i + 1 ))
2305  done
2306
2307  if [ ${status} -gt 0 ] ; then
2308    echo "IGCM_sys_ncpdq : ncpdq error"
2309    IGCM_debug_Exit "ncpdq"
2310  fi
2311
2312  IGCM_debug_PopStack "IGCM_sys_ncpdq"
2313}
2314
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-
2320function IGCM_sys_ncra {
2321  IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
2322  if ( $DEBUG_sys ) ; then
2323    echo "IGCM_sys_ncra :" $@
2324  fi
2325
2326  typeset NB_ESSAI DELAI status i
2327  # number of tentative
2328  NB_ESSAI=3
2329  # time delay between tentative
2330  DELAI=2
2331
2332  i=0
2333  while [ $i -lt $NB_ESSAI ] ; do
2334    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."
2341      sleep $DELAI
2342    else
2343      \rm out_rsync
2344      break
2345    fi
2346    (( i = i + 1 ))
2347  done
2348
2349  if [ ${status} -gt 0 ] ; then
2350    echo "IGCM_sys_ncra : ncra error"
2351    IGCM_debug_Exit "ncra"
2352  fi
2353
2354  IGCM_debug_PopStack "IGCM_sys_ncra"
2355}
2356
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-
2362function IGCM_sys_ncrcat {
2363  IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
2364  if ( $DEBUG_sys ) ; then
2365    echo "IGCM_sys_ncrcat :" $@
2366  fi
2367
2368  typeset NB_ESSAI DELAI status i lastArg
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."
2383      sleep $DELAI
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
2394    else
2395      \rm out_rsync
2396      break
2397    fi
2398    (( i = i + 1 ))
2399  done
2400
2401  if [ ${status} -gt 0 ] ; then
2402    echo "IGCM_sys_ncrcat : ncrcat error"
2403    #IGCM_debug_Exit "ncrcat"
2404  fi
2405
2406  IGCM_debug_PopStack "IGCM_sys_ncrcat"
2407}
2408
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-
2414function IGCM_sys_ncrename {
2415  IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
2416  if ( $DEBUG_sys ) ; then
2417    echo "IGCM_sys_ncrename :" $@
2418  fi
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."
2435      sleep $DELAI
2436    else
2437      \rm out_rsync
2438      break
2439    fi
2440    (( i = i + 1 ))
2441  done
2442
2443  if [ ${status} -gt 0 ] ; then
2444    echo "IGCM_sys_ncrename : ncrename error"
2445    IGCM_debug_Exit "ncrename"
2446  fi
2447
2448  IGCM_debug_PopStack "IGCM_sys_ncrename"
2449}
2450
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-
2456function IGCM_sys_ncwa {
2457  IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
2458  if ( $DEBUG_sys ) ; then
2459    echo "IGCM_sys_ncwa :" $@
2460  fi
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."
2477      sleep $DELAI
2478    else
2479      \rm out_rsync
2480      break
2481    fi
2482    (( i = i + 1 ))
2483  done
2484
2485  if [ ${status} -gt 0 ] ; then
2486    echo "IGCM_sys_ncwa : ncwa error"
2487    IGCM_debug_Exit "ncwa"
2488  fi
2489
2490  IGCM_debug_PopStack "IGCM_sys_ncwa"
2491}
2492
2493##############################################################
2494# CDO OPERATOR
2495
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-
2501function IGCM_sys_cdo {
2502  IGCM_debug_PushStack "IGCM_sys_cdo" -- $@
2503  if ( $DEBUG_sys ) ; then
2504    echo "IGCM_sys_cdo :" $@
2505  fi
2506
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
2515    IGCM_debug_PopStack "IGCM_sys_cdo"
2516    return 1
2517  else
2518    IGCM_debug_PopStack "IGCM_sys_cdo"
2519    return 0
2520  fi
2521
2522  IGCM_debug_PopStack "IGCM_sys_cdo"
2523}
Note: See TracBrowser for help on using the repository browser.