       program test_read_dataset
c
c  This program a test code to read the dataset described in the paper.
c  While the code was tested and runs on many LINUX platform, there is
c  no warranty explicit or implict that goes with its use.  It is provided 
c  free and and to be used 'as is'.  Users can modifiy as pleased.
c  We do not garranty the validity of outputs obtained from this code.
c
c  Definitions of parameters
c  nr         = number of rows
c  nf         = number of columns
c  nperiod    = number of periods in the biophysical dataset
c  nclass     = number of land cover classes
c  itest      = row nymber of the point to be tested (pinted values)
c  jtest      = column nymber of the point to be tested (pinted values)
c
       implicit none
c
      integer ip,nperiod,nr,nc,nclass,i,j,nf,itest,jtest
      integer l,m
c
       parameter (nr=490,nc=1160,nperiod = 46,nclass=11)
c
c  input : time dependent biophysical data.
c  in the order in whihc they are written/read : FPAR, LAI, Greeness,
c  roghness length, zero-plane displacement, boundary layer resistance,
c  ground-canopy resistance.
c
      real  aparc (nr,nc),zlt (nr,nc),green (nr,nc),z0d    (nr,nc)
      real    dd  (nr,nc),cc1 (nr,nc),cc2   (nr,nc) 
c
c  Define the vegetation type and fraction variables
c
      real    veg  (nr,nc),frac (nr,nc)
c
c  Define file names
c
      character*20 file1(nclass),file2(nclass),file3(nperiod)

      character*30 stng
c
c  Define logical for printing
c
      logical first,test_map_var
c
c  input data
c
      data file1/
     &'LC1_types.data','LC2_types.data',
     &'LC3_types.data','LC4_types.data',
     &'LC5_types.data','LC6_types.data',
     &'LC7_types.data','LC8_types.data',
     &'LC9_types.data','LC11_types.data',
     &'LC12_types.data'/
c
      data file2/
     &'LC1_fractions.data','LC2_fractions.data',
     &'LC3_fractions.data','LC4_fractions.data',
     &'LC5_fractions.data','LC6_fractions.data',
     &'LC7_fractions.data','LC8_fractions.data',
     &'LC9_fractions.data','LC11_fractions.data',
     &'LC12_fractions.data'/
c
       data file3/
     &'biophys1 ','biophys2 ','biophys3 ','biophys4 ','biophys5 ',
     &'biophys6 ','biophys7 ','biophys8 ','biophys9 ','biophys10',
     &'biophys11','biophys12','biophys13','biophys14','biophys15',
     &'biophys16','biophys17','biophys18','biophys19','biophys20',
     &'biophys21','biophys22','biophys23','biophys24','biophys25',
     &'biophys26','biophys27','biophys28','biophys29','biophys30',
     &'biophys31','biophys32','biophys33','biophys34','biophys35',
     &'biophys36','biophys37','biophys38','biophys39','biophys40',
     &'biophys41','biophys42','biophys43','biophys44','biophys45',
     &'biophys46'/
c
c     Set logical flags for testing data       
c
       test_map_var =.true.  
c 
       itest = 208
       jtest = 992   
c
c  Open files per vegetation class
c
         first =.true.
c
      do 100 nf = 1, nclass
