source: tags/libIGCM_v2.0_rc3/AA_pack_output @ 998

Last change on this file since 998 was 785, checked in by labetoulle, 11 years ago

Cosmetics :

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