all/06.fluxnet.ncl
changeset 0 0c6405ab2ff4
child 1 4be95183fbcd
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/all/06.fluxnet.ncl	Mon Jan 26 22:08:20 2009 -0500
     1.3 @@ -0,0 +1,544 @@
     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 +; read model data
    1.45 +
    1.46 +  fm    = addfile(dirm+film2,"r")
    1.47 +  
    1.48 +  xm    = fm->lon
    1.49 +  ym    = fm->lat
    1.50 +
    1.51 +  nlat = dimsizes(ym)
    1.52 +  nlon = dimsizes(xm)
    1.53 +
    1.54 +; for 4 fields, 12-monthly
    1.55 +  nmon      = 12
    1.56 +  nfield    = 4
    1.57 +
    1.58 +  data_mod0 = new ((/nfield,nmon,nlat,nlon/),float)
    1.59 +
    1.60 +; change to unit of observed (u mol/m2/s)
    1.61 +; Model_units [=] gC/m2/s
    1.62 +; 12. = molecular weight of C
    1.63 +; u mol = 1e-6 mol
    1.64 +  factor = 1e6 /12.
    1.65 +
    1.66 +if (ENERGY .eq. "old") then
    1.67 +
    1.68 +  data = fm->NEE
    1.69 +  data_mod0(0,:,:,:) = data(:,:,:) * factor
    1.70 +  delete (data)
    1.71 +
    1.72 +; data  = fm->LATENT
    1.73 +  data1 = fm->FCEV
    1.74 +  data2 = fm->FCTR
    1.75 +  data3 = fm->FGEV
    1.76 +  data_mod0(2,:,:,:) = data1(:,:,:)+data2(:,:,:)+data3(:,:,:) 
    1.77 +  delete (data1)
    1.78 +  delete (data2)
    1.79 +  delete (data3)
    1.80 +
    1.81 +; data = fm->SENSIBLE
    1.82 +  data  = fm->FSH
    1.83 +  data_mod0(3,:,:,:) = data(:,:,:) 
    1.84 +  delete (data)
    1.85 +
    1.86 +; data  = fm->NETRAD
    1.87 +  data1 = fm->FSA
    1.88 +  data2 = fm->FIRA
    1.89 +  data_mod0(1,:,:,:) = data1(:,:,:)-data2(:,:,:) 
    1.90 +  delete (data1)
    1.91 +  delete (data2)
    1.92 +
    1.93 +else
    1.94 +
    1.95 +  data = fm->NEE
    1.96 +  data_mod0(0,:,:,:) = data(:,:,:) * factor
    1.97 +  delete (data)
    1.98 +
    1.99 +  data = fm->NETRAD
   1.100 +  data_mod0(1,:,:,:) = data(:,:,:) 
   1.101 +  delete (data)
   1.102 +
   1.103 +  data = fm->LATENT
   1.104 +  data_mod0(2,:,:,:) = data(:,:,:) 
   1.105 +  delete (data)
   1.106 +
   1.107 +  data = fm->FSH
   1.108 +  data_mod0(3,:,:,:) = data(:,:,:) 
   1.109 +  delete (data)
   1.110 +end if
   1.111 +
   1.112 + delete (fm)
   1.113 +
   1.114 +;************************************************
   1.115 +; read data: observed
   1.116 +;************************************************
   1.117 +
   1.118 + station = (/"BOREAS_NSA_OBS" \
   1.119 +            ,"CastelPorziano" \
   1.120 +            ,"Hyytiala" \
   1.121 +            ,"Kaamanen" \
   1.122 +            ,"LBA_Tapajos_KM67" \
   1.123 +            ,"Lethbridge" \
   1.124 +            ,"Tharandt" \
   1.125 +            ,"Vielsalm" \
   1.126 +            /)
   1.127 +
   1.128 + year_ob = (/"1994-2004" \
   1.129 +            ,"1997-2003" \
   1.130 +            ,"1996-2003" \
   1.131 +            ,"2000-2003" \
   1.132 +            ,"2002-2005" \
   1.133 +            ,"1999-2004" \
   1.134 +            ,"1996-2003" \
   1.135 +            ,"1998-2003" \
   1.136 +            /)
   1.137 +
   1.138 + field   = (/"NEE" \
   1.139 +            ,"Net Radiation" \
   1.140 +            ,"Latent Heat" \
   1.141 +            ,"Sensible Heat" \
   1.142 +            /)
   1.143 +
   1.144 + nstation  = dimsizes(station)
   1.145 + nmon      = 12
   1.146 + nfield    = dimsizes(field)
   1.147 +
   1.148 + data_ob   = new ((/nstation, nfield, nmon/),float)
   1.149 + lat_ob    = new ((/nstation/),float)
   1.150 + lon_ob    = new ((/nstation/),float)
   1.151 +
   1.152 + diri_root  = diro + "fluxnet/"
   1.153 +
   1.154 + do n = 0,nstation-1
   1.155 +    diri = diri_root + station(n)+"/"
   1.156 +    fili = station(n)+"_"+year_ob(n)+"_monthly.nc"
   1.157 +    g     = addfile (diri+fili,"r")
   1.158 + 
   1.159 +    lon_ob(n) = g->lon 
   1.160 +    lat_ob(n) = g->lat
   1.161 +
   1.162 +    data      = g->CO2_FLUX
   1.163 +    data_ob(n,0,:) = dim_avg(data(month|:,year|:))
   1.164 +    delete (data)
   1.165 +
   1.166 +    data      = g->RAD_FLUX
   1.167 +    data_ob(n,1,:) = dim_avg(data(month|:,year|:))
   1.168 +    delete (data)
   1.169 +
   1.170 +    data      = g->LH_FLUX
   1.171 +    data_ob(n,2,:) = dim_avg(data(month|:,year|:))
   1.172 +    delete (data)
   1.173 +
   1.174 +    data      = g->SH_FLUX
   1.175 +    data_ob(n,3,:) = dim_avg(data(month|:,year|:))
   1.176 +    delete (data)
   1.177 +
   1.178 +    delete (g)
   1.179 + end do
   1.180 +
   1.181 +;************************************************************
   1.182 +; interpolate model data into observed station
   1.183 +; note: model is 0-360E, 90S-90N
   1.184 +;************************************************************
   1.185 +
   1.186 +; to be able to handle observation at (-89.98,-24.80)
   1.187 +  ym(0) = -90.  
   1.188 +
   1.189 +  yy = linint2_points_Wrap(xm,ym,data_mod0,True,lon_ob,lat_ob,0)
   1.190 +
   1.191 +  delete (data_mod0)
   1.192 +  yy!0 = "field"
   1.193 +  data_mod = yy(pts|:,field|:,time|:)
   1.194 +
   1.195 +;************************************************************
   1.196 +; compute correlation coef and M score
   1.197 +;************************************************************
   1.198 +
   1.199 + score_max = 5.
   1.200 +
   1.201 + ccr     = new ((/nstation, nfield/),float)
   1.202 + M_score = new ((/nstation, nfield/),float) 
   1.203 +
   1.204 + do n=0,nstation-1
   1.205 + do m=0,nfield-1   
   1.206 +    ccr(n,m) = esccr(data_ob(n,m,:),data_mod(n,m,:),0)
   1.207 +    bias = sum(abs(data_mod(n,m,:)-data_ob(n,m,:))/(abs(data_mod(n,m,:))+abs(data_ob(n,m,:))))
   1.208 +    M_score(n,m) = (1. -(bias/nmon)) * score_max
   1.209 + end do
   1.210 + end do
   1.211 +
   1.212 + M_nee = avg(M_score(:,0))
   1.213 + M_rad = avg(M_score(:,1))
   1.214 + M_lh  = avg(M_score(:,2))
   1.215 + M_sh  = avg(M_score(:,3))
   1.216 + M_all = M_nee+ M_rad +M_lh + M_sh
   1.217 +
   1.218 + M_fluxnet_nee = sprintf("%.2f", M_nee)
   1.219 + M_fluxnet_rad = sprintf("%.2f", M_rad)
   1.220 + M_fluxnet_lh  = sprintf("%.2f", M_lh )
   1.221 + M_fluxnet_sh  = sprintf("%.2f", M_sh )
   1.222 + M_fluxnet_all = sprintf("%.2f", M_all)
   1.223 +
   1.224 +;*******************************************************************
   1.225 +; for station line plot
   1.226 +;*******************************************************************
   1.227 +
   1.228 +; for x-axis in xyplot
   1.229 +  mon = ispan(1,12,1)
   1.230 +  mon@long_name = "month"
   1.231 +
   1.232 +  res                   = True               ; plot mods desired
   1.233 +  res@xyLineThicknesses = (/2.0,2.0/)        ; make 2nd lines thicker
   1.234 +  res@xyLineColors      = (/"blue","red"/)   ; line color (ob,model)
   1.235 +;-------------------------------------------------------------------------
   1.236 +; Add a boxed legend using the more simple method
   1.237 +
   1.238 +  res@pmLegendDisplayMode    = "Always"
   1.239 +; res@pmLegendWidthF         = 0.1
   1.240 +  res@pmLegendWidthF         = 0.08
   1.241 +  res@pmLegendHeightF        = 0.06
   1.242 +; res@pmLegendOrthogonalPosF = -1.17
   1.243 +; res@pmLegendOrthogonalPosF = -1.00  ;(downward)
   1.244 +  res@pmLegendOrthogonalPosF = -0.30  ;(downward)
   1.245 +
   1.246 +; res@pmLegendParallelPosF   =  0.18
   1.247 +  res@pmLegendParallelPosF   =  0.23  ;(rightward)
   1.248 +
   1.249 +; res@lgPerimOn             = False
   1.250 +  res@lgLabelFontHeightF     = 0.015
   1.251 +  res@xyExplicitLegendLabels = (/"observed",model_name/)
   1.252 +;-------------------------------------------------------------------
   1.253 +; for panel plot
   1.254 +  res@gsnFrame     = False                   ; Do not draw plot 
   1.255 +  res@gsnDraw      = False                   ; Do not advance frame
   1.256 +
   1.257 +  pres                            = True     ; panel plot mods desired
   1.258 +  pres@gsnPanelYWhiteSpacePercent = 5        ; increase white space around
   1.259 +                                             ; indiv. plots in panel
   1.260 +  pres@gsnMaximize                = True     ; fill the page
   1.261 +;-------------------------------------------------------------------
   1.262 +
   1.263 +  plot_data   = new((/2,12/),float)
   1.264 +  plot_data!0 = "case"
   1.265 +  plot_data!1 = "month"
   1.266 +
   1.267 +; change longitude from 0-360 to -180-180
   1.268 +  lon_ob = where(lon_ob .gt. 180.,lon_ob-360., lon_ob)
   1.269 +
   1.270 +  do n = 0,nstation-1
   1.271 +;----------------------------
   1.272 +; for observed
   1.273 +
   1.274 +    plot_name = station(n)+"_ob"    
   1.275 +    title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")"
   1.276 +    res@tiMainString = title
   1.277 +
   1.278 +    wks = gsn_open_wks (plot_type,plot_name)
   1.279 +    plot=new(4,graphic)                        ; create graphic array   
   1.280 +                           
   1.281 +    plot_data(0,:) = (/data_ob (n,0,:)/)
   1.282 +    plot_data@long_name = field(0)   
   1.283 +    plot(0)=gsn_csm_xy(wks,mon,plot_data(0,:),res)   ; create plot 1
   1.284 +
   1.285 +    plot_data(0,:) = (/data_ob (n,1,:)/)
   1.286 +    plot_data@long_name = field(1)
   1.287 +    plot(1)=gsn_csm_xy(wks,mon,plot_data(0,:),res)   ; create plot 2
   1.288 +
   1.289 +    plot_data(0,:) = (/data_ob (n,2,:)/)
   1.290 +    plot_data@long_name = field(2)   
   1.291 +    plot(2)=gsn_csm_xy(wks,mon,plot_data(0,:),res)   ; create plot 3
   1.292 +
   1.293 +    plot_data(0,:) = (/data_ob (n,3,:)/)
   1.294 +    plot_data@long_name = field(3)
   1.295 +    plot(3)=gsn_csm_xy(wks,mon,plot_data(0,:),res)   ; create plot 4
   1.296 +
   1.297 +    gsn_panel(wks,plot,(/2,2/),pres)                 ; create panel plot
   1.298 +
   1.299 +    delete (wks)  
   1.300 +    delete (plot)
   1.301 +
   1.302 +    system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
   1.303 +           "rm "+plot_name+"."+plot_type)
   1.304 +
   1.305 +;----------------------------
   1.306 +; for model_vs_ob
   1.307 +
   1.308 +    plot_name = station(n)+"_model_vs_ob"
   1.309 +    title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")"    
   1.310 +    res@tiMainString = title
   1.311 +
   1.312 +    wks = gsn_open_wks (plot_type,plot_name)
   1.313 +    plot=new(4,graphic)                        ; create graphic array   
   1.314 +                           
   1.315 +    plot_data(0,:) = (/data_ob (n,0,:)/)
   1.316 +    plot_data(1,:) = (/data_mod(n,0,:)/)
   1.317 +    plot_data@long_name = field(0)   
   1.318 +    plot(0)=gsn_csm_xy(wks,mon,plot_data,res)   ; create plot 1
   1.319 +
   1.320 +    plot_data(0,:) = (/data_ob (n,1,:)/)
   1.321 +    plot_data(1,:) = (/data_mod(n,1,:)/)
   1.322 +    plot_data@long_name = field(1)
   1.323 +    plot(1)=gsn_csm_xy(wks,mon,plot_data,res)   ; create plot 2
   1.324 +
   1.325 +    plot_data(0,:) = (/data_ob (n,2,:)/)
   1.326 +    plot_data(1,:) = (/data_mod(n,2,:)/)
   1.327 +    plot_data@long_name = field(2)   
   1.328 +    plot(2)=gsn_csm_xy(wks,mon,plot_data,res)   ; create plot 3
   1.329 +
   1.330 +    plot_data(0,:) = (/data_ob (n,3,:)/)
   1.331 +    plot_data(1,:) = (/data_mod(n,3,:)/)
   1.332 +    plot_data@long_name = field(3)
   1.333 +    plot(3)=gsn_csm_xy(wks,mon,plot_data,res)   ; create plot 4
   1.334 +
   1.335 +    gsn_panel(wks,plot,(/2,2/),pres)                 ; create panel plot
   1.336 +
   1.337 +    delete (wks)  
   1.338 +    delete (plot)
   1.339 +
   1.340 +    system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
   1.341 +           "rm "+plot_name+"."+plot_type)
   1.342 + end do
   1.343 +
   1.344 +;*******************************************************************
   1.345 +; html table of site: observed
   1.346 +;*******************************************************************
   1.347 +  output_html = "line_ob.html"
   1.348 +
   1.349 +  header = (/"<HTML>" \
   1.350 +            ,"<HEAD>" \
   1.351 +            ,"<TITLE>CLAMP metrics</TITLE>" \
   1.352 +            ,"</HEAD>" \
   1.353 +            ,"<H1>Fluxnet at Site: Observation</H1>" \
   1.354 +            /) 
   1.355 +  footer = "</HTML>"
   1.356 +
   1.357 +  table_header = (/ \
   1.358 +        "<table border=1 cellspacing=0 cellpadding=3 width=60%>" \
   1.359 +       ,"<tr>" \
   1.360 +       ,"   <th bgcolor=DDDDDD >Site Name</th>" \
   1.361 +       ,"   <th bgcolor=DDDDDD >Latitude</th>" \
   1.362 +       ,"   <th bgcolor=DDDDDD >Longitude</th>" \
   1.363 +       ,"   <th bgcolor=DDDDDD >Observed</th>" \ 
   1.364 +       ,"</tr>" \
   1.365 +       /)
   1.366 +  table_footer = "</table>"
   1.367 +  row_header = "<tr>"
   1.368 +  row_footer = "</tr>"
   1.369 +
   1.370 +  lines = new(50000,string)
   1.371 +  nline = 0
   1.372 +
   1.373 +  set_line(lines,nline,header)
   1.374 +  set_line(lines,nline,table_header)
   1.375 +;-----------------------------------------------
   1.376 +; row of table
   1.377 +  
   1.378 +  do n = 0,nstation-1
   1.379 +     set_line(lines,nline,row_header)
   1.380 +
   1.381 +     txt0 = station(n)
   1.382 +     txt1 = sprintf("%5.2f", lat_ob(n))
   1.383 +     txt2 = sprintf("%5.2f", lon_ob(n))
   1.384 +     txt3 = year_ob(n)
   1.385 +
   1.386 +     set_line(lines,nline,"<th><a href="+txt0+"_ob.png>"+txt0+"</a></th>")
   1.387 +     set_line(lines,nline,"<th>"+txt1+"</th>")
   1.388 +     set_line(lines,nline,"<th>"+txt2+"</th>")
   1.389 +     set_line(lines,nline,"<th>"+txt3+"</th>")
   1.390 +
   1.391 +     set_line(lines,nline,row_footer)
   1.392 +  end do
   1.393 +;-----------------------------------------------
   1.394 +  set_line(lines,nline,table_footer)
   1.395 +  set_line(lines,nline,footer) 
   1.396 +
   1.397 +; Now write to an HTML file.
   1.398 +  idx = ind(.not.ismissing(lines))
   1.399 +  if(.not.any(ismissing(idx))) then
   1.400 +    asciiwrite(output_html,lines(idx))
   1.401 +  else
   1.402 +   print ("error?")
   1.403 +  end if
   1.404 +  delete (idx)
   1.405 +
   1.406 +;*******************************************************************
   1.407 +; score and line table : model vs observed
   1.408 +;*******************************************************************
   1.409 +  output_html = "score+line_vs_ob.html"
   1.410 +
   1.411 +  header = (/"<HTML>" \
   1.412 +            ,"<HEAD>" \
   1.413 +            ,"<TITLE>CLAMP metrics</TITLE>" \
   1.414 +            ,"</HEAD>" \
   1.415 +            ,"<H1>Fluxnet at Site: Model "+model_name+"</H1>" \
   1.416 +            /) 
   1.417 +  footer = "</HTML>"
   1.418 +
   1.419 +  delete (table_header)
   1.420 +  table_header = (/ \
   1.421 +        "<table border=1 cellspacing=0 cellpadding=3 width=100%>" \
   1.422 +       ,"<tr>" \
   1.423 +       ,"   <th bgcolor=DDDDDD >Site Name</th>" \
   1.424 +       ,"   <th bgcolor=DDDDDD >Latitude</th>" \
   1.425 +       ,"   <th bgcolor=DDDDDD >Longitude</th>" \
   1.426 +       ,"   <th bgcolor=DDDDDD >Observed</th>" \
   1.427 +       ,"   <th bgcolor=DDDDDD >NEE</th>" \
   1.428 +       ,"   <th bgcolor=DDDDDD >Net Radiation</th>" \
   1.429 +       ,"   <th bgcolor=DDDDDD >Latent Heat</th>" \
   1.430 +       ,"   <th bgcolor=DDDDDD >Sensible Heat</th>" \
   1.431 +       ,"   <th bgcolor=DDDDDD >Average</th>" \
   1.432 +       ,"</tr>" \
   1.433 +       /)
   1.434 +  table_footer = "</table>"
   1.435 +  row_header = "<tr>"
   1.436 +  row_footer = "</tr>"
   1.437 +
   1.438 +  lines = new(50000,string)
   1.439 +  nline = 0
   1.440 +
   1.441 +  set_line(lines,nline,header)
   1.442 +  set_line(lines,nline,table_header)
   1.443 +;-----------------------------------------------
   1.444 +; row of table
   1.445 +  
   1.446 +  do n = 0,nstation-1
   1.447 +     set_line(lines,nline,row_header)
   1.448 +
   1.449 +     txt0 = station(n)
   1.450 +     txt1 = sprintf("%5.2f", lat_ob(n))
   1.451 +     txt2 = sprintf("%5.2f", lon_ob(n))
   1.452 +     txt3 = year_ob(n)
   1.453 +     txt4 = sprintf("%5.2f", M_score(n,0))
   1.454 +     txt5 = sprintf("%5.2f", M_score(n,1))
   1.455 +     txt6 = sprintf("%5.2f", M_score(n,2))
   1.456 +     txt7 = sprintf("%5.2f", M_score(n,3))
   1.457 +     txt8 = sprintf("%5.2f", avg(M_score(n,:)))
   1.458 +
   1.459 +     set_line(lines,nline,"<th><a href="+txt0+"_model_vs_ob.png>"+txt0+"</a></th>")
   1.460 +     set_line(lines,nline,"<th>"+txt1+"</th>")
   1.461 +     set_line(lines,nline,"<th>"+txt2+"</th>")
   1.462 +     set_line(lines,nline,"<th>"+txt3+"</th>")
   1.463 +     set_line(lines,nline,"<th>"+txt4+"</th>")
   1.464 +     set_line(lines,nline,"<th>"+txt5+"</th>")
   1.465 +     set_line(lines,nline,"<th>"+txt6+"</th>")
   1.466 +     set_line(lines,nline,"<th>"+txt7+"</th>")
   1.467 +     set_line(lines,nline,"<th>"+txt8+"</th>")
   1.468 +
   1.469 +     set_line(lines,nline,row_footer)
   1.470 +  end do
   1.471 +
   1.472 +; last row, summary
   1.473 +  set_line(lines,nline,row_header)
   1.474 +
   1.475 +  txt0 = "All_"+sprintf("%.0f", nstation)
   1.476 +  txt1 = "-"
   1.477 +  txt2 = "-"
   1.478 +  txt3 = "-"
   1.479 +  txt4 = M_fluxnet_nee
   1.480 +  txt5 = M_fluxnet_rad
   1.481 +  txt6 = M_fluxnet_lh
   1.482 +  txt7 = M_fluxnet_sh
   1.483 +  txt8 = M_fluxnet_all
   1.484 +
   1.485 +  set_line(lines,nline,"<th>"+txt0+"</th>")
   1.486 +  set_line(lines,nline,"<th>"+txt1+"</th>")
   1.487 +  set_line(lines,nline,"<th>"+txt2+"</th>")
   1.488 +  set_line(lines,nline,"<th>"+txt3+"</th>")
   1.489 +  set_line(lines,nline,"<th>"+txt4+"</th>")
   1.490 +  set_line(lines,nline,"<th>"+txt5+"</th>")
   1.491 +  set_line(lines,nline,"<th>"+txt6+"</th>")
   1.492 +  set_line(lines,nline,"<th>"+txt7+"</th>")
   1.493 +  set_line(lines,nline,"<th>"+txt8+"</th>")
   1.494 +
   1.495 +  set_line(lines,nline,row_footer)
   1.496 +;-----------------------------------------------
   1.497 +  set_line(lines,nline,table_footer)
   1.498 +  set_line(lines,nline,footer) 
   1.499 +
   1.500 +; Now write to an HTML file.
   1.501 +  idx = ind(.not.ismissing(lines))
   1.502 +  if(.not.any(ismissing(idx))) then
   1.503 +    asciiwrite(output_html,lines(idx))
   1.504 +  else
   1.505 +   print ("error?")
   1.506 +  end if
   1.507 +  delete (idx)
   1.508 +
   1.509 +;**************************************************************************************
   1.510 +; update score
   1.511 +;**************************************************************************************
   1.512 + 
   1.513 +  if (isvar("compare")) then
   1.514 +     system("sed -e '1,/M_fluxnet_nee/s/M_fluxnet_nee/"+M_fluxnet_nee+"/' "+html_name2+" > "+html_new2+";"+ \
   1.515 +            "mv -f "+html_new2+" "+html_name2+";"+ \
   1.516 +            "sed -e '1,/M_fluxnet_rad/s/M_fluxnet_rad/"+M_fluxnet_rad+"/' "+html_name2+" > "+html_new2+";"+ \
   1.517 +            "mv -f "+html_new2+" "+html_name2+";"+ \
   1.518 +            "sed -e '1,/M_fluxnet_lh/s/M_fluxnet_lh/"+M_fluxnet_lh+"/' "+html_name2+" > "+html_new2+";"+ \
   1.519 +            "mv -f "+html_new2+" "+html_name2+";"+ \
   1.520 +            "sed -e '1,/M_fluxnet_sh/s/M_fluxnet_sh/"+M_fluxnet_sh+"/' "+html_name2+" > "+html_new2+";"+ \
   1.521 +            "mv -f "+html_new2+" "+html_name2)
   1.522 +  end if
   1.523 +
   1.524 +  system("sed s#M_fluxnet_nee#"+M_fluxnet_nee+"# "+html_name+" > "+html_new+";"+ \
   1.525 +         "mv -f "+html_new+" "+html_name+";"+ \
   1.526 +         "sed s#M_fluxnet_rad#"+M_fluxnet_rad+"# "+html_name+" > "+html_new+";"+ \
   1.527 +         "mv -f "+html_new+" "+html_name+";"+ \
   1.528 +         "sed s#M_fluxnet_lh#"+M_fluxnet_lh+"# "+html_name+" > "+html_new+";"+ \
   1.529 +         "mv -f "+html_new+" "+html_name+";"+ \
   1.530 +         "sed s#M_fluxnet_sh#"+M_fluxnet_sh+"# "+html_name+" > "+html_new+";"+ \
   1.531 +         "mv -f "+html_new+" "+html_name) 
   1.532 +
   1.533 +;***************************************************************************
   1.534 +; add total score and write to file
   1.535 +;***************************************************************************
   1.536 +  M_total = M_fluxnet_all
   1.537 +
   1.538 +  asciiwrite("M_save.fluxnet", M_total)
   1.539 +
   1.540 +;***************************************************************************
   1.541 +; output plots
   1.542 +;***************************************************************************
   1.543 +  output_dir = model_name+"/fluxnet"
   1.544 +
   1.545 +  system("mv *.png *.html " + output_dir) 
   1.546 +;***************************************************************************
   1.547 +end