# include "data.h"

int section (int argc, char **argv) {
  
  int N, List;
  char buffer[65], buffer2[65];
  Graphdata graphmode;
  int Ngraph, Xgraph;

  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);

  if (argc == 1) {
    /* list section */
    write (Xgraph, "LSEC", 4);
    sprintf (buffer, "* %s", argv[1]);
    sprintf (buffer2, "NBYTES: %6d ", strlen (buffer));
    write (Xgraph, buffer2, 16);
    write (Xgraph, buffer, strlen (buffer));
    fprintf (stderr, "USAGE: section name [x y dx dy]\n");
    return (TRUE);
  } 
  
  if (argc == 2) {
    /* set section */
    if (List) {
      write (Xgraph, "LSEC", 4);
    } else {
      write (Xgraph, "SSEC", 4);
    }
    sprintf (buffer, "%s", argv[1]);
    sprintf (buffer2, "NBYTES: %6d ", strlen (buffer));
    write (Xgraph, buffer2, 16);
    write (Xgraph, buffer, strlen (buffer));
    return (TRUE);
  } 
  
  if (argc == 6) {
    /* define section */
    write (Xgraph, "DSEC", 4);
    snprintf (buffer, 65, "%s %6.3f %6.3f %6.3f %6.3f", argv[1], atof (argv[2]), atof (argv[3]), atof (argv[4]), atof (argv[5]));
    snprintf (buffer2, 65, "NBYTES: %6d ", strlen (buffer));
    write (Xgraph, buffer2, 16);
    write (Xgraph, buffer, strlen (buffer));
    return (TRUE);
  }
      
  fprintf (stderr, "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
    */
