source: trunk/libIGCM/AA_pack_output @ 832

Last change on this file since 832 was 832, checked in by sdipsl, 11 years ago
  • Trivial changes to accomodate new_libIGCM function defined here /ccc/cont003/home/dsm/p86mart/.bash_alias (ksh-->bash)

She transforms every cp and rm by IGCM_sys_Cp and IGCM_sys_Rm within IGCM_debug_Check. So we need to source sys before calling it.

  • 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. ${libIGCM}/libIGCM_card/libIGCM_card.ksh
127. ${libIGCM}/libIGCM_date/libIGCM_date.ksh
128#-------
129. ${libIGCM}/libIGCM_sys/libIGCM_sys.ksh
130. ${libIGCM}/libIGCM_config/libIGCM_config.ksh
131. ${libIGCM}/libIGCM_post/libIGCM_post.ksh
132#-------
133( ${DEBUG_debug} ) && IGCM_debug_Check
134( ${DEBUG_debug} ) && IGCM_card_Check
135( ${DEBUG_debug} ) && IGCM_date_Check
136
137########################################################################
138
139#set -vx
140
141RUN_DIR=${RUN_DIR_PATH}
142IGCM_sys_MkdirWork ${RUN_DIR}
143IGCM_sys_Cd ${RUN_DIR}
144
145# ------------------------------------------------------------------
146# Test if all was right before proceeding further
147# ------------------------------------------------------------------
148IGCM_debug_Verif_Exit_Post
149
150if [ ${StandAlone} = true ] ; then
151    CARD_DIR=${SUBMIT_DIR}
152else
153    CARD_DIR=${RUN_DIR_PATH}
154    IGCM_sys_Get_Master ${SUBMIT_DIR}/config.card ${RUN_DIR_PATH}
155    IGCM_sys_Get_Master ${SUBMIT_DIR}/run.card    ${RUN_DIR_PATH}
156    IGCM_sys_Get_Master ${SUBMIT_DIR}/COMP        ${RUN_DIR_PATH}
157    IGCM_sys_Get_Master ${SUBMIT_DIR}/POST        ${RUN_DIR_PATH}
158fi
159
160#==================================
161# First of all
162#
163# Read libIGCM compatibility version in config.card
164# Read UserChoices section
165# Read Ensemble section
166# Read Post section
167# Define all netcdf output directories
168#==================================
169IGCM_config_CommonConfiguration ${CARD_DIR}/config.card
170
171#==================================
172# Read ListOfComponents section
173# to drive the loop over find
174IGCM_card_DefineArrayFromSection ${CARD_DIR}/config.card ListOfComponents
175#
176IGCM_sys_TestDirArchive ${R_SAVE}
177[ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive"
178
179# Where to store used file list /!\ TEMPORARY /!\
180STORE_DEBUG=${R_SAVE}/DEBUG
181
182# Switch to script variables meaning (try to be compatible with ipsl_pack TGCC moving procedure)
183JobName=${config_UserChoices_JobName}
184echo $JobName $DateBegin $DateEnd
185
186# ------------------------------------------------------------------
187# Test if all was right before proceeding further
188# ------------------------------------------------------------------
189IGCM_debug_Verif_Exit_Post
190
191IGCM_debug_Print 1 "Check coherence between PackFrequency and PeriodLength"
192IGCM_post_CheckModuloFrequency PeriodPack config_UserChoices_PeriodLength NbPeriodPerFrequency
193# ------------------------------------------------------------------
194# Test if all was right before proceeding further
195# ------------------------------------------------------------------
196IGCM_debug_Verif_Exit_Post
197
198IGCM_debug_Print 1 "We must process ${NbPeriodPerFrequency} files for each pack"
199
200# Init loop
201date_begin_pack=${DateBegin}
202date_end_simulation=${DateEnd}
203number_pack=1
204
205IGCM_debug_PrintVariables 3 date_begin_pack
206IGCM_debug_PrintVariables 3 date_end_simulation
207
208while [ ${date_begin_pack} -le ${date_end_simulation} ] ; do
209
210  IGCM_debug_PrintVariables 3 number_pack
211  DaysTemp=$( IGCM_date_DaysInCurrentPeriod ${date_begin_pack} ${PeriodPack} )
212  date_end_pack=$( IGCM_date_AddDaysToGregorianDate ${date_begin_pack} $(( ${DaysTemp} - 1 )) )
213
214  for comp in ${config_ListOfComponents[*]} ; do
215    dirList=$( find ${R_BUFR}/${comp}/Output -maxdepth 1 -mindepth 1 -type d )
216    for dir in ${dirList} ; do
217      # dirID is like ATM.Output.MO
218      dirID=$( echo $dir | sed "s:${R_BUFR}/::" | sed "s:/:.:g" )
219      # Sort what's in the directory
220      find ${dir} -type f -name "${JobName}*.nc" -ls | sort -k 11 > liste_files.${dirID}.txt
221      # How much file type. Example : 1M_histmthCOSP.nc, 1M_histmth.nc, 1M_histmthNMC.nc, 1M_paramLMDZ_phy.nc
222      # /!\ fileType include the .nc extension /!\
223      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 )
224      # Loop over the file type and pack them when in between date_begin_pack and date_end_pack
225      for myType in ${fileType} ; do
226        grep ${myType} liste_files.${dirID}.txt > liste_files.${dirID}.${myType}.txt
227        nbfile=0
228        for file in $( gawk '{print $11}' liste_files.${dirID}.${myType}.txt ); do
229          extract_date_file=$( echo ${file}  | sed -e "s/.*${JobName}_[0-9]*_//" )
230          date_file=$( echo ${extract_date_file} | sed 's/\([0-9]\{8\}\)_.*$/\1/g' )
231          # echo pack n°${number_pack}  ${date_file} ${date_begin_pack} ${date_end_pack}
232          if [ ${date_file} -le ${date_end_pack} ] && [ ${date_file} -ge ${date_begin_pack} ] ; then
233            echo ${file} >> liste_pack_${myType}_${date_begin_pack}_${date_end_pack}.txt
234            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
235            (( nbfile = nbfile + 1 ))
236          fi
237        done
238
239        if [ ${nbfile} = 0 ] ; then
240          IGCM_debug_Print 1 "We found no file to process"
241          IGCM_debug_Print 1 "We should have found ${NbPeriodPerFrequency} files"
242          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"
243          continue
244        fi
245
246        # Select list of variables to work with
247        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 ',' )
248        liste_file_tmp=$( for i in $( cat liste_pack_${myType}_${date_begin_pack}_${date_end_pack}.txt ) ; do basename $i ; done )
249        # Create packed files
250        IGCM_debug_Print 1 "Ncrcat ongoing for ${dir} and ${myType}"
251        if [ ! ${nbfile} = ${NbPeriodPerFrequency} ] ; then
252          IGCM_debug_Print 1 "Number of files to process is not equal to what it should be"
253          IGCM_debug_Print 1 "We found ${nbfile} files and it should have been ${NbPeriodPerFrequency} files"
254          IGCM_debug_Exit "ERROR in number of files to process. STOP HERE INCLUDING THE COMPUTING JOB"
255          IGCM_debug_Verif_Exit
256        fi
257        output=${JobName}_${date_begin_pack}_${date_end_pack}_${myType}
258        #cat liste_pack_${myType}_${date_begin_pack}_${date_end_pack}.txt | xargs ncrcat -v ${list_var} -o ${output}
259        if [ X${list_var} = X ] ; then
260          IGCM_sys_ncrcat -p ${dir} ${liste_file_tmp} --output ${output}
261        else
262          IGCM_sys_ncrcat -x -v ${list_var} -p ${dir} ${liste_file_tmp} --output ${output}
263        fi
264        # ------------------------------------------------------------------
265        # Test if all was right before proceeding further
266        # ------------------------------------------------------------------
267        IGCM_debug_Verif_Exit_Post
268        # Save it
269        IGCM_sys_Put_Out ${output} ${R_SAVE}/$( echo $dir | sed "s:${R_BUFR}/::" )/${output}
270        # Clean file produced by ncrcat
271        IGCM_sys_Rm ${output}
272        # ------------------------------------------------------------------
273        # Test if all was right before proceeding further
274        # ------------------------------------------------------------------
275        IGCM_debug_Verif_Exit_Post
276        # Clean files used by ncrcat
277        cat liste_pack_${myType}_${date_begin_pack}_${date_end_pack}.txt | xargs rm
278        # Save the list of files that has been pack (ncrcat)
279        #mv liste_pack_${myType}_${date_begin_pack}_${date_end_pack}.txt ${STORE_DEBUG}
280        IGCM_debug_Print 1 "Ncrcat and cleaning done for ${dir} and ${myType}"
281        echo
282      done
283    done
284  done
285  (( number_pack = number_pack + 1 ))
286  # Add 1 day to date_end_pack to have the new date_begin_pack
287  date_begin_pack=$( IGCM_date_AddDaysToGregorianDate ${date_end_pack} 1 )
288done
289
290# Flush post-processing submission
291if [ -f ${R_BUFR}/FlushPost_${DateEnd}.ksh ] ; then
292  . ${R_BUFR}/FlushPost_${DateEnd}.ksh
293  IGCM_FlushPost
294  #IGCM_sys_Rm -f ${R_BUFR}/FlushPost_${DateEnd}.ksh
295fi
296
297# Clean RUN_DIR_PATH (necessary for cesium and titane only)
298IGCM_sys_RmRunDir -Rf ${RUN_DIR_PATH}
299
300date
Note: See TracBrowser for help on using the repository browser.