ameriflux/11.plot.ncl
author Forrest Hoffman <forrest@climatemodeling.org>
Mon, 26 Jan 2009 22:08:20 -0500
changeset 0 0c6405ab2ff4
permissions -rw-r--r--
Initial commit of C-LAMP Diagnostics from Jeff Lee
forrest@0
     1
;************************************************************
forrest@0
     2
; required command line input parameters:
forrest@0
     3
;  ncl 'model_name="10cn" model_grid="T42" dirm="/.../ film="..."' 01.npp.ncl
forrest@0
     4
;
forrest@0
     5
; using gsn_table for all
forrest@0
     6
; output: line plot for each site (4 fields)
forrest@0
     7
;         table for M_score
forrest@0
     8
;************************************************************
forrest@0
     9
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
forrest@0
    10
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
forrest@0
    11
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
forrest@0
    12
;************************************************************
forrest@0
    13
procedure set_line(lines:string,nline:integer,newlines:string) 
forrest@0
    14
begin
forrest@0
    15
; add line to ascci/html file
forrest@0
    16
    
forrest@0
    17
  nnewlines = dimsizes(newlines)
forrest@0
    18
  if(nline+nnewlines-1.ge.dimsizes(lines))
forrest@0
    19
    print("set_line: bad index, not setting anything.") 
forrest@0
    20
    return
forrest@0
    21
  end if 
forrest@0
    22
  lines(nline:nline+nnewlines-1) = newlines
forrest@0
    23
;  print ("lines = " + lines(nline:nline+nnewlines-1))
forrest@0
    24
  nline = nline + nnewlines
forrest@0
    25
  return 
forrest@0
    26
end
forrest@0
    27
;*************************************************************
forrest@0
    28
begin
forrest@0
    29
forrest@0
    30
  plot_type     = "ps"
forrest@0
    31
  plot_type_new = "png"
forrest@0
    32
forrest@0
    33
; for 6 fields, 12-monthly
forrest@0
    34
  nmon      = 12
forrest@0
    35
  nfield    = 6
forrest@0
    36
forrest@0
    37
;************************************************
forrest@0
    38
; read model data
forrest@0
    39
;************************************************
forrest@0
    40
; model = "cn"
forrest@0
    41
  model = "casa"
forrest@0
    42
  
forrest@0
    43
  model_name = "i01.10" + model
forrest@0
    44
forrest@0
    45
  dirm  = "/fis/cgd/cseg/people/jeff/surface_data/"
forrest@0
    46
  film  = "lnd_T42.nc"
forrest@0
    47
  fm    = addfile(dirm+film,"r")
forrest@0
    48
  
forrest@0
    49
  xm    = fm->lon
forrest@0
    50
  ym    = fm->lat
forrest@0
    51
;------------------------------------------------
forrest@0
    52
  nlat = dimsizes(ym)
forrest@0
    53
  nlon = dimsizes(xm)
forrest@0
    54
forrest@0
    55
  data_mod0 = new ((/nfield,nmon,nlat,nlon/),float)
forrest@0
    56
forrest@0
    57
; change to unit of observed (u mol/m2/s)
forrest@0
    58
; Model_units [=] gC/m2/s
forrest@0
    59
; 12. = molecular weight of C
forrest@0
    60
; u mol = 1e-6 mol
forrest@0
    61
  factor = 1e6 /12.
forrest@0
    62
forrest@0
    63
  ENERGY ="new"
forrest@0
    64
forrest@0
    65
;************************************************
forrest@0
    66
; read data: observed
forrest@0
    67
;************************************************
forrest@0
    68
forrest@0
    69
 station = (/"Duke_Forest_Hardwoods" \
forrest@0
    70
            ,"Duke_Forest_Open_Field" \
forrest@0
    71
            ,"Duke_Forest_Pine" \
forrest@0
    72
            ,"HarvardForest" \
forrest@0
    73
            /)
forrest@0
    74
forrest@0
    75
 year_ob = (/"2003-2005" \
forrest@0
    76
            ,"2001-2005" \
forrest@0
    77
            ,"2001-2005" \
forrest@0
    78
            ,"1991-2004" \
forrest@0
    79
            /)
forrest@0
    80
