beta/07.landfrac.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
; take into account landfrac
forrest@0
     3
; note: landfrac from lnd_T42.nc
forrest@0
     4
;       <= lnd_diag_4.0 has correct landfrac
forrest@0
     5
;          lnd_diag_3.1 has wrong   landfrac  
forrest@0
     6
;
forrest@0
     7
; using model biome
forrest@0
     8
;
forrest@0
     9
; required command line input parameters:
forrest@0
    10
;  ncl 'model_name="10cn" model_grid="T42" dirm="/.../ film="..."' 01.npp.ncl
forrest@0
    11
;
forrest@0
    12
;**************************************************************
forrest@0
    13
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
forrest@0
    14
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
forrest@0
    15
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
forrest@0
    16
;**************************************************************
forrest@0
    17
procedure set_line(lines:string,nline:integer,newlines:string) 
forrest@0
    18
begin
forrest@0
    19
; add line to ascci/html file
forrest@0
    20
    
forrest@0
    21
  nnewlines = dimsizes(newlines)
forrest@0
    22
  if(nline+nnewlines-1.ge.dimsizes(lines))
forrest@0
    23
    print("set_line: bad index, not setting anything.") 
forrest@0
    24
    return
forrest@0
    25
  end if 
forrest@0
    26
  lines(nline:nline+nnewlines-1) = newlines
forrest@0
    27
;  print ("lines = " + lines(nline:nline+nnewlines-1))
forrest@0
    28
  nline = nline + nnewlines
forrest@0
    29
  return 
forrest@0
    30
end
forrest@0
    31
;**************************************************************
forrest@0
    32
; Main code.
forrest@0
    33
begin
forrest@0
    34
 
forrest@0
    35
 plot_type     = "ps"
forrest@0
    36
 plot_type_new = "png"
forrest@0
    37
forrest@0
    38
;************************************************
forrest@0
    39
; read data: model       
forrest@0
    40
;************************************************
forrest@0
    41
 co2_i = 283.1878
forrest@0
    42
 co2_f = 364.1252
forrest@0
    43
forrest@0
    44
 model_grid = "T42"
forrest@0
    45
forrest@0
    46
;model_name_i = "i01.07cn"
forrest@0
    47
;model_name_f = "i01.10cn"
forrest@0
    48
forrest@0
    49
 model_name_i = "i01.07casa"
forrest@0
    50
 model_name_f = "i01.10casa"
forrest@0
    51
forrest@0
    52
 model_name = model_name_f
forrest@0
    53
forrest@0
    54
 dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/"
forrest@0
    55
 film_i = model_name_i + "_1990-2004_ANN_climo.nc"
forrest@0
    56
 film_f = model_name_f + "_1990-2004_ANN_climo.nc"
forrest@0
    57
forrest@0
    58
 fm_i   = addfile (dirm+film_i,"r")
forrest@0
    59
 fm_f   = addfile (dirm+film_f,"r")
forrest@0
    60
  
forrest@0
    61
 xm     = fm_f->lon  
forrest@0
    62
 ym     = fm_f->lat
forrest@0
    63
forrest@0
    64
 npp_i  = fm_i->NPP
forrest@0
    65
 npp_f  = fm_f->NPP
forrest@0
    66
forrest@0
    67
 delete (fm_i)
forrest@0
    68
 delete (fm_f)
forrest@0
    69
forrest@0
    70
;Units for these variables are:
forrest@0
    71
;npp_i: g C/m^2/s
forrest@0
    72
forrest@0
    73
 nsec_per_year = 60*60*24*365
forrest@0
    74
  
forrest@0
    75
 npp_i = npp_i *  nsec_per_year
forrest@0
    76
 npp_f = npp_f *  nsec_per_year
forrest@0
    77
forrest@0
    78
;--------------------------------------------------
forrest@0
    79
;get landfrac data
forrest@0
    80
forrest@0
    81
 dirm= "/fis/cgd/cseg/people/jeff/surface_data/" 
forrest@0
    82
 film_l = "lnd_T42.nc"
