@@ -343,24 +343,39 @@ while [[ "$toDateUnix" -le "$endDateIterUnix" ]]; do
343343 fileEndDateUnix=" $( unix_epoch " $fileEndDate " ) "
344344 fi
345345
346- # Why the date is generated her?
347346 # If fileEndDate goes beyond fileStartDate; continue
348347 if [[ " $fileEndDateUnix " -lt " $fileStartDateUnix " ]]; then
349348 break 1
350349 fi
351350
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
364379
365380 # Remove any left-over .tmp file
366381 if [[ -e ${cache} /${file} * .tmp ]]; then
@@ -372,15 +387,23 @@ while [[ "$toDateUnix" -le "$endDateIterUnix" ]]; do
372387
373388 # Change lon values so the extents are from ~-180 to 0
374389 # 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' \
376391 " ${cache} /${file} " \
377- " ${outputDir } /${prefix}${file} " ; do
392+ " ${cache } /${prefix}${file} " ; do
378393 rm " ${outputDir} /${prefix}${file} "
379394 echo " $( logDate) $( basename $0 ) : Process killed: restarting process in 10 sec" >&2
380395 echo " $( logDate) $( basename $0 ) : NCAP2 -s [...] failed" >&2
381396 sleep 10;
382397 done
383398
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+
384407 # Remove any left-over .tmp file
385408 if [[ -e ${cache} /${file} * .tmp ]]; then
386409 rm -r " ${cache} /${file} *.tmp"
0 commit comments