source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_mercurex9.ksh @ 734

Last change on this file since 734 was 734, checked in by sdipsl, 12 years ago
  • bugfix : looping over rebuild command we must delete the first arguments not the last one.
  • bugfix : catching the last arg we must use this eval lastArg=\${$#} otherwise we won't catch the latest arguments if there are more than 9.
  • add date to debug print
  • Property svn:keywords set to Revision Author Date
File size: 57.3 KB
Line 
1#!/bin/ksh
2
3#**************************************************************
4# Author: Sebastien Denvil, Martial Mancip
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 Mercure SX9
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# gawk specific location on SX9
35export PATH=/applications/gawk-3.0.4/bin:${PATH}
36
37#====================================================
38# set DEBUG_sys to true to output calls of function
39typeset -r DEBUG_sys=${DEBUG_sys:=true}
40
41#====================================================
42# Turn in dry run mode ? (sys_Put_Rest, sys_Put_Out, sys_Get)
43typeset -r DRYRUN=${DRYRUN:=0}
44
45# YOU MUST COMPILE YOUR EXE FILES FOR DRYRUN MODE !
46# -------------------------------------------------------------------------------------
47# | DRYRUN=  |  Date computations, | sys_Get    |  Exe    | sys_Put_Out; sys_Put_Rest |
48# |          |  Cp/Exe param files |            |  Chmod  |                           |
49# |          |      Qsub           |            |         |                           |
50# -------------------------------------------------------------------------------------
51# |    0     |       yes           |    yes     |  yes    |      yes                  |
52# -------------------------------------------------------------------------------------
53# |    1     |       yes           |    yes     |  yes    |      no                   |
54# -------------------------------------------------------------------------------------
55# |    2     |       yes           |    yes     |  no     |      no                   |
56# -------------------------------------------------------------------------------------
57# |    3     |       yes           |    no      |  no     |      no                   |
58# -------------------------------------------------------------------------------------
59
60#=====================================================
61# Global Variables :
62#=====================================================
63# Language : "fr" or "en"
64typeset -r MYLANG="fr"
65
66#=====================================================
67# Host and user names
68# $hostname ou hostname
69typeset  HOST=${HOST:=$( hostname )}
70# $username ou whoami
71typeset  LOGIN=${LOGIN:=$( whoami )}
72# $hostname of the MASTER job
73typeset -r MASTER=mercure
74
75#D-
76#D-#==================================================
77#D-Program used in libIGCM
78#D-#==================================================
79
80# rsync with path
81typeset -r RSYNC=/home/cont003/p86denv/SX_RSYNC/bin/rsync
82# RSYNC_opt args to rsync
83typeset -r RSYNC_opt="-va"
84# ie storage filesystem
85typeset -r STOREHOST=${MASTER}
86
87#====================================================
88# Host specific DIRECTORIES
89#====================================================
90
91# ============ CESIUM START ============ #
92
93#====================================================
94#- Mirror libIGCM from mercure to cesium if needed
95#ROOTSYS=$( echo ${libIGCM} | gawk -F"/" '{print $3}' )
96#if [ ! ${ROOTSYS} = "home" ] ; then
97#  typeset -r MirrorlibIGCM=${MirrorlibIGCM:=true}
98#else
99#  typeset -r MirrorlibIGCM=${MirrorlibIGCM:=false}
100#fi
101
102#====================================================
103#- libIGCM_POST
104#if ( ${MirrorlibIGCM} ) ; then
105#  PATHlibIGCM=$( echo ${libIGCM} | gawk -F"${LOGIN}/" '{print $2}' | sed -e "s&/libIGCM&&" )
106#  typeset -r libIGCM_POST=${HOME}/MIRROR/${PATHlibIGCM}/libIGCM
107#else
108#  typeset -r libIGCM_POST=${libIGCM}
109#fi
110
111# ============ CESIUM  END  ============ #
112
113#====================================================
114#- MirrorlibIGCM for frontend
115typeset -r MirrorlibIGCM=${MirrorlibIGCM:=false}
116
117#====================================================
118#- libIGCM_POST for frontend
119typeset -r libIGCM_POST=${libIGCM}
120
121#====================================================
122#- R_EXE   (==> BIN_DIR = ${MODIPSL}/bin )
123typeset -r R_EXE="${MODIPSL}/bin"
124
125#====================================================
126#- SUBMIT_DIR : submission dir
127typeset SUBMIT_DIR=${SUBMIT_DIR:=${PBS_O_WORKDIR}}
128
129#====================================================
130#- IN
131typeset -r R_IN=${R_IN:=/ccc/work/cont003/dsm/p86ipsl/IGCM}
132typeset -r R_IN_ECMWF=${R_IN_ECMWF:=/ccc/work/cont003/dsm/p24data}
133
134#====================================================
135#- ARCHIVE (dedicated to large files)
136typeset ARCHIVE=${CCCSTOREDIR}
137
138#====================================================
139#- STORAGE (dedicated to small/medium files)
140typeset STORAGE=${CCCWORKDIR}
141
142#====================================================
143#- R_OUT
144typeset R_OUT=${ARCHIVE}/IGCM_OUT
145
146#====================================================
147#- R_FIG (hosting figures : monitoring and atlas, and/or small files)
148typeset R_FIG=${STORAGE}/IGCM_OUT
149
150#====================================================
151#- R_BUF (ONLY FOR double copy an scratch)
152typeset -r R_BUF=${SCRATCHDIR}/IGCM_OUT
153
154#====================================================
155#- BIG_DIR : BIG_DIR to store files waiting for rebuild
156typeset -r BIG_DIR=${BIG_DIR:=${SCRATCHDIR}/REBUILD}
157
158#====================================================
159#- OUT_POST
160typeset -r R_OUT_POST=${SCRATCHDIR}/IGCM_OUT
161
162#====================================================
163#- RUN_DIR_PATH : Temporary working directory (=> TMP)
164typeset -r RUN_DIR_PATH=${RUN_DIR_PATH:=${LOCALTMPDIR}}
165
166#====================================================
167#- HOST_MPIRUN_COMMAND
168typeset -r HOST_MPIRUN_COMMAND=${HOST_MPIRUN_COMMAND:="mpirun"}
169
170#====================================================
171#- Max number of arguments passed to nco operator or demigration command
172UNIX_MAX_LIMIT=360
173
174#====================================================
175#- set PackDefault true on NEC SX9
176PackDefault=true
177
178#====================================================
179#- Default number of MPI task for IPSL coupled model
180#- required for backward compatibility
181#-
182DEFAULT_NUM_PROC_OCE=1
183DEFAULT_NUM_PROC_CPL=1
184(( DEFAULT_NUM_PROC_ATM = BATCH_NUM_PROC_TOT - 1 ))
185DEFAULT_NUM_PROC_TOTAL=${BATCH_NUM_PROC_TOT}
186
187#D-#==================================================
188#D-function IGCM_sys_ChangeArchive
189#D-* Purpose: if SpaceName=TEST everything is stored on SCRATCHDIR
190#D-* Examples:
191#D-
192function IGCM_sys_ChangeArchive {
193  IGCM_debug_PushStack "IGCM_sys_ChangeArchive"
194
195  ARCHIVE=${SCRATCHDIR}
196  STORAGE=${SCRATCHDIR}
197  R_OUT=${ARCHIVE}/IGCM_OUT
198  R_FIG=${STORAGE}/IGCM_OUT
199
200  IGCM_debug_Print 1 "ARCHIVE has been redefined = ${ARCHIVE}"
201  IGCM_debug_Print 1 "STORAGE has been redefined = ${STORAGE}"
202  IGCM_debug_Print 1 "R_OUT   has been redefined = ${R_OUT}"
203  IGCM_debug_Print 1 "R_FIG   has been redefined = ${R_FIG}"
204
205  IGCM_debug_PopStack "IGCM_sys_ChangeArchive"
206}
207
208#D-#==================================================
209#D-function IGCM_sys_RshMaster
210#D-* Purpose: Connection to frontend machine.
211#D-* Examples:
212#D-
213function IGCM_sys_RshMaster {
214  IGCM_debug_PushStack "IGCM_sys_RshMaster" $@
215  ssh -t ${MASTER} /bin/ksh <<-EOF
216  export libIGCM=${libIGCM}
217  export DEBUG_debug=${DEBUG_debug}
218  . ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh
219  . ${libIGCM}/libIGCM_card/libIGCM_card.ksh
220  ${@}
221EOF
222  if [ $? -gt 0 ] ; then
223    echo "IGCM_sys_RshMaster : erreur."
224    IGCM_debug_Exit "IGCM_sys_RshMaster"
225  fi
226  IGCM_debug_PopStack "IGCM_sys_RshMaster"
227}
228
229#D-#==================================================
230#D-function IGCM_sys_RshArchive
231#D-* Purpose: Archive rsh command
232#D-* Examples:
233#D-
234function IGCM_sys_RshArchive {
235  IGCM_debug_PushStack "IGCM_sys_RshArchive" $@
236  /bin/ksh <<-EOF
237    ${@}
238EOF
239  if [ $? -gt 0 ] ; then
240    echo "IGCM_sys_RshArchive : erreur."
241    IGCM_debug_Exit "IGCM_sys_RshArchive"
242  fi
243  IGCM_debug_PopStack "IGCM_sys_RshArchive"
244}
245
246#D-#==================================================
247#D-function IGCM_sys_RshPost
248#D-* Purpose: Post-process rsh command
249#D-* Examples:
250#D-
251function IGCM_sys_RshPost {
252  IGCM_debug_PushStack "IGCM_sys_RshPost" $@
253  if ( $DEBUG_sys ) ; then
254    echo "IGCM_sys_RshPost :" $@
255  fi
256
257  #echo cat tmp_IGCM_sys_RshPost_$$ INITIAL
258  #cat tmp_IGCM_sys_RshPost_$$
259  # keep standard input (stdin) for the loop onto temporary file
260  cat >tmp_IGCM_sys_RshPost_$$
261
262# ============ FRONTEND START ============ #
263
264  /bin/ksh <tmp_IGCM_sys_RshPost_$$
265  if [ $? -gt 0 ] ; then
266    echo "IGCM_sys_RshPost : erreur."
267    IGCM_debug_Exit "IGCM_sys_RshPost"
268  fi
269  # delete temporary file
270  \rm tmp_IGCM_sys_RshPost_$$
271
272# ============ FRONTEND  END  ============ #
273
274# ============ CESIUM START ============ #
275#  typeset NB_ESSAI DELAI status i
276#  # number of tentative
277#  NB_ESSAI=10
278#  # time delay between tentative
279#  DELAI=10
280#  (( i = 0 ))
281#  while [ $i -lt $NB_ESSAI ] ; do
282#    ssh -t mercure01 ssh cesium /bin/ksh <tmp_IGCM_sys_RshPost_$$
283#    status=$?
284#    if [ ${status} -gt 0 ]; then
285#      IGCM_debug_Print 2 "IGCM_sys_RshPost : ssh failed ${i}/${NB_ESSAI}"
286#      IGCM_debug_Print 2 "IGCM_sys_RshPost : sleep ${DELAI} seconds and try again."
287#      sleep $DELAI
288#    else
289#      break
290#    fi
291#    (( i = i + 1 ))
292#  done
293#  # delete temporary file
294#  /bin/rm tmp_IGCM_sys_RshPost_$$
295# ============ CESIUM  END  ============ #
296
297  IGCM_debug_PopStack "IGCM_sys_RshPost"
298}
299
300#D-#==================================================
301#D-function IGCM_sys_SendMail
302#D-* Purpose: Send mail when simulation is over
303#D-* Examples:
304#D-
305function IGCM_sys_SendMail {
306  IGCM_debug_PushStack "IGCM_sys_SendMail" $@
307  if ( $DEBUG_sys ) ; then
308    echo "IGCM_sys_SendMail :" $@
309  fi
310
311  if ( ${ExitFlag} ) ; then
312    status=failed
313  else
314    status=completed
315  fi
316
317  cat  << END_MAIL > job_end.mail
318Dear ${LOGIN},
319
320  Simulation ${config_UserChoices_JobName} is ${status} on supercomputer `hostname`.
321  Job started : ${DateBegin}
322  Job ended   : ${DateEnd}
323  Output files are available in ${R_SAVE}
324  Files to be rebuild are temporarily available in ${REBUILD_DIR}
325  Pre-packed files are temporarily available in ${R_BUFR}
326  Script files, Script Outputs and Debug files (if necessary) are available in ${SUBMIT_DIR}
327END_MAIL
328
329  if  [ X"${config_UserChoices_MailName}" != X ] ; then
330    mailx -s "${config_UserChoices_JobName} ${status}" ${config_UserChoices_MailName} <  job_end.mail
331  elif [ -f ~/.forward ] ; then
332    mailx -s "${config_UserChoices_JobName} ${status}" $( cat ~/.forward ) < job_end.mail
333  else
334    mailx -s "${config_UserChoices_JobName} ${status}" ${LOGIN} < job_end.mail
335  fi
336
337  if [ $? -gt 0 ] ; then
338    echo "IGCM_sys_SendMail : erreur."
339    IGCM_debug_Exit "IGCM_sys_SendMail"
340  fi
341  IGCM_debug_PopStack "IGCM_sys_SendMail"
342}
343
344#D-#==================================================
345#D-function IGCM_sys_Mkdir
346#D-* Purpose: Master locale mkdir command
347#D-* Examples:
348#D-
349function IGCM_sys_Mkdir {
350  IGCM_debug_PushStack "IGCM_sys_Mkdir" $@
351  if ( $DEBUG_sys ) ; then
352    echo "IGCM_sys_Mkdir :" $@
353  fi
354  if [ ! -d ${1} ]; then
355    \mkdir -p $1
356    if [ $? -gt 0 ] ; then
357      echo "IGCM_sys_Mkdir : erreur."
358      IGCM_debug_Exit "IGCM_sys_Mkdir"
359    fi
360  fi
361  # vérification :
362  if [ ! -d ${1} ] ; then
363    echo "IGCM_sys_Mkdir : erreur."
364    IGCM_debug_Exit "IGCM_sys_Mkdir"
365  fi
366  IGCM_debug_PopStack "IGCM_sys_Mkdir"
367}
368
369#D-#==================================================
370#D-function IGCM_sys_MkdirArchive
371#D-* Purpose: Mkdir on Archive
372#D-* Examples:
373#D-
374function IGCM_sys_MkdirArchive {
375  IGCM_debug_PushStack "IGCM_sys_MkdirArchive" $@
376  if ( $DEBUG_sys ) ; then
377    echo "IGCM_sys_MkdirArchive :" $@
378  fi
379  #- creation de repertoire sur le serveur fichier
380  if [ ! -d ${1} ]; then
381    \mkdir -p $1
382    if [ $? -gt 0 ] ; then
383      echo "IGCM_sys_MkdirArchive : erreur."
384      IGCM_debug_Exit "IGCM_sys_MkdirArchive"
385    fi
386  fi
387  IGCM_debug_PopStack "IGCM_sys_MkdirArchive"
388}
389
390#D-#==================================================
391#D-function IGCM_sys_MkdirWork
392#D-* Purpose: Mkdir on Work
393#D-* Examples:
394#D-
395function IGCM_sys_MkdirWork {
396  IGCM_debug_PushStack "IGCM_sys_MkdirWork" $@
397  if ( $DEBUG_sys ) ; then
398    echo "IGCM_sys_MkdirWork :" $@
399  fi
400  #- creation de repertoire sur le serveur fichier
401  if [ ! -d ${1} ]; then
402    \mkdir -p $1
403    if [ $? -gt 0 ] ; then
404      echo "IGCM_sys_MkdirWork : erreur."
405      IGCM_debug_Exit "IGCM_sys_MkdirWork"
406    fi
407  fi
408  IGCM_debug_PopStack "IGCM_sys_MkdirWork"
409}
410
411#D-#==================================================
412#D-function IGCM_sys_Cd
413#D-* Purpose: master cd command
414#D-* Examples:
415#D-
416function IGCM_sys_Cd {
417  IGCM_debug_PushStack "IGCM_sys_Cd" $@
418  if ( $DEBUG_sys ) ; then
419    echo "IGCM_sys_Cd :" $@
420  fi
421  \cd $1
422  if [ $? -gt 0 ] ; then
423    echo "IGCM_sys_Cd : erreur."
424    IGCM_debug_Exit "IGCM_sys_Cd"
425  fi
426  IGCM_debug_PopStack "IGCM_sys_Cd"
427}
428
429#D-#==================================================
430#D-function IGCM_sys_Chmod
431#D-* Purpose: Chmod
432#D-* Examples:
433#D-
434function IGCM_sys_Chmod {
435  IGCM_debug_PushStack "IGCM_sys_Chmod" -- $@
436  if ( $DEBUG_sys ) ; then
437    echo "IGCM_sys_Chmod :" $@
438  fi
439  if [ $DRYRUN -le 1 ]; then
440    \chmod $@
441    if [ $? -gt 0 ] ; then
442      echo "IGCM_sys_Chmod : erreur."
443      IGCM_debug_Exit "IGCM_sys_Chmod"
444    fi
445  else
446    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
447  fi
448  IGCM_debug_PopStack "IGCM_sys_Chmod"
449}
450
451#D-#==================================================
452#D-function IGCM_sys_FileSize
453#D-* Purpose: Filesize
454#D-* Examples:
455#D-
456function IGCM_sys_FileSize {
457  IGCM_debug_PushStack "IGCM_sys_FileSize" $@
458
459  typeset sizeF
460  set +A sizeF -- $( ls -la ${1} )
461  if [ $? -gt 0 ] ; then
462    IGCM_debug_Exit "IGCM_sys_FileSize"
463  fi
464  eval ${2}=${sizeF[4]}
465
466  IGCM_debug_PopStack "IGCM_sys_FileSize"
467}
468
469#D-#==================================================
470#D-function IGCM_sys_TestDir
471#D-* Purpose: Test Directory that must exists
472#D-* Examples:
473#D-
474function IGCM_sys_TestDir {
475  IGCM_debug_PushStack "IGCM_sys_TestDir" $@
476  if ( $DEBUG_sys ) ; then
477    echo "IGCM_sys_TestDir :" $@
478  fi
479  typeset ExistFlag
480  ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
481  IGCM_debug_PopStack "IGCM_sys_TestDir"
482
483  return ${ExistFlag}
484}
485
486#D-#==================================================
487#D-function IGCM_sys_TestDirArchive
488#D-* Purpose: Test Directory that must exists on Archive
489#D-* Examples:
490#D-
491function IGCM_sys_TestDirArchive {
492  IGCM_debug_PushStack "IGCM_sys_TestDirArchive" $@
493  if ( $DEBUG_sys ) ; then
494    echo "IGCM_sys_TestDirArchive :" $@
495  fi
496  typeset ExistFlag
497  ExistFlag=$( [ -d $1 ] && echo 0 || echo 1 )
498  IGCM_debug_PopStack "IGCM_sys_TestDirArchive"
499
500  return ${ExistFlag}
501}
502
503#D-#==================================================
504#D-function IGCM_sys_IsFileArchived
505#D-* Purpose: Test file that must NOT EXISTS on Archive
506#D-* Examples:
507#D-
508function IGCM_sys_IsFileArchived {
509  IGCM_debug_PushStack "IGCM_sys_IsFileArchived" $@
510  if ( $DEBUG_sys ) ; then
511    echo "IGCM_sys_IsFileArchived :" $@
512  fi
513  typeset IsArchivedFlag
514  IsArchivedFlag=$( [ X$( echo $1 | grep ^\/ccc\/store ) != X ] && echo 0 || echo 1 )
515  IGCM_debug_PopStack "IGCM_sys_IsFileArchived"
516
517  return ${IsArchivedFlag}
518}
519
520#D-#==================================================
521#D-function IGCM_sys_TestFileArchive
522#D-* Purpose: Test file that must NOT EXISTS on Archive
523#D-* Examples:
524#D-
525function IGCM_sys_TestFileArchive {
526  IGCM_debug_PushStack "IGCM_sys_TestFileArchive" $@
527  typeset ExistFlag
528  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
529  IGCM_debug_PopStack "IGCM_sys_TestFileArchive"
530
531  return ${ExistFlag}
532}
533
534#D-#==================================================
535#D-function IGCM_sys_TestFileBuffer
536#D-* Purpose: Test file that must NOT EXISTS on Buffer
537#D-* Examples:
538#D-
539function IGCM_sys_TestFileBuffer {
540  IGCM_debug_PushStack "IGCM_sys_TestFileBuffer" $@
541  typeset ExistFlag
542  ExistFlag=$( [ -f $1 ] && echo 0 || echo 1 )
543  IGCM_debug_PopStack "IGCM_sys_TestFileBuffer"
544
545  return ${ExistFlag}
546}
547
548#D-#==================================================
549#D-function IGCM_sys_CountFileArchive
550#D-* Purpose: Count files on Archive filesystem
551#D-* Examples:
552#D-
553function IGCM_sys_CountFileArchive {
554  IGCM_debug_PushStack "IGCM_sys_CountFileArchive" $@
555  ls ${@} 2>/dev/null | wc -l
556  if [ $? -gt 0 ] ; then
557    echo "IGCM_sys_CountFileArchive : erreur."
558  fi
559  IGCM_debug_PopStack "IGCM_sys_CountFileArchive"
560}
561
562#D-#==================================================
563#D-function IGCM_sys_CountFileBuffer
564#D-* Purpose: Count files on Scratch filesystem
565#D-* Examples:
566#D-
567function IGCM_sys_CountFileBuffer {
568  IGCM_debug_PushStack "IGCM_sys_CountFileBuffer" $@
569  ls ${@} 2>/dev/null | wc -l
570  if [ $? -gt 0 ] ; then
571    echo "IGCM_sys_CountFileBuffer : erreur."
572  fi
573  IGCM_debug_PopStack "IGCM_sys_CountFileBuffer"
574}
575
576#D-#==================================================
577#D-function IGCM_sys_Tree
578#D-* Purpose: Tree directories with files on ${ARCHIVE}
579#D-* Examples: IGCM_sys_Tree ${R_IN} ${R_OUT}
580#D-
581function IGCM_sys_Tree {
582  IGCM_debug_PushStack "IGCM_sys_Tree" $@
583  if ( $DEBUG_sys ) ; then
584    echo "IGCM_sys_Tree :" $@
585  fi
586
587  \ls -lR ${@}
588
589  IGCM_debug_PopStack "IGCM_sys_Tree"
590}
591
592#D-#==================================================
593#D-function IGCM_sys_Tar
594#D-* Purpose: master tar command
595#D-* Examples:
596#D-
597function IGCM_sys_Tar {
598  IGCM_debug_PushStack "IGCM_sys_Tar" $@
599  if ( $DEBUG_sys ) ; then
600    echo "IGCM_sys_Tar :" $@
601  fi
602  \tar cf $@
603  if [ $? -gt 0 ] ; then
604    echo "IGCM_sys_Tar : erreur."
605    IGCM_debug_Exit "IGCM_sys_Tar"
606  fi
607  IGCM_debug_PopStack "IGCM_sys_Tar"
608}
609
610#D-#==================================================
611#D-function IGCM_sys_UnTar
612#D-* Purpose: master un-tar command
613#D-* Examples:
614#D-
615function IGCM_sys_UnTar {
616  IGCM_debug_PushStack "IGCM_sys_UnTar" $@
617  if ( $DEBUG_sys ) ; then
618    echo "IGCM_sys_UnTar :" $@
619  fi
620  \tar xvf $1
621  if [ $? -gt 0 ] ; then
622    echo "IGCM_sys_UnTar : erreur."
623    IGCM_debug_Exit "IGCM_sys_UnTar"
624  fi
625  IGCM_debug_PopStack "IGCM_sys_UnTar"
626}
627
628#D-#==================================================
629#D-function IGCM_sys_Qsub
630#D-* Purpose: Qsub new job
631#D-* Examples:
632#D-
633function IGCM_sys_Qsub {
634  IGCM_debug_PushStack "IGCM_sys_Qsub" $@
635  if ( $DEBUG_sys ) ; then
636    echo "IGCM_sys_Qsub :" $@
637  fi
638  /usr/bin/nqsII/qsub -o ${Script_Output} -N ${config_UserChoices_JobName}.${CumulPeriod} < $1
639  if [ $? -gt 0 ] ; then
640    echo "IGCM_sys_Qsub : erreur -o ${Script_Output} -N ${config_UserChoices_JobName}.${CumulPeriod} $@."
641    IGCM_debug_Exit "IGCM_sys_Qsub"
642  fi
643  IGCM_debug_PopStack "IGCM_sys_Qsub"
644}
645
646#D-#==================================================
647#D-function IGCM_sys_QsubPost
648#D-* Purpose: Qsub new job on scalaire
649#D-* Examples:
650#D-
651function IGCM_sys_QsubPost {
652  IGCM_debug_PushStack "IGCM_sys_QsubPost" $@
653  if ( $DEBUG_sys ) ; then
654    echo "IGCM_sys_QsubPost :" $@
655  fi
656
657# ============ FRONTEND START ============ #
658
659  /usr/bin/nqsII/qsub -q scalaire -o ${POST_DIR}/${Script_Post_Output}.out ${libIGCM}/$1.job -v ${listVarEnv}
660
661# ============ FRONTEND  END  ============ #
662
663# ============ CESIUM START ============ #
664#  typeset NB_ESSAI DELAI status i
665#  # number of tentative
666#  NB_ESSAI=10
667#  # time delay between tentative
668#  DELAI=10
669#  (( i = 0 ))
670#  while [ $i -lt $NB_ESSAI ] ; do
671#    /usr/local/bin/ccc_msub -o ${POST_DIR}/${Script_Post_Output}.out -e ${POST_DIR}/${Script_Post_Output}.e.out -E "-v ${listVarEnv}" ${libIGCM_POST}/$1.job
672#    status=$?
673#    if [ ${status} -gt 0 ]; then
674#      sleep $DELAI
675#    else
676#      break
677#    fi
678#    (( i = i + 1 ))
679#  done
680# ============ CESIUM  END  ============ #
681
682  if [ $? -gt 0 ] ; then
683    echo "IGCM_sys_QsubPost : erreur " $@
684    IGCM_debug_Exit "IGCM_sys_QsubPost"
685  fi
686  IGCM_debug_PopStack "IGCM_sys_QsubPost"
687}
688
689#D-*************************
690#D- File transfer functions
691#D-*************************
692#D-
693
694#D-#==================================================
695#D-function IGCM_sys_Rsync_out
696#D-* Purpose: treat return val of rsync
697#D-* Examples: IGCM_sys_Rsync_out out_RET_rsync
698#D-  Error values and explanations can depend on your system version.
699function IGCM_sys_Rsync_out {
700  status=$1
701  if [ ! $status ] ; then
702    echo "rsync error !"
703  fi
704
705  if [ $MYLANG = "fr" ]; then
706    case $status in
707    0)  return ;;
708    1)  echo "Erreur de rsync ; RERR_SYNTAX : "
709      echo "Erreur de syntaxe ou d'utilisation."
710      return;;
711    2)  echo "Erreur de rsync ; RERR_PROTOCOL : "
712      echo "Incompatibilité de protocole."
713      return;;
714    3)  echo "Erreur de rsync ; RERR_FILESELECT 3"
715      echo "Erreurs  lors  de  la  sélection des fichiers d'entrée sortie et"
716      echo "répertoires"
717      return;;
718    4)  echo "Erreur de rsync ; RERR_UNSUPPORTED"
719      echo "Action demandée non supportée : une tentative de manipulation de"
720      echo "fichiers  64-bits  sur une plate-forme qui ne les supporte pas a"
721      echo "été faite ; ou une option qui est supportée par le  client  mais"
722      echo "pas par le serveur a été spécifiée."
723      return;;
724    10) echo "Erreur de rsync ; RERR_SOCKETIO"
725      echo "Erreur dans le socket d'entrée sortie"
726      return;;
727    11) echo "Erreur de rsync ; RERR_FILEIO"
728      echo "Erreur d'entrée sortie fichier"
729      return;;
730    12) echo "Erreur de rsync ; RERR_STREAMIO"
731      echo "Erreur dans flux de donnée du protocole rsync"
732      return;;
733    13) echo "Erreur de rsync ; RERR_MESSAGEIO"
734      echo "Erreur avec les diagnostics du programme"
735      return;;
736    14) echo "Erreur de rsync ; RERR_IPC"
737      echo "Erreur dans le code IPC"
738      return;;
739    20) echo "Erreur de rsync ; RERR_SIGNAL"
740      echo "SIGUSR1 ou SIGINT reçu"
741      return;;
742    21) echo "Erreur de rsync ; RERR_WAITCHILD"
743      echo "Une erreur retournée par waitpid()"
744      return;;
745    22) echo "Erreur de rsync ; RERR_MALLOC"
746      echo "Erreur lors de l'allocation des tampons de mémoire de coeur"
747      return;;
748    23) echo ""
749      echo "Erreur fichier inexistant"
750      return;;
751    30) echo "Erreur de rsync ; RERR_TIMEOUT"
752      echo "Temps d'attente écoulé dans l'envoi/réception de données"
753      return;;
754    *)  echo "Erreur de rsync : code de retour de rsync inconnu :" $status
755      return;;
756    esac
757  elif [ $MYLANG = "en" ] ; then
758    case $status in
759    0)  return;;
760    1)  echo "rsync error : Syntax or usage error "
761      return;;
762    2)  echo "rsync error : Protocol incompatibility "
763      return;;
764    3)  echo "rsync error : Errors selecting input/output files, dirs"
765      return;;
766    4)  echo "rsync error : Requested action not supported: an attempt"
767      echo "was made to manipulate 64-bit files on a platform that cannot support"
768      echo "them; or an option was specified that is supported by the client and"
769      echo "not by the server."
770      return;;
771    5)  echo "rsync error : Error starting client-server protocol"
772      return;;
773    10) echo "rsync error : Error in socket I/O "
774      return;;
775    11) echo "rsync error : Error in file I/O "
776      return;;
777    12) echo "rsync error : Error in rsync protocol data stream "
778      return;;
779    13) echo "rsync error : Errors with program diagnostics "
780      return;;
781    14) echo "rsync error : Error in IPC code "
782      return;;
783    20) echo "rsync error : Received SIGUSR1 or SIGINT "
784      return;;
785    21) echo "rsync error : Some error returned by waitpid() "
786      return;;
787    22) echo "rsync error : Error allocating core memory buffers "
788      return;;
789    23) echo "rsync error : Partial transfer due to error"
790      return;;
791    24) echo "rsync error : Partial transfer due to vanished source files"
792      return;;
793    30) echo "rsync error : Timeout in data send/receive "
794      return;;
795    *)  echo "rsync error : return code of rsync unknown :" $status
796      return;;
797    esac
798  else
799    echo "unknown language $MYLANG."
800    return
801  fi
802}
803
804#D-#==================================================
805#D-function IGCM_sys_Miror_libIGCM
806#D-* Purpose: Mirror libIGCM PATH and lib to cesium
807#D-* Examples:
808#D-
809function IGCM_sys_Mirror_libIGCM {
810  IGCM_debug_PushStack "IGCM_sys_Mirror_libIGCM"
811  if ( $DEBUG_sys ) ; then
812    echo "IGCM_sys_Mirror_libIGCM"
813  fi
814
815  typeset status DEST
816
817  mkdir -p ${HOME}/MIRROR/${PATHlibIGCM}
818
819  echo ${RSYNC} ${RSYNC_opt} ${libIGCM} ${HOME}/MIRROR/${PATHlibIGCM} > out_rsync 2>&1
820  ${RSYNC} ${RSYNC_opt} ${libIGCM} ${HOME}/MIRROR/${PATHlibIGCM} >> out_rsync 2>&1
821  status=$?
822
823  if [ ${status} -gt 0 ] ; then
824    echo "IGCM_sys_Mirror_libIGCM Warning : no libIGCM on cesium."
825    cat out_rsync
826  fi
827  IGCM_debug_PopStack "IGCM_sys_Mirror_libIGCM"
828}
829
830#D-#==================================================
831#D-function IGCM_sys_Cp
832#D-* Purpose: generic cp
833#D-* Examples:
834#D-
835function IGCM_sys_Cp {
836  IGCM_debug_PushStack "IGCM_sys_Cp" $@
837  if ( $DEBUG_sys ) ; then
838    echo "IGCM_sys_Cp :" $@
839  fi
840
841  typeset status
842
843  echo cp $@ > out_rsync 2>&1
844  \cp $@ >> out_rsync 2>&1
845  status=$?
846
847  if [ ${status} -gt 0 ] ; then
848    echo "IGCM_sys_Cp : error code ${status}"
849    cat out_rsync
850    IGCM_debug_Exit "IGCM_sys_Cp"
851  else
852    \rm out_rsync
853  fi
854  IGCM_debug_PopStack "IGCM_sys_Cp"
855}
856
857#D-#==================================================
858#D-function IGCM_sys_Rm
859#D-* Purpose: generic rm
860#D-* Examples:
861#D-
862function IGCM_sys_Rm {
863  IGCM_debug_PushStack "IGCM_sys_Rm" -- $@
864  if ( $DEBUG_sys ) ; then
865    echo "IGCM_sys_Rm :" $@
866  fi
867
868  typeset status
869
870  echo rm $@ > out_rsync 2>&1
871  \rm $@ >> out_rsync 2>&1
872  status=$?
873
874  if [ ${status} -gt 0 ] ; then
875    echo "IGCM_sys_Rm : error code ${status}"
876    cat out_rsync
877    IGCM_debug_Exit "IGCM_sys_Rm"
878  else
879    \rm out_rsync
880  fi
881  IGCM_debug_PopStack "IGCM_sys_Rm"
882}
883
884#D-#==================================================
885#D-function IGCM_sys_Mv
886#D-* Purpose: generic move
887#D-* Examples:
888#D-
889function IGCM_sys_Mv {
890  IGCM_debug_PushStack "IGCM_sys_Mv" $@
891  if ( $DEBUG_sys ) ; then
892    echo "IGCM_sys_Mv :" $@
893  fi
894
895  if [ $DRYRUN = 0 ]; then
896
897    typeset status
898
899    echo mv $@ > out_rsync 2>&1
900    \mv $@ >> out_rsync 2>&1
901    status=$?
902
903    if [ ${status} -gt 0 ] ; then
904      echo "IGCM_sys_Mv : error code ${status}"
905      cat out_rsync
906      IGCM_debug_Exit "IGCM_sys_Mv"
907    else
908      \rm out_rsync
909    fi
910  else
911    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
912  fi
913
914  IGCM_debug_PopStack "IGCM_sys_Mv"
915}
916
917#D-#==================================================
918#D-function IGCM_sys_Put_Dir
919#D-* Purpose: Copy a complete directory on $(ARCHIVE)
920#D-* Examples:
921#D-
922function IGCM_sys_Put_Dir {
923  IGCM_debug_PushStack "IGCM_sys_Put_Dir" $@
924  if ( $DEBUG_sys ) ; then
925    echo "IGCM_sys_Put_Dir :" $@
926  fi
927  if [ $DRYRUN = 0 ]; then
928    if [ ! -d ${1} ] ; then
929      echo "WARNING : IGCM_sys_Put_Dir ${1} DOES NOT EXIST ."
930      IGCM_debug_PopStack "IGCM_sys_Put_Dir"
931      return
932    fi
933
934    typeset status
935
936    # Only if we use rsync
937    #IGCM_sys_TestDirArchive $( dirname $2 )
938    #
939    #USUAL WAY
940    \cp -r $1 $2 > out_rsync 2>&1
941    status=$?
942
943    if [ ${status} -gt 0 ] ; then
944      echo "IGCM_sys_Put_Dir : error code ${status}"
945      cat out_rsync
946      IGCM_debug_Exit "IGCM_sys_Put_Dir"
947    else
948      \rm out_rsync
949    fi
950  else
951    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
952  fi
953  IGCM_debug_PopStack "IGCM_sys_Put_Dir"
954}
955
956#D-#==================================================
957#D-function IGCM_sys_Get_Dir
958#D-* Purpose: Copy a complete directory from ${ARCHIVE}
959#D-* Examples:
960#D-
961function IGCM_sys_Get_Dir {
962  IGCM_debug_PushStack "IGCM_sys_Get_Dir" $@
963  if ( $DEBUG_sys ) ; then
964    echo "IGCM_sys_Get_Dir :" $@
965  fi
966  if [ $DRYRUN = 0 ]; then
967#    if [ ! -d ${1} ] ; then
968#      echo "WARNING : IGCM_sys_Get_Dir ${1} DOES NOT EXIST ."
969#      IGCM_debug_PopStack "IGCM_sys_Get_Dir"
970#      return
971#    fi
972
973    typeset NB_ESSAI DELAI status i
974    # number of tentative
975    NB_ESSAI=3
976    # time delay between tentative
977    DELAI=2
978
979    # Only if we use rsync
980    #IGCM_sys_TestDirArchive $( dirname $2 )
981    #
982    # USUAL WAY
983    # add 'ccc_hsm get' (to demigrate all offline files) to reduce time of this command :
984    ccc_hsm get -r $1
985
986    i=0
987    while [ $i -lt $NB_ESSAI ] ; do
988      \cp -ur $1 $2 >> out_rsync 2>&1
989      status=$?
990      if [ ${status} -gt 0 ]; then
991        IGCM_debug_Print 2 "IGCM_sys_Get_Dir : cp failed error code ${status} ${i}/${NB_ESSAI}"
992        IGCM_debug_Print 2 "IGCM_sys_Get_Dir : sleep ${DELAI} seconds and try again."
993        sleep $DELAI
994      else
995        break
996      fi
997      (( i = i + 1 ))
998    done
999
1000    if [ ${status} -gt 0 ] ; then
1001      echo "IGCM_sys_Get_Dir : error."
1002      cat out_rsync
1003      IGCM_debug_Exit "IGCM_sys_Get_Dir"
1004    else
1005      \rm out_rsync
1006    fi
1007  else
1008    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1009  fi
1010  IGCM_debug_PopStack "IGCM_sys_Get_Dir"
1011}
1012
1013#====================================================
1014#- Call IGCM_sys_Mirror_libIGCM now !
1015if ( $MirrorlibIGCM ) ; then
1016  IGCM_sys_Mirror_libIGCM
1017fi
1018
1019#D-#==================================================
1020#D-function IGCM_sys_Put_Rest
1021#D-* Purpose: Put computied restarts on ${ARCHIVE}.
1022#D-           File and target directory must exist.
1023#D-* Examples:
1024#D-
1025function IGCM_sys_Put_Rest {
1026  IGCM_debug_PushStack "IGCM_sys_Put_Rest" $@
1027  if ( $DEBUG_sys ) ; then
1028    echo "IGCM_sys_Put_Rest :" $@
1029  fi
1030  if [ $DRYRUN = 0 ]; then
1031    if [ ! -f ${1} ] ; then
1032      echo "ERROR : IGCM_sys_Put_Rest ${1} DOES NOT EXIST ."
1033      IGCM_debug_Exit "IGCM_sys_Put_Rest"
1034    fi
1035
1036    typeset status
1037    #
1038    if [ X${JobType} = XRUN ] ; then
1039      IGCM_sys_Chmod 444 ${1}
1040    fi
1041
1042    #
1043    # USUAL WAY
1044    \cp $1 $2 > out_rsync 2>&1
1045    status=$?
1046
1047#       #RSYNC WITH NETWORK SSH CALL
1048#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > out_rsync 2>&1
1049#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> out_rsync 2>&1
1050
1051#       #RSYNC WITH NFS USE
1052#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
1053#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
1054
1055#       status=$?
1056#       IGCM_sys_Rsync_out $status
1057
1058#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1059#       (( status=status+$? ))
1060
1061    if [ ${status} -gt 0 ] ; then
1062      echo "IGCM_sys_Put_Rest : cp failed error code ${status}"
1063      cat out_rsync
1064      IGCM_debug_Exit "IGCM_sys_Put_Rest"
1065    else
1066      \rm out_rsync
1067    fi
1068  else
1069    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1070  fi
1071  IGCM_debug_PopStack "IGCM_sys_Put_Rest"
1072}
1073
1074#D-#==================================================
1075#D-function IGCM_sys_PutBuffer_Rest
1076#D-* Purpose: Put computied restarts on ${SCRATCHDIR}.
1077#D-           File and target directory must exist.
1078#D-* Examples:
1079#D-
1080function IGCM_sys_PutBuffer_Rest {
1081  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Rest" $@
1082  if ( $DEBUG_sys ) ; then
1083    echo "IGCM_sys_PutBuffer_Rest :" $@
1084  fi
1085  if [ $DRYRUN = 0 ]; then
1086    if [ ! -f ${1} ] ; then
1087      echo "ERROR : IGCM_sys_PutBuffer_Rest ${1} DOES NOT EXIST ."
1088      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
1089    fi
1090
1091    typeset status
1092    #
1093    if [ X${JobType} = XRUN ] ; then
1094      IGCM_sys_Chmod 444 ${1}
1095    fi
1096
1097    #
1098    # USUAL WAY
1099    \cp $1 $2 > out_rsync 2>&1
1100    status=$?
1101
1102    if [ ${status} -gt 0 ] ; then
1103      echo "IGCM_sys_PutBuffer_Rest : error code ${status}"
1104      cat out_rsync
1105      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
1106    else
1107      \rm out_rsync
1108    fi
1109  else
1110    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1111  fi
1112  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Rest"
1113}
1114
1115#D-#==================================================
1116#D-function IGCM_sys_Put_Out
1117#D-* Purpose: Copy a file on ${ARCHIVE} after having chmod it in readonly
1118#D-* Examples:
1119#D-
1120function IGCM_sys_Put_Out {
1121  IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
1122  if ( $DEBUG_sys ) ; then
1123    echo "IGCM_sys_Put_Out :" $@
1124  fi
1125
1126  typeset NB_ESSAI DELAI status i exist skip
1127
1128  # number of tentative
1129  NB_ESSAI=3
1130  # time delay between tentative
1131  DELAI=2
1132
1133  if [ $DRYRUN = 0 ]; then
1134    if [ ! -f ${1} ] ; then
1135      echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
1136      IGCM_debug_PopStack "IGCM_sys_Put_Out"
1137      return 1
1138    fi
1139    #
1140    IGCM_sys_MkdirArchive $( dirname $2 )
1141    #
1142
1143    #=====================================================
1144    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1145    #=====================================================
1146
1147    #echo ${2} | grep "${R_OUT}" > /dev/null 2>&1
1148    #if [ $? -eq 0 ] ; then
1149    #    typeset WORKPATH FILEPATH
1150    #    WORKPATH=$( dirname $2 | sed -e "s|${R_OUT}|${R_BUF}|" )
1151    #    IGCM_sys_MkdirWork ${WORKPATH}
1152    #    FILEPATH=${WORKPATH}/$( basename $2 )
1153    #    #
1154    #    IGCM_sys_Cp ${1} ${FILEPATH}
1155    #fi
1156
1157    if [ X${JobType} = XRUN ] ; then
1158      if [ X${3} = X ] ; then
1159        IGCM_sys_Chmod 444 ${1}
1160      fi
1161    fi
1162    #
1163
1164    exist=false
1165    skip=false
1166    if [ -f $2 ] ; then
1167      IGCM_debug_Print 1 "$2 already exist"
1168      #dmget $2
1169      ccc_hsm get $2
1170      exist=true
1171      if [ "X$( diff $1 $2 )" = X ] ; then
1172        IGCM_debug_Print 2 "$1 and $2 are the same file, we skip the copy"
1173        skip=true
1174      else
1175        IGCM_debug_Print 2 "$1 and $2 are not the same file, we force the copy"
1176        skip=false
1177      fi
1178    fi
1179    #
1180    if ( [ X${exist} = Xtrue ] && [ X${skip} = Xfalse ] ) ; then
1181      IGCM_sys_Chmod u+w $2
1182    fi
1183
1184    if [ X${skip} = Xfalse ] ; then
1185      i=0
1186      while [ $i -lt $NB_ESSAI ] ; do
1187        # USUAL WAY
1188        \cp $1 $2 > out_rsync 2>&1
1189        status=$?
1190        if [ ${status} -gt 0 ]; then
1191          IGCM_debug_Print 2 "IGCM_sys_Put_Out : cp failed error code ${status} ${i}/${NB_ESSAI}"
1192          IGCM_debug_Print 2 "IGCM_sys_Put_Out : sleep ${DELAI} seconds and try again."
1193          sleep $DELAI
1194        else
1195          break
1196        fi
1197        (( i = i + 1 ))
1198      done
1199    fi
1200
1201#       #RSYNC WITH NETWORK SSH CALL
1202#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > out_rsync 2>&1
1203#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> out_rsync 2>&1
1204
1205#       #RSYNC WITH NFS USE
1206#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
1207#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
1208
1209#       status=$?
1210#       IGCM_sys_Rsync_out $status
1211
1212#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1213#       (( status=status+$? ))
1214
1215    if [ ${status} -gt 0 ] ; then
1216      echo "IGCM_sys_Put_Out : error."
1217      cat out_rsync
1218      IGCM_debug_Exit "IGCM_sys_Put_Out"
1219    else
1220      \rm out_rsync
1221    fi
1222  else
1223    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1224  fi
1225  IGCM_debug_PopStack "IGCM_sys_Put_Out"
1226  return 0
1227}
1228
1229#D-#==================================================
1230#D-function IGCM_sys_PutBuffer_Out
1231#D-* Purpose: Copy a file on ${SCRATCHDIR} after having chmod it in readonly
1232#D-* Examples:
1233#D-
1234function IGCM_sys_PutBuffer_Out {
1235  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Out" $@
1236  if ( $DEBUG_sys ) ; then
1237    echo "IGCM_sys_PutBuffer_Out :" $@
1238  fi
1239
1240  typeset NB_ESSAI DELAI status i exist skip
1241
1242  # number of tentative
1243  NB_ESSAI=3
1244  # time delay between tentative
1245  DELAI=2
1246
1247  if [ $DRYRUN = 0 ]; then
1248    if [ ! -f ${1} ] ; then
1249      echo "WARNING : IGCM_sys_PutBuffer_Out ${1} DOES NOT EXIST ."
1250      IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1251      return 1
1252    fi
1253    #
1254    IGCM_sys_Mkdir $( dirname $2 )
1255    #
1256
1257    if [ X${JobType} = XRUN ] ; then
1258      if [ X${3} = X ] ; then
1259        IGCM_sys_Chmod 444 ${1}
1260      fi
1261    fi
1262
1263    exist=false
1264    skip=false
1265    if [ -f $2 ] ; then
1266      IGCM_debug_Print 1 "$2 already exist"
1267      exist=true
1268      if [ "X$( diff $1 $2 )" = X ] ; then
1269        IGCM_debug_Print 2 "$1 and $2 are the same file, we skip the copy"
1270        skip=true
1271      else
1272        IGCM_debug_Print 2 "$1 and $2 are not the same file, we force the copy"
1273        skip=false
1274      fi
1275    fi
1276    #
1277    if ( [ X${exist} = Xtrue ] && [ X${skip} = Xfalse ] ) ; then
1278      IGCM_sys_Chmod u+w $2
1279    fi
1280
1281    if [ X${skip} = Xfalse ] ; then
1282      i=0
1283      while [ $i -lt $NB_ESSAI ] ; do
1284        # USUAL WAY
1285        \cp $1 $2 > out_rsync 2>&1
1286        status=$?
1287        if [ ${status} -gt 0 ]; then
1288          IGCM_debug_Print 2 "IGCM_sys_PutBuffer_Out : cp failed error code ${status} ${i}/${NB_ESSAI}"
1289          IGCM_debug_Print 2 "IGCM_sys_PutBuffer_Out : sleep ${DELAI} seconds and try again."
1290          sleep $DELAI
1291        else
1292          break
1293        fi
1294        (( i = i + 1 ))
1295      done
1296    fi
1297
1298    if [ ${status} -gt 0 ] ; then
1299      echo "IGCM_sys_PutBuffer_Out : error."
1300      cat out_rsync
1301      IGCM_debug_Exit "IGCM_sys_PutBuffer_Out"
1302    else
1303      \rm out_rsync
1304    fi
1305  else
1306    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1307  fi
1308  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1309  return 0
1310}
1311
1312#D-#==================================================
1313#D-function IGCM_sys_Get
1314#D-* Purpose: Get a file from ${ARCHIVE}
1315#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
1316#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
1317function IGCM_sys_Get {
1318  IGCM_debug_PushStack "IGCM_sys_Get" $@
1319
1320  typeset DEST dm_liste ifile target file_work
1321  typeset NB_ESSAI DELAI status i
1322
1323  if ( $DEBUG_sys ) ; then
1324    echo "IGCM_sys_Get :" $@
1325  fi
1326
1327  # number of tentative
1328  NB_ESSAI=3
1329  # time delay between tentative
1330  DELAI=2
1331
1332  if [ $DRYRUN -le 2 ]; then
1333    if [ X${1} = X'/l' ] ; then
1334      # test if the first file is present in the old computation :
1335      eval set +A dm_liste \${${2}}
1336    else
1337      eval set +A dm_liste ${1}
1338    fi
1339    eval DEST=\${${#}}
1340
1341    #=====================================================
1342    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1343    #=====================================================
1344
1345    # Is it an R_OUT file (not R_IN) ?
1346    #echo ${dm_liste[0]} | grep "${R_OUT}" > /dev/null 2>&1
1347    #if [ $? -eq 0 ] ; then
1348    #    # Yes  ? then we try to get it in SCRATCHDIR
1349    #    set +A file_work $( echo ${dm_liste[*]} | sed -e "s|${R_OUT}|${R_BUF}|g" )
1350    #    if [ -f ${file_work[0]} ] ; then
1351    #   IGCM_sys_Cp ${file_work[*]} ${DEST}
1352    #   IGCM_debug_PopStack "IGCM_sys_Get"
1353    #   return
1354    #    fi
1355    #fi
1356
1357    ccc_hsm get ${dm_liste[*]} > out_rsync 2>&1
1358    status=$?
1359    if [ ${status} -gt 0 ] ; then
1360      echo "WARNING IGCM_sys_Get : error code ${status}"
1361      cat out_rsync
1362      echo "WARNING IGCM_sys_Get : will stop later if the cp fails."
1363    fi
1364
1365    #if [ ${status} -gt 0 ] ; then
1366    #    if [ ! "X$( grep "Lost dmusrcmd connection" out_rsync )" = "X" ] ; then
1367    #   cat out_rsync
1368    #   echo "WARNING IGCM_sys_Get : Lost dmusrcmd connection : "
1369    #   sleep 30
1370    #   echo "We try another time"
1371    ##  dmget ${dm_liste[*]} > out_rsync 2>&1
1372    #   ccc_hsm get ${dm_liste[*]} > out_rsync 2>&1
1373    #   status=$?
1374    #   if [ ${status} -gt 0 ] ; then
1375    #       echo "ERROR IGCM_sys_Get : again demigration error :"
1376    #       cat out_rsync
1377    #       IGCM_debug_Exit "IGCM_sys_Get"
1378    #   fi
1379    #    else
1380    #   echo "ERROR IGCM_sys_Get : demigration error :"
1381    #   cat out_rsync
1382    #   IGCM_debug_Exit "IGCM_sys_Get"
1383    #    fi
1384    #fi
1385
1386    #   #RSYNC WITH NETWORK SSH CALL
1387    #   echo ${RSYNC} ${RSYNC_opt} -e ssh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} > out_rsync 2>&1
1388    #   ${RSYNC} ${RSYNC_opt} -e ssh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} >> out_rsync 2>&1
1389
1390    #   #RSYNC WITH NFS USE
1391    #   echo ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} > out_rsync 2>&1
1392    #   ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} >> out_rsync 2>&1
1393
1394    #   status=$?
1395    #   IGCM_sys_Rsync_out $status
1396
1397    #   ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1398    #   (( status=status+$? ))
1399
1400    #USUAL WAY
1401    if [ X${1} = X'/l' ] ; then
1402      for target in ${dm_liste[*]} ; do
1403        local_file=$( basename ${target} )
1404        # test if the target file is present before the loop
1405        IGCM_sys_TestFileArchive ${target}
1406        status=$?
1407        if [ ${status} -gt 0 ] ; then
1408          echo "IGCM_sys_Get, ERROR : regular file ${target} DOES NOT EXIST ."
1409          IGCM_debug_Exit "IGCM_sys_Get"
1410        else
1411          i=0
1412          while [ $i -lt $NB_ESSAI ] ; do
1413            \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1414            status=$?
1415            if [ ${status} -gt 0 ]; then
1416              IGCM_debug_Print 2 "IGCM_sys_Get : cp failed error code ${status} ${i}/${NB_ESSAI}"
1417              IGCM_debug_Print 2 "IGCM_sys_Get : sleep ${DELAI} seconds and try again."
1418              sleep $DELAI
1419            else
1420              break
1421            fi
1422            (( i = i + 1 ))
1423          done
1424          if [ ${status} -gt 0 ] ; then
1425            echo "IGCM_sys_Get : error"
1426            cat out_rsync
1427            \rm out_rsync
1428            IGCM_debug_Exit "IGCM_sys_Get"
1429          else
1430            \rm out_rsync
1431          fi
1432        fi
1433      done
1434    else
1435      i=0
1436      while [ $i -lt $NB_ESSAI ] ; do
1437        \cp ${dm_liste} ${DEST} >> out_rsync 2>&1
1438        status=$?
1439        if [ ${status} -gt 0 ]; then
1440          IGCM_debug_Print 2 "IGCM_sys_Get : cp failed error code ${status} ${i}/${NB_ESSAI}"
1441          IGCM_debug_Print 2 "IGCM_sys_Get : sleep ${DELAI} seconds and try again."
1442          sleep $DELAI
1443        else
1444          break
1445        fi
1446        (( i = i + 1 ))
1447      done
1448      if [ ${status} -gt 0 ] ; then
1449        echo "IGCM_sys_Get : error"
1450        cat out_rsync
1451        \rm out_rsync
1452        IGCM_debug_Exit "IGCM_sys_Get"
1453      else
1454        \rm out_rsync
1455      fi
1456    fi
1457  else
1458    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1459  fi
1460  IGCM_debug_PopStack "IGCM_sys_Get"
1461}
1462
1463#D-#==================================================
1464#D-function IGCM_sys_GetBuffer
1465#D-* Purpose: Get a file from ${SCRATCHDIR}
1466#D-* Examples: IGCM_sys_GetBuffer myfile /destpath/myfile_with_PREFIX
1467#D-            IGCM_sys_GetBuffer /l Array_contain_myfiles /destpath/
1468function IGCM_sys_GetBuffer {
1469  IGCM_debug_PushStack "IGCM_sys_GetBuffer" $@
1470
1471  typeset DEST buf_liste ifile target file_work
1472  typeset NB_ESSAI DELAI status i
1473
1474  if ( $DEBUG_sys ) ; then
1475    echo "IGCM_sys_GetBuffer :" $@
1476  fi
1477
1478  # number of tentative
1479  NB_ESSAI=3
1480  # time delay between tentative
1481  DELAI=2
1482
1483  if [ $DRYRUN -le 2 ]; then
1484    if [ X${1} = X'/l' ] ; then
1485      # test if the first file is present in the old computation :
1486      eval set +A buf_liste \${${2}}
1487    else
1488      eval set +A buf_liste ${1}
1489    fi
1490    eval DEST=\${${#}}
1491
1492    #USUAL WAY
1493    if [ X${1} = X'/l' ] ; then
1494      for target in ${buf_liste[*]} ; do
1495        local_file=$( basename ${target} )
1496        i=0
1497        while [ $i -lt $NB_ESSAI ] ; do
1498          \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1499          status=$?
1500          if [ ${status} -gt 0 ]; then
1501            IGCM_debug_Print 2 "IGCM_sys_GetBuffer : cp failed error code ${status} ${i}/${NB_ESSAI}"
1502            IGCM_debug_Print 2 "IGCM_sys_GetBuffer : sleep ${DELAI} seconds and try again."
1503            sleep $DELAI
1504          else
1505            break
1506          fi
1507          (( i = i + 1 ))
1508        done
1509        if [ ${status} -gt 0 ] ; then
1510          echo "IGCM_sys_Get : error"
1511          cat out_rsync
1512          \rm out_rsync
1513          IGCM_debug_Exit "IGCM_sys_GetBuffer"
1514        else
1515          \rm out_rsync
1516        fi
1517      done
1518    else
1519      i=0
1520      while [ $i -lt $NB_ESSAI ] ; do
1521        \cp ${buf_liste} ${DEST} >> out_rsync 2>&1
1522        status=$?
1523        if [ ${status} -gt 0 ]; then
1524          IGCM_debug_Print 2 "IGCM_sys_GetBuffer : cp failed error code ${status} ${i}/${NB_ESSAI}"
1525          IGCM_debug_Print 2 "IGCM_sys_GetBuffer : sleep ${DELAI} seconds and try again."
1526          sleep $DELAI
1527        else
1528          break
1529        fi
1530        (( i = i + 1 ))
1531      done
1532      if [ ${status} -gt 0 ] ; then
1533        echo "IGCM_sys_Get : error"
1534        cat out_rsync
1535        \rm out_rsync
1536        IGCM_debug_Exit "IGCM_sys_GetBuffer"
1537      else
1538        \rm out_rsync
1539      fi
1540    fi
1541  else
1542    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1543  fi
1544  IGCM_debug_PopStack "IGCM_sys_GetBuffer"
1545}
1546
1547#D-#==================================================
1548#D-function IGCM_sys_GetDate_FichWork
1549#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
1550#D-* Examples:
1551#D-
1552function IGCM_sys_GetDate_FichWork {
1553  IGCM_debug_PushStack "IGCM_sys_FichWork" $@
1554  if ( $DEBUG_sys ) ; then
1555    echo "IGCM_sys_GetDate_FichWork :" $@
1556  fi
1557  typeset dateF
1558  set +A dateF -- $( IGCM_sys_RshMaster "ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1}" )
1559  eval ${2}=${dateF[5]}
1560
1561    # donne la date filesys d'un fichier sur la machine work
1562  IGCM_debug_PopStack "IGCM_sys_FichWork"
1563}
1564
1565#D-#==================================================
1566#D-function IGCM_sys_GetDate_FichArchive
1567#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
1568#D-* Examples:
1569#D-
1570function IGCM_sys_GetDate_FichArchive {
1571  IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
1572  if ( $DEBUG_sys ) ; then
1573    echo "IGCM_sys_GetDate_FichArchive :" $@
1574  fi
1575  typeset dateF
1576  set +A dateF -- $( IGCM_sys_RshMaster "ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1}" )
1577  eval ${2}=${dateF[5]}
1578
1579  IGCM_debug_PopStack "IGCM_sys_FichArchive"
1580}
1581
1582##############################################################
1583# REBUILD OPERATOR
1584
1585function IGCM_sys_rebuild {
1586  IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1587  if ( $DEBUG_sys ) ; then
1588    echo "IGCM_sys_rebuild :" $@
1589  fi
1590
1591  typeset NB_ESSAI DELAI status i firstArg
1592  # number of tentative
1593  NB_ESSAI=3
1594  # time delay between tentative
1595  DELAI=2
1596
1597  i=0
1598  while [ $i -lt $NB_ESSAI ] ; do
1599      /home/cont003/p86ipsl/SX8/bin/rebuild -f -o $@ > out_rsync 2>&1
1600    status=$?
1601    if [ ${status} -gt 0 ] ; then
1602      IGCM_debug_Print 2 "IGCM_sys_rebuild : error code ${status}"
1603      cat out_rsync
1604      \rm out_rsync
1605      IGCM_debug_Print 2 "IGCM_sys_rebuild : ${i}/${NB_ESSAI} sleep ${DELAI} seconds and try again."
1606      firstArg=${1}
1607      \rm ${firstArg}
1608      sleep $DELAI
1609    else
1610      \rm out_rsync
1611      break
1612    fi
1613    (( i = i + 1 ))
1614  done
1615
1616  if [ ${status} -gt 0 ] ; then
1617    echo "IGCM_sys_rebuild : rebuild error"
1618    IGCM_debug_Exit "rebuild"
1619  fi
1620
1621  IGCM_debug_PopStack "IGCM_sys_rebuild"
1622}
1623
1624function IGCM_sys_rebuild_station {
1625  IGCM_debug_PushStack "IGCM_sys_rebuild_station" -- $@
1626  typeset i list_opt file_in file_out prefix_invert list_invert
1627  if ( $DEBUG_sys ) ; then
1628    echo "IGCM_sys_rebuild_station :" $@
1629  fi
1630  list_opt=$@
1631
1632  # Invert Axis : t,x -> x,t
1633  #               t,pres,x -> x,t,pres
1634  # So that we can concatenate along x
1635  i=0
1636  for file_in in ${list_opt} ; do
1637    (( i = i + 1))
1638    [ ${i} = 1 ] && file_out=${file_in} && continue
1639    prefix_invert=$( basename ${file_in} .nc )
1640    IGCM_sys_ncpdq -a x,time_counter -a x,time_counter,presnivs ${file_in} ${prefix_invert}_xt.nc
1641    list_invert[${#list_invert[*]}]=${prefix_invert}_xt.nc
1642  done
1643
1644  # Concatenate
1645  IGCM_sys_ncrcat ${list_invert[*]} histstn_xt.nc
1646
1647  # Re-ivert file
1648  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x histstn_xt.nc ${file_out}
1649
1650  # Station re-ordering is too expansive to be run within libICGM
1651  # This is due to (ncpdq - nrcat - ncpdq) I/O sequence.
1652  # This re-ordering must be done "in memory" by the cmorization process
1653  # Anyway this is the best sequence using (ncpdq - nrcat - ncpdq)
1654  # BEGIN reordering
1655
1656  # Only LMDZ text output contains the exact ordering of the station.
1657  # We isolate this in the code below:
1658  #  0  38  -157.5000000000000  70.98591549295774
1659  #  0  54  27.49999999999999   67.18309859154928
1660  #  0  56  -62.50000000000001  82.39436619718309
1661  #  0  79  12.49999999999999   78.59154929577466
1662  #  0  116 -165.0000000000000  76.05633802816901
1663  #  0  117 130.0000000000000   70.98591549295774
1664  #  0  118 110.0000000000000   87.46478873239437
1665  #  1  40  4.999999999999995   51.97183098591550
1666#  typeset iStation iProc list_opt file_in file_out prefix_invert
1667#  typeset -Z4 j4
1668#  typeset -Z3 j3
1669
1670#  unset list_opt
1671#  set +A list_opt $@
1672
1673  # Filename after rebuild
1674#  file_out=${list_opt[0]}
1675  # Prefix of output files
1676#  prefix_invert=$( basename ${file_out} .nc )
1677  # Number of procs
1678#  num_proc=$( grep -i mpi_size ${PREFIX}_${Exe_Output} | wc -l )
1679
1680#  iProc=0
1681#  while [ ${iProc} -lt ${num_proc} ] ; do
1682    # Array containing Station as a number
1683#    unset proc_stn
1684#    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}' )
1685    # Number of stations produced by processor proc
1686#    stationLast=${#proc_stn[*]}
1687    # Proc number on 4 digits
1688#    j4=${iProc}
1689    # Init
1690#    iStation=0
1691#    while [ ${iStation} -lt ${stationLast} ] ; do
1692      # Station number on 3 digits
1693#      j3=${proc_stn[${iStation}]}
1694      # Extract station
1695      # Invert Axis : t,x -> x,t
1696      #               t,pres,x -> x,t,pres
1697      # So that we can concatenate along x
1698#      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
1699#      (( iStation = iStation + 1 ))
1700#    done
1701#    (( iProc = iProc + 1 ))
1702#  done
1703
1704  # Concatenate all station along x
1705#  IGCM_sys_ncrcat ${prefix_invert}_stn_???.nc ${prefix_invert}_xt.nc
1706
1707  # Re-invert file
1708#  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x ${prefix_invert}_xt.nc ${file_out}
1709
1710  # END reordering
1711
1712  IGCM_debug_PopStack "IGCM_sys_rebuild_station"
1713}
1714
1715############################################################
1716# Activate Running Environnment Variables
1717
1718function IGCM_sys_activ_variables {
1719  IGCM_debug_PushStack "IGCM_sys_activ_variables"
1720  if ( $DEBUG_sys ) ; then
1721    echo "IGCM_sys_activ_variables"
1722  fi
1723
1724# --------------------------------------------------------------------
1725#D- MPI specifications
1726# --------------------------------------------------------------------
1727
1728#D-- MPISUSPEND
1729  export MPISUSPEND=${MPISUSPEND:=OFF}
1730
1731#D-- MPIPROGINF #other choices : ALL_DETAIL2
1732  export MPIPROGINF=ALL
1733#D- activate ftrace (with -ftrace)
1734  export F_FTRACE=YES
1735#D- communication information (with -ftrace)
1736  export MPICOMMINF=DETAIL
1737
1738# --------------------------------------------------------------------
1739#D- Other specifications
1740# --------------------------------------------------------------------
1741
1742#D- max number of character/line in output job
1743  export F_SYSLEN=5000
1744#D- number of error that can be admitted on the NEC
1745  export F_ERRCNT=0
1746#D- global performance
1747  export F_PROGINF=DETAIL
1748
1749#D- I/O performance (FORTRAN I/O only not netCDF)
1750  export F_FILEINF=${F_FILEINF:=NO}
1751#D- netCDF I/O performance
1752  export NC_FILEINF=${NC_FILEINF:=NO}
1753
1754  IGCM_debug_PopStack "IGCM_sys_activ_variables"
1755}
1756
1757############################################################
1758# Desactivate Running Environnment Variables
1759
1760function IGCM_sys_desactiv_variables {
1761  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1762  if ( $DEBUG_sys ) ; then
1763    echo "IGCM_sys_desactiv_variables"
1764  fi
1765# --------------------------------------------------------------------
1766#D- MPI specifications
1767# --------------------------------------------------------------------
1768
1769#D-- MPIPROGINF
1770  export MPIPROGINF=NO
1771
1772# --------------------------------------------------------------------
1773#D- Other specifications
1774# --------------------------------------------------------------------
1775
1776#D- global performance
1777  export F_PROGINF=NO 
1778
1779  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1780}
1781
1782############################################################
1783# Build MPI/OMP scripts
1784function IGCM_sys_build_execution_scripts
1785{
1786  IGCM_debug_PushStack "IGCM_sys_build_execution_scripts" $@
1787  if ( $DEBUG_sys ) ; then
1788    echo "IGCM_sys_build_execution_scripts " $@
1789  fi
1790
1791  typeset NbNodes_Job NbProc_Job comp_proc_mpi_loc comp_proc_omp_loc mpi_count
1792 
1793  if [ ! -f ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} ]  ; then
1794    IGCM_debug_Exit "IGCM_sys_mercurex9 build_execution_scripts : Job_${config_UserChoices_JobName} don't exist in SUBMIT_DIR : ${SUBMIT_DIR} "
1795  fi
1796
1797  if ( ${OK_PARA_MPMD} ) ; then
1798
1799    if [ -f run_file ] ; then
1800      IGCM_sys_Rm -f run_file
1801    fi
1802    touch run_file
1803
1804    if ( ${OK_PARA_OMP} ) ; then
1805      IGCM_debug_Print 2 "Error in config.card on SX9 : OpenMP not available"
1806      exit 1
1807    else
1808# OLD :
1809#PBS -v BATCH_NUM_PROC_TOT=4
1810#PBS -l cpunum_job=${BATCH_NUM_PROC_TOT}
1811      echo "Job_${config_UserChoices_JobName} includes BATCH_NUM_PROC_TOT = \c"
1812      cat ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} | grep -- "-v *BATCH_NUM_PROC_TOT" | sed -e "s/.*BATCH_NUM_PROC_TOT *= *//" 
1813      NbProc_Job=$( cat ${SUBMIT_DIR}/Job_${config_UserChoices_JobName} | grep -- "-v *BATCH_NUM_PROC_TOT" | sed -e "s/.*BATCH_NUM_PROC_TOT *= *//" )
1814      NbProc_Job=${NbProc_Job:=0}
1815      if [ ${NbProc_Job} -eq 0 ] ; then
1816        IGCM_debug_Print 2 "Error in Job_${config_UserChoices_JobName} ressources : no BATCH_NUM_PROC_TOT defined with MPI only run."
1817        exit 1
1818      fi
1819    fi
1820
1821# run_file construction
1822
1823# Then first loop on the components for the coupler ie oasis
1824
1825### the coupler ie oasis must be the first one
1826    for comp in ${config_ListOfComponents[*]} ; do
1827     
1828      eval ExeNameIn=\${config_Executable_${comp}[0]}
1829      eval ExeNameOut=\${config_Executable_${comp}[1]}
1830     
1831      # for CPL component only
1832      if [ "X${comp}" = "XCPL" ] ; then
1833
1834        eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1835        eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1836       
1837        if ( ${OK_PARA_MPI} ) ; then
1838          echo "-p ${comp_proc_mpi_loc} -e ./${ExeNameOut}" >> run_file
1839        fi
1840      fi
1841    done
1842
1843# Then second loop on the components
1844
1845    for comp in ${config_ListOfComponents[*]} ; do
1846     
1847      eval ExeNameIn=\${config_Executable_${comp}[0]}
1848      eval ExeNameOut=\${config_Executable_${comp}[1]}
1849     
1850      # Only if we really have an executable for the component and not the coupler ie oasis:
1851      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${comp}" != "XCPL" ] ) ; then
1852
1853        eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1854        eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1855       
1856        if ( ${OK_PARA_MPI} ) ; then
1857          echo "-p ${comp_proc_mpi_loc} -e ./${ExeNameOut}" >> run_file
1858        fi
1859      fi
1860    done
1861
1862    EXECUTION="${HOST_MPIRUN_COMMAND} -f ./run_file"
1863
1864    IGCM_sys_Chmod u+x run_file
1865    if ( $DEBUG_sys ) ; then
1866      echo "run_file contains : "
1867      cat run_file
1868    fi
1869
1870  else # Only one executable. launch it.
1871
1872    for comp in ${config_ListOfComponents[*]} ; do
1873
1874      eval ExeNameIn=\${config_Executable_${comp}[0]}
1875      eval ExeNameOut=\${config_Executable_${comp}[1]}
1876
1877      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${ExeNameOut}" != "Xinca.dat" ] ) ; then
1878        EXECUTION="time mpirun -np ${BATCH_NUM_PROC_TOT} ./${ExeNameOut}"
1879      fi
1880    done
1881
1882  fi
1883
1884  IGCM_debug_Print 1 "sys mercurex9 : execution command is "
1885  IGCM_debug_Print 1 "$EXECUTION"
1886
1887  IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
1888
1889}
1890
1891function IGCM_sys_build_run_file {
1892
1893IGCM_debug_Print 3 " dummy function : IGCM_sys_build_run_file "
1894
1895}
1896
1897############################################################
1898# Check of space available on temporary filesytems
1899function IGCM_sys_check_quota {
1900  IGCM_debug_PushStack "IGCM_sys_check_quota" 
1901
1902  if ( $DEBUG_sys ) ; then
1903    echo "IGCM_sys_check_quota "
1904  fi
1905  # Limit of quota (in %)
1906  limit_quota=95
1907
1908  # Check of the volume (use of RshMaster waiting for ccc_quota command available on SX9 nodes)
1909#  volume_quota=$( IGCM_sys_RshMaster "/applications/ccc-tools/ccc_quota | grep ' scratch' | awk '{print \$2}'" )
1910#  volume_avail=$( IGCM_sys_RshMaster "/applications/ccc-tools/ccc_quota | grep ' scratch' | awk '{print \$3}'" )
1911
1912  volume_quota=$(quota -h | grep 'scratch' | awk '{print $2}')
1913  volume_avail=$(quota -h | grep 'scratch' | awk '{print $3}')
1914
1915  if ( [ ! X${volume_quota} = X ] && [ ! ${volume_quota} = "-" ] ) ; then
1916
1917    unit_quota=$( echo $volume_quota | awk '{print(substr($0, length($0), length($0)))}' )
1918    unit_avail=$( echo $volume_avail | awk '{print(substr($0, length($0), length($0)))}' )
1919
1920    if [ "${unit_quota}" = "*" ] ; then
1921        IGCM_debug_Print 1 "Please, check your quota of volume on scratch"
1922        IGCM_debug_Print 1 "More than 100% of your quota is used"
1923        IGCM_debug_Print 1 "Use the ccc_quota command to check"
1924        IGCM_debug_Print 1 "You must have more than 10% available to run"
1925        IGCM_debug_Exit "Not enough space to run ! STOP HERE"
1926        IGCM_debug_Verif_Exit
1927    fi
1928
1929    temp_avail=${volume_avail%%${unit_avail}*}
1930    temp_quota=${volume_quota%%${unit_quota}*}
1931
1932    if [ ! ${unit_avail} = ${unit_quota} ] ; then
1933
1934    # Convertion
1935      if [ ${unit_avail} = "T" ] ; then
1936          (( temp_avail = temp_avail * 1000000000000 ))
1937      elif [ ${unit_avail} = "G" ] ; then
1938          (( temp_avail = temp_avail * 1000000000 ))
1939      elif [ ${unit_avail} = "M" ] ; then
1940          (( temp_avail = temp_avail * 1000000 ))
1941      elif [ ${unit_avail} = "k" ] ; then
1942          (( temp_avail = temp_avail * 1000 ))
1943      else
1944          (( temp_avail = volume_avail ))
1945      fi
1946      if [ ${unit_quota} = "T" ] ; then
1947          (( temp_quota = temp_quota * 1000000000000 ))
1948      elif [ ${unit_quota} = "G" ] ; then
1949          (( temp_quota = temp_quota * 1000000000 ))
1950      elif [ ${unit_quota} = "M" ] ; then
1951          (( temp_quota = temp_quota * 1000000 ))
1952      elif [ ${unit_quota} = "k" ] ; then
1953          (( temp_quota = temp_quota * 1000 ))
1954      else
1955          (( temp_quota = volume_quota ))
1956      fi
1957    fi
1958
1959    quota_volume=$(echo "scale=2 ; $temp_quota/$temp_avail*100" | bc)
1960#    echo "volume ratio is " $quota_volume
1961
1962    if [ ${quota_volume} -ge ${limit_quota} ] ; then
1963      IGCM_debug_Print 1 "Please, check your quota of volume on scratch"
1964      IGCM_debug_Print 1 "${quota_volume}% of your quota is used"
1965      IGCM_debug_Print 1 "Use the ccc_quota command to check"
1966      IGCM_debug_Print 1 "You must have more than 10% available to run"
1967      IGCM_debug_Exit "Not enough space to run ! STOP HERE"
1968      IGCM_debug_Verif_Exit
1969    fi
1970
1971  fi
1972  IGCM_debug_PopStack "IGCM_sys_check_quota"
1973}
Note: See TracBrowser for help on using the repository browser.