ameriflux/23.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
; move data
forrest@0
     3
; merge annual
forrest@0
     4
; add table
forrest@0
     5
; add time series plot
forrest@0
     6
; sort by latitude in decending order (N->S)
forrest@0
     7
; find year_ob >= 4
forrest@0
     8
; add year_ob_i and year_ob_f
forrest@0
     9
; change long_name
forrest@0
    10
;************************************************************
forrest@0
    11
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
forrest@0
    12
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
forrest@0
    13
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
forrest@0
    14
;************************************************************
forrest@0
    15
procedure set_line(lines:string,nline:integer,newlines:string) 
forrest@0
    16
begin
forrest@0
    17
; add line to ascci/html file
forrest@0
    18
    
forrest@0
    19
  nnewlines = dimsizes(newlines)
forrest@0
    20
  if(nline+nnewlines-1.ge.dimsizes(lines))
forrest@0
    21
    print("set_line: bad index, not setting anything.") 
forrest@0
    22
    return
forrest@0
    23
  end if 
forrest@0
    24
  lines(nline:nline+nnewlines-1) = newlines
forrest@0
    25
;  print ("lines = " + lines(nline:nline+nnewlines-1))
forrest@0
    26
  nline = nline + nnewlines
forrest@0
    27
  return 
forrest@0
    28
end
forrest@0
    29
;*************************************************************
forrest@0
    30
begin
forrest@0
    31
forrest@0
    32
  plot_type     = "ps"
forrest@0
    33
  plot_type_new = "png"
forrest@0
    34
forrest@0
    35
;************************************************
forrest@0
    36
; model data info
forrest@0
    37
;************************************************
forrest@0
    38
  model = "cn"
forrest@0
    39
; model = "casa"
forrest@0
    40
  
forrest@0
    41
  model_name = "i01.10" + model
forrest@0
    42
  
forrest@0
    43
  ENERGY ="new"
forrest@0
    44
forrest@0
    45
  nmonth = 12
forrest@0
    46
forrest@0
    47
;************************************************
forrest@0
    48
; observed data info
forrest@0
    49
;************************************************
forrest@0
    50
forrest@0
    51
 station = (/"ARM_Oklahoma" \
forrest@0
    52
            ,"ARM_Oklahoma_burn" \
forrest@0
    53
            ,"ARM_Oklahoma_control" \
forrest@0
    54
            ,"Atqasuk" \
forrest@0
    55
            ,"Audubon" \
forrest@0
    56
            ,"AustinCary" \
forrest@0
    57
            ,"Bartlett" \
forrest@0
    58
            ,"Bondville" \
forrest@0
    59
            ,"Brookings" \
forrest@0
    60
            ,"Donaldson" \
forrest@0
    61
            ,"Duke_Forest_Hardwoods" \
forrest@0
    62
            ,"Duke_Forest_Open_Field" \
forrest@0
    63
            ,"Duke_Forest_Pine" \
forrest@0
    64
            ,"Fermi_Ag" \
forrest@0
    65
            ,"Fermi_Prairie" \
forrest@0
    66
            ,"Flagstaff_Managed" \
forrest@0
    67
            ,"Flagstaff_Unmanaged" \
forrest@0
    68
            ,"Flagstaff_Wildfire" \
forrest@0
    69
            ,"FortPeck" \
forrest@0
    70
            ,"FreemanRanch_mesquite" \
forrest@0
    71
            ,"Goodwin_Creek" \
forrest@0
    72
            ,"HarvardForest" \
forrest@0
    73
            ,"HarvardForestHemlock" \
forrest@0
    74
            ,"HowlandForestMain" \
forrest@0
    75
            ,"HowlandForestWest" \
forrest@0
    76
            ,"Ivotuk" \
forrest@0
    77
            ,"KendallGrasslands" \
forrest@0
    78
            ,"KennedySpaceCenterPine" \
forrest@0
    79
            ,"KennedySpaceCenterScrub" \
forrest@0
    80
            ,"LittleProspect" \
forrest@0
    81
            ,"LostCreek" \
forrest@0
    82
            ,"Mead-irrigated" \
forrest@0
    83
            ,"Mead-irrigated-rotation" \
forrest@0
    84
            ,"Mead-rainfed" \
forrest@0
    85
            ,"Metolius_2nd_YoungPonderosaPine" \
forrest@0
    86
            ,"MetoliusEyerly" \
forrest@0
    87
            ,"MetoliusIntermediatePine" \
forrest@0
    88
            ,"MetoliusOldPonderosaPine" \
forrest@0
    89
            ,"MissouriOzark" \
forrest@0
    90
            ,"Mize" \
forrest@0
    91
            ,"MorganMonroe" \
forrest@0
    92
            ,"NiwotRidge" \
forrest@0
    93
            ,"NorthCarolina_cc" \
forrest@0
    94
            ,"NorthCarolina_lp" \
forrest@0
    95
            ,"ParkFalls" \
forrest@0
    96
            ,"Rayonier" \
forrest@0
    97
            ,"SantaRita" \
forrest@0
    98
            ,"SkyOaks_Old" \
forrest@0
    99
            ,"SkyOaks_PostFire" \
forrest@0
   100
            ,"SkyOaks_Young" \
forrest@0
   101
            ,"SylvaniaWilderness" \
forrest@0
   102
            ,"Toledo" \
forrest@0
   103
            ,"Tonzi" \
forrest@0
   104
            ,"UCI_1850" \
forrest@0
   105
            ,"UCI_1930" \
forrest@0
   106
            ,"UCI_1964" \
forrest@0
   107
            ,"UCI_1964wet" \
forrest@0
   108
            ,"UCI_1981" \
forrest@0
   109
            ,"UCI_1989" \
forrest@0
   110
            ,"UCI_1998" \
forrest@0
   111
            ,"UMBS" \
forrest@0
   112
            ,"Vaira" \
forrest@0
   113
            ,"WalkerBranch" \
forrest@0
   114
            ,"WillowCreek" \
forrest@0
   115
            ,"WindRiver" \
forrest@0
   116
            ,"Wisconsin_ihw" \
forrest@0
   117
            ,"Wisconsin_irp" \
forrest@0
   118
            ,"Wisconsin_mrp" \
forrest@0
   119
            ,"Wisconsin_myjp" \
forrest@0
   120
            ,"Wisconsin_pb" \
forrest@0
   121
            ,"Wisconsin_rpcc" \
forrest@0
   122
            ,"Wisconsin_yhw" \
forrest@0
   123
            ,"Wisconsin_yjp" \
forrest@0
   124
            ,"Wisconsin_yrp" \
forrest@0
   125
            /)
