require ("xfig");
require ("histogram");
require ("readascii");

private define read_file (file)
{
   variable s = struct
     {
	lam, alpha, cx, cy
     };   
   () = readascii (file, &s.lam, &s.alpha, &s.cx, &s.cy);
   return s;
}

private define make_plot_objs (s)
{
   variable lam_grid = [min(s.lam):max(s.lam):0.001];
   variable hist = hist1d (s.lam, lam_grid);

   variable xywin = xfig_plot_new (7, 7);
   xywin.xlabel ("\\bf X [mm]");
   xywin.ylabel ("\\bf Y [mm]");
   xywin.plot (s.cx, s.cy; color="blue", sym="point", size=0);

   variable lawin = xfig_plot_new (7, 7);
   lawin.xlabel ("\\bf$\\bm\\lambda$ [\\AA]");
   lawin.ylabel ("\\bf$\\bm\\eta$ [mm]");
   lawin.plot (s.lam, s.alpha; color="blue", sym="point", size=0);

   variable hwin = xfig_plot_new (14, 7);
   hwin.xlabel ("\\bf$\\bm\\lambda$ [\\AA]");
   hwin.ylabel ("\\bf Counts per $\\bm 10^{-3}$\\AA");
   hwin.hplot (lam_grid, hist; size=3, color="blue");
   
   return xywin, lawin, hwin;
}

define slsh_main ()
{
   variable lambda = 35;
   variable s = read_file ("resolve.dat");
   struct_filter (s,  where (lambda-1 <= s.lam < lambda+1));

   variable xywin, lawin, hwin;
   (xywin, lawin, hwin) = make_plot_objs (s);
	
   variable wins = xfig_new_hbox_compound (xywin, lawin, 1);
   wins = xfig_new_vbox_compound (wins, hwin, 1);
   wins.render ("conx.png");
}
   
   
