      subroutine imain(round_aper,density,focallength,infilename,
     $     himaglim,lomaglim,magtype,outstyle,outfilename,
     $     pixelsize,ascending,sortfield,catmap,error)
C
C Description:
C
C This program is the main routine controlling the interactive mode
C of the asternet program.
C
C Note: The variable 'infilename' is not used in the program but is
C included in the interface so that this routine will be 'plug' 
C compatible with imain, the batch version.
C
C Programming interface:
C
C Name         In/out Type          Structure Meaning
C
C round_aper   in     logical       scalar    TRUE if a round aperture is
C                                             requested
C density      in     real*8        scalar    The number of stars per square
C                                             degree requested
C focallength  in     real*8        scalar    The focal length of the simulated
C                                             telescope requested for an IRAF 
C                                             star list    
C infilename   in     character*64  scalar    The name of the file containing 
C                                             the list of regions to be 
C                                             searched
C himaglim     in     real*8        scalar    The dim magnitude limit
C lomaglim     in     real*8        scalar    The bright magnitude limit
C magtype      in     character*1   scalar    The way magnitude is considered
C                                             'r' is red
C                                             'b' is blue
C                                             'd' is the difference between red
C                                             and blue
C outstyle     in     character*1   scalar    The style of the list for stars
C                                             'A' is ASCII
C                                             'I' is IRAF
C                                             'c' is catalog
C outfilename  in     character*64  scalar    The name of the file containing
C                                             the list of found stars 
C pixelsize    in     real*8        scalar    The focal length of the simulated
C                                             telescope requested for IRAF     
C                                             star list                        
C ascending    in     logical       scalar    TRUE if the found star list is
C                                             to be sorted in ASCENDING order
C                                             FALSE for decending order
C sortfield    in     character*1   scalar    Selects the parameter that
C                                             will order the found stars
C                                             'R' is RA
C                                             'D' is Decl.
C                                             'r' is red
C                                             'b' is blue
C                                             'd' is radius
C catmap       in     character*64  scalar    Name of the catalog map file
C error        in     logical       scalar    TRUE if an error has occured
C
C Errors
C
C This routine will terminate if any subroutines return with an error.
C
C Subroutines accessed:
C
C prompt_read_user
C err_msg
C find_stars
C make_ascii_list
C make_cat_list
C make_iraf_list
C
      implicit none
      include 'std_io.for'
      include 'include_.for'
      real*8 density,focallength,himaglim,lomaglim,pixelsize,ra,
     $     spd,rahalf,spdhalf,radius
      logical error,round_aper,ascending,done
      integer list_length,region_count,list_ra,list_dec,list_mag
      character*64 infilename,outfilename,catmap
      character*1 magtype,outstyle,sortfield
      dimension list_ra(maxlist),list_dec(maxlist),list_mag(maxlist)
      done=.false.
      region_count=0
      infilename=' '
      do while (.not. done)
         call prompt_read_user(round_aper,ra,spd,rahalf,
     $        spdhalf,radius,error)
         if (error) goto 400
         if (round_aper) then
            if (radius .eq. 0.0d0) then
               done=.true.
            end if
         else
            if (rahalf .eq. 0.0d0) then
               done=.true.
            end if
         end if
         if (.not. done) then
            region_count=region_count+1
            if (round_aper) then
               rahalf=radius
               spdhalf=radius
            end if
            call find_stars(ra,spd,rahalf,spdhalf,
     $           lomaglim,himaglim,magtype,density,
     $           list_ra,list_dec,list_mag,list_length,catmap,error)
            if (error) goto 400
            if (outstyle .eq. 'a') then
               call make_ascii_list(list_ra,list_dec,list_mag,
     $              list_length,spd,ra,round_aper,focallength,
     $              pixelsize,ascending,sortfield,outfilename,
     $              radius,region_count,rahalf,spdhalf,error)
               if (error) goto 400
            elseif (outstyle .eq. 'i') then
               call make_iraf_list(list_ra,list_dec,list_mag,
     $              list_length,spd,ra,round_aper,focallength,
     $              pixelsize,ascending,sortfield,outfilename,
     $              radius,region_count,rahalf,spdhalf,error)
               if (error) goto 400
            elseif (outstyle .eq. 'c') then
               call make_cat_list(list_ra,list_dec,list_mag,
     $              list_length,spd,ra,round_aper,focallength,
     $              pixelsize,ascending,sortfield,outfilename,
     $              radius,region_count,rahalf,spdhalf,error)
               if (error) goto 400
            end if
         end if
      end do
      goto 400
 400  continue
      if (error) then
         call err_msg('imain','Traceback')
      end if
      return
      end
