source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_iitm.ksh @ 818

Last change on this file since 818 was 818, checked in by sdipsl, 11 years ago
  • Side effect of the SpaceName?=TEST behaviour implementation at IDRIS related to IGCM_sys_IsFileArchived function.

Affect only Ada and is in fact the root cause of #110

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