source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_ada.ksh @ 993

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