#! /bin/sh # #+ # # .. program:: add_19890101.sh # # .. _add_19890101.sh: # # =============== # add_19890101.sh # =============== # # SYNOPSIS # ======== # # .. code-block:: bash # # add_19890101.sh [--debug] # # DESCRIPTION # =========== # # .. option:: --debug # # If this option is set, :samp:`ncdump -v tt` will be added to log file # # Artificially add 19890101 to lwr interpolated on OAFLUX grid dataset. # # :file:`${PROJECT_OD}/erai_lwr_19890102_20091231_oafluxgrid.nc` # containing # ++ # has been produced by # :func:`interp_erai_lwr`. # repeat the first time step in # # File :file:`${PROJECT_OD}/erai_lwr_19890101_20091231_oafluxgrid.nc` # will be written # if this file not already exists. # # This output file # :file:`${PROJECT_OD}/erai_lwr_19890101_20091231_oafluxgrid.nc` # must be processed after by # :func:`lwr_correction_ncdf`. # # Log file is written on # :file:`${PROJECT_LOG}/add_19890101.sh.log.{YYYYMMDDTHHMMSS}Z`. # # .. graphviz:: # # digraph add_19890101 { # # filein [shape=ellipse, # fontname=Courier, # label="${PROJECT_OD}/erai_lwr_19890102_20091231_oafluxgrid.nc"]; # # fileout [shape=ellipse, # fontname=Courier, # label="${PROJECT_OD}/erai_lwr_19890101_20091231_oafluxgrid.nc"]; # # add_19890101 [shape=box, # fontname=Courier, # color=blue, # URL="http://forge.ipsl.jussieu.fr/tropflux/browser/trunk/src/add_19890101.sh", # label="${PROJECT}/src/add_19890101.sh"]; # # {filein} -> {add_19890101} -> {fileout} # # } # # EXAMPLES # ======== # # To produce ${PROJECT_OD}/erai_lwr_19890101_20091231_oafluxgrid.nc # from ${PROJECT_OD}/erai_lwr_19890102_20091231_oafluxgrid.nc : # # .. code-block:: bash # # add_19890101.sh --debug # # And look at log file with : # # .. code-block:: bash # # tlogd.sh add_19890101 # # and of course on files in ${PROJECT_OD}. # # TIPS # ==== # # To see the 3 first time values in input and files: # # .. code-block:: bash # # ncks -s "%16.10f\n" -v tt -d time,0,2 ${PROJECT_OD}/erai_lwr_19890102_20091231_oafluxgrid.nc # # .. parsed-literal:: # # 14246.0000000005 # 14247.0000000005 # 14248.0000000005 # # .. code-block:: bash # # ncks -s "%16.10f\n" -v tt -d time,0,2 ${PROJECT_OD}/erai_lwr_19890101_20091231_oafluxgrid.nc # # .. parsed-literal:: # # 14245.0000000005 # 14246.0000000005 # 14247.0000000005 # # while : # # .. code-block:: idl # # print, julday(01, 01, 1989,12)-julday(01, 01, 1950,0) # # .. parsed-literal:: # # 14245.500 # # .. code-block:: idl # # print, julday(01, 01, 1989,12)-julday(01, 01, 1950,0) +1 # # .. parsed-literal:: # # 14246.500 # # SEE ALSO # ======== # # :ref:`project_profile.sh` # # :func:`ncks ` # :func:`ncrcat ` # :func:`ncatted ` # :func:`ncap2 ` # # :ref:`lwr_correction_ncdf.pro` # # TODO # ==== # # coding rules # # won't it be more convenient to add this artificial time step in # the IDL creation tool interp_erai_lwr_1989_2009.pro. # It will allow to avoid a shell interruption in the IDL processing chain. # # improve global attributes with ... creation_date and so on # # check if the first time step is really 19890102 in the input file # # change tt to ttt to complete time correction # # remove hard coded end time # # get rid of this long message on cratos: # # .. parsed-literal:: # # ncrcat: WARNING Variable lwr has attribute "missing_value" but not "_FillValue". To # comply with netCDF conventions, NCO ignores values that equal the _FillValue attribu # te when performing arithmetic. Confusingly, values equal to the missing_value should # also be neglected. However, it is tedious and (possibly) computationally expensive # to check each value against multiple missing values during arithmetic on large varia # bles. So NCO thinks that processing variables with a "missing_value" attribute and n # o "_FillValue" attribute may produce undesired arithmetic results (i.e., where value # s that were intended to be neglected were not, in fact, neglected). We suggest you r # ename all "missing_value" attributes to "_FillValue" or include both "missing_value" # and "_FillValue" attributes (with the _same values_) for all variables that have ei # ther attribute. Because it is long, this message is only printed once per operator e # ven though multiple variables may have the same attribute configuration. More inform # ation on missing values is given at: # http://nco.sf.net/nco.html#mss_val # Examples of renaming attributes are at: # http://nco.sf.net/nco.html#xmp_ncrename # # ... on a déjà une idée de la solution : convention CF et meilleure gestion # des valeurs manquantes dans les softs IDL !!! # # EVOLUTIONS # ========== # # $Id$ # # $URL$ # # - fplod 20110819T091143Z aedon.locean-ipsl.upmc.fr (Darwin) # # * creation from pk email 20110811 "lwr first timestep" # * include time correction and timerange modification # #- 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 # set -u # command=$(basename ${0}) log_date=$(date -u +"%Y%m%dT%H%M%SZ") # usage=" Usage : ${command} [--debug]" # hostname=$(hostname) # # default debug=0 # minargcount=0 if [ ${#} -lt ${minargcount} ] then echo "${command} : eee : not enought arguments" echo "${usage}" exit 1 fi # while [ ${#} -gt 0 ] do case ${1} in --debug) debug=1 ;; *) # anything else echo "${command} : eee : unknown option ${1}" echo "${command} : eee : ${usage}" exit 1 ;; esac # next flag shift done # # check parameters # N.A. # tool=ncrcat type ${tool} 1> /dev/null 2>&1 status=${?} if [ ${status} -ne 0 ] then echo "${command} : eee : tool ${tool} not found" exit 1 fi unset status unset tool # tool=ncks type ${tool} 1> /dev/null 2>&1 status=${?} if [ ${status} -ne 0 ] then echo "${command} : eee : tool ${tool} not found" exit 1 fi unset status unset tool # tool=ncatted type ${tool} 1> /dev/null 2>&1 status=${?} if [ ${status} -ne 0 ] then echo "${command} : eee : tool ${tool} not found" exit 1 fi unset status unset tool # # 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 # 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} echo "log=${log}" 1>> ${log} unset log_date # echo "" 1>> ${log} echo "[Parameters]" 1>> ${log} echo "N.A." 1>> ${log} echo "" 1>> ${log} # filein=${PROJECT_OD}/erai_lwr_19890102_20091231_oafluxgrid.nc if [ ! -f ${filein} ] then echo " eee : ${filein} not found" 1>> ${log} exit 1 fi fileout=${PROJECT_OD}/erai_lwr_19890101_20091231_oafluxgrid.nc if [ -f ${fileout} ] then echo "eee : ${fileout} already exists" 1>>${log} exit 1 fi # rm -f ${PROJECT_OD}/erai_lwr_step19890101.nc 2> /dev/null rm -f ${PROJECT_OD}/erai_lwr_step19890102.nc 2> /dev/null # # extraction of the first time step 19890102 ncks -h -d time,0,0 ${filein} ${PROJECT_OD}/erai_lwr_step19890102.nc >> ${log} 2>&1 status=${?} if [ ${status} -ne 0 ] then echo "eee : pb with ncks" >> ${log} 2>&1 ncdump -h ${filein} >> ${log} 2>&1 exit 1 fi unset status # # ++ check if tt[0] is really 19890102 # # subtract 1 to tt to simulate 19890101 ncap2 -h -s "tt=tt-1" \ ${PROJECT_OD}/erai_lwr_step19890102.nc \ ${PROJECT_OD}/erai_lwr_step19890101.nc status=${?} if [ ${status} -ne 0 ] then echo "eee : pb with ncap2" >> ${log} 2>&1 ncdump -h ${PROJECT_OD}/erai_lwr_step19890102.nc >> ${log} 2>&1 exit 1 fi unset status ls -l ${PROJECT_OD}/erai_lwr_step19890102.nc >> ${log} 2>&1 ls -l ${PROJECT_OD}/erai_lwr_step19890101.nc >> ${log} 2>&1 # # ++ check if tt[0] is really 19890101 # rm ${fileout}_bad_timerange 2> /dev/null ncrcat -h \ ${PROJECT_OD}/erai_lwr_step19890101.nc \ ${filein} \ ${fileout}_bad_timerange >> ${log} 2>&1 status=${?} if [ ${status} -ne 0 ] then echo "eee : pb with ncrcat" >> ${log} 2>&1 ncdump -h ${PROJECT_OD}/erai_lwr_step19890101.nc >> ${log} 2>&1 ncdump -h ${filein} >> ${log} 2>&1 exit 1 fi unset status # ncatted -h -a timerange,global,o,c,"19890101 - 20091231" \ ${fileout}_bad_timerange \ ${fileout} >> ${log} 2>&1 status=${?} if [ ${status} -ne 0 ] then echo "eee : pb with ncatted" >> ${log} 2>&1 ncdump -h ${fileout}_bad_timerange >> ${log} 2>&1 exit 1 fi unset status # if [ ${debug} -eq 1 ] then ncdump -v tt ${fileout} >> ${log} 2>&1 fi # # cleaning #++rm -f ${PROJECT_OD}/erai_lwr_step19890101.nc 2> /dev/null #++rm -f ${PROJECT_OD}/erai_lwr_step19890102.nc 2> /dev/null #++rm -f ${PROJECT_OD}/${fileout}_bad_timerange 2> /dev/null # unset fileout unset filein #++ set # end exit 0