source: trunk/libIGCM/libIGCM_sys/libIGCM_sys_curie.ksh @ 708

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