# include "dvoshell.h"

Image *LoadImages (int *nimage) {

  char *catdir, filename[256];
  Image *image;
  FITS_DB db;
  
  /* VarConfig ("IMAGE_CATALOG", "%s", filename); */

  catdir = GetCATDIR ();
  sprintf (filename, "%s/Images.dat", catdir);

  gfits_db_init (&db);
  db.lockstate = LCK_SOFT;
  db.timeout   = 120.0;

  if (!gfits_db_lock (&db, filename)) {
    gprint (GP_ERR, "error opening image catalog %s (1)\n", filename);
    return (NULL);
  }

  if (db.dbstate == LCK_EMPTY) {
    gprint (GP_ERR, "note: image catalog is empty\n");
    ALLOCATE (image, Image, 1);
    *nimage = 1;
    return (image);
  }

  dvo_image_load (&db, TRUE, FALSE);
  gfits_db_close (&db);

  image = gfits_table_get_Image (&db.ftable, nimage, &db.swapped);
  return (image);
}
