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