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