# include "data.h"

int close_device (int argc, char **argv) {

  int N, Source, Nsource, IsImage;
  /* close current graphics device */

  Nsource = -1;
  if ((N = get_argument (argc, argv, "-n"))) {
    remove_argument (N, &argc, argv);
    Nsource = atof (argv[N]);
    remove_argument (N, &argc, argv);
  }
  if ((N = get_argument (argc, argv, "-g"))) {
    remove_argument (N, &argc, argv);
    SetImageDevice (FALSE);
  }  
  if ((N = get_argument (argc, argv, "-i"))) {
    remove_argument (N, &argc, argv);
    SetImageDevice (TRUE);
  }  

  IsImage = GetCurrentDevice ();
  if (IsImage) {
    if (!GetImage (&Source, &Nsource)) return (FALSE);
    close_image (Nsource); 
  } else {
    if (!GetGraph (NULL, &Source, &Nsource)) return (FALSE);
    close_graph (Nsource); 
  }

  return (TRUE);
}
