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