By: Bill Wingle
e-mail: wwingle@mines.edu
Date: October, 1995
This is a series of subroutines which allow FORTRAN programs to create a X-Windows/Motif window and preform simple graphics routines.
Copyright (C) 1994,1995 Bill Wingle. All rights reserved.
The programs in the graphix library are distributed in the hope that they be useful, but WITHOUT ANY WARRANTY. No author or distributor accepts responsibility to anyone for the consequences of using them or for whether they serve any paticular purpose or work at all, unless stated so in writing. No author or distributor accepts responsibility for the quality of data generated, nor the damage to existing data. Everyone is granted permission to copy, modify, and redistribute the graphix library, but only under the condition that this notice and the above copyright notice remain intact.
NOTE:
----------------------------------------------------------------------------- call initialize_window (INTEGER plot_event_id event ID to define active plot (Valid ID's > 0)
INTEGER key_event_id event ID to define active key
press decision menu (Valid ID's > 0)
INTEGER mouse_press_id event ID to button press (Valid ID's >= 0)
(0 disables mouse callback)
INTEGER mouse_release_id event ID to button release (Valid ID's >= 0) (0 disables mouse callback) INTEGER mouse_move_id event ID to mouse movement (Valid ID's >= 0) (0 disables mouse callback) CHARACTER window_title() this is the X/motif window title INTEGER window_title_length this is the number of characters in the window_title INTEGER window_width this is the window width in pixels INTEGER window_height this is the window height in pixels INTEGER window_x this is the window x location (upper left corner) INTEGER window_y this is the window y location (upper left corner) INTEGER window_background_color valid color are described below EXTERNAL event_subroutine this is the FORTRAN subroutine called to process X and user initiated events INTEGER use_menu) this specifies whether pull-down menus will be used. 0 = NO, 1 = YES This subroutine creates the X window and handles all X events. It also controls when 'event_subroutine' () is called. event_subroutine () is the required FORTRAN subroutine name that controls all the drawing routines. NOTE: Before the 'event_subroutine' () is called in FORTRAN, it MUST be declared EXTERNAL. The program will terminate otherwise. NOTE: Once initialize_window () is called no FORTRAN instructions following it will be executed. initialize_window () has an imbedded infinite loop. All FORTRAN instructions that need to be carried out after the window is initialized must be in, or called from, event_subroutine (), or call by pull down menus. NOTE: The event_subroutine () is called after every X event initialize_menu () determines requires that the drawing be redrawn. ------------------------------------------------------------------------------ subroutine event_handler (INTEGER event event ID to process CHARACTER*1 key(4)) character code if key event This subroutine is used to handle events as they occur. These events maybe user initiated when a keyboard key is pressed, or initiated by X requesting that the graphic window be redrawn. NOTE: This subroutine MUST appear in the FORTRAN program. ------------------------------------------------------------------------------ call clear_window () This subroutine clears the graphics window. ------------------------------------------------------------------------------ call change_integer_to_string (CHARACTER string() string representation of number (RETURN VALUE) INTEGER length length of string (RETURN VALUE) INTEGER number value to convert) This subroutine is used to convert integer*4 values into character string. NOTE: Be sure character string is long enough to accomidate value. If it's not, memory will be overwritten, and the results are unpredictable! ------------------------------------------------------------------------------ call change_real_to_string (CHARACTER string() string representation of number (RETURN VALUE) INTEGER length length of string (RETURN VALUE) REAL number value to convert INTEGER decimals # of decimal places to use INTEGER format # format) This subroutine is used to convert real*8 values into character string. The valid formats are: 0 = Fixed 1 = Exponential 2 = General NOTE: Be sure character string is long enough to accomidate value. If it's not, memory will be overwritten, and the results are unpredictable! NOTE: The returned string is not necessairly correct for FORTRAN output, but the results will be correct when passed to draw_string () or draw_rotated_string (). ------------------------------------------------------------------------------ call destroy_window () This subroutine destroys the graphics window. NOTE: This is not a particularly useful subroutine, because it 1) does not return the program from initialize_window (it is still in an infinite loop), and 2) it does not end the program. ------------------------------------------------------------------------------ call draw_arc (INTEGER x_pos this is screen pixels INTEGER y_pos this is screen pixels INTEGER ellipse_width this is screen pixels INTEGER ellipse height this is screen pixels REAL starting_angle this is in degrees, 3 O'clock = 0 degrees REAL endding_angle this is in degrees, 3 O'clock = 0 degrees INTEGER fill) 0 = No Fill, 1 = Fill This subroutine draws ellipse's. If the ellipse is not complete, and fill is turned on, the ellipse will be drawn as pie section. ------------------------------------------------------------------------------ call draw_gif (CHARACTER string() this is an array of characters, i.e. the GIF filename. INTEGER string_length) this is the number of characters in the string This subroutine uses xv to draw a GIF (or several other type of graphic pixmap files) to its own window. NOTE: You do not have to use initialize_window () to use this subroutine. ------------------------------------------------------------------------------ call draw_integer (INTEGER x_pos this is screen pixels INTEGER y_pos this is screen pixels INTEGER number) this is an integer value This subroutine draws an integer number at the specified location (left justified) with the active font and color. ------------------------------------------------------------------------------ call draw_line (INTEGER begin_x this is screen pixels INTEGER begin_y this is screen pixels INTEGER end_x this is screen pixels INTEGER end_y) this is screen pixels This subroutine draws a line between two points. ------------------------------------------------------------------------------ call draw_point (INTEGER x_pos this is screen pixels INTEGER y_pos) this is screen pixels This subroutine draws a point at the defined pixel location. ------------------------------------------------------------------------------ call draw_polygon (INTEGER x_pos() array of X screen pixels locations INTEGER y_pos() array of Y screen pixels locations INTEGER number_of_points_in_polygon INTEGER fill 0 = No Fill, 1 = Fill INTEGER shape 0 = Complex, 1 = Nonconvex, 2 = Convex INTEGER mode) 0 = CoordModeOrigin, 1 = CoordModePrevious This subroutine draws a series of connected lines and fills the defined area if requested. The way the area will be filled is specified with the shape rule. If the CoordModePrevious mode is use, the fisrt X-Y array position specifies where the polygon will start; each successive point will desribe the relative movement from the last point. ------------------------------------------------------------------------------ call draw_rectangle (INTEGER x_pos this is screen pixels INTEGER y_pos this is screen pixels INTEGER width this is screen pixels INTEGER height this is screen pixels INTEGER fill) 0 = No Fill, 1 = Fill This subroutine draws rectangles. ------------------------------------------------------------------------------ call draw_rotated_string (INTEGER x_pos this is screen pixels INTEGER y_pos this is screen pixels REAL angle this is rotation angle in degrees (+X = 0 degrees) INTEGER position this is a position flag CHARACTER string() this is an array of characters INTEGER string_length) this is the number of characters in the string This subroutine draws a character string rotated to the desired angle. There are several test postion options: NONE = 0 TOP LEFT = 1 TOP CENTER = 2 TOP RIGHT = 3 MIDDLE LEFT = 4 MIDDLE CENTER = 5 MIDDLE RIGHT = 6 BOTTOM LEFT = 7 BOTTOM CENTER = 8 BOTTOM RIGHT = 9 ------------------------------------------------------------------------------ call draw_string (INTEGER x_pos this is screen pixels INTEGER y_pos this is screen pixels CHARACTER string() this is an array of characters INTEGER string_length) this is the number of characters in the string This subroutine draws a character string. ------------------------------------------------------------------------------ call define_main_menu_item (INTEGER menu_item_ID this is the menu ID; start at 1 and increment up CHARACTER menu_label() this is the menu label CHARACTER menu_hot_key this is a shortcut key for enacting the menu item INTEGER menu_label_length this is the number of characters in the menu_label INTEGER sub_menus) this is the number of sub-menus below this item This subroutine initializes one main-menu item NOTE: Each main-menu item must have at least one sub-menu item NOTE: This subroutine must be called after setup_main_menu () NOTE: This subroutine must preceed the subroutines define_sub_menu_item (), which define this menu items sub-menus. ------------------------------------------------------------------------------ call define_sub_menu_item (INTEGER parent_menu_ID this is the parent menu ID. See define_main_menu_item () INTEGER sub_menu_item_ID this is the menu ID; start at 1 and increment up for each pull-down menu series CHARACTER menu_label() this is the menu label CHARACTER menu_hot_key this is a shortcut key for enacting the menu item INTEGER menu_label_length this is the number of characters in the menu_label EXTERNAL menu_subroutine) this is the FORTRAN subroutine that should be called when this sub-menu item is selected. This subroutine initializes one main-menu item NOTE: Before the menu_subroutine () is called in FORTRAN, it MUST be declared EXTERNAL. The program will terminate otherwise. NOTE: This subroutine must be called after setup_main_menu () and after define_main_menu_item () ------------------------------------------------------------------------------ call enter_integer (INTEGER x_pos this is screen pixels INTEGER y_pos this is screen pixels INTEGER number this is an integer value) This subroutine allows an user to enter an integer value. When the subroutine is first called, the old value will be drawn in the background color (see set_string_background (), hides old entry). As the new number is typed, the number will be drawn in string entry color (see set_string_entry_color ()). When done entering the number, press. When the number is entered the number will be rewritten in foreground (see set_color ()). NOTE: Backspace does not work. Missed type numbers currently cannot be corrected without recalling subroutine. ------------------------------------------------------------------------------ call enter_string (INTEGER x_pos this is screen pixels INTEGER y_pos this is screen pixels CHARACTER string() this is the returned character string INTEGER max_len this is the maximum allowed string length INTEGER string_len this is the actual length of returned string 0) this is a dummy entry (used by graphix.c internal calls) This subroutine allows an user to enter a character string. When the subroutine is first called, the old value will be drawn in the background color (see set_string_background (), hides old entry). As the new number is typed, the number will be drawn in string entry color (see set_string_entry_color ()). When done entering the number, press . When the number is entered the number will be rewritten in foreground (see set_color ()). NOTE: Backspace does not work. Missed type numbers currently cannot be corrected without recalling subroutine. ------------------------------------------------------------------------------ call get_mouse_pos (INTEGER x this is returned mouse X coordinate in window pixels INTEGER y) this is returned mouse Y coordinate in window pixels This subroutine is used to get the position of the mouse when a mouse button is pressed, released, or moved. For this subroutine to work correctly, event ID's must be specified in initialize_window for each desired option (press, release, move). The movement, press, or release of the mouse or mouse button cause an event. ------------------------------------------------------------------------------ call get_string_width (CHARACTER string() this is an array of characters INTEGER string_width this is screen pixels INTEGER string_length) this is the number of characters in the string This subroutine is used to determine how wide the character string is in pixels. This is useful for centering or left justifying text. ------------------------------------------------------------------------------ call set_color (INTEGER color) Valid color ID's are listed below. This subroutine is called to redefine the default graphics and text color. ------------------------------------------------------------------------------ call set_font (CHARACTER font_name() valid font names are listed below INTEGER font_size this is desired font size in pixels INTEGER font_name_length) this is the number of characters in the font_name This subroutine attempts to set the default font and font size as specified. If the font_name cannot be found (Different computers have different font sets) a default font is selected. If the desired size is not available, the nearest available font size will be used. ------------------------------------------------------------------------------ call set_key_event (INTEGER event_id) Valid ID's are > 0 This subroutine respecifies which key pressed decision menu will be used in event_handler (). ------------------------------------------------------------------------------ call set_mouse_events (INTEGER button_press_event_id, Valid ID's are >= 0 INTEGER button_release_event_id, Valid ID's are >= 0 INTEGER mouse_move_event_id) Valid ID's are >= 0 This subroutine respecifies which mouse events will be used in event_handler (). ------------------------------------------------------------------------------ call set_plot_event (INTEGER event_id) Valid ID's are > 0 This subroutine respecifies which plot event will be used in event_handler (). ------------------------------------------------------------------------------ call set_string_background (INTEGER color) See valid color ID's below This subroutine sets the background color for input data strings and numbers. ------------------------------------------------------------------------------ call set_string_entry_color (INTEGER color) See valid color ID's below This subroutine sets the entry color for input data strings and numbers. ------------------------------------------------------------------------------ call set_string_foreground (INTEGER color) See valid color ID's below This subroutine sets the foreground color for input data strings and numbers. ------------------------------------------------------------------------------ call setup_main_menu (INTEGER main_menu_items this is the number of main menu options INTEGER max_sub_menus) this is the maximum number of sub-menu options This subroutine initializes the pull-down menu structure. NOTE: When initialize_window () is called, the 'use_menu' variable must be set to '1' if you use this subroutine. NOTE: This subroutine may only be called once. NOTE: This subroutine must preceed the subroutines define_main_menu_item () and define_sub_menu_item (). ------------------------------------------------------------------------------ call unix_system (CHARACTER string()) this is an array of characters This subroutine used to execute a UNIX system command. NOTE: You do not have to use initialize_window () to use this subroutine. -------------------------------------------------------------------------------- Valid Color ID's BLACK = 0 WHITE = 1 RED = 2 GREEN = 3 BLUE = 4 MAGENTA = 5 YELLOW = 6 CYAN = 7 DARKGREEN = 12 DARKGRAY = 13 Valid Fonts: Font names must be in single quotation marks ('') and type exactly as shown with no leading or trailing spaces. Avant Garde-Book Avant Garde-Book Oblique Avant Garde-Demi Avant Garde-Demi Oblique Courier Courier-Bold Courier-Bold Oblique Courier-Oblique Helvetica Helvetica-Bold Helvetica-Bold Oblique Helvetica-Oblique New Century School Book-Bold New Century School Book-Bold Italic New Century School Book-Italic New Century School Book-Roman Palatino-Bold Palatino-Bold Italic Palatino-Italic Palatino-Roman Symbol Times-Bold Times-Bold Italic Times-Italic Times-Roman Zapf Chancery-Medium Italic Zapf Dingbats
NOTE: It is assumed that you have used initialize_window () to create an X-Windows window before you call these routines.
------------------------------------------------------------------------------ call check_tic_frequency (REAL dx, X width of graph (RETURN VALUE) REAL dy, Y height of graph (RETURN VALUE) REAL xmin, mininum X data/graph value REAL xmax, maxinum X data/graph value REAL ymin, mininum Y data/graph value REAL ymax, maxinum Y data/graph value INTEGER x_type, X axis type INTEGER y_type, Y axis type REAL x_main_freq, X axis main tic frequency REAL y_main_freq, Y axis main tic frequency) This subroutine used to define the extents of the X-Y graph. The dx and dy terms are RETURN VALUES. ------------------------------------------------------------------------------ call draw_axis (INTEGER x_shift, X world -> screen shift INTEGER y_shift, Y world -> screen shift REAL x_scale, X world -> screen conversion scale REAL y_scale, Y world -> screen conversion scale REAL xmin, mininum X data/graph value REAL xmax, maxinum X data/graph value REAL ymin, mininum Y data/graph value REAL ymax, maxinum Y data/graph value INTEGER x_type, X axis type INTEGER y_type, Y axis type REAL x_main_freq, X axis main tic frequency INTEGER x_minor_freq, X axis minor tic frequency REAL y_main_freq, Y axis main tic frequency INTEGER y_minor_freq, Y axis minor tic frequency INTEGER x_decimals, # of decimals for X tic labels INTEGER y_decimals, # of decimals for Y tic labels INTEGER y_length maximum character length to Y tic labels (RETURN VALUE)) This subroutine draws the X-Y graph border, axes tic, and axes tic labels. It also returns the maximum number of characters used in a y tic label (y_length) This is used by draw_plot_labels () to position the Y-axis label. The x_shift, y_shift, x_scale, and y_scale terms are defined in set_scaling (). ------------------------------------------------------------------------------ call draw_plot_labels (CHARACTER title() graph main title INTEGER title_len length of title character string CHARACTER secondary_title() graph secondary title INTEGER second_title_len length of secondary character string CHARACTER x_label() graph X label INTEGER x_label_len length of X label character string CHARACTER y_label() graph Y label INTEGER y_label_len length of Y label character string INTEGER x_shift, X world -> screen shift INTEGER y_shift, Y world -> screen shift INTEGER width, X-Window width INTEGER height, X-Window height INTEGER y_length maximum character length to Y tic labels) This subroutine used to plot labels around the X-Y graph. The x_shift and y_shift terms are defined by srt_scaling () and y_length is defined by draw_axis (). NOTE: The secondary title is optional. It will only be plotted when the second_title_len is greater then 0. NOTE: All text is currently assumed to be 12 pixels in height. Using other fonts sizes may cause overlap with graphics. ------------------------------------------------------------------------------ call draw_symbol (REAL x_pos, X point position REAL y_pos, Y point position INTEGER x_shift, X world -> screen shift INTEGER y_shift, Y world -> screen shift REAL x_scale, X world -> screen conversion scale REAL y_scale, Y world -> screen conversion scale REAL xmin, mininum X data/graph value REAL ymax, maxinum Y data/graph value INTEGER symbol_type, point symbol type INTEGER symbol_size, size of symbol in pixels) This subroutine is used to post points within the X-Y graph. Valid Symbol Types: NO_SYMBOL = -1 CIRCLE = 0 CROSS = 1 DIAMOND = 2 SQUARE = 3 X = 4 ------------------------------------------------------------------------------ call set_scaling (REAL dx, X width of graph REAL dy, Y height of graph INTEGER right_margin, right graph margin in pixels INTEGER left_margin, left graph margin in pixels INTEGER top_margin, top graph margin in pixels INTEGER bottom_margin, bottom graph margin in pixels REAL x_scale, X world -> screen conversion scale (RETURN VALUE) REAL y_scale, Y world -> screen conversion scale (RETURN VALUE) INTEGER x_shift, X world -> screen shift (RETURN VALUE) INTEGER y_shift, Y world -> screen shift (RETURN VALUE) INTEGER width, X-Window width INTEGER height, X-Window height INTEGER scale_priority, graph sizing rule (0 = X/Y axis ratio, 1 = Y exaggeration factor) REAL priority_factor, graph Y exaggeration or X/Y axis ratio depending on scale_priority rule) This subroutine used to define the the X and Y scale factors, and determine how far points need to be shifted in the X-Window, so that the fall correctly within the graph. -------------------------------------------------------------------------------- Valid Axes Types: NORMAL_AXES = 0 LOG_X_AXES = 1 LOG_Y_AXES = 2 LOG_LOG_AXES = 3