/*
  Description: Collection of routines providing an interface between
               Fortran graphics primitives and the graphics libraries.
	       Also gives the graphics libraries acces to the Fortran
	       X-Midas libraries

  Author: SES

  $Revision: 1.5 $
  $Modtime:   17 Oct 1996 07:06:52  $

*/

#include "glibc.h"
#include "xfacilities.h"
#include "xwidgets.h"
#include "mjackets.h"

#if !_VMS

/* The non-VMS FORTRAN compilers tack an underscore on to the end of all */
/* FORTRAN routines, hence we will redefine all references to FORTRAN 	 */
/* routines with this added underscore for non-VMS only.		 */

#define mx$annotate		mx$annotate_
#define mx$arrow		mx$arrow_
#define mx$autorepeat		mx$autorepeat_
#define mx$aval			mx$aval_
#define mx$axis			mx$axis_
#define mx$bogus_event		mx$bogus_event_
#define mx$boxes		mx$boxes_
#define mx$clear_area		mx$clear_area_
#define mx$clear_window		mx$clear_window_
#define mx$client_event		mx$client_event_
#define mx$clip			mx$clip_
#define mx$close		mx$close_
#define mx$colorlab		mx$colorlab_
#define mx$colormap		mx$colormap_
#define mx$colormap_id		mx$colormap_id_
#define mx$colortab		mx$colortab_
#define mx$colortext		mx$colortext_
#define mx$contour		mx$contour_
#define mx$control_panel	mx$control_panel_
#define mx$cursor		mx$cursor_
#define mx$dflval		mx$dflval_
#define mx$display		mx$display_
#define mx$dopen		mx$dopen_
#define mx$dprompt		mx$dprompt_
#define mx$dragbox		mx$dragbox_
#define mx$draw_arc		mx$draw_arc_
#define mx$draw_box		mx$draw_box_
#define mx$draw_dots		mx$draw_dots_
#define mx$draw_line		mx$draw_line_
#define mx$draw_lines		mx$draw_lines_
#define mx$draw_mode		mx$draw_mode_
#define mx$draw_symbol		mx$draw_symbol_
#define mx$draw_symbols		mx$draw_symbols_
#define mx$drawaxis		mx$drawaxis_
#define mx$dval			mx$dval_
#define mx$event		mx$event_
#define mx$facilities		mx$facilities_
#define mx$files		mx$files_
#define mx$fill_arc		mx$fill_arc_
#define mx$fill_box		mx$fill_box_
#define mx$fill_poly		mx$fill_poly_
#define mx$fprompt		mx$fprompt_
#define mx$fval			mx$fval_
#define mx$get_image		mx$get_image_
#define mx$getrgb		mx$getrgb_
#define mx$graphics_break	mx$graphics_break_
#define mx$graphics_msg		mx$graphics_msg_
#define mx$graphicsinit		mx$graphicsinit_
#define mx$hardcopy_close	mx$hardcopy_close_
#define mx$hardcopy_open	mx$hardcopy_open_
#define mx$ifevent		mx$ifevent_
#define mx$kbstring		mx$kbstring_
#define mx$label		mx$label_
#define mx$learn		mx$learn_
#define mx$lprompt		mx$lprompt_
#define mx$lval			mx$lval_
#define mx$map			mx$map_
#define mx$menu			mx$menu_
#define mx$menuplus		mx$menuplus_
#define mx$message		mx$message_
#define mx$mhelp		mx$mhelp_
#define mx$mimic_msg		mx$mimic_msg_
#define mx$msgval		mx$msgval_
#define mx$mult			mx$mult_
#define mx$mval			mx$mval_
#define mx$open			mx$open_
#define mx$origin		mx$origin_
#define mx$pipe_monitor		mx$pipe_monitor_
#define mx$plot			mx$plot_
#define mx$points		mx$points_
#define mx$prompt		mx$prompt_
#define mx$psclose		mx$psclose_
#define mx$psopen		mx$psopen_
#define mx$put_image		mx$put_image_
#define mx$putbackevent		mx$putbackevent_
#define mx$putlat_image		mx$putlat_image_
#define mx$query		mx$query_
#define mx$queued		mx$queued_
#define mx$rclip		mx$rclip_
#define mx$rubberbox		mx$rubberbox_
#define mx$rubberdot		mx$rubberdot_
#define mx$rubberline		mx$rubberline_
#define mx$rubbertext		mx$rubbertext_
#define mx$rubberwarpbox	mx$rubberwarpbox_
#define mx$scroll		mx$scroll_
#define mx$scroll_loc		mx$scroll_loc_
#define mx$scroll_vals		mx$scroll_vals_
#define mx$scrollbar		mx$scrollbar_
#define mx$scrollbox		mx$scrollbox_
#define mx$setbar		mx$setbar_
#define mx$setcontext		mx$setcontext_
#define mx$setbgfg		mx$setbgfg_
#define mx$setfont		mx$setfont_
#define mx$shadowbox		mx$shadowbox_
#define mx$tdraw		mx$tdraw_
#define mx$text			mx$text_
#define mx$textline		mx$textline_
#define mx$tfont		mx$tfont_
#define mx$tics			mx$tics_
#define mx$title		mx$title_
#define mx$trace		mx$trace_
#define mx$trace_msg		mx$trace_msg_
#define mx$tselect		mx$tselect_
#define mx$ttics		mx$ttics_
#define mx$unsetbar		mx$unsetbar_
#define mx$unzoom		mx$unzoom_
#define mx$userfiles		mx$userfiles_
#define mx$warpbox		mx$warpbox_
#define mx$widget		mx$widget_
#define mx$widgetbox		mx$widgetbox_
#define mx$window_id		mx$window_id_
/* DR 11244 */
#define mx$display_id 	mx$display_id_
/*          */
#define mx$xc			mx$xc_
#define mx$xflush		mx$xflush_
#define mx$xwidget		mx$xwidget_
#define mx$wakeup		mx$wakeup_
#define mx$zoom			mx$zoom_