forrest@0
    81
 field   = (/"CO2 Flux" \
forrest@0
    82
            ,"Net Radiation" \
forrest@0
    83
            ,"Latent Heat" \
forrest@0
    84
            ,"Sensible Heat" \
forrest@0
    85
            ,"GPP Flux" \
forrest@0
    86
            ,"Respiration" \
forrest@0
    87
            /)
forrest@0
    88
forrest@0
    89
 nstation  = dimsizes(station)
forrest@0
    90
forrest@0
    91
 data_mod  = new ((/nstation, nfield, nmon/),float)
forrest@0
    92
 data_ob   = new ((/nstation, nfield, nmon/),float)
forrest@0
    93
 lat_ob    = new ((/nstation/),float)
forrest@0
    94
 lon_ob    = new ((/nstation/),float)
forrest@0
    95
forrest@0
    96
 diro_root  = "/fis/cgd/cseg/people/jeff/clamp/ameriflux/"
forrest@0
    97
 dirm_root  = "/fis/cgd/cseg/people/jeff/clamp_data/model/"
forrest@0
    98
forrest@0
    99
 do n = 0,nstation-1
forrest@0
   100
forrest@0
   101
;-------------------------------------------------
forrest@0
   102
;   get ob data
forrest@0
   103
forrest@0
   104
    diro = diro_root + station(n)+"/"
forrest@0
   105
    filo = year_ob(n)+"_L4_m.nc"
forrest@0
   106
    fo   = addfile (diro+filo,"r")
forrest@0
   107
forrest@0
   108
    print (filo)
forrest@0
   109
 
forrest@0
   110
    lon_ob(n) = fo->lon 
forrest@0
   111
    lat_ob(n) = fo->lat
forrest@0
   112
forrest@0
   113
    data      = fo->NEE_or_fMDS
forrest@0
   114
    data_ob(n,0,:) = dim_avg(data(month|:,year|:))
forrest@0
   115
    delete (data)
forrest@0
   116
forrest@0
   117
    data      = fo->Rg_f
forrest@0
   118
    data_ob(n,1,:) = dim_avg(data(month|:,year|:))
forrest@0
   119
    delete (data)
forrest@0
   120
forrest@0
   121
    data      = fo->LE_f
forrest@0
   122
    data_ob(n,2,:) = dim_avg(data(month|:,year|:))
forrest@0
   123
    delete (data)
forrest@0
   124
forrest@0
   125
    data      = fo->H_f
forrest@0
   126
    data_ob(n,3,:) = dim_avg(data(month|:,year|:))
forrest@0
   127
    delete (data)
forrest@0
   128
forrest@0
   129
    data      = fo->GPP_or_MDS
forrest@0
   130
    data_ob(n,4,:) = dim_avg(data(month|:,year|:))
forrest@0
   131
    delete (data)
forrest@0
   132
forrest@0
   133
    data      = fo->Reco_or
forrest@0
   134
    data_ob(n,5,:) = dim_avg(data(month|:,year|:))
forrest@0
   135
    delete (data)
forrest@0
   136
forrest@0
   137
    delete (fo)
forrest@0
   138
;---------------------------------------------------
forrest@0
   139
;   get model data
forrest@0
   140
forrest@0
   141
    film = model_name+"_"+year_ob(n)+"_MONS_climo.nc"
forrest@0
   142
    fm   = addfile (dirm_root+film,"r")
forrest@0
   143
forrest@0
   144
    print (film)
forrest@0
   145
forrest@0
   146
if (ENERGY .eq. "old") then
forrest@0
   147
forrest@0
   148
  data = fm->NEE
forrest@0
   149
  data_mod0(0,:,:,:) = data(:,:,:) * factor
forrest@0
   150
  delete (data)
forrest@0
   151
forrest@0
   152
; data  = fm->LATENT
forrest@0
   153
  data1 = fm->FCEV
forrest@0
   154
  data2 = fm->FCTR
forrest@0
   155
  data3 = fm->FGEV
forrest@0
   156
  data_mod0(2,:,:,:) = data1(:,:,:)+data2(:,:,:)+data3(:,:,:) 
forrest@0
   157
  delete (data1)
forrest@0
   158
  delete (data2)
forrest@0
   159
  delete (data3)
forrest@0
   160
forrest@0
   161
