forrest@0
|
1 |
;************************************************
|
forrest@0
|
2 |
; Read half-hourly data and write monthly data
|
forrest@0
|
3 |
; input data is : half-hourly
|
forrest@0
|
4 |
;
|
forrest@0
|
5 |
; output data is : CO2_flux, RAD_FLUX, SH_FLUX, LH_FLUX
|
forrest@0
|
6 |
; date, lat, lon
|
forrest@0
|
7 |
;************************************************
|
forrest@0
|
8 |
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
|
forrest@0
|
9 |
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
|
forrest@0
|
10 |
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
|
forrest@0
|
11 |
;************************************************
|
forrest@0
|
12 |
begin
|
forrest@0
|
13 |
|
forrest@0
|
14 |
dir_root = "/fis/cgd/cseg/people/jeff/clamp_data/fluxnet/"
|
forrest@0
|
15 |
station_name = "BOREAS_NSA_OBS"
|
forrest@0
|
16 |
file_name_add = "ameriflux"
|
forrest@0
|
17 |
year_start = 1994
|
forrest@0
|
18 |
year_end = 2004
|
forrest@0
|
19 |
year_leap1 = 1996
|
forrest@0
|
20 |
year_leap2 = 2000
|
forrest@0
|
21 |
year_leap3 = 2004
|
forrest@0
|
22 |
|
forrest@0
|
23 |
lat_out = 55.879620
|
forrest@0
|
24 |
lon_out = -98.480810 + 360.
|
forrest@0
|
25 |
|
forrest@0
|
26 |
; final output
|
forrest@0
|
27 |
diro = dir_root + station_name + "/"
|
forrest@0
|
28 |
filo = station_name+"_"+year_start+"-"+year_end+"_monthly.nc"
|
forrest@0
|
29 |
c = addfile(diro+filo,"c")
|
forrest@0
|
30 |
print (filo)
|
forrest@0
|
31 |
|
forrest@0
|
32 |
; input dir
|
forrest@0
|
33 |
diri = dir_root + station_name + "/"
|
forrest@0
|
34 |
|
forrest@0
|
35 |
nyear = year_end - year_start + 1
|
forrest@0
|
36 |
nmon = 12
|
forrest@0
|
37 |
nlat = 1
|
forrest@0
|
38 |
nlon = 1
|
forrest@0
|
39 |
|
forrest@0
|
40 |
; day_of_month = (/31.,28.,31.,30.,31.,30.,31.,31.,30.,31.,30.,31./)
|
forrest@0
|
41 |
end_of_month1 = (/31.,59.,90.,120.,151.,181.,212.,243.,273.,304.,334.,365./)
|
forrest@0
|
42 |
end_of_month2 = (/31.,60.,91.,121.,152.,182.,213.,244.,274.,305.,335.,366./)
|
forrest@0
|
43 |
|
forrest@0
|
44 |
data_out1 = new((/nyear,nmon/),float)
|
forrest@0
|
45 |
data_out2 = new((/nyear,nmon/),float)
|
forrest@0
|
46 |
data_out3 = new((/nyear,nmon/),float)
|
forrest@0
|
47 |
data_out4 = new((/nyear,nmon/),float)
|
forrest@0
|
48 |
time_out = new((/nyear,nmon/),integer)
|
forrest@0
|
49 |
|
forrest@0
|
50 |
do m = 0,nyear-1
|
forrest@0
|
51 |
year = year_start + m
|
forrest@0
|
52 |
|
forrest@0
|
53 |
; if (mod(year,4) .eq. 0) then
|
forrest@0
|
54 |
if (year.eq.year_leap1.or.year.eq.year_leap2.or.year.eq.year_leap3) then
|
forrest@0
|
55 |
hour_of_month = end_of_month2 * 24.
|
forrest@0
|
56 |
else
|
forrest@0
|
57 |
hour_of_month = end_of_month1 * 24.
|
forrest@0
|
58 |
end if
|
forrest@0
|
59 |
; print (hour_of_month)
|
forrest@0
|
60 |
|
forrest@0
|
61 |
; input file
|
forrest@0
|
62 |
fili = file_name_add+"."+station_name+"."+year+".nc"
|
forrest@0
|
63 |
b = addfile(diri+fili,"r")
|
forrest@0
|
64 |
print (fili)
|
forrest@0
|
65 |
|
forrest@0
|
66 |
; co2 flux unit: umol m-2 s-1
|
forrest@0
|
67 |
data1 = b->FCO2M
|
forrest@0
|
68 |
; net radiation flux unit: W m-2
|
forrest@0
|
69 |
data2 = b->RN
|
forrest@0
|
70 |
; sensible heat flux unit: W m-2
|
forrest@0
|
71 |
data3 = b->H
|
forrest@0
|
72 |
; latent heat flux unit: W m-2
|
forrest@0
|
73 |
data4 = b->LE
|
forrest@0
|
74 |
|
forrest@0
|
75 |
; time unit: hour since 01-01 (mm-dd)
|
forrest@0
|
76 |
time = b->time
|
forrest@0
|
77 |
|
forrest@0
|
78 |
do n= 0,nmon-1
|
forrest@0
|
79 |
if (n.eq.0) then
|
forrest@0
|
80 |
timeL = 0.
|
forrest@0
|
81 |
timeR = hour_of_month(0)
|
forrest@0
|
82 |
else
|
forrest@0
|
83 |
timeL = hour_of_month(n-1)
|
forrest@0
|
84 |
timeR = hour_of_month(n)
|
forrest@0
|
85 |
end if
|
forrest@0
|
86 |
; print (timeL)
|
forrest@0
|
87 |
; print (timeR)
|
forrest@0
|
88 |
|
forrest@0
|
89 |
i = ind(time.ge.timeL .and. time.lt.timeR)
|
forrest@0
|
90 |
; print (i)
|
forrest@0
|
91 |
|
forrest@0
|
92 |
data_out1(m,n) = avg(data1(i))
|
forrest@0
|
93 |
data_out2(m,n) = avg(data2(i))
|
forrest@0
|
94 |
data_out3(m,n) = avg(data3(i))
|
forrest@0
|
95 |
data_out4(m,n) = avg(data4(i))
|
forrest@0
|
96 |
|
forrest@0
|
97 |
time_out(m,n) = year*100 + n + 1
|
forrest@0
|
98 |
; print (time_out(m,n))
|
forrest@0
|
99 |
|
forrest@0
|
100 |
delete (i)
|
forrest@0
|
101 |
end do
|
forrest@0
|
102 |
if (m.lt.nyear-1) then
|
forrest@0
|
103 |
delete (data1)
|
forrest@0
|
104 |
delete (data2)
|
forrest@0
|
105 |
delete (data3)
|
forrest@0
|
106 |
delete (data4)
|
forrest@0
|
107 |
delete (time)
|
forrest@0
|
108 |
end if
|
forrest@0
|
109 |
end do
|
forrest@0
|
110 |
|
forrest@0
|
111 |
data_out1!0 = "year"
|
forrest@0
|
112 |
data_out1!1 = "month"
|
forrest@0
|
113 |
data_out1@long_name = data1@long_name
|
forrest@0
|
114 |
data_out1@units = data1@units
|
forrest@0
|
115 |
data_out1@_FillValue = 1.e+36
|
forrest@0
|
116 |
; print (data_out1)
|
forrest@0
|
117 |
|
forrest@0
|
118 |
data_out2!0 = "year"
|
forrest@0
|
119 |
data_out2!1 = "month"
|
forrest@0
|
120 |
data_out2@long_name = data2@long_name
|
forrest@0
|
121 |
data_out2@units = data2@units
|
forrest@0
|
122 |
data_out2@_FillValue = 1.e+36
|
forrest@0
|
123 |
; print (data_out2)
|
forrest@0
|
124 |
|
forrest@0
|
125 |
data_out3!0 = "year"
|
forrest@0
|
126 |
data_out3!1 = "month"
|
forrest@0
|
127 |
data_out3@long_name = data3@long_name
|
forrest@0
|
128 |
data_out3@units = data3@units
|
forrest@0
|
129 |
data_out3@_FillValue = 1.e+36
|
forrest@0
|
130 |
; print (data_out3)
|
forrest@0
|
131 |
|
forrest@0
|
132 |
data_out4!0 = "year"
|
forrest@0
|
133 |
data_out4!1 = "month"
|
forrest@0
|
134 |
data_out4@long_name = data4@long_name
|
forrest@0
|
135 |
data_out4@units = data4@units
|
forrest@0
|
136 |
data_out4@_FillValue = 1.e+36
|
forrest@0
|
137 |
; print (data_out4)
|
forrest@0
|
138 |
|
forrest@0
|
139 |
time_out!0 = "year"
|
forrest@0
|
140 |
time_out!1 = "month"
|
forrest@0
|
141 |
time_out@long_name = "current date as yyyymm"
|
forrest@0
|
142 |
time_out@units = "current date as yyyymm"
|
forrest@0
|
143 |
print (time_out)
|
forrest@0
|
144 |
|
forrest@0
|
145 |
lat_out!0 = "lat"
|
forrest@0
|
146 |
lon_out!0 = "lon"
|
forrest@0
|
147 |
lat_out@units = "degrees_north"
|
forrest@0
|
148 |
lat_out@long_name = "Latitude"
|
forrest@0
|
149 |
lon_out@units = "degrees_east"
|
forrest@0
|
150 |
lon_out@long_name = "Longitude"
|
forrest@0
|
151 |
print (lat_out)
|
forrest@0
|
152 |
print (lon_out)
|
forrest@0
|
153 |
|
forrest@0
|
154 |
c->lat = lat_out
|
forrest@0
|
155 |
c->lon = lon_out
|
forrest@0
|
156 |
c->date = time_out
|
forrest@0
|
157 |
c->CO2_FLUX = data_out1
|
forrest@0
|
158 |
c->RAD_FLUX = data_out2
|
forrest@0
|
159 |
c->SH_FLUX = data_out3
|
forrest@0
|
160 |
c->LH_FLUX = data_out4
|
forrest@0
|
161 |
|
forrest@0
|
162 |
end
|