forrest@0
    83
 fm_l   = addfile (dirm+film_l,"r")
forrest@0
    84
  
forrest@0
    85
 landfrac = fm_l->landfrac
forrest@0
    86
forrest@0
    87
;npp_i(0,:,:) = npp_i(0,:,:) * landfrac(:,:)
forrest@0
    88
;npp_f(0,:,:) = npp_f(0,:,:) * landfrac(:,:)
forrest@0
    89
forrest@0
    90
 npp_i = npp_i * conform(npp_i, landfrac, (/1,2/))
forrest@0
    91
 npp_f = npp_f * conform(npp_f, landfrac, (/1,2/))
forrest@0
    92
    
forrest@0
    93
;===================================================
forrest@0
    94
; read data: observed at stations
forrest@0
    95
;===================================================
forrest@0
    96
forrest@0
    97
 station = (/"DukeFACE" \
forrest@0
    98
            ,"AspenFACE" \
forrest@0
    99
            ,"ORNL-FACE" \
forrest@0
   100
            ,"POP-EUROFACE" \
forrest@0
   101
            /)
forrest@0
   102
forrest@0
   103
 lat_ob = (/ 35.58,  45.40,  35.54, 42.22/)
forrest@0
   104
 lon_ob = (/-79.05, -89.37, -84.20, 11.48/)
forrest@0
   105
 lon_ob = where(lon_ob.lt.0.,lon_ob+360.,lon_ob)
forrest@0
   106
;print (lon_ob)
forrest@0
   107
forrest@0
   108
 n_sta  = dimsizes(station)
forrest@0
   109
 beta_4_ob = new((/n_sta/),float)
forrest@0
   110
 beta_4_ob = 0.60
forrest@0
   111
forrest@0
   112
;===================================================
forrest@0
   113
; get model data at station 
forrest@0
   114
;===================================================
forrest@0
   115
forrest@0
   116
 npp_i_4  =linint2_points(xm,ym,npp_i,True,lon_ob,lat_ob,0)
forrest@0
   117
forrest@0
   118
 npp_f_4  =linint2_points(xm,ym,npp_f,True,lon_ob,lat_ob,0)
forrest@0
   119
forrest@0
   120
;print (npp_i_4)
forrest@0
   121
;print (npp_f_4)
forrest@0
   122
forrest@0
   123
;============================
forrest@0
   124
;compute beta_4
forrest@0
   125
;============================
forrest@0
   126
forrest@0
   127
 beta_4 = new((/n_sta/),float)
forrest@0
   128
forrest@0
   129
 beta_4 = ((npp_f_4/npp_i_4) - 1.)/log(co2_f/co2_i)
forrest@0
   130
forrest@0
   131
 beta_4_avg = avg(beta_4)
forrest@0
   132
forrest@0
   133
;print (beta_4)
forrest@0
   134
;print (beta_4_avg)
forrest@0
   135
forrest@0
   136
;M_beta = abs((beta_4_avg/beta_4_ob) - 1.)* 3.
forrest@0
   137
forrest@0
   138
 bias = sum(abs(beta_4-beta_4_ob)/(abs(beta_4)+abs(beta_4_ob))) 
forrest@0
   139
 M_beta  = (1. - (bias/n_sta))*3.
forrest@0
   140
 
forrest@0
   141
 print (M_beta)
forrest@0
   142
forrest@0
   143
;=========================
forrest@0
   144
; for html table - station
forrest@0
   145
;=========================
forrest@0
   146
forrest@0
   147
  output_html = "table_station.html"
forrest@0
   148
forrest@0
   149
; column (not including header column)
forrest@0
   150
forrest@0
   151
  col_head = (/"Latitude","Longitude","CO2_i","CO2_f","NPP_i","NPP_f","Beta_model","Beta_ob"/)
forrest@0
   152
forrest@0
   153
  ncol = dimsizes(col_head)
forrest@0
   154
forrest@0
   155
