Last active
December 21, 2015 03:29
-
-
Save guziy/6242624 to your computer and use it in GitHub Desktop.
Correcting files using NCO utilities (namely: ncatted and ncap2)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
folder=. | |
prefix=ANUSPLIN_latlon_stmn_ | |
var_name=daily_minimum_temperature | |
for x in ${folder}/${prefix}*.nc | |
do | |
x_name=$(basename $x) | |
part=$(echo $x_name | cut -d"." -f 1) | |
#get the year and month from the file name | |
y=$(echo $part | cut -d"_" -f 4) | |
m=$(echo $part | cut -d"_" -f 5) | |
#change time units | |
ncatted -O -a units,time,m,c,"days since ${y}-${m}-01" $x | |
# decrement the time values so they start from 0 | |
ncap2 -O -s "time=time-1;" $x -o $x | |
#replace NaNs with a value specified in the missing_value attribute | |
ncap2 -O -s "where(${var_name} != ${var_name}){${var_name}=${var_name}@missing_value;}" $x -o $x | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment