      program read7778
c     to read Zabelin's soil moisture data for winter crops 1987-1988
c
c     W- available soil moisture for WINTER CROPS, S-SPRING CROPS	
c     (1 - layer 1m wint,2 -layer 20cm wint,
c     (3 - layer 1m spr, 4 -layer 20cm spr,
c     (5 - ratio 20cm/1m  winter, 6 - ratio 20cm/1m spring)

***************************************************************************
CcCc	
	dimension x(1:102,1:73,1:6)
	dimension z(100,21)
	dimension f(102,2)
	character*8 name
***************************************************************************	
c      f(lat, long),....	
c	1- lat
c	2-lon

******** INPUT UNITS
c     RUSSIA
	open (unit=11, status='old',form='formatted',
     $file='Data8788/dat.w100')
     	open (unit=12, status='old',form='formatted',
     $file='Data8788/dat.w20')
	open (unit=13, status='old',form='formatted',
     $file='Data8788/dat.s100')
     	open (unit=14, status='old',form='formatted',
     $file='Data8788/dat.s20')
     	open (unit=15, status='old',form='formatted',
     $file='Data8788/dat.wr')
     	open (unit=16, status='old',form='formatted',
     $file='Data8788/dat.sr')
  
***************************************************     
CCC  OUTPUT: WRITE GRADS STATIONS BINARY FILES
	open (30, file='Grads/sta.w100',
     $form='UNFORMATTED',recordtype='STREAM',status='unknown')
   	open (31, file='Grads/sta.w20',
     $form='UNFORMATTED',recordtype='STREAM',status='unknown')  
    	open (32, file='Grads/sta.s100',
     $form='UNFORMATTED',recordtype='STREAM',status='unknown') 
  	open (33, file='Grads/sta.s20',
     $form='UNFORMATTED',recordtype='STREAM',status='unknown')   
     	open (40, file='Grads/sta.wr',
     $form='UNFORMATTED',recordtype='STREAM',status='unknown') 
  	open (41, file='Grads/sta.sr',
     $form='UNFORMATTED',recordtype='STREAM',status='unknown')     
     
     
     
     
CCC   TEMPLATES: WRITE GRADS GRIDDED BINARY FILE
	open (34, file='Grads/grd.w100',
     $  access='direct',form='UNFORMATTED',recl=2100,status='unknown')
 	open (35, file='Grads/grd.w20',
     $  access='direct',form='UNFORMATTED',recl=2100,status='unknown')    
  	open (36, file='Grads/grd.s100',
     $  access='direct',form='UNFORMATTED',recl=2100,status='unknown')   
  	open (37, file='Grads/grd.s20',
     $  access='direct',form='UNFORMATTED',recl=2100,status='unknown')   
     
  	open (38, file='Grads/grd.wr',
     $  access='direct',form='UNFORMATTED',recl=2100,status='unknown')   
  	open (39, file='Grads/grd.sr',
     $  access='direct',form='UNFORMATTED',recl=2100,status='unknown')        
     
     
     
     
***************************************************
********INPUT SOIL MOISTURE DATA

  900 format (6x,f5.2,x,f6.2,4x,73(xf4.1)) 
  903 format (22x,73(xf4.1))
	do 901 n=1,102
	read (11,900) f(n,1),f(n,2),(x(n,m,1),m=1,73)
	read (12,903) (x(n,m,2),m=1,73)
	
	read (13,903) (x(n,m,3),m=1,73)
	read (14,903) (x(n,m,4),m=1,73)
	
        read (15,902) (x(n,m,5),m=1,73)
	read (16,902) (x(n,m,6),m=1,73)

  901 continue 
	
  902 format (22x,73(xf6.3)) 

  
*******************************************************
	
CCC   TO WRITE GRADS STATIONS BINARY FILE
	
	nulat=0.0
	nulon=0.0
	tim=0.0
	nulev=0


CCC    102(station ID; lat; long; time of observ;
CCC    number of levels, flag (1 means that there are surface);
CCC    2years*36decs(winter20, winter100, spring20; spring100))

      do 205 m=1,73
      do 200 n=1,102
      write (name,555) (n+100)

  555 format(i3)
      write (30) name, f(n,1), f(n,2), 0.0,1,1
      write (31) name, f(n,1), f(n,2), 0.0,1,1
      write (32) name, f(n,1), f(n,2), 0.0,1,1     
      write (33) name, f(n,1), f(n,2), 0.0,1,1 
      write (40) name, f(n,1), f(n,2), 0.0,1,1     
      write (41) name, f(n,1), f(n,2), 0.0,1,1       
                 
      write (30) x(n,m,1)
      write (31) x(n,m,2)
      write (32) x(n,m,3)
      write (33) x(n,m,4)
      write (40) x(n,m,5)
      write (41) x(n,m,6)
  200 continue
  
c	TIME GROUP TERMINATOR

      write (30) name,nulat,nulon,tim,nulev,1
      write (31) name,nulat,nulon,tim,nulev,1  
      write (32) name,nulat,nulon,tim,nulev,1    
      write (33) name,nulat,nulon,tim,nulev,1
      write (40) name,nulat,nulon,tim,nulev,1    
      write (41) name,nulat,nulon,tim,nulev,1     
      
  205 continue 
     
CCC   TO WRITE GRADS GRIDDED BINARY FILE
      do 201 i=1,100
      do 201 j=1,21
      z(i,j)=0.0
  201 continue
      irec=0
      do 202 i=1,73
      
      irec=irec+1
      write (34,rec=irec) z
      write (35,rec=irec) z      
      write (36,rec=irec) z      
      write (37,rec=irec) z 
      write (38,rec=irec) z      
      write (39,rec=irec) z       
           
  202 continue

*******************************************************      
      stop
      end
    