#define mxf$annotate		mxf$annotate_
#define mxf$axis		mxf$axis_
#define mxf$boxes		mxf$boxes_
#define mxf$drawaxis		mxf$drawaxis_
#define mxf$facilities		mxf$facilities_
#define mxf$mhelp		mxf$mhelp_
#define mxf$msgval_poll		mxf$msgval_poll_
#define mxf$points		mxf$points_
#define mxf$plot		mxf$plot_
#define mxf$setup		mxf$setup_
#define mxf$trace		mxf$trace_

#endif


/* NON-VAX: FORTRAN calling C interface passing strings */

void mx$psopen (const char *filename, int_4 *status, char *errstr,
		const int_4 *interact, fstring_len_t flen, fstring_len_t elen)
{ mx_psopen (filename, status, errstr, *interact, flen, elen); }

void mx$colorlab (const int_4 *ic, const char *text, fstring_len_t length)
{ mx_colorlab (*ic, text, length); }

void mx$colortext (const int_4 *ic, const int_4 *x, const int_4 *y,
		   const char *text, fstring_len_t length)
{ mx_colortext (*ic, *x, *y, text, length); }

void mx$dval (const char *prompt, real_8 *v,
  real_8 *vmin, real_8 *vmax, real_8 *vinc, int_4 *id, fstring_len_t length)
{ mx_dval (prompt, v, vmin, vmax, vinc, *id, length); }

void mx$fval (const char *prompt, real_4 *v,
  real_4 *vmin, real_4 *vmax, real_4 *vinc, fstring_len_t *id, fstring_len_t length)
{ mx_fval (prompt, v, vmin, vmax, vinc, *id, length); }

int_4 mx$kbstring (const char *prompt, char *string,
  const int_4 *x, const int_4 *y, const int_4 *linel, fstring_len_t lenp, fstring_len_t lens)
{ return mx_kbstring (prompt, string, *x, *y, *linel, lenp, lens); }

void mx$lval (const char *prompt, int_4 *v,
  int_4 *vmin, int_4 *vmax, int_4 *vinc, int_4 *id, fstring_len_t length)
{ mx_lval (prompt, v, vmin, vmax, vinc, *id, length); }

int_4 mx$menu (int_4 *mask, const char *string, fstring_len_t length)
{ return mx_menu (*mask, string, length); }

int_4 mx$menuplus (int_4 *value, const char *string,
		int_4 *mask, int_4 *mode, void (*func)(), fstring_len_t length)
{ return mx_menuplus (*value, string,
		*mask, *mode, (void(*)())func, length); }

void mx$message (const char *text, const real_4 *time, fstring_len_t length)
{ mx_message (text, *time, length); }

void mx$open (const char *name, fstring_len_t length)
{ mx_open (name, length); }

void mx$pipe_monitor (const char *name, const HEADER *hcb, fstring_len_t length)
{ mx_pipe_monitor (name, hcb, length); }

void mx$prompt (const char *prompt, char *string, fstring_len_t plen, fstring_len_t slen)
{ mx_prompt (prompt, string, plen, slen); }

int_4 mx$query (const char *object, fstring_len_t length)
{ return (mx_query (object[0])); }

void mx$rubbertext (const int_4 *x, const int_4 *y,
  const char *text, fstring_len_t length)
{ XDrawString (G.D, G.W, G.gcr, *x, *y, text, length); }

void mx$setbar (const char *name, fstring_len_t length)
{ mx_setbar (name, length); }

void mx$shadowbox (const int_4 *xc, const int_4 *yc,
  const int_4 *xs, const int_4 *ys,
  const int_4 *shape, const int_4 *mode, const char *label, fstring_len_t length)
{ mx_shadowbox (*xc, *yc, *xs, *ys, *shape, *mode, label, length); }

void mx$text (const int_4 *x, const int_4 *y, const char *text, fstring_len_t length)
{ mx_text (*x, *y, text, length); }

void mx$title (const char *name, int_4 *mask, fstring_len_t length)
{ mx_title (name, *mask, length); }

void mx$widgetbox (const int_4 *xc, const int_4 *yc,
         const int_4 *xs, const int_4 *ys,
	 const int_4 *xcc, const int_4 *ycc,
	 const int_4 *xss, const int_4 *yss,
	 const char *text, fstring_len_t length)
{
  register int i;
  for (i=length; i>0 && text[i-1]==' '; i--);
  mx_widgetbox (*xc, *yc, *xs, *ys, *xcc, *ycc, *xss, *yss, text, i);
}

/* NON-VAX: FORTRAN calling FORTRAN interface passing Mx structure */
/* and a string */

void mx$axis (const real_8 *xmin, const real_8 *ymin,
	      const real_8 *xmax, const real_8 *ymax,
	      const real_8 *xtic1, const real_8 *ytic1,
	      const real_8 *xtic, const real_8 *ytic,
	      const real_8 *xmult, const real_8 *ymult,
	      const int_4 *xc, const int_4 *yc,
	      const int_4 *w, const int_4 *h,
	      const char *xlabel, const char *ylabel,
	      const bool_4 *grid, fstring_len_t xlen, fstring_len_t ylen)
{ mxf$axis (Mx, xmin, ymin, xmax, ymax, xtic1, ytic1, xtic, ytic,
	    xmult, ymult, xc, yc, w, h, xlabel, ylabel, grid, xlen, ylen); }

void mx$facilities (void *xf, const char *type, int_4 *mode, fstring_len_t length)
{ mxf$facilities (Mx, xf, type, mode, length); }

void mx$mhelp (const char *menu, const char *item, fstring_len_t mlen, fstring_len_t ilen)
{ mxf$mhelp (Mx, menu, item, mlen, ilen); }

/* NON-VAX: C calling FORTRAN interface passing strings */

void mx_axis (real_8 xmin, real_8 ymin, real_8 xmax, real_8 ymax,
	      real_8 xtic1, real_8 ytic1, real_8 xtic, real_8 ytic,
	      real_8 xmult, real_8 ymult,
	      int_4 xc, int_4 yc, int_4 w, int_4 h,
	      const char *xlabel, const char *ylabel, bool_4 grid,
	      int_4 xlen, int_4 ylen)
{ mxf$axis (Mx, &xmin, &ymin, &xmax, &ymax, &xtic1, &ytic1, &xtic, &ytic,
     &xmult, &ymult, &xc, &yc, &w, &h, xlabel, ylabel, &grid, xlen, ylen); }

void mx_dopen (const MX *mx_ptr, const char *name, int_4 length)
{ mx$dopen (mx_ptr, name, length); }

void mx_dprompt (const char *prompt, real_8 *dval, int_4 length)
{ mx$dprompt (prompt, dval, length); }

int_4 mx_hardcopy_open (const char *filename, int_4 flag, int_4 length)
{ return mx$hardcopy_open (filename, &flag, length); }

void mx_label (int_4 units, real_8 mult, char *label, int_4 length)
{ mx$label (&units, &mult, label, length); }

void mx_facilities (void *xf, const char *type, int_4 mode, int_4 length)
{ mxf$facilities (Mx, xf, type, &mode, length); }

int_4 mx_files (char *filename, int_4 length)
{ return mx$files (filename, length); }

void mx_fprompt (const char *prompt, real_4 *fval, int_4 length)
{ mx$fprompt (prompt, fval, length); }

void mx_lprompt (const char *prompt, int_4 *lval, int_4 length)
{ mx$lprompt (prompt, lval, length); }

void mx_mhelp (const char *menu, const char *item, int_4 mlen, int_4 ilen)
{ mxf$mhelp (Mx, menu, item, mlen, ilen); }

int_4 mx_userfiles (char *filename, const char *userargs,
  int_4 flen, int_4 ulen)
{ return mx$userfiles (filename, userargs, flen, ulen); }

/*+++                          */
/* DR 11244                    */
void mx_display_id(int_4 xs, int_4 op, char *node, int_4 ln)
{
  mx$display_id(&xs, &op, node, ln);
  if (node != NULL)
    strf2c(node, ln, node, ln, F2C_TRIM);
  return;
}
/*---                          */



/* ALL: FORTRAN calling C interface */

void mx$arrow (const int_4 *x, const int_4 *y,
	       const int_4 *d, const int_4 *orient)
{ mx_arrow (*x, *y, *d, *orient); }

void mx$autorepeat (bool_4 *autorepeat, const int_4 *mode)
{ mx_autorepeat (autorepeat, *mode); }

int_4 mx$aval (XWIDGET *m, const int_4 *mode)
{ return mx_aval (m, *mode); }

int_4 mx$bogus_event ()
{ return mx_bogus_event(); }

void mx$clear_area (const int_4 *x, const int_4 *y,
		    const int_4 *w, const int_4 *h)
{ mx_clear_area(*x, *y, *w, *h); }

void mx$clear_window ()
{ mx_clear_window(); }

bool_4 mx$client_event (const int_4 *window_id, const int_4 *mesg,
  const int_4 vals[], const int_4 *nvals)
{ return mx_client_event ((Window)(*window_id), *mesg, vals, *nvals); }

void mx$clip (const int_4 *x, const int_4 *y, const int_4 *w, const int_4 *h)
{ mx_clip (*x, *y, *w, *h); }

void mx$close ()
{ mx_close (); }

void mx$colormap (int_2 map[7][4], int_4 *pcolors)
{ mx_colormap (map, pcolors); }

void mx$colortab (const int_4 *ic, int_2 map[7][4], int_4 *position)
{ mx_colortab (*ic, map, *position); }

void mx$control_panel (XFACILITIES *Xf, const int_4 *mode)
{ mx_control_panel(Xf, *mode); }

void mx$cursor (const int_4 *shape)
{ mx_cursor (*shape); }

void mx$dflval (XWIDGET *dv, const int_4 *mode)
{ mx_dflval (dv, *mode); }

void mx$display (MX *mx_ptr, bool_4 *b_ptr, bool_4 *unl_ptr)
{ mx_display (mx_ptr, b_ptr, unl_ptr); }