; data = fm->SENSIBLE
forrest@0
   162
  data  = fm->FSH
forrest@0
   163
  data_mod0(3,:,:,:) = data(:,:,:) 
forrest@0
   164
  delete (data)
forrest@0
   165
forrest@0
   166
; data  = fm->NETRAD
forrest@0
   167
  data1 = fm->FSA
forrest@0
   168
  data2 = fm->FIRA
forrest@0
   169
  data_mod0(1,:,:,:) = data1(:,:,:)-data2(:,:,:)-data_mod0(2,:,:,:)-data_mod0(3,:,:,:) 
forrest@0
   170
  delete (data1)
forrest@0
   171
  delete (data2)
forrest@0
   172
forrest@0
   173
else
forrest@0
   174
forrest@0
   175
  data = fm->NEE
forrest@0
   176
  data_mod0(0,:,:,:) = data(:,:,:) * factor
forrest@0
   177
  delete (data)
forrest@0
   178
forrest@0
   179
  data = fm->NETRAD
forrest@0
   180
  data_mod0(1,:,:,:) = data(:,:,:) 
forrest@0
   181
  delete (data)
forrest@0
   182
forrest@0
   183
  data = fm->LATENT
forrest@0
   184
  data_mod0(2,:,:,:) = data(:,:,:) 
forrest@0
   185
  delete (data)
forrest@0
   186
forrest@0
   187
; data = fm->SENSIBLE
forrest@0
   188
  data = fm->FSH
forrest@0
   189
  data_mod0(3,:,:,:) = data(:,:,:) 
forrest@0
   190
  delete (data)
forrest@0
   191
end if
forrest@0
   192
forrest@0
   193
  data = fm->GPP
forrest@0
   194
  data_mod0(4,:,:,:) = data(:,:,:) * factor 
forrest@0
   195
  delete (data)
forrest@0
   196
forrest@0
   197
  if (model .eq. "cn") then
forrest@0
   198
     data = fm->ER
forrest@0
   199
  else
forrest@0
   200
     data1 = fm->AR
forrest@0
   201
     data2 = fm->HR
forrest@0
   202
     data  = data1 + data2
forrest@0
   203
    
forrest@0
   204
     delete (data1)
forrest@0
   205
     delete (data2)
forrest@0
   206
  end if
forrest@0
   207
forrest@0
   208
  data_mod0(5,:,:,:) = data(:,:,:) * factor
forrest@0
   209
  delete (data)
forrest@0
   210
forrest@0
   211
  delete (fm) 
forrest@0
   212
forrest@0
   213
;************************************************************
forrest@0
   214
; interpolate model data into observed station
forrest@0
   215
; note: model is 0-360E, 90S-90N
forrest@0
   216
;************************************************************
forrest@0
   217
forrest@0
   218
; to be able to handle observation at (-89.98,-24.80)
forrest@0
   219
  ym(0) = -90.  
forrest@0
   220
forrest@0
   221
  yy = linint2_points_Wrap(xm,ym,data_mod0,True,lon_ob(n),lat_ob(n),0)
forrest@0
   222
forrest@0
   223
; print (yy)
forrest@0
   224
 
forrest@0
   225
  data_mod(n,:,:) = yy(:,:,0)
forrest@0
   226
forrest@0
   227
  delete (yy)
forrest@0
   228
forrest@0
   229
 end do
forrest@0
   230
;************************************************************
forrest@0
   231
; compute correlation coef and M score
forrest@0
   232
;************************************************************
forrest@0
   233
forrest@0
   234
 score_max = 5.
forrest@0
   235
forrest@0
   236
 ccr     = new ((/nstation, nfield/),float)
forrest@0
   237
 M_score = new ((/nstation, nfield/),float) 
forrest@0
   238
forrest@0
   239
 do n=0,nstation-1
forrest@0
   240
 do m=0,nfield-1   
forrest@0
   241
    ccr(n,m) = esccr(data_ob(n,m,:),data_mod(n,m,:),0)
forrest@0
   242
    bias = sum(abs(data_mod(n,m,:)-data_ob(n,m,:))/(abs(data_mod(n,m,:))+abs(data_ob(n,m,:))))
forrest@0
   243
    M_score(n,m) = (1. -(bias/nmon)) * score_max
