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

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