1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/energy/04.monthly_avg.ncl Mon Jan 26 22:08:20 2009 -0500
1.3 @@ -0,0 +1,161 @@
1.4 +;************************************************
1.5 +; Read half-hourly data and write monthly data
1.6 +; input data is : half-hourly
1.7 +;
1.8 +; output data is : CO2_flux, RAD_FLUX, SH_FLUX, LH_FLUX
1.9 +; date, lat, lon
1.10 +;************************************************
1.11 +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
1.12 +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
1.13 +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
1.14 +;************************************************
1.15 +begin
1.16 +
1.17 + dir_root = "/fis/cgd/cseg/people/jeff/clamp_data/fluxnet/"
1.18 + station_name = "Tharandt"
1.19 + file_name_add = "carboeurope"
1.20 + year_start = 1996
1.21 + year_end = 2003
1.22 + year_leap1 = 1996
1.23 + year_leap2 = 2000
1.24 +
1.25 + lat_out = 50.9636
1.26 + lon_out = 13.5669
1.27 +
1.28 +; final output
1.29 + diro = dir_root + station_name + "/"
1.30 + filo = station_name+"_"+year_start+"-"+year_end+"_monthly.nc"
1.31 + c = addfile(diro+filo,"c")
1.32 + print (filo)
1.33 +
1.34 +; input dir
1.35 + diri = dir_root + station_name + "/"
1.36 +
1.37 + nyear = year_end - year_start + 1
1.38 + nmon = 12
1.39 + nlat = 1
1.40 + nlon = 1
1.41 +
1.42 +; day_of_month = (/31.,28.,31.,30.,31.,30.,31.,31.,30.,31.,30.,31./)
1.43 + end_of_month1 = (/31.,59.,90.,120.,151.,181.,212.,243.,273.,304.,334.,365./)
1.44 + end_of_month2 = (/31.,60.,91.,121.,152.,182.,213.,244.,274.,305.,335.,366./)
1.45 +
1.46 + data_out1 = new((/nyear,nmon/),float)
1.47 + data_out2 = new((/nyear,nmon/),float)
1.48 + data_out3 = new((/nyear,nmon/),float)
1.49 + data_out4 = new((/nyear,nmon/),float)
1.50 + time_out = new((/nyear,nmon/),integer)
1.51 +
1.52 + do m = 0,nyear-1
1.53 + year = year_start + m
1.54 +
1.55 +; if (mod(year,4) .eq. 0) then
1.56 + if (year .eq. year_leap1 .or. year .eq. year_leap2 ) then
1.57 + hour_of_month = end_of_month2 * 24.
1.58 + else
1.59 + hour_of_month = end_of_month1 * 24.
1.60 + end if
1.61 +; print (hour_of_month)
1.62 +
1.63 +; input file
1.64 + fili = file_name_add+"."+station_name+"."+year+".nc"
1.65 + b = addfile(diri+fili,"r")
1.66 + print (fili)
1.67 +
1.68 +; co2 flux unit: umol m-2 s-1
1.69 + data1 = b->FCO2M
1.70 +; net radiation flux unit: W m-2
1.71 + data2 = b->RN
1.72 +; sensible heat flux unit: W m-2
1.73 + data3 = b->H
1.74 +; latent heat flux unit: W m-2
1.75 + data4 = b->LE
1.76 +
1.77 +; time unit: hour since 01-01 (mm-dd)
1.78 + time = b->time
1.79 +
1.80 + do n= 0,nmon-1
1.81 + if (n.eq.0) then
1.82 + timeL = 0.
1.83 + timeR = hour_of_month(0)
1.84 + else
1.85 + timeL = hour_of_month(n-1)
1.86 + timeR = hour_of_month(n)
1.87 + end if
1.88 +; print (timeL)
1.89 +; print (timeR)
1.90 +
1.91 + i = ind(time.ge.timeL .and. time.lt.timeR)
1.92 +; print (i)
1.93 +
1.94 + data_out1(m,n) = avg(data1(i))
1.95 + data_out2(m,n) = avg(data2(i))
1.96 + data_out3(m,n) = avg(data3(i))
1.97 + data_out4(m,n) = avg(data4(i))
1.98 +
1.99 + time_out(m,n) = year*100 + n + 1
1.100 +; print (time_out(m,n))
1.101 +
1.102 + delete (i)
1.103 + end do
1.104 + if (m.lt.nyear-1) then
1.105 + delete (data1)
1.106 + delete (data2)
1.107 + delete (data3)
1.108 + delete (data4)
1.109 + delete (time)
1.110 + end if
1.111 + end do
1.112 +
1.113 + data_out1!0 = "year"
1.114 + data_out1!1 = "month"
1.115 + data_out1@long_name = data1@long_name
1.116 + data_out1@units = data1@units
1.117 + data_out1@_FillValue = 1.e+36
1.118 +; print (data_out1)
1.119 +
1.120 + data_out2!0 = "year"
1.121 + data_out2!1 = "month"
1.122 + data_out2@long_name = data2@long_name
1.123 + data_out2@units = data2@units
1.124 + data_out2@_FillValue = 1.e+36
1.125 +; print (data_out2)
1.126 +
1.127 + data_out3!0 = "year"
1.128 + data_out3!1 = "month"
1.129 + data_out3@long_name = data3@long_name
1.130 + data_out3@units = data3@units
1.131 + data_out3@_FillValue = 1.e+36
1.132 +; print (data_out3)
1.133 +
1.134 + data_out4!0 = "year"
1.135 + data_out4!1 = "month"
1.136 + data_out4@long_name = data4@long_name
1.137 + data_out4@units = data4@units
1.138 + data_out4@_FillValue = 1.e+36
1.139 +; print (data_out4)
1.140 +
1.141 + time_out!0 = "year"
1.142 + time_out!1 = "month"
1.143 + time_out@long_name = "current date as yyyymm"
1.144 + time_out@units = "current date as yyyymm"
1.145 + print (time_out)
1.146 +
1.147 + lat_out!0 = "lat"
1.148 + lon_out!0 = "lon"
1.149 + lat_out@units = "degrees_north"
1.150 + lat_out@long_name = "Latitude"
1.151 + lon_out@units = "degrees_east"
1.152 + lon_out@long_name = "Longitude"
1.153 + print (lat_out)
1.154 + print (lon_out)
1.155 +
1.156 + c->lat = lat_out
1.157 + c->lon = lon_out
1.158 + c->date = time_out
1.159 + c->CO2_FLUX = data_out1
1.160 + c->RAD_FLUX = data_out2
1.161 + c->SH_FLUX = data_out3
1.162 + c->LH_FLUX = data_out4
1.163 +
1.164 +end