      program astronet
C
C Description:
C
C This program selects a set of astrometric stars (from the USNO's 
C catalog A0.9) in a defined region of the sky.
C
C User Interface:
C
C The user interface is described in detail in the 'man' page for 
C astronet. Additional details can be found in the astronet design
C documents. Also see 'command_line', 'imain', and 'bmain'. 
C
C Programming Interface:
C
C Since this is the top level of astronet, not programming interface
C needs to be specified.
C
C Errors:
C
C If any I/O error occurs, the source of the error is reported and
C the program is immeadiately abandoned. The program design focused
C on eliminating logic errors so, hopefully, the only errors that
C will occur are I/O errors or hardware errors.
C
C Implementation note: The input and output parameters are requested
C or presented in a variety of different units. However, internally,
C all angles will be stored as radians. RA radians will have a zero
C point in the standard place. DEC radians will not be traditional. The
C zero point will be the South pole and the angle will be the South
C Polar Distance or SPD. SPD=DEC+pi/2. In addition, the precision of
C position measurements is 8 or 9 significant digits. This implies that
C real numbers should be stored as double precision
C
C Routines accessed:
C 
C command_line
C bmain
C imain
C err_msg
C exit
C
      implicit none
      include 'std_io.for'
      include 'include_.for'
      real*8 density,focallength,himaglim,lomaglim,pixelsize
      logical error,round_aper,batch,ascending
      character*64 infilename,outfilename,catmap
      character*1 magtype,outstyle,sortfield
      error=.false.
      open(unit=debug,file='debug.dat',err=401)
      call command_line(round_aper,density,focallength,infilename,
     $     himaglim,lomaglim,magtype,outstyle,outfilename,batch,
     $     pixelsize,ascending,sortfield,catmap,error)
      if (error) goto 400
      if (batch) then
         call bmain(round_aper,density,focallength,infilename,
     $        himaglim,lomaglim,magtype,outstyle,outfilename,
     $        pixelsize,ascending,sortfield,catmap,error)
         if (error) goto 400
      else
         call imain(round_aper,density,focallength,infilename,
     $        himaglim,lomaglim,magtype,outstyle,outfilename,
     $        pixelsize,ascending,sortfield,catmap,error)
         if (error) goto 400
      end if
      goto 400
 401  call err_msg('astronet','Error opening debug file.')
      error=.true.
 400  continue
C
C This silly segment is to force traceback information into the
C log file before it is closed. Otherwise it is placed into 'fort.7'
C and nobody will ever think about looking there. Can't put traceback
C information into the logfile if the error occurs on the close
C statement so just forget it.
C
      if (error) then
         call err_msg('astronet','Traceback')
      end if
      close(unit=debug)
C
C The following code segment is for UNIX systems.The argument 
C of 'exit' is made available to the calling routine.  
C If you are not running UNIX or your FORTRAN does not support the 'exit' 
C subroutine, you may omit the following 5 lines of code.
C
c      if (error) then
c         call exit(1)
c      else
c         call exit(0)
c      end if
      stop
      end
