-
Notifications
You must be signed in to change notification settings - Fork 0
/
io_obs.ncl
140 lines (132 loc) · 3.71 KB
/
io_obs.ncl
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
load "$DIAGDIR/dict_obs.ncl"
undef("gauswgt_txt")
undef("gauswgt_nc")
undef("read_obs_2d")
undef("read_obs_3d")
undef("read_obs_ty")
undef("read_obs_tr")
undef("calc_obs_2d")
levfact_obs = 1
function gauswgt_txt(ny)
local ns, fname
begin
ns = (ny*2-1)/3
fname = "T"+ns+"_wgt.txt"
if (isfilepresent("T"+ns+"_wgt.txt")) then
gw = asciiread(fname, ny, "float")
else
gauinfo = gaus(ny/2)
gw = doubletofloat(gauinfo(:,1))
asciiwrite(fname, gw)
end if
return gw
end
function gauswgt_nc(fname)
begin
f = addfile(fname, "r")
return f->gw
delete(f)
end
function read_obs_2d(fname, varname)
local f
begin
f = addfile(fname, "r")
obs_varname = obs_varname@$varname$
d = f->$obs_varname$(0,:,:)
return d
delete(f)
end
function read_obs_3d(fname, varname)
local f
begin
f = addfile(fname, "r")
obs_varname = obs_varname@$varname$
d = f->$obs_varname$(0,:,:,:)
return d
delete(f)
end
function read_obs_ty(fname, varname, l)
local t, f
begin
nt = 12
obs_varname = obs_varname@$varname$
f = addfile(fname+"01_climo.nc", "r")
d = new((/nt,dimsizes(f->lat)/), "float")
d!0 = "time"
d!1 = "lat"
d&lat = f->lat
d&time = ispan(1, 12, 1)
d@long_name = f->$obs_varname$@long_name
d@units = f->$obs_varname$@units
d@_FillValue = f->$obs_varname$@_FillValue
delete(f)
do t=0, nt-1
f = addfile(fname+sprinti("%0.2i",t+1)+"_climo.nc", "r")
if (l.eq.0) then
d(t,:) = (/ dim_avg(f->$obs_varname$(0,:,:)) /)
else
d(t,:) = (/ dim_avg(f->$obs_varname$(0,{l*levfact_obs},:,:)) /)
end if
delete(f)
end do
return d
end
procedure read_obs_tr(fname:string,lat[*]:numeric,oht[*][*]:numeric,aht[*][*]:numeric)
local lat, ny, j65N, j65S, buf
begin
j65S = 7
j65N = 56
ny = dimsizes(lat)
buf = asciiread(fname,(/ny,22/),"integer")
lat = buf(::-1,0)*0.01
lat!0 = "lat"
lat&lat = lat
oht(0,:) = buf(::-1,8)*0.01 ; Pacific Ocean
oht(1,:) = buf(::-1,7)*0.01 ; Atlantic Ocean
oht(1,j65N:) = oht@_FillValue ; Set to missing > 65N
oht(2,:) = buf(::-1,9)*0.01 ; Indian Ocean
oht(3,:) = buf(::-1,4)*0.01 ; World Ocean
oht(3,:j65S) = oht@_FillValue ; Set to missing < 65S
oht(3,j65N:) = oht@_FillValue ; Set to missing > 65N
aht(0,:) = buf(::-1,1)*0.01 ; RHT (ERBE TOA)
aht(1,:) = aht(0,:) - oht(3,:) ; AHT = RHT (ERBE TOA) - OHT
aht(2,:) = oht(3,:) ; OHT
end
function calc_obs_2d(fname:string,varname:string,obsdir:string,tstr:string)
local ofname
begin
seasons = (/"ANN", "MAM", "JJA", "SON", "DJF", "MON"/)
if (varname.eq."RT") then
ofname = obsdir+"/"+"ERBE_"+tstr+"_climo.nc"
rt = read_obs_2d(ofname, "OSR")
rt = (/rt-read_obs_2d(ofname, "OLR")/)
rt@long_name = "TOA rad flux down"
return rt
end if
if (varname.eq."FS") then
ofname = obsdir+"/"+"ISCCPFD_"+tstr+"_climo.nc"
fs = read_obs_2d(ofname, "SSR")
fs = (/-fs+read_obs_2d(ofname, "SLR")/)
ofname = obsdir+"/"+"ECMWF_"+tstr+"_climo.nc"
fs = (/fs+read_obs_2d(ofname, "EVAP")/)
ofname = obsdir+"/"+"NCEP_"+tstr+"_climo.nc"
fs = (/fs+read_obs_2d(ofname, "SENS")/)
fs@long_name = "sfc flux up"
return fs
end if
if (varname.eq."RTFS") then
ofname = obsdir+"/"+"ERBE_"+tstr+"_climo.nc"
rtfs = read_obs_2d(ofname, "OSR")
rtfs = (/rtfs-read_obs_2d(ofname, "OLR")/)
ofname = obsdir+"/"+"ISCCPFD_"+tstr+"_climo.nc"
rtfs = (/rtfs-read_obs_2d(ofname, "SSR")/)
rtfs = (/rtfs+read_obs_2d(ofname, "SLR")/)
ofname = obsdir+"/"+"ECMWF_"+tstr+"_climo.nc"
rtfs = (/rtfs+read_obs_2d(ofname, "EVAP")/)
ofname = obsdir+"/"+"NCEP_"+tstr+"_climo.nc"
rtfs = (/rtfs+read_obs_2d(ofname, "SENS")/)
rtfs@long_name = "residual flux"
return rtfs
end if
return read_obs_2d(fname,varname)
end