forrest@0
   126
forrest@0
   127
 year_ob = (/"2003-2006" \
forrest@0
   128
            ,"2005-2006" \
forrest@0
   129
            ,"2005-2006" \
forrest@0
   130
            ,"1999-2006" \
forrest@0
   131
            ,"2002-2006" \
forrest@0
   132
            ,"2000-2005" \
forrest@0
   133
            ,"2004-2005" \
forrest@0
   134
            ,"1996-2006" \
forrest@0
   135
            ,"2004-2006" \
forrest@0
   136
            ,"1999-2004" \
forrest@0
   137
            ,"2003-2005" \
forrest@0
   138
            ,"2001-2005" \
forrest@0
   139
            ,"2001-2005" \
forrest@0
   140
            ,"2005-2006" \
forrest@0
   141
            ,"2004-2006" \
forrest@0
   142
            ,"2005-2006" \
forrest@0
   143
            ,"2005-2006" \
forrest@0
   144
            ,"2005-2006" \
forrest@0
   145
            ,"2000-2006" \
forrest@0
   146
            ,"2004-2006" \
forrest@0
   147
            ,"2002-2006" \
forrest@0
   148
            ,"1991-2004" \
forrest@0
   149
            ,"2004-2004" \
forrest@0
   150
            ,"1996-2004" \
forrest@0
   151
            ,"1999-2004" \
forrest@0
   152
            ,"2003-2006" \
forrest@0
   153
            ,"2004-2006" \
forrest@0
   154
            ,"2002-2002" \
forrest@0
   155
            ,"2000-2006" \
forrest@0
   156
            ,"2002-2005" \
forrest@0
   157
            ,"2001-2005" \
forrest@0
   158
            ,"2001-2005" \
forrest@0
   159
            ,"2001-2005" \
forrest@0
   160
            ,"2001-2005" \
forrest@0
   161
            ,"2004-2005" \
forrest@0
   162
            ,"2004-2005" \
forrest@0
   163
            ,"2003-2005" \
forrest@0
   164
            ,"1996-2000" \
forrest@0
   165
            ,"2004-2006" \
forrest@0
   166
            ,"1998-2004" \
forrest@0
   167
            ,"1999-2005" \
forrest@0
   168
            ,"1999-2003" \
forrest@0
   169
            ,"2005-2006" \
forrest@0
   170
            ,"2005-2006" \
forrest@0
   171
            ,"1996-2003" \
forrest@0
   172
            ,"1998-1998" \
forrest@0
   173
            ,"2004-2006" \
forrest@0
   174
            ,"1997-2006" \
forrest@0
   175
            ,"2004-2006" \
forrest@0
   176
            ,"1997-2006" \
forrest@0
   177
            ,"2002-2006" \
forrest@0
   178
            ,"2004-2005" \
forrest@0
   179
            ,"2001-2006" \
forrest@0
   180
            ,"2004-2005" \
forrest@0
   181
            ,"2001-2005" \
forrest@0
   182
            ,"2001-2005" \
forrest@0
   183
            ,"2002-2004" \
forrest@0
   184
            ,"2001-2005" \
forrest@0
   185
            ,"2001-2005" \
forrest@0
   186
            ,"2002-2005" \
forrest@0
   187
            ,"1999-2003" \
forrest@0
   188
            ,"2001-2006" \
forrest@0
   189
            ,"1995-1999" \
forrest@0
   190
            ,"1999-2005" \
forrest@0
   191
            ,"1999-2004" \
forrest@0
   192
            ,"2003-2003" \
forrest@0
   193
            ,"2003-2003" \
forrest@0
   194
            ,"2002-2005" \
forrest@0
   195
            ,"2004-2004" \
forrest@0
   196
            ,"2002-2002" \
forrest@0
   197
            ,"2005-2005" \
forrest@0
   198
            ,"2002-2002" \
forrest@0
   199
            ,"2004-2005" \
forrest@0
   200
            ,"2002-2002" \
forrest@0
   201
            /)
forrest@0
   202
forrest@0
   203
 field   = (/"NEE Flux" \
forrest@0
   204
            ,"Net Radiation" \
forrest@0
   205
            ,"Latent Heat" \
forrest@0
   206
            ,"Sensible Heat" \
forrest@0
   207
            ,"GPP Flux" \
forrest@0
   208
            ,"Respiration" \
forrest@0
   209
            /)
forrest@0
   210
forrest@0
   211
 field_unit = (/"u mol/m2/s" \
forrest@0
   212
               ,"W/m2" \
forrest@0
   213
               ,"W/m2" \
forrest@0
   214
               ,"W/m2" \
forrest@0
   215
               ,"u mol/m2/s" \
forrest@0
   216
               ,"u mol/m2/s" \
forrest@0
   217
               /)
forrest@0
   218
forrest@0
   219
 nstation = dimsizes(station)
forrest@0
   220
 nfield   = dimsizes(field)
forrest@0
   221
forrest@0
   222
;========================================================================
forrest@0
   223
; get observed info: number of year, first/last year, lat, lon
forrest@0
   224
; and annual data
forrest@0
   225
forrest@0
   226
 dir_root = "/fis/cgd/cseg/people/jeff/clamp_data/observed/ameriflux/"
forrest@0
   227
forrest@0
   228
 year_station = new ((/nstation/),integer) ; number of year
forrest@0
   229
 year_ob_i    = new ((/nstation/),integer) ; first year
forrest@0
   230
 year_ob_f    = new ((/nstation/),integer) ; last year
forrest@0
   231
 lat_ob       = new ((/nstation/),float)   ; latitude
forrest@0
   232
 lon_ob       = new ((/nstation/),float)   ; longitude 
forrest@0
   233
forrest@0
   234
 data_ob_ann  = new ((/nfield, nmonth, nstation/),float)
forrest@0
   235
forrest@0
   236
 do n = 0, nstation-1
forrest@0
   237
forrest@0
   238
    diro = dir_root + station(n)+"/"
forrest@0
   239
    filo = year_ob(n)+"_L4_m.nc"
forrest@0
   240
    fo   = addfile (diro+filo,"r")
forrest@0
   241
 
forrest@0
   242
    lat_ob(n) = fo->lat
forrest@0
   243
    lon_ob(n) = fo->lon
forrest@0
   244
forrest@0
   245
    year      = fo->year