void mx$dragbox (int_4 *x, int_4 *y, const int_4 *w, const int_4 *h,
  const int_4 *xmin, const int_4 *xmax, const int_4 *ymin, const int_4 *ymax,
  void (*func)())
{
  int_4 x2, y2;
  x2 = *x + *w;
  y2 = *y + *h;
  mx_warpbox (x, y, &x2, &y2, *xmin, *ymin, *xmax, *ymax, (void(*)())func, 2);
}

void mx$draw_dots (const int_4 *ic, const XPoint pix[], const int_4 *npix,
		   const int_4 *rr)
{ mx_draw_dots (*ic, pix, *npix, *rr); }

void mx$draw_symbol (const int_4 *ic, const int_4 *x, const int_4 *y,
		   const int_4 *symbol, const int_4 *rr)
{
  XPoint pix[1]; pix[0].x = *x; pix[0].y = *y;
  mx_draw_symbols (*ic, pix, 1, *symbol, *rr);
}

void mx$draw_symbols (const int_4 *ic, const XPoint pix[], const int_4 *npix,
		   const int_4 *symbol, const int_4 *rr)
{ mx_draw_symbols (*ic, pix, *npix, *symbol, *rr); }

void mx$draw_line (const int_4 *ic, const int_4 *x1, const int_4 *y1,
		   const int_4 *x2, const int_4 *y2)
{ mx_draw_line (*ic, *x1, *y1, *x2, *y2); }

void mx$draw_lines (const int_4 *ic, const XPoint pix[], const int_4 *npix)
{ mx_draw_lines (*ic, pix, *npix); }

void mx$draw_mode (int_4 *mode)
{ mx_draw_mode (*mode); }

void mx$draw_arc (const int_4 *ic, const int_4 *x, const int_4 *y,
  const int_4 *w, const int_4 *h, const int_4 *a1, const int_4 *a2)
{ mx_draw_arc (*ic, *x, *y, *w, *h, *a1, *a2); }

void mx$draw_box (const int_4 *ic, const int_4 *x, const int_4 *y,
		  const int_4 *w, const int_4 *h)
{ mx_draw_box (*ic, *x, *y, *w, *h); }

void mx$event ()
{ mx_event(); }

void mx$fill_poly (const int_4 *ic, const XPoint pix[], const int_4 *npix,
		   const int_4 *mode)
{ mx_fill_poly (*ic, pix, *npix, *mode); }

void mx$fill_arc (const int_4 *ic, const int_4 *x, const int_4 *y,
  const int_4 *w, const int_4 *h, const int_4 *a1, const int_4 *a2)
{ mx_fill_arc (*ic, *x, *y, *w, *h, *a1, *a2); }

void mx$fill_box (const int_4 *ic, const int_4 *x, const int_4 *y,
		  const int_4 *w, const int_4 *h)
{ mx_fill_box (*ic, *x, *y, *w, *h); }

void mx$get_image (int_4 data[], const int_4 *xc, const int_4 *yc,
		   const int_4 *w, const int_4 *h, const int_4 *ncolors)
{ mx_get_image (data, *xc, *yc, *w, *h, *ncolors); }

void mx$getrgb (int_4 *ic, int_4 *red, int_4 *green, int_4 *blue)
{ mx_getrgb (*ic, red, green, blue); }

void mx$graphics_break (bool_4 *breakflag)
{ mx_graphics_break (breakflag); }

void mx$graphicsinit ()
{ mx_graphicsinit (); }

bool_4 mx$ifevent ()
{ return mx_ifevent(); }

bool_4 mx$learn (const int_4 *xs,
  int_4 *left, int_4 *top, int_4 *width, int_4 *height)
{ return mx_learn (*xs, left, top, width, height); }

void mx$map (MAPSTRUCT *map, const int_4 *x, const int_4 *y,
	     const int_4 *w, const int_4 *h, const int_4 *func)
{ mx_map (map, *x, *y, *w, *h, *func); }

int_4 mx$mval (XWIDGET *m, const int_4 *mode)
{ return mx_mval (m, *mode); }

void mx$msgval (XWIDGET *xw, int_4 *op)
{ mx_msgval (xw, *op); }

void mx$psclose ()
{ mx_psclose (); }