; row (not including header row)
forrest@0
   156
  row_head = (/"DukeFACE" \
forrest@0
   157
              ,"AspenFACE" \
forrest@0
   158
              ,"ORNL-FACE" \
forrest@0
   159
              ,"POP-EUROFACE" \
forrest@0
   160
              ,"All Station" \                
forrest@0
   161
              /)  
forrest@0
   162
  nrow = dimsizes(row_head)                  
forrest@0
   163
forrest@0
   164
; arrays to be passed to table. 
forrest@0
   165
  text4 = new ((/nrow, ncol/),string )
forrest@0
   166
forrest@0
   167
 do i=0,nrow-2
forrest@0
   168
  text4(i,0) = sprintf("%.1f",lat_ob(i))
forrest@0
   169
  text4(i,1) = sprintf("%.1f",lon_ob(i))
forrest@0
   170
  text4(i,2) = sprintf("%.1f",co2_i)
forrest@0
   171
  text4(i,3) = sprintf("%.1f",co2_f)
forrest@0
   172
  text4(i,4) = sprintf("%.1f",npp_i_4(0,i))
forrest@0
   173
  text4(i,5) = sprintf("%.1f",npp_f_4(0,i))
forrest@0
   174
  text4(i,6) = sprintf("%.2f",beta_4(i))
forrest@0
   175
  text4(i,7) = "-"
forrest@0
   176
 end do
forrest@0
   177
  text4(nrow-1,0) = "-"
forrest@0
   178
  text4(nrow-1,1) = "-"
forrest@0
   179
  text4(nrow-1,2) = "-"
forrest@0
   180
  text4(nrow-1,3) = "-"
forrest@0
   181
  text4(nrow-1,4) = "-"
forrest@0
   182
  text4(nrow-1,5) = "-"
forrest@0
   183
  text4(nrow-1,6) = sprintf("%.2f",beta_4_avg)
forrest@0
   184
  text4(nrow-1,7) = sprintf("%.2f",avg(beta_4_ob))
forrest@0
   185
forrest@0
   186
;-----------
forrest@0
   187
; html table
forrest@0
   188
;-----------
forrest@0
   189
forrest@0
   190
  header_text = "<H1>Beta Factor: Model "+model_name+"</H1>" 
forrest@0
   191
forrest@0
   192
  header = (/"<HTML>" \
forrest@0
   193
            ,"<HEAD>" \
forrest@0
   194
            ,"<TITLE>CLAMP metrics</TITLE>" \
forrest@0
   195
            ,"</HEAD>" \
forrest@0
   196
            ,header_text \
forrest@0
   197
            /) 
forrest@0
   198
  footer = "</HTML>"
forrest@0
   199
forrest@0
   200
  table_header = (/ \
forrest@0
   201
        "<table border=1 cellspacing=0 cellpadding=3 width=80%>" \
forrest@0
   202
       ,"<tr>" \
forrest@0
   203
       ,"   <th bgcolor=DDDDDD >Station</th>" \
forrest@0
   204
       ,"   <th bgcolor=DDDDDD >"+col_head(0)+"</th>" \
forrest@0
   205
       ,"   <th bgcolor=DDDDDD >"+col_head(1)+"</th>" \
forrest@0
   206
       ,"   <th bgcolor=DDDDDD >"+col_head(2)+"</th>" \
forrest@0
   207
       ,"   <th bgcolor=DDDDDD >"+col_head(3)+"</th>" \
forrest@0
   208
       ,"   <th bgcolor=DDDDDD >"+col_head(4)+"</th>" \
forrest@0
   209
       ,"   <th bgcolor=DDDDDD >"+col_head(5)+"</th>" \
forrest@0
   210
       ,"   <th bgcolor=DDDDDD >"+col_head(6)+"</th>" \
forrest@0
   211
       ,"   <th bgcolor=DDDDDD >"+col_head(7)+"</th>" \
forrest@0
   212
       ,"</tr>" \
forrest@0
   213
       /)
forrest@0
   214
  table_footer = "</table>"
forrest@0
   215
  row_header = "<tr>"
forrest@0
   216
  row_footer = "</tr>"
forrest@0
   217