forrest@0
   246
forrest@0
   247
    year_station(n) = dimsizes(year)
forrest@0
   248
    year_ob_i(n)    = year(0)
forrest@0
   249
    year_ob_f(n)    = year(year_station(n)-1)
forrest@0
   250
 
forrest@0
   251
    delete (year)
forrest@0
   252
 
forrest@0
   253
    data = fo->NEE_or_fMDS
forrest@0
   254
    data_ob_ann(0,:,n) = dim_avg(data(month|:,year|:))
forrest@0
   255
forrest@0
   256
    data = fo->Rg_f
forrest@0
   257
    data_ob_ann(1,:,n) = dim_avg(data(month|:,year|:))
forrest@0
   258
forrest@0
   259
    data = fo->LE_f
forrest@0
   260
    data_ob_ann(2,:,n) = dim_avg(data(month|:,year|:))
forrest@0
   261
forrest@0
   262
    data = fo->H_f
forrest@0
   263
    data_ob_ann(3,:,n) = dim_avg(data(month|:,year|:))
forrest@0
   264
forrest@0
   265
    data = fo->GPP_or_MDS
forrest@0
   266
    data_ob_ann(4,:,n) = dim_avg(data(month|:,year|:))
forrest@0
   267
forrest@0
   268
    data = fo->Reco_or
forrest@0
   269
    data_ob_ann(5,:,n) = dim_avg(data(month|:,year|:))
forrest@0
   270
forrest@0
   271
    delete (data) 
forrest@0
   272
    delete (fo)   
forrest@0
   273
 end do
forrest@0
   274
forrest@0
   275
;print (year_ob_i)
forrest@0
   276
;print (year_ob_f)
forrest@0
   277
forrest@0
   278
;--------------------------------------------------------------
forrest@0
   279
; find (# of year observed) >=4 and year_ob_i <= 2001
forrest@0
   280
forrest@0
   281
 i_long_ob = ind(year_station .ge. 4 .and. year_ob_i .le. 2001)
forrest@0
   282
 
forrest@0
   283
 station_long      = station(i_long_ob)
forrest@0
   284
 lat_ob_long       = lat_ob(i_long_ob)
forrest@0
   285
 lon_ob_long       = lat_ob(i_long_ob)
forrest@0
   286
 year_ob_long      = year_ob(i_long_ob)
forrest@0
   287
 year_ob_i_long    = year_ob_i(i_long_ob)
forrest@0
   288
 year_ob_f_long    = year_ob_f(i_long_ob)
forrest@0
   289
 year_station_long = year_station(i_long_ob)
forrest@0
   290
forrest@0
   291
 nstation_long     = dimsizes(station_long)
forrest@0
   292
forrest@0
   293
; print (i_long_ob)
forrest@0
   294
; print (nstation_long)
forrest@0
   295
; print (station_long)
forrest@0
   296
; print (year_ob_i(i_long_ob))
forrest@0
   297
forrest@0
   298
;=========================================================
forrest@0
   299
;   get model data at observed lat-lon
forrest@0
   300
forrest@0
   301
    dirm = "/fis/cgd/cseg/people/jeff/clamp_data/model/"    
forrest@0
   302
    film = model_name+"_ameriflux_1990-2004_monthly.nc"
forrest@0
   303
    fm   = addfile (dirm+film,"r")
forrest@0
   304
forrest@0
   305
    xm   = fm->lon
forrest@0
   306
    ym   = fm->lat 
forrest@0
   307
    date = fm->date
forrest@0
   308
forrest@0
   309
    date_dim = dimsizes(date)
forrest@0
   310
    nyear  = date_dim(0)
forrest@0
   311
forrest@0
   312
    data_mod      = new ((/nfield,nyear,nmonth,nstation/),float)
forrest@0
   313
    data_mod_ann  = new ((/nfield,nmonth,nstation/),float)
forrest@0
   314
    data_mod_long = new ((/nfield,nyear,nmonth,nstation_long/),float)
forrest@0
   315
forrest@0
   316
;   change to unit of observed (u mol/m2/s)
forrest@0
   317
;   Model_units [=] gC/m2/s
forrest@0
   318
;   12. = molecular weight of C
forrest@0
   319
;   u mol = 1e-6 mol
forrest@0
   320
forrest@0
   321
    factor = 1.e6 /12.
forrest@0
   322
forrest@0
   323
;------------------------------------------------------------
forrest@0
   324
;   interpolate model data into observed station
forrest@0
   325
;   note: model is 0-360E, 90S-90N
forrest@0
   326
forrest@0
   327
;   to be able to handle observation at (-89.98,-24.80)
forrest@0
   328
    ym(0) = -90.
forrest@0
   329
;------------------------------------------------------------  
forrest@0
   330
forrest@0
   331
if (ENERGY .eq. "old") then
forrest@0
   332
forrest@0
   333
  data = fm->NEE
forrest@0
   334
  data_mod(0,:,:,:) = data(:,:,:) * factor
forrest@0
   335
forrest@0
   336
; data  = fm->LATENT
forrest@0
   337
  data1 = fm->FCEV
forrest@0
   338
  data2 = fm->FCTR
forrest@0
   339
  data3 = fm->FGEV
forrest@0
   340
  data_mod(2,:,:,:) = data1(:,:,:)+data2(:,:,:)+data3(:,:,:) 
forrest@0
   341
  delete (data1)
forrest@0
   342
  delete (data2)
forrest@0
   343
  delete (data3)
forrest@0
   344
forrest@0
   345
; data = fm->SENSIBLE
forrest@0
   346
  data  = fm->FSH
forrest@0
   347
  data_mod(3,:,:,:) = data(:,:,:) 
forrest@0
   348
forrest@0
   349
; data  = fm->NETRAD
forrest@0
   350
  data1 = fm->FSA
forrest@0
   351
  data2 = fm->FIRA
forrest@0
   352
  data_mod(1,:,:,:) = data1(:,:,:)-data2(:,:,:) 
forrest@0
   353
  delete (data1)
forrest@0
   354
  delete (data2)
forrest@0
   355
forrest@0
   356
else
forrest@0
   357
forrest@0
   358
  data = fm->NEE
forrest@0
   359
  yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0)
forrest@0
   360
  data_mod_ann(0,:,:)= dim_avg(yy(month|:,pts|:,year|:)) * factor
forrest@0
   361
  data_mod(0,:,:,:) = yy(:,:,:) * factor
forrest@0
   362
forrest@0
   363
