@@ -343,24 +343,39 @@ while [[ "$toDateUnix" -le "$endDateIterUnix" ]]; do
343
343
fileEndDateUnix=" $( unix_epoch " $fileEndDate " ) "
344
344
fi
345
345
346
- # Why the date is generated her?
347
346
# If fileEndDate goes beyond fileStartDate; continue
348
347
if [[ " $fileEndDateUnix " -lt " $fileStartDateUnix " ]]; then
349
348
break 1
350
349
fi
351
350
352
- # Extracting spatial extents and variables
353
- until cdo -z zip \
354
- -s -L \
355
- -sellonlatbox," $lonLims " ," $latLims " \
356
- -selvar," $variables " \
357
- -seldate," ${fileStartDate} " ," ${fileEndDate} " \
358
- " ${datasetDir} /${file} " \
359
- " ${cache} /${file} " ; do
360
- echo " $( logDate) $( basename $0 ) : Process killed: restarting process in 10 sec" >&2
361
- echo " CDO [...] failed" >&2
362
- sleep 10;
363
- done # until ncks
351
+ # If the filestartDate equals startDate, or if fileEndDate equals
352
+ # endDate then subset time as well, otherwise, no need for time
353
+ # subsetting (to save computational time)
354
+ if [[ ${fileStartDateUnix} == ${startDateUnix} ]] ||
355
+ [[ ${fileEndDateUnix} == ${endDateUnix} ]]; then
356
+ until cdo -z zip \
357
+ -s -L \
358
+ -sellonlatbox," $lonLims " ," $latLims " \
359
+ -selvar," $variables " \
360
+ -seldate," ${fileStartDate} " ," ${fileEndDate} " \
361
+ " ${datasetDir} /${file} " \
362
+ " ${cache} /${file} " ; do
363
+ echo " $( logDate) $( basename $0 ) : Process killed: restarting process in 10 sec" >&2
364
+ echo " CDO [...] failed" >&2
365
+ sleep 10;
366
+ done # until ncks
367
+ else
368
+ until cdo -z zip \
369
+ -s -L \
370
+ -sellonlatbox," $lonLims " ," $latLims " \
371
+ -selvar," $variables " \
372
+ " ${datasetDir} /${file} " \
373
+ " ${cache} /${file} " ; do
374
+ echo " $( logDate) $( basename $0 ) : Process killed: restarting process in 10 sec" >&2
375
+ echo " CDO [...] failed" >&2
376
+ sleep 10;
377
+ done # until ncks
378
+ fi
364
379
365
380
# Remove any left-over .tmp file
366
381
if [[ -e ${cache} /${file} * .tmp ]]; then
@@ -372,15 +387,23 @@ while [[ "$toDateUnix" -le "$endDateIterUnix" ]]; do
372
387
373
388
# Change lon values so the extents are from ~-180 to 0
374
389
# assuring the process finished using an `until` loop
375
- until ncap2 -O -s ' where(lon>0) lon=lon-360' \
390
+ until ncap2 -A -s ' where(lon>0) lon=lon-360' \
376
391
" ${cache} /${file} " \
377
- " ${outputDir } /${prefix}${file} " ; do
392
+ " ${cache } /${prefix}${file} " ; do
378
393
rm " ${outputDir} /${prefix}${file} "
379
394
echo " $( logDate) $( basename $0 ) : Process killed: restarting process in 10 sec" >&2
380
395
echo " $( logDate) $( basename $0 ) : NCAP2 -s [...] failed" >&2
381
396
sleep 10;
382
397
done
383
398
399
+ # Check to see if the final file exists in the $outputDir
400
+ if [[ -f " ${outputDir} /${prefix}${file} " ]]; then
401
+ ncrcat -O " ${cache} /${prefix}${file} " " ${outputDir} /${prefix}${file} " \
402
+ " ${outputDir} /${prefix}${file} " ;
403
+ else
404
+ cp " ${cache} /${prefix}${file} " " ${outputDir} /${prefix}${file} "
405
+ fi
406
+
384
407
# Remove any left-over .tmp file
385
408
if [[ -e ${cache} /${file} * .tmp ]]; then
386
409
rm -r " ${cache} /${file} *.tmp"
0 commit comments