C+ MCSDEMO4
C.
C.  Demo using DIF functions to select sky regions.
C.
C.  Optional input params are center and radius/side and catalogue.
C.
C.  Example: ./mcsdemo4 "20,30,6"
C.           ./mcsdemo4 "10,20,16" ascc25
C.           ./mcsdemo4 "20,30,6" TMASS
C.
C-    LN 24/06/2010: v. 0.1c

      PROGRAM MCSDEMO4
      IMPLICIT NONE

      INCLUDE 'mcs_usrlib.inc'
      INTEGER   status, is_circle, LENSTR, DBExec_qry
      CHARACTER*256 DIFHTMQRY
      CHARACTER*32 par, coords
      CHARACTER*16 idname, catname

      DATA c_user /'mpe'/, c_password /'mpe2014pass'/,
     .     c_dbname /'mpe2014'/,
     .     coords /'40.0,-80.0,12.0'/,  ! comma separated center and rad./side
     .     catname /'UCAC_2orig'/
C--

C- Optional arguments: coords (in "") and catname
      CALL GETARG( 1, par )
      IF (par.NE.' ') THEN
        coords = par
        CALL GETARG( 2, par )
        IF (par.NE.' ') catname = par
      ENDIF
C- The DIF HTM specific query builder (for square and circle)
      is_circle = 0
      c_query = DIFHTMQRY(coords,catname,is_circle)
      write(6,'("The query: "/,A/)') c_query(1:LENSTR(c_query))
      status = DBExec_qry('localhost')
      IF (status.EQ.0) STOP 'Error in DB operations.'

      write(6,'("Selected Nr. of rows: ", I9,/)') n_rows
      CALL printValues()

      is_circle = 1
      c_query = DIFHTMQRY(coords,catname,is_circle)
      write(6,'(/"The query: "/,A/)') c_query(1:LENSTR(c_query))

      status = DBExec_qry('localhost')
      IF (status.EQ.0) STOP 'Error in DB operations.'

      CALL FieldInfo(1)

      CALL printValues()
      CALL DBFree

      END