forrest@0
   218
  lines = new(50000,string)
forrest@0
   219
  nline = 0
forrest@0
   220
forrest@0
   221
  set_line(lines,nline,header)
forrest@0
   222
  set_line(lines,nline,table_header)
forrest@0
   223
;-----------------------------------------------
forrest@0
   224
;row of table
forrest@0
   225
forrest@0
   226
  do n = 0,nrow-1
forrest@0
   227
     set_line(lines,nline,row_header)
forrest@0
   228
forrest@0
   229
     txt1  = row_head(n)
forrest@0
   230
     txt2  = text4(n,0)
forrest@0
   231
     txt3  = text4(n,1)
forrest@0
   232
     txt4  = text4(n,2)
forrest@0
   233
     txt5  = text4(n,3)
forrest@0
   234
     txt6  = text4(n,4)
forrest@0
   235
     txt7  = text4(n,5)
forrest@0
   236
     txt8  = text4(n,6)
forrest@0
   237
     txt9  = text4(n,7)
forrest@0
   238
forrest@0
   239
     set_line(lines,nline,"<th>"+txt1+"</th>")
forrest@0
   240
     set_line(lines,nline,"<th>"+txt2+"</th>")
forrest@0
   241
     set_line(lines,nline,"<th>"+txt3+"</th>")
forrest@0
   242
     set_line(lines,nline,"<th>"+txt4+"</th>")
forrest@0
   243
     set_line(lines,nline,"<th>"+txt5+"</th>")
forrest@0
   244
     set_line(lines,nline,"<th>"+txt6+"</th>")
forrest@0
   245
     set_line(lines,nline,"<th>"+txt7+"</th>")
forrest@0
   246
     set_line(lines,nline,"<th>"+txt8+"</th>")
forrest@0
   247
     set_line(lines,nline,"<th>"+txt9+"</th>")
forrest@0
   248
forrest@0
   249
     set_line(lines,nline,row_footer)
forrest@0
   250
  end do
forrest@0
   251
;-----------------------------------------------
forrest@0
   252
  set_line(lines,nline,table_footer)
forrest@0
   253
  set_line(lines,nline,footer) 
forrest@0
   254
forrest@0
   255
; Now write to an HTML file.
forrest@0
   256
  idx = ind(.not.ismissing(lines))
forrest@0
   257
  if(.not.any(ismissing(idx))) then
forrest@0
   258
    asciiwrite(output_html,lines(idx))
forrest@0
   259
  else
forrest@0
   260
   print ("error?")
forrest@0
   261
  end if
forrest@0
   262
forrest@0
   263
  delete (col_head)
forrest@0
   264
  delete (row_head)
forrest@0
   265
  delete (text4)
forrest@0
   266
  delete (table_header)
forrest@0
   267
  delete (idx)
forrest@0
   268
forrest@0
   269
;------------------------------------------------
forrest@0
   270
; read biome data: model
forrest@0
   271
forrest@0
   272
  biome_name_mod = "Model PFT Class"
forrest@0
   273
forrest@0
   274
  dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/"
forrest@0
   275
  film = "class_pft_"+model_grid+".nc"
forrest@0
   276
forrest@0
   277
  fm = addfile(dirm+film,"r")
forrest@0
   278
 
forrest@0
   279
  classmod = fm->CLASS_PFT               
forrest@0
   280
forrest@0
   281
  delete (fm)
forrest@0
   282
forrest@0
   283
; model data has 17 land-type classes
forrest@0
   284
forrest@0
   285
  nclass_mod = 17
forrest@0
   286
forrest@0
   287
;------------------------------------------------
forrest@0
   288
; read biome data: observed
forrest@0
   289
forrest@0
   290
  biome_name_ob = "MODIS LandCover"
forrest@0
   291
forrest@0
   292
  diro = "/fis/cgd/cseg/people/jeff/clamp_data/lai/ob/"
forrest@0
   293
  filo = "land_class_"+model_grid+".nc"
forrest@0
   294
forrest@0
   295
  fo = addfile(diro+filo,"r")