forrest@0
   244
 end do
forrest@0
   245
 end do
forrest@0
   246
forrest@0
   247
 M_co2 = avg(M_score(:,0))
forrest@0
   248
 M_rad = avg(M_score(:,1))
forrest@0
   249
 M_lh  = avg(M_score(:,2))
forrest@0
   250
 M_sh  = avg(M_score(:,3))
forrest@0
   251
 M_gpp = avg(M_score(:,4))
forrest@0
   252
 M_er  = avg(M_score(:,5))
forrest@0
   253
 M_all = M_co2+ M_rad +M_lh + M_sh + M_gpp + M_er
forrest@0
   254
forrest@0
   255
 M_energy_co2 = sprintf("%.2f", M_co2)
forrest@0
   256
 M_energy_rad = sprintf("%.2f", M_rad)
forrest@0
   257
 M_energy_lh  = sprintf("%.2f", M_lh )
forrest@0
   258
 M_energy_sh  = sprintf("%.2f", M_sh )
forrest@0
   259
 M_energy_gpp = sprintf("%.2f", M_gpp)
forrest@0
   260
 M_energy_er  = sprintf("%.2f", M_er )
forrest@0
   261
 M_energy_all = sprintf("%.2f", M_all)
forrest@0
   262
forrest@0
   263
;*******************************************************************
forrest@0
   264
; for station line plot
forrest@0
   265
;*******************************************************************
forrest@0
   266
forrest@0
   267
; for x-axis in xyplot
forrest@0
   268
  mon = ispan(1,12,1)
forrest@0
   269
  mon@long_name = "month"
forrest@0
   270
forrest@0
   271
  res                   = True               ; plot mods desired
forrest@0
   272
  res@xyLineThicknesses = (/2.0,2.0/)        ; make 2nd lines thicker
forrest@0
   273
  res@xyLineColors      = (/"blue","red"/)   ; line color (ob,model)
forrest@0
   274
;-------------------------------------------------------------------------
forrest@0
   275
; Add a boxed legend using the more simple method
forrest@0
   276
forrest@0
   277
  res@pmLegendDisplayMode    = "Always"
forrest@0
   278
; res@pmLegendWidthF         = 0.1
forrest@0
   279
  res@pmLegendWidthF         = 0.08
forrest@0
   280
  res@pmLegendHeightF        = 0.06
forrest@0
   281
; res@pmLegendOrthogonalPosF = -1.17
forrest@0
   282
; res@pmLegendOrthogonalPosF = -1.00  ;(downward)
forrest@0
   283
  res@pmLegendOrthogonalPosF = -0.30  ;(downward)
forrest@0
   284
forrest@0
   285
; res@pmLegendParallelPosF   =  0.18
forrest@0
   286
  res@pmLegendParallelPosF   =  0.23  ;(rightward)
forrest@0
   287
forrest@0
   288
; res@lgPerimOn             = False
forrest@0
   289
  res@lgLabelFontHeightF     = 0.015
forrest@0
   290
  res@xyExplicitLegendLabels = (/"observed",model_name/)
forrest@0
   291
;-------------------------------------------------------------------
forrest@0
   292
; for panel plot
forrest@0
   293
  res@gsnFrame     = False                   ; Do not draw plot 
forrest@0
   294
  res@gsnDraw      = False                   ; Do not advance frame
forrest@0
   295
forrest@0
   296
  pres                            = True     ; panel plot mods desired
forrest@0
   297
  pres@gsnPanelYWhiteSpacePercent = 5        ; increase white space around
forrest@0
   298
                                             ; indiv. plots in panel
forrest@0
   299
  pres@gsnMaximize                = True     ; fill the page
forrest@0
   300
;-------------------------------------------------------------------
forrest@0
   301
forrest@0
   302
  plot_data   = new((/2,12/),float)
forrest@0
   303
  plot_data!0 = "case"
forrest@0
   304
  plot_data!1 = "month"
forrest@0
   305
forrest@0
   306
  do n = 0,nstation-1
forrest@0
   307
;----------------------------
forrest@0
   308
; for observed
forrest@0
   309
forrest@0
   310
    plot_name = station(n)+"_ob"    
forrest@0
   311
    title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")"
forrest@0
   312
    res@tiMainString = title
