ameriflux/23.plot.ncl
changeset 0 0c6405ab2ff4
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ameriflux/23.plot.ncl	Mon Jan 26 22:08:20 2009 -0500
     1.3 @@ -0,0 +1,920 @@
     1.4 +;************************************************************
     1.5 +; move data
     1.6 +; merge annual
     1.7 +; add table
     1.8 +; add time series plot
     1.9 +; sort by latitude in decending order (N->S)
    1.10 +; find year_ob >= 4
    1.11 +; add year_ob_i and year_ob_f
    1.12 +; change long_name
    1.13 +;************************************************************
    1.14 +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
    1.15 +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
    1.16 +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
    1.17 +;************************************************************
    1.18 +procedure set_line(lines:string,nline:integer,newlines:string) 
    1.19 +begin
    1.20 +; add line to ascci/html file
    1.21 +    
    1.22 +  nnewlines = dimsizes(newlines)
    1.23 +  if(nline+nnewlines-1.ge.dimsizes(lines))
    1.24 +    print("set_line: bad index, not setting anything.") 
    1.25 +    return
    1.26 +  end if 
    1.27 +  lines(nline:nline+nnewlines-1) = newlines
    1.28 +;  print ("lines = " + lines(nline:nline+nnewlines-1))
    1.29 +  nline = nline + nnewlines
    1.30 +  return 
    1.31 +end
    1.32 +;*************************************************************
    1.33 +begin
    1.34 +
    1.35 +  plot_type     = "ps"
    1.36 +  plot_type_new = "png"
    1.37 +
    1.38 +;************************************************
    1.39 +; model data info
    1.40 +;************************************************
    1.41 +  model = "cn"
    1.42 +; model = "casa"
    1.43 +  
    1.44 +  model_name = "i01.10" + model
    1.45 +  
    1.46 +  ENERGY ="new"
    1.47 +
    1.48 +  nmonth = 12
    1.49 +
    1.50 +;************************************************
    1.51 +; observed data info
    1.52 +;************************************************
    1.53 +
    1.54 + station = (/"ARM_Oklahoma" \
    1.55 +            ,"ARM_Oklahoma_burn" \
    1.56 +            ,"ARM_Oklahoma_control" \
    1.57 +            ,"Atqasuk" \
    1.58 +            ,"Audubon" \
    1.59 +            ,"AustinCary" \
    1.60 +            ,"Bartlett" \
    1.61 +            ,"Bondville" \
    1.62 +            ,"Brookings" \
    1.63 +            ,"Donaldson" \
    1.64 +            ,"Duke_Forest_Hardwoods" \
    1.65 +            ,"Duke_Forest_Open_Field" \
    1.66 +            ,"Duke_Forest_Pine" \
    1.67 +            ,"Fermi_Ag" \
    1.68 +            ,"Fermi_Prairie" \
    1.69 +            ,"Flagstaff_Managed" \
    1.70 +            ,"Flagstaff_Unmanaged" \
    1.71 +            ,"Flagstaff_Wildfire" \
    1.72 +            ,"FortPeck" \
    1.73 +            ,"FreemanRanch_mesquite" \
    1.74 +            ,"Goodwin_Creek" \
    1.75 +            ,"HarvardForest" \
    1.76 +            ,"HarvardForestHemlock" \
    1.77 +            ,"HowlandForestMain" \
    1.78 +            ,"HowlandForestWest" \
    1.79 +            ,"Ivotuk" \
    1.80 +            ,"KendallGrasslands" \
    1.81 +            ,"KennedySpaceCenterPine" \
    1.82 +            ,"KennedySpaceCenterScrub" \
    1.83 +            ,"LittleProspect" \
    1.84 +            ,"LostCreek" \
    1.85 +            ,"Mead-irrigated" \
    1.86 +            ,"Mead-irrigated-rotation" \
    1.87 +            ,"Mead-rainfed" \
    1.88 +            ,"Metolius_2nd_YoungPonderosaPine" \
    1.89 +            ,"MetoliusEyerly" \
    1.90 +            ,"MetoliusIntermediatePine" \
    1.91 +            ,"MetoliusOldPonderosaPine" \
    1.92 +            ,"MissouriOzark" \
    1.93 +            ,"Mize" \
    1.94 +            ,"MorganMonroe" \
    1.95 +            ,"NiwotRidge" \
    1.96 +            ,"NorthCarolina_cc" \
    1.97 +            ,"NorthCarolina_lp" \
    1.98 +            ,"ParkFalls" \
    1.99 +            ,"Rayonier" \
   1.100 +            ,"SantaRita" \
   1.101 +            ,"SkyOaks_Old" \
   1.102 +            ,"SkyOaks_PostFire" \
   1.103 +            ,"SkyOaks_Young" \
   1.104 +            ,"SylvaniaWilderness" \
   1.105 +            ,"Toledo" \
   1.106 +            ,"Tonzi" \
   1.107 +            ,"UCI_1850" \
   1.108 +            ,"UCI_1930" \
   1.109 +            ,"UCI_1964" \
   1.110 +            ,"UCI_1964wet" \
   1.111 +            ,"UCI_1981" \
   1.112 +            ,"UCI_1989" \
   1.113 +            ,"UCI_1998" \
   1.114 +            ,"UMBS" \
   1.115 +            ,"Vaira" \
   1.116 +            ,"WalkerBranch" \
   1.117 +            ,"WillowCreek" \
   1.118 +            ,"WindRiver" \
   1.119 +            ,"Wisconsin_ihw" \
   1.120 +            ,"Wisconsin_irp" \
   1.121 +            ,"Wisconsin_mrp" \
   1.122 +            ,"Wisconsin_myjp" \
   1.123 +            ,"Wisconsin_pb" \
   1.124 +            ,"Wisconsin_rpcc" \
   1.125 +            ,"Wisconsin_yhw" \
   1.126 +            ,"Wisconsin_yjp" \
   1.127 +            ,"Wisconsin_yrp" \
   1.128 +            /)
   1.129 +
   1.130 + year_ob = (/"2003-2006" \
   1.131 +            ,"2005-2006" \
   1.132 +            ,"2005-2006" \
   1.133 +            ,"1999-2006" \
   1.134 +            ,"2002-2006" \
   1.135 +            ,"2000-2005" \
   1.136 +            ,"2004-2005" \
   1.137 +            ,"1996-2006" \
   1.138 +            ,"2004-2006" \
   1.139 +            ,"1999-2004" \
   1.140 +            ,"2003-2005" \
   1.141 +            ,"2001-2005" \
   1.142 +            ,"2001-2005" \
   1.143 +            ,"2005-2006" \
   1.144 +            ,"2004-2006" \
   1.145 +            ,"2005-2006" \
   1.146 +            ,"2005-2006" \
   1.147 +            ,"2005-2006" \
   1.148 +            ,"2000-2006" \
   1.149 +            ,"2004-2006" \
   1.150 +            ,"2002-2006" \
   1.151 +            ,"1991-2004" \
   1.152 +            ,"2004-2004" \
   1.153 +            ,"1996-2004" \
   1.154 +            ,"1999-2004" \
   1.155 +            ,"2003-2006" \
   1.156 +            ,"2004-2006" \
   1.157 +            ,"2002-2002" \
   1.158 +            ,"2000-2006" \
   1.159 +            ,"2002-2005" \
   1.160 +            ,"2001-2005" \
   1.161 +            ,"2001-2005" \
   1.162 +            ,"2001-2005" \
   1.163 +            ,"2001-2005" \
   1.164 +            ,"2004-2005" \
   1.165 +            ,"2004-2005" \
   1.166 +            ,"2003-2005" \
   1.167 +            ,"1996-2000" \
   1.168 +            ,"2004-2006" \
   1.169 +            ,"1998-2004" \
   1.170 +            ,"1999-2005" \
   1.171 +            ,"1999-2003" \
   1.172 +            ,"2005-2006" \
   1.173 +            ,"2005-2006" \
   1.174 +            ,"1996-2003" \
   1.175 +            ,"1998-1998" \
   1.176 +            ,"2004-2006" \
   1.177 +            ,"1997-2006" \
   1.178 +            ,"2004-2006" \
   1.179 +            ,"1997-2006" \
   1.180 +            ,"2002-2006" \
   1.181 +            ,"2004-2005" \
   1.182 +            ,"2001-2006" \
   1.183 +            ,"2004-2005" \
   1.184 +            ,"2001-2005" \
   1.185 +            ,"2001-2005" \
   1.186 +            ,"2002-2004" \
   1.187 +            ,"2001-2005" \
   1.188 +            ,"2001-2005" \
   1.189 +            ,"2002-2005" \
   1.190 +            ,"1999-2003" \
   1.191 +            ,"2001-2006" \
   1.192 +            ,"1995-1999" \
   1.193 +            ,"1999-2005" \
   1.194 +            ,"1999-2004" \
   1.195 +            ,"2003-2003" \
   1.196 +            ,"2003-2003" \
   1.197 +            ,"2002-2005" \
   1.198 +            ,"2004-2004" \
   1.199 +            ,"2002-2002" \
   1.200 +            ,"2005-2005" \
   1.201 +            ,"2002-2002" \
   1.202 +            ,"2004-2005" \
   1.203 +            ,"2002-2002" \
   1.204 +            /)
   1.205 +
   1.206 + field   = (/"NEE Flux" \
   1.207 +            ,"Net Radiation" \
   1.208 +            ,"Latent Heat" \
   1.209 +            ,"Sensible Heat" \
   1.210 +            ,"GPP Flux" \
   1.211 +            ,"Respiration" \
   1.212 +            /)
   1.213 +
   1.214 + field_unit = (/"u mol/m2/s" \
   1.215 +               ,"W/m2" \
   1.216 +               ,"W/m2" \
   1.217 +               ,"W/m2" \
   1.218 +               ,"u mol/m2/s" \
   1.219 +               ,"u mol/m2/s" \
   1.220 +               /)
   1.221 +
   1.222 + nstation = dimsizes(station)
   1.223 + nfield   = dimsizes(field)
   1.224 +
   1.225 +;========================================================================
   1.226 +; get observed info: number of year, first/last year, lat, lon
   1.227 +; and annual data
   1.228 +
   1.229 + dir_root = "/fis/cgd/cseg/people/jeff/clamp_data/observed/ameriflux/"
   1.230 +
   1.231 + year_station = new ((/nstation/),integer) ; number of year
   1.232 + year_ob_i    = new ((/nstation/),integer) ; first year
   1.233 + year_ob_f    = new ((/nstation/),integer) ; last year
   1.234 + lat_ob       = new ((/nstation/),float)   ; latitude
   1.235 + lon_ob       = new ((/nstation/),float)   ; longitude 
   1.236 +
   1.237 + data_ob_ann  = new ((/nfield, nmonth, nstation/),float)
   1.238 +
   1.239 + do n = 0, nstation-1
   1.240 +
   1.241 +    diro = dir_root + station(n)+"/"
   1.242 +    filo = year_ob(n)+"_L4_m.nc"
   1.243 +    fo   = addfile (diro+filo,"r")
   1.244 + 
   1.245 +    lat_ob(n) = fo->lat
   1.246 +    lon_ob(n) = fo->lon
   1.247 +
   1.248 +    year      = fo->year
   1.249 +
   1.250 +    year_station(n) = dimsizes(year)
   1.251 +    year_ob_i(n)    = year(0)
   1.252 +    year_ob_f(n)    = year(year_station(n)-1)
   1.253 + 
   1.254 +    delete (year)
   1.255 + 
   1.256 +    data = fo->NEE_or_fMDS
   1.257 +    data_ob_ann(0,:,n) = dim_avg(data(month|:,year|:))
   1.258 +
   1.259 +    data = fo->Rg_f
   1.260 +    data_ob_ann(1,:,n) = dim_avg(data(month|:,year|:))
   1.261 +
   1.262 +    data = fo->LE_f
   1.263 +    data_ob_ann(2,:,n) = dim_avg(data(month|:,year|:))
   1.264 +
   1.265 +    data = fo->H_f
   1.266 +    data_ob_ann(3,:,n) = dim_avg(data(month|:,year|:))
   1.267 +
   1.268 +    data = fo->GPP_or_MDS
   1.269 +    data_ob_ann(4,:,n) = dim_avg(data(month|:,year|:))
   1.270 +
   1.271 +    data = fo->Reco_or
   1.272 +    data_ob_ann(5,:,n) = dim_avg(data(month|:,year|:))
   1.273 +
   1.274 +    delete (data) 
   1.275 +    delete (fo)   
   1.276 + end do
   1.277 +
   1.278 +;print (year_ob_i)
   1.279 +;print (year_ob_f)
   1.280 +
   1.281 +;--------------------------------------------------------------
   1.282 +; find (# of year observed) >=4 and year_ob_i <= 2001
   1.283 +
   1.284 + i_long_ob = ind(year_station .ge. 4 .and. year_ob_i .le. 2001)
   1.285 + 
   1.286 + station_long      = station(i_long_ob)
   1.287 + lat_ob_long       = lat_ob(i_long_ob)
   1.288 + lon_ob_long       = lat_ob(i_long_ob)
   1.289 + year_ob_long      = year_ob(i_long_ob)
   1.290 + year_ob_i_long    = year_ob_i(i_long_ob)
   1.291 + year_ob_f_long    = year_ob_f(i_long_ob)
   1.292 + year_station_long = year_station(i_long_ob)
   1.293 +
   1.294 + nstation_long     = dimsizes(station_long)
   1.295 +
   1.296 +; print (i_long_ob)
   1.297 +; print (nstation_long)
   1.298 +; print (station_long)
   1.299 +; print (year_ob_i(i_long_ob))
   1.300 +
   1.301 +;=========================================================
   1.302 +;   get model data at observed lat-lon
   1.303 +
   1.304 +    dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/"    
   1.305 +    film = model_name+"_ameriflux_1990-2004_monthly.nc"
   1.306 +    fm   = addfile (dirm+film,"r")
   1.307 +
   1.308 +    xm   = fm->lon
   1.309 +    ym   = fm->lat 
   1.310 +    date = fm->date
   1.311 +
   1.312 +    date_dim = dimsizes(date)
   1.313 +    nyear  = date_dim(0)
   1.314 +
   1.315 +    data_mod      = new ((/nfield,nyear,nmonth,nstation/),float)
   1.316 +    data_mod_ann  = new ((/nfield,nmonth,nstation/),float)
   1.317 +    data_mod_long = new ((/nfield,nyear,nmonth,nstation_long/),float)
   1.318 +
   1.319 +;   change to unit of observed (u mol/m2/s)
   1.320 +;   Model_units [=] gC/m2/s
   1.321 +;   12. = molecular weight of C
   1.322 +;   u mol = 1e-6 mol
   1.323 +
   1.324 +    factor = 1.e6 /12.
   1.325 +
   1.326 +;------------------------------------------------------------
   1.327 +;   interpolate model data into observed station
   1.328 +;   note: model is 0-360E, 90S-90N
   1.329 +
   1.330 +;   to be able to handle observation at (-89.98,-24.80)
   1.331 +    ym(0) = -90.
   1.332 +;------------------------------------------------------------  
   1.333 +
   1.334 +if (ENERGY .eq. "old") then
   1.335 +
   1.336 +  data = fm->NEE
   1.337 +  data_mod(0,:,:,:) = data(:,:,:) * factor
   1.338 +
   1.339 +; data  = fm->LATENT
   1.340 +  data1 = fm->FCEV
   1.341 +  data2 = fm->FCTR
   1.342 +  data3 = fm->FGEV
   1.343 +  data_mod(2,:,:,:) = data1(:,:,:)+data2(:,:,:)+data3(:,:,:) 
   1.344 +  delete (data1)
   1.345 +  delete (data2)
   1.346 +  delete (data3)
   1.347 +
   1.348 +; data = fm->SENSIBLE
   1.349 +  data  = fm->FSH
   1.350 +  data_mod(3,:,:,:) = data(:,:,:) 
   1.351 +
   1.352 +; data  = fm->NETRAD
   1.353 +  data1 = fm->FSA
   1.354 +  data2 = fm->FIRA
   1.355 +  data_mod(1,:,:,:) = data1(:,:,:)-data2(:,:,:) 
   1.356 +  delete (data1)
   1.357 +  delete (data2)
   1.358 +
   1.359 +else
   1.360 +
   1.361 +  data = fm->NEE
   1.362 +  yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0)
   1.363 +  data_mod_ann(0,:,:)= dim_avg(yy(month|:,pts|:,year|:)) * factor
   1.364 +  data_mod(0,:,:,:) = yy(:,:,:) * factor
   1.365 +
   1.366 +; printVarSummary(yy)
   1.367 +
   1.368 +  data = fm->NETRAD
   1.369 +  yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0)
   1.370 +  data_mod_ann(1,:,:)= dim_avg(yy(month|:,pts|:,year|:)) 
   1.371 +  data_mod(1,:,:,:) = yy(:,:,:) 
   1.372 +
   1.373 +  data = fm->LATENT
   1.374 +  yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0)
   1.375 +  data_mod_ann(2,:,:)= dim_avg(yy(month|:,pts|:,year|:)) 
   1.376 +  data_mod(2,:,:,:) = yy(:,:,:) 
   1.377 +
   1.378 +; data = fm->SENSIBLE
   1.379 +  data = fm->FSH
   1.380 +  yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0)
   1.381 +  data_mod_ann(3,:,:)= dim_avg(yy(month|:,pts|:,year|:)) 
   1.382 +  data_mod(3,:,:,:) = yy(:,:,:) 
   1.383 +
   1.384 +end if
   1.385 +
   1.386 +  data = fm->GPP
   1.387 +  yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0)
   1.388 +  data_mod_ann(4,:,:)= dim_avg(yy(month|:,pts|:,year|:)) * factor
   1.389 +  data_mod(4,:,:,:) = yy(:,:,:) * factor 
   1.390 +
   1.391 +  if (model .eq. "cn") then
   1.392 +     data = fm->ER
   1.393 +  else
   1.394 +     data1 = fm->AR
   1.395 +     data2 = fm->HR
   1.396 +     data  = data1 + data2
   1.397 +    
   1.398 +     delete (data1)
   1.399 +     delete (data2)
   1.400 +  end if
   1.401 +
   1.402 +  yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0)
   1.403 +  data_mod_ann(5,:,:)= dim_avg(yy(month|:,pts|:,year|:)) * factor
   1.404 +  data_mod(5,:,:,:) = yy(:,:,:) * factor
   1.405 +
   1.406 +  data_mod_long(:,:,:,:) = data_mod(:,:,:,i_long_ob)
   1.407 +
   1.408 +  delete (data_mod)
   1.409 +  delete (fm) 
   1.410 +  delete (data)
   1.411 +  delete (yy)
   1.412 +
   1.413 +;*******************************************************************
   1.414 +; for station line plot
   1.415 +;*******************************************************************
   1.416 +
   1.417 +; for x-axis in xyplot
   1.418 +  mon = ispan(1,12,1)
   1.419 +  mon@long_name = "month"
   1.420 +
   1.421 +  res                   = True               ; plot mods desired
   1.422 +  res@xyLineThicknesses = (/2.0,2.0/)        ; make 2nd lines thicker
   1.423 +  res@xyLineColors      = (/"blue","red"/)   ; line color (ob,model)
   1.424 +
   1.425 +  res@tmXBFormat  = "f"                      ; not to add trailing zeros
   1.426 +
   1.427 +;-------------------------------------------------------------------------
   1.428 +; Add a boxed legend using the more simple method
   1.429 +
   1.430 +  res@pmLegendDisplayMode    = "Always"
   1.431 +; res@pmLegendWidthF         = 0.1
   1.432 +  res@pmLegendWidthF         = 0.08
   1.433 +  res@pmLegendHeightF        = 0.06
   1.434 +; res@pmLegendOrthogonalPosF = -1.17
   1.435 +; res@pmLegendOrthogonalPosF = -1.00  ;(downward)
   1.436 +  res@pmLegendOrthogonalPosF = -0.30  ;(downward)
   1.437 +
   1.438 +; res@pmLegendParallelPosF   =  0.18
   1.439 +  res@pmLegendParallelPosF   =  0.23  ;(rightward)
   1.440 +
   1.441 +; res@lgPerimOn             = False
   1.442 +  res@lgLabelFontHeightF     = 0.015
   1.443 +  res@xyExplicitLegendLabels = (/"observed",model_name/)
   1.444 +;-------------------------------------------------------------------
   1.445 +; for panel plot
   1.446 +  res@gsnFrame     = False                   ; Do not draw plot 
   1.447 +  res@gsnDraw      = False                   ; Do not advance frame
   1.448 +
   1.449 +  pres                            = True     ; panel plot mods desired
   1.450 +  pres@gsnPanelYWhiteSpacePercent = 5        ; increase white space around
   1.451 +                                             ; indiv. plots in panel
   1.452 +  pres@gsnMaximize                = True     ; fill the page
   1.453 +;-------------------------------------------------------------------
   1.454 +
   1.455 +;==============================================================
   1.456 +; get ob data at each site with long observation
   1.457 +
   1.458 +  dir_root = "/fis/cgd/cseg/people/jeff/clamp/ameriflux/data/"
   1.459 +
   1.460 +  do n = 0,nstation_long-1
   1.461 +; do n = 0,0
   1.462 +
   1.463 +    year_setback = 0
   1.464 +
   1.465 +    nyear = year_station_long(n)
   1.466 +
   1.467 +    if (year_ob_f_long(n).eq. 2006) then
   1.468 +       year_setback = 2006 -2004
   1.469 +    end if
   1.470 +    if (year_ob_f_long(n).eq. 2005) then
   1.471 +       year_setback = 2005 -2004
   1.472 +    end if
   1.473 +    
   1.474 +    ntime = (nyear - year_setback) * nmonth
   1.475 +
   1.476 +    data_ob   = new ((/nfield, nyear, nmonth/),float)
   1.477 +
   1.478 +    diro = dir_root + station_long(n)+"/"
   1.479 +    filo = year_ob_long(n)+"_L4_m.nc"
   1.480 +    fo   = addfile (diro+filo,"r")
   1.481 +
   1.482 +;   print (diro)
   1.483 +;   print (filo)
   1.484 +
   1.485 +    data_ob(0,:,:) = fo->NEE_or_fMDS
   1.486 +    data_ob(1,:,:) = fo->Rg_f
   1.487 +    data_ob(2,:,:) = fo->LE_f
   1.488 +    data_ob(3,:,:) = fo->H_f
   1.489 +    data_ob(4,:,:) = fo->GPP_or_MDS
   1.490 +    data_ob(5,:,:) = fo->Reco_or
   1.491 +
   1.492 +    delete (fo)
   1.493 +
   1.494 +    timeI = new((/ntime/),integer)
   1.495 +    timeF = new((/ntime/),float)
   1.496 +    timeI = ispan(1,ntime,1)
   1.497 +    timeF = year_ob_i_long(n) + (timeI-1)/12.
   1.498 +    timeF@long_name = "year" 
   1.499 +
   1.500 +    plot_data = new((/2,ntime/),float)
   1.501 + 
   1.502 +;----------------------------
   1.503 +; for model_vs_ob
   1.504 +
   1.505 +    plot_name = station_long(n)+"_tseries_vs_ob"
   1.506 +    title = station_long(n)+"("+sprintf("%5.2f",lat_ob_long(n))+","+sprintf("%5.2f",lon_ob_long(n))+")"    
   1.507 +    res@tiMainString = title
   1.508 +
   1.509 +    wks = gsn_open_wks (plot_type,plot_name)
   1.510 +    plot=new(nfield,graphic)                         ; create graphic array   
   1.511 +
   1.512 +    i_year_mod_i = year_ob_i_long(n) - 1990 
   1.513 +    i_year_mod_f = i_year_mod_i + nyear - 1 - year_setback
   1.514 +
   1.515 +    i_year_ob_f =  nyear - year_setback - 1 
   1.516 +
   1.517 +;   print (nyear)
   1.518 +;   print (i_year_ob_f)
   1.519 +;   print (i_year_mod_i)
   1.520 +;   print (i_year_mod_f)
   1.521 +
   1.522 +    do i = 0,nfield-1                           
   1.523 +       plot_data(0,:) = ndtooned(data_ob (i,0:i_year_ob_f,:))
   1.524 +       plot_data(1,:) = ndtooned(data_mod_long(i,i_year_mod_i:i_year_mod_f,:,n))
   1.525 +       plot_data@long_name = field(i)+" ("+field_unit(i)+")"   
   1.526 +       plot(i)=gsn_csm_xy(wks,timeF,plot_data,res)            ; create plot 
   1.527 +    end do
   1.528 +   
   1.529 +    gsn_panel(wks,plot,(/3,2/),pres)                    ; create panel plot
   1.530 +
   1.531 +    system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
   1.532 +           "rm "+plot_name+"."+plot_type)
   1.533 +
   1.534 +    clear (wks)  
   1.535 +    delete (plot)
   1.536 +
   1.537 +    delete (data_ob)
   1.538 +    delete (timeI)    
   1.539 +    delete (timeF)
   1.540 +    delete (plot_data)
   1.541 +
   1.542 + end do
   1.543 +
   1.544 +;###################################################################
   1.545 +; for the following tables,
   1.546 +; sort by latitude in decending order (N->S)
   1.547 +
   1.548 +  isort = dim_pqsort(lat_ob_long,-1)
   1.549 +
   1.550 +  station_sort = station_long(isort)
   1.551 +  year_ob_sort = year_ob_long(isort)
   1.552 +  lat_ob_sort  = lat_ob_long(isort)
   1.553 +  lon_ob_sort  = lon_ob_long(isort)
   1.554 + 
   1.555 +; print(isort)
   1.556 +; print(lat_ob_sort)
   1.557 +
   1.558 +;*******************************************************************
   1.559 +; html table of site: observed
   1.560 +;*******************************************************************
   1.561 +  output_html = "tseries_vs_ob.html"
   1.562 +
   1.563 +  header = (/"<HTML>" \
   1.564 +            ,"<HEAD>" \
   1.565 +            ,"<TITLE>CLAMP metrics</TITLE>" \
   1.566 +            ,"</HEAD>" \
   1.567 +            ,"<H1>Timeseries at Site: "+model_name+" vs Observation</H1>" \
   1.568 +            /) 
   1.569 +  footer = "</HTML>"
   1.570 +
   1.571 +  table_header = (/ \
   1.572 +        "<table border=1 cellspacing=0 cellpadding=3 width=60%>" \
   1.573 +       ,"<tr>" \
   1.574 +       ,"   <th bgcolor=DDDDDD >Site Name</th>" \
   1.575 +       ,"   <th bgcolor=DDDDDD >Latitude</th>" \
   1.576 +       ,"   <th bgcolor=DDDDDD >Longitude</th>" \
   1.577 +       ,"   <th bgcolor=DDDDDD >Observed</th>" \ 
   1.578 +       ,"</tr>" \
   1.579 +       /)
   1.580 +  table_footer = "</table>"
   1.581 +  row_header = "<tr>"
   1.582 +  row_footer = "</tr>"
   1.583 +
   1.584 +  lines = new(50000,string)
   1.585 +  nline = 0
   1.586 +
   1.587 +  set_line(lines,nline,header)
   1.588 +  set_line(lines,nline,table_header)
   1.589 +;-----------------------------------------------
   1.590 +; row of table
   1.591 +  
   1.592 +  do n = 0,nstation_long-1
   1.593 +
   1.594 +     set_line(lines,nline,row_header)
   1.595 +
   1.596 +     txt0 = station_sort(n)
   1.597 +     txt1 = sprintf("%5.2f", lat_ob_sort(n))
   1.598 +     txt2 = sprintf("%5.2f", lon_ob_sort(n))
   1.599 +     txt3 = year_ob_sort(n)
   1.600 +
   1.601 +     set_line(lines,nline,"<th><a href="+txt0+"_tseries_vs_ob.png>"+txt0+"</a></th>")
   1.602 +     set_line(lines,nline,"<th>"+txt1+"</th>")
   1.603 +     set_line(lines,nline,"<th>"+txt2+"</th>")
   1.604 +     set_line(lines,nline,"<th>"+txt3+"</th>")
   1.605 +
   1.606 +     set_line(lines,nline,row_footer)
   1.607 +  end do
   1.608 +;-----------------------------------------------
   1.609 +  set_line(lines,nline,table_footer)
   1.610 +  set_line(lines,nline,footer) 
   1.611 +
   1.612 +; Now write to an HTML file.
   1.613 +  idx = ind(.not.ismissing(lines))
   1.614 +  if(.not.any(ismissing(idx))) then
   1.615 +    asciiwrite(output_html,lines(idx))
   1.616 +  else
   1.617 +   print ("error?")
   1.618 +  end if
   1.619 +  delete (idx)
   1.620 +
   1.621 +  delete (isort)
   1.622 +  delete (station_sort)
   1.623 +  delete (year_ob_sort)
   1.624 +  delete (lat_ob_sort)
   1.625 +  delete (lon_ob_sort)
   1.626 +
   1.627 +;************************************************************
   1.628 +; compute annual cycle correlation coef and M score
   1.629 +;************************************************************
   1.630 +
   1.631 + score_max = 5.
   1.632 +
   1.633 + ccr     = new ((/nstation, nfield/),float)
   1.634 + M_score = new ((/nstation, nfield/),float) 
   1.635 +
   1.636 + do n=0,nstation-1
   1.637 + do m=0,nfield-1   
   1.638 +    ccr(n,m) = esccr(data_ob_ann(m,:,n),data_mod_ann(m,:,n),0)
   1.639 +    bias = sum(abs(data_mod_ann(m,:,n)-data_ob_ann(m,:,n))/(abs(data_mod_ann(m,:,n))+abs(data_ob_ann(m,:,n))))
   1.640 +    M_score(n,m) = (1. -(bias/nmonth)) * score_max
   1.641 + end do
   1.642 + end do
   1.643 +
   1.644 + M_co2 = avg(M_score(:,0))
   1.645 + M_rad = avg(M_score(:,1))
   1.646 + M_lh  = avg(M_score(:,2))
   1.647 + M_sh  = avg(M_score(:,3))
   1.648 + M_gpp = avg(M_score(:,4))
   1.649 + M_er  = avg(M_score(:,5))
   1.650 + M_all = M_co2+ M_rad +M_lh + M_sh + M_gpp + M_er
   1.651 +
   1.652 + M_energy_co2 = sprintf("%.2f", M_co2)
   1.653 + M_energy_rad = sprintf("%.2f", M_rad)
   1.654 + M_energy_lh  = sprintf("%.2f", M_lh )
   1.655 + M_energy_sh  = sprintf("%.2f", M_sh )
   1.656 + M_energy_gpp = sprintf("%.2f", M_gpp)
   1.657 + M_energy_er  = sprintf("%.2f", M_er )
   1.658 + M_energy_all = sprintf("%.2f", M_all)
   1.659 +
   1.660 +;*******************************************************************
   1.661 +; for station line plot
   1.662 +;*******************************************************************
   1.663 +
   1.664 +; for x-axis in xyplot
   1.665 +  mon = ispan(1,12,1)
   1.666 +  mon@long_name = "month"
   1.667 +
   1.668 +;-------------------------------------------------------------------
   1.669 +
   1.670 +  plot_data   = new((/2,nmonth/),float)
   1.671 +  plot_data!0 = "case"
   1.672 +  plot_data!1 = "month"
   1.673 +
   1.674 +  do n = 0,nstation-1
   1.675 +;----------------------------
   1.676 +; for observed
   1.677 +
   1.678 +    plot_name = station(n)+"_ob"    
   1.679 +    title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")"
   1.680 +    res@tiMainString = title
   1.681 +
   1.682 +    wks = gsn_open_wks (plot_type,plot_name)
   1.683 +    plot=new(nfield,graphic)                        ; create graphic array   
   1.684 +
   1.685 +    do i = 0,nfield-1                           
   1.686 +       plot_data(0,:) = (/data_ob_ann(i,:,n)/)
   1.687 +       plot_data@long_name = field(i)+" ("+field_unit(i)+")"   
   1.688 +       plot(i)=gsn_csm_xy(wks,mon,plot_data(0,:),res)    ; create plot 
   1.689 +    end do
   1.690 +
   1.691 +    gsn_panel(wks,plot,(/3,2/),pres)                 ; create panel plot
   1.692 +
   1.693 +    system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
   1.694 +           "rm "+plot_name+"."+plot_type)
   1.695 +
   1.696 +    clear (wks)  
   1.697 +    delete (plot)
   1.698 +;----------------------------
   1.699 +; for model_vs_ob
   1.700 +
   1.701 +    plot_name = station(n)+"_model_vs_ob"
   1.702 +    title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")"    
   1.703 +    res@tiMainString = title
   1.704 +
   1.705 +    wks = gsn_open_wks (plot_type,plot_name)
   1.706 +    plot=new(nfield,graphic)                         ; create graphic array   
   1.707 +
   1.708 +    do i = 0,nfield-1                           
   1.709 +       plot_data(0,:) = (/data_ob_ann(i,:,n)/)
   1.710 +       plot_data(1,:) = (/data_mod_ann(i,:,n)/)
   1.711 +       plot_data@long_name = field(i)+" ("+field_unit(i)+")"   
   1.712 +       plot(i)=gsn_csm_xy(wks,mon,plot_data,res)     ; create plot 
   1.713 +    end do
   1.714 +   
   1.715 +    gsn_panel(wks,plot,(/3,2/),pres)                 ; create panel plot
   1.716 +
   1.717 +    system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
   1.718 +           "rm "+plot_name+"."+plot_type)
   1.719 +
   1.720 +    clear (wks)  
   1.721 +    delete (plot)
   1.722 + end do
   1.723 +
   1.724 +;###################################################################
   1.725 +; for the following tables,
   1.726 +; sort by latitude in decending order (N->S)
   1.727 +; sort by lat in decending order (N->S)
   1.728 +
   1.729 +  isort = dim_pqsort(lat_ob,-1)
   1.730 +
   1.731 +  station_sort = station(isort)
   1.732 +  year_ob_sort = year_ob(isort)
   1.733 +  lat_ob_sort  = lat_ob(isort)
   1.734 +  lon_ob_sort  = lon_ob(isort)
   1.735 +  M_score_sort = M_score(isort,:)
   1.736 + 
   1.737 +; print(isort)
   1.738 +; print(lat_ob_sort)
   1.739 +;###################################################################
   1.740 +;*******************************************************************
   1.741 +; html table of site: observed
   1.742 +;*******************************************************************
   1.743 +  output_html = "line_ob.html"
   1.744 +
   1.745 +  header = (/"<HTML>" \
   1.746 +            ,"<HEAD>" \
   1.747 +            ,"<TITLE>CLAMP metrics</TITLE>" \
   1.748 +            ,"</HEAD>" \
   1.749 +            ,"<H1>Energy at Site: Observation</H1>" \
   1.750 +            /) 
   1.751 +  footer = "</HTML>"
   1.752 +
   1.753 +  table_header = (/ \
   1.754 +        "<table border=1 cellspacing=0 cellpadding=3 width=60%>" \
   1.755 +       ,"<tr>" \
   1.756 +       ,"   <th bgcolor=DDDDDD >Site Name</th>" \
   1.757 +       ,"   <th bgcolor=DDDDDD >Latitude</th>" \
   1.758 +       ,"   <th bgcolor=DDDDDD >Longitude</th>" \
   1.759 +       ,"   <th bgcolor=DDDDDD >Observed</th>" \ 
   1.760 +       ,"</tr>" \
   1.761 +       /)
   1.762 +  table_footer = "</table>"
   1.763 +  row_header = "<tr>"
   1.764 +  row_footer = "</tr>"
   1.765 +
   1.766 +  lines = new(50000,string)
   1.767 +  nline = 0
   1.768 +
   1.769 +  set_line(lines,nline,header)
   1.770 +  set_line(lines,nline,table_header)
   1.771 +;-----------------------------------------------
   1.772 +; row of table
   1.773 +  
   1.774 +  do n = 0,nstation-1
   1.775 +     set_line(lines,nline,row_header)
   1.776 +
   1.777 +     txt0 = station_sort(n)
   1.778 +     txt1 = sprintf("%5.2f", lat_ob_sort(n))
   1.779 +     txt2 = sprintf("%5.2f", lon_ob_sort(n))
   1.780 +     txt3 = year_ob_sort(n)
   1.781 +
   1.782 +     set_line(lines,nline,"<th><a href="+txt0+"_ob.png>"+txt0+"</a></th>")
   1.783 +     set_line(lines,nline,"<th>"+txt1+"</th>")
   1.784 +     set_line(lines,nline,"<th>"+txt2+"</th>")
   1.785 +     set_line(lines,nline,"<th>"+txt3+"</th>")
   1.786 +
   1.787 +     set_line(lines,nline,row_footer)
   1.788 +  end do
   1.789 +;-----------------------------------------------
   1.790 +  set_line(lines,nline,table_footer)
   1.791 +  set_line(lines,nline,footer) 
   1.792 +
   1.793 +; Now write to an HTML file.
   1.794 +  idx = ind(.not.ismissing(lines))
   1.795 +  if(.not.any(ismissing(idx))) then
   1.796 +    asciiwrite(output_html,lines(idx))
   1.797 +  else
   1.798 +   print ("error?")
   1.799 +  end if
   1.800 +  delete (idx)
   1.801 +
   1.802 +;*******************************************************************
   1.803 +; score and line table : model vs observed
   1.804 +;*******************************************************************
   1.805 +  output_html = "score+line_vs_ob.html"
   1.806 +
   1.807 +  header = (/"<HTML>" \
   1.808 +            ,"<HEAD>" \
   1.809 +            ,"<TITLE>CLAMP metrics</TITLE>" \
   1.810 +            ,"</HEAD>" \
   1.811 +            ,"<H1>Energy at Site: Model "+model_name+"</H1>" \
   1.812 +            /) 
   1.813 +  footer = "</HTML>"
   1.814 +
   1.815 +  delete (table_header)
   1.816 +  table_header = (/ \
   1.817 +        "<table border=1 cellspacing=0 cellpadding=3 width=100%>" \
   1.818 +       ,"<tr>" \
   1.819 +       ,"   <th bgcolor=DDDDDD >Site Name</th>" \
   1.820 +       ,"   <th bgcolor=DDDDDD >Latitude</th>" \
   1.821 +       ,"   <th bgcolor=DDDDDD >Longitude</th>" \
   1.822 +       ,"   <th bgcolor=DDDDDD >Observed</th>" \
   1.823 +       ,"   <th bgcolor=DDDDDD >CO2 Flux</th>" \
   1.824 +       ,"   <th bgcolor=DDDDDD >Net Radiation</th>" \
   1.825 +       ,"   <th bgcolor=DDDDDD >Latent Heat</th>" \
   1.826 +       ,"   <th bgcolor=DDDDDD >Sensible Heat</th>" \
   1.827 +       ,"   <th bgcolor=DDDDDD >GPP Glux</th>" \
   1.828 +       ,"   <th bgcolor=DDDDDD >Respiration</th>" \
   1.829 +       ,"   <th bgcolor=DDDDDD >Average</th>" \
   1.830 +       ,"</tr>" \
   1.831 +       /)
   1.832 +  table_footer = "</table>"
   1.833 +  row_header = "<tr>"
   1.834 +  row_footer = "</tr>"
   1.835 +
   1.836 +  lines = new(50000,string)
   1.837 +  nline = 0
   1.838 +
   1.839 +  set_line(lines,nline,header)
   1.840 +  set_line(lines,nline,table_header)
   1.841 +;-----------------------------------------------
   1.842 +; row of table
   1.843 +  
   1.844 +  do n = 0,nstation-1
   1.845 +     set_line(lines,nline,row_header)
   1.846 +
   1.847 +     txt0  = station_sort(n)
   1.848 +     txt1  = sprintf("%5.2f", lat_ob_sort(n))
   1.849 +     txt2  = sprintf("%5.2f", lon_ob_sort(n))
   1.850 +     txt3  = year_ob_sort(n)
   1.851 +     txt4  = sprintf("%5.2f", M_score_sort(n,0))
   1.852 +     txt5  = sprintf("%5.2f", M_score_sort(n,1))
   1.853 +     txt6  = sprintf("%5.2f", M_score_sort(n,2))
   1.854 +     txt7  = sprintf("%5.2f", M_score_sort(n,3))
   1.855 +     txt8  = sprintf("%5.2f", M_score_sort(n,4))
   1.856 +     txt9  = sprintf("%5.2f", M_score_sort(n,5))
   1.857 +     txt10 = sprintf("%5.2f", avg(M_score_sort(n,:)))
   1.858 +
   1.859 +     set_line(lines,nline,"<th><a href="+txt0+"_model_vs_ob.png>"+txt0+"</a></th>")
   1.860 +     set_line(lines,nline,"<th>"+txt1+"</th>")
   1.861 +     set_line(lines,nline,"<th>"+txt2+"</th>")
   1.862 +     set_line(lines,nline,"<th>"+txt3+"</th>")
   1.863 +     set_line(lines,nline,"<th>"+txt4+"</th>")
   1.864 +     set_line(lines,nline,"<th>"+txt5+"</th>")
   1.865 +     set_line(lines,nline,"<th>"+txt6+"</th>")
   1.866 +     set_line(lines,nline,"<th>"+txt7+"</th>")
   1.867 +     set_line(lines,nline,"<th>"+txt8+"</th>")
   1.868 +     set_line(lines,nline,"<th>"+txt9+"</th>")
   1.869 +     set_line(lines,nline,"<th>"+txt10+"</th>")
   1.870 +
   1.871 +     set_line(lines,nline,row_footer)
   1.872 +  end do
   1.873 +
   1.874 +; last row, summary
   1.875 +  set_line(lines,nline,row_header)
   1.876 +
   1.877 +  txt0  = "All_"+sprintf("%.0f", nstation)
   1.878 +  txt1  = "-"
   1.879 +  txt2  = "-"
   1.880 +  txt3  = "-"
   1.881 +  txt4  = M_energy_co2
   1.882 +  txt5  = M_energy_rad
   1.883 +  txt6  = M_energy_lh
   1.884 +  txt7  = M_energy_sh
   1.885 +  txt8  = M_energy_gpp
   1.886 +  txt9  = M_energy_er
   1.887 +  txt10 = M_energy_all
   1.888 +
   1.889 +  set_line(lines,nline,"<th>"+txt0+"</th>")
   1.890 +  set_line(lines,nline,"<th>"+txt1+"</th>")
   1.891 +  set_line(lines,nline,"<th>"+txt2+"</th>")
   1.892 +  set_line(lines,nline,"<th>"+txt3+"</th>")
   1.893 +  set_line(lines,nline,"<th>"+txt4+"</th>")
   1.894 +  set_line(lines,nline,"<th>"+txt5+"</th>")
   1.895 +  set_line(lines,nline,"<th>"+txt6+"</th>")
   1.896 +  set_line(lines,nline,"<th>"+txt7+"</th>")
   1.897 +  set_line(lines,nline,"<th>"+txt8+"</th>")
   1.898 +  set_line(lines,nline,"<th>"+txt9+"</th>")
   1.899 +  set_line(lines,nline,"<th>"+txt10+"</th>")
   1.900 +
   1.901 +  set_line(lines,nline,row_footer)
   1.902 +;-----------------------------------------------
   1.903 +  set_line(lines,nline,table_footer)
   1.904 +  set_line(lines,nline,footer) 
   1.905 +
   1.906 +; Now write to an HTML file.
   1.907 +  idx = ind(.not.ismissing(lines))
   1.908 +  if(.not.any(ismissing(idx))) then
   1.909 +    asciiwrite(output_html,lines(idx))
   1.910 +  else
   1.911 +   print ("error?")
   1.912 +  end if
   1.913 +  delete (idx)
   1.914 +
   1.915 +;***************************************************************************
   1.916 +; output plots
   1.917 +;***************************************************************************
   1.918 +  output_dir = model_name+"/ameriflux"
   1.919 +
   1.920 +  system("mv *.png *.html " + output_dir) 
   1.921 +;***************************************************************************
   1.922 +end
   1.923 +