forrest@0
   296
 
forrest@0
   297
  classob = tofloat(fo->LAND_CLASS)               
forrest@0
   298
forrest@0
   299
  delete (fo)
forrest@0
   300
forrest@0
   301
; input observed data has 20 land-type classes
forrest@0
   302
forrest@0
   303
  nclass_ob = 20
forrest@0
   304
                
forrest@0
   305
;********************************************************************
forrest@0
   306
; use land-type class to bin the data in equally spaced ranges
forrest@0
   307
;********************************************************************
forrest@0
   308
forrest@0
   309
; using observed biome class  
forrest@0
   310
; nclass      = nclass_ob
forrest@0
   311
; using model biome class
forrest@0
   312
  nclass      = nclass_mod
forrest@0
   313
forrest@0
   314
  nclassn     = nclass + 1
forrest@0
   315
  range       = fspan(0,nclassn-1,nclassn)
forrest@0
   316
; print (range)
forrest@0
   317
forrest@0
   318
; Use this range information to grab all the values in a
forrest@0
   319
; particular range, and then take an average.
forrest@0
   320
forrest@0
   321
  nr           = dimsizes(range)
forrest@0
   322
  nx           = nr-1
forrest@0
   323
  xvalues      = new((/2,nx/),float)
forrest@0
   324
  xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2.
forrest@0
   325
  dx           = xvalues(0,1) - xvalues(0,0)       ; range width
forrest@0
   326
  dx4          = dx/4                              ; 1/4 of the range
forrest@0
   327
  xvalues(1,:) = xvalues(0,:) - dx/5.
forrest@0
   328
forrest@0
   329
;==============================
forrest@0
   330
; put data into bins
forrest@0
   331
;==============================
forrest@0
   332
forrest@0
   333
; using observed biome class
forrest@0
   334
; base_1D  = ndtooned(classob)
forrest@0
   335
; using model biome class
forrest@0
   336
  base_1D  = ndtooned(classmod)
forrest@0
   337
forrest@0
   338
  data1_1D = ndtooned(npp_i)
forrest@0
   339
  data2_1D = ndtooned(npp_f)
forrest@0
   340
forrest@0
   341
; output
forrest@0
   342
forrest@0
   343
  yvalues = new((/2,nx/),float)
forrest@0
   344
  count   = new((/2,nx/),float)
forrest@0
   345
forrest@0
   346
  do nd=0,1
forrest@0
   347
forrest@0
   348
;   See if we are doing data1 (nd=0) or data2 (nd=1).
forrest@0
   349
forrest@0
   350
    base = base_1D
forrest@0
   351
forrest@0
   352
    if(nd.eq.0) then
forrest@0
   353
      data = data1_1D
forrest@0
   354
    else
forrest@0
   355
      data = data2_1D
forrest@0
   356
    end if
forrest@0
   357
forrest@0
   358
; Loop through each range, using base.
forrest@0
   359
forrest@0
   360
    do i=0,nr-2
forrest@0
   361
      if (i.ne.(nr-2)) then
forrest@0
   362
;        print("")
forrest@0
   363
;        print("In range ["+range(i)+","+range(i+1)+")")
forrest@0
   364
         idx = ind((base.ge.range(i)).and.(base.lt.range(i+1)))
forrest@0
   365
      else
forrest@0
   366
;        print("")
forrest@0
   367
;        print("In range ["+range(i)+",)")
forrest@0
   368
         idx = ind(base.ge.range(i))
forrest@0
   369
      end if
forrest@0
   370
forrest@0
   371
;     Calculate average 
forrest@0
   372
forrest@0
   373
      if(.not.any(ismissing(idx))) then
forrest@0
   374
        yvalues(nd,i) = avg(data(idx))
forrest@0
   375
        count(nd,i)   = dimsizes(idx)
forrest@0
   376
      else
forrest@0
   377
        yvalues(nd,i) = yvalues@_FillValue
forrest@0
   378
        count(nd,i)   = 0
forrest@0
   379
      end if
forrest@0
   380
