source: tags/libIGCM_v2.0_beta2/AA_pack_output

Last change on this file was 658, checked in by labetoulle, 12 years ago

Add Ensemble functionality to libIGCM - First step :
modify output directories according to an option in section [Ensemble]
in config.card (modification of config.card yet to be done).

  • Property svn:keywords set to Revision Author Date
File size: 17.7 KB
Line 
1#-Q- cesium #!/bin/ksh
2#-Q- cesium ######################
3#-Q- cesium ## CESIUM   CEA ##
4#-Q- cesium ######################
5#-Q- cesium #MSUB -r PACKOUTPUT    # Nom du job
6#-Q- cesium #MSUB -N 1              # Reservation du noeud
7#-Q- cesium #MSUB -n 1              # Reservation du processus
8#-Q- cesium #MSUB -T 86400          # Limite de temps elapsed du job
9#-Q- cesium #MSUB -E "-j o"
10#-Q- cesium #MSUB -E "-S /bin/ksh"
11#-Q- curie ######################
12#-Q- curie ## CURIE   TGCC/CEA ##
13#-Q- curie ######################
14#-Q- curie #MSUB -r PACKOUTPUT     # Nom du job               
15#-Q- curie #MSUB -eo
16#-Q- curie #MSUB -n 1              # Reservation du processus
17#-Q- curie #MSUB -T 86400          # Limite de temps elapsed du job
18#-Q- curie #MSUB -E '--no-requeue'
19#-Q- platine #!/usr/bin/ksh
20#-Q- platine ###################
21#-Q- platine ## PLATINE   CEA ##
22#-Q- platine ###################
23#-Q- platine #BSUB -J PACKOUTPUT            # Nom du job
24#-Q- platine #BSUB -N                        # message a la fin du job
25#-Q- platine #BSUB -n 1                      # reservation des processeurs pour le job
26#-Q- platine #BSUB -W 4:00                   # Limite temps
27#-Q- platine #BSUB -q post                   # Passage en queue post
28#-Q- platine #BSUB -L /bin/ksh
29#-Q- sx8brodie #!/bin/ksh
30#-Q- sx8brodie #######################
31#-Q- sx8brodie ## SX8BRODIE   IDRIS ##
32#-Q- sx8brodie #######################
33#-Q- sx8brodie # Temps Elapsed max. d'une requete hh:mm:ss
34#-Q- sx8brodie # @ wall_clock_limit = 10:00:00
35#-Q- sx8brodie # Nom du travail LoadLeveler
36#-Q- sx8brodie # @ job_name   = PACKOUTPUT
37#-Q- sx8brodie # Fichier de sortie standard du travail
38#-Q- sx8brodie # @ output     = $(job_name).$(jobid)
39#-Q- sx8brodie # Fichier de sortie d'erreur du travail
40#-Q- sx8brodie # @ error      =  $(job_name).$(jobid)
41#-Q- sx8brodie # pour recevoir un mail en cas de depassement du temps Elapsed (ou autre pb.)
42#-Q- sx8brodie # @ notification = error
43#-Q- sx8brodie # @ environment  = $DEBUG_debug ; $MODIPSL ; $libIGCM ; $libIGCM_SX ; $SUBMIT_DIR ; $DateBegin ; $DateEnd ; $PeriodPack ; $StandAlone ; $MASTER
44#-Q- sx8brodie # @ queue
45#-Q- aix6 #!/bin/ksh
46#-Q- aix6 #######################
47#-Q- aix6 ##   VARGAS   IDRIS  ##
48#-Q- aix6 #######################
49#-Q- aix6 # Temps Elapsed max. d'une requete hh:mm:ss
50#-Q- aix6 # @ wall_clock_limit = 10:00:00
51#-Q- aix6 # Nom du travail LoadLeveler
52#-Q- aix6 # @ job_name   = PACKOUTPUT
53#-Q- aix6 # Fichier de sortie standard du travail
54#-Q- aix6 # @ output     = $(job_name).$(jobid)
55#-Q- aix6 # Fichier de sortie d'erreur du travail
56#-Q- aix6 # @ error      =  $(job_name).$(jobid)
57#-Q- aix6 # pour recevoir un mail en cas de depassement du temps Elapsed (ou autre pb.)
58#-Q- aix6 # @ notification = error
59#-Q- aix6 # @ environment  = $DEBUG_debug ; $MODIPSL ; $libIGCM ; $libIGCM_SX ; $SUBMIT_DIR ; $DateBegin ; $DateEnd ; $PeriodPack ; $StandAlone ; $MASTER
60#-Q- aix6 # @ queue
61#-Q- ulam #!/bin/ksh
62#-Q- ulam #######################
63#-Q- ulam ##   VARGAS   IDRIS  ##
64#-Q- ulam #######################
65#-Q- ulam # Temps Elapsed max. d'une requete hh:mm:ss
66#-Q- ulam # @ wall_clock_limit = 10:00:00
67#-Q- ulam # Nom du travail LoadLeveler
68#-Q- ulam # @ job_name   = PACKOUTPUT
69#-Q- ulam # Fichier de sortie standard du travail
70#-Q- ulam # @ output     = $(job_name).$(jobid)
71#-Q- ulam # Fichier de sortie d'erreur du travail
72#-Q- ulam # @ error      =  $(job_name).$(jobid)
73#-Q- ulam # pour recevoir un mail en cas de depassement du temps Elapsed (ou autre pb.)
74#-Q- ulam # @ notification = error
75#-Q- ulam # @ environment  = $DEBUG_debug ; $MODIPSL ; $libIGCM ; $libIGCM_SX ; $SUBMIT_DIR ; $DateBegin ; $DateEnd ; $PeriodPack ; $StandAlone ; $MASTER
76#-Q- ulam # @ queue
77#-Q- sx8mercure #!/bin/ksh
78#-Q- sx8mercure ######################
79#-Q- sx8mercure ## SX8MERCURE   CEA ##
80#-Q- sx8mercure ######################
81#-Q- sx8mercure #PBS -N PACKOUTPUT          # Nom du job
82#-Q- sx8mercure #PBS -j o                    # regroupement des stdout et stderr
83#-Q- sx8mercure #PBS -S /usr/bin/ksh         # shell de soumission
84#-Q- sx8mercure #PBS -l memsz_job=1gb        # Limite memoire a 1 Go
85#-Q- sx8mercure #PBS -l cputim_job=24:00:00  # Limite temps a 1 heures
86#-Q- sx8mercure #PBS -q scalaire
87#-Q- sx8mercure #PBS -r n
88#-Q- sx9mercure #!/bin/ksh
89#-Q- sx9mercure ######################
90#-Q- sx9mercure ## SX9MERCURE  CCRT ##
91#-Q- sx9mercure ######################
92#-Q- sx9mercure #PBS -N PACKOUTPUT          # Nom du job
93#-Q- sx9mercure #PBS -j o                    # regroupement des stdout et stderr
94#-Q- sx9mercure #PBS -S /usr/bin/ksh         # shell de soumission
95#-Q- sx9mercure #PBS -l memsz_job=1gb        # Limite memoire a 1 Go
96#-Q- sx9mercure #PBS -l elapstim_req=24:00:00  # Limite temps a 1 heures
97#-Q- sx9mercure #PBS -q scalaire
98#-Q- sx9mercure #PBS -r n
99#-Q- titane #!/bin/ksh
100#-Q- titane ######################
101#-Q- titane ## TITANE   CEA     ##
102#-Q- titane ######################
103#-Q- titane #MSUB -r PACKOUTPUT    # Nom du job
104#-Q- titane #MSUB -eo
105#-Q- titane #MSUB -n 1              # Reservation du processus
106#-Q- titane #MSUB -T 86400          # Limite de temps elapsed du job
107#-Q- titane #MSUB -q mono
108#-Q- titane #MSUB -E '-rn'
109#-Q- lxiv8 ######################
110#-Q- lxiv8 ## OBELIX      LSCE ##
111#-Q- lxiv8 ######################
112#-Q- lxiv8 #PBS -N PACKOUTPUT
113#-Q- lxiv8 #PBS -m a
114#-Q- lxiv8 #PBS -j oe
115#-Q- lxiv8 #PBS -q medium
116#-Q- lxiv8 #PBS -o PACKOUTPUT.$$
117#-Q- lxiv8 #PBS -S /bin/ksh
118#-Q- default #!/bin/ksh
119#-Q- default ##################
120#-Q- default ## DEFAULT HOST ##
121#-Q- default ##################
122
123#**************************************************************
124# Author: Sebastien Denvil
125# Contact: Sebastien.Denvil__at__ipsl.jussieu.fr
126# $Revision::                                          $ Revision of last commit
127# $Author::                                            $ Author of last commit
128# $Date::                                              $ Date of last commit
129# IPSL (2006)
130#  This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC
131#
132#**************************************************************
133
134#set -eu
135#set -vx
136
137date
138
139########################################################################
140
141#D- Flag to determine if this job in a standalone mode
142#D- Default : value from AA_job if any
143StandAlone=${StandAlone:=true}
144
145#D- Path to libIGCM
146#D- Default : value from AA_job if any
147# WARNING For StandAlone use : To run this script on some machine (ulam and cesium)
148# WARNING you must check MirrorlibIGCM variable in sys library.
149# WARNING If this variable is true, you must use libIGCM_POST path instead
150# WARNING of your running libIGCM directory.
151libIGCM=${libIGCM:=::modipsl::/libIGCM}
152
153#-D- $hostname of the MASTER job when SUBMIT_DIR is not visible on postprocessing computer.
154MASTER=${MASTER:=mercure|titane|brodie|vargas}
155
156#D- Flag to determine begin date for restart pack
157#D- Default : value from AA_job if any
158DateBegin=${DateBegin:=20000101}
159
160#D- Flag to determine end date for restart pack
161#D- Default : value from AA_job if any
162DateEnd=${DateEnd:=20691231}
163
164#D- Flag to determine pack period
165#D- Default : value from AA_job if any
166PeriodPack=${PeriodPack:=10Y}
167
168#D- Uncomment to run interactively
169#D- For testing purpose, will be remove
170#SUBMIT_DIR=${PWD}
171#RUN_DIR_PATH=${SCRATCHDIR}/Pack_Test
172
173#D- Increased verbosity (1, 2, 3)
174#D- Default : value from AA_job if any
175Verbosity=${Verbosity:=3}
176
177#D- Low level debug : to bypass lib test checks and stack construction
178#D- Default : value from AA_job if any
179DEBUG_debug=${DEBUG_debug:=false}
180
181########################################################################
182
183. ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh
184( ${DEBUG_debug} ) && IGCM_debug_Check
185. ${libIGCM}/libIGCM_card/libIGCM_card.ksh
186( ${DEBUG_debug} ) && IGCM_card_Check
187. ${libIGCM}/libIGCM_date/libIGCM_date.ksh
188( ${DEBUG_debug} ) && IGCM_date_Check
189#-------
190. ${libIGCM}/libIGCM_sys/libIGCM_sys.ksh
191. ${libIGCM}/libIGCM_post/libIGCM_post.ksh
192
193########################################################################
194
195#set -vx
196
197RUN_DIR=${RUN_DIR_PATH}
198IGCM_sys_MkdirWork ${RUN_DIR}
199IGCM_sys_Cd ${RUN_DIR}
200
201# ------------------------------------------------------------------
202# Test if all was right before proceeding further
203# ------------------------------------------------------------------
204IGCM_debug_Verif_Exit_Post
205
206if [ ${StandAlone} = true ] ; then
207    CARD_DIR=${SUBMIT_DIR}
208else
209    CARD_DIR=${RUN_DIR_PATH}
210    IGCM_sys_Get_Master ${SUBMIT_DIR}/config.card ${RUN_DIR_PATH}
211    IGCM_sys_Get_Master ${SUBMIT_DIR}/run.card    ${RUN_DIR_PATH}
212    IGCM_sys_Get_Master ${SUBMIT_DIR}/COMP        ${RUN_DIR_PATH}
213    IGCM_sys_Get_Master ${SUBMIT_DIR}/POST        ${RUN_DIR_PATH}
214fi
215
216#====================================================
217# First of all
218#
219# Read config.card
220
221IGCM_card_DefineArrayFromSection     ${CARD_DIR}/config.card UserChoices
222typeset option
223for option in ${config_UserChoices[*]} ; do
224  IGCM_card_DefineVariableFromOption ${CARD_DIR}/config.card UserChoices ${option}
225done
226#
227IGCM_card_DefineArrayFromSection     ${CARD_DIR}/config.card Ensemble
228typeset option
229for option in ${config_Ensemble[*]} ; do
230  IGCM_card_DefineVariableFromOption ${CARD_DIR}/config.card Ensemble ${option}
231done
232#
233echo
234IGCM_debug_Print 1 "DefineArrayFromOption  : config_UserChoices"
235IGCM_debug_PrintVariables 3 config_UserChoices_JobName
236IGCM_debug_PrintVariables 3 config_UserChoices_LongName
237IGCM_debug_PrintVariables 3 config_UserChoices_TagName
238IGCM_debug_PrintVariables 3 config_UserChoices_SpaceName
239IGCM_debug_PrintVariables 3 config_UserChoices_ExperimentName
240IGCM_debug_PrintVariables 3 config_UserChoices_CalendarType
241IGCM_debug_PrintVariables 3 config_UserChoices_DateBegin
242IGCM_debug_PrintVariables 3 config_UserChoices_DateEnd
243IGCM_debug_PrintVariables 3 config_UserChoices_PeriodLength
244IGCM_debug_PrintVariables 3 config_Ensemble_EnsembleName
245IGCM_debug_PrintVariables 3 config_Ensemble_EnsembleDate
246echo
247
248# Get ListOfComponents to drive the loop over find
249IGCM_card_DefineArrayFromSection ${CARD_DIR}/config.card ListOfComponents
250
251#====================================================
252#R_SAVE : Job output storage directory
253#R_BUFR : Job output buffered directory
254
255if ( [ ! X${config_UserChoices_SpaceName} = X ] && [ ! X${config_UserChoices_ExperimentName} = X ] ) ; then
256  FreeName=$( echo ${config_UserChoices_JobName} | sed 's/.*_//' )
257  if ( [ ! X${config_Ensemble_EnsembleName} = X ] && [ ! X${config_Ensemble_EnsembleDate} = X ] ) ; then
258    R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${config_Ensemble_EnsembleName}/${config_Ensemble_EnsembleDate}/${FreeName}
259    R_BUFR=${R_BUF}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${config_Ensemble_EnsembleName}/${config_Ensemble_EnsembleDate}/${FreeName}
260  else
261    R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${FreeName}
262    R_BUFR=${R_BUF}/${config_UserChoices_TagName}/${config_UserChoices_SpaceName}/${config_UserChoices_ExperimentName}/${FreeName}
263  fi
264else
265  if ( [ ! X${config_Ensemble_EnsembleName} = X ] && [ ! X${config_Ensemble_EnsembleDate} = X ] ) ; then
266    R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_Ensemble_EnsembleName}/${config_Ensemble_EnsembleDate}/${config_UserChoices_JobName}
267    R_BUFR=${R_BUF}/${config_UserChoices_TagName}/${config_Ensemble_EnsembleName}/${config_Ensemble_EnsembleDate}/${config_UserChoices_JobName}
268  else
269    R_SAVE=${R_OUT}/${config_UserChoices_TagName}/${config_UserChoices_JobName}
270    R_BUFR=${R_BUF}/${config_UserChoices_TagName}/${config_UserChoices_JobName}
271  fi
272fi
273IGCM_sys_TestDirArchive ${R_SAVE}
274[ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive"
275
276# Where to store used file list /!\ TEMPORARY /!\
277STORE_DEBUG=${R_SAVE}/DEBUG
278
279# Switch to script variables meaning (try to be compatible with ipsl_pack TGCC moving procedure)
280JobName=${config_UserChoices_JobName}
281echo $JobName $DateBegin $DateEnd
282
283# ------------------------------------------------------------------
284# Test if all was right before proceeding further
285# ------------------------------------------------------------------
286IGCM_debug_Verif_Exit_Post
287
288IGCM_debug_Print 1 "Check coherence between PackFrequency and PeriodLength"
289IGCM_post_CheckModuloFrequency PeriodPack config_UserChoices_PeriodLength NbPeriodPerFrequency
290# ------------------------------------------------------------------
291# Test if all was right before proceeding further
292# ------------------------------------------------------------------
293IGCM_debug_Verif_Exit_Post
294
295IGCM_debug_Print 1 "We must process ${NbPeriodPerFrequency} files for each pack"
296
297# Init loop
298date_begin_pack=${DateBegin}
299date_end_simulation=${DateEnd}
300number_pack=1
301
302IGCM_debug_PrintVariables 3 date_begin_pack
303IGCM_debug_PrintVariables 3 date_end_simulation
304
305while [ ${date_begin_pack} -le ${date_end_simulation} ] ; do
306
307  IGCM_debug_PrintVariables 3 number_pack
308  DaysTemp=$( IGCM_date_DaysInCurrentPeriod ${date_begin_pack} ${PeriodPack} )
309  date_end_pack=$( IGCM_date_AddDaysToGregorianDate ${date_begin_pack} $(( ${DaysTemp} - 1 )) )
310
311  for comp in ${config_ListOfComponents[*]} ; do
312    dirList=$( find ${R_BUFR}/${comp}/Output -maxdepth 1 -mindepth 1 -type d )
313    for dir in ${dirList} ; do
314      # dirID is like ATM.Output.MO
315      dirID=$( echo $dir | sed "s:${R_BUFR}/::" | sed "s:/:.:g" )
316      # Sort what's in the directory
317      find ${dir} -type f -name "${JobName}*.nc" -ls | sort -k 11 > liste_files.${dirID}.txt
318      # How much file type. Example : 1M_histmthCOSP.nc, 1M_histmth.nc, 1M_histmthNMC.nc, 1M_paramLMDZ_phy.nc
319      # /!\ fileType include the .nc extension /!\
320      fileType=$( gawk '{print $11}' liste_files.${dirID}.txt | gawk -F$dir/ '{print $2}' | sed "s:${JobName}_[0-9]\{8,9\}_[0-9]\{8,9\}_::g" | sort | uniq )
321      # Loop over the file type and pack them when in between date_begin_pack and date_end_pack
322      for myType in ${fileType} ; do
323        grep ${myType} liste_files.${dirID}.txt > liste_files.${dirID}.${myType}.txt
324        nbfile=0
325        for file in $( gawk '{print $11}' liste_files.${dirID}.${myType}.txt ); do
326          extract_date_file=$( echo ${file}  | sed -e "s/.*${JobName}_[0-9]*_//" )
327          date_file=$( echo ${extract_date_file} | sed 's/\([0-9]\{8\}\)_.*$/\1/g' )
328          # echo pack n°${number_pack}  ${date_file} ${date_begin_pack} ${date_end_pack}
329          if [ ${date_file} -le ${date_end_pack} ] && [ ${date_file} -ge ${date_begin_pack} ] ; then
330            echo ${file} >> liste_pack_${myType}_${date_begin_pack}_${date_end_pack}.txt
331            ncdump -h ${file} | grep -E 'float|double' | cut -f 1 -d '(' | cut -f 2 -d ' ' >> liste_variables_${myType}_${date_begin_pack}_${date_end_pack}.txt
332            (( nbfile = nbfile + 1 ))
333          fi
334        done
335
336        if ( [ X${StandAlone} = Xtrue ] && [ ${nbfile} = 0 ] ) ; then
337          IGCM_debug_Print 1 "We found ${nbfile} files to process"
338          IGCM_debug_Print 1 "We should have found ${NbPeriodPerFrequency} files"
339          IGCM_debug_Print 1 "As we are in StandAlone mode we consider the job has been done and move to the next file type"
340          continue
341        fi
342
343        # Select list of variables to work with
344        list_var=$( cat liste_variables_${myType}_${date_begin_pack}_${date_end_pack}.txt | sort | uniq -c | awk -v nbfile=$nbfile '{if ($1 != nbfile) {print $2}}' | paste -s -d ',' )
345        liste_file_tmp=$( for i in $( cat liste_pack_${myType}_${date_begin_pack}_${date_end_pack}.txt ) ; do basename $i ; done )
346        # Create packed files
347        IGCM_debug_Print 1 "Ncrcat ongoing for ${dir} and ${myType}"
348        if [ ! ${nbfile} = ${NbPeriodPerFrequency} ] ; then
349          IGCM_debug_Print 1 "Number of files to process is not equal to what it should be"
350          IGCM_debug_Print 1 "We found ${nbfile} files and it should have been ${NbPeriodPerFrequency} files"
351          IGCM_debug_Exit "ERROR in number of files to process. STOP HERE INCLUDING THE COMPUTING JOB"
352          IGCM_debug_Verif_Exit
353        fi
354        output=${JobName}_${date_begin_pack}_${date_end_pack}_${myType}
355        #cat liste_pack_${myType}_${date_begin_pack}_${date_end_pack}.txt | xargs ncrcat -v ${list_var} -o ${output}
356        if [ X${list_var} = X ] ; then
357          IGCM_sys_ncrcat -p ${dir} ${liste_file_tmp} --output ${output}
358        else
359          IGCM_sys_ncrcat -x -v ${list_var} -p ${dir} ${liste_file_tmp} --output ${output}
360        fi
361        # ------------------------------------------------------------------
362        # Test if all was right before proceeding further
363        # ------------------------------------------------------------------
364        IGCM_debug_Verif_Exit_Post
365        # Save it
366        IGCM_sys_Put_Out ${output} ${R_SAVE}/$( echo $dir | sed "s:${R_BUFR}/::" )/${output}
367        # ------------------------------------------------------------------
368        # Test if all was right before proceeding further
369        # ------------------------------------------------------------------
370        IGCM_debug_Verif_Exit_Post
371        # Clean file produced by ncrcat
372        IGCM_sys_Rm ${output}
373        # Clean files used by ncrcat
374        cat liste_pack_${myType}_${date_begin_pack}_${date_end_pack}.txt | xargs rm
375        # Save the list of files that has been pack (ncrcat)
376        #mv liste_pack_${myType}_${date_begin_pack}_${date_end_pack}.txt ${STORE_DEBUG}
377        IGCM_debug_Print 1 "Ncrcat and cleaning done for ${dir} and ${myType}"
378        echo
379      done
380    done
381  done
382  (( number_pack = number_pack + 1 ))
383  # Add 1 day to date_end_pack to have the new date_begin_pack
384  date_begin_pack=$( IGCM_date_AddDaysToGregorianDate ${date_end_pack} 1 )
385done
386
387# Flush post-processing submission
388if [ -f ${R_BUFR}/FlushPost_${DateEnd}.ksh ] ; then
389  . ${R_BUFR}/FlushPost_${DateEnd}.ksh
390  IGCM_FlushPost
391  #IGCM_sys_Rm -f ${R_BUFR}/FlushPost_${DateEnd}.ksh
392fi
393
394# Clean RUN_DIR_PATH (necessary for cesium and titane only)
395IGCM_sys_RmRunDir -Rf ${RUN_DIR_PATH}
396
397date
Note: See TracBrowser for help on using the repository browser.