Commits

Tom Roche committed 855ae97

driver tweaks noted while porting to CLM_CN. tested with uber_driver::file

  • Participants
  • Parent commits eef59bc

Comments (0)

Files changed (1)

 export MOLAR_MASS_N2O='44.0128' # grams per mole of N2O, per wolframalpha.com
 export MOLAR_MASS_N='14.0067'   # molar mass of N2 (per wolframalpha.com)/2
 
-# model/inventory constants
-export MODEL_YEAR='2008'
-export NOMINAL_GRIDCELL_AREA='1.440e8' # in meter^2, is a float ; stringtofloat(getenv("NOMINAL_GRIDCELL_AREA"))
-export MOLAR_MASS_N2O='44.0128'    # grams per mole of N2O, per wolframalpha.com
-export NITROGEN_MASS_N2O='28.0134' # grams per mole of N2,  per wolframalpha.com
-
 # for visualization (generally)
 export OUTPUT_SIGNIFICANT_DIGITS='3' # see conservation report below
 
 PLOT_FUNCS_FN='plotLayersForTimestep.r'
 export PLOT_FUNCS_FP="${WORK_DIR}/${PLOT_FUNCS_FN}"
 
-## helpers retrieved from elsewhere. TODO: R-package my code
-
-BASH_UTILS_URI='https://bitbucket.org/tlroche/gfed-3.1_global_to_aqmeii-na/raw/95484c5d63502ab146402cedc3612dcdaf629bd7/bash_utilities.sh'
-export BASH_UTILS_FN="$(basename ${BASH_UTILS_URI})"
+# BASH_UTILS_URI='https://bitbucket.org/tlroche/gfed-3.1_global_to_aqmeii-na/raw/95484c5d63502ab146402cedc3612dcdaf629bd7/bash_utilities.sh'
+# export BASH_UTILS_FN="$(basename ${BASH_UTILS_URI})"
+# in this repo
+export BASH_UTILS_FN='bash_utilities.sh'
 BASH_UTILS_FP="${WORK_DIR}/${BASH_UTILS_FN}"
 
-STATS_FUNCS_URI='https://bitbucket.org/tlroche/clm_cn_global_to_aqmeii-na/raw/53b5f09469e2426952eb83711f72961566e4932b/netCDF.stats.to.stdout.r'
+## helpers retrieved from elsewhere. TODO: R-package my code
+
+STATS_FUNCS_URI='https://bitbucket.org/tlroche/aqmeii_ag_soil/raw/0fa7d1180b67265540cdf0dd1d82e06d9b4fa789/netCDF.stats.to.stdout.r'
 # get base filename, ignoring query string (if any)
 STATS_FUNCS_FN="$(basename ${STATS_FUNCS_URI%%\?*})"
 export STATS_FUNCS_FP="${WORK_DIR}/${STATS_FUNCS_FN}"
 export GEIA_REFORMAT_PDF_FP="${WORK_DIR}/${GEIA_REFORMAT_PDF_FN}"
 export GEIA_REFORMAT_PDF_TITLE='GEIA annual oceanic N2O emissions'
 
-## Template for `raster` regridding.
+### Template for `raster` regridding.
 
 # The template input is a copy of some meteorological data with 52 "real" datavars.
 # That data is in the IOAPI format, which here is basically a wrapper around netCDF.
 # (IOAPI can be used with other data, and similar wrappers exist for other models.)
 # I removed all but one of the datavars (with NCO 'ncks'). TODO: script that!
