# include "data.h"

int box (int argc, char **argv) {
  
  int i, N, Ngraph, Xgraph;
  char buffer[65], buffer2[65];
  Graphdata graphmode;
  char Ticks[16], Axis[16], Labels[16];
  
  strcpy (Ticks, "2222");
  if (N = get_argument (argc, argv, "-ticks")) {
    remove_argument (N, &argc, argv);
    strcpy (Ticks, argv[N]);
    remove_argument (N, &argc, argv);
    if (strlen (Ticks) != 4) { goto usage; }
    for (i = 0; i < strlen (Ticks); i++) {
      if ((Ticks[i] != '0') && (Ticks[i] != '1') && (Ticks[i] != '2')) { goto usage; }
    }
  }
  
  strcpy (Labels, "2222");
  if (N = get_argument (argc, argv, "-labels")) {
    remove_argument (N, &argc, argv);
    strcpy (Labels, argv[N]);
    remove_argument (N, &argc, argv);
    if (strlen (Labels) != 4) { goto usage; }
    for (i = 0; i < strlen (Labels); i++) {
      if ((Labels[i] != '0') && (Labels[i] != '1') && (Labels[i] != '2')) { goto usage; }
    }
  }

  strcpy (Axis, "2222");
  if (N = get_argument (argc, argv, "-axis")) {
    remove_argument (N, &argc, argv);
    strcpy (Axis, argv[N]);
    remove_argument (N, &argc, argv);
    if (strlen (Axis) != 4) { goto usage; }
    for (i = 0; i < strlen (Axis); i++) {
      if ((Axis[i] != '0') && (Axis[i] != '1') && (Axis[i] != '2')) { goto usage; }
    }
  }

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

  write (Xgraph, "DBOX", 4);

  snprintf (buffer, 64, "%12.6g %12.6g %12.6g %12.6g", graphmode.xmin, graphmode.xmax, graphmode.ymin, graphmode.ymax);
  snprintf (buffer2, 64, "NBYTES: %6d", strlen (buffer));
  write (Xgraph, buffer2, 16);
  write (Xgraph, buffer, strlen (buffer));
  
  snprintf (buffer, 64, "%s %s %s", Axis, Labels, Ticks);
  snprintf (buffer2, 64, "NBYTES: %6d", strlen (buffer));
  write (Xgraph, buffer2, 16);
  write (Xgraph, buffer, strlen (buffer));
  
  return (TRUE);
      
 usage:
  fprintf (stderr, "USAGE: box [-ticks NNNN] [-axis NNNN] [-labels NNNN]\n");
  return (FALSE);

}


/* box has:
   axis
   labels
   ticks

   assign like this:   
   -axis 0000
   -labels 0000
   -ticks 0000

   default:
   -axis 1111
   -labels 1100
   -ticks 1111
   


   messages to kapa:

   DBOX
   (xmin) (xmax) (ymin) (ymax)
   AAAA LLLL TTTT

   A = axis
   L = label
   T = ticks
   
   0 = off
   1 = on
   2 = default / maintain

*/
