all/10.fire.ncl
author Forrest Hoffman <forrest@climatemodeling.org>
Thu, 26 Mar 2009 14:02:21 -0400
changeset 1 4be95183fbcd
parent 0 0c6405ab2ff4
permissions -rw-r--r--
Modifications to scoring and graphics production for the final version of code for the C-LAMP paper in GCB.
     1 ;**************************************************************
     2 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
     3 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
     4 load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
     5 ;**************************************************************
     6 procedure set_line(lines:string,nline:integer,newlines:string) 
     7 begin
     8 ; add line to ascci/html file
     9     
    10   nnewlines = dimsizes(newlines)
    11   if(nline+nnewlines-1.ge.dimsizes(lines))
    12     print("set_line: bad index, not setting anything.") 
    13     return
    14   end if 
    15   lines(nline:nline+nnewlines-1) = newlines
    16 ;  print ("lines = " + lines(nline:nline+nnewlines-1))
    17   nline = nline + nnewlines
    18   return 
    19 end
    20 ;**************************************************************
    21 ; Main code.
    22 begin
    23  
    24   plot_type     = "ps"
    25   plot_type_new = "png"
    26 
    27 ;------------------------------------------------------
    28 ; edit table.html of current model for movel1_vs_model2
    29 
    30  if (isvar("compare")) then
    31     html_name2 = compare+"/table.html"  
    32     html_new2  = html_name2 +".new"
    33  end if
    34 
    35 ;------------------------------------------------------
    36 ; edit table.html for current model
    37 
    38  html_name = model_name+"/table.html"  
    39  html_new  = html_name +".new"
    40 
    41 ;------------------------------------------------------ 
    42 ; get biome data: model
    43 
    44   biome_name_mod = "Model PFT Class"
    45 
    46   film_c   = "class_pft_"+ model_grid +".nc"
    47   fm_c     = addfile (dirs+film_c,"r") 
    48   classmod = fm_c->CLASS_PFT
    49 
    50   delete (fm_c)
    51 
    52 ; model data has 17 land-type classes
    53   nclass_mod = 17
    54 
    55 ;--------------------------------
    56 ; get model data: landmask, landfrac and area
    57  
    58   film_l   = "lnd_"+ model_grid +".nc"
    59   fm_l     = addfile (dirs+film_l,"r")  
    60   landmask = fm_l->landmask
    61   landfrac = fm_l->landfrac
    62   area     = fm_l->area
    63 
    64   delete (fm_l)
    65 
    66 ; change area from km**2 to m**2
    67   area = area * 1.e6
    68              
    69 ; take into account landfrac
    70   area     = area * landfrac
    71 
    72 ;--------------------------------
    73 ; read data: time series, model
    74 
    75  fm   = addfile (dirm+film7,"r")
    76 
    77  ; FMH: This was Jeff's, but I got an error
    78  data_mod = fm->COL_FIRE_CLOSS(18:25,:,:,:)
    79  ; FMH: So I'll try this
    80  ;data_mod = fm->COL_FIRE_CLOSS(17:24,:,:,:)
    81 
    82  delete (fm)
    83 
    84 ; Units for these variables are:
    85 ; g C/m^2/s
    86 
    87 ; change unit to gC/m2/month
    88 
    89   nsec_per_month = 60*60*24*30
    90  
    91   data_mod = data_mod * nsec_per_month 
    92 
    93   data_mod@units = "gC/m2/month"
    94 
    95 ;----------------------------------------------------
    96 ; read data: time series, observed
    97 
    98  dir_f   = diro + "fire/"
    99  fil_f   = "Fire_C_1997-2006_monthly_"+ model_grid+".nc"
   100  fm      = addfile (dir_f+fil_f,"r")
   101  data_ob = fm->FIRE_C(0:7,:,:,:)
   102 
   103  delete (fm)
   104 
   105  ob_name = "GFEDv2"
   106 
   107 ; Units for these variables are: gC/m2/month
   108 
   109  data_ob@units = "gC/m2/month"
   110 
   111 ;-------------------------------------------------------------
   112 ; html table1 data
   113 
   114 ; column (not including header column)
   115 
   116   col_head  = (/"Observed Fire_Flux (PgC/yr)" \
   117                ,"Model Fire_Flux (PgC/yr)" \
   118                ,"Correlation Coefficient" \
   119                ,"Ratio model/observed" \
   120                ,"M_score" \
   121                ,"Timeseries plot" \
   122                /)
   123 
   124   ncol = dimsizes(col_head)
   125 
   126 ; row (not including header row)                   
   127 
   128 ; using model biome class:  
   129   row_head  = (/"Not Vegetated" \
   130                ,"Needleleaf Evergreen Temperate Tree" \
   131                ,"Needleleaf Evergreen Boreal Tree" \
   132 ;              ,"Needleleaf Deciduous Boreal Tree" \
   133                ,"Broadleaf Evergreen Tropical Tree" \
   134                ,"Broadleaf Evergreen Temperate Tree" \
   135                ,"Broadleaf Deciduous Tropical Tree" \
   136                ,"Broadleaf Deciduous Temperate Tree" \
   137 ;              ,"Broadleaf Deciduous Boreal Tree" \
   138 ;              ,"Broadleaf Evergreen Shrub" \
   139                ,"Broadleaf Deciduous Temperate Shrub" \
   140                ,"Broadleaf Deciduous Boreal Shrub" \
   141                ,"C3 Arctic Grass" \
   142                ,"C3 Non-Arctic Grass" \
   143                ,"C4 Grass" \
   144                ,"Corn" \
   145 ;              ,"Wheat" \                      
   146                ,"All Biomes" \                
   147                /)  
   148   nrow = dimsizes(row_head)                  
   149 
   150 ; arrays to be passed to table. 
   151   text = new ((/nrow, ncol/),string ) 
   152 
   153 ;*****************************************************************
   154 ; (A) get time-mean
   155 ;*****************************************************************
   156   
   157   x          = dim_avg_Wrap(data_mod(lat|:,lon|:,month|:,year|:))
   158   data_mod_m = dim_avg_Wrap(       x(lat|:,lon|:,month|:))
   159   delete (x)
   160 
   161   x          = dim_avg_Wrap( data_ob(lat|:,lon|:,month|:,year|:))
   162   data_ob_m  = dim_avg_Wrap(       x(lat|:,lon|:,month|:))
   163   delete (x)
   164 
   165 ;----------------------------------------------------
   166 ; compute correlation coef: space
   167 
   168   landmask_1d = ndtooned(landmask)
   169   data_mod_1d = ndtooned(data_mod_m)
   170   data_ob_1d  = ndtooned(data_ob_m )
   171   area_1d     = ndtooned(area)
   172   landfrac_1d = ndtooned(landfrac)
   173 
   174   good = ind(landmask_1d .gt. 0.)
   175 
   176   global_mod = sum(data_mod_1d(good)*area_1d(good)) * 1.e-15 * 12.
   177   global_ob  = sum(data_ob_1d(good) *area_1d(good)) * 1.e-15 * 12.
   178 ; print (global_mod)
   179 ; print (global_ob)  
   180 
   181   global_area= sum(area_1d)
   182   global_land= sum(area_1d(good))
   183 ; print (global_area)
   184 ; print (global_land)
   185 
   186   cc_space = esccr(data_mod_1d(good)*landfrac_1d(good),data_ob_1d(good)*landfrac_1d(good),0)
   187 
   188   delete (landmask_1d)
   189   delete (landfrac_1d)
   190 ; delete (area_1d)
   191   delete (data_mod_1d)
   192   delete (data_ob_1d)
   193   delete (good)
   194 
   195 ;----------------------------------------------------
   196 ; compute M_global
   197 
   198   score_max = 2.5
   199 
   200   Mscore1 = cc_space * cc_space * score_max
   201 
   202   M_global = sprintf("%.2f", Mscore1)
   203  
   204 ;----------------------------------------------------
   205 ; global res
   206 
   207   resg                      = True             ; Use plot options
   208   resg@cnFillOn             = True             ; Turn on color fill
   209   resg@gsnSpreadColors      = True             ; use full colormap
   210   resg@cnLinesOn            = False            ; Turn off contourn lines
   211   resg@mpFillOn             = False            ; Turn off map fill
   212   resg@cnLevelSelectionMode = "ManualLevels"   ; Manual contour invtervals
   213       
   214 ;----------------------------------------------------
   215 ; global contour: model vs ob
   216 
   217   plot_name = "global_model_vs_ob"
   218 
   219   wks = gsn_open_wks (plot_type,plot_name)   
   220   gsn_define_colormap(wks,"gui_default")     
   221 
   222   plot=new(3,graphic)                        ; create graphic array
   223 
   224   resg@gsnFrame             = False          ; Do not draw plot 
   225   resg@gsnDraw              = False          ; Do not advance frame
   226 
   227 ;----------------------
   228 ; plot correlation coef
   229 
   230   gRes               = True
   231   gRes@txFontHeightF = 0.02
   232   gRes@txAngleF      = 90
   233 
   234   correlation_text = "(correlation coef = "+sprintf("%.2f", cc_space)+")"
   235 
   236   gsn_text_ndc(wks,correlation_text,0.20,0.50,gRes)
   237 
   238 ;-----------------------  
   239 ; plot ob 
   240 ; change from gC/m2/month to gC/m2/yr
   241   month_to_year = 12. 
   242  
   243   data_ob_m@units  = "gC/m2/yr"
   244   data_mod_m@units = "gC/m2/yr"
   245 
   246   data_ob_m = data_ob_m * month_to_year
   247   data_ob_m = where(landmask .gt. 0., data_ob_m, data_ob_m@_FillValue)
   248 
   249   title     = ob_name
   250   resg@tiMainString  = title
   251 
   252   resg@cnMinLevelValF       = 10.             
   253   resg@cnMaxLevelValF       = 100.             
   254   resg@cnLevelSpacingF      = 10.
   255 
   256   plot(0) = gsn_csm_contour_map_ce(wks,data_ob_m,resg)       
   257 
   258 ;-----------------------
   259 ; plot model
   260 
   261   data_mod_m = data_mod_m * month_to_year
   262 
   263   data_mod_m = where(landmask .gt. 0., data_mod_m, data_mod_m@_FillValue)
   264 
   265   title     = "Model "+ model_name
   266   resg@tiMainString  = title
   267 
   268   resg@cnMinLevelValF       = 10.             
   269   resg@cnMaxLevelValF       = 100.             
   270   resg@cnLevelSpacingF      = 10.
   271 
   272   plot(1) = gsn_csm_contour_map_ce(wks,data_mod_m,resg) 
   273 
   274 ;-----------------------
   275 ; plot model-ob
   276 
   277   resg@cnMinLevelValF  = -80.           
   278   resg@cnMaxLevelValF  =  20.            
   279   resg@cnLevelSpacingF =  10.
   280 
   281   zz = data_ob_m
   282   zz = data_mod_m - data_ob_m
   283   title = "Model_"+model_name+" - Observed"
   284   resg@tiMainString    = title
   285 
   286   plot(2) = gsn_csm_contour_map_ce(wks,zz,resg) 
   287 
   288 ; plot panel
   289 
   290   pres                            = True        ; panel plot mods desired
   291   pres@gsnMaximize                = True        ; fill the page
   292 
   293   gsn_panel(wks,plot,(/3,1/),pres)              ; create panel plot
   294 
   295   delete (wks)
   296   delete (plot)
   297 
   298   system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
   299         "rm "+plot_name+"."+plot_type)
   300 
   301   delete (data_ob_m)
   302   delete (data_mod_m)
   303   delete (zz)
   304 
   305   resg@gsnFrame             = True          ; Do advance frame 
   306   resg@gsnDraw              = True          ; Do draw plot
   307 
   308 ;*******************************************************************
   309 ; (B) Time series : per biome
   310 ;*******************************************************************
   311 
   312  data_n = 2
   313 
   314  dsizes = dimsizes(data_mod)
   315  nyear  = dsizes(0)
   316  nmonth = dsizes(1)
   317  ntime  = nyear * nmonth
   318 
   319  year_start = 1997
   320  year_end   = 2004
   321                 
   322 ;-------------------------------------------
   323 ; Calculate "nice" bins for binning the data
   324 
   325 ; using model biome class
   326   nclass = nclass_mod
   327 
   328   range  = fspan(0,nclass,nclass+1)
   329 
   330 ; Use this range information to grab all the values in a
   331 ; particular range, and then take an average.
   332 
   333   nx = dimsizes(range) - 1
   334 
   335 ;-------------------------------------------
   336 ; put data into bins
   337 
   338 ; using observed biome class
   339 ; base  = ndtooned(classob)
   340 ; using model biome class
   341   base  = ndtooned(classmod)
   342 
   343 ; output
   344 
   345   area_bin = new((/nx/),float)
   346   yvalues  = new((/ntime,data_n,nx/),float)
   347 
   348 ; Loop through each range, using base.
   349 
   350   do i=0,nx-1
   351 
   352      if (i.ne.(nx-1)) then
   353         idx = ind((base.ge.range(i)).and.(base.lt.range(i+1)))
   354      else
   355         idx = ind(base.ge.range(i))
   356      end if
   357 ;---------------------
   358 ;    for area  
   359 
   360      if (.not.any(ismissing(idx))) then 
   361         area_bin(i) = sum(area_1d(idx))
   362      else
   363         area_bin(i) = area_bin@_FillValue
   364      end if
   365 
   366 ;#############################################################
   367 ; using model biome class:
   368 ;     set the following 4 classes to _FillValue:
   369 ;     (3)Needleleaf Deciduous Boreal Tree,
   370 ;     (8)Broadleaf Deciduous Boreal Tree,
   371 ;     (9)Broadleaf Evergreen Shrub,
   372 ;     (16)Wheat
   373 
   374      if (i.eq.3 .or. i.eq.8 .or. i.eq.9 .or. i.eq.16) then
   375         area_bin(i) = area_bin@_FillValue
   376      end if
   377 ;#############################################################  
   378 
   379 ;---------------------
   380 ; for data_mod and data_ob
   381 
   382   do n = 0,data_n-1
   383 
   384      t = -1
   385      do m = 0,nyear-1
   386      do k = 0,nmonth-1
   387     
   388         t = t + 1 
   389 
   390         if (n.eq.0) then
   391            data = ndtooned(data_ob(m,k,:,:))
   392         end if
   393 
   394         if (n.eq.1) then
   395            data = ndtooned(data_mod(m,k,:,:))
   396         end if
   397 
   398 ;       Calculate average
   399  
   400         if (.not.any(ismissing(idx))) then 
   401            yvalues(t,n,i) = sum(data(idx)*area_1d(idx))
   402         else
   403            yvalues(t,n,i) = yvalues@_FillValue
   404         end if
   405 
   406 ;#############################################################
   407 ; using model biome class:
   408 ;     set the following 4 classes to _FillValue:
   409 ;     (3)Needleleaf Deciduous Boreal Tree,
   410 ;     (8)Broadleaf Deciduous Boreal Tree,
   411 ;     (9)Broadleaf Evergreen Shrub,
   412 ;     (16)Wheat
   413 
   414         if (i.eq.3 .or. i.eq.8 .or. i.eq.9 .or. i.eq.16) then
   415            yvalues(t,n,i) = yvalues@_FillValue
   416         end if
   417 ;#############################################################  
   418 
   419      end do
   420      end do
   421 
   422      delete(data)
   423   end do 
   424 
   425     delete(idx)
   426   end do
   427 
   428   delete (base)
   429   delete (data_mod)
   430   delete (data_ob)
   431 
   432   global_bin = sum(area_bin)
   433 ; print (global_bin)
   434 
   435 ;----------------------------------------------------------------
   436 ; get area_good
   437 
   438   good = ind(.not.ismissing(area_bin))
   439 
   440   area_g = area_bin(good)  
   441 
   442   n_biome = dimsizes(good)
   443 
   444   global_good = sum(area_g)
   445 ; print (global_good)
   446 
   447 ;----------------------------------------------------------------
   448 ; data for tseries plot
   449 
   450   yvalues_g = new((/ntime,data_n,n_biome/),float)
   451 
   452   yvalues_g@units = "TgC/month"
   453 
   454 ; change unit to Tg C/month
   455 ; change unit from g to Tg (Tera gram)
   456   factor_unit = 1.e-12
   457 
   458   yvalues_g = yvalues(:,:,good) * factor_unit
   459 
   460   delete (good)
   461 
   462 ;-------------------------------------------------------------------
   463 ; general settings for line plot
   464 
   465   res                   = True               
   466   res@xyDashPatterns    = (/0,0/)          ; make lines solid
   467   res@xyLineThicknesses = (/2.0,2.0/)      ; make lines thicker
   468   res@xyLineColors      = (/"blue","red"/) ; line color
   469 
   470   res@trXMinF   = year_start
   471   res@trXMaxF   = year_end + 1
   472 
   473   res@vpHeightF = 0.4                 ; change aspect ratio of plot
   474 ; res@vpWidthF  = 0.8
   475   res@vpWidthF  = 0.75   
   476 
   477   res@tiMainFontHeightF = 0.025       ; size of title 
   478 
   479   res@tmXBFormat  = "f"               ; not to add trailing zeros
   480 
   481 ; res@gsnMaximize = True
   482 
   483 ;----------------------------------------------
   484 ; Add a boxed legend using the simple method
   485 
   486   res@pmLegendDisplayMode    = "Always"
   487 ; res@pmLegendWidthF         = 0.1
   488   res@pmLegendWidthF         = 0.08
   489   res@pmLegendHeightF        = 0.06
   490   res@pmLegendOrthogonalPosF = -1.17
   491 ; res@pmLegendOrthogonalPosF = -1.00  ;(downward)
   492 ; res@pmLegendOrthogonalPosF = -0.30  ;(downward)
   493 
   494 ; res@pmLegendParallelPosF   =  0.18
   495   res@pmLegendParallelPosF   =  0.23  ;(rightward)
   496   res@pmLegendParallelPosF   =  0.73  ;(rightward)
   497   res@pmLegendParallelPosF   =  0.83  ;(rightward)
   498 
   499 ; res@lgPerimOn             = False
   500   res@lgLabelFontHeightF     = 0.015
   501   res@xyExplicitLegendLabels = (/"observed",model_name/)
   502 
   503 ;*******************************************************************
   504 ; (A) time series plot: monthly ( 2 lines per plot)
   505 ;*******************************************************************
   506 
   507 ; x-axis in time series plot
   508 
   509   timeI = new((/ntime/),integer)
   510   timeF = new((/ntime/),float)
   511   timeI = ispan(1,ntime,1)
   512   timeF = year_start + (timeI-1)/12.
   513   timeF@long_name = "year" 
   514 
   515   plot_data = new((/2,ntime/),float)
   516   plot_data@long_name = "TgC/month"
   517 
   518 ;----------------------------------------------
   519 ; time series plot : per biome
   520  
   521   do m = 0, n_biome-1
   522 
   523      plot_name = "monthly_biome_"+ m
   524 
   525      wks = gsn_open_wks (plot_type,plot_name)   
   526 
   527      title = "Fire : "+ row_head(m)
   528      res@tiMainString = title
   529 
   530      plot_data(0,:) = yvalues_g(:,0,m)
   531      plot_data(1,:) = yvalues_g(:,1,m)
   532                                   
   533      plot = gsn_csm_xy(wks,timeF,plot_data,res)
   534 
   535      delete (wks)
   536      delete (plot)
   537 
   538      system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
   539             "rm "+plot_name+"."+plot_type)
   540   end do
   541 
   542 ;------------------------------------------
   543 ; data for table : per biome
   544 
   545 ; unit change from TgC/month to PgC/month
   546   unit_factor = 1.e-3
   547 
   548   score_max = 2.5
   549 
   550   tmp_ob    = new((/ntime/),float)
   551   tmp_mod   = new((/ntime/),float)
   552 
   553   total_ob  = new((/n_biome/),float)
   554   total_mod = new((/n_biome/),float)
   555   Mscore2   = new((/n_biome/),float)
   556 
   557   do m = 0, n_biome-1
   558 
   559      tmp_ob  = yvalues_g(:,0,m) 
   560      tmp_mod = yvalues_g(:,1,m) 
   561 
   562      total_ob(m)  = avg(month_to_annual(tmp_ob, 0)) * unit_factor 
   563      total_mod(m) = avg(month_to_annual(tmp_mod,0)) * unit_factor
   564      
   565      cc_time = esccr(tmp_mod,tmp_ob,0)
   566 
   567      ratio = total_mod(m)/total_ob(m)
   568 
   569      good = ind(tmp_ob .ne. 0. .and. tmp_mod .ne. 0.)
   570 
   571      bias = sum( abs( tmp_mod(good)-tmp_ob(good) )/( abs(tmp_mod(good))+abs(tmp_ob(good)) ) )
   572      Mscore2(m) = (1.- (bias/dimsizes(good)))*score_max
   573 
   574      delete (good)
   575      
   576      text(m,0) = sprintf("%.2f",total_ob(m))
   577      text(m,1) = sprintf("%.2f",total_mod(m))
   578      text(m,2) = sprintf("%.2f",cc_time)
   579      text(m,3) = sprintf("%.2f",ratio)
   580      text(m,4) = sprintf("%.2f",Mscore2(m))
   581      text(m,5) = "<a href=./monthly_biome_"+m+".png>model_vs_ob</a>" 
   582   end do
   583  
   584   delete (tmp_ob)
   585   delete (tmp_mod)
   586 
   587 ;--------------------------------------------
   588 ; time series plot: all biome
   589 
   590      plot_name = "monthly_global"
   591 
   592      wks = gsn_open_wks (plot_type,plot_name)   
   593 
   594      title = "Fire : "+ row_head(n_biome)
   595      res@tiMainString = title
   596 
   597      do k = 0,ntime-1
   598         plot_data(0,k) = sum(yvalues_g(k,0,:))
   599         plot_data(1,k) = sum(yvalues_g(k,1,:))
   600      end do
   601                                   
   602      plot = gsn_csm_xy(wks,timeF,plot_data,res)
   603 
   604      delete (wks)
   605      delete (plot)
   606 
   607      system("convert "+plot_name+"."+plot_type+" "+plot_name+"."+plot_type_new+";"+ \
   608             "rm "+plot_name+"."+plot_type)
   609 
   610 ;------------------------------------------
   611 ; data for table : global
   612 
   613   score_max = 2.5
   614 
   615   tmp_ob  = ndtooned(yvalues_g(:,0,:))
   616   tmp_mod = ndtooned(yvalues_g(:,1,:))
   617 
   618   cc_time = esccr(tmp_mod,tmp_ob,0)
   619 
   620   ratio = sum(total_mod)/sum(total_ob) 
   621 
   622   good = ind(tmp_ob .ne. 0. .and. tmp_mod .ne. 0.)
   623 
   624   bias = sum( abs( tmp_mod(good)-tmp_ob(good) )/( abs(tmp_mod(good))+abs(tmp_ob(good)) ) )
   625   Mscore3 = (1.- (bias/dimsizes(good)))*score_max
   626 
   627 ; print (Mscore3)
   628 
   629   delete (good) 
   630 
   631   text(nrow-1,0) = sprintf("%.2f",sum(total_ob))
   632   text(nrow-1,1) = sprintf("%.2f",sum(total_mod))
   633   text(nrow-1,2) = sprintf("%.2f",cc_time)
   634   text(nrow-1,3) = sprintf("%.2f",ratio)
   635 ; text(nrow-1,4) = sprintf("%.2f",avg(Mscore2))
   636   text(nrow-1,4) = sprintf("%.2f",    Mscore3)
   637   text(nrow-1,5) = "<a href=./monthly_global.png>model_vs_ob</a>"
   638 
   639 ;**************************************************
   640 ; create html table
   641 ;**************************************************
   642 
   643   header_text = "<H1>Fire Emissions from GFEDv2 (1997-2004) vs "+model_name+"</H1>" 
   644 
   645   header = (/"<HTML>" \
   646             ,"<HEAD>" \
   647             ,"<TITLE>CLAMP metrics</TITLE>" \
   648             ,"</HEAD>" \
   649             ,header_text \
   650             /) 
   651   footer = "</HTML>"
   652 
   653   table_header = (/ \
   654         "<table border=1 cellspacing=0 cellpadding=3 width=60%>" \
   655        ,"<tr>" \
   656        ,"   <th bgcolor=DDDDDD >Biome Type</th>" \
   657        ,"   <th bgcolor=DDDDDD >"+col_head(0)+"</th>" \
   658        ,"   <th bgcolor=DDDDDD >"+col_head(1)+"</th>" \
   659        ,"   <th bgcolor=DDDDDD >"+col_head(2)+"</th>" \
   660        ,"   <th bgcolor=DDDDDD >"+col_head(3)+"</th>" \
   661        ,"   <th bgcolor=DDDDDD >"+col_head(4)+"</th>" \
   662        ,"   <th bgcolor=DDDDDD >"+col_head(5)+"</th>" \
   663        ,"</tr>" \
   664        /)
   665   table_footer = "</table>"
   666   row_header = "<tr>"
   667   row_footer = "</tr>"
   668 
   669   lines = new(50000,string)
   670   nline = 0
   671 
   672   set_line(lines,nline,header)
   673   set_line(lines,nline,table_header)
   674 ;-----------------------------------------------
   675 ;row of table
   676 
   677   do n = 0,nrow-1
   678      set_line(lines,nline,row_header)
   679 
   680      txt0  = row_head(n)
   681      txt1  = text(n,0)
   682      txt2  = text(n,1)
   683      txt3  = text(n,2)
   684      txt4  = text(n,3)
   685      txt5  = text(n,4)
   686      txt6  = text(n,5)
   687 
   688      set_line(lines,nline,"<th>"+txt0+"</th>")
   689      set_line(lines,nline,"<th>"+txt1+"</th>")
   690      set_line(lines,nline,"<th>"+txt2+"</th>")
   691      set_line(lines,nline,"<th>"+txt3+"</th>")
   692      set_line(lines,nline,"<th>"+txt4+"</th>")
   693      set_line(lines,nline,"<th>"+txt5+"</th>")
   694      set_line(lines,nline,"<th>"+txt6+"</th>")
   695 
   696      set_line(lines,nline,row_footer)
   697   end do
   698 ;-----------------------------------------------
   699   set_line(lines,nline,table_footer)
   700   set_line(lines,nline,footer) 
   701 
   702 ; Now write to an HTML file.
   703 
   704   output_html = "table_fire.html"
   705 
   706   idx = ind(.not.ismissing(lines))
   707   if(.not.any(ismissing(idx))) then
   708     asciiwrite(output_html,lines(idx))
   709   else
   710    print ("error?")
   711   end if
   712 
   713   delete (idx)
   714 
   715 ;**************************************************************************************
   716 ; update score
   717 ;**************************************************************************************
   718 
   719   M_all  = Mscore1 + Mscore3
   720   M_fire = sprintf("%.2f", M_all) 
   721 
   722   if (isvar("compare")) then
   723      system("sed -e '1,/M_fire/s/M_fire/"+M_fire+"/' "+html_name2+" > "+html_new2+";"+ \
   724             "mv -f "+html_new2+" "+html_name2)
   725   end if
   726 
   727   system("sed s#M_fire#"+M_fire+"# "+html_name+" > "+html_new+";"+ \
   728          "mv -f "+html_new+" "+html_name)
   729 
   730 ;***************************************************************************
   731 ; get total score and write to file
   732 ;***************************************************************************
   733 
   734   asciiwrite("M_save.fire", M_fire)
   735 
   736   delete (M_fire)
   737 
   738 ;***************************************************************************
   739 ; output plot and html
   740 ;***************************************************************************
   741   output_dir = model_name+"/fire"
   742 
   743   system("mv *.png *.html " + output_dir) 
   744 ;***************************************************************************
   745 
   746 end
   747