forrest@0
   381
;#############################################################
forrest@0
   382
;using observed biome class:
forrest@0
   383
; 
forrest@0
   384
;     set the following 4 classes to _FillValue:
forrest@0
   385
;     Water Bodies(0), Urban and Build-Up(13),
forrest@0
   386
;     Permenant Snow and Ice(15), Unclassified(17)
forrest@0
   387
forrest@0
   388
;     if (i.eq.0 .or. i.eq.13 .or. i.eq.15 .or. i.eq.17) then
forrest@0
   389
;        yvalues(nd,i) = yvalues@_FillValue
forrest@0
   390
;        count(nd,i)   = 0
forrest@0
   391
;     end if
forrest@0
   392
;############################################################# 
forrest@0
   393
forrest@0
   394
;#############################################################
forrest@0
   395
;using model biome class:
forrest@0
   396
;
forrest@0
   397
;     set the following 4 classes to _FillValue:
forrest@0
   398
;     (3)Needleleaf Deciduous Boreal Tree,
forrest@0
   399
;     (8)Broadleaf Deciduous Boreal Tree,
forrest@0
   400
;     (9)Broadleaf Evergreen Shrub,
forrest@0
   401
;     (16)Wheat
forrest@0
   402
forrest@0
   403
      if (i.eq.3 .or. i.eq.8 .or. i.eq.9 .or. i.eq.16) then
forrest@0
   404
         yvalues(nd,i) = yvalues@_FillValue
forrest@0
   405
         count(nd,i)   = 0
forrest@0
   406
      end if
forrest@0
   407
;############################################################# 
forrest@0
   408
forrest@0
   409
;     print(nd + ": " + count(nd,i) + " points, avg = " + yvalues(nd,i))
forrest@0
   410
forrest@0
   411
; Clean up for next time in loop.
forrest@0
   412
forrest@0
   413
      delete(idx)
forrest@0
   414
    end do
forrest@0
   415
forrest@0
   416
    delete(data)
forrest@0
   417
  end do
forrest@0
   418
forrest@0
   419
;============================
forrest@0
   420
;compute beta
forrest@0
   421
;============================
forrest@0
   422
forrest@0
   423
 u       = yvalues(0,:)
forrest@0
   424
 v       = yvalues(1,:)
forrest@0
   425
 u_count = count(0,:)
forrest@0
   426
 v_count = count(1,:)
forrest@0
   427
forrest@0
   428
 good = ind(.not.ismissing(u) .and. .not.ismissing(v))
forrest@0
   429
forrest@0
   430
 uu       = u(good)
forrest@0
   431
 vv       = v(good)
forrest@0
   432
 uu_count = u_count(good)
forrest@0
   433
 vv_count = v_count(good) 
forrest@0
   434
forrest@0
   435
 n_biome = dimsizes(uu)
forrest@0
   436
 beta_biome = new((/n_biome/),float)
forrest@0
   437
forrest@0
   438
 beta_biome = ((vv/uu) - 1.)/log(co2_f/co2_i)
forrest@0
   439
forrest@0
   440
;beta_biome_avg = avg(beta_biome)
forrest@0
   441
 beta_biome_avg = (sum(vv*vv_count)/sum(uu*uu_count) - 1.)/log(co2_f/co2_i)
forrest@0
   442
  
forrest@0
   443
;print (beta_biome_avg)
forrest@0
   444
forrest@0
   445
;===========================
forrest@0
   446
; for html table - biome
forrest@0
   447
;===========================
forrest@0
   448
forrest@0
   449
  output_html = "table_biome.html"
forrest@0
   450
forrest@0
   451
; column (not including header column)
forrest@0
   452
forrest@0
   453
  col_head = (/"CO2_i","CO2_f","NPP_i","NPP_f","Beta_model"/)
forrest@0
   454
forrest@0
   455
  ncol = dimsizes(col_head)
forrest@0
   456
forrest@0
   457
; row (not including header row)
forrest@0
   458
forrest@0
   459
;----------------------------------------------------
forrest@0
   460