forrest@0
   313
forrest@0
   314
    wks = gsn_open_wks (plot_type,plot_name)
forrest@0
   315
    plot=new(nfield,graphic)                        ; create graphic array   
forrest@0
   316
                           
forrest@0
   317
    plot_data(0,:) = (/data_ob (n,0,:)/)
forrest@0
   318
    plot_data@long_name = field(0)   
forrest@0
   319
    plot(0)=gsn_csm_xy(wks,mon,plot_data(0,:),res)   ; create plot 1
forrest@0
   320
forrest@0
   321
    plot_data(0,:) = (/data_ob (n,1,:)/)
forrest@0
   322
    plot_data@long_name = field(1)
forrest@0
   323
    plot(1)=gsn_csm_xy(wks,mon,plot_data(0,:),res)   ; create plot 2
forrest@0
   324
forrest@0
   325
    plot_data(0,:) = (/data_ob (n,2,:)/)
forrest@0
   326
    plot_data@long_name = field(2)   
forrest@0
   327
    plot(2)=gsn_csm_xy(wks,mon,plot_data(0,:),res)   ; create plot 3
forrest@0
   328
forrest@0
   329
    plot_data(0,:) = (/data_ob (n,3,:)/)
forrest@0
   330
    plot_data@long_name = field(3)
forrest@0
   331
    plot(3)=gsn_csm_xy(wks,mon,plot_data(0,:),res)   ; create plot 4
forrest@0
   332
forrest@0
   333
    plot_data(0,:) = (/data_ob (n,4,:)/)
forrest@0
   334
    plot_data@long_name = field(4)
forrest@0
   335
    plot(4)=gsn_csm_xy(wks,mon,plot_data(0,:),res)   ; create plot 5
forrest@0
   336
forrest@0
   337
    plot_data(0,:) = (/data_ob (n,5,:)/)
forrest@0
   338
    plot_data@long_name = field(5)
forrest@0
   339
    plot(5)=gsn_csm_xy(wks,mon,plot_data(0,:),res)   ; create plot 6
forrest@0
   340
forrest@0
   341
    gsn_panel(wks,plot,(/3,2/),pres)                 ; create panel plot
forrest@0
   342
forrest@0
   343
    system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
forrest@0
   344
           "rm "+plot_name+"."+plot_type)
forrest@0
   345
forrest@0
   346
    clear (wks)  
forrest@0
   347
    delete (plot)
forrest@0
   348
;----------------------------
forrest@0
   349
; for model_vs_ob
forrest@0
   350
forrest@0
   351
    plot_name = station(n)+"_model_vs_ob"
forrest@0
   352
    title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")"    
forrest@0
   353
    res@tiMainString = title
forrest@0
   354
forrest@0
   355
    wks = gsn_open_wks (plot_type,plot_name)
forrest@0
   356
    plot=new(nfield,graphic)                        ; create graphic array   
forrest@0
   357
                           
forrest@0
   358
    plot_data(0,:) = (/data_ob (n,0,:)/)
forrest@0
   359
    plot_data(1,:) = (/data_mod(n,0,:)/)
forrest@0
   360
    plot_data@long_name = field(0)   
forrest@0
   361
    plot(0)=gsn_csm_xy(wks,mon,plot_data,res)   ; create plot 1
forrest@0
   362
forrest@0
   363
    plot_data(0,:) = (/data_ob (n,1,:)/)
forrest@0
   364
    plot_data(1,:) = (/data_mod(n,1,:)/)
forrest@0
   365
    plot_data@long_name = field(1)
forrest@0
   366
    plot(1)=gsn_csm_xy(wks,mon,plot_data,res)   ; create plot 2
forrest@0
   367
forrest@0
   368
    plot_data(0,:) = (/data_ob (n,2,:)/)
forrest@0
   369
    plot_data(1,:) = (/data_mod(n,2,:)/)
forrest@0
   370
    plot_data@long_name = field(2)   
forrest@0
   371
    plot(2)=gsn_csm_xy(wks,mon,plot_data,res)   ; create plot 3
forrest@0
   372
forrest@0
   373
    plot_data(0,:) = (/data_ob (n,3,:)/)
forrest@0
   374
    plot_data(1,:) = (/data_mod(n,3,:)/)
