source: tags/libIGCM_v2.0_rc1/libIGCM_sys/libIGCM_sys_ulam.ksh @ 1137

Last change on this file since 1137 was 725, checked in by sdipsl, 12 years ago
  • prepare sys lib to be able to run/store on scratchdir when running TEST simulation
  • bugfix : rebuild can't overwrite existing files neither write things in a tmp file before moving it to a final file. So we need to clean things up for him
  • cosmetics
  • Property svn:keywords set to Revision Author Date
File size: 45.3 KB
Line 
1#!/bin/ksh
2
3#**************************************************************
4# Author: Sebastien Denvil
5# Contact: Sebastien.Denvil__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 Ulam
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 |            |  Chmod  |                           |
46# |          |      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
70#D-
71#D-#==================================================
72#D-Program used in libIGCM
73#D-#==================================================
74
75# rsync with path
76typeset -r RSYNC=/usr/bin/rsync
77# RSYNC_opt args to rsync
78typeset -r RSYNC_opt="-Lt -v"
79# RSYNC_opt args to "remote rsync"
80# ie storage filesystem
81typeset -r RHOST=gaya.idris.fr
82typeset -r REMOTE_RSYNC=/u/rech/ces/rces452/RSYNC/bin/rsync
83
84#====================================================
85# Set environment tools (ferret, nco, cdo)
86#====================================================
87. /home/rech/psl/rpsl035/.atlas_env_ulam_bash
88
89#====================================================
90# Host specific DIRECTORIES
91#====================================================
92
93#====================================================
94#- R_EXE   (==> BIN_DIR = ${MODIPSL}/bin )
95typeset -r R_EXE="${MODIPSL}/bin"
96
97#====================================================
98#- SUBMIT_DIR : submission dir
99typeset SUBMIT_DIR=${SUBMIT_DIR:=${LOADL_STEP_INITDIR}}
100
101#====================================================
102#- IN
103typeset -r R_IN=${R_IN:=/u/rech/psl/rpsl035/IGCM}
104typeset -r R_IN_ECMWF=${R_IN_ECMWF:=/u/rech/psl/rpsl376}
105
106#====================================================
107#- ARCHIVE
108# modified 17/10/2011 /u to be used for file stored on gaya
109if (tty -s ) then
110  typeset -r ARCHIVE=${HOMEGAYA}
111else
112  typeset -r ARCHIVE=$(echo ${HOMEGAYA}|sed 's,/homegaya/,/u/',)
113fi
114
115#====================================================
116#- OUT
117typeset -r R_OUT=${ARCHIVE}/IGCM_OUT
118
119#====================================================
120#- R_FIG (hosting figures : monitoring and atlas, and/or small files)
121typeset -r R_FIG=${ARCHIVE}/IGCM_OUT
122
123#====================================================
124#- R_BUF  Buffer to pack files stored on Master
125typeset -r R_BUF=${WORKDIR}/IGCM_OUT
126
127#====================================================
128#- OUT_POST
129typeset -r R_OUT_POST=${WORKDIR}/IGCM_OUT
130
131#====================================================
132#- RUN_DIR_PATH : Temporary working directory (=> TMP)
133typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=${TMPDIR}}
134
135#====================================================
136#- Max number of arguments passed to nco operator or demigration command
137UNIX_MAX_LIMIT=120
138
139#D-#==================================================
140#D-function IGCM_sys_ChangeArchive
141#D-* Purpose: Just a dummy call on this machine
142#D-* Examples:
143#D-
144function IGCM_sys_ChangeArchive {
145
146  IGCM_debug_Print 1 " dummy function : IGCM_sys_ChangeArchive "
147
148}
149
150#D-#==================================================
151#D-function IGCM_sys_RshMaster
152#D-* Purpose: Master rsh command
153#D-* Examples:
154#D-
155function IGCM_sys_RshMaster {
156    #set -vx
157  IGCM_debug_PushStack "IGCM_sys_RshMaster" $@
158  rsh ${MASTER} exec /bin/ksh <<-EOF
159    export libIGCM=${libIGCM_SX}
160    export DEBUG_debug=${DEBUG_debug}
161    . ${libIGCM_SX}/libIGCM_debug/libIGCM_debug.ksh
162    . ${libIGCM_SX}/libIGCM_card/libIGCM_card.ksh
163    ${@}
164EOF
165  if [ $? -gt 0 ] ; then
166    echo "IGCM_sys_RshMaster : erreur."
167    IGCM_debug_Exit "IGCM_sys_RshMaster"
168  fi
169  IGCM_debug_PopStack "IGCM_sys_RshMaster"
170}
171
172#D-#==================================================
173#D-function IGCM_sys_RshArchive
174#D-* Purpose: Archive rsh command
175#D-* Examples:
176#D-
177function IGCM_sys_RshArchive {
178  IGCM_debug_PushStack "IGCM_sys_RshArchive" $@
179  /bin/ksh <<-EOF
180    ${@}
181EOF
182  if [ $? -gt 0 ] ; then
183    echo "IGCM_sys_RshArchive : erreur."
184    IGCM_debug_Exit "IGCM_sys_RshArchive"
185  fi
186  IGCM_debug_PopStack "IGCM_sys_RshArchive"
187}
188
189#D-#==================================================
190#D-function IGCM_sys_RshPost
191#D-* Purpose: Master rsh command
192#D-* Examples:
193#D-
194function IGCM_sys_RshPost {
195  IGCM_debug_PushStack "IGCM_sys_RshPost" $@
196  if ( $DEBUG_sys ) ; then
197    echo "IGCM_sys_RshPost :" $@
198  fi
199  /bin/ksh ${@}
200  if [ $? -gt 0 ] ; then
201    echo "IGCM_sys_RshPost : erreur."
202    IGCM_debug_Exit "IGCM_sys_RshPost"
203  fi
204  IGCM_debug_PopStack "IGCM_sys_RshPost"
205}
206
207#D-#==================================================
208#D-function IGCM_sys_SendMail
209#D-* Purpose: Send mail when simulation is over
210#D-* Examples:
211#D-
212function IGCM_sys_SendMail {
213  IGCM_debug_PushStack "IGCM_sys_SendMailPost" $@
214  if ( $DEBUG_sys ) ; then
215    echo "IGCM_sys_SendMail :" $@
216  fi
217
218  if ( ${ExitFlag} ) ; then
219    status=failed
220  else
221    status=completed
222  fi
223  cat  << END_MAIL > job_end.mail
224Dear ${LOGIN},
225
226  Simulation ${config_UserChoices_JobName} is ${status} on supercomputer `hostname`.
227  Job started : ${DateBegin}
228  Job ended   : ${DateEnd}
229  Output files are available in ${R_SAVE}
230  Script files, Script Outputs and Debug files (if necessary) are available in ${SUBMIT_DIR}
231END_MAIL
232
233  if [ ! -z ${config_UserChoices_MailName} ] ; then
234    mailx -s "${config_UserChoices_JobName} ${status}" ${config_UserChoices_MailName} < job_end.mail
235  elif [ -f ~/.forward ] ; then
236    mailx -s "${config_UserChoices_JobName} ${status}" $( cat ~/.forward ) < job_end.mail
237  fi
238
239  if [ $? -gt 0 ] ; then
240    echo "IGCM_sys_SendMail : erreur."
241    IGCM_debug_Exit "IGCM_sys_SendMail"
242  fi
243  IGCM_debug_PopStack "IGCM_sys_SendMail"
244}
245
246#D-#==================================================
247#D-function IGCM_sys_Mkdir
248#D-* Purpose: Master locale mkdir command
249#D-* Examples:
250#D-
251function IGCM_sys_Mkdir {
252  IGCM_debug_PushStack "IGCM_sys_Mkdir" $@
253  if ( $DEBUG_sys ) ; then
254    echo "IGCM_sys_Mkdir :" $@
255  fi
256  if [ ! -d ${1} ]; then
257    \mkdir -p $1
258    if [ $? -gt 0 ] ; then
259      echo "IGCM_sys_Mkdir : erreur."
260      IGCM_debug_Exit "IGCM_sys_Mkdir"
261    fi
262  fi
263    # vérification :
264  if [ ! -d ${1} ] ; then
265    echo "IGCM_sys_Mkdir : erreur."
266    IGCM_debug_Exit "IGCM_sys_Mkdir"
267  fi
268  IGCM_debug_PopStack "IGCM_sys_Mkdir"
269}
270
271#D-#==================================================
272#D-function IGCM_sys_MkdirArchive
273#D-* Purpose: Mkdir on Archive
274#D-* Examples:
275#D-
276function IGCM_sys_MkdirArchive {
277  IGCM_debug_PushStack "IGCM_sys_MkdirArchive" $@
278  if ( $DEBUG_sys ) ; then
279    echo "IGCM_sys_MkdirArchive :" $@
280  fi
281    #- creation de repertoire sur le serveur fichier
282  if [ ! -d ${1} ]; then
283    \mkdir -p $1
284    if [ $? -gt 0 ] ; then
285      echo "IGCM_sys_MkdirArchive : erreur."
286      IGCM_debug_Exit "IGCM_sys_MkdirArchive"
287    fi
288  fi
289  IGCM_debug_PopStack "IGCM_sys_MkdirArchive"
290}
291
292#D-#==================================================
293#D-function IGCM_sys_MkdirWork
294#D-* Purpose: Mkdir on Work
295#D-* Examples:
296#D-
297function IGCM_sys_MkdirWork {
298  IGCM_debug_PushStack "IGCM_sys_MkdirWork" $@
299  if ( $DEBUG_sys ) ; then
300    echo "IGCM_sys_MkdirWork :" $@
301  fi
302    #- creation de repertoire sur le serveur fichier
303  if [ ! -d ${1} ]; then
304    \mkdir -p $1
305    if [ $? -gt 0 ] ; then
306      echo "IGCM_sys_MkdirWork : erreur."
307      IGCM_debug_Exit "IGCM_sys_MkdirWork"
308    fi
309  fi
310  IGCM_debug_PopStack "IGCM_sys_MkdirWork"
311}
312
313#D-#==================================================
314#D-function IGCM_sys_Cd
315#D-* Purpose: master cd command
316#D-* Examples:
317#D-
318function IGCM_sys_Cd {
319  IGCM_debug_PushStack "IGCM_sys_Cd" $@
320  if ( $DEBUG_sys ) ; then
321    echo "IGCM_sys_Cd :" $@
322  fi
323  \cd $1
324  if [ $? -gt 0 ] ; then
325    echo "IGCM_sys_Cd : erreur."
326    IGCM_debug_Exit "IGCM_sys_Cd"
327  fi
328  IGCM_debug_PopStack "IGCM_sys_Cd"
329}
330
331#D-#==================================================
332#D-function IGCM_sys_Chmod
333#D-* Purpose: Chmod
334#D-* Examples:
335#D-
336function IGCM_sys_Chmod {
337  IGCM_debug_PushStack "IGCM_sys_Chmod" $@
338  if ( $DEBUG_sys ) ; then
339    echo "IGCM_sys_Chmod :" $@
340  fi
341  if [ $DRYRUN -le 1 ]; then
342    \chmod $@
343    if [ $? -gt 0 ] ; then
344      echo "IGCM_sys_Chmod : erreur."
345      IGCM_debug_Exit "IGCM_sys_Chmod"
346    fi
347  else
348    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
349  fi
350  IGCM_debug_PopStack "IGCM_sys_Chmod"
351}
352
353#D-#==================================================
354#D-function IGCM_sys_FileSize
355#D-* Purpose: Filesize
356#D-* Examples:
357#D-
358function IGCM_sys_FileSize {
359  IGCM_debug_PushStack "IGCM_sys_FileSize" $@
360
361  typeset sizeF
362  set +A sizeF -- $( ls -la ${1} )
363  if [ $? -gt 0 ] ; then
364    IGCM_debug_Exit "IGCM_sys_FileSize"
365  fi
366  eval ${2}=${sizeF[4]}
367
368  IGCM_debug_PopStack "IGCM_sys_FileSize"
369}
370
371#D-#==================================================
372#D-function IGCM_sys_TestDir
373#D-* Purpose: Test Directory that must exists
374#D-* Examples:
375#D-
376function IGCM_sys_TestDir {
377  IGCM_debug_PushStack "IGCM_sys_TestDir" $@
378  if ( $DEBUG_sys ) ; then
379    echo "IGCM_sys_TestDir :" $@
380  fi
381  typeset ExistFlag
382  ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
383  IGCM_debug_PopStack "IGCM_sys_TestDir"
384
385  return ${ExistFlag}
386}
387
388#D-#==================================================
389#D-function IGCM_sys_TestDirArchive
390#D-* Purpose: Test Directory that must exists on Archive
391#D-* Examples:
392#D-
393function IGCM_sys_TestDirArchive {
394  IGCM_debug_PushStack "IGCM_sys_TestDirArchive" $@
395  if ( $DEBUG_sys ) ; then
396    echo "IGCM_sys_TestDirArchive :" $@
397  fi
398  typeset ExistFlag DirNameToTest
399    # modified 17/10/2011 /u is not known on ulam, use /homegaya instead to test dir locally on ulam
400  DirNameToTest=$(echo $1 | sed 's,/u/,/homegaya/,')
401  ExistFlag=$( [ -d ${DirNameToTest} ] && echo 0 || echo 1 )
402  IGCM_debug_PopStack "IGCM_sys_TestDirArchive"
403
404  return ${ExistFlag}
405}
406
407#D-#==================================================
408#D-function IGCM_sys_TestFileArchive
409#D-* Purpose: Test file that must NOT EXISTS on Archive
410#D-* Examples:
411#D-
412function IGCM_sys_TestFileArchive {
413  IGCM_debug_PushStack "IGCM_sys_TestFileArchive" $@
414  typeset ExistFlag FileNameToTest
415  # modified 17/10/2011 /u is not known on ulam, use /homegaya instead to test dir locally on ulam
416  FileNameToTest=$(echo $1 | sed 's,/u/,/homegaya/,')
417  ExistFlag=$( IGCM_sys_RshArchive "[ -f ${FileNameToTest} ] && echo 0 || echo 1" )
418  IGCM_debug_PopStack "IGCM_sys_TestFileArchive"
419
420  return ${ExistFlag}
421}
422
423#D-#==================================================
424#D-function IGCM_sys_CountFileArchive
425#D-* Purpose: Count files on Archive filesystem
426#D-* Examples:
427#D-
428function IGCM_sys_CountFileArchive {
429  IGCM_debug_PushStack "IGCM_sys_CountFileArchive" $@
430  IGCM_sys_RshArchive "ls ${@} 2>/dev/null | wc -l"
431  if [ $? -gt 0 ] ; then
432    echo "IGCM_sys_CountFileArchive : erreur."
433  fi
434  IGCM_debug_PopStack "IGCM_sys_CountFileArchive"
435}
436
437#D-#==================================================
438#D-function IGCM_sys_Tree
439#D-* Purpose: Tree directories with files on ${ARCHIVE}
440#D-* Examples: IGCM_sys_Tree ${R_IN} ${R_OUT}
441#D-
442function IGCM_sys_Tree {
443  IGCM_debug_PushStack "IGCM_sys_Tree" $@
444  if ( $DEBUG_sys ) ; then
445    echo "IGCM_sys_Tree :" $@
446  fi
447
448  \mfls -r $@
449
450  IGCM_debug_PopStack "IGCM_sys_Tree"
451}
452
453#D-#==================================================
454#D-function IGCM_sys_Tar
455#D-* Purpose: master un-tar command
456#D-* Examples:
457#D-
458function IGCM_sys_Tar {
459  IGCM_debug_PushStack "IGCM_sys_Tar" $@
460  if ( $DEBUG_sys ) ; then
461    echo "IGCM_sys_Tar :" $@
462  fi
463  \tar cvf $@
464  if [ $? -gt 0 ] ; then
465    echo "IGCM_sys_Tar : erreur."
466    IGCM_debug_Exit "IGCM_sys_Tar"
467  fi
468  \tar tvf $1
469
470  IGCM_debug_PopStack "IGCM_sys_Tar"
471}
472
473#D-#==================================================
474#D-function IGCM_sys_UnTar
475#D-* Purpose: master un-tar command
476#D-* Examples:
477#D-
478function IGCM_sys_UnTar {
479  IGCM_debug_PushStack "IGCM_sys_UnTar" $@
480  if ( $DEBUG_sys ) ; then
481    echo "IGCM_sys_UnTar :" $@
482  fi
483  \tar xvf $1
484  if [ $? -gt 0 ] ; then
485    echo "IGCM_sys_UnTar : erreur."
486    IGCM_debug_Exit "IGCM_sys_UnTar"
487  fi
488  IGCM_debug_PopStack "IGCM_sys_UnTar"
489}
490
491#D-#==================================================
492#D-function IGCM_sys_QsubPost
493#D-* Purpose: Qsub new job on scalaire
494#D-* Examples:
495#D-
496function IGCM_sys_QsubPost {
497  IGCM_debug_PushStack "IGCM_sys_QsubPost" $@
498  if ( $DEBUG_sys ) ; then
499    echo "IGCM_sys_QsubPost :" $@
500  fi
501  cd ${POST_DIR}
502  /opt/ibmll/LoadL/full/bin/llsubmit ${libIGCM}/$1.job
503  cd -
504  if [ $? -gt 0 ] ; then
505    echo "IGCM_sys_QsubPost : erreur " $@
506    IGCM_debug_Exit "IGCM_sys_QsubPost"
507  fi
508  IGCM_debug_PopStack "IGCM_sys_QsubPost"
509}
510
511#D-*************************
512#D- File transfer functions
513#D-*************************
514#D-
515
516#D-#==================================================
517#D-function IGCM_sys_Rsync_out
518#D-* Purpose: treat return val of rsync
519#D-* Examples: IGCM_sys_Rsync_out out_RET_rsync
520#D-  Error values and explanations can depend on your system version.
521function IGCM_sys_Rsync_out {
522  status=$1
523  if [ ! $status ] ; then
524    echo "rsync error !"
525  fi
526
527  if [ $MYLANG = "fr" ]; then
528    case $status in
529    0)  return ;;
530    1)  echo "Erreur de rsync ; RERR_SYNTAX : "
531      echo "Erreur de syntaxe ou d'utilisation."
532      return;;
533    2)  echo "Erreur de rsync ; RERR_PROTOCOL : "
534      echo "Incompatibilité de protocole."
535      return;;
536    3)  echo "Erreur de rsync ; RERR_FILESELECT 3"
537      echo "Erreurs  lors  de  la  sélection des fichiers d'entrée sortie et"
538      echo "répertoires"
539      return;;
540    4)  echo "Erreur de rsync ; RERR_UNSUPPORTED"
541      echo "Action demandée non supportée : une tentative de manipulation de"
542      echo "fichiers  64-bits  sur une plate-forme qui ne les supporte pas a"
543      echo "été faite ; ou une option qui est supportée par le  client  mais"
544      echo "pas par le serveur a été spécifiée."
545      return;;
546    10) echo "Erreur de rsync ; RERR_SOCKETIO"
547      echo "Erreur dans le socket d'entrée sortie"
548      return;;
549    11) echo "Erreur de rsync ; RERR_FILEIO"
550      echo "Erreur d'entrée sortie fichier"
551      return;;
552    12) echo "Erreur de rsync ; RERR_STREAMIO"
553      echo "Erreur dans flux de donnée du protocole rsync"
554      return;;
555    13) echo "Erreur de rsync ; RERR_MESSAGEIO"
556      echo "Erreur avec les diagnostics du programme"
557      return;;
558    14) echo "Erreur de rsync ; RERR_IPC"
559      echo "Erreur dans le code IPC"
560      return;;
561    20) echo "Erreur de rsync ; RERR_SIGNAL"
562      echo "SIGUSR1 ou SIGINT reçu"
563      return;;
564    21) echo "Erreur de rsync ; RERR_WAITCHILD"
565      echo "Une erreur retournée par waitpid()"
566      return;;
567    22) echo "Erreur de rsync ; RERR_MALLOC"
568      echo "Erreur lors de l'allocation des tampons de mémoire de coeur"
569      return;;
570    23) echo ""
571      echo "Erreur fichier inexistant"
572      return;;
573    30) echo "Erreur de rsync ; RERR_TIMEOUT"
574      echo "Temps d'attente écoulé dans l'envoi/réception de données"
575      return;;
576    *)  echo "Erreur de rsync : code de retour de rsync inconnu :" $status
577      return;;
578    esac
579  elif [ $MYLANG = "en" ] ; then
580    case $status in
581    0)  return;;
582    1)  echo "rsync error : Syntax or usage error "
583      return;;
584    2)  echo "rsync error : Protocol incompatibility "
585      return;;
586    3)  echo "rsync error : Errors selecting input/output files, dirs"
587      return;;
588    4)  echo "rsync error : Requested action not supported: an attempt"
589      echo "was made to manipulate 64-bit files on a platform that cannot support"
590      echo "them; or an option was specified that is supported by the client and"
591      echo "not by the server."
592      return;;
593    5)  echo "rsync error : Error starting client-server protocol"
594      return;;
595    10) echo "rsync error : Error in socket I/O "
596      return;;
597    11) echo "rsync error : Error in file I/O "
598      return;;
599    12) echo "rsync error : Error in rsync protocol data stream "
600      return;;
601    13) echo "rsync error : Errors with program diagnostics "
602      return;;
603    14) echo "rsync error : Error in IPC code "
604      return;;
605    20) echo "rsync error : Received SIGUSR1 or SIGINT "
606      return;;
607    21) echo "rsync error : Some error returned by waitpid() "
608      return;;
609    22) echo "rsync error : Error allocating core memory buffers "
610      return;;
611    23) echo "rsync error : Partial transfer due to error"
612      return;;
613    24) echo "rsync error : Partial transfer due to vanished source files"
614      return;;
615    30) echo "rsync error : Timeout in data send/receive "
616      return;;
617    *)  echo "rsync error : return code of rsync unknown :" $status
618      return;;
619    esac
620  else
621    echo "unknown language $MYLANG."
622    return
623  fi
624}
625
626#D-#==================================================
627#D-function IGCM_sys_Cp
628#D-* Purpose: generic cp
629#D-* Examples:
630#D-
631function IGCM_sys_Cp {
632  IGCM_debug_PushStack "IGCM_sys_Cp" $@
633  if ( $DEBUG_sys ) ; then
634    echo "IGCM_sys_Cp :" $@
635  fi
636
637  typeset status
638
639  echo cp $@ > out_rsync 2>&1
640  \cp $@ >> out_rsync 2>&1
641  status=$?
642
643  if [ ${status} -gt 0 ] ; then
644    echo "IGCM_sys_Cp : error."
645    cat out_rsync
646    IGCM_debug_Exit "IGCM_sys_Cp"
647  fi
648  IGCM_debug_PopStack "IGCM_sys_Cp"
649}
650
651#D-#==================================================
652#D-function IGCM_sys_Rm
653#D-* Purpose: generic rm
654#D-* Examples:
655#D-
656function IGCM_sys_Rm {
657  IGCM_debug_PushStack "IGCM_sys_Rm" -- $@
658  if ( $DEBUG_sys ) ; then
659    echo "IGCM_sys_Rm :" $@
660  fi
661
662  typeset status
663
664  echo rm $@ > out_rsync 2>&1
665  \rm $@ >> out_rsync 2>&1
666  status=$?
667
668  if [ ${status} -gt 0 ] ; then
669    echo "IGCM_sys_Rm : error."
670    cat out_rsync
671    IGCM_debug_Exit "IGCM_sys_Rm"
672  fi
673  IGCM_debug_PopStack "IGCM_sys_Rm"
674}
675
676#D-#==================================================
677#D-function IGCM_sys_RmRunDir
678#D-* Purpose: rm tmpdir (dummy function most of the time batch
679#D-                      scheduler will do the job)
680#D-* Examples:
681#D-
682function IGCM_sys_RmRunDir {
683  IGCM_debug_PushStack "IGCM_sys_RmRunDir" -- $@
684  if ( $DEBUG_sys ) ; then
685    echo "IGCM_sys_RmRunDir :" $@
686    echo "Dummy call, let the scheduler do that."
687  fi
688  IGCM_debug_PopStack "IGCM_sys_RmRunDir"
689}
690
691#D-#==================================================
692#D-function IGCM_sys_Mv
693#D-* Purpose: generic move
694#D-* Examples:
695#D-
696function IGCM_sys_Mv {
697  IGCM_debug_PushStack "IGCM_sys_Mv" $@
698  if ( $DEBUG_sys ) ; then
699    echo "IGCM_sys_Mv :" $@
700  fi
701
702  if [ $DRYRUN = 0 ]; then
703
704    typeset status
705
706    echo mv $@ > out_rsync 2>&1
707    \mv $@ >> out_rsync 2>&1
708    status=$?
709
710    if [ ${status} -gt 0 ] ; then
711      echo "IGCM_sys_Mv : error in mv."
712      cat out_rsync
713      IGCM_debug_Exit "IGCM_sys_Mv"
714    fi
715  else
716    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
717  fi
718
719  IGCM_debug_PopStack "IGCM_sys_Mv"
720}
721
722#D-#==================================================
723#D-function IGCM_sys_Put_Dir
724#D-* Purpose: Copy a complete directory on $(ARCHIVE)
725#D-* Examples:
726#D-
727function IGCM_sys_Put_Dir {
728  IGCM_debug_PushStack "IGCM_sys_Put_Dir" $@
729  if ( $DEBUG_sys ) ; then
730    echo "IGCM_sys_Put_Dir :" $@
731  fi
732  if [ $DRYRUN = 0 ]; then
733    if [ ! -d ${1} ] ; then
734      echo "WARNING : IGCM_sys_Put_Dir ${1} DOES NOT EXIST ."
735      IGCM_debug_PopStack "IGCM_sys_Put_Dir"
736      return
737    fi
738
739    typeset status
740
741    # Only if we use rsync
742    #IGCM_sys_TestDirArchive $( dirname $2 )
743    #
744    #USUAL WAY
745    rcp -r $1 gaya:$2 > out_rsync 2>&1
746    status=$?
747
748    if [ ${status} -gt 0 ] ; then
749      echo "IGCM_sys_Put_Dir : error."
750      cat out_rsync
751      IGCM_debug_Exit "IGCM_sys_Put_Dir"
752    fi
753
754    # due to rcommand latency
755    sleep 10
756
757  else
758    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
759  fi
760  IGCM_debug_PopStack "IGCM_sys_Put_Dir"
761}
762
763#D-#==================================================
764#D-function IGCM_sys_Get_Dir
765#D-* Purpose: Copy a complete directory from $(ARCHIVE)
766#D-* Examples:
767#D-
768function IGCM_sys_Get_Dir {
769  IGCM_debug_PushStack "IGCM_sys_Get_Dir" $@
770  if ( $DEBUG_sys ) ; then
771    echo "IGCM_sys_Get_Dir :" $@
772  fi
773  if [ $DRYRUN = 0 ]; then
774
775#       if [ ! -d ${1} ] ; then
776#           echo "WARNING : IGCM_sys_Get_Dir ${1} DOES NOT EXIST ."
777#           IGCM_debug_PopStack "IGCM_sys_Get_Dir"
778#           return
779#       fi
780
781    typeset status
782
783    #USUAL WAY
784    rcp -rp gaya:$1 $2 > out_rsync 2>&1
785    status=$?
786
787    if [ ${status} -gt 0 ] ; then
788      echo "IGCM_sys_Get_Dir : error."
789      cat out_rsync
790      IGCM_debug_Exit "IGCM_sys_Get_Dir"
791    fi
792  else
793    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
794  fi
795  IGCM_debug_PopStack "IGCM_sys_Get_Dir"
796}
797
798#D-#==================================================
799#D-function IGCM_sys_Get_Master
800#D-* Purpose: Copy a complete directory from MASTER filesystem
801#D-* Examples:
802#D-
803function IGCM_sys_Get_Master {
804  IGCM_debug_PushStack "IGCM_sys_Get_Master" $@
805  if ( $DEBUG_sys ) ; then
806    echo "IGCM_sys_Get_Master :" $@
807  fi
808  if [ $DRYRUN = 0 ]; then
809    TEST=$( IGCM_sys_RshMaster [ -d $1 ] || [ -f $1 ] && echo 1 || echo 0 )
810    if [ ${TEST} -ne 1 ] ; then
811      echo "WARNING : IGCM_sys_Get_Master ${1} DOES NOT EXIST ON ${MASTER}."
812      IGCM_debug_PopStack "IGCM_sys_Get_Master"
813      return
814    fi
815
816    typeset status
817
818    #USUAL WAY
819    rcp -r ${MASTER}:$1 $2 > out_rsync 2>&1
820    status=$?
821
822    if [ ${status} -gt 0 ] ; then
823      echo "IGCM_sys_Get_Master : error."
824      cat out_rsync
825      IGCM_debug_Exit "IGCM_sys_Get_Master"
826    fi
827  else
828    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
829  fi
830  IGCM_debug_PopStack "IGCM_sys_Get_Master"
831}
832
833#D-#==================================================
834#D-function IGCM_sys_Put_Out
835#D-* Purpose: Copy a file on $(ARCHIVE) after have chmod it in readonly
836#D-* Examples:
837#D-
838function IGCM_sys_Put_Out {
839  IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
840  if ( $DEBUG_sys ) ; then
841    echo "IGCM_sys_Put_Out :" $@
842  fi
843  if [ $DRYRUN = 0 ]; then
844    if [ ! -f ${1} ] ; then
845      echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
846      IGCM_debug_PopStack "IGCM_sys_Put_Out"
847      return 1
848    fi
849
850    typeset status
851        #
852    if [ X${JobType} = XRUN ] ; then
853      if [ X${3} = X ] ; then
854        IGCM_sys_Chmod 444 ${1}
855      fi
856    fi
857    #
858    #
859    # USUAL WAY
860    mfput $1 $2 > out_rsync 2>&1
861    status=$?
862
863#       #RSYNC WITH NETWORK RSH CALL
864#       echo ${RSYNC} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${RUN_DIR}/$1 ${RHOST}:${2} > out_rsync 2>&1
865#       ${RSYNC} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${RUN_DIR}/$1 ${RHOST}:${2} >> out_rsync 2>&1
866
867#       #RSYNC WITH NFS USE
868#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
869#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
870
871#       status=$?
872#       IGCM_sys_Rsync_out $status
873
874#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
875#       (( status=status+$? ))
876
877    if [ ${status} -gt 0 ] ; then
878      echo "IGCM_sys_Put_Out : error."
879      cat out_rsync
880      IGCM_debug_Print 1 "mfput failed. Make a second try :"
881            #
882      mfput $1 $2 > out_rsync 2>&1
883      status=$?
884            #
885      if [ ${status} -gt 0 ] ; then
886        echo "IGCM_sys_Put_Out : error."
887        IGCM_debug_Print 1 "mfput failed twice. You have a problem"
888        cat out_rsync
889        IGCM_debug_Exit "IGCM_sys_Put_Out"
890      fi
891    fi
892  else
893    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
894  fi
895  IGCM_debug_PopStack "IGCM_sys_Put_Out"
896  return 0
897}
898
899#D-#==================================================
900#D-function IGCM_sys_Get
901#D-* Purpose: Get a file from ${ARCHIVE}
902#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
903#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
904function IGCM_sys_Get {
905  IGCM_debug_PushStack "IGCM_sys_Get" $@
906
907  typeset DEST status dm_liste ifile target
908
909  if ( $DEBUG_sys ) ; then
910    echo "IGCM_sys_Get :" $@
911  fi
912  if [ $DRYRUN -le 2 ]; then
913    if [ X${1} = X'/l' ] ; then
914      # test if the first file is present in the old computation :
915      eval set +A dm_liste \${${2}}
916    else
917      dm_liste=${1}
918    fi
919    eval DEST=\${${#}}
920
921    # test if the (first) file is present in the old computation :
922    IGCM_sys_TestFileArchive ${dm_liste[0]}
923    status=$?
924    if [ ${status} -gt 0 ] ; then
925      echo "IGCM_sys_Get, ERROR : regular file ${dm_liste[0]} DOES NOT EXIST ."
926      IGCM_debug_Exit "IGCM_sys_Get"
927      #IGCM_debug_PopStack "IGCM_sys_Get"
928      #return
929    fi
930
931    # SD : dm_liste is not suited for computing job
932    #      because we change filename during transfert
933    #      dm_liste is better suited for post-treatment
934    # SD : dm_liste necessary only with RSYNC
935
936    #dm_liste=" "
937    #(( ifile=1 ))
938    #while [ $ifile -lt $# ] ; do
939    #    dm_liste=$( eval echo ${dm_liste[*]} " "\${${ifile}} )
940    #    (( ifile = ifile + 1 ))
941    #done
942    #DEST=$( eval echo \${${#}} )
943
944    #USUAL WAY
945    mfget ${dm_liste[*]} ${DEST} > out_rsync 2>&1
946
947#   #RSYNC WITH NETWORK RSH CALL
948#   echo ${RSYNC} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${RHOST}:"${dm_liste}" ${RHOST}:${RUN_DIR}/${DEST} > out_rsync 2>&1
949#   ${RSYNC} ${RSYNC_opt} --rsync-path=${REMOTE_RSYNC} -e rsh ${RHOST}:"${dm_liste}" ${RHOST}:${RUN_DIR}/${DEST} >> out_rsync 2>&1
950
951#   #RSYNC WITH NFS USE
952#   echo ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} > out_rsync 2>&1
953#   ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} >> out_rsync 2>&1
954
955#   status=$?
956#   IGCM_sys_Rsync_out $status
957
958#   ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
959#   (( status=status+$? ))
960
961  else
962    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
963  fi
964  IGCM_debug_PopStack "IGCM_sys_Get"
965}
966
967#D-#==================================================
968#D-function IGCM_sys_Put_Dods
969#D-* Purpose: Put $(ARCHIVE) files on DODS internet protocole.
970#D-* Examples:
971#D-
972function IGCM_sys_Put_Dods {
973  IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
974  if ( $DEBUG_sys ) ; then
975    echo "IGCM_sys_Put_Dods :" $@
976  fi
977  if [ $DRYRUN = 0 ]; then
978    # We take our time on that
979    sleep 10
980    IGCM_sys_TestDirArchive ${R_SAVE}/${1}
981    if [ $? != 0 ] ; then
982      echo "WARNING : IGCM_sys_Put_Dods ${R_SAVE}/${1} DOES NOT EXIST ."
983      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
984      return
985    fi
986
987    typeset status
988    #
989    rsh gaya exec /bin/ksh <<EOF
990          cd ${R_SAVE}
991          /usr/local/bin/dods_rm DODS/pub/${LOGIN}/${R_DODS}/${1} > /dev/null 2>&1
992          /bin/chmod -R u+w ${R_SAVE}/${1}
993          /usr/local/bin/dods_cp ${1} DODS/pub/${LOGIN}/${R_DODS} > /dev/null 2>&1
994          /bin/chmod -R +rX ${R_SAVE}/${1}
995          /bin/chmod -R u+w ${R_SAVE}/${1}
996EOF
997    status=$?
998
999    if [ ${status} -gt 0 ] ; then
1000      echo "IGCM_sys_Put_Dods : error."
1001      IGCM_debug_Exit "IGCM_sys_Put_Dods"
1002    fi
1003  else
1004    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1005  fi
1006  IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1007}
1008
1009############################################################## A FINIR !!
1010
1011#D-#==================================================
1012#D-function IGCM_sys_GetDate_FichWork
1013#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
1014#D-* Examples:
1015#D-
1016function IGCM_sys_GetDate_FichWork {
1017  IGCM_debug_PushStack "IGCM_sys_FichWork" $@
1018  if ( $DEBUG_sys ) ; then
1019    echo "IGCM_sys_GetDate_FichWork :" $@
1020  fi
1021    # donne la date filesys d'un fichier sur la machine work
1022  IGCM_debug_PopStack "IGCM_sys_FichWork"
1023}
1024
1025#D-#==================================================
1026#D-function IGCM_sys_GetDate_FichArchive
1027#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
1028#D-* Examples:
1029#D-
1030function IGCM_sys_GetDate_FichArchive {
1031  IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
1032  if ( $DEBUG_sys ) ; then
1033    echo "IGCM_sys_GetDate_FichArchive :" $@
1034  fi
1035  IGCM_debug_PopStack "IGCM_sys_FichArchive"
1036}
1037
1038##############################################################
1039# REBUILD OPERATOR
1040
1041function IGCM_sys_rebuild {
1042  IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1043  if ( $DEBUG_sys ) ; then
1044    echo "IGCM_sys_rebuild :" $@
1045  fi
1046  /home/rech/psl/rpsl035/bin/rebuild -f -o $@
1047  if [ $? -gt 0 ] ; then
1048    echo "IGCM_sys_rebuild : erreur ${@}."
1049    IGCM_debug_Exit "rebuild"
1050  fi
1051
1052  IGCM_debug_PopStack "IGCM_sys_rebuild"
1053}
1054
1055function IGCM_sys_rebuild_station {
1056  IGCM_debug_PushStack "IGCM_sys_rebuild_station" -- $@
1057  typeset i list_opt file_in file_out prefix_invert list_invert
1058  if ( $DEBUG_sys ) ; then
1059    echo "IGCM_sys_rebuild_station :" $@
1060  fi
1061  list_opt=$@
1062
1063  # Invert Axis : t,x -> x,t
1064  #               t,pres,x -> x,t,pres
1065  # So that we can concatenate along x
1066  i=0
1067  for file_in in ${list_opt} ; do
1068    (( i = i + 1))
1069    [ ${i} = 1 ] && file_out=${file_in} && continue
1070    prefix_invert=$( basename ${file_in} .nc )
1071    IGCM_sys_ncpdq -a x,time_counter -a x,time_counter,presnivs ${file_in} ${prefix_invert}_xt.nc
1072    list_invert[${#list_invert[*]}]=${prefix_invert}_xt.nc
1073  done
1074
1075  # Concatenate
1076  IGCM_sys_ncrcat ${list_invert[*]} histstn_xt.nc
1077
1078  # Re-ivert file
1079  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x histstn_xt.nc ${file_out}
1080
1081  # Station re-ordering is too expansive to be run within libICGM
1082  # This is due to (ncpdq - nrcat - ncpdq) I/O sequence.
1083  # This re-ordering must be done "in memory" by the cmorization process
1084  # Anyway this is the best sequence using (ncpdq - nrcat - ncpdq)
1085  # BEGIN reordering
1086
1087  # Only LMDZ text output contains the exact ordering of the station.
1088  # We isolate this in the code below:
1089  #  0  38  -157.5000000000000  70.98591549295774
1090  #  0  54  27.49999999999999   67.18309859154928
1091  #  0  56  -62.50000000000001  82.39436619718309
1092  #  0  79  12.49999999999999   78.59154929577466
1093  #  0  116 -165.0000000000000  76.05633802816901
1094  #  0  117 130.0000000000000   70.98591549295774
1095  #  0  118 110.0000000000000   87.46478873239437
1096  #  1  40  4.999999999999995   51.97183098591550
1097#  typeset iStation iProc list_opt file_in file_out prefix_invert
1098#  typeset -Z4 j4
1099#  typeset -Z3 j3
1100
1101#  unset list_opt
1102#  set +A list_opt $@
1103
1104  # Filename after rebuild
1105#  file_out=${list_opt[0]}
1106  # Prefix of output files
1107#  prefix_invert=$( basename ${file_out} .nc )
1108  # Number of procs
1109#  num_proc=$( grep -i mpi_size ${PREFIX}_${Exe_Output} | wc -l )
1110
1111#  iProc=0
1112#  while [ ${iProc} -lt ${num_proc} ] ; do
1113    # Array containing Station as a number
1114#    unset proc_stn
1115#    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}' )
1116    # Number of stations produced by processor proc
1117#    stationLast=${#proc_stn[*]}
1118    # Proc number on 4 digits
1119#    j4=${iProc}
1120    # Init
1121#    iStation=0
1122#    while [ ${iStation} -lt ${stationLast} ] ; do
1123      # Station number on 3 digits
1124#      j3=${proc_stn[${iStation}]}
1125      # Extract station
1126      # Invert Axis : t,x -> x,t
1127      #               t,pres,x -> x,t,pres
1128      # So that we can concatenate along x
1129#      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
1130#      (( iStation = iStation + 1 ))
1131#    done
1132#    (( iProc = iProc + 1 ))
1133#  done
1134
1135  # Concatenate all station along x
1136#  IGCM_sys_ncrcat ${prefix_invert}_stn_???.nc ${prefix_invert}_xt.nc
1137
1138  # Re-invert file
1139#  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x ${prefix_invert}_xt.nc ${file_out}
1140
1141  # END reordering
1142
1143  IGCM_debug_PopStack "IGCM_sys_rebuild_station"
1144}
1145
1146##############################################################
1147# NCO OPERATOR
1148
1149function IGCM_sys_ncap2 {
1150  IGCM_debug_PushStack "IGCM_sys_ncap2" -- $@
1151  if ( $DEBUG_sys ) ; then
1152    echo "IGCM_sys_ncap2 :" $@
1153  fi
1154
1155  typeset NB_ESSAI DELAI status i
1156  # number of tentative
1157  NB_ESSAI=3
1158  # time delay between tentative
1159  DELAI=2
1160
1161  i=0
1162  while [ $i -lt $NB_ESSAI ] ; do
1163    ncap2 "$@" > out_rsync 2>&1
1164    status=$?
1165    if [ ${status} -gt 0 ] ; then
1166      IGCM_debug_Print 2 "IGCM_sys_ncap2 : error code ${status}"
1167      cat out_rsync
1168      \rm out_rsync
1169      IGCM_debug_Print 2 "IGCM_sys_ncap2 : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1170    else
1171      \rm out_rsync
1172      break
1173    fi
1174    (( i = i + 1 ))
1175  done
1176
1177  if [ ${status} -gt 0 ] ; then
1178      echo "IGCM_sys_ncap2 : ncap2 error"
1179      IGCM_debug_Exit "ncap2"
1180  fi
1181
1182  IGCM_debug_PopStack "IGCM_sys_ncap2"
1183}
1184
1185function IGCM_sys_ncatted {
1186  IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
1187  if ( $DEBUG_sys ) ; then
1188    echo "IGCM_sys_ncatted :" $@
1189  fi
1190
1191  typeset NB_ESSAI DELAI status i
1192  # number of tentative
1193  NB_ESSAI=3
1194  # time delay between tentative
1195  DELAI=2
1196
1197  i=0
1198  while [ $i -lt $NB_ESSAI ] ; do
1199    ncatted "$@" > out_rsync 2>&1
1200    status=$?
1201    if [ ${status} -gt 0 ] ; then
1202      IGCM_debug_Print 2 "IGCM_sys_ncatted : error code ${status}"
1203      cat out_rsync
1204      \rm out_rsync
1205      IGCM_debug_Print 2 "IGCM_sys_ncatted : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1206    else
1207      \rm out_rsync
1208      break
1209    fi
1210    (( i = i + 1 ))
1211  done
1212
1213  if [ ${status} -gt 0 ] ; then
1214      echo "IGCM_sys_ncatted : ncatted error"
1215      IGCM_debug_Exit "ncatted"
1216  fi
1217
1218  IGCM_debug_PopStack "IGCM_sys_ncatted"
1219}
1220
1221function IGCM_sys_ncbo {
1222  IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
1223  if ( $DEBUG_sys ) ; then
1224    echo "IGCM_sys_ncbo :" $@
1225  fi
1226
1227  typeset NB_ESSAI DELAI status i
1228  # number of tentative
1229  NB_ESSAI=3
1230  # time delay between tentative
1231  DELAI=2
1232
1233  i=0
1234  while [ $i -lt $NB_ESSAI ] ; do
1235    ncbo $@ > out_rsync 2>&1
1236    status=$?
1237    if [ ${status} -gt 0 ] ; then
1238      IGCM_debug_Print 2 "IGCM_sys_ncbo : error code ${status}"
1239      cat out_rsync
1240      \rm out_rsync
1241      IGCM_debug_Print 2 "IGCM_sys_ncbo : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1242    else
1243      \rm out_rsync
1244      break
1245    fi
1246    (( i = i + 1 ))
1247  done
1248
1249  if [ ${status} -gt 0 ] ; then
1250      echo "IGCM_sys_ncbo : ncbo error"
1251      IGCM_debug_Exit "ncbo"
1252  fi
1253
1254  IGCM_debug_PopStack "IGCM_sys_ncbo"
1255}
1256
1257function IGCM_sys_ncdiff {
1258  IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
1259  if ( $DEBUG_sys ) ; then
1260    echo "IGCM_sys_ncdiff :" $@
1261  fi
1262
1263  typeset NB_ESSAI DELAI status i
1264  # number of tentative
1265  NB_ESSAI=3
1266  # time delay between tentative
1267  DELAI=2
1268
1269  i=0
1270  while [ $i -lt $NB_ESSAI ] ; do
1271    ncdiff $@ > out_rsync 2>&1
1272    status=$?
1273    if [ ${status} -gt 0 ] ; then
1274      IGCM_debug_Print 2 "IGCM_sys_ncdiff : error code ${status}"
1275      cat out_rsync
1276      \rm out_rsync
1277      IGCM_debug_Print 2 "IGCM_sys_ncdiff : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1278    else
1279      \rm out_rsync
1280      break
1281    fi
1282    (( i = i + 1 ))
1283  done
1284
1285  if [ ${status} -gt 0 ] ; then
1286      echo "IGCM_sys_ncdiff : ncdiff error"
1287      IGCM_debug_Exit "ncdiff"
1288  fi
1289
1290  IGCM_debug_PopStack "IGCM_sys_ncdiff"
1291}
1292
1293function IGCM_sys_ncea {
1294  IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
1295  if ( $DEBUG_sys ) ; then
1296    echo "IGCM_sys_ncea :" $@
1297  fi
1298
1299  typeset NB_ESSAI DELAI status i
1300  # number of tentative
1301  NB_ESSAI=3
1302  # time delay between tentative
1303  DELAI=2
1304
1305  i=0
1306  while [ $i -lt $NB_ESSAI ] ; do
1307    ncea $@ > out_rsync 2>&1
1308    status=$?
1309    if [ ${status} -gt 0 ] ; then
1310      IGCM_debug_Print 2 "IGCM_sys_ncea : error code ${status}"
1311      cat out_rsync
1312      \rm out_rsync
1313      IGCM_debug_Print 2 "IGCM_sys_ncea : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1314    else
1315      \rm out_rsync
1316      break
1317    fi
1318    (( i = i + 1 ))
1319  done
1320
1321  if [ ${status} -gt 0 ] ; then
1322      echo "IGCM_sys_ncea : ncea error"
1323      IGCM_debug_Exit "ncea"
1324  fi
1325
1326  IGCM_debug_PopStack "IGCM_sys_ncea"
1327}
1328
1329function IGCM_sys_ncecat {
1330  IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
1331  if ( $DEBUG_sys ) ; then
1332    echo "IGCM_sys_ncecat :" $@
1333  fi
1334
1335  typeset NB_ESSAI DELAI status i
1336  # number of tentative
1337  NB_ESSAI=3
1338  # time delay between tentative
1339  DELAI=2
1340
1341  i=0
1342  while [ $i -lt $NB_ESSAI ] ; do
1343    ncecat $@ > out_rsync 2>&1
1344    status=$?
1345    if [ ${status} -gt 0 ] ; then
1346      IGCM_debug_Print 2 "IGCM_sys_ncecat : error code ${status}"
1347      cat out_rsync
1348      \rm out_rsync
1349      IGCM_debug_Print 2 "IGCM_sys_ncecat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1350    else
1351      \rm out_rsync
1352      break
1353    fi
1354    (( i = i + 1 ))
1355  done
1356
1357  if [ ${status} -gt 0 ] ; then
1358      echo "IGCM_sys_ncecat : ncecat error"
1359      IGCM_debug_Exit "ncecat"
1360  fi
1361
1362  IGCM_debug_PopStack "IGCM_sys_ncecat"
1363}
1364
1365function IGCM_sys_ncflint {
1366  IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
1367  if ( $DEBUG_sys ) ; then
1368    echo "IGCM_sys_ncflint :" $@
1369  fi
1370
1371  typeset NB_ESSAI DELAI status i
1372  # number of tentative
1373  NB_ESSAI=3
1374  # time delay between tentative
1375  DELAI=2
1376
1377  i=0
1378  while [ $i -lt $NB_ESSAI ] ; do
1379    ncflint $@ > out_rsync 2>&1
1380    status=$?
1381    if [ ${status} -gt 0 ] ; then
1382      IGCM_debug_Print 2 "IGCM_sys_ncflint : error code ${status}"
1383      cat out_rsync
1384      \rm out_rsync
1385      IGCM_debug_Print 2 "IGCM_sys_ncflint : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1386    else
1387      \rm out_rsync
1388      break
1389    fi
1390    (( i = i + 1 ))
1391  done
1392
1393  if [ ${status} -gt 0 ] ; then
1394      echo "IGCM_sys_ncflint : ncflint error"
1395      IGCM_debug_Exit "ncflint"
1396  fi
1397
1398  IGCM_debug_PopStack "IGCM_sys_ncflint"
1399}
1400
1401function IGCM_sys_ncks {
1402  IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
1403  if ( $DEBUG_sys ) ; then
1404    echo "IGCM_sys_ncks :" $@
1405  fi
1406
1407  typeset NB_ESSAI DELAI status i
1408  # number of tentative
1409  NB_ESSAI=3
1410  # time delay between tentative
1411  DELAI=2
1412
1413  i=0
1414  while [ $i -lt $NB_ESSAI ] ; do
1415    ncks $@ > out_rsync 2>&1
1416    status=$?
1417    if [ ${status} -gt 0 ] ; then
1418      IGCM_debug_Print 2 "IGCM_sys_ncks : error code ${status}"
1419      cat out_rsync
1420      \rm out_rsync
1421      IGCM_debug_Print 2 "IGCM_sys_ncks : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1422    else
1423      \rm out_rsync
1424      break
1425    fi
1426    (( i = i + 1 ))
1427  done
1428
1429  if [ ${status} -gt 0 ] ; then
1430      echo "IGCM_sys_ncks : ncks error"
1431      IGCM_debug_Exit "ncks"
1432  fi
1433
1434  IGCM_debug_PopStack "IGCM_sys_ncks"
1435}
1436
1437function IGCM_sys_ncpdq {
1438  IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
1439  if ( $DEBUG_sys ) ; then
1440    echo "IGCM_sys_ncpdq :" $@
1441  fi
1442
1443  typeset NB_ESSAI DELAI status i
1444  # number of tentative
1445  NB_ESSAI=3
1446  # time delay between tentative
1447  DELAI=2
1448
1449  i=0
1450  while [ $i -lt $NB_ESSAI ] ; do
1451    ncpdq $@ > out_rsync 2>&1
1452    status=$?
1453    if [ ${status} -gt 0 ] ; then
1454      IGCM_debug_Print 2 "IGCM_sys_ncpdq : error code ${status}"
1455      cat out_rsync
1456      \rm out_rsync
1457      IGCM_debug_Print 2 "IGCM_sys_ncpdq : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1458    else
1459      \rm out_rsync
1460      break
1461    fi
1462    (( i = i + 1 ))
1463  done
1464
1465  if [ ${status} -gt 0 ] ; then
1466      echo "IGCM_sys_ncpdq : ncpdq error"
1467      IGCM_debug_Exit "ncpdq"
1468  fi
1469
1470  IGCM_debug_PopStack "IGCM_sys_ncpdq"
1471}
1472
1473function IGCM_sys_ncra {
1474  IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
1475  if ( $DEBUG_sys ) ; then
1476    echo "IGCM_sys_ncra :" $@
1477  fi
1478
1479  typeset NB_ESSAI DELAI status i
1480  # number of tentative
1481  NB_ESSAI=3
1482  # time delay between tentative
1483  DELAI=2
1484
1485  i=0
1486  while [ $i -lt $NB_ESSAI ] ; do
1487    ncra $@ > out_rsync 2>&1
1488    status=$?
1489    if [ ${status} -gt 0 ] ; then
1490      IGCM_debug_Print 2 "IGCM_sys_ncra : error code ${status}"
1491      cat out_rsync
1492      \rm out_rsync
1493      IGCM_debug_Print 2 "IGCM_sys_ncra : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1494    else
1495      \rm out_rsync
1496      break
1497    fi
1498    (( i = i + 1 ))
1499  done
1500
1501  if [ ${status} -gt 0 ] ; then
1502      echo "IGCM_sys_ncra : ncra error"
1503      IGCM_debug_Exit "ncra"
1504  fi
1505
1506  IGCM_debug_PopStack "IGCM_sys_ncra"
1507}
1508
1509function IGCM_sys_ncrcat {
1510  IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
1511  if ( $DEBUG_sys ) ; then
1512    echo "IGCM_sys_ncrcat :" $@
1513  fi
1514
1515  typeset NB_ESSAI DELAI status i
1516  # number of tentative
1517  NB_ESSAI=3
1518  # time delay between tentative
1519  DELAI=2
1520
1521  i=0
1522  while [ $i -lt $NB_ESSAI ] ; do
1523    ncrcat $@ > out_rsync 2>&1
1524    status=$?
1525    if [ ${status} -gt 0 ] ; then
1526      IGCM_debug_Print 2 "IGCM_sys_ncrcat : error code ${status}"
1527      cat out_rsync
1528      \rm out_rsync
1529      IGCM_debug_Print 2 "IGCM_sys_ncrcat : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1530    else
1531      \rm out_rsync
1532      break
1533    fi
1534    (( i = i + 1 ))
1535  done
1536
1537  if [ ${status} -gt 0 ] ; then
1538      echo "IGCM_sys_ncrcat : ncrcat error"
1539      #IGCM_debug_Exit "ncrcat"
1540  fi
1541
1542  IGCM_debug_PopStack "IGCM_sys_ncrcat"
1543}
1544
1545function IGCM_sys_ncrename {
1546  IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
1547  if ( $DEBUG_sys ) ; then
1548    echo "IGCM_sys_ncrename :" $@
1549  fi
1550
1551  typeset NB_ESSAI DELAI status i
1552  # number of tentative
1553  NB_ESSAI=3
1554  # time delay between tentative
1555  DELAI=2
1556
1557  i=0
1558  while [ $i -lt $NB_ESSAI ] ; do
1559    ncrename $@ > out_rsync 2>&1
1560    status=$?
1561    if [ ${status} -gt 0 ] ; then
1562      IGCM_debug_Print 2 "IGCM_sys_ncrename : error code ${status}"
1563      cat out_rsync
1564      \rm out_rsync
1565      IGCM_debug_Print 2 "IGCM_sys_ncrename : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1566    else
1567      \rm out_rsync
1568      break
1569    fi
1570    (( i = i + 1 ))
1571  done
1572
1573  if [ ${status} -gt 0 ] ; then
1574      echo "IGCM_sys_ncrename : ncrename error"
1575      IGCM_debug_Exit "ncrename"
1576  fi
1577
1578  IGCM_debug_PopStack "IGCM_sys_ncrename"
1579}
1580
1581function IGCM_sys_ncwa {
1582  IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
1583  if ( $DEBUG_sys ) ; then
1584    echo "IGCM_sys_ncwa :" $@
1585  fi
1586
1587  typeset NB_ESSAI DELAI status i
1588  # number of tentative
1589  NB_ESSAI=3
1590  # time delay between tentative
1591  DELAI=2
1592
1593  i=0
1594  while [ $i -lt $NB_ESSAI ] ; do
1595    ncwa $@ > out_rsync 2>&1
1596    status=$?
1597    if [ ${status} -gt 0 ] ; then
1598      IGCM_debug_Print 2 "IGCM_sys_ncwa : error code ${status}"
1599      cat out_rsync
1600      \rm out_rsync
1601      IGCM_debug_Print 2 "IGCM_sys_ncwa : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1602    else
1603      \rm out_rsync
1604      break
1605    fi
1606    (( i = i + 1 ))
1607  done
1608
1609  if [ ${status} -gt 0 ] ; then
1610      echo "IGCM_sys_ncwa : ncwa error"
1611      IGCM_debug_Exit "ncwa"
1612  fi
1613
1614  IGCM_debug_PopStack "IGCM_sys_ncwa"
1615}
1616
1617##############################################################
1618# CDO OPERATOR
1619
1620function IGCM_sys_cdo {
1621  IGCM_debug_PushStack "IGCM_sys_cdo" -- $@
1622  if ( $DEBUG_sys ) ; then
1623    echo "IGCM_sys_cdo :" $@
1624  fi
1625
1626  typeset status
1627
1628  \cdo $@ > out_rsync 2>&1
1629  status=$?
1630  if [ ${status} -gt 0 ] ; then
1631    echo "IGCM_sys_cdo : error code ${status}"
1632    cat out_rsync
1633    \rm out_rsync
1634    IGCM_debug_PopStack "IGCM_sys_cdo"
1635    return 1
1636  else
1637    IGCM_debug_PopStack "IGCM_sys_cdo"
1638    return 0
1639  fi
1640
1641  IGCM_debug_PopStack "IGCM_sys_cdo"
1642}
1643
1644############################################################
1645# Activate Running Environnment Variables
1646
1647function IGCM_sys_activ_variables {
1648  IGCM_debug_PushStack "IGCM_sys_activ_variables"
1649  if ( $DEBUG_sys ) ; then
1650    echo "IGCM_sys_activ_variables"
1651  fi
1652  IGCM_debug_PopStack "IGCM_sys_activ_variables"
1653}
1654
1655############################################################
1656# Desactivate Running Environnment Variables
1657
1658function IGCM_sys_desactiv_variables {
1659  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1660  if ( $DEBUG_sys ) ; then
1661    echo "IGCM_sys_desactiv_variables"
1662  fi
1663  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1664}
1665
1666############################################################
1667# Build run file
1668
1669function IGCM_sys_build_run_file {
1670  IGCM_debug_PushStack "IGCM_sys_build_run_file"
1671  if ( $DEBUG_sys ) ; then
1672    echo "IGCM_sys_build_run_file"
1673  fi
1674  IGCM_debug_PopStack "IGCM_sys_build_run_file"
1675}
1676
1677############################################################
1678# Check of space available on temporary filesytems
1679function IGCM_sys_check_quota {
1680    IGCM_debug_PushStack "IGCM_sys_check_quota"
1681    if ( $DEBUG_sys ) ; then
1682        echo "IGCM_sys_check_quota"
1683    fi
1684    IGCM_debug_PopStack "IGCM_sys_check_quota"
1685}
Note: See TracBrowser for help on using the repository browser.