        program wimage
C       very simple program to create a FITS file

        integer iunit,status,bitpix,naxis,naxes(99),pcount,gcount
        integer group,fpixel,nelem,i
        integer ivalue(100)
        logical simple,extend
        character*30 errtxt

        status=0
        iunit=15
C       open the new FITS file
        call ftinit(iunit,'image.fit',2880,status)

        simple=.true.
        bitpix=32
        naxis=2
        naxes(1)=10
        naxes(2)=2
        pcount=0
        gcount=1
        extend=.true.

C       write the required primary array keywords
        call ftpprh(iunit,simple,bitpix,naxis,naxes,pcount,gcount,
     &       extend,status)

C	write an additional integer keyword and a comment and history keyword:
        call ftpkyj(iunit,'jkey',-35,'The value is -35',status)
        call ftpcom(iunit,'This was written by FTPCOM',status)
        call ftphis(iunit,'This was written by FTPHIS',status)

        group=1
        fpixel=1
        nelem=20

C       set the values for the primary array
        do 14 i=1,nelem
                ivalue(i)=i+64
14      continue

C	define primary array structure
        call ftpdef(iunit,bitpix,naxis,naxes,pcount,gcount,status)

C	write the primary array of data
        call ftpprj(iunit,group,fpixel,nelem,ivalue,status)

C	now create an image extension, exactly like the primary array
	call ftcrhd(iunit,status)
        call ftpprh(iunit,simple,bitpix,naxis,naxes,pcount,gcount,
     &       extend,status)

C	write an additional integer keyword and a comment and history keyword:
        call ftpkyj(iunit,'jkey',-35,'The value is -35',status)
        call ftpcom(iunit,'This was written by FTPCOM',status)
        call ftphis(iunit,'This was written by FTPHIS',status)

C       define array structure and write the data
        call ftpdef(iunit,bitpix,naxis,naxes,pcount,gcount,status)
        call ftpprj(iunit,group,fpixel,nelem,ivalue,status)

        call ftclos(iunit,status)

        if (status .le. 0)then
                print *,'*** Program completed successfully ***'
        else
           call ftgerr(status,errtxt)
           print *,'*** ERROR - program did not run successfully ***'
           print *,'status =',status,': ',errtxt
        end if
        end