; printVarSummary(yy)
forrest@0
   364
forrest@0
   365
  data = fm->NETRAD
forrest@0
   366
  yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0)
forrest@0
   367
  data_mod_ann(1,:,:)= dim_avg(yy(month|:,pts|:,year|:)) 
forrest@0
   368
  data_mod(1,:,:,:) = yy(:,:,:) 
forrest@0
   369
forrest@0
   370
  data = fm->LATENT
forrest@0
   371
  yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0)
forrest@0
   372
  data_mod_ann(2,:,:)= dim_avg(yy(month|:,pts|:,year|:)) 
forrest@0
   373
  data_mod(2,:,:,:) = yy(:,:,:) 
forrest@0
   374
forrest@0
   375
; data = fm->SENSIBLE
forrest@0
   376
  data = fm->FSH
forrest@0
   377
  yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0)
forrest@0
   378
  data_mod_ann(3,:,:)= dim_avg(yy(month|:,pts|:,year|:)) 
forrest@0
   379
  data_mod(3,:,:,:) = yy(:,:,:) 
forrest@0
   380
forrest@0
   381
end if
forrest@0
   382
forrest@0
   383
  data = fm->GPP
forrest@0
   384
  yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0)
forrest@0
   385
  data_mod_ann(4,:,:)= dim_avg(yy(month|:,pts|:,year|:)) * factor
forrest@0
   386
  data_mod(4,:,:,:) = yy(:,:,:) * factor 
forrest@0
   387
forrest@0
   388
  if (model .eq. "cn") then
forrest@0
   389
     data = fm->ER
forrest@0
   390
  else
forrest@0
   391
     data1 = fm->AR
forrest@0
   392
     data2 = fm->HR
forrest@0
   393
     data  = data1 + data2
forrest@0
   394
    
forrest@0
   395
     delete (data1)
forrest@0
   396
     delete (data2)
forrest@0
   397
  end if
forrest@0
   398
forrest@0
   399
  yy = linint2_points_Wrap(xm,ym,data,True,lon_ob,lat_ob,0)
forrest@0
   400
  data_mod_ann(5,:,:)= dim_avg(yy(month|:,pts|:,year|:)) * factor
forrest@0
   401
  data_mod(5,:,:,:) = yy(:,:,:) * factor
forrest@0
   402
forrest@0
   403
  data_mod_long(:,:,:,:) = data_mod(:,:,:,i_long_ob)
forrest@0
   404
forrest@0
   405
  delete (data_mod)
forrest@0
   406
  delete (fm) 
forrest@0
   407
  delete (data)
forrest@0
   408
  delete (yy)
forrest@0
   409
forrest@0
   410
;*******************************************************************
forrest@0
   411
; for station line plot
forrest@0
   412
;*******************************************************************
forrest@0
   413
forrest@0
   414
; for x-axis in xyplot
forrest@0
   415
  mon = ispan(1,12,1)
forrest@0
   416
  mon@long_name = "month"
forrest@0
   417
forrest@0
   418
  res                   = True               ; plot mods desired
forrest@0
   419
  res@xyLineThicknesses = (/2.0,2.0/)        ; make 2nd lines thicker
forrest@0
   420
  res@xyLineColors      = (/"blue","red"/)   ; line color (ob,model)
forrest@0
   421
forrest@0
   422
  res@tmXBFormat  = "f"                      ; not to add trailing zeros
forrest@0
   423
forrest@0
   424
;-------------------------------------------------------------------------
forrest@0
   425
; Add a boxed legend using the more simple method
forrest@0
   426
forrest@0
   427
  res@pmLegendDisplayMode    = "Always"
forrest@0
   428
; res@pmLegendWidthF         = 0.1
forrest@0
   429
  res@pmLegendWidthF         = 0.08
forrest@0
   430
  res@pmLegendHeightF        = 0.06
forrest@0
   431
; res@pmLegendOrthogonalPosF = -1.17
forrest@0
   432
; res@pmLegendOrthogonalPosF = -1.00  ;(downward)
forrest@0
   433
  res@pmLegendOrthogonalPosF = -0.30  ;(downward)
forrest@0
   434
forrest@0
   435
; res@pmLegendParallelPosF   =  0.18
forrest@0
   436
  res@pmLegendParallelPosF   =  0.23  ;(rightward)
forrest@0
   437
forrest@0
   438
; res@lgPerimOn             = False
forrest@0
   439
  res@lgLabelFontHeightF     = 0.015
forrest@0
   440
  res@xyExplicitLegendLabels = (/"observed",model_name/)
forrest@0
   441
;-------------------------------------------------------------------
forrest@0
   442
; for panel plot
forrest@0
   443
  res@gsnFrame     = False                   ; Do not draw plot 
forrest@0
   444
  res@gsnDraw      = False                   ; Do not advance frame
forrest@0
   445
forrest@0
   446
  pres                            = True     ; panel plot mods desired
forrest@0
   447
  pres@gsnPanelYWhiteSpacePercent = 5        ; increase white space around
forrest@0
   448
                                             ; indiv. plots in panel
forrest@0
   449
  pres@gsnMaximize                = True     ; fill the page
forrest@0
   450
;-------------------------------------------------------------------
forrest@0
   451
forrest@0
   452
;==============================================================
forrest@0
   453
; get ob data at each site with long observation
forrest@0
   454
forrest@0
   455
  dir_root = "/fis/cgd/cseg/people/jeff/clamp/ameriflux/data/"
forrest@0
   456
forrest@0
   457
  do n = 0,nstation_long-1
forrest@0
   458
; do n = 0,0
forrest@0
   459
forrest@0
   460
    year_setback = 0
forrest@0
   461
forrest@0
   462
    nyear = year_station_long(n)
forrest@0
   463
forrest@0
   464
    if (year_ob_f_long(n).eq. 2006) then
forrest@0
   465
       year_setback = 2006 -2004
forrest@0
   466
    end if
forrest@0
   467
    if (year_ob_f_long(n).eq. 2005) then
forrest@0
   468
       year_setback = 2005 -2004
forrest@0
   469
    end if
forrest@0
   470
    
forrest@0
   471
    ntime = (nyear - year_setback) * nmonth
forrest@0
   472
forrest@0
   473
    data_ob   = new ((/nfield, nyear, nmonth/),float)
forrest@0
   474
forrest@0
   475
    diro = dir_root + station_long(n)+"/"
forrest@0
   476
    filo = year_ob_long(n)+"_L4_m.nc"
