-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtas2temp
executable file
·61 lines (44 loc) · 1.49 KB
/
tas2temp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/tcsh
## This script converts netcdf files with temperatures in Kelvin (K)
## to Celsius (degC) by subtracting 273.15. Only the first
## temperature variable found is converted.
## The variable name is determined by grepping the input file header
## for a variable with the appropriate units for conversion.
## If no output filename is specified, a default filename is
## constructed by substitution on the input filename as follows:
## s/tasmin/tmin/
## s/tasmax/tmax/
## s/tas/temp/
## The resulting output file is placed in the same directory
## as the input file.
set prog = `basename $0`
if ($#argv < 1 || $#argv > 2) then
echo "Usage: $prog infile [outfile]"
exit 1
endif
set infile = $1
if ($#argv == 2) then
set outfile = $2
else
set outfile = `dirname $infile`/`basename $infile | \
sed -s 's/tasmin/tmin/;s/tasmax/tmax/;s/tas/temp/'`
endif
set v = `ncdump -h $infile | grep units | grep '= \"K\"' \
| head -1 | cut -f 1 -d : | awk '{print $1}'`
if ($v == "") then
echo ${prog}: no temperature variable found with units = \"K\"
exit 2
endif
ncap2 -O -s "$v=$v-float(273.15)" \
-s $v'@units="degC"' \
$infile $outfile
if ($v == "tasmax") then
ncrename -v $v,tmax $outfile
else if ($v == "tasmin") then
ncrename -v $v,tmin $outfile
else
ncrename -v $v,temp $outfile
endif
ncatted -h -a tracking_id,global,o,c,`uuidgen` $outfile
# Copyright 2010-2018 Univ. Corp. for Atmos. Research
# Author: Seth McGinnis, [email protected]