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