# include "data.h"

int tvcolors (int argc, char **argv) {
  
  int N, kapa;
  char *name;
  // KapaImageData data;

  name = NULL;
  if ((N = get_argument (argc, argv, "-n"))) {
    remove_argument (N, &argc, argv);
    name = strcreate (argv[N]);
    remove_argument (N, &argc, argv);
  }
  if (!GetGraph (NULL, &kapa, name)) return (FALSE);
  FREE (name);

  int SetNAN = FALSE;
  int red, green, blue;
  if ((N = get_argument (argc, argv, "-nan"))) {
    if (N > argc - 4) { 
      gprint (GP_ERR, "ERROR: -nan (red) (green) (blue) does not have enough arguments\n"); 
      return FALSE; 
    }
    remove_argument (N, &argc, argv);
    red = strtol (argv[N], NULL, 0);
    remove_argument (N, &argc, argv);
    green = strtol (argv[N], NULL, 0);
    remove_argument (N, &argc, argv);
    blue = strtol (argv[N], NULL, 0);
    remove_argument (N, &argc, argv);
    SetNAN = TRUE;
  }

  // use the currently-set zero,range values if not supplied
  if (!SetNAN && (argc != 2)) {
    gprint (GP_ERR, "USAGE: tvcolors (colormap) [-nan red green blue]\n");
    gprint (GP_ERR, " colormap options : greyscale, -greyscale, rainbow, heat, fullcolor, ruffcolor (also grayscale, -grayscale)\n");
    return (FALSE);
  }

  if (SetNAN) {
    KiiSetNanColor (kapa, red, green, blue);
  }
  if (argc == 2) {
    KiiSetColormap (kapa, argv[1]);
  }
  return (TRUE);
}
