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