program FITSsize

  implicit none

  integer :: status, bitpix, naxis, naxes(2)
  ! status ... FITS status (0=no error)
  ! naxis .. number of axes in image (we require =2)
  ! naxes .. dimension of the image (2-element array) 

  integer :: blocksize,pcount,gcount
  logical :: extend, simple
  ! required by cFITSIO

  character(len=666) :: name = 'image.fits'
  ! name .. fill with name of the image to open

  status = 0
  call ftopen(25,name,0,blocksize,status)
  call ftghpr(25,2,simple,bitpix,naxis,naxes,pcount,gcount,extend,status)
  call ftclos(25,status)

  if( status == 0 ) then
     write(*,*) 'The image ',trim(name),' has the size:',naxes
  else
     write(*,*) 'The image "',trim(name),'" not found or not accessible.'
  end if

end program FITSsize