-# TEMPLATE_INPUT_GZ_URI='https://bitbucket.org/tlroche/clm_cn_global_to_aqmeii-na/downloads/emis_mole_all_20080101_12US1_cmaq_cb05_soa_2008ab_08c.EXTENTS_INPUT.nc.gz' # no need for another copy
-# TEMPLATE_INPUT_GZ_FN="$(basename ${TEMPLATE_INPUT_GZ_URI})"
-# TEMPLATE_INPUT_GZ_FP="${WORK_DIR}/${TEMPLATE_INPUT_GZ_FN}"
-# TEMPLATE_INPUT_ROOT="${TEMPLATE_INPUT_GZ_FN%.*}" # everything left of the LAST dot
-# TEMPLATE_INPUT_FN="${TEMPLATE_INPUT_ROOT}"
-TEMPLATE_INPUT_URI='https://bitbucket.org/tlroche/geia_regrid/downloads/emis_mole_all_20080101_12US1_cmaq_cb05_soa_2008ab_08c.EXTENTS_INPUT.nc'
-TEMPLATE_INPUT_FN="$(basename ${TEMPLATE_INPUT_URI})"
-TEMPLATE_INPUT_FP="${WORK_DIR}/${TEMPLATE_INPUT_FN}"
-TEMPLATE_INPUT_ROOT="${TEMPLATE_INPUT_FN%.*}" # everything left of the LAST dot
+TEMPLATE_INPUT_GZ_URI='https://bitbucket.org/tlroche/clm_cn_global_to_aqmeii-na/downloads/emis_mole_all_20080101_12US1_cmaq_cb05_soa_2008ab_08c.EXTENTS_INPUT.nc.gz'
+TEMPLATE_INPUT_GZ_FN="$(basename ${TEMPLATE_INPUT_GZ_URI})"
+TEMPLATE_INPUT_GZ_FP="${WORK_DIR}/${TEMPLATE_INPUT_GZ_FN}"
+TEMPLATE_INPUT_ROOT="${TEMPLATE_INPUT_GZ_FN%.*}" # everything left of the LAST dot
+TEMPLATE_INPUT_FN="${TEMPLATE_INPUT_ROOT}"
 export TEMPLATE_INPUT_FP="${WORK_DIR}/${TEMPLATE_INPUT_FN}"
 # export TEMPLATE_INPUT_BAND='1' # `ncks` makes dim=TSTEP first
 export TEMPLATE_DATAVAR_NAME='emi_n2o'
   ; do
     if [[ -z "${CMD}" ]] ; then
       echo -e "${THIS_FN}::${FUNCNAME[0]}: ERROR: '${CMD}' not defined"
-      exit 1
+      exit 2
     else
       echo -e "\n$ ${THIS_FN}::${FUNCNAME[0]}::${CMD}\n"
       eval "${CMD}" # comment this out for NOPing, e.g., to `source`
   ; do
     if [[ -z "${CMD}" ]] ; then
       echo -e "${THIS_FN}::${FUNCNAME[0]}: ERROR: '${CMD}' not defined"
-      exit 1
+      exit 3
     else
       echo -e "\n$ ${THIS_FN}::${FUNCNAME[0]}::${CMD}\n"
       eval "${CMD}" # comment this out for NOPing, e.g., to `source`
 function get_map_table {
   if [[ -z "${MAP_TABLE_FP}" ]] ; then
     echo -e "${THIS_FN}: ERROR: MAP_TABLE_FP not defined"
-    exit 1
+    exit 4
   fi
   if [[ ! -r "${MAP_TABLE_FP}" ]] ; then
     for CMD in \
   fi
   if [[ ! -r "${MAP_TABLE_FP}" ]] ; then
     echo -e "${THIS_FN}: ERROR: cannot download MAP_TABLE_FP=='${MAP_TABLE_FP}'"
-    exit 2
+    exit 5
   fi
 } # end function get_map_table
 
 function get_geia_raw {
   if [[ -z "${GEIA_RAW_FP}" ]] ; then
     echo -e "${THIS_FN}: ERROR: GEIA_RAW_FP not defined"
-    exit 11
+    exit 6
   fi
   if [[ ! -r "${GEIA_RAW_FP}" ]] ; then
     for CMD in \
   fi
   if [[ ! -r "${GEIA_RAW_FP}" ]] ; then
     echo -e "${THIS_FN}: ERROR: cannot download GEIA_RAW_FP=='${GEIA_RAW_FP}'"
-    exit 12
+    exit 7
   fi
 } # end function get_geia_raw
 
