3
3
#
4
4
# usage: srv_downsampler.sh recipe.
5
5
# where
6
- # recipe: The name of the recipe file (e.g., earth_relief.recipe )
6
+ # recipe: The name of the recipe file (e.g., earth_relief)
7
7
#
8
8
# These recipe files contain meta data such as where to get the highest-resolution
9
9
# master file from which to derive the lower-resolution versions, information about
34
34
cd ${TOPDIR} /staging
35
35
36
36
# 2. Get recipe full file path
37
- RECIPE=$TOPDIR /recipes/$1
37
+ RECIPE=$TOPDIR /recipes/$1 .recipe
38
38
if [ ! -f $RECIPE ]; then
39
39
echo " error: srv_downsampler.sh: Recipe $RECIPE not found"
40
40
exit -1
@@ -56,6 +56,7 @@ source /tmp/par.sh
56
56
# 4. Get the file name of the source file
57
57
SRC_BASENAME=` basename ${SRC_FILE} `
58
58
SRC_ORIG=${SRC_BASENAME}
59
+
59
60
# 5. Determine if this source is an URL and if we need to download it first
60
61
is_url=` echo ${SRC_FILE} | grep -c :`
61
62
if [ $is_url ]; then # Data source is an URL
@@ -66,8 +67,17 @@ if [ $is_url ]; then # Data source is an URL
66
67
SRC_FILE=${SRC_BASENAME}
67
68
fi
68
69
69
- # 6. Extract the requested resolutions
70
+ # 6. Extract the requested resolutions and registrations
71
+
70
72
grep -v ' ^#' $RECIPE > /tmp/res.lis
73
+ DST_NODES=$( echo $DST_NODES | tr ' ,' ' ' )
74
+ REG=$( gmt grdinfo ${SRC_FILE} -Cn -o10)
75
+ if [ $REG -eq 0 ]; then
76
+ SRC_REG=g
77
+ else
78
+ SRC_REG=p
79
+ fi
80
+
71
81
# 7. Replace underscores with spaces in the title and remark
72
82
TITLE=` echo ${SRC_TITLE} | tr ' _' ' ' `
73
83
REMARK=` echo ${SRC_REMARK} | tr ' _' ' ' `
@@ -100,25 +110,28 @@ while read RES UNIT CHUNK MASTER; do
100
110
if [ ! ${RES} = " 01" ]; then # Use plural unit
101
111
UNIT_NAME=" ${UNIT_NAME} s"
102
112
fi
103
- DST_FILE=${DST_PREFIX} _${RES}${UNIT} .grd
104
- grdtitle=" ${TITLE} at ${RES} arc ${UNIT_NAME} "
105
- # Note: The ${SRC_ORIG/+/\\+} below is to escape any plus-symbols in the file name with a backslash so grdedit -D will work
106
- if [ -f ${DST_FILE} ]; then # Do nothing
107
- echo " ${DST_FILE} exist - skipping"
108
- elif [ " X${MASTER} " = " Xmaster" ]; then # Just make a copy of the master
109
- echo " Convert ${SRC_FILE} to ${DST_FILE} =${DST_FORMAT} "
110
- gmt grdconvert ${SRC_FILE} ${DST_FILE} =${DST_FORMAT} --IO_NC4_DEFLATION_LEVEL=9
111
- remark=" Reformatted from master file ${SRC_ORIG/ +/ \\ +} [${REMARK} ]"
112
- gmt grdedit ${DST_FILE} -D+t" ${grdtitle} " +r" ${remark} " +z" ${SRC_NAME} (${SRC_UNIT} )"
113
-
114
- else # Must downsample to a lower resolution via spherical Gaussian filtering
115
- # Get suitable Gaussian full-width filter rounded to nearest 0.1 km after adding 50 meters for noise
116
- echo " Down-filter ${SRC_FILE} to ${DST_FILE} =${DST_FORMAT} "
117
- FILTER_WIDTH=` gmt math -Q ${SRC_RADIUS} 2 MUL PI MUL 360 DIV $INC MUL 0.05 ADD 10 MUL RINT 10 DIV =`
118
- gmt grdfilter ${SRC_FILE} -Fg${FILTER_WIDTH} -D${FMODE} -I${RES}${UNIT} -r${DST_NODES} -G${DST_FILE} =${DST_FORMAT} --IO_NC4_DEFLATION_LEVEL=9 --IO_NC4_CHUNK_SIZE=${CHUNK} --PROJ_ELLIPSOID=Sphere
119
- remark=" Obtained by Gaussian ${DST_MODE} filtering (${FILTER_WIDTH} km fullwidth) from ${SRC_FILE/ +/ \\ +} [${REMARK} ]"
120
- gmt grdedit ${DST_FILE} -D+t" ${grdtitle} " +r" ${remark} " +z" ${SRC_NAME} (${SRC_UNIT} )"
121
- fi
113
+ for REG in ${DST_NODES} ; do # Probably doing both pixel and gridline registered output, except for master */
114
+ DST_FILE=${DST_PREFIX} _${RES}${UNIT} _${REG} .grd
115
+ grdtitle=" ${TITLE} at ${RES} arc ${UNIT_NAME} "
116
+ # Note: The ${SRC_ORIG/+/\\+} below is to escape any plus-symbols in the file name with a backslash so grdedit -D will work
117
+ if [ -f ${DST_FILE} ]; then # Do nothing
118
+ echo " ${DST_FILE} exist - skipping"
119
+ elif [ " X${MASTER} " = " Xmaster" ]; then # Just make a copy of the master to a new output file
120
+ if [ ${REG} = ${SRC_REG} ]; then # Only do the matching node registration for master
121
+ echo " Convert ${SRC_FILE} to ${DST_FILE} =${DST_FORMAT} "
122
+ gmt grdconvert ${SRC_FILE} ${DST_FILE} =${DST_FORMAT} --IO_NC4_DEFLATION_LEVEL=9
123
+ remark=" Reformatted from master file ${SRC_ORIG/ +/ \\ +} [${REMARK} ]"
124
+ gmt grdedit ${DST_FILE} -D+t" ${grdtitle} " +r" ${remark} " +z" ${SRC_NAME} (${SRC_UNIT} )"
125
+ fi
126
+ else # Must down-sample to a lower resolution via spherical Gaussian filtering
127
+ # Get suitable Gaussian full-width filter rounded to nearest 0.1 km after adding 50 meters for noise
128
+ echo " Down-filter ${SRC_FILE} to ${DST_FILE} =${DST_FORMAT} "
129
+ FILTER_WIDTH=` gmt math -Q ${SRC_RADIUS} 2 MUL PI MUL 360 DIV $INC MUL 0.05 ADD 10 MUL RINT 10 DIV =`
130
+ gmt grdfilter ${SRC_FILE} -Fg${FILTER_WIDTH} -D${FMODE} -I${RES}${UNIT} -r${REG} -G${DST_FILE} =${DST_FORMAT} --IO_NC4_DEFLATION_LEVEL=9 --IO_NC4_CHUNK_SIZE=${CHUNK} --PROJ_ELLIPSOID=Sphere
131
+ remark=" Obtained by Gaussian ${DST_MODE} filtering (${FILTER_WIDTH} km fullwidth) from ${SRC_FILE/ +/ \\ +} [${REMARK} ]"
132
+ gmt grdedit ${DST_FILE} -D+t" ${grdtitle} " +r" ${remark} " +z" ${SRC_NAME} (${SRC_UNIT} )"
133
+ fi
134
+ done
122
135
done < /tmp/res.lis
123
136
# 10. Clean up /tmp
124
137
rm -f /tmp/res.lis /tmp/par.sh
0 commit comments