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

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