forrest@0: ;************************************************ forrest@0: ; Read half-hourly data and write monthly data forrest@0: ; input data is : half-hourly forrest@0: ; forrest@0: ; output data is : CO2_flux, RAD_FLUX, SH_FLUX, LH_FLUX forrest@0: ; date, lat, lon forrest@0: ;************************************************ forrest@0: load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" forrest@0: load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" forrest@0: load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" forrest@0: ;************************************************ forrest@0: begin forrest@0: forrest@0: dir_root = "/fis/cgd/cseg/people/jeff/clamp_data/fluxnet/" forrest@0: station_name = "Hyytiala" forrest@0: file_name_add = "carboeurope" forrest@0: year_start = 1996 forrest@0: year_end = 2003 forrest@0: year_leap1 = 1996 forrest@0: year_leap2 = 2000 forrest@0: year_leap3 = 2004 forrest@0: forrest@0: lat_out = 61.8474 forrest@0: lon_out = 24.2948 forrest@0: forrest@0: ; final output forrest@0: diro = dir_root + station_name + "/" forrest@0: filo = station_name+"_"+year_start+"-"+year_end+"_monthly.nc" forrest@0: c = addfile(diro+filo,"c") forrest@0: print (filo) forrest@0: forrest@0: ; input dir forrest@0: diri = dir_root + station_name + "/" forrest@0: forrest@0: nyear = year_end - year_start + 1 forrest@0: nmon = 12 forrest@0: nlat = 1 forrest@0: nlon = 1 forrest@0: forrest@0: ; day_of_month = (/31.,28.,31.,30.,31.,30.,31.,31.,30.,31.,30.,31./) forrest@0: end_of_month1 = (/31.,59.,90.,120.,151.,181.,212.,243.,273.,304.,334.,365./) forrest@0: end_of_month2 = (/31.,60.,91.,121.,152.,182.,213.,244.,274.,305.,335.,366./) forrest@0: forrest@0: data_out1 = new((/nyear,nmon/),float) forrest@0: data_out2 = new((/nyear,nmon/),float) forrest@0: data_out3 = new((/nyear,nmon/),float) forrest@0: data_out4 = new((/nyear,nmon/),float) forrest@0: time_out = new((/nyear,nmon/),integer) forrest@0: forrest@0: do m = 0,nyear-1 forrest@0: year = year_start + m forrest@0: forrest@0: ; if (mod(year,4) .eq. 0) then forrest@0: if (year.eq.year_leap1.or.year.eq.year_leap2.or.year.eq.year_leap3) then forrest@0: hour_of_month = end_of_month2 * 24. forrest@0: else forrest@0: hour_of_month = end_of_month1 * 24. forrest@0: end if forrest@0: ; print (hour_of_month) forrest@0: forrest@0: ; input file forrest@0: fili = file_name_add+"."+station_name+"."+year+".nc" forrest@0: b = addfile(diri+fili,"r") forrest@0: print (fili) forrest@0: forrest@0: ; co2 flux unit: umol m-2 s-1 forrest@0: data1 = b->FCO2M forrest@0: ; net radiation flux unit: W m-2 forrest@0: data2 = b->RN forrest@0: ; sensible heat flux unit: W m-2 forrest@0: data3 = b->H forrest@0: ; latent heat flux unit: W m-2 forrest@0: data4 = b->LE forrest@0: forrest@0: ; time unit: hour since 01-01 (mm-dd) forrest@0: time = b->time forrest@0: forrest@0: do n= 0,nmon-1 forrest@0: if (n.eq.0) then forrest@0: timeL = 0. forrest@0: timeR = hour_of_month(0) forrest@0: else forrest@0: timeL = hour_of_month(n-1) forrest@0: timeR = hour_of_month(n) forrest@0: end if forrest@0: ; print (timeL) forrest@0: ; print (timeR) forrest@0: forrest@0: i = ind(time.ge.timeL .and. time.lt.timeR) forrest@0: ; print (i) forrest@0: forrest@0: data_out1(m,n) = avg(data1(i)) forrest@0: data_out2(m,n) = avg(data2(i)) forrest@0: data_out3(m,n) = avg(data3(i)) forrest@0: data_out4(m,n) = avg(data4(i)) forrest@0: forrest@0: time_out(m,n) = year*100 + n + 1 forrest@0: ; print (time_out(m,n)) forrest@0: forrest@0: delete (i) forrest@0: end do forrest@0: if (m.lt.nyear-1) then forrest@0: delete (data1) forrest@0: delete (data2) forrest@0: delete (data3) forrest@0: delete (data4) forrest@0: delete (time) forrest@0: end if forrest@0: end do forrest@0: forrest@0: data_out1!0 = "year" forrest@0: data_out1!1 = "month" forrest@0: data_out1@long_name = data1@long_name forrest@0: data_out1@units = data1@units forrest@0: data_out1@_FillValue = 1.e+36 forrest@0: ; print (data_out1) forrest@0: forrest@0: data_out2!0 = "year" forrest@0: data_out2!1 = "month" forrest@0: data_out2@long_name = data2@long_name forrest@0: data_out2@units = data2@units forrest@0: data_out2@_FillValue = 1.e+36 forrest@0: ; print (data_out2) forrest@0: forrest@0: data_out3!0 = "year" forrest@0: data_out3!1 = "month" forrest@0: data_out3@long_name = data3@long_name forrest@0: data_out3@units = data3@units forrest@0: data_out3@_FillValue = 1.e+36 forrest@0: ; print (data_out3) forrest@0: forrest@0: data_out4!0 = "year" forrest@0: data_out4!1 = "month" forrest@0: data_out4@long_name = data4@long_name forrest@0: data_out4@units = data4@units forrest@0: data_out4@_FillValue = 1.e+36 forrest@0: ; print (data_out4) forrest@0: forrest@0: time_out!0 = "year" forrest@0: time_out!1 = "month" forrest@0: time_out@long_name = "current date as yyyymm" forrest@0: time_out@units = "current date as yyyymm" forrest@0: print (time_out) forrest@0: forrest@0: lat_out!0 = "lat" forrest@0: lon_out!0 = "lon" forrest@0: lat_out@units = "degrees_north" forrest@0: lat_out@long_name = "Latitude" forrest@0: lon_out@units = "degrees_east" forrest@0: lon_out@long_name = "Longitude" forrest@0: print (lat_out) forrest@0: print (lon_out) forrest@0: forrest@0: c->lat = lat_out forrest@0: c->lon = lon_out forrest@0: c->date = time_out forrest@0: c->CO2_FLUX = data_out1 forrest@0: c->RAD_FLUX = data_out2 forrest@0: c->SH_FLUX = data_out3 forrest@0: c->LH_FLUX = data_out4 forrest@0: forrest@0: end