forrest@0
   375
    plot_data@long_name = field(3)
forrest@0
   376
    plot(3)=gsn_csm_xy(wks,mon,plot_data,res)   ; create plot 4
forrest@0
   377
forrest@0
   378
forrest@0
   379
    plot_data(0,:) = (/data_ob (n,4,:)/)
forrest@0
   380
    plot_data(1,:) = (/data_mod(n,4,:)/)
forrest@0
   381
    plot_data@long_name = field(4)
forrest@0
   382
    plot(4)=gsn_csm_xy(wks,mon,plot_data,res)   ; create plot 5
forrest@0
   383
forrest@0
   384
forrest@0
   385
    plot_data(0,:) = (/data_ob (n,5,:)/)
forrest@0
   386
    plot_data(1,:) = (/data_mod(n,5,:)/)
forrest@0
   387
    plot_data@long_name = field(5)
forrest@0
   388
    plot(5)=gsn_csm_xy(wks,mon,plot_data,res)   ; create plot 6
forrest@0
   389
forrest@0
   390
    gsn_panel(wks,plot,(/3,2/),pres)                 ; create panel plot
forrest@0
   391
forrest@0
   392
    system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
forrest@0
   393
           "rm "+plot_name+"."+plot_type)
forrest@0
   394
forrest@0
   395
    clear (wks)  
forrest@0
   396
    delete (plot)
forrest@0
   397
 end do
forrest@0
   398
forrest@0
   399
;*******************************************************************
forrest@0
   400
; html table of site: observed
forrest@0
   401
;*******************************************************************
forrest@0
   402
  output_html = "line_ob.html"
forrest@0
   403
forrest@0
   404
  header = (/"<HTML>" \
forrest@0
   405
            ,"<HEAD>" \
forrest@0
   406
            ,"<TITLE>CLAMP metrics</TITLE>" \
forrest@0
   407
            ,"</HEAD>" \
forrest@0
   408
            ,"<H1>Energy at Site: Observation</H1>" \
forrest@0
   409
            /) 
forrest@0
   410
  footer = "</HTML>"
forrest@0
   411
forrest@0
   412
  table_header = (/ \
forrest@0
   413
        "<table border=1 cellspacing=0 cellpadding=3 width=60%>" \
forrest@0
   414
       ,"<tr>" \
forrest@0
   415
       ,"   <th bgcolor=DDDDDD >Site Name</th>" \
forrest@0
   416
       ,"   <th bgcolor=DDDDDD >Latitude</th>" \
forrest@0
   417
       ,"   <th bgcolor=DDDDDD >Longitude</th>" \
forrest@0
   418
       ,"   <th bgcolor=DDDDDD >Observed</th>" \ 
forrest@0
   419
       ,"</tr>" \
forrest@0
   420
       /)
forrest@0
   421
  table_footer = "</table>"
forrest@0
   422
  row_header = "<tr>"
forrest@0
   423
  row_footer = "</tr>"
forrest@0
   424
forrest@0
   425
  lines = new(50000,string)
forrest@0
   426
  nline = 0
forrest@0
   427
forrest@0
   428
  set_line(lines,nline,header)
forrest@0
   429
  set_line(lines,nline,table_header)
forrest@0
   430
;-----------------------------------------------
forrest@0
   431
; row of table
forrest@0
   432
  
forrest@0
   433
  do n = 0,nstation-1
forrest@0
   434
     set_line(lines,nline,row_header)
forrest@0
   435
forrest@0
   436
     txt0 = station(n)
forrest@0
   437
     txt1 = sprintf("%5.2f", lat_ob(n))
forrest@0
   438
     txt2 = sprintf("%5.2f", lon_ob(n))
forrest@0
   439
     txt3 = year_ob(n)
forrest@0
   440
forrest@0
   441
     set_line(lines,nline,"<th><a href="+txt0+"_ob.png>"+txt0+"</a></th>")
forrest@0
   442
     set_line(lines,nline,"<th>"+txt1+"</th>")
forrest@0
   443
     set_line(lines,nline,"<th>"+txt2+"</th>")
forrest@0
   444
     set_line(lines,nline,"<th>"+txt3+"</th>")
forrest@0
   445
forrest@0
   446
     set_line(lines,nline,row_footer)
