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