void mx$put_image (const char data[], const int_4 *nx, const int_4 *ny,
	const int_4 *nex, const int_4 *ney, const int_4 *xd, const int_4 *yd,
	const int_4 *level)
{ mx_put_image (data, *nx, *ny, *nex, *ney, *xd, *yd, *level); }

void mx$putlat_image (const char data[], const int_4 *nx, const int_4 *ny,
	const int_4 *nex, const int_4 *ney, const int_4 *xd, const int_4 *yd,
	const int_4 *level)
{ mx_putlat_image (data, *nx, *ny, *nex, *ney, *xd, *yd, *level); }

void mx$putbackevent ()
{ XPutBackEvent(G.D, &GEvent); }

int_4 mx$queued ()
{
#if _HEADLESS
 if (Mx->headless == 1)
   return 0;
 else
#endif
   return XPending (G.D);
}

void mx$rclip (const int_4 *x, const int_4 *y, const int_4 *w, const int_4 *h)
{ mx_rclip (*x, *y, *w, *h); }

void mx$rubberbox (int_4 *x1, int_4 *y1, int_4 *x2, int_4 *y2, void (*func)())
{ mx_warpbox (x1,y1, x2,y2, 0,0, Mx->width,Mx->height, (void(*)())func, 0); }

void mx$rubberdot (const int_4 *x, const int_4 *y, const int_4 *r)
{ mx_rubberdot (*x, *y, *r); }

void mx$rubberline  (const int_4 *x1, const int_4 *y1,
  const int_4 *x2, const int_4 *y2)
{ mx_rubberline  (*x1, *y1, *x2, *y2); }

void mx$rubberwarpbox (int_4 *x1, int_4 *y1, int_4 *x2, int_4 *y2,
  void (*func)())
{ mx_warpbox (x1,y1, x2,y2, 0,0, Mx->width,Mx->height, (void(*)())func, 1); }

bool_4 mx$scroll (SCROLLBAR *sb, const int_4 *mode)
{ return mx_scroll (sb, *mode); }

void mx$scroll_loc (SCROLLBAR *sb, const int_4 *x, const int_4 *y,
  const int_4 *w, const int_4 *h, const int_4 *origin)
{ mx_scroll_loc (sb, *x, *y, *w, *h, *origin); }

void mx$scroll_vals (SCROLLBAR *sb, const real_8 *smin, const real_8 *srange,
  const real_8 *tmin, const real_8 *trange, const real_8 *step,
  const real_8 *page, const real_8 *scale)
{ mx_scroll_vals (sb, *smin, *srange, *tmin, *trange, *step, *page, *scale); }

int_4 mx$scrollbar (SCROLLBAR *sb, const int_4 *xs, const int_4 *xe,
  const int_4 *ys, int_4 *ye, real_8 *ps, real_8 *pe,
  const real_8 *qs, const real_8 *qe)
{ return mx_scrollbar (sb, *xs, *xe, *ys, *ye, ps, pe, *qs, *qe); }

void mx$scrollbox (const char text[], const int_4 line[], int_4 *lines,
		   int_4 *maxlen, const int_4 *type)
{ mx_scrollbox (text, line, lines, maxlen, *type); }

void mx$setcontext (MX *mx_ptr)
{ mx_setcontext(mx_ptr); }

void mx$setbgfg (const int_4 *black, const int_4 *white, const int_4 *xi)
{ mx_setbgfg(*black, *white, *xi); }

void mx$setfont (const int_4 *width)
{ mx_setfont (*width); }

void mx$textline (const int_4 *x1, const int_4 *y1,
  const int_4 *x2, const int_4 *y2)
{ mx_textline(*x1, *y1, *x2, *y2); }

void mx$tdraw (XFANNOTATION *tn)
{ mx_tdraw (tn); }

void mx$tfont (XFANNOTATION *tn, const int_4 *task)
{ mx_tfont (tn, *task); }

void mx$tselect (XFANNOTATION *tn, const int_4 *task)
{ mx_tselect (tn, *task); }

void mx$unsetbar ()
{ mx_unsetbar (); }

