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

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