# include "data.h"

int section (int argc, char **argv) {
  
  int N, List;
  int Ngraph, Xgraph;
  Graphdata graphmode;
  KapaSection section;

  List = FALSE;
  if ((N = get_argument (argc, argv, "-list"))) {
    remove_argument (N, &argc, argv);
    List = TRUE;
  }

  Ngraph = -1;
  if ((N = get_argument (argc, argv, "-n"))) {
    remove_argument (N, &argc, argv);
    Ngraph = atof (argv[N]);
    remove_argument (N, &argc, argv);
  }
  if (!GetGraph (&graphmode, &Xgraph, &Ngraph)) return (FALSE);

  /* list sections */
  if (argc == 1) {
    KapaGetSection (Xgraph, "*");
    gprint (GP_ERR, "USAGE: section name [x y dx dy]\n");
    return (TRUE);
  } 
  
  if (argc == 2) {
    /* select / show section */
    if (List) {
      KapaGetSection (Xgraph, argv[1]);
    } else {
      KapaSelectSection (Xgraph, argv[1]);
    }
    return (TRUE);
  } 
  
  if (argc == 6) {
    /* set section */
    section.name = argv[1];
    section.x = atof (argv[2]);
    section.y = atof (argv[3]);
    section.dx = atof (argv[4]);
    section.dy = atof (argv[5]);
    KapaSetSection (Xgraph, &section);
    return (TRUE);
  }
  gprint (GP_ERR, "USAGE: section name [x y dx dy]\n");
  return (FALSE);
}

/* should do some range checking on x y dx dy
   should be between 0.0 and 1.0, precision of 0.001
   is sufficient
*/