forrest@0
   477
    fo   = addfile (diro+filo,"r")
forrest@0
   478
forrest@0
   479
;   print (diro)
forrest@0
   480
;   print (filo)
forrest@0
   481
forrest@0
   482
    data_ob(0,:,:) = fo->NEE_or_fMDS
forrest@0
   483
    data_ob(1,:,:) = fo->Rg_f
forrest@0
   484
    data_ob(2,:,:) = fo->LE_f
forrest@0
   485
    data_ob(3,:,:) = fo->H_f
forrest@0
   486
    data_ob(4,:,:) = fo->GPP_or_MDS
forrest@0
   487
    data_ob(5,:,:) = fo->Reco_or
forrest@0
   488
forrest@0
   489
    delete (fo)
forrest@0
   490
forrest@0
   491
    timeI = new((/ntime/),integer)
forrest@0
   492
    timeF = new((/ntime/),float)
forrest@0
   493
    timeI = ispan(1,ntime,1)
forrest@0
   494
    timeF = year_ob_i_long(n) + (timeI-1)/12.
forrest@0
   495
    timeF@long_name = "year" 
forrest@0
   496
forrest@0
   497
    plot_data = new((/2,ntime/),float)
forrest@0
   498
 
forrest@0
   499
;----------------------------
forrest@0
   500
; for model_vs_ob
forrest@0
   501
forrest@0
   502
    plot_name = station_long(n)+"_tseries_vs_ob"
forrest@0
   503
    title = station_long(n)+"("+sprintf("%5.2f",lat_ob_long(n))+","+sprintf("%5.2f",lon_ob_long(n))+")"    
forrest@0
   504
    res@tiMainString = title
forrest@0
   505
forrest@0
   506
    wks = gsn_open_wks (plot_type,plot_name)
forrest@0
   507
    plot=new(nfield,graphic)                         ; create graphic array   
forrest@0
   508
forrest@0
   509
    i_year_mod_i = year_ob_i_long(n) - 1990 
forrest@0
   510
    i_year_mod_f = i_year_mod_i + nyear - 1 - year_setback
forrest@0
   511
forrest@0
   512
    i_year_ob_f =  nyear - year_setback - 1 
forrest@0
   513
forrest@0
   514
;   print (nyear)
forrest@0
   515
;   print (i_year_ob_f)
forrest@0
   516
;   print (i_year_mod_i)
forrest@0
   517
;   print (i_year_mod_f)
forrest@0
   518
forrest@0
   519
    do i = 0,nfield-1                           
forrest@0
   520
       plot_data(0,:) = ndtooned(data_ob (i,0:i_year_ob_f,:))
forrest@0
   521
       plot_data(1,:) = ndtooned(data_mod_long(i,i_year_mod_i:i_year_mod_f,:,n))
forrest@0
   522
       plot_data@long_name = field(i)+" ("+field_unit(i)+")"   
forrest@0
   523
       plot(i)=gsn_csm_xy(wks,timeF,plot_data,res)            ; create plot 
forrest@0
   524
    end do
forrest@0
   525
   
forrest@0
   526
    gsn_panel(wks,plot,(/3,2/),pres)                    ; create panel plot
forrest@0
   527
forrest@0
   528
    system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
forrest@0
   529
           "rm "+plot_name+"."+plot_type)
forrest@0
   530
forrest@0
   531
    clear (wks)  
forrest@0
   532
    delete (plot)
forrest@0
   533
forrest@0
   534
    delete (data_ob)
forrest@0
   535
    delete (timeI)    
forrest@0
   536
    delete (timeF)
forrest@0
   537
    delete (plot_data)
forrest@0
   538
forrest@0
   539
 end do
forrest@0
   540
forrest@0
   541
;###################################################################
forrest@0
   542
; for the following tables,
forrest@0
   543
; sort by latitude in decending order (N->S)
forrest@0
   544
forrest@0
   545
  isort = dim_pqsort(lat_ob_long,-1)
forrest@0
   546
forrest@0
   547
  station_sort = station_long(isort)
forrest@0
   548
  year_ob_sort = year_ob_long(isort)
forrest@0
   549
  lat_ob_sort  = lat_ob_long(isort)
forrest@0
   550
  lon_ob_sort  = lon_ob_long(isort)
forrest@0
   551
 
forrest@0
   552
; print(isort)
forrest@0
   553
; print(lat_ob_sort)
forrest@0
   554
forrest@0
   555
;*******************************************************************
forrest@0
   556
; html table of site: observed
forrest@0
   557
;*******************************************************************
forrest@0
   558
  output_html = "tseries_vs_ob.html"
forrest@0
   559
forrest@0
   560
  header = (/"<HTML>" \
forrest@0
   561
            ,"<HEAD>" \
forrest@0
   562
            ,"<TITLE>CLAMP metrics</TITLE>" \
forrest@0
   563
            ,"</HEAD>" \
forrest@0
   564
            ,"<H1>Timeseries at Site: "+model_name+" vs Observation</H1>" \
forrest@0
   565
            /) 
forrest@0
   566
  footer = "</HTML>"
forrest@0
   567
forrest@0
   568
  table_header = (/ \
forrest@0
   569
        "<table border=1 cellspacing=0 cellpadding=3 width=60%>" \
forrest@0
   570
       ,"<tr>" \
forrest@0
   571
       ,"   <th bgcolor=DDDDDD >Site Name</th>" \
forrest@0
   572
       ,"   <th bgcolor=DDDDDD >Latitude</th>" \
forrest@0
   573
       ,"   <th bgcolor=DDDDDD >Longitude</th>" \
forrest@0
   574
       ,"   <th bgcolor=DDDDDD >Observed</th>" \ 
forrest@0
   575
       ,"</tr>" \
forrest@0
   576
       /)
forrest@0
   577
  table_footer = "</table>"
forrest@0
   578
  row_header = "<tr>"
forrest@0
   579
  row_footer = "</tr>"
forrest@0
   580
forrest@0
   581
  lines = new(50000,string)
forrest@0
   582
  nline = 0
forrest@0
   583
forrest@0
   584
  set_line(lines,nline,header)
forrest@0
   585
  set_line(lines,nline,table_header)
forrest@0
   586
;-----------------------------------------------
forrest@0
   587
; row of table
forrest@0
   588
  
forrest@0
   589
  do n = 0,nstation_long-1
forrest@0
   590
forrest@0
   591
     set_line(lines,nline,row_header)
forrest@0
   592
forrest@0
   593
     txt0 = station_sort(n)