; using observed biome class:
forrest@0
   461
;  
forrest@0
   462
; row_head  = (/"Evergreen Needleleaf Forests" \
forrest@0
   463
;              ,"Evergreen Broadleaf Forests" \
forrest@0
   464
;              ,"Deciduous Needleleaf Forest" \
forrest@0
   465
;              ,"Deciduous Broadleaf Forests" \
forrest@0
   466
;              ,"Mixed Forests" \                      
forrest@0
   467
;              ,"Closed Bushlands" \                   
forrest@0
   468
;              ,"Open Bushlands" \                     
forrest@0
   469
;              ,"Woody Savannas (S. Hem.)" \           
forrest@0
   470
;              ,"Savannas (S. Hem.)" \                 
forrest@0
   471
;              ,"Grasslands" \                         
forrest@0
   472
;              ,"Permanent Wetlands" \                 
forrest@0
   473
;              ,"Croplands" \                                           
forrest@0
   474
;              ,"Cropland/Natural Vegetation Mosaic" \             
forrest@0
   475
;              ,"Barren or Sparsely Vegetated" \                             
forrest@0
   476
;              ,"Woody Savannas (N. Hem.)" \           
forrest@0
   477
;              ,"Savannas (N. Hem.)" \
forrest@0
   478
;              ,"All Biome" \                
forrest@0
   479
;              /)
forrest@0
   480
forrest@0
   481
;----------------------------------------------------
forrest@0
   482
; using model biome class:
forrest@0
   483
;  
forrest@0
   484
  row_head  = (/"Not Vegetated" \
forrest@0
   485
               ,"Needleleaf Evergreen Temperate Tree" \
forrest@0
   486
               ,"Needleleaf Evergreen Boreal Tree" \
forrest@0
   487
;              ,"Needleleaf Deciduous Boreal Tree" \
forrest@0
   488
               ,"Broadleaf Evergreen Tropical Tree" \
forrest@0
   489
               ,"Broadleaf Evergreen Temperate Tree" \
forrest@0
   490
               ,"Broadleaf Deciduous Tropical Tree" \
forrest@0
   491
               ,"Broadleaf Deciduous Temperate Tree" \
forrest@0
   492
;              ,"Broadleaf Deciduous Boreal Tree" \
forrest@0
   493
;              ,"Broadleaf Evergreen Shrub" \
forrest@0
   494
               ,"Broadleaf Deciduous Temperate Shrub" \
forrest@0
   495
               ,"Broadleaf Deciduous Boreal Shrub" \
forrest@0
   496
               ,"C3 Arctic Grass" \
forrest@0
   497
               ,"C3 Non-Arctic Grass" \
forrest@0
   498
               ,"C4 Grass" \
forrest@0
   499
               ,"Corn" \
forrest@0
   500
;              ,"Wheat" \                      
forrest@0
   501
               ,"All Biome" \                
forrest@0
   502
               /)  
forrest@0
   503
forrest@0
   504
  nrow = dimsizes(row_head)                  
forrest@0
   505
forrest@0
   506
; arrays to be passed to table. 
forrest@0
   507
  text4 = new ((/nrow, ncol/),string )
forrest@0
   508
 
forrest@0
   509
 do i=0,nrow-2
forrest@0
   510
  text4(i,0) = sprintf("%.1f",co2_i)
forrest@0
   511
  text4(i,1) = sprintf("%.1f",co2_f)
forrest@0
   512
  text4(i,2) = sprintf("%.1f",uu(i))
forrest@0
   513
  text4(i,3) = sprintf("%.1f",vv(i))
forrest@0
   514
  text4(i,4) = sprintf("%.2f",beta_biome(i))
forrest@0
   515
 end do
forrest@0
   516
  text4(nrow-1,0) = "-"
forrest@0
   517
  text4(nrow-1,1) = "-"
forrest@0
   518
  text4(nrow-1,2) = "-"
forrest@0
   519
  text4(nrow-1,3) = "-"
forrest@0
   520
  text4(nrow-1,4) = sprintf("%.2f",beta_biome_avg)