+### get the "template" file, used for extent-setting and emissions-file creation
 function get_template_input {
   if [[ -z "${TEMPLATE_INPUT_FP}" ]] ; then
     echo -e "${THIS_FN}: ERROR: TEMPLATE_INPUT_FP not defined"
-    exit 13
+    exit 8
   fi
   if [[ ! -r "${TEMPLATE_INPUT_FP}" ]] ; then
-    for CMD in \
-      "wget --no-check-certificate -c -O ${TEMPLATE_INPUT_FP} ${TEMPLATE_INPUT_URI}" \
-    ; do
-      echo -e "$ ${CMD}"
-      eval "${CMD}"
-    done
+    if [[ ! -r "${TEMPLATE_INPUT_GZ_FP}" ]] ; then
+      for CMD in \
+	"${WGET_TO_FILE} ${TEMPLATE_INPUT_GZ_FP} ${TEMPLATE_INPUT_GZ_URI}" \
+      ; do
+	echo -e "$ ${CMD}"
+	eval "${CMD}"
+      done
+    fi
+    if [[ -r "${TEMPLATE_INPUT_GZ_FP}" ]] ; then
+      for CMD in \
+	"gunzip ${TEMPLATE_INPUT_GZ_FP}" \
+      ; do
+	echo -e "$ ${CMD}"
+	eval "${CMD}"
+      done
+    fi
   fi
   if [[ ! -r "${TEMPLATE_INPUT_FP}" ]] ; then
-    echo -e "${THIS_FN}: ERROR: cannot download TEMPLATE_INPUT_FP=='${TEMPLATE_INPUT_FP}'"
-    exit 14
+    echo -e "${THIS_FN}: ERROR: cannot read TEMPLATE_INPUT_FP=='${TEMPLATE_INPUT_FP}'"
+    exit 9
   fi
 } # end function get_template_input
 
 function put_geia_target_ncl {
   if [[ -z "${GEIA_TARGET_FP_NCL}" ]] ; then
     echo -e "${THIS_FN}: ERROR: GEIA_TARGET_FP_NCL not defined"
-    exit 15
+    exit 10
   fi
   if [[ -r "${GEIA_TARGET_FP_NCL}" ]] ; then
     # delete: NCL will recreate
   fi
   if [[ -r "${GEIA_TARGET_FP_NCL}" ]] ; then
     echo -e "${THIS_FN}: ERROR: cannot delete GEIA_TARGET_FP_NCL=='${GEIA_TARGET_FP_NCL}'"
-    exit 16
+    exit 11
   fi
 } # end function put_geia_target_ncl
 
 function put_geia_target_cmaq {
   if [[ -z "${GEIA_TARGET_FP_CMAQ}" ]] ; then
     echo -e "${THIS_FN}: ERROR: GEIA_TARGET_FP_CMAQ not defined"
-    exit 17
+    exit 12
   fi
   if [[ -r "${GEIA_TARGET_FP_CMAQ}" ]] ; then
     # delete: NCL will recreate
   fi
   if [[ -r "${GEIA_TARGET_FP_CMAQ}" ]] ; then
     echo -e "${THIS_FN}: ERROR: cannot delete GEIA_TARGET_FP_CMAQ=='${GEIA_TARGET_FP_CMAQ}'"
-    exit 18
+    exit 13
   fi
 } # end function put_geia_target_cmaq
 
 function get_geia_reformat {
   if [[ -z "${GEIA_REFORMAT_FP}" ]] ; then
     echo -e "${THIS_FN}: ERROR: GEIA_REFORMAT_FP not defined"
-    exit 1
+    exit 14
   fi
 # only for testing. TODO: flag control
 #   if [[ ! -r "${GEIA_REFORMAT_FP}" ]] ; then
 #   fi
 #   if [[ ! -r "${GEIA_REFORMAT_FP}" ]] ; then
 #     echo -e "${THIS_FN}: ERROR: cannot download GEIA_REFORMAT_FP=='${GEIA_REFORMAT_FP}'"
-#     exit 2
+#     exit 15
 #   fi
 } # end function get_geia_reformat
 
 function get_geia_regrid {
   if [[ -z "${GEIA_REGRID_FP}" ]] ; then
     echo -e "${THIS_FN}: ERROR: GEIA_REGRID_FP not defined"
-    exit 1
+    exit 16
   fi
 # only for testing. TODO: flag control
 #   if [[ ! -r "${GEIA_REGRID_FP}" ]] ; then
 #   fi
 #   if [[ ! -r "${GEIA_REGRID_FP}" ]] ; then
 #     echo -e "${THIS_FN}: ERROR: cannot download GEIA_REGRID_FP=='${GEIA_REGRID_FP}'"
-#     exit 2
+#     exit 17
 #   fi
 } # end function get_geia_regrid
 
 function get_bash_utils {
   if [[ -z "${BASH_UTILS_FP}" ]] ; then
     echo -e "${THIS_FN}: ERROR: BASH_UTILS_FP not defined"
-    exit 1
+    exit 18
   fi
   # in this repository
 #   if [[ ! -r "${BASH_UTILS_FP}" ]] ; then
 #   fi
   if [[ ! -r "${BASH_UTILS_FP}" ]] ; then
     echo -e "${THIS_FN}::${FUNCNAME[0]}: ERROR: BASH_UTILS_FP=='${BASH_UTILS_FP}' not readable"
-    exit 1
+    exit 19
   fi
   # This is bash, so gotta ...
   source "${BASH_UTILS_FP}"
 function get_plot_funcs {
   if [[ -z "${PLOT_FUNCS_FP}" ]] ; then
     echo -e "${THIS_FN}: ERROR: PLOT_FUNCS_FP not defined"
-    exit 1
+    exit 20
   fi
   # is in this repo
 #  if [[ ! -r "${PLOT_FUNCS_FP}" ]] ; then
 #  fi
   if [[ ! -r "${PLOT_FUNCS_FP}" ]] ; then
     echo -e "${THIS_FN}::${FUNCNAME[0]}: ERROR: PLOT_FUNCS_FP=='${PLOT_FUNCS_FP}' not readable"
-    exit 1
+    exit 21
   fi
 } # end function get_plot_funcs
 
 function get_stats_funcs {
   if [[ -z "${STATS_FUNCS_FP}" ]] ; then
     echo -e "${THIS_FN}: ERROR: STATS_FUNCS_FP not defined"
-    exit 1
+    exit 22
   fi
   if [[ ! -r "${STATS_FUNCS_FP}" ]] ; then
     for CMD in \
   fi
   if [[ ! -r "${STATS_FUNCS_FP}" ]] ; then
     echo -e "${THIS_FN}::${FUNCNAME[0]}: ERROR: STATS_FUNCS_FP=='${STATS_FUNCS_FP}' not readable"
-    exit 1
+    exit 23
   fi
 } # end function get_stats_funcs
 
 function get_summarize_funcs {
   if [[ -z "${SUMMARIZE_FUNCS_FP}" ]] ; then
     echo -e "${THIS_FN}: ERROR: SUMMARIZE_FUNCS_FP not defined"
-    exit 1
+    exit 24
   fi
   if [[ ! -r "${SUMMARIZE_FUNCS_FP}" ]] ; then
     for CMD in \
   fi
   if [[ ! -r "${SUMMARIZE_FUNCS_FP}" ]] ; then
     echo -e "${THIS_FN}::${FUNCNAME[0]}: ERROR: SUMMARIZE_FUNCS_FP=='${SUMMARIZE_FUNCS_FP}' not readable"
-    exit 1
+    exit 25
   fi
 } # end function get_summarize_funcs
 
 function get_time_funcs {
   if [[ -z "${TIME_FUNCS_FP}" ]] ; then
     echo -e "${THIS_FN}: ERROR: TIME_FUNCS_FP not defined"
-    exit 1
+    exit 26
   fi
   if [[ ! -r "${TIME_FUNCS_FP}" ]] ; then
     for CMD in \
   fi
   if [[ ! -r "${TIME_FUNCS_FP}" ]] ; then
     echo -e "${THIS_FN}::${FUNCNAME[0]}: ERROR: TIME_FUNCS_FP=='${TIME_FUNCS_FP}' not readable"
-    exit 1
+    exit 27
   fi
 } # end function get_time_funcs
 
 function get_vis_funcs {
   if [[ -z "${VIS_FUNCS_FP}" ]] ; then
     echo -e "${THIS_FN}: ERROR: VIS_FUNCS_FP not defined"
-    exit 1
+    exit 28
   fi
   if [[ ! -r "${VIS_FUNCS_FP}" ]] ; then
     for CMD in \
   fi
   if [[ ! -r "${VIS_FUNCS_FP}" ]] ; then
     echo -e "${THIS_FN}::${FUNCNAME[0]}: ERROR: VIS_FUNCS_FP=='${VIS_FUNCS_FP}' not readable"
-    exit 1
+    exit 29
   fi
 } # end function get_vis_funcs
 
 function get_reformat {
   if [[ -z "${CALL_REFORMAT_FP}" ]] ; then
     echo -e "${THIS_FN}: ERROR: CALL_REFORMAT_FP not defined"
-    exit 1
+    exit 30
   fi
   # is in this repo
 #  if [[ ! -r "${CALL_REFORMAT_FP}" ]] ; then
 #  fi
   if [[ ! -r "${CALL_REFORMAT_FP}" ]] ; then
     echo -e "${THIS_FN}::${FUNCNAME[0]}: ERROR: CALL_REFORMAT_FP=='${CALL_REFORMAT_FP}' not readable"
-    exit 1
+    exit 31
   fi
 } # end function get_reformat
 
 function get_regrid {
   if [[ -z "${CALL_REGRID_FP}" ]] ; then
     echo -e "${THIS_FN}: ERROR: CALL_REGRID_FP not defined"
-    exit 1
+    exit 32
   fi
   # is in this repo
 #  if [[ ! -r "${CALL_REGRID_FP}" ]] ; then
 #  fi
   if [[ ! -r "${CALL_REGRID_FP}" ]] ; then
     echo -e "${THIS_FN}::${FUNCNAME[0]}: ERROR: CALL_REGRID_FP=='${CALL_REGRID_FP}' not readable"
-    exit 1
+    exit 33
   fi
 } # end function get_regrid
 
 function get_retemp {
   if [[ -z "${CALL_RETEMP_FP}" ]] ; then
     echo -e "${THIS_FN}: ERROR: CALL_RETEMP_FP not defined"
-    exit 1
+    exit 34
   fi
   # is in this repo
 #  if [[ ! -r "${CALL_RETEMP_FP}" ]] ; then
 #  fi
   if [[ ! -r "${CALL_RETEMP_FP}" ]] ; then
     echo -e "${THIS_FN}::${FUNCNAME[0]}: ERROR: CALL_RETEMP_FP=='${CALL_RETEMP_FP}' not readable"
-    exit 1
+    exit 35
   fi
 } # end function get_retemp
 
 function get_conserv {
   if [[ -z "${CALL_CONSERV_FP}" ]] ; then
     echo -e "${THIS_FN}: ERROR: CALL_CONSERV_FP not defined"
-    exit 1
+    exit 36
   fi
   # is in this repo
 #  if [[ ! -r "${CALL_CONSERV_FP}" ]] ; then
 #  fi
   if [[ ! -r "${CALL_CONSERV_FP}" ]] ; then
     echo -e "${THIS_FN}::${FUNCNAME[0]}: ERROR: CALL_CONSERV_FP=='${CALL_CONSERV_FP}' not readable"
-    exit 1
+    exit 37
   fi
 } # end function get_conserv
 
   fi
   if [[ -r "${GEIA_TARGET_FP_TEMPLATE_NCL}" ]] ; then
     echo -e "${THIS_FN}: ERROR: cannot delete GEIA_TARGET_FP_TEMPLATE_NCL=='${GEIA_TARGET_FP_TEMPLATE_NCL}'"
-    exit 11
+    exit 38
   fi
 
   if [[ -r "${GEIA_TARGET_FP_NCL}" ]] ; then
   fi
   if [[ -r "${GEIA_TARGET_FP_NCL}" ]] ; then
     echo -e "${THIS_FN}: ERROR: cannot delete GEIA_TARGET_FP_NCL=='${GEIA_TARGET_FP_NCL}'"
-    exit 12
+    exit 39
   fi
 
   ### show new annual hourly files
 # ----------------------------------------------------------------------
 
 # should always
-# * begin with `setup` to do `module add`
+# * begin with `setup` to setup paths, apps, helpers, resources
 # * end with `teardown` for tidy and testing (e.g., plot display)
 for CMD in \
   'setup' \
 ; do
   if [[ -z "${CMD}" ]] ; then
     echo -e "${THIS_FN}::main loop: ERROR: '${CMD}' not defined"
-    exit 1
+    exit 40
   else
     echo -e "\n$ ${THIS_FN}::main loop: ${CMD}\n"
     eval "${CMD}" # comment this out for NOPing, e.g., to `source`