void mx$unzoom ()
{ mx_unzoom (); }

void mx$warpbox (int_4 *x1, int_4 *y1, int_4 *x2, int_4 *y2,
  const int_4 *xmin, const int_4 *xmax, const int_4 *ymin, const int_4 *ymax,
  void (*func)(), const int_4 *mode)
{ mx_warpbox (x1,y1, x2,y2, *xmin,*ymin, *xmax,*ymax, (void(*)())func, *mode); }

void mx$wakeup (const int_4 *window_id, const int_4 *mode, const int_4 *val)
{ mx_wakeup((Window)*window_id, *mode, *val); }

void mx$widget (XWIDGET *xw, int_4 *op)
{ mx_widget (xw, *op); }

void mx$xflush ()
{ mx_xflush (); }

void mx$zoom (const int_4 *xc, const int_4 *yc, const int_4 *w, const int_4 *h,
  const int_4 *xd, const int_4 *yd, const int_4 *nx, const int_4 *ny)
{ mx_zoom (*xc, *yc, *w, *h, *xd, *yd, *nx, *ny); }

/*  ALL: C calling FORTRAN interface */

int_4 mx_colormap_id (int_2 map[7][4], int_4 ncolors)
{ return mx$colormap_id (Mx, map, &ncolors); }

void mx_contour (real_4 zstart, real_4 zdelta, int_4 nslices,
  const real_4 zvals[],
  int_4 work[], real_4 lines[], int_4 *npoints, int_4 nbytes,
  int_4 nx, int_4 ny, real_4 xstart, real_4 xdelta,
  real_4 ystart, real_4 ydelta)
{ mx$contour (&zstart, &zdelta, &nslices, zvals, work, lines, npoints, &nbytes,
  &nx, &ny, &xstart, &xdelta, &ystart, &ydelta); }

void mx_drawaxis (int_4 xdiv, int_4 ydiv, int_4 xlab, int_4 ylab, bool_4 grid)
{ mxf$drawaxis (Mx, &xdiv, &ydiv, &xlab, &ylab, &grid); }

int_4 mx_graphics_msg (MX *mx_ptr, void *mqh, void *mqd, int_4 *msgid, int_4 *msgmask)
{ return mx$graphics_msg (mx_ptr, mqh, mqd, msgid, msgmask); }

void mx_hardcopy_close ()
{ mx$hardcopy_close (); }

int_4 mx_mimic_msg (void *mqh, void *mqd, int_4 mimic)
{ return mx$mimic_msg (mqh, mqd, &mimic); }

void mx_msgval_poll (XWIDGET *xw)
{ mxf$msgval_poll (Mx, xw); }

void mx_mult (real_8 end1, real_8 end2, real_8 *mult)
{ mx$mult (&end1, &end2, mult); }

void mx_origin (int_4 inorigin, int_4 outorigin,
                const STKSTRUCT *instack, STKSTRUCT *outstack)
{ mx$origin (&inorigin, &outorigin, instack, outstack); }

void mx_setup (int_4 width, int_4 height)
{ mxf$setup (Mx, &width, &height); }

void mx_tics (real_8 vmin, real_8 vmax, real_8 *tic1, real_8 *dtic, int_4 ndiv)
{ mx$tics (&vmin, &vmax, tic1, dtic, &ndiv); }

void mx_ttics (real_8 vmin, real_8 vmax, real_8 *tic1, real_8 *dtic, int_4 ndiv)
{ mx$ttics (&vmin, &vmax, tic1, dtic, &ndiv); }

void mx_trace (int_4 ic, const real_8 x[], const real_8 y[], int_4 npoint,
	      int_4 skip, int_4 line, int_4 symb, int_4 rad, XPoint work[],
	      int_u4 opts)
{ mxf$trace (Mx, &ic, x, y, &npoint, &skip, &line, &symb, &rad, work, &opts); }

void mx_trace_msg (void *mqd, int_4 *line, int_4 *thk,
			int_4 *sym, int_4 *rad, int_4 *colr)
{ mx$trace_msg (mqd, line, thk, sym, rad, colr); }

