#! /bin/sh # #+ # # .. program:: compute_erai_daily_region_2d.sh # # .. _compute_erai_daily_region_2d.sh: # # ========================================================================== # compute_erai_daily_region_2d.sh - get ERA-I uninterpolated reference files # ========================================================================== # # SYNOPSIS # ======== # # :: # # $ compute_erai_daily_region_2d.sh [--debug] [--diff_cmd arg] -b yyyymmdd -e yyyymmdd # # DESCRIPTION # =========== # # .. option:: --diff_cmd # # By default :samp:`ncflint` command is used to compute difference between NetCDF files # # If :samp:`cdo` is specified here, this command will be used instead. # # .. option:: --debug # # If this option is set, :samp:`ncdump -v time` will be added to log file # # .. option:: -b beginning date # .. option:: -e end date # # Put in ${PROJECT_ID} ERA-Intermin reference files. # # Log file is written on :file:`${PROJECT_LOG}/compute_erai_daily_region_2d.log.{YYYYMMDDTHHMMSSZ}` # # .. graphviz:: # # digraph compute_erai_daily_region_2d { # graph [ # rankdir="LR", # ] # filein_str [shape=ellipse,fontname=Courier,label="/bdd/ERAI/NETCDF/GLOBAL_075/4xdaily/FC_SF/yyyy/mm/str.yyyymmdd.fshei.GLOBAL_075.nc"]; # filein_msl [shape=ellipse,fontname=Courier,label="/bdd/ERAI/NETCDF/GLOBAL_075/4xdaily/AN_SF/yyyy/msl.yyyymm.ashei.GLOBAL_075.nc"]; # filein_sstk [shape=ellipse,fontname=Courier,label="/bdd/ERAI/NETCDF/GLOBAL_075/4xdaily/AN_SF/yyyy/sstk.yyyymm.ashei.GLOBAL_075.nc"]; # filein_t2 [shape=ellipse,fontname=Courier,label="/bdd/ERAI/NETCDF/GLOBAL_075/4xdaily/AN_SF/yyyy/t2.yyyymm.ashei.GLOBAL_075.nc"]; # filein_d2 [shape=ellipse,fontname=Courier,label="/bdd/ERAI/NETCDF/GLOBAL_075/4xdaily/AN_SF/yyyy/d2.yyyymm.ashei.GLOBAL_075.nc"]; # filein_u10 [shape=ellipse,fontname=Courier,label="/bdd/ERAI/NETCDF/GLOBAL_075/4xdaily/AN_SF/yyyy/u10.yyyymm.ashei.GLOBAL_075.nc"]; # filein_v10 [shape=ellipse,fontname=Courier,label="/bdd/ERAI/NETCDF/GLOBAL_075/4xdaily/AN_SF/yyyy/v10.yyyymm.ashei.GLOBAL_075.nc"]; # # fileout_str [shape=ellipse,fontname=Courier,label="${PROJECT_ID}/erai_TROP_1d_yyyy0101_yyyy1231_str_gridOrig.nc"]; # fileout_msl [shape=ellipse,fontname=Courier,label="${PROJECT_ID}/erai_TROP_1d_yyyy0101_yyyy1231_msl_gridOrig.nc"]; # fileout_sstk [shape=ellipse,fontname=Courier,label="${PROJECT_ID}/erai_TROP_1d_yyyy0101_yyyy1231_sstk_gridOrig.nc"]; # fileout_t2 [shape=ellipse,fontname=Courier,label="${PROJECT_ID}/erai_TROP_1d_yyyy0101_yyyy1231_t2_gridOrig.nc"]; # fileout_d2 [shape=ellipse,fontname=Courier,label="${PROJECT_ID}/erai_TROP_1d_yyyy0101_yyyy1231_d2_gridOrig.nc"]; # fileout_u10 [shape=ellipse,fontname=Courier,label="${PROJECT_ID}/erai_TROP_1d_yyyy0101_yyyy1231_u10_gridOrig.nc"]; # fileout_v10 [shape=ellipse,fontname=Courier,label="${PROJECT_ID}/erai_TROP_1d_yyyy0101_yyyy1231_v10_gridOrig.nc"]; # # compute_erai_daily_region_2d [shape=box, # fontname=Courier, # color=blue, # URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/compute_erai_daily_region_2d.sh", # label="${PROJECT}/src/compute_erai_daily_region_2d.sh"]; # # {filein_str filein_msl filein_sstk filein_t2 filein_d2 filein_u10 filein_v10} -> {compute_erai_daily_region_2d} -> {fileout_str fileout_msl fileout_sstk fileout_t2 fileout_d2 fileout_u10 fileout_v10} # # } # # .. caution:: # # Output files if exist are overwritten. # # EXAMPLES # ======== # # On climserv only if you don't have any ERA-I reference data, # you just have to run this tool :: # # $ compute_erai_daily_region_2d.sh -b 19890102 -e 20091231 # # And look at log file with :: # # $ tlogd.sh compute_erai_daily_region_2d # # and of course on files in ${PROJECT_ID}. # # SEE ALSO # ======== # # :ref:`guide data ERA-I ` # # http://climserv.ipsl.polytechnique.fr/fr/les-donnees/era-interim-4.html # for variables names # # :ref:`project_profile.sh` # # :func:`ncpdq ` # :func:`ncks ` # :func:`ncrcat ` # :func:`ncea ` # :func:`ncflint ` # # :func:`sub ` # :func:`divc ` # # :ref:`interp_erai_dewt_1989_2009.pro` # :ref:`interp_erai_lwr_1989_2009.pro` # :ref:`interp_erai_sst_1989_2009.pro` # :ref:`interp_erai_t2m_1989_2009.pro` # :ref:`interp_erai_ws_1989_2009.pro` # # TODO # ==== # # catalog # # improve log # # handle dd parameter : now from 1 to end of month # # adjust yyyymmddb_min and yyyymmddb_max # # trouble with cdo reference (extra %23name in generated url using sphinx1.0.7) # # minimize use of generic characters (*) to avoid ambiguity # # split get and process files # # coding rules # # correction of min and max values of latitude attributes (still -90,+90 !) in output files # # are cmonthmin and cmonthmax the real info to put in output file name ? may be not because if input files do not exist # # same idea for day min and max - some time hard coded with 01 or 31 (avoid yyyy0231 !!) # # solve this kind of warning:: # # ncrcat: WARNING Intra-file non-monotonicity. Record coordinate "time" does not monotonically decrease between (input file /homedata/pinsard/log//compute_erai_daily_region_2d.20110126T154235Z.temp//temp_int_str_199012.nc record indices: 29, 30) (output file /homedata/pinsard/tropflux_d//erai_TROP_1d_19900101_19901231_str_gridOrig.nc record indices 363, 364) record coordinate values -0.000278, -0.000278 # # this seems to be solved by using cdo instead of ncflint. to be confirmed ! # # no files *19890101* in /bdd/ERAI/NETCDF/GLOBAL_075/4xdaily/FC_SF/1989/01/ : # is it normal ? # # check units of str :: # # str:long_name = "Surface thermal radiation" ; # str:units = "W/m^2 s" # # still true after ncflint/cdo arithmetic ? # # Modify global attributes : Still CF ? no more "five time values per day " in Forecast attributes # # enrich info in log file # # EVOLUTIONS # ========== # # $URL$ # # - fplod 20110429T114649Z aedon.locean-ipsl.upmc.fr (Darwin) # # * add -b and -e parameters # # - fplod 20110203T101720Z aedon.locean-ipsl.upmc.fr (Darwin) # # * add cdo reference # # - pinsard 2011-02-02T16:11:07Z loholt1.ipsl.polytechnique.fr (Linux) # # * add parameter --debug # * add parameter --diff_cmd to choose between ncflint and cdo # * usage of :samp:`cdo sub` and :samp: cdo divc,86400.` if parameter --diff_cmd is set to cdo # thanks to https://code.zmaw.de/embedded/cdo/1.4.7/cdo.html#x1-2280002.7.4 # * add natural language explanation on ncflit usage provided by Matthieu # # - fplod 20110127T142038Z # # * correction of path of input files in header # # - fplod 20110126T132641Z # # * avoid ncrcat interactive question # * remove unused variables # * change GLOG to TROP (36N,36S) # * yearmax 2009 # * add a test of existence of monthly file (symetric to test on daily files) # # - fplod 20101223T084153Z aedon.locean-ipsl.upmc.fr (Darwin) # # * add reference to nco commands # # - fplod 20101220T150356Z aedon.locean-ipsl.upmc.fr# # # * indentation # * replace date by yyyy (date is a shell command) # * replace for yyyy by while yyyy # * replace for month by while month # * replace for day by while day # * work only on existing dates # # - fplod 20101220T142107Z aedon.locean-ipsl.upmc.fr (Darwin) # # * add Long name variables # * replace /bdd/IPCC/Reanalysis/ERAI/${reg}/ by ${TROPFLUX_ID} # * add examples # * add log management # * dirtemp not hard coded values # * check dirin permission # # - fplod 20101216T110626Z aedon.locean-ipsl.upmc.fr (Darwin) # # * add minimal header # * add graph in header # #- system=$(uname) case "${system}" in AIX|IRIX64) echo "www : no specific posix checking" date_cmd=date ;; Darwin) set -o posix date_cmd=gdate ;; Linux) set -o posix date_cmd=date ;; *) set -o posix ;; esac unset system # LANG=POSIX # command=$(basename ${0}) log_date=$(date -u +"%Y%m%dT%H%M%SZ") # usage=" Usage : ${command} [--debug] [--diff_cmd [ncflint|cdo]] -b yyyymmdd -e yyyymmdd" # hostname=$(hostname) # yyyymmddb_min=19890101 yyyymmdde_max=20091231 # # default diff_cmd=ncflint debug=0 yyyymmddb=19890101 yyyymmdde=20091231 minlat=-36. maxlat=36. minlon=0. maxlon=360. reg=TROP # minargcount=4 if [ ${#} -lt ${minargcount} ] then echo "${command} : eee : not enought arguments" echo "${usage}" exit 1 fi # set +u while [ ! -z "${1}" ] do case ${1} in --debug) debug=1 ;; --diff_cmd) diff_cmd=${2} shift ;; -b) # first date to get yyyymmddb=${2} shift ;; -e) # last date to get yyyymmdde=${2} shift ;; *) # anything else echo "${command} : eee : unknown option ${1}" echo "${command} : eee : ${usage}" exit 1 ;; esac # next flag shift done # set -u # check parameters # ${date_cmd} -d "${yyyymmddb}" > /dev/null status_date=${?} if [ ${status_date} -ne 0 ] then echo "${command} : eee : yyyymmddb ${yyyymmddb} argument invalid" exit 1 fi unset status_date # if [[ "${yyyymmddb}" < "${yyyymmddb_min}" ]] then echo "${command} : eee : yyyymmddb ${yyyymmddb} must be equal or greater than ${yyyymmddb_min}" exit 1 fi # ${date_cmd} -d "${yyyymmdde}" > /dev/null status_date=${?} if [ ${status_date} -ne 0 ] then echo "${command} : eee : yyyymmdde ${yyyymmdde} argument invalid" exit 1 fi unset status_date # if [[ "${yyyymmdde}" > "${yyyymmdde_max}" ]] then echo "${command} : eee : yyyymmdde ${yyyymmdde} must be lower or equal to ${yyyymmdde_max}" exit 1 fi # # if [[ "${yyyymmdde}" < "${yyyymmddb}" ]] then echo "${command} : eee : yyyymmdde ${yyyymmdde} must be equal or greater than yyyymmddb ${yyyymmddb}" exit 1 fi # # test if diff_cmd valid case ${diff_cmd} in ncflint) # test if ncflint available tool=ncflint type ${tool} 1> /dev/null 2>&1 status=${?} if [ ${status} -ne 0 ] then echo "${command} : eee : ${tool} not found" exit 1 fi unset status ;; cdo) # test if cdo available tool=cdo type ${tool} 1> /dev/null 2>&1 status=${?} if [ ${status} -ne 0 ] then echo "${command} : eee : ${tool} not found" exit 1 fi unset status ;; *) echo "${command} : eee : diff_cmd ${diff_cmd} argument invalid" exit 1 esac # check for ${PROJECT_LOG} definition if [ "${PROJECT_LOG}" = "" ] then echo "${command} : eee : \${PROJECT_LOG} not defined" exit 1 fi # # check for ${PROJECT_LOG} existence if [ ! -d ${PROJECT_LOG} ] then echo "${command} : eee : ${PROJECT_LOG} not found" exit 1 fi # # check for permission access on PROJECT_LOG if [ ! -x ${PROJECT_LOG} ] then echo "${command} : eee : ${PROJECT_LOG} not reachable" exit 1 fi # # check for write permission on PROJECT_LOG if [ ! -w ${PROJECT_LOG} ] then echo "${command} : eee : ${PROJECT_LOG} not writable" exit 1 fi # dirtemp=${PROJECT_LOG}/$(basename ${0} .sh).${log_date}.temp/ mkdir -p ${dirtemp} # log=${PROJECT_LOG}/$(basename ${0} .sh).log.${log_date} echo "[Context]" 1>> ${log} echo "command=$(basename ${0})" 1>>${log} echo "hostname=${hostname}" 1>> ${log} echo "runtime=${log_date}" 1>> ${log} unset log_date # echo "" 1>> ${log} echo "[Parameters]" 1>> ${log} echo "yyyymmddb=${yyyymmddb}" 1>> ${log} echo "yyyymmdde=${yyyymmdde}" 1>> ${log} echo "minlat=${minlat}" 1>> ${log} echo "maxlat=${maxlat}" 1>> ${log} echo "minlon=${minlon}" 1>> ${log} echo "maxlon=${maxlon}" 1>> ${log} echo "diff_cmd=${diff_cmd}" 1>> ${log} echo "" 1>> ${log} # yearmin=$(${date_cmd} -d "${yyyymmddb}" +%Y) yearmax=$(${date_cmd} -d "${yyyymmdde}" +%Y) monthmin=$(${date_cmd} -d "${yyyymmddb}" +%m) monthmax=$(${date_cmd} -d "${yyyymmdde}" +%m) cmonthmin=$(printf "%2.2d" ${monthmin}) cmonthmax=$(printf "%2.2d" ${monthmax}) dirin=/bdd/ERAI/NETCDF/GLOBAL_075/4xdaily/ # check for dirin existence if [ ! -d ${dirin} ] then echo "${command} : eee : ${dirin} not found" exit 1 fi # # check for permission access on dirin if [ ! -x ${dirin} ] then echo "${command} : eee : ${dirin} not reachable" exit 1 fi # # str = Surface thermal radiation for var in str ; do yyyy=${yearmin} while [ ${yyyy} -le ${yearmax} ] do month=${monthmin} while [ ${month} -le ${monthmax} ] do cmonth=$(printf "%2.2d" ${month}) daymin=1 daymax=$(cal ${month} ${yyyy} | grep . | fmt -1 | tail -1) day=${daymin} while [ ${day} -le ${daymax} ] do echo "iii : ${yyyy}${cmonth}${day}" cday=$(printf "%2.2d" ${day}) if [ -f ${dirin}/FC_SF/${yyyy}/${cmonth}/${var}.${yyyy}${cmonth}${cday}.fshei.GLOBAL_075.nc ] then if [ ${debug} -eq 1 ] then ncdump -v time ${dirin}/FC_SF/${yyyy}/${cmonth}/${var}.${yyyy}${cmonth}${cday}.fshei.GLOBAL_075.nc >> ${log} 2>&1 fi ncpdq -U ${dirin}/FC_SF/${yyyy}/${cmonth}/${var}.${yyyy}${cmonth}${cday}.fshei.GLOBAL_075.nc ${dirtemp}/${var}.${yyyy}${cmonth}${cday}.temp.GLOBAL_075.nc if [ ${debug} -eq 1 ] then ncdump -v time ${dirtemp}/${var}.${yyyy}${cmonth}${cday}.temp.GLOBAL_075.nc >> ${log} 2>&1 fi else echo "${command} : iii : no files ${dirin}/FC_SF/${yyyy}/${cmonth}/${var}.${yyyy}${cmonth}${cday}*" >> ${log} fi day=$(( ${day} + 1 )) done exist_temp_files=$(find ${dirtemp} -name "${var}.${yyyy}${cmonth}*temp*") if [ "${exist_temp_files}" != "" ] then # concatenation of daily files ncrcat -O ${dirtemp}/${var}.${yyyy}${cmonth}??.temp.GLOBAL_075.nc ${dirtemp}/${var}.${yyyy}${cmonth}.fshei.GLOBAL_075.nc if [ ${debug} -eq 1 ] then ncdump -v time ${dirtemp}/${var}.${yyyy}${cmonth}.fshei.GLOBAL_075.nc >> ${log} 2>&1 fi rm ${dirtemp}/${var}.${yyyy}${cmonth}??.temp.GLOBAL_075.nc 2> /dev/null ncks -d lat,${minlat},${maxlat} -d lon,${minlon},${maxlon} -d time,0,,5 ${dirtemp}/${var}.${yyyy}${cmonth}.fshei.GLOBAL_075.nc ${dirtemp}/temp_time0.nc if [ ${debug} -eq 1 ] then ncdump -v time ${dirtemp}/temp_time0.nc >> ${log} 2>&1 fi ncks -d lat,${minlat},${maxlat} -d lon,${minlon},${maxlon} -d time,4,,5 ${dirtemp}/${var}.${yyyy}${cmonth}.fshei.GLOBAL_075.nc ${dirtemp}/temp_time4.nc if [ ${debug} -eq 1 ] then ncdump -v time ${dirtemp}/temp_time4.nc >> ${log} 2>&1 fi case "${diff_cmd}" in ncflint) # différence entre les forcast a 36 et a 12h (pour avoir des flux par jour) et la constante suivant le -w permet de se ramener a des unites connues ncflint -w 1.1574074,-1.1574074 ${dirtemp}/temp_time0.nc ${dirtemp}/temp_time4.nc ${dirtemp}/temp_time.nc if [ ${debug} -eq 1 ] then ncdump -v time ${dirtemp}/temp_time.nc >> ${log} 2>&1 fi # La deuxieme permet uniquement de passer en seconde. 1.1574074*.00001=1/86400. (jour a seconde) ncflint -w 0.00001,0.0 ${dirtemp}/temp_time.nc ${dirtemp}/temp_time.nc ${dirtemp}/temp_int_${var}_${yyyy}${cmonth}.nc if [ ${debug} -eq 1 ] then ncdump -v time ${dirtemp}/temp_int_${var}_${yyyy}${cmonth}.nc >> ${log} 2>&1 fi ;; cdo) cdo sub ${dirtemp}/temp_time0.nc ${dirtemp}/temp_time4.nc ${dirtemp}/temp_time.nc >> ${log} 2>&1 if [ ${debug} -eq 1 ] then ncdump -v time ${dirtemp}/temp_time.nc >> ${log} 2>&1 fi cdo divc,86400. ${dirtemp}/temp_time.nc ${dirtemp}/temp_int_${var}_${yyyy}${cmonth}.nc >> ${log} 2>&1 if [ ${debug} -eq 1 ] then ncdump -v time ${dirtemp}/temp_int_${var}_${yyyy}${cmonth}.nc >> ${log} 2>&1 fi ;; esac rm ${dirtemp}/temp_time* 2> /dev/null rm ${dirtemp}/${var}.${yyyy}${cmonth}.fshei.GLOBAL_075.nc 2> /dev/null else echo "${command} : iii : no files ${dirtemp}/${var}.${yyyy}${cmonth}*temp*" >> ${log} fi unset exist_temp_files month=$(( ${month} + 1 )) done # concatenation of monthly files if [ ${debug} -eq 1 ] then ncdump -v time ${dirtemp}/temp_int_${var}_${yyyy}??.nc 1>> ${log} 2>&1 fi ncrcat -O ${dirtemp}/temp_int_${var}_${yyyy}??.nc ${PROJECT_ID}/erai_${reg}_1d_${yyyy}${cmonthmin}01_${yyyy}${cmonthmax}31_${var}_gridOrig.nc 1>> ${log} 2>&1 rm ${dirtemp}/temp_int_${var}_${yyyy}* 2> /dev/null yyyy=$(( ${yyyy} + 1 )) done done # # msl = Mean sea level pressure # sstk = Sea surface temperature # t2 = Temperature at 2 meters # d2 = Dew point at 2 meters # u10 = 10m U wind component # v10 = 10m V wind component for var in msl sstk t2 d2 u10 v10 ; do yyyy=${yearmin} while [ ${yyyy} -le ${yearmax} ] do month=${monthmin} while [ ${month} -le ${monthmax} ] do cmonth=$(printf "%2.2d" ${month}) if [ -f ${dirin}/AN_SF/${yyyy}/${var}.${yyyy}${cmonth}.ashei.GLOBAL_075.nc ] then ncpdq -U ${dirin}/AN_SF/${yyyy}/${var}.${yyyy}${cmonth}.ashei.GLOBAL_075.nc ${dirtemp}/${var}.${yyyy}${cmonth}.ashei.GLOBAL_075.nc ncks -d lat,${minlat},${maxlat} -d lon,${minlon},${maxlon} -d time,0,,4 ${dirtemp}/${var}.${yyyy}${cmonth}.ashei.GLOBAL_075.nc ${dirtemp}/temp_time1.nc ncks -d lat,${minlat},${maxlat} -d lon,${minlon},${maxlon} -d time,1,,4 ${dirtemp}/${var}.${yyyy}${cmonth}.ashei.GLOBAL_075.nc ${dirtemp}/temp_time2.nc ncks -d lat,${minlat},${maxlat} -d lon,${minlon},${maxlon} -d time,2,,4 ${dirtemp}/${var}.${yyyy}${cmonth}.ashei.GLOBAL_075.nc ${dirtemp}/temp_time3.nc ncks -d lat,${minlat},${maxlat} -d lon,${minlon},${maxlon} -d time,3,,4 ${dirtemp}/${var}.${yyyy}${cmonth}.ashei.GLOBAL_075.nc ${dirtemp}/temp_time4.nc ncea ${dirtemp}/temp_time* ${dirtemp}/temp_int_${yyyy}${cmonth}.nc rm ${dirtemp}/temp_time* 2> /dev/null rm ${dirtemp}/${var}.${yyyy}${cmonth}.ashei.GLOBAL_075.nc 2> /dev/null month=$(( ${month} + 1 )) else echo "${command} : iii : no file ${dirin}/AN_SF/${yyyy}/${var}.${yyyy}${cmonth}.ashei.GLOBAL_075.nc " >> ${log} fi done # concatenation of monthly files if [ ${debug} -eq 1 ] then ncdump -v time ${dirtemp}/temp_int_${yyyy}??.nc >> ${log} 2>&1 fi ncrcat -O ${dirtemp}/temp_int_${yyyy}??.nc ${PROJECT_ID}/erai_${reg}_1d_${yyyy}${cmonthmin}01_${yyyy}${cmonthmax}31_${var}_gridOrig.nc >> ${log} 2>&1 rm ${dirtemp}/temp_int_${yyyy}* 2> /dev/null yyyy=$(( ${yyyy} + 1 )) done done # debug to check if clean is done if [ ${debug} -eq 1 ] then ls ${dirtemp}/ >> ${log} 2>&1 fi # end exit 0