source: tags/libIGCM_v2.0_beta4/libIGCM_sys/libIGCM_sys_mercurex9.ksh @ 1638

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