forrest@0
   447
  end do
forrest@0
   448
;-----------------------------------------------
forrest@0
   449
  set_line(lines,nline,table_footer)
forrest@0
   450
  set_line(lines,nline,footer) 
forrest@0
   451
forrest@0
   452
; Now write to an HTML file.
forrest@0
   453
  idx = ind(.not.ismissing(lines))
forrest@0
   454
  if(.not.any(ismissing(idx))) then
forrest@0
   455
    asciiwrite(output_html,lines(idx))
forrest@0
   456
  else
forrest@0
   457
   print ("error?")
forrest@0
   458
  end if
forrest@0
   459
  delete (idx)
forrest@0
   460
forrest@0
   461
;*******************************************************************
forrest@0
   462
; score and line table : model vs observed
forrest@0
   463
;*******************************************************************
forrest@0
   464
  output_html = "score+line_vs_ob.html"
forrest@0
   465
forrest@0
   466
  header = (/"<HTML>" \
forrest@0
   467
            ,"<HEAD>" \
forrest@0
   468
            ,"<TITLE>CLAMP metrics</TITLE>" \
forrest@0
   469
            ,"</HEAD>" \
forrest@0
   470
            ,"<H1>Energy at Site: Model "+model_name+"</H1>" \
forrest@0
   471
            /) 
forrest@0
   472
  footer = "</HTML>"
forrest@0
   473
forrest@0
   474
  delete (table_header)
forrest@0
   475
  table_header = (/ \
forrest@0
   476
        "<table border=1 cellspacing=0 cellpadding=3 width=100%>" \
forrest@0
   477
       ,"<tr>" \
forrest@0
   478
       ,"   <th bgcolor=DDDDDD >Site Name</th>" \
forrest@0
   479
       ,"   <th bgcolor=DDDDDD >Latitude</th>" \
forrest@0
   480
       ,"   <th bgcolor=DDDDDD >Longitude</th>" \
forrest@0
   481
       ,"   <th bgcolor=DDDDDD >Observed</th>" \
forrest@0
   482
       ,"   <th bgcolor=DDDDDD >CO2 Flux</th>" \
forrest@0
   483
       ,"   <th bgcolor=DDDDDD >Net Radiation</th>" \
forrest@0
   484
       ,"   <th bgcolor=DDDDDD >Latent Heat</th>" \
forrest@0
   485
       ,"   <th bgcolor=DDDDDD >Sensible Heat</th>" \
forrest@0
   486
       ,"   <th bgcolor=DDDDDD >GPP Glux</th>" \
forrest@0
   487
       ,"   <th bgcolor=DDDDDD >Respiration</th>" \
forrest@0
   488
       ,"   <th bgcolor=DDDDDD >Average</th>" \
forrest@0
   489
       ,"</tr>" \
forrest@0
   490
       /)
forrest@0
   491
  table_footer = "</table>"
forrest@0
   492
  row_header = "<tr>"
forrest@0
   493
  row_footer = "</tr>"
forrest@0
   494
forrest@0
   495
  lines = new(50000,string)
forrest@0
   496
  nline = 0
forrest@0
   497
forrest@0
   498
  set_line(lines,nline,header)
forrest@0
   499
  set_line(lines,nline,table_header)
forrest@0
   500
;-----------------------------------------------
forrest@0
   501
; row of table
forrest@0
   502
  
forrest@0
   503
  do n = 0,nstation-1
forrest@0
   504
     set_line(lines,nline,row_header)
forrest@0
   505
forrest@0
   506
     txt0  = station(n)
forrest@0
   507
     txt1  = sprintf("%5.2f", lat_ob(n))
forrest@0
   508
     txt2  = sprintf("%5.2f", lon_ob(n))
forrest@0
   509
     txt3  = year_ob(n)
forrest@0
   510
     txt4  = sprintf("%5.2f", M_score(n,0))
forrest@0
   511
     txt5  = sprintf("%5.2f", M_score(n,1))
forrest@0
   512
     txt6  = sprintf("%5.2f", M_score(n,2))
forrest@0
   513
     txt7  = sprintf("%5.2f", M_score(n,3))
forrest@0
   514
     txt8  = sprintf("%5.2f", M_score(n,4))
