/* ************************************************************** */ /* * Module BLHARUI * This module contains functions for the integrated harmonic * strength measurement user interface. * * Zachary Wolf * 10/2/00 */ /* ************************************************************** */ /* INCLUDES */ #include #include #include /* Needed if linking in external compiler; harmless otherwise */ #include #include #include "blharuir.h" #include "blharui.h" #include "blhar.h" /* ************************************************************** */ /* PRIVATE PARAMETERS */ static struct blhar_param_struct blhar_param; /* ************************************************************** */ /* PRIVATE VARIABLES */ static int blhar_panel; /* ************************************************************** */ /* PRIVATE FUNCTION DECLARATIONS */ void blharui_error(char* msg); /* ************************************************************** */ /* PUBLIC FUNCTIONS */ /* ************************************************************** */ /* * blharui_init * This function initializes the user interface for the BLHAR system. * * Input: * top_pos, vertical position of top left panel corner in screen coordinates * left_pos, horizontal position of top left panel corner in screen coordinates * blhar_par, blhar system parameters * * Zachary Wolf * 10/2/00 */ void blharui_init(int top_pos, int left_pos, struct blhar_param_struct blhar_param_in) { /* Save parameters for future use */ blhar_param = blhar_param_in; /* Make sure the user interface panel is desired */ if (blhar_param.show_ui != BLHAR_TRUE) return; /* Open the BLHAR panel */ blhar_panel = LoadPanel(0, "blharuir.uir", BLHARPAN); if (blhar_panel < 0) { blharui_error("Could not open user interface panel"); return; } /* Set the panel position */ SetPanelPos(blhar_panel, top_pos, left_pos); /* Display the panel */ DisplayPanel(blhar_panel); /* Done */ return; } /* ************************************************************** */ /* * blharui_scale_str_vs_imag * This function sets the scale on the horizontal axis of the strength * vs Imag plot. * * Input: * num_imag, number of magnet currents * imag[0 to num_imag - 1], magnet currents * * Zachary Wolf * 10/2/00 */ void blharui_scale_str_vs_imag(int num_imag, double imag[]) { /* Declare variables */ double i_min, i_max; int min_index, max_index; double i_min_plt, i_max_plt; /* Make sure the user interface panel is being used */ if (blhar_param.show_ui != BLHAR_TRUE) return; /* Determine the minimum and maximum magnet currents */ MaxMin1D(imag, num_imag, &i_max, &max_index, &i_min, &min_index); i_min_plt = i_min - .01 * (i_max - i_min) - 1.; i_max_plt = i_max + .01 * (i_max - i_min) + 1.; i_min_plt = floor(i_min_plt); i_max_plt = ceil(i_max_plt); if (i_min_plt > 0.) i_min_plt = 0.; /* Set the horizontal scale of the BL vs X plot */ SetAxisRange(blhar_panel, BLHARPAN_GRAPH_STR_VS_I, VAL_MANUAL, i_min_plt, i_max_plt, VAL_AUTOSCALE, 0., 0.); /* Done */ return; } /* ************************************************************** */ /* * blharui_update_str_vs_imag * This function adds measured points to the strength vs Imag plot. * * Input: * imag, magnet current (A) * str_ave, average of the magnet strength measurements (Tm/m^(n-1)) * str_rms, rms variation of the magnet strength measurements (Tm/m^(n-1)) * * Zachary Wolf * 10/2/00 */ void blharui_update_str_vs_imag(double imag, double str_ave, double str_rms) { /* Check for the user interface */ if (blhar_param.show_ui != BLHAR_TRUE) return; /* Plot the magnet strength sample */ PlotPoint(blhar_panel, BLHARPAN_GRAPH_STR_VS_I, imag, str_ave, VAL_SOLID_SQUARE, VAL_RED); /* Done */ return; } /* ************************************************************** */ /* * blharui_clear_str_vs_imag * This function clears the strength vs Imag plot. * * Zachary Wolf * 10/2/00 */ void blharui_clear_str_vs_imag(void) { /* Check for the user interface */ if (blhar_param.show_ui != BLHAR_TRUE) return; /* Remove previous plot */ DeleteGraphPlot(blhar_panel, BLHARPAN_GRAPH_STR_VS_I, -1, VAL_IMMEDIATE_DRAW); /* Done */ return; } /* ************************************************************** */ /* * blharui_scale_bln_vs_n * This function sets the scale on the horizontal axis of the BLn vs n * plot. * * Zachary Wolf * 10/2/00 */ void blharui_scale_bln_vs_n(void) { /* Make sure the user interface panel is being used */ if (blhar_param.show_ui != BLHAR_TRUE) return; /* Set the horizontal scale of the BLn vs n plot */ SetAxisRange(blhar_panel, BLHARPAN_GRAPH_BLn_VS_n, VAL_MANUAL, 0, (double)blhar_param.num_har, VAL_AUTOSCALE, 0., 0.); /* Done */ return; } /* ************************************************************** */ /* * blharui_update_bln_vs_n * This function adds measured points to the BLn vs n plot. * * Input: * blhar_data, harmonics data structure * * Zachary Wolf * 10/2/00 */ void blharui_update_bln_vs_n(struct blhar_data_struct blhar_data) { /* Declare variables */ double har_number[BLHAR_MAX_NUM_HAR + 1]; double BLn_mag[BLHAR_MAX_NUM_HAR + 1]; int i; /* Check for the user interface */ if (blhar_param.show_ui != BLHAR_TRUE) return; /* Fill the harmonic number array */ for (i = 0; i <= blhar_data.num_har; i++) har_number[i] = (double)i; /* Fill the harmonic magnitude array (handles the zero'th term) */ BLn_mag[0] = 0.; for (i = 1; i <= blhar_data.num_har; i++) BLn_mag[i] = blhar_data.BLn_mag_ave[i]; /* Plot the BLn samples */ PlotXY(blhar_panel, BLHARPAN_GRAPH_BLn_VS_n, har_number, BLn_mag, blhar_data.num_har + 1, VAL_DOUBLE, VAL_DOUBLE, VAL_VERTICAL_BAR, VAL_SMALL_SOLID_SQUARE, VAL_SOLID, 1, VAL_BLUE); /* Done */ return; } /* ************************************************************** */ /* * blharui_clear_bln_vs_n * This function clears the BLn vs n plot. * * Zachary Wolf * 10/2/00 */ void blharui_clear_bln_vs_n(void) { /* Check for the user interface */ if (blhar_param.show_ui != BLHAR_TRUE) return; /* Remove previous plot */ DeleteGraphPlot(blhar_panel, BLHARPAN_GRAPH_BLn_VS_n, -1, VAL_IMMEDIATE_DRAW); /* Done */ return; } /* ************************************************************** */ /* PRIVATE FUNCTIONS */ /* ************************************************************** */ /* * blharui_error * This function handles error messages for the BLHAR user interface. * * Input: * message, string to display in standard I/O * * Zachary Wolf * 9/18/98 */ void blharui_error(char* message) { /* Declare variables */ char buf[80]; /* Notify the operator of the error */ printf("\nBLHARUI ERROR: %s\n", message); Beep(); Delay(.5); Beep(); /* Terminate the program if the operator desires */ printf("Press ENTER to continue.\nPress any key then ENTER to terminate program.\n"); fgets(buf, 80, stdin); if (buf[0] == '\n') return; else exit(0); }