forrest@0
   594
     txt1 = sprintf("%5.2f", lat_ob_sort(n))
forrest@0
   595
     txt2 = sprintf("%5.2f", lon_ob_sort(n))
forrest@0
   596
     txt3 = year_ob_sort(n)
forrest@0
   597
forrest@0
   598
     set_line(lines,nline,"<th><a href="+txt0+"_tseries_vs_ob.png>"+txt0+"</a></th>")
forrest@0
   599
     set_line(lines,nline,"<th>"+txt1+"</th>")
forrest@0
   600
     set_line(lines,nline,"<th>"+txt2+"</th>")
forrest@0
   601
     set_line(lines,nline,"<th>"+txt3+"</th>")
forrest@0
   602
forrest@0
   603
     set_line(lines,nline,row_footer)
forrest@0
   604
  end do
forrest@0
   605
;-----------------------------------------------
forrest@0
   606
  set_line(lines,nline,table_footer)
forrest@0
   607
  set_line(lines,nline,footer) 
forrest@0
   608
forrest@0
   609
; Now write to an HTML file.
forrest@0
   610
  idx = ind(.not.ismissing(lines))
forrest@0
   611
  if(.not.any(ismissing(idx))) then
forrest@0
   612
    asciiwrite(output_html,lines(idx))
forrest@0
   613
  else
forrest@0
   614
   print ("error?")
forrest@0
   615
  end if
forrest@0
   616
  delete (idx)
forrest@0
   617
forrest@0
   618
  delete (isort)
forrest@0
   619
  delete (station_sort)
forrest@0
   620
  delete (year_ob_sort)
forrest@0
   621
  delete (lat_ob_sort)
forrest@0
   622
  delete (lon_ob_sort)
forrest@0
   623
forrest@0
   624
;************************************************************
forrest@0
   625
; compute annual cycle correlation coef and M score
forrest@0
   626
;************************************************************
forrest@0
   627
forrest@0
   628
 score_max = 5.
forrest@0
   629
forrest@0
   630
 ccr     = new ((/nstation, nfield/),float)
forrest@0
   631
 M_score = new ((/nstation, nfield/),float) 
forrest@0
   632
forrest@0
   633
 do n=0,nstation-1
forrest@0
   634
 do m=0,nfield-1   
forrest@0
   635
    ccr(n,m) = esccr(data_ob_ann(m,:,n),data_mod_ann(m,:,n),0)
forrest@0
   636
    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))))
forrest@0
   637
    M_score(n,m) = (1. -(bias/nmonth)) * score_max
forrest@0
   638
 end do
forrest@0
   639
 end do
forrest@0
   640
forrest@0
   641
 M_co2 = avg(M_score(:,0))
forrest@0
   642
 M_rad = avg(M_score(:,1))
forrest@0
   643
 M_lh  = avg(M_score(:,2))
forrest@0
   644
 M_sh  = avg(M_score(:,3))
forrest@0
   645
 M_gpp = avg(M_score(:,4))
forrest@0
   646
 M_er  = avg(M_score(:,5))
forrest@0
   647
 M_all = M_co2+ M_rad +M_lh + M_sh + M_gpp + M_er
forrest@0
   648
forrest@0
   649
 M_energy_co2 = sprintf("%.2f", M_co2)
forrest@0
   650
 M_energy_rad = sprintf("%.2f", M_rad)
forrest@0
   651
 M_energy_lh  = sprintf("%.2f", M_lh )
forrest@0
   652
 M_energy_sh  = sprintf("%.2f", M_sh )
forrest@0
   653
 M_energy_gpp = sprintf("%.2f", M_gpp)
forrest@0
   654
 M_energy_er  = sprintf("%.2f", M_er )
forrest@0
   655
 M_energy_all = sprintf("%.2f", M_all)
forrest@0
   656
forrest@0
   657
;*******************************************************************
forrest@0
   658
; for station line plot
forrest@0
   659
;*******************************************************************
forrest@0
   660
forrest@0
   661
; for x-axis in xyplot
forrest@0
   662
  mon = ispan(1,12,1)
forrest@0
   663
  mon@long_name = "month"
forrest@0
   664
forrest@0
   665
;-------------------------------------------------------------------
forrest@0
   666
forrest@0
   667
  plot_data   = new((/2,nmonth/),float)
forrest@0
   668
  plot_data!0 = "case"
forrest@0
   669
  plot_data!1 = "month"
forrest@0
   670
forrest@0
   671
  do n = 0,nstation-1
forrest@0
   672
;----------------------------
forrest@0
   673
; for observed
forrest@0
   674
forrest@0
   675
    plot_name = station(n)+"_ob"    
forrest@0
   676
    title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")"
forrest@0
   677
    res@tiMainString = title
forrest@0
   678
forrest@0
   679
    wks = gsn_open_wks (plot_type,plot_name)
forrest@0
   680
    plot=new(nfield,graphic)                        ; create graphic array   
forrest@0
   681
forrest@0
   682
    do i = 0,nfield-1                           
forrest@0
   683
       plot_data(0,:) = (/data_ob_ann(i,:,n)/)
forrest@0
   684
       plot_data@long_name = field(i)+" ("+field_unit(i)+")"   
forrest@0
   685
       plot(i)=gsn_csm_xy(wks,mon,plot_data(0,:),res)    ; create plot 
forrest@0
   686
    end do
forrest@0
   687
forrest@0
   688
    gsn_panel(wks,plot,(/3,2/),pres)                 ; create panel plot
forrest@0
   689
forrest@0
   690
    system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
forrest@0
   691
           "rm "+plot_name+"."+plot_type)
forrest@0
   692
forrest@0
   693
    clear (wks)  
forrest@0
   694
    delete (plot)
forrest@0
   695
;----------------------------
forrest@0
   696
; for model_vs_ob
forrest@0
   697
forrest@0
   698
    plot_name = station(n)+"_model_vs_ob"
forrest@0
   699
    title = station(n)+"("+sprintf("%5.2f",lat_ob(n))+","+sprintf("%5.2f",lon_ob(n))+")"    
forrest@0
   700
    res@tiMainString = title
forrest@0
   701
forrest@0
   702
    wks = gsn_open_wks (plot_type,plot_name)
forrest@0
   703
    plot=new(nfield,graphic)                         ; create graphic array   
forrest@0
   704
forrest@0
   705
    do i = 0,nfield-1                           
forrest@0
   706
       plot_data(0,:) = (/data_ob_ann(i,:,n)/)
