[4425] | 1 | ###################### |
---|
| 2 | ## IRENE TGCC/CEA ## |
---|
| 3 | ###################### |
---|
| 4 | #MSUB -r PACKOUTPUT # Job name |
---|
| 5 | #MSUB -o PACKOUTPUT.out_%I |
---|
| 6 | #MSUB -e PACKOUTPUT.out_%I |
---|
| 7 | #MSUB -n 1 # Number of cores |
---|
| 8 | #MSUB -T 36000 # Maximum elapsed time |
---|
| 9 | #MSUB -q xlarge |
---|
| 10 | #MSUB -c 8 |
---|
| 11 | #MSUB -Q normal |
---|
| 12 | #MSUB -A scecmip6 |
---|
| 13 | #MSUB -m store,work,scratch |
---|
| 14 | set +x |
---|
| 15 | |
---|
| 16 | #************************************************************** |
---|
| 17 | # Author: Sebastien Denvil |
---|
| 18 | # Contact: Sebastien.Denvil__at__ipsl.jussieu.fr |
---|
| 19 | # $Revision:: 1468 $ Revision of last commit |
---|
| 20 | # $Author:: mafoipsl $ Author of last commit |
---|
| 21 | # $Date:: 2018-08-14 15:55:41 +0200 (Tue, 14 Aug 2018) $ Date of last commit |
---|
| 22 | # IPSL (2006) |
---|
| 23 | # This software is governed by the CeCILL licence see libIGCM/libIGCM_CeCILL.LIC |
---|
| 24 | # |
---|
| 25 | #************************************************************** |
---|
| 26 | |
---|
| 27 | #set -eu |
---|
| 28 | #set -vx |
---|
| 29 | |
---|
| 30 | date |
---|
| 31 | |
---|
| 32 | #D- Task type DO NOT CHANGE (computing, post-processing or checking) |
---|
| 33 | TaskType=post-processing |
---|
| 34 | |
---|
| 35 | ######################################################################## |
---|
| 36 | |
---|
| 37 | #D- Flag to determine if this job in a standalone mode |
---|
| 38 | #D- Default : value from AA_job if any |
---|
| 39 | StandAlone=${StandAlone:=true} |
---|
| 40 | |
---|
| 41 | #D- Path to libIGCM |
---|
| 42 | #D- Default : value from AA_job if any |
---|
| 43 | # WARNING For StandAlone use : To run this script on some machine (ulam and cesium) |
---|
| 44 | # WARNING you must check MirrorlibIGCM variable in sys library. |
---|
| 45 | # WARNING If this variable is true, you must use libIGCM_POST path instead |
---|
| 46 | # WARNING of your running libIGCM directory. |
---|
| 47 | libIGCM=${libIGCM:=/ccc/cont003/dsku/perle1/home/app/gencmip6/devillim/modipsl_v20fev/libIGCM} |
---|
| 48 | |
---|
| 49 | #-D- $hostname of the MASTER job when SUBMIT_DIR is not visible on postprocessing computer. |
---|
| 50 | MASTER=${MASTER:=irene} |
---|
| 51 | |
---|
| 52 | #D- Flag to determine begin date for restart pack |
---|
| 53 | #D- Default : value from AA_job if any |
---|
| 54 | DateBegin=${DateBegin:=21000101} |
---|
| 55 | |
---|
| 56 | #D- Flag to determine end date for restart pack |
---|
| 57 | #D- Default : value from AA_job if any |
---|
| 58 | DateEnd=${DateEnd:=21001231} |
---|
| 59 | |
---|
| 60 | #D- Flag to determine pack period |
---|
| 61 | #D- Default : value from AA_job if any |
---|
| 62 | PeriodPack=${PeriodPack:=1Y} |
---|
| 63 | |
---|
| 64 | #D- Uncomment to run interactively |
---|
| 65 | #D- For testing purpose, will be remove |
---|
| 66 | #SUBMIT_DIR=${PWD} |
---|
| 67 | #RUN_DIR_PATH=${SCRATCHDIR}/Pack_Test |
---|
| 68 | |
---|
| 69 | #D- Increased verbosity (1, 2, 3) |
---|
| 70 | #D- Default : value from AA_job if any |
---|
| 71 | Verbosity=${Verbosity:=3} |
---|
| 72 | |
---|
| 73 | #D- Low level debug : to bypass lib test checks and stack construction |
---|
| 74 | #D- Default : value from AA_job if any |
---|
| 75 | DEBUG_debug=${DEBUG_debug:=false} |
---|
| 76 | |
---|
| 77 | ######################################################################## |
---|
| 78 | |
---|
| 79 | . ${libIGCM}/libIGCM_debug/libIGCM_debug.ksh |
---|
| 80 | . ${libIGCM}/libIGCM_card/libIGCM_card.ksh |
---|
| 81 | . ${libIGCM}/libIGCM_date/libIGCM_date.ksh |
---|
| 82 | #------- |
---|
| 83 | . ${libIGCM}/libIGCM_sys/libIGCM_sys.ksh |
---|
| 84 | . ${libIGCM}/libIGCM_config/libIGCM_config.ksh |
---|
| 85 | . ${libIGCM}/libIGCM_post/libIGCM_post.ksh |
---|
| 86 | #------- |
---|
| 87 | RUN_DIR=${RUN_DIR_PATH} |
---|
| 88 | IGCM_sys_MkdirWork ${RUN_DIR} |
---|
| 89 | IGCM_sys_Cd ${RUN_DIR} |
---|
| 90 | #------- |
---|
| 91 | ( ${DEBUG_debug} ) && IGCM_debug_Check |
---|
| 92 | ( ${DEBUG_debug} ) && IGCM_card_Check |
---|
| 93 | ( ${DEBUG_debug} ) && IGCM_date_Check |
---|
| 94 | |
---|
| 95 | ######################################################################## |
---|
| 96 | |
---|
| 97 | #set -vx |
---|
| 98 | |
---|
| 99 | # ------------------------------------------------------------------ |
---|
| 100 | # Test if all was right before proceeding further |
---|
| 101 | # ------------------------------------------------------------------ |
---|
| 102 | IGCM_debug_Verif_Exit |
---|
| 103 | |
---|
| 104 | if [ ${StandAlone} = true ] ; then |
---|
| 105 | CARD_DIR=${SUBMIT_DIR} |
---|
| 106 | else |
---|
| 107 | CARD_DIR=${RUN_DIR_PATH} |
---|
| 108 | IGCM_sys_Get_Master ${SUBMIT_DIR}/config.card ${RUN_DIR_PATH} |
---|
| 109 | IGCM_sys_Get_Master ${SUBMIT_DIR}/run.card ${RUN_DIR_PATH} |
---|
| 110 | IGCM_sys_Get_Master ${SUBMIT_DIR}/COMP ${RUN_DIR_PATH} |
---|
| 111 | IGCM_sys_Get_Master ${SUBMIT_DIR}/POST ${RUN_DIR_PATH} |
---|
| 112 | fi |
---|
| 113 | |
---|
| 114 | #================================== |
---|
| 115 | # First of all |
---|
| 116 | # |
---|
| 117 | # Read libIGCM compatibility version in config.card |
---|
| 118 | # Read UserChoices section |
---|
| 119 | # Read Ensemble section |
---|
| 120 | # Read Post section |
---|
| 121 | # Define all netcdf output directories |
---|
| 122 | #================================== |
---|
| 123 | IGCM_config_CommonConfiguration ${CARD_DIR}/config.card |
---|
| 124 | |
---|
| 125 | # ------------------------------------------------------------------ |
---|
| 126 | # Activate BigBrother so as to supervise this job |
---|
| 127 | # ------------------------------------------------------------------ |
---|
| 128 | IGCM_debug_BigBro_Initialize |
---|
| 129 | |
---|
| 130 | #================================== |
---|
| 131 | # Read ListOfComponents section |
---|
| 132 | # to drive the loop over find |
---|
| 133 | IGCM_card_DefineArrayFromSection ${CARD_DIR}/config.card ListOfComponents |
---|
| 134 | |
---|
| 135 | #================================== |
---|
| 136 | # Test and set up directories |
---|
| 137 | #================================== |
---|
| 138 | IGCM_sys_TestDirArchive ${R_SAVE} |
---|
| 139 | [ $? != 0 ] && IGCM_debug_Exit "IGCM_sys_TestDirArchive" |
---|
| 140 | |
---|
| 141 | # Where to store used file list /!\ TEMPORARY /!\ |
---|
| 142 | STORE_DEBUG=${R_SAVE}/DEBUG |
---|
| 143 | |
---|
| 144 | # Switch to script variables meaning (try to be compatible with ipsl_pack TGCC moving procedure) |
---|
| 145 | JobName=${config_UserChoices_JobName} |
---|
| 146 | echo $JobName $DateBegin $DateEnd |
---|
| 147 | |
---|
| 148 | # ------------------------------------------------------------------ |
---|
| 149 | # Test if all was right before proceeding further |
---|
| 150 | # ------------------------------------------------------------------ |
---|
| 151 | IGCM_debug_Verif_Exit |
---|
| 152 | |
---|
| 153 | IGCM_debug_Print 1 "Check coherence between PackFrequency and PeriodLength" |
---|
| 154 | IGCM_post_CheckModuloFrequency PeriodPack config_UserChoices_PeriodLength NbPeriodPerFrequency |
---|
| 155 | # ------------------------------------------------------------------ |
---|
| 156 | # Test if all was right before proceeding further |
---|
| 157 | # ------------------------------------------------------------------ |
---|
| 158 | IGCM_debug_Verif_Exit |
---|
| 159 | |
---|
| 160 | IGCM_debug_Print 1 "We must process ${NbPeriodPerFrequency} files for each pack" |
---|
| 161 | |
---|
| 162 | # Init loop |
---|
| 163 | date_begin_pack=${DateBegin} |
---|
| 164 | date_end_simulation=${DateEnd} |
---|
| 165 | number_pack=1 |
---|
| 166 | |
---|
| 167 | IGCM_debug_PrintVariables 3 date_begin_pack |
---|
| 168 | IGCM_debug_PrintVariables 3 date_end_simulation |
---|
| 169 | |
---|
| 170 | while [ ${date_begin_pack} -le ${date_end_simulation} ] ; do |
---|
| 171 | |
---|
| 172 | IGCM_debug_PrintVariables 3 number_pack |
---|
| 173 | DaysTemp=$( IGCM_date_DaysInCurrentPeriod ${date_begin_pack} ${PeriodPack} ) |
---|
| 174 | date_end_pack=$( IGCM_date_AddDaysToGregorianDate ${date_begin_pack} $(( ${DaysTemp} - 1 )) ) |
---|
| 175 | |
---|
| 176 | for comp in ${config_ListOfComponents[*]} ; do |
---|
| 177 | dirList=$( find ${R_BUFR}/${comp}/Output -maxdepth 1 -mindepth 1 -type d ) |
---|
| 178 | for dir in ${dirList} ; do |
---|
| 179 | # dirID is like ATM.Output.MO |
---|
| 180 | dirID=$( echo $dir | sed "s:${R_BUFR}/::" | sed "s:/:.:g" ) |
---|
| 181 | # Sort what's in the directory |
---|
| 182 | find ${dir} -type f -name "${JobName}*.nc" -ls | sort -k 11 > liste_files.${dirID}.txt |
---|
| 183 | # How much file type. Example : 1M_histmthCOSP.nc, 1M_histmth.nc, 1M_histmthNMC.nc, 1M_paramLMDZ_phy.nc |
---|
| 184 | # /!\ fileType include the .nc extension /!\ |
---|
| 185 | 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 ) |
---|
| 186 | # Loop over the file type and pack them when in between date_begin_pack and date_end_pack |
---|
| 187 | for myType in ${fileType} ; do |
---|
| 188 | grep ${myType} liste_files.${dirID}.txt > liste_files.${dirID}.${myType}.txt |
---|
| 189 | nbfile=0 |
---|
| 190 | for file in $( gawk '{print $11}' liste_files.${dirID}.${myType}.txt ); do |
---|
| 191 | extract_date_file=$( echo ${file} | sed -e "s/.*${JobName}_[0-9]*_//" ) |
---|
| 192 | date_file=$( echo ${extract_date_file} | sed 's/\([0-9]\{8\}\)_.*$/\1/g' ) |
---|
| 193 | # echo pack n°${number_pack} ${date_file} ${date_begin_pack} ${date_end_pack} |
---|
| 194 | if [ ${date_file} -le ${date_end_pack} ] && [ ${date_file} -ge ${date_begin_pack} ] ; then |
---|
| 195 | echo ${file} >> liste_pack_${myType}_${date_begin_pack}_${date_end_pack}.txt |
---|
| 196 | 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 |
---|
| 197 | (( nbfile = nbfile + 1 )) |
---|
| 198 | fi |
---|
| 199 | done |
---|
| 200 | |
---|
| 201 | if [ ${nbfile} = 0 ] ; then |
---|
| 202 | IGCM_debug_Print 1 "We found no file to process" |
---|
| 203 | IGCM_debug_Print 1 "We should have found ${NbPeriodPerFrequency} files" |
---|
| 204 | 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" |
---|
| 205 | continue |
---|
| 206 | fi |
---|
| 207 | |
---|
| 208 | # Select list of variables to work with |
---|
| 209 | 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 ',' ) |
---|
| 210 | liste_file_tmp=$( for i in $( cat liste_pack_${myType}_${date_begin_pack}_${date_end_pack}.txt ) ; do basename $i ; done ) |
---|
| 211 | # Create packed files |
---|
| 212 | IGCM_debug_Print 1 "Ncrcat ongoing for ${dir} and ${myType}" |
---|
| 213 | if [ ! ${nbfile} = ${NbPeriodPerFrequency} ] ; then |
---|
| 214 | IGCM_debug_Print 1 "Number of files to process is not equal to what it should be" |
---|
| 215 | IGCM_debug_Print 1 "We found ${nbfile} files and it should have been ${NbPeriodPerFrequency} files" |
---|
| 216 | IGCM_debug_Exit "ERROR in number of files to process. STOP HERE INCLUDING THE COMPUTING JOB" |
---|
| 217 | IGCM_debug_Verif_Exit |
---|
| 218 | fi |
---|
| 219 | output=${JobName}_${date_begin_pack}_${date_end_pack}_${myType} |
---|
| 220 | #cat liste_pack_${myType}_${date_begin_pack}_${date_end_pack}.txt | xargs ncrcat -v ${list_var} -o ${output} |
---|
| 221 | if [ X${list_var} = X ] ; then |
---|
| 222 | IGCM_sys_ncrcat -p ${dir} ${liste_file_tmp} --output ${output} |
---|
| 223 | else |
---|
| 224 | IGCM_sys_ncrcat -x -v ${list_var} -p ${dir} ${liste_file_tmp} --output ${output} |
---|
| 225 | fi |
---|
| 226 | # ------------------------------------------------------------------ |
---|
| 227 | # Test if all was right before proceeding further |
---|
| 228 | # ------------------------------------------------------------------ |
---|
| 229 | IGCM_debug_Verif_Exit |
---|
| 230 | # Save it |
---|
| 231 | IGCM_sys_Put_Out ${output} ${R_SAVE}/$( echo $dir | sed "s:${R_BUFR}/::" )/${output} |
---|
| 232 | # Clean file produced by ncrcat |
---|
| 233 | IGCM_sys_Rm ${output} |
---|
| 234 | # ------------------------------------------------------------------ |
---|
| 235 | # Test if all was right before proceeding further |
---|
| 236 | # ------------------------------------------------------------------ |
---|
| 237 | IGCM_debug_Verif_Exit |
---|
| 238 | # Clean files used by ncrcat |
---|
| 239 | cat liste_pack_${myType}_${date_begin_pack}_${date_end_pack}.txt | xargs rm |
---|
| 240 | # Save the list of files that has been pack (ncrcat) |
---|
| 241 | #mv liste_pack_${myType}_${date_begin_pack}_${date_end_pack}.txt ${STORE_DEBUG} |
---|
| 242 | IGCM_debug_Print 1 "Ncrcat and cleaning done for ${dir} and ${myType}" |
---|
| 243 | echo |
---|
| 244 | done |
---|
| 245 | done |
---|
| 246 | done |
---|
| 247 | (( number_pack = number_pack + 1 )) |
---|
| 248 | # Add 1 day to date_end_pack to have the new date_begin_pack |
---|
| 249 | date_begin_pack=$( IGCM_date_AddDaysToGregorianDate ${date_end_pack} 1 ) |
---|
| 250 | done |
---|
| 251 | |
---|
| 252 | # Flush post-processing submission |
---|
| 253 | if [ -f ${R_BUFR}/FlushPost_${DateEnd}.ksh ] ; then |
---|
| 254 | . ${R_BUFR}/FlushPost_${DateEnd}.ksh |
---|
| 255 | IGCM_FlushPost |
---|
| 256 | #IGCM_sys_Rm -f ${R_BUFR}/FlushPost_${DateEnd}.ksh |
---|
| 257 | fi |
---|
| 258 | |
---|
| 259 | # Clean RUN_DIR_PATH (necessary for cesium and titane only) |
---|
| 260 | IGCM_sys_RmRunDir -Rf ${RUN_DIR_PATH} |
---|
| 261 | |
---|
| 262 | # ------------------------------------------------------------------ |
---|
| 263 | # Finalize BigBrother to inform that the jobs end |
---|
| 264 | # ------------------------------------------------------------------ |
---|
| 265 | IGCM_debug_BigBro_Finalize |
---|
| 266 | |
---|
| 267 | date |
---|