c shade.for
c
c uses output of normal.for to compute an illuminated standard grid
c
c Jeff Phillips 8 Aug 91
      dimension v1(3000),v2(3000),v3(3000)
      dimension id(14),pgm(2)
      character*50 ifile
      data ddval,dval/1.e37,1.e38/
      print *,'Enter n1 file name: '
      read(5,100) ifile
  100 format(a)
      open(10,file=ifile,form='unformatted',status='old')
      print *,'Enter n2 file name: '
      read(5,100) ifile
      open(11,file=ifile,form='unformatted',status='old')
      print *,'Enter n3 file name: '
      read(5,100) ifile
      open(12,file=ifile,form='unformatted',status='old')
      print *,'Enter output file name: '
      read(5,100) ifile
      open(13,file=ifile,form='unformatted',status='unknown')
      print *,'Enter sun altitude and azimuth (degrees): '
      read (5,*) alt,azi
      conv=3.1415927/180.
      alt=alt*conv
      azi=azi*conv
      sl=sin(alt)
      cl=cos(alt)
      sz=sin(azi)
      cz=cos(azi)
      w2=cl*cz
      w1=cl*sz
      w3=sl
      read(10) id,pgm,ncol,nrow,nz,xo,dx,yo,dy
      write(13) id,pgm,ncol,nrow,nz,xo,dx,yo,dy
      read(11) id
      read(12) id
      do 20 j=1,nrow
      read(10) dlt,(v1(i),i=1,ncol)
      read(11) dlt,(v2(i),i=1,ncol)
      read(12) dlt,(v3(i),i=1,ncol)
      do 10 i=1,ncol
      if(v1(i).gt.ddval.or.v2(i).gt.ddval.or.v3(i).gt.ddval) go to 9
c      if(v1(i).eq.0.0.and.v2(i).eq.0.0.and.v3(i).eq.0.0) go to 9
      v1(i)=v1(i)*w1+v2(i)*w2+v3(i)*w3
      go to 10
    9 v1(i)=dval
   10 continue
      write(13) dlt,(v1(i),i=1,ncol)
   20 continue
      stop
      end