forrest@0
   707
       plot_data(1,:) = (/data_mod_ann(i,:,n)/)
forrest@0
   708
       plot_data@long_name = field(i)+" ("+field_unit(i)+")"   
forrest@0
   709
       plot(i)=gsn_csm_xy(wks,mon,plot_data,res)     ; create plot 
forrest@0
   710
    end do
forrest@0
   711
   
forrest@0
   712
    gsn_panel(wks,plot,(/3,2/),pres)                 ; create panel plot
forrest@0
   713
forrest@0
   714
    system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
forrest@0
   715
           "rm "+plot_name+"."+plot_type)
forrest@0
   716
forrest@0
   717
    clear (wks)  
forrest@0
   718
    delete (plot)
forrest@0
   719
 end do
forrest@0
   720
forrest@0
   721
;###################################################################
forrest@0
   722
; for the following tables,
forrest@0
   723
; sort by latitude in decending order (N->S)
forrest@0
   724
; sort by lat in decending order (N->S)
forrest@0
   725
forrest@0
   726
  isort = dim_pqsort(lat_ob,-1)
forrest@0
   727
forrest@0
   728
  station_sort = station(isort)
forrest@0
   729
  year_ob_sort = year_ob(isort)
forrest@0
   730
  lat_ob_sort  = lat_ob(isort)
forrest@0
   731
  lon_ob_sort  = lon_ob(isort)
forrest@0
   732
  M_score_sort = M_score(isort,:)
forrest@0
   733
 
forrest@0
   734
; print(isort)
forrest@0
   735
; print(lat_ob_sort)
forrest@0
   736
;###################################################################
forrest@0
   737
;*******************************************************************
forrest@0
   738
; html table of site: observed
forrest@0
   739
;*******************************************************************
forrest@0
   740
  output_html = "line_ob.html"
forrest@0
   741
forrest@0
   742
  header = (/"<HTML>" \
forrest@0
   743
            ,"<HEAD>" \
forrest@0
   744
            ,"<TITLE>CLAMP metrics</TITLE>" \
forrest@0
   745
            ,"</HEAD>" \
forrest@0
   746
            ,"<H1>Energy at Site: Observation</H1>" \
forrest@0
   747
            /) 
forrest@0
   748
  footer = "</HTML>"
forrest@0
   749
forrest@0
   750
  table_header = (/ \
forrest@0
   751
        "<table border=1 cellspacing=0 cellpadding=3 width=60%>" \
forrest@0
   752
       ,"<tr>" \
forrest@0
   753
       ,"   <th bgcolor=DDDDDD >Site Name</th>" \
forrest@0
   754
       ,"   <th bgcolor=DDDDDD >Latitude</th>" \
forrest@0
   755
       ,"   <th bgcolor=DDDDDD >Longitude</th>" \
forrest@0
   756
       ,"   <th bgcolor=DDDDDD >Observed</th>" \ 
forrest@0
   757
       ,"</tr>" \
forrest@0
   758
       /)
forrest@0
   759
  table_footer = "</table>"
forrest@0
   760
  row_header = "<tr>"
forrest@0
   761
  row_footer = "</tr>"
forrest@0
   762
forrest@0
   763
  lines = new(50000,string)
forrest@0
   764
  nline = 0
forrest@0
   765
forrest@0
   766
  set_line(lines,nline,header)
forrest@0
   767
  set_line(lines,nline,table_header)
forrest@0
   768
;-----------------------------------------------
forrest@0
   769
; row of table
forrest@0
   770
  
forrest@0
   771
  do n = 0,nstation-1
forrest@0
   772
     set_line(lines,nline,row_header)
forrest@0
   773
forrest@0
   774
     txt0 = station_sort(n)
forrest@0
   775
     txt1 = sprintf("%5.2f", lat_ob_sort(n))
forrest@0
   776
     txt2 = sprintf("%5.2f", lon_ob_sort(n))
forrest@0
   777
     txt3 = year_ob_sort(n)
forrest@0
   778
forrest@0
   779
     set_line(lines,nline,"<th><a href="+txt0+"_ob.png>"+txt0+"</a></th>")
forrest@0
   780
     set_line(lines,nline,"<th>"+txt1+"</th>")
forrest@0
   781
     set_line(lines,nline,"<th>"+txt2+"</th>")
forrest@0
   782
     set_line(lines,nline,"<th>"+txt3+"</th>")
forrest@0
   783
forrest@0
   784
     set_line(lines,nline,row_footer)
forrest@0
   785
  end do
forrest@0
   786
;-----------------------------------------------
forrest@0
   787
  set_line(lines,nline,table_footer)
forrest@0
   788
  set_line(lines,nline,footer) 
forrest@0
   789
forrest@0
   790
; Now write to an HTML file.
forrest@0
   791
  idx = ind(.not.ismissing(lines))
forrest@0
   792
  if(.not.any(ismissing(idx))) then
forrest@0
   793
    asciiwrite(output_html,lines(idx))
forrest@0
   794
  else
forrest@0
   795
   print ("error?")
forrest@0
   796
  end if
forrest@0
   797
  delete (idx)
forrest@0
   798
forrest@0
   799
;*******************************************************************
forrest@0
   800
; score and line table : model vs observed
forrest@0
   801
;*******************************************************************
forrest@0
   802
  output_html = "score+line_vs_ob.html"
forrest@0
   803
forrest@0
   804
  header = (/"<HTML>" \
forrest@0
   805
            ,"<HEAD>" \
forrest@0
   806
            ,"<TITLE>CLAMP metrics</TITLE>" \
forrest@0
   807
            ,"</HEAD>" \
forrest@0
   808
            ,"<H1>Energy at Site: Model "+model_name+"</H1>" \
forrest@0
   809
            /) 
forrest@0
   810
  footer = "</HTML>"
forrest@0
   811
forrest@0
   812
  delete (table_header)
