@@ -378,35 +378,57 @@ while [[ "$toDateUnix" -le "$endDateIterUnix" ]]; do
378
378
fi
379
379
380
380
# Remove any left-over .tmp file
381
- if [[ -e ${cache} /${file} * .tmp ]]; then
382
- rm -r " ${cache} /${file} *.tmp"
381
+ if [[ -e ${cache} /* ${file} * .tmp ]]; then
382
+ rm -r " ${cache} /* ${file} *.tmp"
383
383
fi
384
384
385
385
# Wait for any left-over processes to finish
386
386
wait
387
387
388
388
# Change lon values so the extents are from ~-180 to 0
389
389
# assuring the process finished using an `until` loop
390
- until ncap2 -A -s ' where(lon>0) lon=lon-360' \
390
+ until ncap2 -O -s ' where(lon>0) lon=lon-360' \
391
391
" ${cache} /${file} " \
392
- " ${cache} /${prefix} ${file}" ; do
393
- rm " ${outputDir} / ${prefix}${ file}"
392
+ " ${cache} /lon_ ${file} " ; do
393
+ rm " ${cache} /lon_ ${ file}* "
394
394
echo " $( logDate) $( basename $0 ) : Process killed: restarting process in 10 sec" >&2
395
395
echo " $( logDate) $( basename $0 ) : NCAP2 -s [...] failed" >&2
396
396
sleep 10;
397
397
done
398
398
399
399
# Check to see if the final file exists in the $outputDir
400
400
if [[ -f " ${outputDir} /${prefix}${file} " ]]; then
401
- ncrcat -O " ${cache} /${prefix}${file} " " ${outputDir} /${prefix}${file} " \
402
- " ${outputDir} /${prefix}${file} " ;
401
+ # If it already has 24 time-steps (complete file), skip it
402
+ tSteps=" $( cdo ntime " ${outputDir} /${prefix}${file} " | head -n 1) "
403
+
404
+ if [[ $tSteps != 24 ]]; then
405
+ # Copying the existing file to cache for further merging
406
+ cp " ${outputDir} /${prefix}${file} " " ${cache} /temp_${file} "
407
+
408
+ # Enable skipping duplicate time-steps
409
+ export SKIP_SAME_TIME=1
410
+
411
+ # Merging existing time-steps (temp_) with the extracted ones (lon_)
412
+ echo " $( logDate) $( basename $0 ) : WARNING! File ${prefix}${file} already exists in ${outputDir} " >&2 ;
413
+ echo " $( logDate) $( basename $0 ) : Merging missing time-steps" >&2 ;
414
+ cdo -O mergetime " ${cache} /lon_${file} " " ${cache} /temp_${file} " \
415
+ " ${cache} /merged_${file} " >&2 ;
416
+
417
+ # Copy the merged_ file to the $outputDir
418
+ cp " ${cache} /merged_${file} " " ${outputDir} /${prefix}${file} "
419
+
420
+ else
421
+ echo " $( logDate) $( basename $0 ) : ${prefix}${file} and all time-steps already exist, skipping" >&2 ;
422
+ fi
423
+
403
424
else
404
- cp " ${cache} /${prefix}${file} " " ${outputDir} /${prefix}${file} "
425
+ # Otherwise, copy whatever has been extracted
426
+ cp " ${cache} /lon_${file} " " ${outputDir} /${prefix}${file} "
405
427
fi
406
428
407
429
# Remove any left-over .tmp file
408
- if [[ -e ${cache} /${file} * .tmp ]]; then
409
- rm -r " ${cache} /${file} *.tmp"
430
+ if [[ -e ${cache} /* ${file} * .tmp ]]; then
431
+ rm -r " ${cache} /* ${file} *.tmp"
410
432
fi
411
433
412
434
# Wait for any left-over processes to finish
0 commit comments