# include "data.h"

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

  char *end;
  double NX, NY;
  int N, Source, Nsource, IsImage;
  
  /* display source */
  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);
  } else {
    if (!GetGraph (NULL, &Source, &Nsource)) return (FALSE);
  }

  if (argc != 3) {
    gprint (GP_ERR, "USAGE: resize NX NY [-n] [-g | -i]\n");
    return (FALSE);
  }

  /* NX & NY are pixels for the screen & points for PS 
     convert units to points (1in = 72pt, 1cm = 28pt) */

  /* have kapa convert physical units to screen units 
     for now, fixed at 96 pix / in == 38 pix / cm
  */

  NX = strtod (argv[1], &end);
  if (!strcmp (end, "in")) { NX *= 96; }
  if (!strcmp (end, "cm")) { NX *= 38; }

  NY = strtod (argv[2], &end);
  if (!strcmp (end, "in")) { NY *= 96; }
  if (!strcmp (end, "cm")) { NY *= 38; }

  KiiResize (Source, NX, NY);
  return (TRUE);
}

