source: tags/libIGCM_v2.0_beta4/libIGCM_sys/libIGCM_sys_curie.ksh

Last change on this file 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: 59.1 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 -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 RET
1012
1013    # Only if we use rsync
1014    #IGCM_sys_TestDirArchive $( dirname $2 )
1015    #
1016    #USUAL WAY
1017    # add get (to demigrate all offline files) to reduce time of this command :
1018    ccc_hsm get $1/*
1019    \cp -r $1 $2 > out_rsync 2>&1
1020    RET=$?
1021
1022    if [ ${RET} -gt 0 ] ; then
1023      echo "IGCM_sys_Get_Dir : error."
1024      cat out_rsync
1025      IGCM_debug_Exit "IGCM_sys_Get_Dir"
1026    else
1027      \rm out_rsync
1028    fi
1029  else
1030    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1031  fi
1032  IGCM_debug_PopStack "IGCM_sys_Get_Dir"
1033}
1034
1035#D-#==================================================
1036#D-function IGCM_sys_Get_Master
1037#D-* Purpose: Copy a complete directory from MASTER filesystem
1038#D-* Examples:
1039#D-
1040function IGCM_sys_Get_Master {
1041  IGCM_debug_PushStack "IGCM_sys_Get_Master" $@
1042  if ( $DEBUG_sys ) ; then
1043    echo "IGCM_sys_Get_Master :" $@
1044  fi
1045  if [ $DRYRUN = 0 ]; then
1046    if ( [ ! -d ${1} ] && [ ! -f ${1} ] ) ; then
1047      echo "WARNING : IGCM_sys_Get_Master ${1} DOES NOT EXIST ."
1048      IGCM_debug_PopStack "IGCM_sys_Get_Master"
1049      return
1050    fi
1051
1052    typeset RET
1053
1054    #USUAL WAY
1055    \cp -rL $1 $2 > out_rsync 2>&1
1056    RET=$?
1057
1058    if [ ${RET} -gt 0 ] ; then
1059      echo "IGCM_sys_Get_Master : error."
1060      cat out_rsync
1061      IGCM_debug_Exit "IGCM_sys_Get_Master"
1062    else
1063      \rm out_rsync
1064    fi
1065  else
1066    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1067  fi
1068  IGCM_debug_PopStack "IGCM_sys_Get_Master"
1069}
1070
1071#====================================================
1072#- Call IGCM_sys_Mirror_libIGCM now !
1073if ( $MirrorlibIGCM ) ; then
1074  IGCM_sys_Mirror_libIGCM
1075fi
1076
1077#D-#==================================================
1078#D-function IGCM_sys_Put_Rest
1079#D-* Purpose: Put computied restarts on ${ARCHIVE}.
1080#D-           File and target directory must exist.
1081#D-* Examples:
1082#D-
1083function IGCM_sys_Put_Rest {
1084  IGCM_debug_PushStack "IGCM_sys_Put_Rest" $@
1085  if ( $DEBUG_sys ) ; then
1086    echo "IGCM_sys_Put_Rest :" $@
1087  fi
1088  if [ $DRYRUN = 0 ]; then
1089    if [ ! -f ${1} ] ; then
1090      echo "ERROR : IGCM_sys_Put_Rest ${1} DOES NOT EXIST ."
1091      IGCM_debug_Exit "IGCM_sys_Put_Rest"
1092    fi
1093
1094    typeset RET
1095    #
1096    if [ X${JobType} = XRUN ] ; then
1097      IGCM_sys_Chmod 444 ${1}
1098    fi
1099
1100    #
1101    # USUAL WAY
1102    \cp $1 $2 > out_rsync 2>&1
1103    RET=$?
1104
1105#       #RSYNC WITH NETWORK SSH CALL
1106#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > out_rsync 2>&1
1107#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> out_rsync 2>&1
1108
1109#       #RSYNC WITH NFS USE
1110#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
1111#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
1112
1113#       RET=$?
1114#       IGCM_sys_Rsync_out $RET
1115
1116#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1117#       (( RET=RET+$? ))
1118
1119    if [ ${RET} -gt 0 ] ; then
1120      echo "IGCM_sys_Put_Rest : error."
1121      cat out_rsync
1122      IGCM_debug_Exit "IGCM_sys_Put_Rest"
1123    else
1124      \rm out_rsync
1125    fi
1126  else
1127    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1128  fi
1129  IGCM_debug_PopStack "IGCM_sys_Put_Rest"
1130}
1131
1132#D-#==================================================
1133#D-function IGCM_sys_PutBuffer_Rest
1134#D-* Purpose: Put computied restarts on ${SCRATCHDIR}.
1135#D-           File and target directory must exist.
1136#D-* Examples:
1137#D-
1138function IGCM_sys_PutBuffer_Rest {
1139  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Rest" $@
1140  if ( $DEBUG_sys ) ; then
1141    echo "IGCM_sys_PutBuffer_Rest :" $@
1142  fi
1143  if [ $DRYRUN = 0 ]; then
1144    if [ ! -f ${1} ] ; then
1145      echo "ERROR : IGCM_sys_PutBuffer_Rest ${1} DOES NOT EXIST ."
1146      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
1147    fi
1148
1149    typeset RET
1150    #
1151    if [ X${JobType} = XRUN ] ; then
1152      IGCM_sys_Chmod 444 ${1}
1153    fi
1154
1155    #
1156    # USUAL WAY
1157    \cp $1 $2 > out_rsync 2>&1
1158    RET=$?
1159
1160    if [ ${RET} -gt 0 ] ; then
1161      echo "IGCM_sys_PutBuffer_Rest : error."
1162      cat out_rsync
1163      IGCM_debug_Exit "IGCM_sys_PutBuffer_Rest"
1164    else
1165      \rm out_rsync
1166    fi
1167  else
1168    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1169  fi
1170  IGCM_debug_PopStack "IGCM_sys_PutBuffer_Rest"
1171}
1172
1173#D-#==================================================
1174#D-function IGCM_sys_Put_Out
1175#D-* Purpose: Copy a file on ${ARCHIVE} after having chmod it in readonly
1176#D-* Examples:
1177#D-
1178function IGCM_sys_Put_Out {
1179  IGCM_debug_PushStack "IGCM_sys_Put_Out" $@
1180  if ( $DEBUG_sys ) ; then
1181    echo "IGCM_sys_Put_Out :" $@
1182  fi
1183
1184  typeset NB_ESSAI DELAI RET i
1185
1186  # number of tentative
1187  NB_ESSAI=3
1188  # time delay between tentative
1189  DELAI=2
1190
1191  if [ $DRYRUN = 0 ]; then
1192    if [ ! -f ${1} ] ; then
1193      echo "WARNING : IGCM_sys_Put_Out ${1} DOES NOT EXIST ."
1194      IGCM_debug_PopStack "IGCM_sys_Put_Out"
1195      return 1
1196    fi
1197    #
1198    IGCM_sys_MkdirArchive $( dirname $2 )
1199    #
1200
1201    #=====================================================
1202    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1203    #=====================================================
1204
1205    #echo ${2} | grep "${R_OUT}" > /dev/null 2>&1
1206    #if [ $? -eq 0 ] ; then
1207    #    typeset WORKPATH FILEPATH
1208    #    WORKPATH=$( dirname $2 | sed -e "s|${R_OUT}|${R_BUF}|" )
1209    #    IGCM_sys_MkdirWork ${WORKPATH}
1210    #    FILEPATH=${WORKPATH}/$( basename $2 )
1211    #    #
1212    #    IGCM_sys_Cp ${1} ${FILEPATH}
1213    #fi
1214
1215    if [ X${JobType} = XRUN ] ; then
1216      if [ X${3} = X ] ; then
1217        IGCM_sys_Chmod 444 ${1}
1218      fi
1219    fi
1220    #
1221
1222    (( i = 0 ))
1223    while [ $i -lt $NB_ESSAI ] ; do
1224    # USUAL WAY
1225      \cp $1 $2 > out_rsync 2>&1
1226      RET=$?
1227      if [ ${RET} -gt 0 ]; then
1228        IGCM_debug_Print 2 "IGCM_sys_Put_Out : cp failed ${i}/${NB_ESSAI}"
1229        IGCM_debug_Print 2 "IGCM_sys_Put_Out : sleep ${DELAI} seconds and try again."
1230        sleep $DELAI
1231      else
1232        break
1233      fi
1234      (( i = i + 1 ))
1235    done
1236
1237#       #RSYNC WITH NETWORK SSH CALL
1238#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} > out_rsync 2>&1
1239#       ${RSYNC} ${RSYNC_opt} -e ssh ${RUN_DIR}/$1 ${STOREHOST}:${2} >> out_rsync 2>&1
1240
1241#       #RSYNC WITH NFS USE
1242#       echo ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} > out_rsync 2>&1
1243#       ${RSYNC} ${RSYNC_opt} ${RUN_DIR}/$1 ${2} >> out_rsync 2>&1
1244
1245#       RET=$?
1246#       IGCM_sys_Rsync_out $RET
1247
1248#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1249#       (( RET=RET+$? ))
1250
1251    if [ ${RET} -gt 0 ] ; then
1252      echo "IGCM_sys_Put_Out : error."
1253      cat out_rsync
1254      IGCM_debug_Exit "IGCM_sys_Put_Out"
1255    else
1256      \rm out_rsync
1257    fi
1258  else
1259    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1260  fi
1261  IGCM_debug_PopStack "IGCM_sys_Put_Out"
1262  return 0
1263}
1264
1265#D-#==================================================
1266#D-function IGCM_sys_PutBuffer_Out
1267#D-* Purpose: Copy a file on ${SCRATCHDIR} after having chmod it in readonly
1268#D-* Examples:
1269#D-
1270function IGCM_sys_PutBuffer_Out {
1271  IGCM_debug_PushStack "IGCM_sys_PutBuffer_Out" $@
1272  if ( $DEBUG_sys ) ; then
1273    echo "IGCM_sys_PutBuffer_Out :" $@
1274  fi
1275  if [ $DRYRUN = 0 ]; then
1276    if [ ! -f ${1} ] ; then
1277      echo "WARNING : IGCM_sys_PutBuffer_Out ${1} DOES NOT EXIST ."
1278      IGCM_debug_PopStack "IGCM_sys_PutBuffer_Out"
1279      return 1
1280    fi
1281    #
1282    IGCM_sys_Mkdir $( dirname $2 )
1283    #
1284    typeset RET
1285
1286    if [ X${JobType} = XRUN ] ; then
1287      if [ X${3} = X ] ; then
1288        IGCM_sys_Chmod 444 ${1}
1289      fi
1290    fi
1291    #
1292    # USUAL WAY
1293    \cp $1 $2 > out_rsync 2>&1
1294    RET=$?
1295
1296    if [ ${RET} -gt 0 ] ; then
1297      echo "IGCM_sys_PutBuffer_Out : error."
1298      cat out_rsync
1299      IGCM_debug_Exit "IGCM_sys_PutBuffer_Out"
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_PutBuffer_Out"
1307  return 0
1308}
1309
1310#D-#==================================================
1311#D-function IGCM_sys_Get
1312#D-* Purpose: Get a file from ${ARCHIVE}
1313#D-* Examples: IGCM_sys_Get myfile /destpath/myfile_with_PREFIX
1314#D-            IGCM_sys_Get /l Array_contain_myfiles /destpath/
1315function IGCM_sys_Get {
1316  IGCM_debug_PushStack "IGCM_sys_Get" $@
1317
1318  typeset DEST RET dm_liste ifile target file_work
1319  typeset NB_ESSAI DELAI status i
1320
1321  if ( $DEBUG_sys ) ; then
1322    echo "IGCM_sys_Get :" $@
1323  fi
1324
1325  # number of tentative
1326  NB_ESSAI=3
1327  # time delay between tentative
1328  DELAI=2
1329
1330  if [ $DRYRUN -le 2 ]; then
1331    if [ X${1} = X'/l' ] ; then
1332      # test if the first file is present in the old computation :
1333      eval set +A dm_liste \${${2}}
1334    else
1335      eval set +A dm_liste ${1}
1336    fi
1337    eval DEST=\${${#}}
1338
1339    #=====================================================
1340    #         COMMENT OUT DOUBLE COPY ON SCRATCHDIR
1341    #=====================================================
1342
1343    # Is it an R_OUT file (not R_IN) ?
1344    #echo ${dm_liste[0]} | grep "${R_OUT}" > /dev/null 2>&1
1345    #if [ $? -eq 0 ] ; then
1346    #    # Yes  ? then we try to get it in SCRATCHDIR
1347    #    set +A file_work $( echo ${dm_liste[*]} | sed -e "s|${R_OUT}|${R_BUF}|g" )
1348    #    if [ -f ${file_work[0]} ] ; then
1349    #   IGCM_sys_Cp ${file_work[*]} ${DEST}
1350    #   IGCM_debug_PopStack "IGCM_sys_Get"
1351    #   return
1352    #    fi
1353    #fi
1354
1355    ccc_hsm get ${dm_liste[*]} > out_rsync 2>&1
1356    RET=$?
1357    if [ ${RET} -gt 0 ] ; then
1358      echo "WARNING IGCM_sys_Get : demigration error."
1359      cat out_rsync
1360      echo "WARNING IGCM_sys_Get : will stop later if the cp fails."
1361    fi
1362
1363    #if [ ${RET} -gt 0 ] ; then
1364    #    if [ ! "X$( grep "Lost dmusrcmd connection" out_rsync )" = "X" ] ; then
1365    #   cat out_rsync
1366    #   echo "WARNING IGCM_sys_Get : Lost dmusrcmd connection : "
1367    #   sleep 30
1368    #   echo "We try another time"
1369    ##  dmget ${dm_liste[*]} > out_rsync 2>&1
1370    #   ccc_hsm get ${dm_liste[*]} > out_rsync 2>&1
1371    #   RET=$?
1372    #   if [ ${RET} -gt 0 ] ; then
1373    #       echo "ERROR IGCM_sys_Get : again demigration error :"
1374    #       cat out_rsync
1375    #       IGCM_debug_Exit "IGCM_sys_Get"
1376    #   fi
1377    #    else
1378    #   echo "ERROR IGCM_sys_Get : demigration error :"
1379    #   cat out_rsync
1380    #   IGCM_debug_Exit "IGCM_sys_Get"
1381    #    fi
1382    #fi
1383
1384    #USUAL WAY
1385    if [ X${1} = X'/l' ] ; then
1386      (( RET=0 ))
1387      for target in ${dm_liste[*]} ; do
1388        local_file=$( basename ${target} )
1389        (( i = 0 ))
1390        # test if the target file is present before the loop
1391        IGCM_sys_TestFileArchive ${target}
1392        RET=$?
1393        if [ ${RET} -gt 0 ] ; then
1394          echo "IGCM_sys_Get, ERROR : regular file ${dm_liste[0]} DOES NOT EXIST ."
1395          IGCM_debug_Exit "IGCM_sys_Get"
1396        else
1397          while [ $i -lt $NB_ESSAI ] ; do
1398            \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1399            status=$?
1400            if [ ${status} -gt 0 ]; then
1401              IGCM_debug_Print 2 "IGCM_sys_Get : cp failed ${i}/${NB_ESSAI}"
1402              IGCM_debug_Print 2 "IGCM_sys_Get : sleep ${DELAI} seconds and try again."
1403              sleep $DELAI
1404            else
1405              break
1406            fi
1407            (( i = i + 1 ))
1408          done
1409          (( RET = RET + status ))
1410        fi
1411      done
1412    else
1413      \cp ${dm_liste} ${DEST} >> out_rsync 2>&1
1414      RET=$?
1415    fi
1416
1417#       #RSYNC WITH NETWORK SSH CALL
1418#       echo ${RSYNC} ${RSYNC_opt} -e ssh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} > out_rsync 2>&1
1419#       ${RSYNC} ${RSYNC_opt} -e ssh ${STOREHOST}:"${dm_liste}" ${STOREHOST}:${RUN_DIR}/${DEST} >> out_rsync 2>&1
1420
1421#       #RSYNC WITH NFS USE
1422#       echo ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} > out_rsync 2>&1
1423#       ${RSYNC} ${RSYNC_opt} ${dm_liste} ${RUN_DIR}/${DEST} >> out_rsync 2>&1
1424
1425#       RET=$?
1426#       IGCM_sys_Rsync_out $RET
1427
1428#       ${libIGCM}/libIGCM_sys/IGCM_analyse_rsync_out.awk out_rsync
1429#       (( RET=RET+$? ))
1430
1431    if [ ${RET} -gt 0 ] ; then
1432      echo "IGCM_sys_Get : copy error."
1433      cat out_rsync
1434      IGCM_debug_Exit "IGCM_sys_Get"
1435    else
1436      \rm out_rsync
1437    fi
1438  else
1439    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1440  fi
1441  IGCM_debug_PopStack "IGCM_sys_Get"
1442}
1443
1444#D-#==================================================
1445#D-function IGCM_sys_GetBuffer
1446#D-* Purpose: Get a file from ${SCRATCHDIR}
1447#D-* Examples: IGCM_sys_GetBuffer myfile /destpath/myfile_with_PREFIX
1448#D-            IGCM_sys_GetBuffer /l Array_contain_myfiles /destpath/
1449function IGCM_sys_GetBuffer {
1450  IGCM_debug_PushStack "IGCM_sys_GetBuffer" $@
1451
1452  typeset DEST RET buf_liste ifile target file_work
1453
1454  if ( $DEBUG_sys ) ; then
1455    echo "IGCM_sys_GetBuffer :" $@
1456  fi
1457  if [ $DRYRUN -le 2 ]; then
1458    if [ X${1} = X'/l' ] ; then
1459      # test if the first file is present in the old computation :
1460      eval set +A buf_liste \${${2}}
1461    else
1462      eval set +A buf_liste ${1}
1463    fi
1464    eval DEST=\${${#}}
1465
1466    #USUAL WAY
1467    if [ X${1} = X'/l' ] ; then
1468      (( RET=0 ))
1469      for target in ${buf_liste[*]} ; do
1470        local_file=$( basename ${target} )
1471        \cp ${target} ${DEST}/${local_file} >> out_rsync 2>&1
1472        (( RET = RET + $? ))
1473      done
1474    else
1475      \cp ${buf_liste} ${DEST} >> out_rsync 2>&1
1476      RET=$?
1477    fi
1478
1479    if [ ${RET} -gt 0 ] ; then
1480      echo "IGCM_sys_GetBuffer : copy error."
1481      cat out_rsync
1482      IGCM_debug_Exit "IGCM_sys_GetBuffer"
1483    else
1484      \rm out_rsync
1485    fi
1486  else
1487    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1488  fi
1489  IGCM_debug_PopStack "IGCM_sys_GetBuffer"
1490}
1491
1492#D-#==================================================
1493#D-function IGCM_sys_GetDate_FichWork
1494#D-* Purpose: donne la date filesys d'un fichier sur le filesystem WORK
1495#D-* Examples:
1496#D-
1497function IGCM_sys_GetDate_FichWork {
1498  IGCM_debug_PushStack "IGCM_sys_FichWork" $@
1499  if ( $DEBUG_sys ) ; then
1500    echo "IGCM_sys_GetDate_FichWork :" $@
1501  fi
1502  typeset dateF
1503  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1504  eval ${2}=${dateF[5]}
1505
1506    # donne la date filesys d'un fichier sur la machine work
1507  IGCM_debug_PopStack "IGCM_sys_FichWork"
1508}
1509
1510#D-#==================================================
1511#D-function IGCM_sys_GetDate_FichArchive
1512#D-* Purpose: donne la date filesys d'un fichier sur le filesystem ARCHIVE
1513#D-* Examples:
1514#D-
1515function IGCM_sys_GetDate_FichArchive {
1516  IGCM_debug_PushStack "IGCM_sys_FichArchive" $@
1517  if ( $DEBUG_sys ) ; then
1518    echo "IGCM_sys_GetDate_FichArchive :" $@
1519  fi
1520  typeset dateF
1521  set +A dateF -- $( ls -l --full-time --time-style='+%Y%m%d%H%M%S' ${1} )
1522  eval ${2}=${dateF[5]}
1523
1524  IGCM_debug_PopStack "IGCM_sys_FichArchive"
1525}
1526
1527#D-#==================================================
1528#D-function IGCM_sys_Dods_Rm
1529#D-* Purpose: DO NOTHING ! Put ${ARCHIVE} files on DODS internet protocole.
1530#D-* Examples:
1531#D-
1532function IGCM_sys_Dods_Rm {
1533  if ( $DEBUG_sys ) ; then
1534    echo "IGCM_sys_Dods_Rm :" $@
1535  fi
1536  typeset RET
1537  RET=0
1538  if [ $DRYRUN = 0 ]; then
1539
1540#    if [ ! -d /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} ] ; then
1541#      echo "WARNING : IGCM_sys_Dods_Rm /dmnfs/cont003/dods/public/${LOGIN}/${R_DODS}/${1} DOES NOT EXIST ."
1542#      echo "Nothing has been done."
1543#      return
1544#    fi
1545
1546    /ccc/cont003/home/dsm/p86ipsl/bin/dods_rm public/${LOGIN}/${R_DODS}/${1} # > out_dods_rm 2>&1
1547    RET=$?
1548
1549#       if [ ${RET} -gt 0 ] ; then
1550#           echo "IGCM_sys_Dods_Rm : error."
1551#           cat out_dods_rm
1552#           IGCM_debug_Exit "IGCM_sys_Dods_Rm"
1553#       else
1554#           rm out_dods_rm
1555#       fi
1556
1557  else
1558    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1559  fi
1560  return $RET
1561}
1562
1563#D-#==================================================
1564#D-function IGCM_sys_Dods_Cp
1565#D-* Purpose: Copy $(ARCHIVE) files on DODS internet protocole.
1566#D-* Examples:
1567#D-
1568function IGCM_sys_Dods_Cp {
1569  if ( $DEBUG_sys ) ; then
1570    echo "IGCM_sys_Dods_Cp :" $@
1571  fi
1572  typeset RET
1573  RET=0
1574  if [ $DRYRUN = 0 ]; then
1575
1576#    if [ ! -d ${R_SAVE}/${1} ] ; then
1577#      echo "WARNING : IGCM_sys_Dods_Cp ${R_SAVE}/${1} DOES NOT EXIST ."
1578#      echo "Nothing has been done."
1579#      return
1580#    fi
1581
1582    /ccc/cont003/home/dsm/p86ipsl/bin/dods_cp ${1} public/${LOGIN}/${R_DODS} # > out_dods_cp 2>&1
1583    RET=$?
1584
1585#       if [ ${RET} -gt 0 ] ; then
1586#           echo "IGCM_sys_Dods_Cp : error."
1587#           cat out_dods_cp
1588#           IGCM_debug_Exit "IGCM_sys_Dods_Cp"
1589#       else
1590#           rm out_dods_cp
1591#       fi
1592
1593  else
1594    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1595  fi
1596  return $RET
1597}
1598
1599#D-#==================================================
1600#D-function IGCM_sys_Put_Dods
1601#D-* Purpose: Put $(ARCHIVE) files on DODS internet protocole.
1602#D-* Examples:
1603#D-
1604function IGCM_sys_Put_Dods {
1605  IGCM_debug_PushStack "IGCM_sys_Put_Dods" $@
1606  if ( $DEBUG_sys ) ; then
1607    echo "IGCM_sys_Put_Dods :" $@
1608  fi
1609  set -vx
1610  typeset RET
1611  if [ $DRYRUN = 0 ]; then
1612    if ( [ ! -d ${R_SAVE}/${1} ] && [ ! -d ${R_FIGR}/${1} ] ) ; then
1613      echo "WARNING IGCM_sys_Put_Dods : None of the following directories exist. Exactly one should."
1614      echo "WARNING IGCM_sys_Put_Dods : ${R_SAVE}/${1} DOES NOT EXIST."
1615      echo "WARNING IGCM_sys_Put_Dods : ${R_FIGR}/${1} DOES NOT EXIST."
1616      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1617      return
1618    fi
1619
1620    if ( [ -d ${R_SAVE}/${1} ] && [ -d ${R_FIGR}/${1} ] ) ; then
1621      echo "WARNING IGCM_sys_Put_Dods : Both of the following directories exist. Exactly one should."
1622      echo "WARNING IGCM_sys_Put_Dods : ${R_SAVE}/${1} EXISTS."
1623      echo "WARNING IGCM_sys_Put_Dods : ${R_FIGR}/${1} EXISTS."
1624      IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1625      return
1626    fi
1627    #
1628    if [ -d ${R_SAVE}/${1} ] ; then
1629      cd ${R_SAVE}
1630    elif [ -d ${R_FIGR}/${1} ] ; then
1631      cd ${R_FIGR}
1632    fi
1633
1634    IGCM_sys_Dods_Rm ${1}
1635    IGCM_sys_Dods_Cp ${1}
1636    RET=0
1637
1638    if [ ${RET} -gt 0 ] ; then
1639      echo "IGCM_sys_Put_Dods : error."
1640      IGCM_debug_Exit "IGCM_sys_Put_Dods"
1641    fi
1642  else
1643    ( ${DEBUG_debug} ) && echo "DRYRUN mode = " $DRYRUN >> stack
1644  fi
1645  IGCM_debug_PopStack "IGCM_sys_Put_Dods"
1646}
1647
1648##############################################################
1649# REBUILD OPERATOR
1650
1651function IGCM_sys_rebuild {
1652  IGCM_debug_PushStack "IGCM_sys_rebuild" -- $@
1653  if ( $DEBUG_sys ) ; then
1654    echo "IGCM_sys_rebuild :" $@
1655  fi
1656  ~p86ipsl/CESIUM/bin/rebuild -f -o $@
1657  if [ $? -gt 0 ] ; then
1658    echo "IGCM_sys_rebuild : erreur ${@}."
1659    IGCM_debug_Exit "rebuild"
1660  fi
1661
1662  IGCM_debug_PopStack "IGCM_sys_rebuild"
1663}
1664
1665function IGCM_sys_rebuild_station {
1666  IGCM_debug_PushStack "IGCM_sys_rebuild_station" -- $@
1667  typeset i list_opt file_in file_out prefix_invert list_invert
1668  if ( $DEBUG_sys ) ; then
1669    echo "IGCM_sys_rebuild_station :" $@
1670  fi
1671  list_opt=$@
1672
1673  # Invert Axis : t,x -> x,t
1674  #               t,pres,x -> x,t,pres
1675  # So that we can concatenate along x
1676  i=0
1677  for file_in in ${list_opt} ; do
1678    (( i = i + 1))
1679    [ ${i} = 1 ] && file_out=${file_in} && continue
1680    prefix_invert=$( basename ${file_in} .nc )
1681    IGCM_sys_ncpdq -a x,time_counter -a x,time_counter,presnivs ${file_in} ${prefix_invert}_xt.nc
1682    list_invert[${#list_invert[*]}]=${prefix_invert}_xt.nc
1683  done
1684
1685  # Concatenate
1686  IGCM_sys_ncrcat ${list_invert[*]} histstn_xt.nc
1687
1688  # Re-ivert file
1689  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x histstn_xt.nc ${file_out}
1690
1691  # Station re-ordering is too expansive to be run within libICGM
1692  # This is due to (ncpdq - nrcat - ncpdq) I/O sequence.
1693  # This re-ordering must be done "in memory" by the cmorization process
1694  # Anyway this is the best sequence using (ncpdq - nrcat - ncpdq)
1695  # BEGIN reordering
1696
1697  # Only LMDZ text output contains the exact ordering of the station.
1698  # We isolate this in the code below:
1699  #  0  38  -157.5000000000000  70.98591549295774
1700  #  0  54  27.49999999999999   67.18309859154928
1701  #  0  56  -62.50000000000001  82.39436619718309
1702  #  0  79  12.49999999999999   78.59154929577466
1703  #  0  116 -165.0000000000000  76.05633802816901
1704  #  0  117 130.0000000000000   70.98591549295774
1705  #  0  118 110.0000000000000   87.46478873239437
1706  #  1  40  4.999999999999995   51.97183098591550
1707#  typeset iStation iProc list_opt file_in file_out prefix_invert
1708#  typeset -Z4 j4
1709#  typeset -Z3 j3
1710
1711#  unset list_opt
1712#  set +A list_opt $@
1713
1714  # Filename after rebuild
1715#  file_out=${list_opt[0]}
1716  # Prefix of output files
1717#  prefix_invert=$( basename ${file_out} .nc )
1718  # Number of procs
1719#  num_proc=$( grep -i mpi_size ${PREFIX}_${Exe_Output} | wc -l )
1720
1721#  iProc=0
1722#  while [ ${iProc} -lt ${num_proc} ] ; do
1723    # Array containing Station as a number
1724#    unset proc_stn
1725#    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}' )
1726    # Number of stations produced by processor proc
1727#    stationLast=${#proc_stn[*]}
1728    # Proc number on 4 digits
1729#    j4=${iProc}
1730    # Init
1731#    iStation=0
1732#    while [ ${iStation} -lt ${stationLast} ] ; do
1733      # Station number on 3 digits
1734#      j3=${proc_stn[${iStation}]}
1735      # Extract station
1736      # Invert Axis : t,x -> x,t
1737      #               t,pres,x -> x,t,pres
1738      # So that we can concatenate along x
1739#      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
1740#      (( iStation = iStation + 1 ))
1741#    done
1742#    (( iProc = iProc + 1 ))
1743#  done
1744
1745  # Concatenate all station along x
1746#  IGCM_sys_ncrcat ${prefix_invert}_stn_???.nc ${prefix_invert}_xt.nc
1747
1748  # Re-invert file
1749#  IGCM_sys_ncpdq -a time_counter,x -a time_counter,presnivs,x ${prefix_invert}_xt.nc ${file_out}
1750
1751  # END reordering
1752
1753  IGCM_debug_PopStack "IGCM_sys_rebuild_station"
1754}
1755
1756############################################################
1757# Activate Running Environnment Variables
1758
1759function IGCM_sys_activ_variables {
1760  IGCM_debug_PushStack "IGCM_sys_activ_variables"
1761  if ( $DEBUG_sys ) ; then
1762    echo "IGCM_sys_activ_variables"
1763  fi
1764
1765  ulimit -s unlimited
1766
1767  IGCM_debug_PopStack "IGCM_sys_activ_variables"
1768}
1769
1770############################################################
1771# Desactivate Running Environnment Variables
1772
1773function IGCM_sys_desactiv_variables {
1774  IGCM_debug_PushStack "IGCM_sys_desactiv_variables"
1775  if ( $DEBUG_sys ) ; then
1776    echo "IGCM_sys_desactiv_variables"
1777  fi
1778  IGCM_debug_PopStack "IGCM_sys_desactiv_variables"
1779}
1780
1781############################################################
1782# Build MPI/OMP scripts run file (dummy function)
1783
1784function IGCM_sys_build_run_file {
1785
1786IGCM_debug_Print 3 " dummy function : IGCM_sys_build_run_file "
1787
1788}
1789
1790############################################################
1791# Build MPI/OMP scripts
1792function IGCM_sys_build_execution_scripts
1793{
1794  IGCM_debug_PushStack "IGCM_sys_build_execution_scripts" $@
1795  if ( $DEBUG_sys ) ; then
1796    echo "IGCM_sys_build_execution_scripts " $@
1797  fi
1798
1799    # Verification with MSUB parameter
1800  EXECUTION=${HOST_MPIRUN_COMMAND}
1801
1802  if ( ${OK_PARA_MPMD} ) ; then
1803
1804    if [ -f run_file ] ; then
1805      IGCM_sys_Rm -f run_file
1806    fi
1807    touch run_file
1808
1809# run_file construction
1810
1811# Then first loop on the components for the coupler ie oasis
1812
1813### the coupler ie oasis must be the first one
1814    for comp in ${config_ListOfComponents[*]} ; do
1815
1816      eval ExeNameIn=\${config_Executable_${comp}[0]}
1817      eval ExeNameOut=\${config_Executable_${comp}[1]}
1818
1819        # for CPL component only
1820      if [ "X${comp}" = "XCPL" ] ; then
1821
1822        eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1823        eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1824        echo "${comp_proc_mpi_loc} ./${ExeNameOut}" >> run_file
1825      fi
1826    done
1827
1828# Then second loop on the components
1829
1830    for comp in ${config_ListOfComponents[*]} ; do
1831
1832      eval ExeNameIn=\${config_Executable_${comp}[0]}
1833      eval ExeNameOut=\${config_Executable_${comp}[1]}
1834
1835        # Only if we really have an executable for the component and not the coupler ie oasis:
1836      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${comp}" != "XCPL" ] ) ; then
1837
1838        eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1839        eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1840        echo "${comp_proc_mpi_loc} ./${ExeNameOut}" >> run_file
1841      fi
1842    done
1843
1844    EXECUTION="${HOST_MPIRUN_COMMAND} -f ./run_file"
1845
1846    IGCM_sys_Chmod u+x run_file
1847    if ( $DEBUG_sys ) ; then
1848      echo "run_file contains : "
1849      cat run_file
1850    fi
1851
1852  else # Only one executable. launch it.
1853
1854    #
1855    for comp in ${config_ListOfComponents[*]} ; do
1856
1857      # Only if we really have an executable for the component :
1858      eval ExeNameOut=\${config_Executable_${comp}[1]}
1859      if ( [ "X${ExeNameOut}" != X\"\" ] && [ "X${ExeNameOut}" != "Xinca.dat" ] ) ; then
1860
1861        echo "#!/bin/ksh" > script_${ExeNameOut}.ksh
1862        echo ""  >> script_${ExeNameOut}.ksh
1863        IGCM_sys_Chmod u+x script_${ExeNameOut}.ksh
1864
1865        if ( ${OK_PARA_OMP} ) ; then
1866          eval comp_proc_omp_loc=\${${comp}_PROC_OMP}
1867          echo ""  >> script_${ExeNameOut}.ksh
1868          echo "export KMP_STACKSIZE=3g"  >> script_${ExeNameOut}.ksh
1869          echo "export KMP_LIBRARY=turnaround"  >> script_${ExeNameOut}.ksh
1870          echo "export MKL_SERIAL=YES"  >> script_${ExeNameOut}.ksh
1871          echo "OMP_NUM_THREADS=${comp_proc_omp_loc}" >> script_${ExeNameOut}.ksh
1872        fi
1873
1874        if  ( ${OK_PARA_MPI} ) ; then
1875          eval comp_proc_mpi_loc=\${${comp}_PROC_MPI}
1876          # Default : ccc_mprun used if nb_proc gt 1
1877          # to have out/err per process on different files
1878          # echo "./${ExeNameOut} > out_${ExeNameOut}.out.\${SLURM_PROCID} 2>out_${ExeNameOut}.err.\${SLURM_PROCID}"  >> script_${ExeNameOut}.ksh
1879          echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1880          EXECUTION="${HOST_MPIRUN_COMMAND} -n ${comp_proc_mpi_loc} ./script_${ExeNameOut}.ksh"
1881        else
1882          # Default : ccc_mprun is NOT used if nb_proc eq 1
1883          # to have out/err per process on different files
1884          # echo "./${ExeNameOut} > out_${ExeNameOut}.out 2>out_${ExeNameOut}.err" >> script_${ExeNameOut}.ksh
1885          echo "./${ExeNameOut}" >> script_${ExeNameOut}.ksh
1886          EXECUTION="/usr/bin/time ./script_${ExeNameOut}.ksh"
1887        fi
1888
1889        IGCM_debug_Print 1 "sys Curie : script_${ExeNameOut}.ksh contains"
1890        cat script_${ExeNameOut}.ksh
1891
1892      fi
1893
1894    done
1895
1896  fi
1897
1898  IGCM_debug_Print 1 "sys Curie : execution command is "
1899  IGCM_debug_Print 1 "$EXECUTION"
1900
1901  IGCM_debug_PopStack "IGCM_sys_build_execution_scripts"
1902}
1903
1904##############################################################
1905# NCO OPERATOR
1906
1907function IGCM_sys_ncap2 {
1908  IGCM_debug_PushStack "IGCM_sys_ncap2" -- $@
1909  if ( $DEBUG_sys ) ; then
1910    echo "IGCM_sys_ncap2 :" $@
1911  fi
1912  ncap2 "$@"
1913  if [ $? -gt 0 ] ; then
1914    echo "IGCM_sys_ncap2 : erreur ${@}."
1915    IGCM_debug_Exit "ncap2"
1916  fi
1917
1918  IGCM_debug_PopStack "IGCM_sys_ncap2"
1919}
1920
1921function IGCM_sys_ncatted {
1922  IGCM_debug_PushStack "IGCM_sys_ncatted" -- $@
1923  if ( $DEBUG_sys ) ; then
1924    echo "IGCM_sys_ncatted :" $@
1925  fi
1926  ncatted "$@"
1927  if [ $? -gt 0 ] ; then
1928    echo "IGCM_sys_ncatted : erreur ${@}."
1929    IGCM_debug_Exit "ncatted"
1930  fi
1931
1932  IGCM_debug_PopStack "IGCM_sys_ncatted"
1933}
1934
1935function IGCM_sys_ncbo {
1936  IGCM_debug_PushStack "IGCM_sys_ncbo" -- $@
1937  if ( $DEBUG_sys ) ; then
1938    echo "IGCM_sys_ncbo :" $@
1939  fi
1940  ncbo $@
1941  if [ $? -gt 0 ] ; then
1942    echo "IGCM_sys_ncbo : erreur ${@}."
1943    IGCM_debug_Exit "ncbo"
1944  fi
1945
1946  IGCM_debug_PopStack "IGCM_sys_ncbo"
1947}
1948
1949function IGCM_sys_ncdiff {
1950  IGCM_debug_PushStack "IGCM_sys_ncdiff" -- $@
1951  if ( $DEBUG_sys ) ; then
1952    echo "IGCM_sys_ncdiff :" $@
1953  fi
1954  ncdiff $@
1955  if [ $? -gt 0 ] ; then
1956    echo "IGCM_sys_ncdiff : erreur ${@}."
1957    IGCM_debug_Exit "ncdiff"
1958  fi
1959
1960  IGCM_debug_PopStack "IGCM_sys_ncdiff"
1961}
1962
1963function IGCM_sys_ncea {
1964  IGCM_debug_PushStack "IGCM_sys_ncea" -- $@
1965  if ( $DEBUG_sys ) ; then
1966    echo "IGCM_sys_ncea :" $@
1967  fi
1968  ncea $@
1969  if [ $? -gt 0 ] ; then
1970    echo "IGCM_sys_ncea : erreur ${@}."
1971    IGCM_debug_Exit "ncea"
1972  fi
1973
1974  IGCM_debug_PopStack "IGCM_sys_ncea"
1975}
1976
1977function IGCM_sys_ncecat {
1978  IGCM_debug_PushStack "IGCM_sys_ncecat" -- $@
1979  if ( $DEBUG_sys ) ; then
1980    echo "IGCM_sys_ncecat :" $@
1981  fi
1982  ncecat $@
1983  if [ $? -gt 0 ] ; then
1984    echo "IGCM_sys_ncecat : erreur ${@}."
1985    IGCM_debug_Exit "ncecat"
1986  fi
1987
1988  IGCM_debug_PopStack "IGCM_sys_ncecat"
1989}
1990
1991function IGCM_sys_ncflint {
1992  IGCM_debug_PushStack "IGCM_sys_ncflint" -- $@
1993  if ( $DEBUG_sys ) ; then
1994    echo "IGCM_sys_ncflint :" $@
1995  fi
1996  ncflint $@
1997  if [ $? -gt 0 ] ; then
1998    echo "IGCM_sys_ncflint : erreur ${@}."
1999    IGCM_debug_Exit "ncflint"
2000  fi
2001
2002  IGCM_debug_PopStack "IGCM_sys_ncflint"
2003}
2004
2005function IGCM_sys_ncks {
2006  IGCM_debug_PushStack "IGCM_sys_ncks" -- $@
2007  if ( $DEBUG_sys ) ; then
2008    echo "IGCM_sys_ncks :" $@
2009  fi
2010  ncks $@
2011  if [ $? -gt 0 ] ; then
2012    echo "IGCM_sys_ncks : erreur ${@}."
2013    IGCM_debug_Exit "ncks"
2014  fi
2015
2016  IGCM_debug_PopStack "IGCM_sys_ncks"
2017}
2018
2019function IGCM_sys_ncpdq {
2020  IGCM_debug_PushStack "IGCM_sys_ncpdq" -- $@
2021  if ( $DEBUG_sys ) ; then
2022    echo "IGCM_sys_ncpdq :" $@
2023  fi
2024  ncpdq $@
2025  if [ $? -gt 0 ] ; then
2026    echo "IGCM_sys_ncpdq : erreur ${@}."
2027    IGCM_debug_Exit "ncpdq"
2028  fi
2029
2030  IGCM_debug_PopStack "IGCM_sys_ncpdq"
2031}
2032
2033function IGCM_sys_ncra {
2034  IGCM_debug_PushStack "IGCM_sys_ncra" -- $@
2035  if ( $DEBUG_sys ) ; then
2036    echo "IGCM_sys_ncra :" $@
2037  fi
2038  ncra $@
2039  if [ $? -gt 0 ] ; then
2040    echo "IGCM_sys_ncra : erreur ${@}."
2041    IGCM_debug_Exit "ncra"
2042  fi
2043
2044  IGCM_debug_PopStack "IGCM_sys_ncra"
2045}
2046
2047function IGCM_sys_ncrcat {
2048  IGCM_debug_PushStack "IGCM_sys_ncrcat" -- $@
2049  if ( $DEBUG_sys ) ; then
2050    echo "IGCM_sys_ncrcat :" $@
2051  fi
2052  ncrcat $@
2053  if [ $? -gt 0 ] ; then
2054    echo "IGCM_sys_ncrcat : erreur ${@}."
2055#       IGCM_debug_Exit "ncrcat"
2056  fi
2057
2058  IGCM_debug_PopStack "IGCM_sys_ncrcat"
2059}
2060
2061function IGCM_sys_ncrename {
2062  IGCM_debug_PushStack "IGCM_sys_ncrename" -- $@
2063  if ( $DEBUG_sys ) ; then
2064    echo "IGCM_sys_ncrename :" $@
2065  fi
2066  ncrename $@
2067  if [ $? -gt 0 ] ; then
2068    echo "IGCM_sys_ncrename : erreur ${@}."
2069    IGCM_debug_Exit "ncrename"
2070  fi
2071
2072  IGCM_debug_PopStack "IGCM_sys_ncrename"
2073}
2074
2075function IGCM_sys_ncwa {
2076  IGCM_debug_PushStack "IGCM_sys_ncwa" -- $@
2077  if ( $DEBUG_sys ) ; then
2078    echo "IGCM_sys_ncwa :" $@
2079  fi
2080  ncwa $@
2081  if [ $? -gt 0 ] ; then
2082    echo "IGCM_sys_ncwa : erreur ${@}."
2083    IGCM_debug_Exit "ncwa"
2084  fi
2085
2086  IGCM_debug_PopStack "IGCM_sys_ncwa"
2087}
2088
2089##############################################################
2090# CDO OPERATOR
2091
2092function IGCM_sys_cdo {
2093  IGCM_debug_PushStack "IGCM_sys_cdo" -- $@
2094  if ( $DEBUG_sys ) ; then
2095    echo "IGCM_sys_cdo :" $@
2096  fi
2097  \cdo $@
2098  if [ $? -gt 0 ] ; then
2099    echo "IGCM_sys_cdo : erreur ${@}."
2100    IGCM_debug_PopStack "IGCM_sys_cdo"
2101    return 1
2102  else
2103    IGCM_debug_PopStack "IGCM_sys_cdo"
2104    return 0
2105  fi
2106
2107  IGCM_debug_PopStack "IGCM_sys_cdo"
2108}
2109
2110############################################################
2111# Check of space available on temporary filesytems
2112function IGCM_sys_check_quota {
2113    IGCM_debug_PushStack "IGCM_sys_check_quota"
2114    if ( $DEBUG_sys ) ; then
2115        echo "IGCM_sys_check_quota"
2116    fi
2117    IGCM_debug_PopStack "IGCM_sys_check_quota"
2118}
Note: See TracBrowser for help on using the repository browser.