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

Last change on this file since 809 was 809, checked in by sdipsl, 11 years ago

Activate IGCM_sys_Chmod from DRYRUN=3 and add BoundaryFiles? list in FileToBeDeleted list at each Period.
Whitespace cleanup (from emacs macro) on libIGCM_sys_iitm.ksh
see #105

  • Property svn:keywords set to Revision Author Date
File size: 61.1 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 (dedicated to large files)
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
176  IGCM_debug_Print 1 " dummy function : IGCM_sys_ChangeArchive "
177
178}
179
180#D-#==================================================
181#D-function IGCM_sys_RshMaster
182#D-* Purpose: Connection to frontend machine.
183#D-* Examples:
184#D-
185function IGCM_sys_RshMaster {
186  IGCM_debug_PushStack "IGCM_sys_RshMaster" $@
187  ssh obelix3 /bin/ksh  <<-EOF
188    export libIGCM=${libIGCM}
189    export DEBUG_debug=${DEBUG_debug}
190    . ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh
191    . ${libIGCM}/libIGCM_card/libIGCM_card.ksh
192    ${@}
193EOF
194  if [ $? -gt 0 ] ; then
195    echo "IGCM_sys_RshMaster : erreur."
196    IGCM_debug_Exit "IGCM_sys_RshMaster"
197  fi
198  IGCM_debug_PopStack "IGCM_sys_RshMaster"
199}
200
201#D-#==================================================
202#D-function IGCM_sys_RshArchive
203#D-* Purpose: Archive rsh command
204#D-* Examples:
205#D-
206function IGCM_sys_RshArchive {
207  IGCM_debug_PushStack "IGCM_sys_RshArchive" $@
208  /bin/ksh <<-EOF
209    ${@}
210EOF
211  if [ $? -gt 0 ] ; then
212    echo "IGCM_sys_RshArchive : erreur."
213    IGCM_debug_Exit "IGCM_sys_RshArchive"
214  fi
215  IGCM_debug_PopStack "IGCM_sys_RshArchive"
216}
217
218#D-#==================================================
219#D-function IGCM_sys_RshPost
220#D-* Purpose: Post-process rsh command
221#D-* Examples:
222#D-
223function IGCM_sys_RshPost {
224  IGCM_debug_PushStack "IGCM_sys_RshPost" $@
225  if ( $DEBUG_sys ) ; then
226    echo "IGCM_sys_RshPost :" $@
227  fi
228
229  #echo cat tmp_IGCM_sys_RshPost_$$ INITIAL
230  #cat tmp_IGCM_sys_RshPost_$$
231  # keep standard input (stdin) for the loop onto temporary file
232  cat >tmp_IGCM_sys_RshPost_$$
233
234# ============ FRONTEND START ============ #
235
236    ssh obelix3 exec /bin/ksh <tmp_IGCM_sys_RshPost_$$
237  if [ $? -gt 0 ] ; then
238    echo "IGCM_sys_RshPost : erreur."
239    IGCM_debug_Exit "IGCM_sys_RshPost"
240  fi
241  # delete temporary file
242  \rm tmp_IGCM_sys_RshPost_$$
243  IGCM_debug_PopStack "IGCM_sys_RshPost"
244}
245
246#D-#==================================================
247#D-function IGCM_sys_SendMail
248#D-* Purpose: Send mail when simulation is over
249#D-* Examples:
250#D-
251function IGCM_sys_SendMail {
252  IGCM_debug_PushStack "IGCM_sys_SendMail" $@
253  if ( $DEBUG_sys ) ; then
254    echo "IGCM_sys_SendMail :" $@
255  fi
256
257  if ( ${ExitFlag} ) ; then
258    status=failed
259  else
260    status=completed
261  fi
262
263  cat  << END_MAIL > job_end.mail
264Dear ${LOGIN},
265
266  Simulation ${config_UserChoices_JobName} is ${status} on supercomputer `hostname`.
267  Job started : ${DateBegin}
268  Job ended   : ${DateEnd}
269  Output files are available in ${R_SAVE}
270  Files to be rebuild are temporarily available in ${REBUILD_DIR}
271  Pre-packed files are temporarily available in ${R_BUFR}
272  Script files, Script Outputs and Debug files (if necessary) are available in ${SUBMIT_DIR}
273END_MAIL
274
275  if [ ! -z ${config_UserChoices_MailName} ] ; then
276    mailx -s "${config_UserChoices_JobName} ${status}" ${config_UserChoices_MailName} <  job_end.mail
277  elif [ -f ~/.forward ] ; then
278    mailx -s "${config_UserChoices_JobName} ${status}" $( cat ~/.forward ) < job_end.mail
279  fi
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    if [ $? -gt 0 ] ; then
327      echo "IGCM_sys_MkdirArchive : erreur."
328      IGCM_debug_Exit "IGCM_sys_MkdirArchive"
329    fi
330  fi
331  IGCM_debug_PopStack "IGCM_sys_MkdirArchive"
332}
333
334#D-#==================================================
335#D-function IGCM_sys_MkdirWork
336#D-* Purpose: Mkdir on Work
337#D-* Examples:
338#D-
339function IGCM_sys_MkdirWork {
340  IGCM_debug_PushStack "IGCM_sys_MkdirWork" $@
341  if ( $DEBUG_sys ) ; then
342    echo "IGCM_sys_MkdirWork :" $@
343  fi
344  #- creation de repertoire sur le serveur fichier
345  if [ ! -d ${1} ]; then
346    \mkdir -p $1
347    if [ $? -gt 0 ] ; then
348      echo "IGCM_sys_MkdirWork : erreur."
349      IGCM_debug_Exit "IGCM_sys_MkdirWork"
350    fi
351  fi
352  IGCM_debug_PopStack "IGCM_sys_MkdirWork"
353}
354
355#D-#==================================================
356#D-function IGCM_sys_Cd
357#D-* Purpose: master cd command
358#D-* Examples:
359#D-
360function IGCM_sys_Cd {
361  IGCM_debug_PushStack "IGCM_sys_Cd" $@
362  if ( $DEBUG_sys ) ; then
363    echo "IGCM_sys_Cd :" $@
364  fi
365  \cd $1
366  if [ $? -gt 0 ] ; then
367    echo "IGCM_sys_Cd : erreur."
368    IGCM_debug_Exit "IGCM_sys_Cd"
369  fi
370  IGCM_debug_PopStack "IGCM_sys_Cd"
371}
372
373#D-#==================================================
374#D-function IGCM_sys_Chmod
375#D-* Purpose: Chmod
376#D-* Examples:
377#D-
378function IGCM_sys_Chmod {
379  IGCM_debug_PushStack "IGCM_sys_Chmod" -- $@
380  if ( $DEBUG_sys ) ; then
381    echo "IGCM_sys_Chmod :" $@
382  fi
383  \chmod $@
384  if [ $? -gt 0 ] ; then
385    echo "IGCM_sys_Chmod : erreur."
386    IGCM_debug_Exit "IGCM_sys_Chmod"
387  fi
388  IGCM_debug_PopStack "IGCM_sys_Chmod"
389}
390
391#D-#==================================================
392#D-function IGCM_sys_FileSize
393#D-* Purpose: Filesize
394#D-* Examples:
395#D-
396function IGCM_sys_FileSize {
397  IGCM_debug_PushStack "IGCM_sys_FileSize" $@
398
399  typeset sizeF
400  set +A sizeF -- $( ls -la ${1} )
401  if [ $? -gt 0 ] ; then
402    IGCM_debug_Exit "IGCM_sys_FileSize"
403  fi
404  eval ${2}=${sizeF[4]}
405
406  IGCM_debug_PopStack "IGCM_sys_FileSize"
407}
408
409#D-#==================================================
410#D-function IGCM_sys_TestDir
411#D-* Purpose: Test Directory that must exists
412#D-* Examples:
413#D-
414function IGCM_sys_TestDir {
415  IGCM_debug_PushStack "IGCM_sys_TestDir" $@
416  if ( $DEBUG_sys ) ; then
417    echo "IGCM_sys_TestDir :" $@
418  fi
419  typeset ExistFlag
420  ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
421  IGCM_debug_PopStack "IGCM_sys_TestDir"
422
423  return ${ExistFlag}
424}
425
426#D-#==================================================
427#D-function IGCM_sys_TestDirArchive
428#D-* Purpose: Test Directory that must exists on Archive
429#D-* Examples:
430#D-
431function IGCM_sys_TestDirArchive {
432  IGCM_debug_PushStack "IGCM_sys_TestDirArchive" $@
433  if ( $DEBUG_sys ) ; then
434    echo "IGCM_sys_TestDirArchive :" $@
435  fi
436  typeset ExistFlag
437  ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
438  IGCM_debug_PopStack "IGCM_sys_TestDirArchive"
439
440  return ${ExistFlag}
441}
442
443#D-#==================================================
444#D-function IGCM_sys_IsFileArchived
445#D-* Purpose: Test file that must NOT EXISTS on Archive
446#D-* Examples:
447#D-
448function IGCM_sys_IsFileArchived {
449  IGCM_debug_PushStack "IGCM_sys_IsFileArchived" $@
450  if ( $DEBUG_sys ) ; then
451    echo "IGCM_sys_IsFileArchived :" $@
452  fi
453  typeset IsArchivedFlag
454  # Never archived for this system
455  IsArchivedFlag=1
456  IGCM_debug_PopStack "IGCM_sys_IsFileArchived"
457
458  return ${IsArchivedFlag}
459}
460
461#D-#==================================================
462#D-function IGCM_sys_TestFileArchive
463#D-* Purpose: Test file that must NOT EXISTS on Archive
464#D-* Examples:
465#D-
466function IGCM_sys_TestFileArchive {
467  IGCM_debug_PushStack "IGCM_sys_TestFileArchive" $@
468  typeset ExistFlag
469  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
470  IGCM_debug_PopStack "IGCM_sys_TestFileArchive"
471
472  return ${ExistFlag}
473}
474
475#D-#==================================================
476#D-function IGCM_sys_TestFileBuffer
477#D-* Purpose: Test file that must NOT EXISTS on Buffer
478#D-* Examples:
479#D-
480function IGCM_sys_TestFileBuffer {
481  IGCM_debug_PushStack "IGCM_sys_TestFileBuffer" $@
482  typeset ExistFlag
483  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
484  IGCM_debug_PopStack "IGCM_sys_TestFileBuffer"
485
486  return ${ExistFlag}
487}
488
489#D-#==================================================
490#D-function IGCM_sys_CountFileArchive
491#D-* Purpose: Count files on Archive filesystem
492#D-* Examples:
493#D-
494function IGCM_sys_CountFileArchive {
495  IGCM_debug_PushStack "IGCM_sys_CountFileArchive" $@
496  ls ${@} 2>/dev/null | wc -l
497  if [ $? -gt 0 ] ; then
498    echo "IGCM_sys_CountFileArchive : erreur."
499  fi
500  IGCM_debug_PopStack "IGCM_sys_CountFileArchive"
501}
502
503#D-#==================================================
504#D-function IGCM_sys_CountFileBuffer
505#D-* Purpose: Count files on Scratch filesystem
506#D-* Examples:
507#D-
508function IGCM_sys_CountFileBuffer {
509  IGCM_debug_PushStack "IGCM_sys_CountFileBuffer" $@
510  ls ${@} 2>/dev/null | wc -l
511  if [ $? -gt 0 ] ; then
512    echo "IGCM_sys_CountFileBuffer : erreur."
513  fi
514  IGCM_debug_PopStack "IGCM_sys_CountFileBuffer"
515}
516
517#D-#==================================================
518#D-function IGCM_sys_Tree
519#D-* Purpose: Tree directories with files on ${ARCHIVE}
520#D-* Examples: IGCM_sys_Tree ${R_IN} ${R_OUT}
521#D-
522function IGCM_sys_Tree {
523  IGCM_debug_PushStack "IGCM_sys_Tree" $@
524  if ( $DEBUG_sys ) ; then
525    echo "IGCM_sys_Tree :" $@
526  fi
527
528  \tree -f $@
529
530  IGCM_debug_PopStack "IGCM_sys_Tree"
531}
532
533#D-#==================================================
534#D-function IGCM_sys_Tar
535#D-* Purpose: master tar command
536#D-* Examples:
537#D-
538function IGCM_sys_Tar {
539  IGCM_debug_PushStack "IGCM_sys_Tar" $@
540  if ( $DEBUG_sys ) ; then
541    echo "IGCM_sys_Tar :" $@
542  fi
543  \tar cf $@
544  if [ $? -gt 0 ] ; then
545    echo "IGCM_sys_Tar : erreur."
546    IGCM_debug_Exit "IGCM_sys_Tar"
547  fi
548  IGCM_debug_PopStack "IGCM_sys_Tar"
549}
550
551#D-#==================================================
552#D-function IGCM_sys_UnTar
553#D-* Purpose: master un-tar command
554#D-* Examples:
555#D-
556function IGCM_sys_UnTar {
557  IGCM_debug_PushStack "IGCM_sys_UnTar" $@
558  if ( $DEBUG_sys ) ; then
559    echo "IGCM_sys_UnTar :" $@
560  fi
561  \tar xvf $1
562  if [ $? -gt 0 ] ; then
563    echo "IGCM_sys_UnTar : erreur."
564    IGCM_debug_Exit "IGCM_sys_UnTar"
565  fi
566  IGCM_debug_PopStack "IGCM_sys_UnTar"
567}
568
569#D-#==================================================
570#D-function IGCM_sys_Qsub
571#D-* Purpose: Qsub new job
572#D-* Examples:
573#D-
574function IGCM_sys_Qsub {
575  IGCM_debug_PushStack "IGCM_sys_Qsub" $@
576  if ( $DEBUG_sys ) ; then
577    echo "IGCM_sys_Qsub :" $@
578  fi
579  /usr/local/bin/qsub -q medium -o ${Script_Output} -N ${config_UserChoices_JobName}.${CumulPeriod} < $1
580  if [ $? -gt 0 ] ; then
581    echo "IGCM_sys_Qsub : erreur."
582    IGCM_debug_Exit "IGCM_sys_Qsub"
583  fi
584  IGCM_debug_PopStack "IGCM_sys_Qsub"
585}
586
587#D-#==================================================
588#D-function IGCM_sys_QsubPost
589#D-* Purpose: Qsub new job on scalaire
590#D-* Examples:
591#D-
592function IGCM_sys_QsubPost {
593  IGCM_debug_PushStack "IGCM_sys_QsubPost" $@
594  if ( $DEBUG_sys ) ; then
595    echo "IGCM_sys_QsubPost :" $@
596  fi
597  /usr/local/bin/qsub -q medium -o ${POST_DIR}/${Script_Post_Output}.out ${libIGCM_POST}/$1.job -v ${listVarEnv}
598  if [ $? -gt 0 ] ; then
599    echo "IGCM_sys_QsubPost : erreur " $@
600    IGCM_debug_Exit "IGCM_sys_QsubPost"
601  fi
602  IGCM_debug_PopStack "IGCM_sys_QsubPost"
603}
604
605#D-*************************
606#D- File transfer functions
607#D-*************************
608#D-
609
610#D-#==================================================
611#D-function IGCM_sys_Rsync_out
612#D-* Purpose: treat return val of rsync
613#D-* Examples: IGCM_sys_Rsync_out out_RET_rsync
614#D-  Error values and explanations can depend on your system version.
615function IGCM_sys_Rsync_out {
616  status=$1
617  if [ ! $status ] ; then
618    echo "rsync error !"
619  fi
620
621  if [ $MYLANG = "fr" ]; then
622    case $status in
623    0)  return ;;
624    1)  echo "Erreur de rsync ; RERR_SYNTAX : "
625      echo "Erreur de syntaxe ou d'utilisation."
626      return;;
627    2)  echo "Erreur de rsync ; RERR_PROTOCOL : "
628      echo "Incompatibilité de protocole."
629      return;;
630    3)  echo "Erreur de rsync ; RERR_FILESELECT 3"
631      echo "Erreurs  lors  de  la  sélection des fichiers d'entrée sortie et"
632      echo "répertoires"
633      return;;
634    4)  echo "Erreur de rsync ; RERR_UNSUPPORTED"
635      echo "Action demandée non supportée : une tentative de manipulation de"
636      echo "fichiers  64-bits  sur une plate-forme qui ne les supporte pas a"
637      echo "été faite ; ou une option qui est supportée par le  client  mais"
638      echo "pas par le serveur a été spécifiée."
639      return;;
640    10) echo "Erreur de rsync ; RERR_SOCKETIO"
641      echo "Erreur dans le socket d'entrée sortie"
642      return;;
643    11) echo "Erreur de rsync ; RERR_FILEIO"
644      echo "Erreur d'entrée sortie fichier"
645      return;;
646    12) echo "Erreur de rsync ; RERR_STREAMIO"
647      echo "Erreur dans flux de donnée du protocole rsync"
648      return;;
649    13) echo "Erreur de rsync ; RERR_MESSAGEIO"
650      echo "Erreur avec les diagnostics du programme"
651      return;;
652    14) echo "Erreur de rsync ; RERR_IPC"
653      echo "Erreur dans le code IPC"
654      return;;
655    20) echo "Erreur de rsync ; RERR_SIGNAL"
656      echo "SIGUSR1 ou SIGINT reçu"
657      return;;
658    21) echo "Erreur de rsync ; RERR_WAITCHILD"
659      echo "Une erreur retournée par waitpid()"
660      return;;
661    22) echo "Erreur de rsync ; RERR_MALLOC"
662      echo "Erreur lors de l'allocation des tampons de mémoire de coeur"
663      return;;
664    23) echo ""
665      echo "Erreur fichier inexistant"
666      return;;
667    30) echo "Erreur de rsync ; RERR_TIMEOUT"
668      echo "Temps d'attente écoulé dans l'envoi/réception de données"
669      return;;
670    *)  echo "Erreur de rsync : code de retour de rsync inconnu :" $status
671      return;;
672    esac
673  elif [ $MYLANG = "en" ] ; then
674    case $status in
675    0)  return;;
676    1)  echo "rsync error : Syntax or usage error "
677      return;;
678    2)  echo "rsync error : Protocol incompatibility "
679      return;;
680    3)  echo "rsync error : Errors selecting input/output files, dirs"
681      return;;
682    4)  echo "rsync error : Requested action not supported: an attempt"
683      echo "was made to manipulate 64-bit files on a platform that cannot support"
684      echo "them; or an option was specified that is supported by the client and"
685      echo "not by the server."
686      return;;
687    5)  echo "rsync error : Error starting client-server protocol"
688      return;;
689    10) echo "rsync error : Error in socket I/O "
690      return;;
691    11) echo "rsync error : Error in file I/O "
692      return;;
693    12) echo "rsync error : Error in rsync protocol data stream "
694      return;;
695    13) echo "rsync error : Errors with program diagnostics "
696      return;;
697    14) echo "rsync error : Error in IPC code "
698      return;;
699    20) echo "rsync error : Received SIGUSR1 or SIGINT "
700      return;;
701    21) echo "rsync error : Some error returned by waitpid() "
702      return;;
703    22) echo "rsync error : Error allocating core memory buffers "
704      return;;
705    23) echo "rsync error : Partial transfer due to error"
706      return;;
707    24) echo "rsync error : Partial transfer due to vanished source files"
708      return;;
709    30) echo "rsync error : Timeout in data send/receive "
710      return;;
711    *)  echo "rsync error : return code of rsync unknown :" $status
712      return;;
713    esac
714  else
715    echo "unknown language $MYLANG."
716    return
717  fi
718}
719
720#D-#==================================================
721#D-function IGCM_sys_Cp
722#D-* Purpose: generic cp
723#D-* Examples:
724#D-
725function IGCM_sys_Cp {
726  IGCM_debug_PushStack "IGCM_sys_Cp" $@
727  if ( $DEBUG_sys ) ; then
728    echo "IGCM_sys_Cp :" $@
729  fi
730
731  typeset status
732
733  echo cp $@ > out_rsync 2>&1
734  \cp $@ >> out_rsync 2>&1
735  status=$?
736
737  if [ ${status} -gt 0 ] ; then
738    echo "IGCM_sys_Cp : error code ${status}"
739    cat out_rsync
740    IGCM_debug_Exit "IGCM_sys_Cp"
741  else
742    \rm out_rsync
743  fi
744  IGCM_debug_PopStack "IGCM_sys_Cp"
745}
746
747#D-#==================================================
748#D-function IGCM_sys_Rm
749#D-* Purpose: generic rm
750#D-* Examples:
751#D-
752function IGCM_sys_Rm {
753  IGCM_debug_PushStack "IGCM_sys_Rm" -- $@
754  if ( $DEBUG_sys ) ; then
755    echo "IGCM_sys_Rm :" $@
756  fi
757
758  typeset status
759
760  echo rm $@ > out_rsync 2>&1
761  \rm $@ >> out_rsync 2>&1
762  status=$?
763
764  if [ ${status} -gt 0 ] ; then
765    echo "IGCM_sys_Rm : error code ${status}"
766    cat out_rsync
767    IGCM_debug_Exit "IGCM_sys_Rm"
768  else
769    \rm out_rsync
770  fi
771  IGCM_debug_PopStack "IGCM_sys_Rm"
772}
773
774#D-#==================================================
775#D-function IGCM_sys_RmRunDir
776#D-* Purpose: rm tmpdir (dummy function most of the time batch
777#D-                      scheduler will do the job)
778#D-* Examples:
779#D-
780function IGCM_sys_RmRunDir {
781  IGCM_debug_PushStack "IGCM_sys_RmRunDir" -- $@
782  if ( $DEBUG_sys ) ; then
783    echo "IGCM_sys_RmRunDir :" $@
784  fi
785
786  typeset status
787
788  echo rm $@ > out_rsync 2>&1
789  \rm $@ >> out_rsync 2>&1
790  status=$?
791
792  if [ ${status} -gt 0 ] ; then
793    echo "IGCM_sys_RmRunDir : error code ${status}"
794    cat out_rsync
795    IGCM_debug_Exit "IGCM_sys_RmRunDir"
796  else
797    \rm out_rsync
798  fi
799  IGCM_debug_PopStack "IGCM_sys_RmRunDir"
800}
801
802#D-#==================================================
803#D-function IGCM_sys_Mv
804#D-* Purpose: generic move
805#D-* Examples:
806#D-
807function IGCM_sys_Mv {
808  IGCM_debug_PushStack "IGCM_sys_Mv" $@
809  if ( $DEBUG_sys ) ; then
810    echo "IGCM_sys_Mv :" $@
811  fi
812
813  if [ $DRYRUN = 0 ]; then
814
815    typeset status
816
817    echo mv $@ > out_rsync 2>&1
818    \mv $@ >> out_rsync 2>&1
819    status=$?
820
821    if [ ${status} -gt 0 ] ; then
822      echo "IGCM_sys_Mv : error code ${status}"
823      cat out_rsync
824      IGCM_debug_Exit "IGCM_sys_Mv"
825    else
826      \rm out_rsync
827    fi
828  else
829    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
830  fi
831
832  IGCM_debug_PopStack "IGCM_sys_Mv"
833}
834
835#D-#==================================================
836#D-function IGCM_sys_Put_Dir
837#D-* Purpose: Copy a complete directory on $(ARCHIVE)
838#D-* Examples:
839#D-
840function IGCM_sys_Put_Dir {
841  IGCM_debug_PushStack "IGCM_sys_Put_Dir" $@
842  if ( $DEBUG_sys ) ; then
843    echo "IGCM_sys_Put_Dir :" $@
844  fi
845  if [ $DRYRUN = 0 ]; then
846    if [ ! -d ${1} ] ; then
847      echo "WARNING : IGCM_sys_Put_Dir ${1} DOES NOT EXIST ."
848      IGCM_debug_PopStack "IGCM_sys_Put_Dir"
849      return
850    fi
851
852    typeset status
853
854    # Only if we use rsync
855    #IGCM_sys_TestDirArchive $( dirname $2 )
856    #
857    #USUAL WAY
858    \cp -r $1 $2 > out_rsync 2>&1
859    status=$?
860
861    if [ ${status} -gt 0 ] ; then
862      echo "IGCM_sys_Put_Dir : error code ${status}"
863      cat out_rsync
864      IGCM_debug_Exit "IGCM_sys_Put_Dir"
865    else
866      \rm out_rsync
867    fi
868  else
869    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
870  fi
871  IGCM_debug_PopStack "IGCM_sys_Put_Dir"
872}
873
874#D-#==================================================
875#D-function IGCM_sys_Get_Dir
876#D-* Purpose: Copy a complete directory from ${ARCHIVE}
877#D-* Examples:
878#D-
879function IGCM_sys_Get_Dir {
880  IGCM_debug_PushStack "IGCM_sys_Get_Dir" $@
881  if ( $DEBUG_sys ) ; then
882    echo "IGCM_sys_Get_Dir :" $@
883  fi
884  if [ $DRYRUN = 0 ]; then
885    if [ ! -d ${1} ] ; then
886      echo "WARNING : IGCM_sys_Get_Dir ${1} DOES NOT EXIST ."
887      IGCM_debug_PopStack "IGCM_sys_Get_Dir"
888      return
889    fi
890
891    typeset status
892
893    #USUAL WAY
894    \cp -R $1 $2 > out_rsync 2>&1
895    status=$?
896
897    if [ ${status} -gt 0 ] ; then
898      echo "IGCM_sys_Get_Dir : error."
899      cat out_rsync
900      IGCM_debug_Exit "IGCM_sys_Get_Dir"
901    else
902      \rm out_rsync
903    fi
904  else
905    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
906  fi
907  IGCM_debug_PopStack "IGCM_sys_Get_Dir"
908}
909
910#D-#==================================================
911#D-function IGCM_sys_Get_Master
912#D-* Purpose: Copy a complete directory from MASTER filesystem
913#D-* Examples:
914#D-
915function IGCM_sys_Get_Master {
916  IGCM_debug_PushStack "IGCM_sys_Get_Master" $@
917  if ( $DEBUG_sys ) ; then
918    echo "IGCM_sys_Get_Master :" $@
919  fi
920  if [ $DRYRUN = 0 ]; then
921    if ( [ ! -d ${1} ] && [ ! -f ${1} ] ) ; then
922      echo "WARNING : IGCM_sys_Get_Master ${1} DOES NOT EXIST ."
923      IGCM_debug_PopStack "IGCM_sys_Get_Master"
924      return
925    fi
926
927    typeset status
928
929    #USUAL WAY
930    cp -RL $1 $2 > out_rsync 2>&1
931    status=$?
932
933    if [ ${status} -gt 0 ] ; then
934      echo "IGCM_sys_Get_Master : error."
935      cat out_rsync
936      IGCM_debug_Exit "IGCM_sys_Get_Master"
937    else
938      rm out_rsync
939    fi
940  else
941    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
942  fi
943  IGCM_debug_PopStack "IGCM_sys_Get_Master"
944}
945
946#D-#==================================================
947#D-function IGCM_sys_Put_Rest
948#D-* Purpose: Put computied restarts on ${ARCHIVE}.
949#D-           File and target directory must exist.
950#D-* Examples:
951#D-
952function IGCM_sys_Put_Rest {
953  IGCM_debug_PushStack "IGCM_sys_Put_Rest" $@
954  if ( $DEBUG_sys ) ; then
955    echo "IGCM_sys_Put_Rest :" $@
956  fi
957  if [ $DRYRUN = 0 ]; then
958    if [ ! -f ${1} ] ; then
959      echo "ERROR : IGCM_sys_Put_Rest ${1} DOES NOT EXIST ."
960      IGCM_debug_Exit "IGCM_sys_Put_Rest"
961    fi
962
963    typeset status
964    #
965    if [ X${JobType} = XRUN ] ; then
966      IGCM_sys_Chmod 444 ${1}
967    fi
968
969    #
970    # USUAL WAY
971    \cp $1 $2 > out_rsync 2>&1
972    status=$?
973
974#       #RSYNC WITH NETWORK SSH CALL
975#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > out_rsync 2>&1
976#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> out_rsync 2>&1
977
978#       #RSYNC WITH NFS USE
979#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
980#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
981
982#       status=$?
983#       IGCM_sys_Rsync_out $status
984
985#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
986#       (( status=status+$? ))
987
988    if [ ${status} -gt 0 ] ; then
989      echo "IGCM_sys_Put_Rest : cp failed error code ${status}"
990      cat out_rsync
991      IGCM_debug_Exit "IGCM_sys_Put_Rest"
992    else
993      \rm out_rsync
994    fi
995  else
996    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
997  fi
998  IGCM_debug_PopStack "IGCM_sys_Put_Rest"
999}
1000
1001#D-#==================================================
1002#D-function IGCM_sys_PutBuffer_Rest
1003#D-* Purpose: Put computied restarts on ${SCRATCHDIR}.
1004#D-           File and target directory must exist.
1005#D-* Examples:
1006#D-
1007function IGCM_sys_PutBuffer_Rest {
1008  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Rest" $@
1009  if ( $DEBUG_sys ) ; then
1010    echo "IGCM_sys_PutBuffer_Rest :" $@
1011  fi
1012  if [ $DRYRUN = 0 ]; then
1013    if [ ! -f ${1} ] ; then
1014      echo "ERROR : IGCM_sys_PutBuffer_Rest ${1} DOES NOT EXIST ."
1015      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
1016    fi
1017
1018    typeset status
1019    #
1020    if [ X${JobType} = XRUN ] ; then
1021      IGCM_sys_Chmod 444 ${1}
1022    fi
1023
1024    #
1025    # USUAL WAY
1026    \cp $1 $2 > out_rsync 2>&1
1027    status=$?
1028
1029    if [ ${status} -gt 0 ] ; then
1030      echo "IGCM_sys_PutBuffer_Rest : error code ${status}"
1031      cat out_rsync
1032      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
1033    else
1034      \rm out_rsync
1035    fi
1036  else
1037    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1038  fi
1039  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Rest"
1040}
1041
1042#D-#==================================================
1043#D-function IGCM_sys_PrepareTaredRestart
1044#D-* Purpose: Prepare tared restart to be access by computing job. Identity here.
1045#D-* Examples:
1046#D-
1047function IGCM_sys_PrepareTaredRestart {
1048  IGCM_debug_PushStack "IGCM_sys_PrepareTaredRestart" $@
1049  echo $1
1050  IGCM_debug_PopStack "IGCM_sys_PrepareTaredRestart"
1051}
1052
1053#D-#==================================================
1054#D-function IGCM_sys_Put_Out
1055#D-* Purpose: Copy a file on ${ARCHIVE} after having chmod it in readonly
1056#D-* Examples:
1057#D-
1058function IGCM_sys_Put_Out {
1059  IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
1060  if ( $DEBUG_sys ) ; then
1061    echo "IGCM_sys_Put_Out :" $@
1062  fi
1063  if [ $DRYRUN = 0 ]; then
1064    if [ -f ${1} ] ; then
1065      if [ ! -d $( dirname $2 ) ] ; then
1066        IGCM_sys_MkdirArchive $( dirname $2 )
1067      fi
1068    else
1069      echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
1070      IGCM_debug_PopStack "IGCM_sys_Put_Out"
1071      return 1
1072    fi
1073
1074    typeset status
1075    #
1076    if [ X${JobType} = XRUN ] ; then
1077      if [ X${3} = X ] ; then
1078        IGCM_sys_Chmod 444 ${1}
1079      fi
1080    fi
1081    #
1082
1083    echo ${RSYNC} ${RSYNC_opt} $1 $2 > out_rsync 2>&1
1084    ${RSYNC} ${RSYNC_opt} $1 $2 >> out_rsync 2>&1
1085    status=$?
1086    IGCM_sys_Rsync_out $status
1087
1088    ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1089    (( status=status+$? ))
1090
1091    if [ ${status} -gt 0 ] ; then
1092      echo "IGCM_sys_Put_Out : error."
1093      cat out_rsync
1094      IGCM_debug_Exit "IGCM_sys_Put_Out"
1095    else
1096      \rm out_rsync
1097    fi
1098  else
1099    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1100  fi
1101  IGCM_debug_PopStack "IGCM_sys_Put_Out"
1102  return 0
1103}
1104
1105#D-#==================================================
1106#D-function IGCM_sys_PutBuffer_Out
1107#D-* Purpose: Copy a file on ${SCRATCHDIR} after having chmod it in readonly
1108#D-* Examples:
1109#D-
1110function IGCM_sys_PutBuffer_Out {
1111  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Out" $@
1112  if ( $DEBUG_sys ) ; then
1113    echo "IGCM_sys_PutBuffer_Out :" $@
1114  fi
1115
1116  typeset status
1117
1118  if [ $DRYRUN = 0 ]; then
1119    if [ ! -f ${1} ] ; then
1120      echo "WARNING : IGCM_sys_PutBuffer_Out ${1} DOES NOT EXIST ."
1121      IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1122      return 1
1123    fi
1124    #
1125    IGCM_sys_Mkdir $( dirname $2 )
1126    #
1127
1128    if [ X${JobType} = XRUN ] ; then
1129      if [ X${3} = X ] ; then
1130        IGCM_sys_Chmod 444 ${1}
1131      fi
1132    fi
1133    #
1134    # USUAL WAY
1135    \cp $1 $2 > out_rsync 2>&1
1136    status=$?
1137
1138    if [ ${status} -gt 0 ] ; then
1139      echo "IGCM_sys_PutBuffer_Out : error."
1140      cat out_rsync
1141      IGCM_debug_Exit "IGCM_sys_PutBuffer_Out"
1142    else
1143      \rm out_rsync
1144    fi
1145  else
1146    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1147  fi
1148  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1149  return 0
1150}
1151
1152#D-#==================================================
1153#D-function IGCM_sys_Get
1154#D-* Purpose: Get a file from ${ARCHIVE}
1155#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
1156#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
1157function IGCM_sys_Get {
1158  IGCM_debug_PushStack "IGCM_sys_Get" $@
1159
1160  typeset DEST RET status dm_liste ifile target
1161
1162  if ( $DEBUG_sys ) ; then
1163    echo "IGCM_sys_Get :" $@
1164  fi
1165  if [ $DRYRUN -le 2 ]; then
1166    if [ X${1} = X'/l' ] ; then
1167      # test if the first file is present in the old computation :
1168      eval set +A dm_liste \${${2}}
1169    else
1170      dm_liste=${1}
1171    fi
1172    eval DEST=\${${#}}
1173
1174    # test if the (first) file is present in the old computation :
1175    IGCM_sys_TestFileArchive ${dm_liste[0]}
1176    status=$?
1177    if [ ${status} -gt 0 ] ; then
1178      echo "IGCM_sys_Get, ERROR : regular file ${dm_liste[0]} DOES NOT EXIST ."
1179      IGCM_debug_Exit "IGCM_sys_Get"
1180      #return
1181    fi
1182
1183    (( RET=0 ))
1184    for target in ${dm_liste[*]} ; do
1185      \cp ${target} ${DEST} >> out_rsync 2>&1
1186      (( RET=RET+$? ))
1187    done
1188
1189#       echo ${RSYNC} ${RSYNC_opt} $@ > out_rsync 2>&1
1190#       ${RSYNC} ${RSYNC_opt} $@ >> out_rsync 2>&1
1191#       status=$?
1192#       IGCM_sys_Rsync_out $status
1193
1194#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1195#       (( RET=RET+$? ))
1196
1197    if [ ${RET} -gt 0 ] ; then
1198      echo "IGCM_sys_Get : error"
1199      cat out_rsync
1200      \rm out_rsync
1201      IGCM_debug_Exit "IGCM_sys_Get"
1202    else
1203      \rm out_rsync
1204    fi
1205  else
1206    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1207  fi
1208  IGCM_debug_PopStack "IGCM_sys_Get"
1209}
1210
1211#D-#==================================================
1212#D-function IGCM_sys_GetBuffer
1213#D-* Purpose: Get a file from ${SCRATCHDIR}
1214#D-* Examples: IGCM_sys_GetBuffer myfile /destpath/myfile_with_PREFIX
1215#D-            IGCM_sys_GetBuffer /l Array_contain_myfiles /destpath/
1216function IGCM_sys_GetBuffer {
1217  IGCM_debug_PushStack "IGCM_sys_GetBuffer" $@
1218
1219  typeset DEST RET status buf_liste ifile target file_work
1220
1221  if ( $DEBUG_sys ) ; then
1222    echo "IGCM_sys_GetBuffer :" $@
1223  fi
1224  if [ $DRYRUN -le 2 ]; then
1225    if [ X${1} = X'/l' ] ; then
1226      # test if the first file is present in the old computation :
1227      eval set +A buf_liste \${${2}}
1228    else
1229      eval set +A buf_liste ${1}
1230    fi
1231    eval DEST=\${${#}}
1232
1233    #USUAL WAY
1234    if [ X${1} = X'/l' ] ; then
1235      (( RET=0 ))
1236      for target in ${buf_liste[*]} ; do
1237        local_file=$( basename ${target} )
1238        \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1239        (( RET = RET + $? ))
1240      done
1241    else
1242      \cp ${buf_liste} ${DEST} >> out_rsync 2>&1
1243      status=$?
1244    fi
1245
1246    if [ ${RET} -gt 0 ] ; then
1247      echo "IGCM_sys_GetBuffer : error"
1248      cat out_rsync
1249      \rm out_rsync
1250      IGCM_debug_Exit "IGCM_sys_GetBuffer"
1251    else
1252      \rm out_rsync
1253    fi
1254  else
1255    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1256  fi
1257  IGCM_debug_PopStack "IGCM_sys_GetBuffer"
1258}
1259
1260#D-#==================================================
1261#D-function IGCM_sys_GetDate_FichWork
1262#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
1263#D-* Examples:
1264#D-
1265function IGCM_sys_GetDate_FichWork {
1266  IGCM_debug_PushStack "IGCM_sys_FichWork" $@
1267  if ( $DEBUG_sys ) ; then
1268    echo "IGCM_sys_GetDate_FichWork :" $@
1269  fi
1270  typeset dateF
1271  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1272  eval ${2}=${dateF[5]}
1273
1274  # donne la date filesys d'un fichier sur la machine work
1275  IGCM_debug_PopStack "IGCM_sys_FichWork"
1276}
1277
1278#D-#==================================================
1279#D-function IGCM_sys_GetDate_FichArchive
1280#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
1281#D-* Examples:
1282#D-
1283function IGCM_sys_GetDate_FichArchive {
1284  IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
1285  if ( $DEBUG_sys ) ; then
1286    echo "IGCM_sys_GetDate_FichArchive :" $@
1287  fi
1288  typeset dateF
1289  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1290  eval ${2}=${dateF[5]}
1291
1292  IGCM_debug_PopStack "IGCM_sys_FichArchive"
1293}
1294
1295#D-#==================================================
1296#D-function IGCM_sys_Dods_Rm
1297#D-* Purpose: DO NOTHING ! Put ${ARCHIVE} files on DODS internet protocole.
1298#D-* Examples:
1299#D-
1300function IGCM_sys_Dods_Rm {
1301  if ( $DEBUG_sys ) ; then
1302    echo "IGCM_sys_Dods_Rm :" $@
1303  fi
1304  return 0
1305}
1306
1307#D-#==================================================
1308#D-function IGCM_sys_Dods_Cp
1309#D-* Purpose: Copy $(ARCHIVE) files on DODS internet protocole.
1310#D-* Examples:
1311#D-
1312function IGCM_sys_Dods_Cp {
1313  if ( $DEBUG_sys ) ; then
1314    echo "IGCM_sys_Dods_Cp :" $@
1315  fi
1316  return 0
1317}
1318
1319#D-#==================================================
1320#D-function IGCM_sys_Put_Dods
1321#D-* Purpose: Put $(ARCHIVE) files on DODS internet protocole.
1322#D-* Examples:
1323#D-
1324function IGCM_sys_Put_Dods {
1325  IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
1326  if ( $DEBUG_sys ) ; then
1327    echo "IGCM_sys_Put_Dods :" $@
1328  fi
1329  IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1330}
1331
1332##############################################################
1333# REBUILD OPERATOR
1334
1335function IGCM_sys_rebuild {
1336  IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1337  if ( $DEBUG_sys ) ; then
1338    echo "IGCM_sys_rebuild :" $@
1339  fi
1340
1341  typeset status
1342
1343  /home/users/igcmg/rebuild/bin/rebuild -f -o $@
1344  status=$?
1345  if [ ${status} -gt 0 ] ; then
1346    IGCM_debug_Print 2 "IGCM_sys_rebuild : error code ${status}"
1347    IGCM_debug_Exit "rebuild"
1348  fi
1349
1350  IGCM_debug_PopStack "IGCM_sys_rebuild"
1351}
1352
1353function IGCM_sys_rebuild_station {
1354  IGCM_debug_PushStack "IGCM_sys_rebuild_station" -- $@
1355  typeset i list_opt file_in file_out prefix_invert list_invert
1356  if ( $DEBUG_sys ) ; then
1357    echo "IGCM_sys_rebuild_station :" $@
1358  fi
1359  list_opt=$@
1360
1361  # Invert Axis : t,x -> x,t
1362  #               t,pres,x -> x,t,pres
1363  # So that we can concatenate along x
1364  i=0
1365  for file_in in ${list_opt} ; do
1366    (( i = i + 1))
1367    [ ${i} = 1 ] && file_out=${file_in} && continue
1368    prefix_invert=$( basename ${file_in} .nc )
1369    IGCM_sys_ncpdq -a x,time_counter -a x,time_counter,presnivs ${file_in} ${prefix_invert}_xt.nc
1370    list_invert[${#list_invert[*]}]=${prefix_invert}_xt.nc
1371  done
1372
1373  # Concatenate
1374  IGCM_sys_ncrcat ${list_invert[*]} histstn_xt.nc
1375
1376  # Re-ivert file
1377  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x histstn_xt.nc ${file_out}
1378
1379  # Station re-ordering is too expansive to be run within libICGM
1380  # This is due to (ncpdq - nrcat - ncpdq) I/O sequence.
1381  # This re-ordering must be done "in memory" by the cmorization process
1382  # Anyway this is the best sequence using (ncpdq - nrcat - ncpdq)
1383  # BEGIN reordering
1384
1385  # Only LMDZ text output contains the exact ordering of the station.
1386  # We isolate this in the code below:
1387  #  0  38  -157.5000000000000  70.98591549295774
1388  #  0  54  27.49999999999999   67.18309859154928
1389  #  0  56  -62.50000000000001  82.39436619718309
1390  #  0  79  12.49999999999999   78.59154929577466
1391  #  0  116 -165.0000000000000  76.05633802816901
1392  #  0  117 130.0000000000000   70.98591549295774
1393  #  0  118 110.0000000000000   87.46478873239437
1394  #  1  40  4.999999999999995   51.97183098591550
1395#  typeset iStation iProc list_opt file_in file_out prefix_invert
1396#  typeset -Z4 j4
1397#  typeset -Z3 j3
1398
1399#  unset list_opt
1400#  set +A list_opt $@
1401
1402  # Filename after rebuild
1403#  file_out=${list_opt[0]}
1404  # Prefix of output files
1405#  prefix_invert=$( basename ${file_out} .nc )
1406  # Number of procs
1407#  num_proc=$( grep -i mpi_size ${PREFIX}_${Exe_Output} | wc -l )
1408
1409#  iProc=0
1410#  while [ ${iProc} -lt ${num_proc} ] ; do
1411    # Array containing Station as a number
1412#    unset proc_stn
1413#    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}' )
1414    # Number of stations produced by processor proc
1415#    stationLast=${#proc_stn[*]}
1416    # Proc number on 4 digits
1417#    j4=${iProc}
1418    # Init
1419#    iStation=0
1420#    while [ ${iStation} -lt ${stationLast} ] ; do
1421      # Station number on 3 digits
1422#      j3=${proc_stn[${iStation}]}
1423      # Extract station
1424      # Invert Axis : t,x -> x,t
1425      #               t,pres,x -> x,t,pres
1426      # So that we can concatenate along x
1427#      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
1428#      (( iStation = iStation + 1 ))
1429#    done
1430#    (( iProc = iProc + 1 ))
1431#  done
1432
1433  # Concatenate all station along x
1434#  IGCM_sys_ncrcat ${prefix_invert}_stn_???.nc ${prefix_invert}_xt.nc
1435
1436  # Re-invert file
1437#  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x ${prefix_invert}_xt.nc ${file_out}
1438
1439  # END reordering
1440
1441  IGCM_debug_PopStack "IGCM_sys_rebuild_station"
1442}
1443
1444############################################################
1445# Activate Running Environnment Variables
1446
1447function IGCM_sys_activ_variables {
1448  IGCM_debug_PushStack "IGCM_sys_activ_variables"
1449  if ( $DEBUG_sys ) ; then
1450    echo "IGCM_sys_activ_variables"
1451  fi
1452  IGCM_debug_PopStack "IGCM_sys_activ_variables"
1453}
1454
1455############################################################
1456# Desactivate Running Environnment Variables
1457
1458function IGCM_sys_desactiv_variables {
1459  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1460  if ( $DEBUG_sys ) ; then
1461    echo "IGCM_sys_desactiv_variables"
1462  fi
1463  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1464}
1465
1466############################################################
1467# Build MPI/OMP scripts run file (dummy function)
1468
1469function IGCM_sys_build_run_file {
1470
1471  IGCM_debug_Print 3 " dummy function : IGCM_sys_build_run_file "
1472
1473}
1474
1475############################################################
1476# Build MPI/OMP scripts
1477function IGCM_sys_build_execution_scripts
1478{
1479  IGCM_debug_PushStack "IGCM_sys_build_execution_scripts" $@
1480  if ( $DEBUG_sys ) ; then
1481    echo "IGCM_sys_build_execution_scripts " $@
1482  fi
1483  typeset nodes listnodes init_node start_num init_exec comp ExeNameIn ExeNameOut
1484  typeset node_num_current node_current comp_proc_mpi_loc comp_proc_omp_loc
1485  typeset num_corempi nombre_restant_node nombre_restant_comp
1486
1487  if [ ! -f ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} ]  ; then
1488    IGCM_debug_Exit "IGCM_sys_titane build_execution_scripts : Job_${config_UserChoices_JobName} doesn't exist in SUBMIT_DIR : ${SUBMIT_DIR} "
1489  fi
1490
1491  if ( ${OK_PARA_MPMD} ) ; then
1492
1493    if [ -f run_file ] ; then
1494      IGCM_sys_Rm -f run_file
1495    fi
1496    touch run_file
1497
1498    if ( ${OK_PARA_OMP} ) ; then
1499
1500      #  Hosts treatment
1501
1502      ${HOST_MPIRUN_COMMAND} hostname | sort | uniq > hosts.tmp
1503
1504      i=0
1505      rm -f hosts
1506      IGCM_debug_Print 1 "sys Obelix, Hosts avaible :"
1507      for nodes in `cat hosts.tmp` ; do
1508        host[$i]=$nodes
1509        echo "${host[$i]} slots=1 max_slots=1" >> hosts
1510        IGCM_debug_Print 1 ${host[$i]}
1511        i=$((i+1))
1512      done
1513      rm -f hosts.tmp
1514
1515      listnodes=${host[*]}
1516
1517      EXECUTION="${HOST_MPIRUN_COMMAND} -hostfile hosts"
1518
1519      # Initialisation
1520
1521      init_node=y
1522      node_num_current=0
1523      start_num=0
1524      init_exec=n
1525
1526      # Test : if oasis is there, we put it at the first position
1527
1528      for comp in ${config_ListOfComponents[*]} ; do
1529
1530        if [ "X${comp}" = "XCPL" ]  ; then
1531
1532          eval ExeNameIn=\${config_Executable_${comp}[0]}
1533          eval ExeNameOut=\${config_Executable_${comp}[1]}
1534
1535          echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1536          echo ""  >> script_${ExeNameOut}.ksh
1537          #echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
1538          #echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
1539          #echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
1540          echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err"  >> script_${ExeNameOut}.ksh
1541          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1542
1543          init_node=n
1544
1545          (( nombre_restant_node = NUM_COREPERNODE - 1 ))
1546          node_num_current=0
1547          node_current=${host[${node_num_current}]}
1548
1549          EXECUTION="${EXECUTION} -H ${node_current} -np 1 ./script_${ExeNameOut}.ksh"
1550
1551          init_exec=y
1552          start_num=1
1553
1554        fi
1555
1556      done
1557
1558      # Then loop on the components (except for oasis)
1559
1560      for comp in ${config_ListOfComponents[*]} ; do
1561
1562        eval ExeNameIn=\${config_Executable_${comp}[0]}
1563        eval ExeNameOut=\${config_Executable_${comp}[1]}
1564
1565        # Only if we really have an executable for the component :
1566        if ( [ "X${ExeNameOut}" != X\"\" ] &&  [ "X${comp}" != "XCPL" ] ) ; then
1567
1568          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1569          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1570
1571          echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1572          # echo "set -vx" >> script_${ExeNameOut}.ksh
1573          echo ""  >> script_${ExeNameOut}.ksh
1574          #echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
1575          #echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
1576          #echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
1577          echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
1578          echo "(( MYMPIRANK = OMPI_COMM_WORLD_RANK - ${start_num})) " >>  script_${ExeNameOut}.ksh
1579          echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${MYMPIRANK} 2>out_${ExeNameOut}.err.\${MYMPIRANK}"  >> script_${ExeNameOut}.ksh
1580          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1581
1582          node_num=0
1583
1584          # We define the number of MPI process to be assigned for the component
1585
1586          nombre_restant_comp=${comp_proc_mpi_loc}
1587
1588          # Loop on the allocated nodes
1589
1590          for node in ${listnodes} ; do
1591
1592            # We go to the current node
1593            if [ ${node_num} = ${node_num_current} ] ; then
1594
1595              node_current=${host[${node_num_current}]}
1596
1597              # If first time on the node : initialisation
1598
1599              if [ ${init_node} = y ] ; then
1600                nombre_restant_node=${NUM_COREPERNODE}
1601              fi
1602
1603              # Test on the number of OMP threads
1604
1605              if [ ${comp_proc_omp_loc} -gt ${nombre_restant_node} ] ; then
1606                (( node_num = node_num + 1 ))
1607                node_num_current=${node_num}
1608                init_node=y
1609                continue
1610              fi
1611
1612              # Number of MPI process to assign
1613
1614              (( num_corempi = nombre_restant_node / comp_proc_omp_loc ))
1615
1616              if [ ${num_corempi} -gt ${nombre_restant_comp} ] ; then
1617                num_corempi=${nombre_restant_comp}
1618              fi
1619
1620              (( nombre_restant_node = nombre_restant_node - num_corempi * comp_proc_omp_loc ))
1621              (( nombre_restant_comp = nombre_restant_comp - num_corempi ))
1622
1623              if [ ${init_exec} = y ] ; then
1624                EXECUTION="${EXECUTION} : -H ${node_current} -np ${num_corempi} ./script_${ExeNameOut}.ksh"
1625              else
1626                EXECUTION="${EXECUTION} -H ${node_current} -np ${num_corempi} ./script_${ExeNameOut}.ksh"
1627                init_exec=y
1628              fi
1629
1630              ((  start_num = num_corempi + start_num ))
1631
1632            else
1633
1634              (( node_num = node_num + 1 ))
1635              continue
1636            fi
1637
1638            # Test on the number of core/process remaining on the node/component
1639
1640            if [ ${nombre_restant_node} = 0 ] ; then
1641              (( node_num = node_num + 1 ))
1642              node_num_current=${node_num}
1643              init_node=y
1644
1645              if [ ${nombre_restant_comp} = 0 ] ; then
1646                break 1
1647              fi
1648            else
1649
1650              node_num_current=${node_num}
1651              init_node=n
1652
1653              if [ ${nombre_restant_comp} = 0 ] ; then
1654                break 1
1655              fi
1656            fi
1657          done
1658        fi
1659      done
1660
1661    else
1662
1663      # Then first loop on the components for the coupler ie oasis
1664
1665      ## the coupler ie oasis must be the first one
1666      for comp in ${config_ListOfComponents[*]} ; do
1667
1668        eval ExeNameOut=\${config_Executable_${comp}[1]}
1669
1670        # for CPL component only
1671        if [ "X${comp}" = "XCPL" ] ; then
1672          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1673          echo "-np ${comp_proc_mpi_loc} ./${ExeNameOut} " >> run_file
1674        fi
1675      done
1676
1677        # Then second loop on the components
1678
1679      for comp in ${config_ListOfComponents[*]} ; do
1680
1681        eval ExeNameOut=\${config_Executable_${comp}[1]}
1682
1683        # Only if we really have an executable for the component and not the coupler ie oasis:
1684        if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${comp}" != "XCPL" ] ) ; then
1685          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1686          echo "-np ${comp_proc_mpi_loc} ./${ExeNameOut}" >> run_file
1687        fi
1688      done
1689      IGCM_sys_Chmod u+x run_file
1690
1691      EXECUTION="${HOST_MPIRUN_COMMAND} --app ./run_file"
1692
1693    fi
1694
1695  else # Only one executable. launch it.
1696
1697    for comp in ${config_ListOfComponents[*]} ; do
1698
1699      # Only if we really have an executable for the component :
1700      eval ExeNameOut=\${config_Executable_${comp}[1]}
1701      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${ExeNameOut}" != "Xinca.dat" ] ) ; then
1702
1703        echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1704        echo ""  >> script_${ExeNameOut}.ksh
1705        if ( ${OK_PARA_OMP} ) ; then
1706          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1707          echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
1708        fi
1709        if  ( ${OK_PARA_MPI} ) ; then
1710          # Default : mpirun used if nb_proc gt 1
1711          # pour sortie out/err par process
1712          # echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${OMPI_COMM_WORLD_RANK} 2>out_${ExeNameOut}.err.\${OMPI_COMM_WORLD_RANK}"  >> script_${ExeNameOut}.ksh
1713          echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1714          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1715          EXECUTION="${HOST_MPIRUN_COMMAND} ./script_${ExeNameOut}.ksh"
1716        else
1717          # Default : mpirun is NOT used if nb_proc eq 1
1718          # pour sortie out/err par process
1719          # echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err" >> script_${ExeNameOut}.ksh
1720          echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1721          IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1722          EXECUTION="time ./script_${ExeNameOut}.ksh"
1723        fi
1724      fi
1725    done
1726
1727  fi
1728
1729  IGCM_debug_Print 1 "sys Obelix : La commande d execution est "
1730  IGCM_debug_Print 1 $EXECUTION
1731
1732  IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
1733}
1734
1735############################################################
1736# Check of space available on temporary filesytems
1737function IGCM_sys_check_quota {
1738  IGCM_debug_PushStack "IGCM_sys_check_quota"
1739  if ( $DEBUG_sys ) ; then
1740    echo "IGCM_sys_check_quota"
1741  fi
1742  IGCM_debug_PopStack "IGCM_sys_check_quota"
1743}
1744
1745##############################################################
1746# NCO OPERATOR
1747
1748function IGCM_sys_ncap2 {
1749  IGCM_debug_PushStack "IGCM_sys_ncap2" -- $@
1750  if ( $DEBUG_sys ) ; then
1751    echo "IGCM_sys_ncap2 :" $@
1752  fi
1753
1754  typeset NB_ESSAI DELAI status i
1755  # number of tentative
1756  NB_ESSAI=3
1757  # time delay between tentative
1758  DELAI=2
1759
1760  i=0
1761  while [ $i -lt $NB_ESSAI ] ; do
1762    ncap2 "$@" > out_rsync 2>&1
1763    status=$?
1764    if [ ${status} -gt 0 ] ; then
1765      IGCM_debug_Print 2 "IGCM_sys_ncap2 : error code ${status}"
1766      cat out_rsync
1767      \rm out_rsync
1768      IGCM_debug_Print 2 "IGCM_sys_ncap2 : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1769      sleep $DELAI
1770    else
1771      \rm out_rsync
1772      break
1773    fi
1774    (( i = i + 1 ))
1775  done
1776
1777  if [ ${status} -gt 0 ] ; then
1778      echo "IGCM_sys_ncap2 : ncap2 error"
1779      IGCM_debug_Exit "ncap2"
1780  fi
1781
1782  IGCM_debug_PopStack "IGCM_sys_ncap2"
1783}
1784
1785function IGCM_sys_ncatted {
1786  IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
1787  if ( $DEBUG_sys ) ; then
1788    echo "IGCM_sys_ncatted :" $@
1789  fi
1790
1791  typeset NB_ESSAI DELAI status i
1792  # number of tentative
1793  NB_ESSAI=3
1794  # time delay between tentative
1795  DELAI=2
1796
1797  i=0
1798  while [ $i -lt $NB_ESSAI ] ; do
1799    ncatted "$@" > out_rsync 2>&1
1800    status=$?
1801    if [ ${status} -gt 0 ] ; then
1802      IGCM_debug_Print 2 "IGCM_sys_ncatted : error code ${status}"
1803      cat out_rsync
1804      \rm out_rsync
1805      IGCM_debug_Print 2 "IGCM_sys_ncatted : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1806      sleep $DELAI
1807    else
1808      \rm out_rsync
1809      break
1810    fi
1811    (( i = i + 1 ))
1812  done
1813
1814  if [ ${status} -gt 0 ] ; then
1815      echo "IGCM_sys_ncatted : ncatted error"
1816      IGCM_debug_Exit "ncatted"
1817  fi
1818
1819  IGCM_debug_PopStack "IGCM_sys_ncatted"
1820}
1821
1822function IGCM_sys_ncbo {
1823  IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
1824  if ( $DEBUG_sys ) ; then
1825    echo "IGCM_sys_ncbo :" $@
1826  fi
1827
1828  typeset NB_ESSAI DELAI status i
1829  # number of tentative
1830  NB_ESSAI=3
1831  # time delay between tentative
1832  DELAI=2
1833
1834  i=0
1835  while [ $i -lt $NB_ESSAI ] ; do
1836    ncbo $@ > out_rsync 2>&1
1837    status=$?
1838    if [ ${status} -gt 0 ] ; then
1839      IGCM_debug_Print 2 "IGCM_sys_ncbo : error code ${status}"
1840      cat out_rsync
1841      \rm out_rsync
1842      IGCM_debug_Print 2 "IGCM_sys_ncbo : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1843      sleep $DELAI
1844    else
1845      \rm out_rsync
1846      break
1847    fi
1848    (( i = i + 1 ))
1849  done
1850
1851  if [ ${status} -gt 0 ] ; then
1852      echo "IGCM_sys_ncbo : ncbo error"
1853      IGCM_debug_Exit "ncbo"
1854  fi
1855
1856  IGCM_debug_PopStack "IGCM_sys_ncbo"
1857}
1858
1859function IGCM_sys_ncdiff {
1860  IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
1861  if ( $DEBUG_sys ) ; then
1862    echo "IGCM_sys_ncdiff :" $@
1863  fi
1864
1865  typeset NB_ESSAI DELAI status i
1866  # number of tentative
1867  NB_ESSAI=3
1868  # time delay between tentative
1869  DELAI=2
1870
1871  i=0
1872  while [ $i -lt $NB_ESSAI ] ; do
1873    ncdiff $@ > out_rsync 2>&1
1874    status=$?
1875    if [ ${status} -gt 0 ] ; then
1876      IGCM_debug_Print 2 "IGCM_sys_ncdiff : error code ${status}"
1877      cat out_rsync
1878      \rm out_rsync
1879      IGCM_debug_Print 2 "IGCM_sys_ncdiff : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1880      sleep $DELAI
1881    else
1882      \rm out_rsync
1883      break
1884    fi
1885    (( i = i + 1 ))
1886  done
1887
1888  if [ ${status} -gt 0 ] ; then
1889      echo "IGCM_sys_ncdiff : ncdiff error"
1890      IGCM_debug_Exit "ncdiff"
1891  fi
1892
1893  IGCM_debug_PopStack "IGCM_sys_ncdiff"
1894}
1895
1896function IGCM_sys_ncea {
1897  IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
1898  if ( $DEBUG_sys ) ; then
1899    echo "IGCM_sys_ncea :" $@
1900  fi
1901
1902  typeset NB_ESSAI DELAI status i
1903  # number of tentative
1904  NB_ESSAI=3
1905  # time delay between tentative
1906  DELAI=2
1907
1908  i=0
1909  while [ $i -lt $NB_ESSAI ] ; do
1910    ncea $@ > out_rsync 2>&1
1911    status=$?
1912    if [ ${status} -gt 0 ] ; then
1913      IGCM_debug_Print 2 "IGCM_sys_ncea : error code ${status}"
1914      cat out_rsync
1915      \rm out_rsync
1916      IGCM_debug_Print 2 "IGCM_sys_ncea : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1917      sleep $DELAI
1918    else
1919      \rm out_rsync
1920      break
1921    fi
1922    (( i = i + 1 ))
1923  done
1924
1925  if [ ${status} -gt 0 ] ; then
1926      echo "IGCM_sys_ncea : ncea error"
1927      IGCM_debug_Exit "ncea"
1928  fi
1929
1930  IGCM_debug_PopStack "IGCM_sys_ncea"
1931}
1932
1933function IGCM_sys_ncecat {
1934  IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
1935  if ( $DEBUG_sys ) ; then
1936    echo "IGCM_sys_ncecat :" $@
1937  fi
1938
1939  typeset NB_ESSAI DELAI status i
1940  # number of tentative
1941  NB_ESSAI=3
1942  # time delay between tentative
1943  DELAI=2
1944
1945  i=0
1946  while [ $i -lt $NB_ESSAI ] ; do
1947    ncecat $@ > out_rsync 2>&1
1948    status=$?
1949    if [ ${status} -gt 0 ] ; then
1950      IGCM_debug_Print 2 "IGCM_sys_ncecat : error code ${status}"
1951      cat out_rsync
1952      \rm out_rsync
1953      IGCM_debug_Print 2 "IGCM_sys_ncecat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1954      sleep $DELAI
1955    else
1956      \rm out_rsync
1957      break
1958    fi
1959    (( i = i + 1 ))
1960  done
1961
1962  if [ ${status} -gt 0 ] ; then
1963      echo "IGCM_sys_ncecat : ncecat error"
1964      IGCM_debug_Exit "ncecat"
1965  fi
1966
1967  IGCM_debug_PopStack "IGCM_sys_ncecat"
1968}
1969
1970function IGCM_sys_ncflint {
1971  IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
1972  if ( $DEBUG_sys ) ; then
1973    echo "IGCM_sys_ncflint :" $@
1974  fi
1975
1976  typeset NB_ESSAI DELAI status i
1977  # number of tentative
1978  NB_ESSAI=3
1979  # time delay between tentative
1980  DELAI=2
1981
1982  i=0
1983  while [ $i -lt $NB_ESSAI ] ; do
1984    ncflint $@ > out_rsync 2>&1
1985    status=$?
1986    if [ ${status} -gt 0 ] ; then
1987      IGCM_debug_Print 2 "IGCM_sys_ncflint : error code ${status}"
1988      cat out_rsync
1989      \rm out_rsync
1990      IGCM_debug_Print 2 "IGCM_sys_ncflint : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1991      sleep $DELAI
1992    else
1993      \rm out_rsync
1994      break
1995    fi
1996    (( i = i + 1 ))
1997  done
1998
1999  if [ ${status} -gt 0 ] ; then
2000      echo "IGCM_sys_ncflint : ncflint error"
2001      IGCM_debug_Exit "ncflint"
2002  fi
2003
2004  IGCM_debug_PopStack "IGCM_sys_ncflint"
2005}
2006
2007function IGCM_sys_ncks {
2008  IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
2009  if ( $DEBUG_sys ) ; then
2010    echo "IGCM_sys_ncks :" $@
2011  fi
2012
2013  typeset NB_ESSAI DELAI status i
2014  # number of tentative
2015  NB_ESSAI=3
2016  # time delay between tentative
2017  DELAI=2
2018
2019  i=0
2020  while [ $i -lt $NB_ESSAI ] ; do
2021    ncks $@ > out_rsync 2>&1
2022    status=$?
2023    if [ ${status} -gt 0 ] ; then
2024      IGCM_debug_Print 2 "IGCM_sys_ncks : error code ${status}"
2025      cat out_rsync
2026      \rm out_rsync
2027      IGCM_debug_Print 2 "IGCM_sys_ncks : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2028      sleep $DELAI
2029    else
2030      \rm out_rsync
2031      break
2032    fi
2033    (( i = i + 1 ))
2034  done
2035
2036  if [ ${status} -gt 0 ] ; then
2037      echo "IGCM_sys_ncks : ncks error"
2038      IGCM_debug_Exit "ncks"
2039  fi
2040
2041  IGCM_debug_PopStack "IGCM_sys_ncks"
2042}
2043
2044function IGCM_sys_ncpdq {
2045  IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
2046  if ( $DEBUG_sys ) ; then
2047    echo "IGCM_sys_ncpdq :" $@
2048  fi
2049
2050  typeset NB_ESSAI DELAI status i
2051  # number of tentative
2052  NB_ESSAI=3
2053  # time delay between tentative
2054  DELAI=2
2055
2056  i=0
2057  while [ $i -lt $NB_ESSAI ] ; do
2058    ncpdq $@ > out_rsync 2>&1
2059    status=$?
2060    if [ ${status} -gt 0 ] ; then
2061      IGCM_debug_Print 2 "IGCM_sys_ncpdq : error code ${status}"
2062      cat out_rsync
2063      \rm out_rsync
2064      IGCM_debug_Print 2 "IGCM_sys_ncpdq : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2065      sleep $DELAI
2066    else
2067      \rm out_rsync
2068      break
2069    fi
2070    (( i = i + 1 ))
2071  done
2072
2073  if [ ${status} -gt 0 ] ; then
2074      echo "IGCM_sys_ncpdq : ncpdq error"
2075      IGCM_debug_Exit "ncpdq"
2076  fi
2077
2078  IGCM_debug_PopStack "IGCM_sys_ncpdq"
2079}
2080
2081function IGCM_sys_ncra {
2082  IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
2083  if ( $DEBUG_sys ) ; then
2084    echo "IGCM_sys_ncra :" $@
2085  fi
2086
2087  typeset NB_ESSAI DELAI status i
2088  # number of tentative
2089  NB_ESSAI=3
2090  # time delay between tentative
2091  DELAI=2
2092
2093  i=0
2094  while [ $i -lt $NB_ESSAI ] ; do
2095    ncra $@ > out_rsync 2>&1
2096    status=$?
2097    if [ ${status} -gt 0 ] ; then
2098      IGCM_debug_Print 2 "IGCM_sys_ncra : error code ${status}"
2099      cat out_rsync
2100      \rm out_rsync
2101      IGCM_debug_Print 2 "IGCM_sys_ncra : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2102      sleep $DELAI
2103    else
2104      \rm out_rsync
2105      break
2106    fi
2107    (( i = i + 1 ))
2108  done
2109
2110  if [ ${status} -gt 0 ] ; then
2111      echo "IGCM_sys_ncra : ncra error"
2112      IGCM_debug_Exit "ncra"
2113  fi
2114
2115  IGCM_debug_PopStack "IGCM_sys_ncra"
2116}
2117
2118function IGCM_sys_ncrcat {
2119  IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
2120  if ( $DEBUG_sys ) ; then
2121    echo "IGCM_sys_ncrcat :" $@
2122  fi
2123
2124  typeset NB_ESSAI DELAI status i
2125  # number of tentative
2126  NB_ESSAI=3
2127  # time delay between tentative
2128  DELAI=2
2129
2130  i=0
2131  while [ $i -lt $NB_ESSAI ] ; do
2132    ncrcat $@ > out_rsync 2>&1
2133    status=$?
2134    if [ ${status} -gt 0 ] ; then
2135      IGCM_debug_Print 2 "IGCM_sys_ncrcat : error code ${status}"
2136      cat out_rsync
2137      \rm out_rsync
2138      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2139      sleep $DELAI
2140    else
2141      \rm out_rsync
2142      break
2143    fi
2144    (( i = i + 1 ))
2145  done
2146
2147  if [ ${status} -gt 0 ] ; then
2148      echo "IGCM_sys_ncrcat : ncrcat error"
2149      #IGCM_debug_Exit "ncrcat"
2150  fi
2151
2152  IGCM_debug_PopStack "IGCM_sys_ncrcat"
2153}
2154
2155function IGCM_sys_ncrename {
2156  IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
2157  if ( $DEBUG_sys ) ; then
2158    echo "IGCM_sys_ncrename :" $@
2159  fi
2160
2161  typeset NB_ESSAI DELAI status i
2162  # number of tentative
2163  NB_ESSAI=3
2164  # time delay between tentative
2165  DELAI=2
2166
2167  i=0
2168  while [ $i -lt $NB_ESSAI ] ; do
2169    ncrename $@ > out_rsync 2>&1
2170    status=$?
2171    if [ ${status} -gt 0 ] ; then
2172      IGCM_debug_Print 2 "IGCM_sys_ncrename : error code ${status}"
2173      cat out_rsync
2174      \rm out_rsync
2175      IGCM_debug_Print 2 "IGCM_sys_ncrename : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2176      sleep $DELAI
2177    else
2178      \rm out_rsync
2179      break
2180    fi
2181    (( i = i + 1 ))
2182  done
2183
2184  if [ ${status} -gt 0 ] ; then
2185      echo "IGCM_sys_ncrename : ncrename error"
2186      IGCM_debug_Exit "ncrename"
2187  fi
2188
2189  IGCM_debug_PopStack "IGCM_sys_ncrename"
2190}
2191
2192function IGCM_sys_ncwa {
2193  IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
2194  if ( $DEBUG_sys ) ; then
2195    echo "IGCM_sys_ncwa :" $@
2196  fi
2197
2198  typeset NB_ESSAI DELAI status i
2199  # number of tentative
2200  NB_ESSAI=3
2201  # time delay between tentative
2202  DELAI=2
2203
2204  i=0
2205  while [ $i -lt $NB_ESSAI ] ; do
2206    ncwa $@ > out_rsync 2>&1
2207    status=$?
2208    if [ ${status} -gt 0 ] ; then
2209      IGCM_debug_Print 2 "IGCM_sys_ncwa : error code ${status}"
2210      cat out_rsync
2211      \rm out_rsync
2212      IGCM_debug_Print 2 "IGCM_sys_ncwa : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
2213      sleep $DELAI
2214    else
2215      \rm out_rsync
2216      break
2217    fi
2218    (( i = i + 1 ))
2219  done
2220
2221  if [ ${status} -gt 0 ] ; then
2222      echo "IGCM_sys_ncwa : ncwa error"
2223      IGCM_debug_Exit "ncwa"
2224  fi
2225
2226  IGCM_debug_PopStack "IGCM_sys_ncwa"
2227}
2228
2229##############################################################
2230# CDO OPERATOR
2231
2232function IGCM_sys_cdo {
2233  IGCM_debug_PushStack "IGCM_sys_cdo" -- $@
2234  if ( $DEBUG_sys ) ; then
2235    echo "IGCM_sys_cdo :" $@
2236  fi
2237
2238  typeset status
2239
2240  \cdo $@ > out_rsync 2>&1
2241  status=$?
2242  if [ ${status} -gt 0 ] ; then
2243    echo "IGCM_sys_cdo : error code ${status}"
2244    cat out_rsync
2245    \rm out_rsync
2246    IGCM_debug_PopStack "IGCM_sys_cdo"
2247    return 1
2248  else
2249    IGCM_debug_PopStack "IGCM_sys_cdo"
2250    return 0
2251  fi
2252
2253  IGCM_debug_PopStack "IGCM_sys_cdo"
2254}
Note: See TracBrowser for help on using the repository browser.