forrest@0
   515
     txt9  = sprintf("%5.2f", M_score(n,5))
forrest@0
   516
     txt10 = sprintf("%5.2f", avg(M_score(n,:)))
forrest@0
   517
forrest@0
   518
     set_line(lines,nline,"<th><a href="+txt0+"_model_vs_ob.png>"+txt0+"</a></th>")
forrest@0
   519
     set_line(lines,nline,"<th>"+txt1+"</th>")
forrest@0
   520
     set_line(lines,nline,"<th>"+txt2+"</th>")
forrest@0
   521
     set_line(lines,nline,"<th>"+txt3+"</th>")
forrest@0
   522
     set_line(lines,nline,"<th>"+txt4+"</th>")
forrest@0
   523
     set_line(lines,nline,"<th>"+txt5+"</th>")
forrest@0
   524
     set_line(lines,nline,"<th>"+txt6+"</th>")
forrest@0
   525
     set_line(lines,nline,"<th>"+txt7+"</th>")
forrest@0
   526
     set_line(lines,nline,"<th>"+txt8+"</th>")
forrest@0
   527
     set_line(lines,nline,"<th>"+txt9+"</th>")
forrest@0
   528
     set_line(lines,nline,"<th>"+txt10+"</th>")
forrest@0
   529
forrest@0
   530
     set_line(lines,nline,row_footer)
forrest@0
   531
  end do
forrest@0
   532
forrest@0
   533
; last row, summary
forrest@0
   534
  set_line(lines,nline,row_header)
forrest@0
   535
forrest@0
   536
  txt0  = "All_"+sprintf("%.0f", nstation)
forrest@0
   537
  txt1  = "-"
forrest@0
   538
  txt2  = "-"
forrest@0
   539
  txt3  = "-"
forrest@0
   540
  txt4  = M_energy_co2
forrest@0
   541
  txt5  = M_energy_rad
forrest@0
   542
  txt6  = M_energy_lh
forrest@0
   543
  txt7  = M_energy_sh
forrest@0
   544
  txt8  = M_energy_gpp
forrest@0
   545
  txt9  = M_energy_er
forrest@0
   546
  txt10 = M_energy_all
forrest@0
   547
forrest@0
   548
  set_line(lines,nline,"<th>"+txt0+"</th>")
forrest@0
   549
  set_line(lines,nline,"<th>"+txt1+"</th>")
forrest@0
   550
  set_line(lines,nline,"<th>"+txt2+"</th>")
forrest@0
   551
  set_line(lines,nline,"<th>"+txt3+"</th>")
forrest@0
   552
  set_line(lines,nline,"<th>"+txt4+"</th>")
forrest@0
   553
  set_line(lines,nline,"<th>"+txt5+"</th>")
forrest@0
   554
  set_line(lines,nline,"<th>"+txt6+"</th>")
forrest@0
   555
  set_line(lines,nline,"<th>"+txt7+"</th>")
forrest@0
   556
  set_line(lines,nline,"<th>"+txt8+"</th>")
forrest@0
   557
  set_line(lines,nline,"<th>"+txt9+"</th>")
forrest@0
   558
  set_line(lines,nline,"<th>"+txt10+"</th>")
forrest@0
   559
forrest@0
   560
  set_line(lines,nline,row_footer)
forrest@0
   561
;-----------------------------------------------
forrest@0
   562
  set_line(lines,nline,table_footer)
forrest@0
   563
  set_line(lines,nline,footer) 
forrest@0
   564
forrest@0
   565
; Now write to an HTML file.
forrest@0
   566
  idx = ind(.not.ismissing(lines))
forrest@0
   567
  if(.not.any(ismissing(idx))) then
forrest@0
   568
    asciiwrite(output_html,lines(idx))
forrest@0
   569
  else
forrest@0
   570
   print ("error?")
forrest@0
   571
  end if
forrest@0
   572
  delete (idx)
forrest@0
   573
forrest@0
   574
;***************************************************************************
forrest@0
   575
; output plots
forrest@0
   576
;***************************************************************************
forrest@0
   577
  output_dir = model_name+"/ameriflux"
forrest@0
   578
forrest@0
   579
  system("mv *.png *.html " + output_dir) 
forrest@0
   580
;***************************************************************************
forrest@0
   581
end