@@ -98,6 +98,8 @@ if [[ -z $prefix ]]; then
98
98
prefix=" data_"
99
99
fi
100
100
101
+ # useful log date format function
102
+ logDate () { echo " ($( date +" %Y-%m-%d %H:%M:%S" ) ) " ; }
101
103
102
104
# =====================
103
105
# Necessary assumptions
@@ -156,16 +158,29 @@ lims_to_float () { IFS=',' read -ra l <<< $@; f_arr=(); for i in "${l[@]}"; do f
156
158
# Data processing
157
159
# ===============
158
160
# display info
159
- echo " $( basename $0 ) : processing ECMWF ERA5..."
161
+ echo " $( logDate ) $( basename $0 ) : processing ECMWF ERA5..."
160
162
161
163
# make the output directory
162
- echo " $( basename $0 ) : creating output directory under $outputDir "
164
+ echo " $( logDate ) $( basename $0 ) : creating output directory under $outputDir "
163
165
mkdir -p " $outputDir "
164
166
167
+ # take care of dates
165
168
toDate=" $startDate "
166
169
toDateUnix=" $( unix_epoch " $toDate " ) "
167
170
endDateUnix=" $( unix_epoch " $endDate " ) "
168
171
172
+ # parse the upper and lower bounds of a given spatial limit
173
+ minLat=$( lims_to_float $latLims | cut -d ' ,' -f 1)
174
+ maxLat=$( lims_to_float $latLims | cut -d ' ,' -f 2)
175
+ minLon=$( lims_to_float $lonLims | cut -d ' ,' -f 1)
176
+ maxLon=$( lims_to_float $lonLims | cut -d ' ,' -f 2)
177
+
178
+ # adding/subtracting 0.1 degree to/from max/min values
179
+ minLat=$( bc <<< " $minLat - 0.25" )
180
+ maxLat=$( bc <<< " $maxLat + 0.25" )
181
+ minLon=$( bc <<< " $minLon - 0.25" )
182
+ maxLon=$( bc <<< " $maxLon + 0.25" )
183
+
169
184
# creating yearly directory
170
185
mkdir -p " $outputDir " # making the output directory
171
186
@@ -177,13 +192,17 @@ while [[ "$toDateUnix" -le "$endDateUnix" ]]; do
177
192
# creating file name
178
193
file=" ${fileStruct} _${toDateFormatted} .nc" # current file name
179
194
195
+ # wait to be trapped
196
+ trap ' wait' CHLD
197
+
180
198
# extracting variables from the files and spatial subsetting
181
- ncks -O -v " $variables " \
182
- -d latitude," $( lims_to_float " $latLims " ) " \
183
- -d longitude," $( lims_to_float " $lonLims " ) " \
184
- " ${datasetDir} /${file} " " ${outputDir} /${prefix}${file} "
199
+ ( ncks -O -v " $variables " \
200
+ -d latitude," ${minLat} , ${maxLat} " \
201
+ -d longitude," ${minLon} , ${maxLon} " \
202
+ " ${datasetDir} /${file} " " ${outputDir} /${prefix}${file} " ) &
185
203
186
- [ $( jobs | wc -l ) -ge $( nproc ) ] && wait # forking shell processes
204
+ # make sure ncks finishes
205
+ wait $!
187
206
188
207
# increment time-step by one unit
189
208
toDate=" $( date --date " $toDate 1month" ) " # current time-step
@@ -198,6 +217,6 @@ if [[ "$toDateUnix" == "$endOfCurrentYearUnix" ]]; then
198
217
toDate=$( date --date " $toDate 1month" )
199
218
fi
200
219
201
-
202
- echo " $( basename $0 ) : results are produced under $outputDir ."
220
+ # exit message
221
+ echo " $( logDate ) $( basename $0 ) : results are produced under $outputDir ."
203
222
0 commit comments