lai/99.all.ncl.new
changeset 0 0c6405ab2ff4
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/lai/99.all.ncl.new	Mon Jan 26 22:08:20 2009 -0500
     1.3 @@ -0,0 +1,735 @@
     1.4 +;*************************************************************
     1.5 +; remove histogram plots.
     1.6 +;
     1.7 +; required command line input parameters:
     1.8 +;  ncl 'model_name="10cn" model_grid="T42" dirm="/.../ film="..."' 01.npp.ncl
     1.9 +;
    1.10 +; histogram normalized by rain and compute correleration
    1.11 +;**************************************************************
    1.12 +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl.test"
    1.13 +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl.test"
    1.14 +load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
    1.15 +;**************************************************************
    1.16 +procedure set_line(lines:string,nline:integer,newlines:string) 
    1.17 +begin
    1.18 +; add line to ascci/html file
    1.19 +    
    1.20 +  nnewlines = dimsizes(newlines)
    1.21 +  if(nline+nnewlines-1.ge.dimsizes(lines))
    1.22 +    print("set_line: bad index, not setting anything.") 
    1.23 +    return
    1.24 +  end if 
    1.25 +  lines(nline:nline+nnewlines-1) = newlines
    1.26 +;  print ("lines = " + lines(nline:nline+nnewlines-1))
    1.27 +  nline = nline + nnewlines
    1.28 +  return 
    1.29 +end
    1.30 +;**************************************************************
    1.31 +; Main code.
    1.32 +begin
    1.33 + 
    1.34 +  plot_type     = "ps"
    1.35 +  plot_type_new = "png"
    1.36 +
    1.37 +;************************************************
    1.38 +; read data: model       
    1.39 +;************************************************
    1.40 +
    1.41 +;film  = "b30.061n_1995-2004_MONS_climo_lnd.nc"
    1.42 +;model_name = "b30.061n"
    1.43 +;model_grid = "T31"
    1.44 +
    1.45 +;film  = "newcn05_ncep_1i_MONS_climo_lnd.nc"
    1.46 +;model_name = "newcn"
    1.47 +;model_grid = "1.9"
    1.48 +
    1.49 +;film  = "i01.06cn_1798-2004_MONS_climo.nc"
    1.50 +;model_name = "06cn"
    1.51 +;model_grid = "T42"
    1.52 +
    1.53 +;film  = "i01.06casa_1798-2004_MONS_climo.nc"
    1.54 +;model_name = "06casa"
    1.55 +;model_grid = "T42"
    1.56 +
    1.57 + film  = "i01.10cn_1948-2004_MONS_climo.nc"
    1.58 + model_name = "10cn"
    1.59 + model_grid = "T42"
    1.60 +
    1.61 +;film  = "i01.10casa_1948-2004_MONS_climo.nc"
    1.62 +;model_name = "10casa"
    1.63 +;model_grid = "T42"
    1.64 +
    1.65 + dirm  = "/fis/cgd/cseg/people/jeff/clamp_data/model/"
    1.66 + fm    = addfile(dirm+film,"r")
    1.67 +      
    1.68 + laimod  = fm->TLAI
    1.69 +      
    1.70 +;************************************************
    1.71 +; read data: observed
    1.72 +;************************************************
    1.73 +
    1.74 +  ob_name = "MODIS MOD 15A2 2000-2005"
    1.75 +
    1.76 +  diro  = "/fis/cgd/cseg/people/jeff/clamp_data/lai/ob/"
    1.77 +  filo1  = "land_class_"+model_grid+".nc"
    1.78 +  filo2  = "LAI_2000-2005_MONS_"+model_grid+".nc"
    1.79 +
    1.80 +  fo1 = addfile(diro+filo1,"r")
    1.81 +  fo2 = addfile(diro+filo2,"r")
    1.82 + 
    1.83 +  classob    = tofloat(fo1->LAND_CLASS)               
    1.84 +  laiob      = fo2->LAI
    1.85 +
    1.86 +; input observed data has 20 land-type classes
    1.87 +  nclass = 20
    1.88 +
    1.89 +;************************************************
    1.90 +; global res
    1.91 +;************************************************
    1.92 +  resg                      = True             ; Use plot options
    1.93 +  resg@cnFillOn             = True             ; Turn on color fill
    1.94 +  resg@gsnSpreadColors      = True             ; use full colormap
    1.95 +  resg@cnLinesOn            = False            ; Turn off contourn lines
    1.96 +  resg@mpFillOn             = False            ; Turn off map fill
    1.97 +  resg@cnLevelSelectionMode = "ManualLevels"   ; Manual contour invtervals
    1.98 +
    1.99 +;************************************************
   1.100 +; plot global land class: observed
   1.101 +;************************************************
   1.102 +
   1.103 +  resg@cnMinLevelValF       = 1.              ; Min level
   1.104 +  resg@cnMaxLevelValF       = 19.             ; Max level
   1.105 +  resg@cnLevelSpacingF      = 1.              ; interval
   1.106 +
   1.107 +; global contour ob
   1.108 +  classob@_FillValue = 1.e+36
   1.109 +  classob = where(classob.eq.0,classob@_FillValue,classob)
   1.110 +  
   1.111 +  plot_name = "global_class_ob"
   1.112 +  title     = ob_name
   1.113 +  resg@tiMainString  = title
   1.114 +
   1.115 +  wks = gsn_open_wks (plot_type,plot_name)   ; open workstation
   1.116 +  gsn_define_colormap(wks,"gui_default")     ; choose colormap
   1.117 +
   1.118 +  plot = gsn_csm_contour_map_ce(wks,classob,resg)   
   1.119 +  frame(wks)
   1.120 +
   1.121 +  clear (wks)
   1.122 + 
   1.123 +;*******************************************************************
   1.124 +; for html table : all 4 components (Mean, Max, Phase, Growth)
   1.125 +;*******************************************************************
   1.126 +
   1.127 +; column (not including header column)
   1.128 +
   1.129 +  component = (/"Mean","Max","Phase","Growth"/)
   1.130 +  col_head2 = (/"observed",model_name,"M_score" \
   1.131 +               ,"observed",model_name,"M_score" \
   1.132 +               ,"observed",model_name,"M_score" \
   1.133 +               ,"observed",model_name,"M_score" \
   1.134 +               /)
   1.135 +  
   1.136 +  n_comp = dimsizes(component) 
   1.137 +  ncol   = dimsizes(col_head2)
   1.138 +
   1.139 +; row (not including header row)
   1.140 +  row_head  = (/"Evergreen Needleleaf Forests" \
   1.141 +               ,"Evergreen Broadleaf Forests" \
   1.142 +               ,"Deciduous Needleleaf Forest" \
   1.143 +               ,"Deciduous Broadleaf Forests" \
   1.144 +               ,"Mixed Forests" \                      
   1.145 +               ,"Closed Bushlands" \                   
   1.146 +               ,"Open Bushlands" \                     
   1.147 +               ,"Woody Savannas (S. Hem.)" \           
   1.148 +               ,"Savannas (S. Hem.)" \                 
   1.149 +               ,"Grasslands" \                         
   1.150 +               ,"Permanent Wetlands" \                 
   1.151 +               ,"Croplands" \                                           
   1.152 +               ,"Cropland/Natural Vegetation Mosaic" \             
   1.153 +               ,"Barren or Sparsely Vegetated" \                             
   1.154 +               ,"Woody Savannas (N. Hem.)" \           
   1.155 +               ,"Savannas (N. Hem.)" \
   1.156 +               ,"All Biome" \                
   1.157 +               /)  
   1.158 +  nrow = dimsizes(row_head)                  
   1.159 +
   1.160 +; arrays to be passed to table. 
   1.161 +  text4 = new ((/nrow, ncol/),string )
   1.162 +
   1.163 +; M_comp
   1.164 +  M_comp = (/"M_lai_mean","M_lai_max","M_lai_phase","M_lai_grow"/) 
   1.165 +
   1.166 +; total M_score
   1.167 +  M_total = 0.
   1.168 +
   1.169 +;********************************************************************
   1.170 +; use land-type class to bin the data in equally spaced ranges
   1.171 +;********************************************************************
   1.172 +
   1.173 +  nclassn     = nclass + 1
   1.174 +  range       = fspan(0,nclassn-1,nclassn)
   1.175 +; print (range)
   1.176 +
   1.177 +; Use this range information to grab all the values in a
   1.178 +; particular range, and then take an average.
   1.179 +
   1.180 +  nr           = dimsizes(range)
   1.181 +  nx           = nr-1
   1.182 +  xvalues      = new((/2,nx/),float)
   1.183 +  xvalues(0,:) = range(0:nr-2) + (range(1:)-range(0:nr-2))/2.
   1.184 +  dx           = xvalues(0,1) - xvalues(0,0)       ; range width
   1.185 +  dx4          = dx/4                              ; 1/4 of the range
   1.186 +  xvalues(1,:) = xvalues(0,:) - dx/5.
   1.187 +
   1.188 +;************************************************************************
   1.189 +; go through all components
   1.190 +;************************************************************************
   1.191 +
   1.192 +  do n = 0,n_comp-1
   1.193 +
   1.194 +;===================
   1.195 +; get data:
   1.196 +;===================
   1.197 +; (A) Mean
   1.198 + 
   1.199 +  if (n .eq. 0) then
   1.200 +     data_ob  = dim_avg_Wrap(laiob (lat|:,lon|:,time|:))
   1.201 +     data_mod = dim_avg_Wrap(laimod(lat|:,lon|:,time|:))
   1.202 +  end if
   1.203 +
   1.204 +; (B) Max
   1.205 +
   1.206 +  if (n .eq. 1) then
   1.207 +
   1.208 +;    observed  
   1.209 +     data_ob = laiob(0,:,:)
   1.210 +     s       = laiob(:,0,0)
   1.211 +     data_ob@long_name = "Leaf Area Index Max"
   1.212 + 
   1.213 +     dsizes_z = dimsizes(laiob)
   1.214 +     nlat     = dsizes_z(1)
   1.215 +     nlon     = dsizes_z(2)
   1.216 +  
   1.217 +     do j = 0,nlat-1
   1.218 +     do i = 0,nlon-1
   1.219 +        s = laiob(:,j,i) 
   1.220 +        data_ob(j,i) = max(s)
   1.221 +     end do
   1.222 +     end do
   1.223 +
   1.224 +     delete (s)
   1.225 +     delete (dsizes_z)          
   1.226 +
   1.227 +;    model  
   1.228 +     data_mod = laimod(0,:,:)
   1.229 +     s        = laimod(:,0,0)
   1.230 +     data_mod@long_name = "Leaf Area Index Max"
   1.231 + 
   1.232 +     dsizes_z = dimsizes(laimod)
   1.233 +     nlat     = dsizes_z(1)
   1.234 +     nlon     = dsizes_z(2)
   1.235 +  
   1.236 +     do j = 0,nlat-1
   1.237 +     do i = 0,nlon-1
   1.238 +        s = laimod(:,j,i) 
   1.239 +        data_mod(j,i) = max(s)
   1.240 +     end do
   1.241 +     end do
   1.242 +
   1.243 +     delete (s)
   1.244 +     delete (dsizes_z)          
   1.245 +  end if
   1.246 +
   1.247 +; (C) phase
   1.248 +
   1.249 +  if (n .eq. 2) then  
   1.250 +
   1.251 +;    observed
   1.252 +     data_ob = laiob(0,:,:)
   1.253 +     s       = laiob(:,0,0)
   1.254 +     data_ob@long_name = "Leaf Area Index Max Month"
   1.255 + 
   1.256 +     dsizes_z = dimsizes(laiob)
   1.257 +     nlat     = dsizes_z(1)
   1.258 +     nlon     = dsizes_z(2)
   1.259 +  
   1.260 +     do j = 0,nlat-1
   1.261 +     do i = 0,nlon-1
   1.262 +        s = laiob(:,j,i) 
   1.263 +        data_ob(j,i) = maxind(s) + 1
   1.264 +     end do
   1.265 +     end do
   1.266 +
   1.267 +     delete (s)
   1.268 +     delete (dsizes_z)          
   1.269 +
   1.270 +;    model
   1.271 +     data_mod = laimod(0,:,:)
   1.272 +     s        = laimod(:,0,0)
   1.273 +     data_mod@long_name = "Leaf Area Index Max Month"
   1.274 + 
   1.275 +     dsizes_z = dimsizes(laimod)
   1.276 +     nlat     = dsizes_z(1)
   1.277 +     nlon     = dsizes_z(2)
   1.278 +  
   1.279 +     do j = 0,nlat-1
   1.280 +     do i = 0,nlon-1
   1.281 +        s = laimod(:,j,i) 
   1.282 +        data_mod(j,i) = maxind(s) + 1
   1.283 +     end do
   1.284 +     end do
   1.285 +
   1.286 +     delete (s)
   1.287 +     delete (dsizes_z)          
   1.288 +  end if
   1.289 +
   1.290 +; (D) grow day
   1.291 +
   1.292 +  if (n .eq. 3) then   
   1.293 +
   1.294 +     day_of_data = (/31,28,31,30,31,30,31,31,30,31,30,31/)
   1.295 +
   1.296 +;    observed
   1.297 +     data_ob = laiob(0,:,:)
   1.298 +     data_ob@long_name = "Days of Growing Season"
   1.299 + 
   1.300 +     dsizes_z = dimsizes(laiob)
   1.301 +     ntime    = dsizes_z(0)
   1.302 +     nlat     = dsizes_z(1)
   1.303 +     nlon     = dsizes_z(2)
   1.304 +  
   1.305 +     do j = 0,nlat-1
   1.306 +     do i = 0,nlon-1
   1.307 +        nday = 0.
   1.308 +        do k = 0,ntime-1
   1.309 +           if (.not. ismissing(laiob(k,j,i)) .and. laiob(k,j,i) .gt. 1.0) then
   1.310 +              nday = nday + day_of_data(k)
   1.311 +           end if
   1.312 +        end do
   1.313 +
   1.314 +        data_ob(j,i) = nday
   1.315 +     end do
   1.316 +     end do
   1.317 +
   1.318 +     delete (dsizes_z)     
   1.319 +
   1.320 +;    model
   1.321 +     data_mod = laimod(0,:,:)
   1.322 +     data_mod@long_name = "Days of Growing Season"
   1.323 + 
   1.324 +     dsizes_z = dimsizes(laimod)
   1.325 +     ntime    = dsizes_z(0)
   1.326 +     nlat     = dsizes_z(1)
   1.327 +     nlon     = dsizes_z(2)
   1.328 +  
   1.329 +     do j = 0,nlat-1
   1.330 +     do i = 0,nlon-1
   1.331 +        nday = 0.
   1.332 +        do k = 0,ntime-1
   1.333 +           if (.not. ismissing(laimod(k,j,i)) .and. laimod(k,j,i) .gt. 1.0) then
   1.334 +              nday = nday + day_of_data(k)
   1.335 +           end if
   1.336 +        end do
   1.337 +
   1.338 +        data_mod(j,i) = nday
   1.339 +     end do
   1.340 +     end do
   1.341 +
   1.342 +     delete (dsizes_z)
   1.343 +  end if
   1.344 +
   1.345 +;==============================
   1.346 +; put data into bins
   1.347 +;==============================
   1.348 +
   1.349 +  base_1D  = ndtooned(classob)
   1.350 +  data1_1D = ndtooned(data_ob)
   1.351 +  data2_1D = ndtooned(data_mod)
   1.352 +
   1.353 +; output for data in bins
   1.354 +
   1.355 +  yvalues = new((/2,nx/),float)
   1.356 +  count   = new((/2,nx/),float)
   1.357 +
   1.358 +; put data into bins
   1.359 +
   1.360 +  do nd=0,1
   1.361 +
   1.362 +;   See if we are doing data1 (nd=0) or data2 (nd=1).
   1.363 +
   1.364 +    base = base_1D
   1.365 +
   1.366 +    if(nd.eq.0) then
   1.367 +      data = data1_1D
   1.368 +    else
   1.369 +      data = data2_1D
   1.370 +    end if
   1.371 +
   1.372 +;   Loop through each range, using base.
   1.373 +
   1.374 +    do i=0,nr-2
   1.375 +      if (i.ne.(nr-2)) then
   1.376 +;        print("")
   1.377 +;        print("In range ["+range(i)+","+range(i+1)+")")
   1.378 +         idx = ind((base.ge.range(i)).and.(base.lt.range(i+1)))
   1.379 +      else
   1.380 +;        print("")
   1.381 +;        print("In range ["+range(i)+",)")
   1.382 +         idx = ind(base.ge.range(i))
   1.383 +      end if
   1.384 +
   1.385 +;     Calculate average 
   1.386 +
   1.387 +      if(.not.any(ismissing(idx))) then
   1.388 +        yvalues(nd,i) = avg(data(idx))
   1.389 +        count(nd,i)   = dimsizes(idx)
   1.390 +      else
   1.391 +        yvalues(nd,i) = yvalues@_FillValue
   1.392 +        count(nd,i)   = 0
   1.393 +      end if
   1.394 +
   1.395 +;#############################################################
   1.396 +;     set the following 4 classes to _FillValue:
   1.397 +;     Water Bodies(0), Urban and Build-Up(13),
   1.398 +;     Permenant Snow and Ice(15), Unclassified(17)
   1.399 +
   1.400 +      if (i.eq.0 .or. i.eq.13 .or. i.eq.15 .or. i.eq.17) then
   1.401 +         yvalues(nd,i) = yvalues@_FillValue
   1.402 +         count(nd,i)   = 0
   1.403 +      end if
   1.404 +;############################################################# 
   1.405 +
   1.406 +;     print(nd + ": " + count(nd,i) + " points, avg = " + yvalues(nd,i))
   1.407 +
   1.408 +;     Clean up for next time in loop.
   1.409 +
   1.410 +      delete(idx)
   1.411 +    end do
   1.412 +
   1.413 +    delete(data)
   1.414 +  end do
   1.415 +
   1.416 +  delete (base)
   1.417 +  delete (base_1D)
   1.418 +  delete (data1_1D)
   1.419 +  delete (data2_1D)
   1.420 +
   1.421 +;=====================================
   1.422 +; compute correlation coef and M score 
   1.423 +;=====================================
   1.424 +
   1.425 +  u = yvalues(0,:)
   1.426 +  v = yvalues(1,:)
   1.427 +
   1.428 +  good = ind(.not.ismissing(u) .and. .not.ismissing(v))
   1.429 +  uu = u(good)
   1.430 +  vv = v(good)
   1.431 +
   1.432 +; compute correlation coef
   1.433 +  cc = esccr(uu,vv,0)
   1.434 +
   1.435 +  if (n .eq. 2) then
   1.436 +     bias   = avg(abs(vv-uu))
   1.437 +     bias   = where((bias.gt. 6.),12.-bias,bias)
   1.438 +     Mscore = ((6. - bias)/6.)*5.
   1.439 +     M_score = sprintf("%.2f", Mscore)
   1.440 +  else
   1.441 +     bias  = sum(abs(vv-uu)/abs(vv+uu))
   1.442 +     Mscore = (1.- (bias/dimsizes(uu)))*5.
   1.443 +     M_score = sprintf("%.2f", Mscore)
   1.444 +  end if
   1.445 +
   1.446 +; compute M_total
   1.447 +  
   1.448 +  M_total = M_total + Mscore
   1.449 +
   1.450 +;==================
   1.451 +; output M_score
   1.452 +;==================
   1.453 +
   1.454 +  print (Mscore)
   1.455 +;=======================
   1.456 +; output to html table
   1.457 +;=======================
   1.458 +
   1.459 +  nn = n*3
   1.460 +
   1.461 +  do i=0,nrow-2
   1.462 +     text4(i,nn)   = sprintf("%.2f",u(i))
   1.463 +     text4(i,nn+1) = sprintf("%.2f",v(i))
   1.464 +     text4(i,nn+2) = "-"
   1.465 +  end do
   1.466 +  text4(nrow-1,nn)   = sprintf("%.2f",avg(u))
   1.467 +  text4(nrow-1,nn+1) = sprintf("%.2f",avg(v))
   1.468 +  text4(nrow-1,nn+2) = M_score
   1.469 +
   1.470 +  delete (u)
   1.471 +  delete (v)
   1.472 +  delete (uu)
   1.473 +  delete (vv)
   1.474 +  delete (yvalues)
   1.475 +  delete (good)
   1.476 +
   1.477 +;======================================== 
   1.478 +; global res changes for each component
   1.479 +;========================================
   1.480 +  delta = 0.00001  
   1.481 +
   1.482 +  if (n .eq. 0) then
   1.483 +     resg@cnMinLevelValF       = 0.             
   1.484 +     resg@cnMaxLevelValF       = 10.             
   1.485 +     resg@cnLevelSpacingF      = 1.
   1.486 +
   1.487 +     data_ob = where(ismissing(data_ob).and.(ismissing(data_mod).or.(data_mod.lt.delta)),0.,data_ob)
   1.488 +  end if
   1.489 +
   1.490 +  if (n .eq. 1) then
   1.491 +     resg@cnMinLevelValF       = 0.             
   1.492 +     resg@cnMaxLevelValF       = 10.             
   1.493 +     resg@cnLevelSpacingF      = 1.
   1.494 +
   1.495 +     data_ob = where(ismissing(data_ob).and.(ismissing(data_mod).or.(data_mod.lt.delta)),0.,data_ob)
   1.496 +  end if
   1.497 +
   1.498 +  if (n .eq. 2) then
   1.499 +     resg@cnMinLevelValF       = 1.             
   1.500 +     resg@cnMaxLevelValF       = 12.             
   1.501 +     resg@cnLevelSpacingF      = 1.
   1.502 +
   1.503 +     data_ob = where(ismissing(data_ob).and.(ismissing(data_mod).or.(data_mod.lt.delta)),0.,data_ob)
   1.504 +  end if
   1.505 +
   1.506 +  if (n .eq. 3) then
   1.507 +     resg@cnMinLevelValF       = 60.             
   1.508 +     resg@cnMaxLevelValF       = 360.             
   1.509 +     resg@cnLevelSpacingF      = 20.
   1.510 +
   1.511 +     data_ob@_FillValue = 1.e+36
   1.512 +     data_ob = where(data_ob .lt. 10.,data_ob@_FillValue,data_ob)
   1.513 +
   1.514 +     data_mod@_FillValue = 1.e+36
   1.515 +     data_mod = where(data_mod .lt. 10.,data_mod@_FillValue,data_mod)        
   1.516 +  end if                                                        
   1.517 +
   1.518 +;=========================
   1.519 +; global contour : ob
   1.520 +;=========================
   1.521 +  
   1.522 +  plot_name = "global_"+component(n)+"_ob"
   1.523 +  title     = ob_name
   1.524 +  resg@tiMainString  = title
   1.525 +
   1.526 +  wks = gsn_open_wks (plot_type,plot_name)   ; open workstation
   1.527 +  gsn_define_colormap(wks,"gui_default")     ; choose colormap
   1.528 +
   1.529 +  plot = gsn_csm_contour_map_ce(wks,data_ob,resg)   
   1.530 +  frame(wks)
   1.531 +
   1.532 +  clear (wks)
   1.533 +  delete (plot)
   1.534 +
   1.535 +;============================
   1.536 +; global contour : model
   1.537 +;============================
   1.538 +
   1.539 +  plot_name = "global_"+component(n)+"_model"  
   1.540 +  title     = "Model " + model_name
   1.541 +  resg@tiMainString  = title
   1.542 +
   1.543 +  wks = gsn_open_wks (plot_type,plot_name)
   1.544 +  gsn_define_colormap(wks,"gui_default")     
   1.545 +
   1.546 +  plot = gsn_csm_contour_map_ce(wks,data_mod,resg)   
   1.547 +  frame(wks)
   1.548 +
   1.549 +  clear (wks)
   1.550 +  delete (plot)
   1.551 +
   1.552 +;================================
   1.553 +; global contour: model vs ob
   1.554 +;================================
   1.555 +
   1.556 +  plot_name = "global_"+component(n)+"_model_vs_ob"
   1.557 +
   1.558 +  wks = gsn_open_wks (plot_type,plot_name)   
   1.559 +  gsn_define_colormap(wks,"gui_default")     
   1.560 +
   1.561 +  plot=new(3,graphic)                        ; create graphic array
   1.562 +
   1.563 +  resg@gsnFrame             = False          ; Do not draw plot 
   1.564 +  resg@gsnDraw              = False          ; Do not advance frame
   1.565 +
   1.566 +; plot correlation coef
   1.567 +
   1.568 +  gRes               = True
   1.569 +  gRes@txFontHeightF = 0.02
   1.570 +  gRes@txAngleF      = 90
   1.571 +
   1.572 +  correlation_text = "(correlation coef = "+sprintf("%.2f", cc)+")"
   1.573 +
   1.574 +  gsn_text_ndc(wks,correlation_text,0.20,0.50,gRes)
   1.575 +  
   1.576 +; plot ob
   1.577 +
   1.578 +  title     = ob_name
   1.579 +  resg@tiMainString  = title
   1.580 +
   1.581 +  plot(0) = gsn_csm_contour_map_ce(wks,data_ob,resg)       
   1.582 +
   1.583 +; plot model
   1.584 +
   1.585 +  title     = "Model "+ model_name
   1.586 +  resg@tiMainString  = title
   1.587 +
   1.588 +  plot(1) = gsn_csm_contour_map_ce(wks,data_mod,resg) 
   1.589 +
   1.590 +; plot model-ob
   1.591 +
   1.592 +  if (n .eq. 0) then
   1.593 +     resg@cnMinLevelValF  = -2.           
   1.594 +     resg@cnMaxLevelValF  =  2.            
   1.595 +     resg@cnLevelSpacingF =  0.4
   1.596 +  end if
   1.597 +
   1.598 +  if (n .eq. 1) then
   1.599 +     resg@cnMinLevelValF  = -6.           
   1.600 +     resg@cnMaxLevelValF  =  6.            
   1.601 +     resg@cnLevelSpacingF =  1.
   1.602 +  end if
   1.603 +
   1.604 +  if (n .eq. 2) then
   1.605 +     resg@cnMinLevelValF  = -6.           
   1.606 +     resg@cnMaxLevelValF  =  6.            
   1.607 +     resg@cnLevelSpacingF =  1.
   1.608 +  end if
   1.609 +
   1.610 +  if (n .eq. 3) then
   1.611 +     resg@cnMinLevelValF  = -100.           
   1.612 +     resg@cnMaxLevelValF  =  100.            
   1.613 +     resg@cnLevelSpacingF =  20.
   1.614 +  end if            
   1.615 +
   1.616 +  zz = data_mod
   1.617 +  zz = data_mod - data_ob
   1.618 +  title = "Model_"+model_name+" - Observed"
   1.619 +  resg@tiMainString    = title
   1.620 +
   1.621 +  plot(2) = gsn_csm_contour_map_ce(wks,zz,resg) 
   1.622 +
   1.623 +; plot panel
   1.624 +
   1.625 +  pres                            = True        ; panel plot mods desired
   1.626 +  pres@gsnMaximize                = True        ; fill the page
   1.627 +
   1.628 +  gsn_panel(wks,plot,(/3,1/),pres)              ; create panel plot
   1.629 +
   1.630 +  clear (wks)
   1.631 +  delete (plot)
   1.632 +
   1.633 +  end do
   1.634 +;**************************************************
   1.635 +; html table
   1.636 +;**************************************************
   1.637 +  output_html = "table_model_vs_ob.html"
   1.638 +
   1.639 +  header_text = "<H1>LAI: Model "+model_name+" vs Observed</H1>" 
   1.640 +
   1.641 +  header = (/"<HTML>" \
   1.642 +            ,"<HEAD>" \
   1.643 +            ,"<TITLE>CLAMP metrics</TITLE>" \
   1.644 +            ,"</HEAD>" \
   1.645 +            ,header_text \
   1.646 +            /) 
   1.647 +  footer = "</HTML>"
   1.648 +
   1.649 +  table_header = (/ \
   1.650 +        "<table border=1 cellspacing=0 cellpadding=3 width=100%>" \
   1.651 +       ,"<tr>" \
   1.652 +       ,"   <th bgcolor=DDDDDD rowspan=2>Biome Class</th>" \
   1.653 +       ,"   <th bgcolor=DDDDDD colspan=3>"+component(0)+"</th>" \
   1.654 +       ,"   <th bgcolor=DDDDDD colspan=3>"+component(1)+"</th>" \
   1.655 +       ,"   <th bgcolor=DDDDDD colspan=3>"+component(2)+"</th>" \
   1.656 +       ,"   <th bgcolor=DDDDDD colspan=3>"+component(3)+"</th>" \
   1.657 +       ,"</tr>" \
   1.658 +       ,"<tr>" \
   1.659 +       ,"   <th bgcolor=DDDDDD >observed</th>" \
   1.660 +       ,"   <th bgcolor=DDDDDD >"+model_name+"</th>" \
   1.661 +       ,"   <th bgcolor=DDDDDD >M_score</th>" \
   1.662 +       ,"   <th bgcolor=DDDDDD >observed</th>" \
   1.663 +       ,"   <th bgcolor=DDDDDD >"+model_name+"</th>" \
   1.664 +       ,"   <th bgcolor=DDDDDD >M_score</th>" \
   1.665 +       ,"   <th bgcolor=DDDDDD >observed</th>" \
   1.666 +       ,"   <th bgcolor=DDDDDD >"+model_name+"</th>" \
   1.667 +       ,"   <th bgcolor=DDDDDD >M_score</th>" \
   1.668 +       ,"   <th bgcolor=DDDDDD >observed</th>" \
   1.669 +       ,"   <th bgcolor=DDDDDD >"+model_name+"</th>" \
   1.670 +       ,"   <th bgcolor=DDDDDD >M_score</th>" \
   1.671 +       ,"</tr>" \
   1.672 +       /)
   1.673 +  table_footer = "</table>"
   1.674 +  row_header = "<tr>"
   1.675 +  row_footer = "</tr>"
   1.676 +
   1.677 +  lines = new(50000,string)
   1.678 +  nline = 0
   1.679 +
   1.680 +  set_line(lines,nline,header)
   1.681 +  set_line(lines,nline,table_header)
   1.682 +;-----------------------------------------------
   1.683 +;row of table
   1.684 +
   1.685 +  do n = 0,nrow-1
   1.686 +     set_line(lines,nline,row_header)
   1.687 +
   1.688 +     txt1  = row_head(n)
   1.689 +     txt2  = text4(n,0)
   1.690 +     txt3  = text4(n,1)
   1.691 +     txt4  = text4(n,2)
   1.692 +     txt5  = text4(n,3)
   1.693 +     txt6  = text4(n,4)
   1.694 +     txt7  = text4(n,5)
   1.695 +     txt8  = text4(n,6)
   1.696 +     txt9  = text4(n,7)
   1.697 +     txt10 = text4(n,8)
   1.698 +     txt11 = text4(n,9)
   1.699 +     txt12 = text4(n,10)
   1.700 +     txt13 = text4(n,11) 
   1.701 +
   1.702 +     set_line(lines,nline,"<th>"+txt1+"</th>")
   1.703 +     set_line(lines,nline,"<th>"+txt2+"</th>")
   1.704 +     set_line(lines,nline,"<th>"+txt3+"</th>")
   1.705 +     set_line(lines,nline,"<th>"+txt4+"</th>")
   1.706 +     set_line(lines,nline,"<th>"+txt5+"</th>")
   1.707 +     set_line(lines,nline,"<th>"+txt6+"</th>")
   1.708 +     set_line(lines,nline,"<th>"+txt7+"</th>")
   1.709 +     set_line(lines,nline,"<th>"+txt8+"</th>")
   1.710 +     set_line(lines,nline,"<th>"+txt9+"</th>")
   1.711 +     set_line(lines,nline,"<th>"+txt10+"</th>")
   1.712 +     set_line(lines,nline,"<th>"+txt11+"</th>")
   1.713 +     set_line(lines,nline,"<th>"+txt12+"</th>")
   1.714 +     set_line(lines,nline,"<th>"+txt13+"</th>")
   1.715 +
   1.716 +     set_line(lines,nline,row_footer)
   1.717 +  end do
   1.718 +;-----------------------------------------------
   1.719 +  set_line(lines,nline,table_footer)
   1.720 +  set_line(lines,nline,footer) 
   1.721 +
   1.722 +; Now write to an HTML file.
   1.723 +  idx = ind(.not.ismissing(lines))
   1.724 +  if(.not.any(ismissing(idx))) then
   1.725 +    asciiwrite(output_html,lines(idx))
   1.726 +  else
   1.727 +   print ("error?")
   1.728 +  end if
   1.729 +
   1.730 +;***************************************************************************
   1.731 +; write total score to file
   1.732 +;***************************************************************************
   1.733 +
   1.734 +  asciiwrite("M_save.lai", M_total)
   1.735 +
   1.736 +;***************************************************************************
   1.737 +end
   1.738 +