       PROGRAMME INSOLATION
       IMPLICIT NONE
       INTEGER NLON,NLAT,I,J,NTIM,NT,NDAY,ND
       REAL XPI,DLON,DLAT
       PARAMETER(NLON=180,NLAT=90,NDAY=365)
       REAL OME,LON(NLON),LAT(NLAT),THM
       REAL INSO(NLAT)

       
       open(24,file=
     C   'insolation.dat',form='unformatted')

       XPI=ACOS(-1.)
       DLAT=XPI/FLOAT(NLAT)
       DLON=2.*XPI/FLOAT(NLON)
       THM=23.5/180.*xpi

       DO J=1,nlat
       lat(j)=-xpi/2.+dlat*(float(J)-0.5)
       enddo
       do i=1,nlon
       lon(i)=float(i-1)*dlon
       enddo

       DO 1 ND=1,NDAY

       OME=2.*XPI*FLOAT(ND-1)/FLOAT(NDAY)

       do j=1,nlat
       inso(j)=0.
       do i=1,nlon
          inso(j)=inso(j)+amax1(0.,
     c            -cos(lat(j))*cos(lon(i))*cos(ome)*cos(thm)
     c            -cos(lat(j))*sin(lon(i))*sin(ome)         
     c            -sin(lat(j))*cos(ome)*sin(thm))
       enddo
c         inso(j)=cos(lat(j))*inso(j)
c         write(34,*)float(nd),lat(j),inso(j)
       enddo

          write(24)(inso(j),j=1,nlat)

1      CONTINUE

       close(24)

       open(23,file=
     C   'insolation.ctl',form='formatted')
       write(23,220)'DSET   ','insolation.dat'
       write(23,220)'TITLE  ','insolation'
       write(23,220)'FORMAT ','sequential'
        write(23,220)'UNDEF  ','1.0E30'
        write(23,221) 'XDEF',1,' LINEAR ',0.,dlon*180./xpi
        write(23,221) 'YDEF',nlat,' LINEAR ',
     c                      lat(1)*180./xpi,
     c                      dlat*180./xpi
        write(23,224) 'ZDEF',1,' LEVELS ',0.
        write(23,222) 'TDEF',nday,' LINEAR','00Z01JAN1979','24hr'
        write(23,223) 'VARS      ',1
        write(23,223) 'insol     ',1,1,'insol     '
        
        write(23,223) 'ENDVARS'
        close(23)


220     format(a7,a20)
211     format(f18.11)
221     format(a4,1x,i3,a8,f9.3,1x,f9.3)
222     format(a4,1x,i3,a8,1x,a12,1x,a6)
223     format(a10,3x,i2,3x,i2,1x,a20)
224     format(a4,1x,i3,a8,f6.0,1x,23(f7.1,1x))


        





       stop
       end       
       
        
