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