/* ************************************************************** */ /* * Module RUNPARAMUI * This module contains functions for the run parameter user * interface. * * Zachary Wolf * 11/19/99 */ /* ************************************************************** */ /* INCLUDES */ #include #include #include #include #include "runparam.h" #include "runparamui.h" #include "runparamuir.h" /* ************************************************************** */ /* PRIVATE VARIABLES */ static struct run_param_struct run_param; static int run_param_panel; static int ui_status; /* ************************************************************** */ /* PRIVATE FUNCTION PROTOTYPES */ void runparamui_error(char* message); void runparamui_get_last_run(struct run_param_struct* run_param_last); void runparamui_save_last_run(struct run_param_struct run_param_last); /* ************************************************************** */ /* PUBLIC FUNCTIONS */ /* ************************************************************** */ /* * runparamui_get_run_param * This function gets the run parameters from the user. * * Zachary Wolf * 11/19/99 */ void runparamui_get_run_param(struct run_param_struct* run_param_in) { /* Declare variables */ static int num_call; int run_num; int n; /* Load the run parameter panel */ run_param_panel = LoadPanel(0, "c:\\dataccvi\\lib\\utilities\\run parameters\\runparamuir.uir", PAN_RUNPAR); if (run_param_panel < 0) { runparamui_error("Could not open run parameter user interface panel"); return; } /* Increment the number of times called */ num_call++; /* On the first call, get the parameters from the previous run, increment the run number */ if (num_call == 1) { runparamui_get_last_run(&run_param); n = Scan(run_param.run_num, "%s>%i", &run_num); if (n == 1) { run_num++; Fmt(run_param.run_num, "%s<%i", run_num); } SetCtrlVal(run_param_panel, PAN_RUNPAR_TXT_project, run_param.project); SetCtrlVal(run_param_panel, PAN_RUNPAR_TXT_mag_type, run_param.mag_type); SetCtrlVal(run_param_panel, PAN_RUNPAR_TXT_mag_name, run_param.mag_name); SetCtrlVal(run_param_panel, PAN_RUNPAR_TXT_serial_num, run_param.ser_num); SetCtrlVal(run_param_panel, PAN_RUNPAR_TXT_run_num, run_param.run_num); SetCtrlVal(run_param_panel, PAN_RUNPAR_TXT_meas_dev, run_param.meas_dev); SetCtrlVal(run_param_panel, PAN_RUNPAR_TXT_operator, run_param.operator); SetCtrlVal(run_param_panel, PAN_RUNPAR_TXT_comment, run_param.comment); } /* After the first call, display what the operator has already entered */ if (num_call > 1) { SetCtrlVal(run_param_panel, PAN_RUNPAR_TXT_project, run_param.project); SetCtrlVal(run_param_panel, PAN_RUNPAR_TXT_mag_type, run_param.mag_type); SetCtrlVal(run_param_panel, PAN_RUNPAR_TXT_mag_name, run_param.mag_name); SetCtrlVal(run_param_panel, PAN_RUNPAR_TXT_serial_num, run_param.ser_num); SetCtrlVal(run_param_panel, PAN_RUNPAR_TXT_run_num, run_param.run_num); SetCtrlVal(run_param_panel, PAN_RUNPAR_TXT_meas_dev, run_param.meas_dev); SetCtrlVal(run_param_panel, PAN_RUNPAR_TXT_operator, run_param.operator); SetCtrlVal(run_param_panel, PAN_RUNPAR_TXT_comment, run_param.comment); } /* Display the panel */ DisplayPanel(run_param_panel); /* Run the user interface until the operator presses OK */ ui_status = RunUserInterface(); /* Remove the panel */ DiscardPanel(run_param_panel); /* Return the run parameters */ *run_param_in = run_param; /* Save the run parameters for the next run */ runparamui_save_last_run(run_param); /* Done */ return; } /* ************************************************************** */ /* PRIVATE FUNCTIONS */ /* ************************************************************** */ /* * runparamui_error * This function handles errors for the RUNPARAMUI module. * * Input: * message, string to display in standard I/O * * Zachary Wolf * 11/19/99 */ void runparamui_error(char* message) { /* Declare variables */ char buf[80]; /* Notify the operator of the error */ printf("\nRUNPARAMUI 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); } /* ************************************************************** */ /* * runparamui_get_last_run * This function opens the file containing the run parameters from * the last run. * * Output: * run_param_last, structure containing all the run parameters from the last run * * Zachary Wolf * 11/19/99 */ void runparamui_get_last_run(struct run_param_struct* run_param_last) { /* Declare variables */ FILE* file_ptr; char buf[RUNPARAM_MAX_NUM_CHAR + 1]; int n; /* Open the run parameter file */ SetBreakOnLibraryErrors(0); file_ptr = fopen ("runparam.dat", "r"); SetBreakOnLibraryErrors(1); /* If the file could not be opened, return empty strings */ if (file_ptr == NULL) { strcpy(run_param_last->project, ""); strcpy(run_param_last->mag_type, ""); strcpy(run_param_last->mag_name, ""); strcpy(run_param_last->ser_num, ""); strcpy(run_param_last->run_num, ""); strcpy(run_param_last->meas_dev, ""); strcpy(run_param_last->operator, ""); strcpy(run_param_last->comment, ""); return; } /* Read the parameters from the last run, except for the comment */ fgets(buf, RUNPARAM_MAX_NUM_CHAR, file_ptr); n = Scan(buf, "%s>project: %s\n", run_param_last->project); if (n < 1) strcpy(run_param_last->project, ""); fgets(buf, RUNPARAM_MAX_NUM_CHAR, file_ptr); n = Scan(buf, "%s>mag_type: %s\n", run_param_last->mag_type); if (n < 1) strcpy(run_param_last->mag_type, ""); fgets(buf, RUNPARAM_MAX_NUM_CHAR, file_ptr); n = Scan(buf, "%s>mag_name: %s\n", run_param_last->mag_name); if (n < 1) strcpy(run_param_last->mag_name, ""); fgets(buf, RUNPARAM_MAX_NUM_CHAR, file_ptr); n = Scan(buf, "%s>ser_num: %s\n", run_param_last->ser_num); if (n < 1) strcpy(run_param_last->ser_num, ""); fgets(buf, RUNPARAM_MAX_NUM_CHAR, file_ptr); n = Scan(buf, "%s>run_num: %s\n", run_param_last->run_num); if (n < 1) strcpy(run_param_last->run_num, ""); fgets(buf, RUNPARAM_MAX_NUM_CHAR, file_ptr); n = Scan(buf, "%s>meas_dev: %s[t10]\n", run_param_last->meas_dev); if (n < 1) strcpy(run_param_last->meas_dev, ""); fgets(buf, RUNPARAM_MAX_NUM_CHAR, file_ptr); n = Scan(buf, "%s>operator: %s[t10]\n", run_param_last->operator); if (n < 1) strcpy(run_param_last->operator, ""); strcpy(run_param_last->comment, ""); /* Close the coil parameter file */ fclose(file_ptr); /* Done */ return; } /* ************************************************************** */ /* * runparamui_save_last_run * This function saves the run parameters from the last run. * * Input: * run_param_last, structure containing all the run parameters * * Zachary Wolf * 11/19/99 */ void runparamui_save_last_run(struct run_param_struct run_param_last) { /* Declare variables */ FILE* file_ptr; /* Open the run parameter file */ file_ptr = fopen ("runparam.dat", "w"); if (file_ptr == NULL) { runparamui_error("Could not open run parameter file."); return; } /* Write the parameters from the last run, except for the comment */ fprintf(file_ptr, "project: %s\n", run_param_last.project); fprintf(file_ptr, "mag_type: %s\n", run_param_last.mag_type); fprintf(file_ptr, "mag_name: %s\n", run_param_last.mag_name); fprintf(file_ptr, "ser_num: %s\n", run_param_last.ser_num); fprintf(file_ptr, "run_num: %s\n", run_param_last.run_num); fprintf(file_ptr, "meas_dev: %s\n", run_param_last.meas_dev); fprintf(file_ptr, "operator: %s\n", run_param_last.operator); fprintf(file_ptr, "comment: %s\n", run_param_last.comment); /* Close the coil parameter file */ fclose(file_ptr); /* Done */ return; } /* ************************************************************** */ /* PRIVATE USER INTERFACE FUNCTIONS */ /* ************************************************************** */ int CVICALLBACK runparamui_ok (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { switch (event) { case EVENT_COMMIT: GetCtrlVal (panel, PAN_RUNPAR_TXT_project, run_param.project); GetCtrlVal (panel, PAN_RUNPAR_TXT_mag_type, run_param.mag_type); GetCtrlVal (panel, PAN_RUNPAR_TXT_mag_name, run_param.mag_name); GetCtrlVal (panel, PAN_RUNPAR_TXT_serial_num, run_param.ser_num); GetCtrlVal (panel, PAN_RUNPAR_TXT_run_num, run_param.run_num); GetCtrlVal (panel, PAN_RUNPAR_TXT_meas_dev, run_param.meas_dev); GetCtrlVal (panel, PAN_RUNPAR_TXT_operator, run_param.operator); GetCtrlVal (panel, PAN_RUNPAR_TXT_comment, run_param.comment); QuitUserInterface(ui_status); break; } return 0; }