forrest@0
   813
  table_header = (/ \
forrest@0
   814
        "<table border=1 cellspacing=0 cellpadding=3 width=100%>" \
forrest@0
   815
       ,"<tr>" \
forrest@0
   816
       ,"   <th bgcolor=DDDDDD >Site Name</th>" \
forrest@0
   817
       ,"   <th bgcolor=DDDDDD >Latitude</th>" \
forrest@0
   818
       ,"   <th bgcolor=DDDDDD >Longitude</th>" \
forrest@0
   819
       ,"   <th bgcolor=DDDDDD >Observed</th>" \
forrest@0
   820
       ,"   <th bgcolor=DDDDDD >CO2 Flux</th>" \
forrest@0
   821
       ,"   <th bgcolor=DDDDDD >Net Radiation</th>" \
forrest@0
   822
       ,"   <th bgcolor=DDDDDD >Latent Heat</th>" \
forrest@0
   823
       ,"   <th bgcolor=DDDDDD >Sensible Heat</th>" \
forrest@0
   824
       ,"   <th bgcolor=DDDDDD >GPP Glux</th>" \
forrest@0
   825
       ,"   <th bgcolor=DDDDDD >Respiration</th>" \
forrest@0
   826
       ,"   <th bgcolor=DDDDDD >Average</th>" \
forrest@0
   827
       ,"</tr>" \
forrest@0
   828
       /)
forrest@0
   829
  table_footer = "</table>"
forrest@0
   830
  row_header = "<tr>"
forrest@0
   831
  row_footer = "</tr>"
forrest@0
   832
forrest@0
   833
  lines = new(50000,string)
forrest@0
   834
  nline = 0
forrest@0
   835
forrest@0
   836
  set_line(lines,nline,header)
forrest@0
   837
  set_line(lines,nline,table_header)
forrest@0
   838
;-----------------------------------------------
forrest@0
   839
; row of table
forrest@0
   840
  
forrest@0
   841
  do n = 0,nstation-1
forrest@0
   842
     set_line(lines,nline,row_header)
forrest@0
   843
forrest@0
   844
     txt0  = station_sort(n)
forrest@0
   845
     txt1  = sprintf("%5.2f", lat_ob_sort(n))
forrest@0
   846
     txt2  = sprintf("%5.2f", lon_ob_sort(n))
forrest@0
   847
     txt3  = year_ob_sort(n)
forrest@0
   848
     txt4  = sprintf("%5.2f", M_score_sort(n,0))
forrest@0
   849
     txt5  = sprintf("%5.2f", M_score_sort(n,1))
forrest@0
   850
     txt6  = sprintf("%5.2f", M_score_sort(n,2))
forrest@0
   851
     txt7  = sprintf("%5.2f", M_score_sort(n,3))
forrest@0
   852
     txt8  = sprintf("%5.2f", M_score_sort(n,4))
forrest@0
   853
     txt9  = sprintf("%5.2f", M_score_sort(n,5))
forrest@0
   854
     txt10 = sprintf("%5.2f", avg(M_score_sort(n,:)))
forrest@0
   855
forrest@0
   856
     set_line(lines,nline,"<th><a href="+txt0+"_model_vs_ob.png>"+txt0+"</a></th>")
forrest@0
   857
     set_line(lines,nline,"<th>"+txt1+"</th>")
forrest@0
   858
     set_line(lines,nline,"<th>"+txt2+"</th>")
forrest@0
   859
     set_line(lines,nline,"<th>"+txt3+"</th>")
forrest@0
   860
     set_line(lines,nline,"<th>"+txt4+"</th>")
forrest@0
   861
     set_line(lines,nline,"<th>"+txt5+"</th>")
forrest@0
   862
     set_line(lines,nline,"<th>"+txt6+"</th>")
forrest@0
   863
     set_line(lines,nline,"<th>"+txt7+"</th>")
forrest@0
   864
     set_line(lines,nline,"<th>"+txt8+"</th>")
forrest@0
   865
     set_line(lines,nline,"<th>"+txt9+"</th>")
forrest@0
   866
     set_line(lines,nline,"<th>"+txt10+"</th>")
forrest@0
   867
forrest@0
   868
     set_line(lines,nline,row_footer)
forrest@0
   869
  end do
forrest@0
   870
forrest@0
   871
; last row, summary
forrest@0
   872
  set_line(lines,nline,row_header)
forrest@0
   873
forrest@0
   874
  txt0  = "All_"+sprintf("%.0f", nstation)
forrest@0
   875
  txt1  = "-"
forrest@0
   876
  txt2  = "-"
forrest@0
   877
  txt3  = "-"
forrest@0
   878
  txt4  = M_energy_co2
forrest@0
   879
  txt5  = M_energy_rad
forrest@0
   880
  txt6  = M_energy_lh
forrest@0
   881
  txt7  = M_energy_sh
forrest@0
   882
  txt8  = M_energy_gpp
forrest@0
   883
  txt9  = M_energy_er
forrest@0
   884
  txt10 = M_energy_all
forrest@0
   885
forrest@0
   886
  set_line(lines,nline,"<th>"+txt0+"</th>")
forrest@0
   887
  set_line(lines,nline,"<th>"+txt1+"</th>")
forrest@0
   888
  set_line(lines,nline,"<th>"+txt2+"</th>")
forrest@0
   889
  set_line(lines,nline,"<th>"+txt3+"</th>")
forrest@0
   890
  set_line(lines,nline,"<th>"+txt4+"</th>")
forrest@0
   891
  set_line(lines,nline,"<th>"+txt5+"</th>")
forrest@0
   892
  set_line(lines,nline,"<th>"+txt6+"</th>")
forrest@0
   893
  set_line(lines,nline,"<th>"+txt7+"</th>")
forrest@0
   894
  set_line(lines,nline,"<th>"+txt8+"</th>")
forrest@0
   895
  set_line(lines,nline,"<th>"+txt9+"</th>")
forrest@0
   896
  set_line(lines,nline,"<th>"+txt10+"</th>")
forrest@0
   897
forrest@0
   898
  set_line(lines,nline,row_footer)
forrest@0
   899
;-----------------------------------------------
forrest@0
   900
  set_line(lines,nline,table_footer)
forrest@0
   901
  set_line(lines,nline,footer) 
forrest@0
   902
forrest@0
   903
; Now write to an HTML file.
forrest@0
   904
  idx = ind(.not.ismissing(lines))
forrest@0
   905
  if(.not.any(ismissing(idx))) then
forrest@0
   906
    asciiwrite(output_html,lines(idx))
forrest@0
   907
  else
forrest@0
   908
   print ("error?")
forrest@0
   909
  end if
forrest@0
   910
  delete (idx)
forrest@0
   911
forrest@0
   912
;***************************************************************************
forrest@0
   913
; output plots
forrest@0
   914
;***************************************************************************
forrest@0
   915
  output_dir = model_name+"/ameriflux"
forrest@0
   916
forrest@0
   917
  system("mv *.png *.html " + output_dir) 
forrest@0
   918
;***************************************************************************
forrest@0
   919
end
forrest@0
   920