# include "dvo.h"

int gcat (int argc, char **argv) {
  
  int i, Nregions;
  RegionFile *regions;
  char filename[128];
  struct stat filestat;
  double Ra, Dec, Radius;
  char catdir[256];

  VarConfig ("CATDIR", "%s", catdir);

  if ((argc != 3) && (argc != 4)) {
    fprintf (stderr, "USAGE: gcat RA DEC [Radius]\n");
    return (FALSE);
  }

  Ra = atof (argv[1]);
  Dec = atof (argv[2]);
  if (argc == 4) 
    Radius = atof(argv[3]);
  else 
    Radius = 0.0001;

  regions = find_regions (Ra, Dec, Radius, &Nregions);

  for (i = 0; i < Nregions; i++) {
    sprintf (filename, "%s/%s", catdir, regions[i].name);
    if (stat (filename, &filestat) != -1) {
      fprintf (stderr, "%3d %s *\n", i, regions[i].name);
    } else {
      fprintf (stderr, "%3d %s\n", i, regions[i].name);
    } 
    set_str_variable ("CATNAME", regions[i].name);
  }

  return (TRUE);
  free (regions);

}