Window mx_window_id (int_4 xs, int_4 op)
{ return (Window) mx$window_id (&xs, &op); }

void mx_xc (const int_2 map[7][4], int_2 color[][4], int_4 *ncolors)
{ mx$xc(map, color, ncolors); }

void mx_xwidget (int_4 id)
{ mx$xwidget (&id); }

/* On their way out */

void mx_annotate (int_4 mode)
{ mxf$annotate (Mx, &mode); }

void mx_boxes (int_4 mode, void (*routine)(), int_4 *iarg, real_8 *darg)
{ mxf$boxes (Mx, &mode, (void (*)())routine, iarg, darg); }

void mx_plot (int_4 ic, const real_8 x[], const real_8 y[], int_4 npoint,
	      int_4 skip, int_4 line, int_4 dot, XPoint work[])
{ mxf$plot (Mx, &ic, x, y, &npoint, &skip, &line, &dot, work); }

void mx_points (int_4 mode, void (*routine)(), int_4 *iarg, real_8 *darg)
{ mxf$points (Mx, &mode, (void (*)())routine, iarg, darg); }

/* ALL: FORTRAN calling FORTRAN interfaces passing the Mx structure */

void mx$drawaxis (const int_4 *xdiv, const int_4 *ydiv, const int_4 *xlab,
		  const int_4 *ylab, const bool_4 *grid)
{ mxf$drawaxis (Mx, xdiv, ydiv, xlab, ylab, grid); }

void mx$trace (const int_4 *ic, const real_8 xpoint[], const real_8 ypoint[],
  const int_4 *npoint, const int_4 *skip, const int_4 *line,
  const int_4 *symb, const int_4 *rad, XPoint work[], int_u4 *opts)
{ mxf$trace(Mx,ic,xpoint,ypoint,npoint,skip,line,symb,rad,work,opts); }

/* On their way out */

void mx$annotate (const int_4 *mode)
{ mxf$annotate (Mx, mode); }

void mx$boxes (const int_4 *mode, void (*routine)(), int_4 *iarg, real_8 *darg)
{ mxf$boxes (Mx, mode, routine, iarg, darg); }

void mx$plot (const int_4 *ic, const real_8 xpoint[], const real_8 ypoint[],
  const int_4 *npoint, const int_4 *skip, const int_4 *line, const int_4 *dot,
  XPoint work[])
{ mxf$plot (Mx, ic, xpoint, ypoint, npoint, skip, line, dot, work); }

void mx$points (const int_4 *mode, void (*routine)(), int_4 *iarg, real_8 *darg)
{ mxf$points (Mx, mode, routine, iarg, darg); }


/*
   The following routines are compiled only if we are on a VAX, since
   VAX C seems to have left them out of its library.  Silly VAX!
*/

#if _PRE70VMS


/* strncasecmp

Description:
  Compares two strings without regard to case, up to at most n characters.

*/

int strncasecmp(const char *s, const char *t, int n)

{
  int	i;

  for (i = 0; i < n; i++) {
    if (s[i] == '\0' || t[i] == '\0')
      if (s[i] == '\0' && t[i] == '\0')
	return(0);
      else
	return(-1);
    if (tolower(s[i]) != tolower(t[i]))
      return(-1);
  }

  return(0);

}



/* strcasecmp

Description:
  Compares two strings without regard to case.

*/

int strcasecmp(const char *s, const char *t)

{
  int	i;

  for (i = 0; s[i] != '\0' && t[i] != '\0'; i++)
    if (tolower(s[i]) != tolower(t[i]))
      return(-1);

  if (s[i] == '\0' && t[i] == '\0')
    return(0);
  else
    return(1);

}



/* strdup

Description:
  Creates a copy of the given string using dynamic memory and passes
  a pointer to it back to the caller.  Afterwards the string must be
  freed using free().

*/

char *strdup(const char *s)

{
  char	*t;

/* Need to allocate enough space for all characters plus one
   for the '\0'. */

  t = (char *)malloc(sizeof(char)*(strlen(s) + 1));
  strcpy(t, s);

  return(t);

}

#endif