c
      if (nf.eq.1) then
      open (92,file=
     &'DATA_OUT/ASC/LC1/'//file1(nf),status='old',form='formatted')
      open (93,file=
     &'DATA_OUT/ASC/LC1/'//file2(nf),status='old',form='formatted')
      endif
c
      if (nf.eq.2) then
      open (92,file=
     &'DATA_OUT/ASC/LC2/'//file1(nf),status='old',form='formatted')
      open (93,file=
     &'DATA_OUT/ASC/LC2/'//file2(nf),status='old',form='formatted')
      endif
c
      if (nf.eq.3) then
      open (92,file=
     &'DATA_OUT/ASC/LC3/'//file1(nf),status='old',form='formatted')
      open (93,file=
     &'DATA_OUT/ASC/LC3/'//file2(nf),status='old',form='formatted')
      endif
c
      if (nf.eq.4) then
      open (92,file=
     &'DATA_OUT/ASC/LC4/'//file1(nf),status='old',form='formatted')
      open (93,file=
     &'DATA_OUT/ASC/LC4/'//file2(nf),status='old',form='formatted')
      endif
c
      if (nf.eq.5) then
      open (92,file=
     &'DATA_OUT/ASC/LC5/'//file1(nf),status='old',form='formatted')
      open (93,file=
     &'DATA_OUT/ASC/LC5/'//file2(nf),status='old',form='formatted')
      endif
c
      if (nf.eq.6) then
      open (92,file=
     &'DATA_OUT/ASC/LC6/'//file1(nf),status='old',form='formatted')
      open (93,file=
     &'DATA_OUT/ASC/LC6/'//file2(nf),status='old',form='formatted')
      endif
c
      if (nf.eq.7) then
      open (92,file=
     &'DATA_OUT/ASC/LC7/'//file1(nf),status='old',form='formatted')
      open (93,file=
     &'DATA_OUT/ASC/LC7/'//file2(nf),status='old',form='formatted')
      endif
c
      if (nf.eq.8) then
      open (92,file=
     &'DATA_OUT/ASC/LC8/'//file1(nf),status='old',form='formatted')
      open (93,file=
     &'DATA_OUT/ASC/LC8/'//file2(nf),status='old',form='formatted')
      endif
c
      if (nf.eq.9) then
      open (92,file=
     &'DATA_OUT/ASC/LC9/'//file1(nf),status='old',form='formatted')
      open (93,file=
     &'DATA_OUT/ASC/LC9/'//file2(nf),status='old',form='formatted')
      endif
c
      if (nf.eq.10) then
      open (92,file=
     &'DATA_OUT/ASC/LC11/'//file1(nf),status='old',form='formatted')
      open (93,file=
     &'DATA_OUT/ASC/LC11/'//file2(nf),status='old',form='formatted')
      endif
c
      if (nf.eq.11) then
      open (92,file=
     &'DATA_OUT/ASC/LC12/'//file1(nf),status='old',form='formatted')
      open (93,file=
     &'DATA_OUT/ASC/LC12/'//file2(nf),status='old',form='formatted')
      endif
c
c     Read vegetation and fraction data from SOUTH to NORTH
c
      read(92,900)   ((veg   (i,j),j=1,nc),i=1,nr)
      read(93,900)   ((frac  (i,j),j=1,nc),i=1,nr)
c
c    Detemine the minimum and maximum values of the vegetation type and fractions
c    remove the comment line to display min-max values of fields.
c
      stng=' vegtype  '
c      call minmax1   (veg ,nr,nc,veg,stng)                                   
      stng=' fraction '
c      call minmax1   (frac,nr,nc,veg,stng)
c
c Read tape 89 for all time period
c
c
      do 200 ip = 1, nperiod          
c	  
c  Open biophysical files containing all variables for each period
c
      if (nf.eq.1)open (90,file=
     &'DATA_OUT/ASC/LC1/'//file3(ip),status='old',form='formatted')
      if (nf.eq.2)open (90,file=
     &'DATA_OUT/ASC/LC2/'//file3(ip),status='old',form='formatted')
      if (nf.eq.3)open (90,file=
     &'DATA_OUT/ASC/LC3/'//file3(ip),status='old',form='formatted')
      if (nf.eq.4)open (90,file=
     &'DATA_OUT/ASC/LC4/'//file3(ip),status='old',form='formatted')
      if (nf.eq.5)open (90,file=
     &'DATA_OUT/ASC/LC5/'//file3(ip),status='old',form='formatted')
      if (nf.eq.6)open (90,file=
     &'DATA_OUT/ASC/LC6/'//file3(ip),status='old',form='formatted')
      if (nf.eq.7)open (90,file=
     &'DATA_OUT/ASC/LC7/'//file3(ip),status='old',form='formatted')
      if (nf.eq.8)open (90,file=
     &'DATA_OUT/ASC/LC8/'//file3(ip),status='old',form='formatted')
      if (nf.eq.9)open (90,file=
     &'DATA_OUT/ASC/LC9/'//file3(ip),status='old',form='formatted')
      if (nf.eq.10)open (90,file=
     &'DATA_OUT/ASC/LC11/'//file3(ip),status='old',form='formatted')
      if (nf.eq.11)open (90,file=
     &'DATA_OUT/ASC/LC12/'//file3(ip),status='old',form='formatted')
c
c     Read biophysical data from SOUTH to NORTH
c
900   format (1160(f7.2,1x))    
      read(90,900)   ((aparc (i,j),j=1,nc),i=1,nr)                            
     &,              ((zlt   (i,j),j=1,nc),i=1,nr)                              
     &,              ((green (i,j),j=1,nc),i=1,nr)
     &,              ((z0d   (i,j),j=1,nc),i=1,nr)                              
     &,              ((dd    (i,j),j=1,nc),i=1,nr)                               
     &,              ((cc1   (i,j),j=1,nc),i=1,nr)                              
     &,              ((cc2   (i,j),j=1,nc),i=1,nr)                              
c
      if (test_map_var.and.first) then
c           
      print *, '       '
      print *, ' Test Vegetation, fraction and LAI values for point'
     &, itest,jtest         
	   print *, '       '
	   print *, ' Period   ','  VEGETATION ',' FRACTION   ',' LAI    ' 
	   print *, '       '
	   first=.false.
      endif
c
      if (test_map_var.and.ip.eq.18) then
c
 66   format(1x,i6,4x,f8.2,4x,f8.2,4x,f8.2)
      write(6,66)ip,veg(itest,jtest),frac(itest,jtest)
     &,zlt (itest,jtest)
c       
      endif
c
200    continue
c
100   continue 
      stop 99
       end
c
      subroutine minmax1 (data,l,m,veg,stng)                                   
      real data (l,m),veg(l,m)
      real amin,amax
      character*30 stng
      amax      = -999.0                                                            
      amin      = +999.0                                                          
      do 3250   j = 1, m                                                               
      do 3250   i = 1, l
       if (veg (i,j).ne.-999.0) then 
          if (data(i,j).gt.amax) amax = data(i,j)                                      
          if (data(i,j).lt.amin) amin = data(i,j)
       endif
3250  continue 
  86  format(a20,'  :',2f8.2)
      write(6,86)stng,amin,amax                                                
      return                                                                
      end                                                                       