forrest@0
   521
forrest@0
   522
;**************************************************
forrest@0
   523
; html table
forrest@0
   524
;**************************************************
forrest@0
   525
forrest@0
   526
  header_text = "<H1>Beta Factor: Model "+model_name+"</H1>" 
forrest@0
   527
forrest@0
   528
  header = (/"<HTML>" \
forrest@0
   529
            ,"<HEAD>" \
forrest@0
   530
            ,"<TITLE>CLAMP metrics</TITLE>" \
forrest@0
   531
            ,"</HEAD>" \
forrest@0
   532
            ,header_text \
forrest@0
   533
            /) 
forrest@0
   534
  footer = "</HTML>"
forrest@0
   535
forrest@0
   536
  table_header = (/ \
forrest@0
   537
        "<table border=1 cellspacing=0 cellpadding=3 width=80%>" \
forrest@0
   538
       ,"<tr>" \
forrest@0
   539
       ,"   <th bgcolor=DDDDDD >Biome Class</th>" \
forrest@0
   540
       ,"   <th bgcolor=DDDDDD >"+col_head(0)+"</th>" \
forrest@0
   541
       ,"   <th bgcolor=DDDDDD >"+col_head(1)+"</th>" \
forrest@0
   542
       ,"   <th bgcolor=DDDDDD >"+col_head(2)+"</th>" \
forrest@0
   543
       ,"   <th bgcolor=DDDDDD >"+col_head(3)+"</th>" \
forrest@0
   544
       ,"   <th bgcolor=DDDDDD >"+col_head(4)+"</th>" \
forrest@0
   545
       ,"</tr>" \
forrest@0
   546
       /)
forrest@0
   547
  table_footer = "</table>"
forrest@0
   548
  row_header = "<tr>"
forrest@0
   549
  row_footer = "</tr>"
forrest@0
   550
forrest@0
   551
  lines = new(50000,string)
forrest@0
   552
  nline = 0
forrest@0
   553
forrest@0
   554
  set_line(lines,nline,header)
forrest@0
   555
  set_line(lines,nline,table_header)
forrest@0
   556
;-----------------------------------------------
forrest@0
   557
;row of table
forrest@0
   558
forrest@0
   559
  do n = 0,nrow-1
forrest@0
   560
     set_line(lines,nline,row_header)
forrest@0
   561
forrest@0
   562
     txt1  = row_head(n)
forrest@0
   563
     txt2  = text4(n,0)
forrest@0
   564
     txt3  = text4(n,1)
forrest@0
   565
     txt4  = text4(n,2)
forrest@0
   566
     txt5  = text4(n,3)
forrest@0
   567
     txt6  = text4(n,4)
forrest@0
   568
forrest@0
   569
     set_line(lines,nline,"<th>"+txt1+"</th>")
forrest@0
   570
     set_line(lines,nline,"<th>"+txt2+"</th>")
forrest@0
   571
     set_line(lines,nline,"<th>"+txt3+"</th>")
forrest@0
   572
     set_line(lines,nline,"<th>"+txt4+"</th>")
forrest@0
   573
     set_line(lines,nline,"<th>"+txt5+"</th>")
forrest@0
   574
     set_line(lines,nline,"<th>"+txt6+"</th>")
forrest@0
   575
forrest@0
   576
     set_line(lines,nline,row_footer)
forrest@0
   577
  end do
forrest@0
   578
;-----------------------------------------------
forrest@0
   579
  set_line(lines,nline,table_footer)
forrest@0
   580
  set_line(lines,nline,footer) 
forrest@0
   581
forrest@0
   582
; Now write to an HTML file.
forrest@0
   583
  idx = ind(.not.ismissing(lines))
forrest@0
   584
  if(.not.any(ismissing(idx))) then
forrest@0
   585
    asciiwrite(output_html,lines(idx))
forrest@0
   586
  else
forrest@0
   587
   print ("error?")
forrest@0
   588
  end if
forrest@0
   589
forrest@0
   590
end
forrest@0
   591