/* ************************************************************* */ /* INCLUDE FILES */ #include #include #include #include #include "movezparam.h" #include "movez.h" #include "vscanparam.h" #include "vscan.h" #include "vscanui.h" #include "calib.h" #include "bscanparam.h" #include "bscan.h" #include "bscanui.h" /* ************************************************************* */ /* PRIVATE FUNCTIONS */ void bscanop_init(void); void bscanop_exit(void); void bscanop_generate_test_calib(void); /* ************************************************************* */ int main(int argc, char *argv[]) { /* Perform all initialization for the program */ bscanop_init(); /* Generate test calibration data if desired */ bscanop_generate_test_calib(); /* Run the user interface */ RunUserInterface(); /* Exit all systems */ bscanop_exit(); /* Message */ printf("\nDone\n"); /* Done */ return 0; } /* ************************************************************** */ void bscanop_init(void) { /* Declare variables */ char log_file[80]; char plt_file[80]; FILE* file_ptr; struct movez_param_struct movez_param; struct vscan_param_struct vscan_param; struct bscan_param_struct bscan_param; /* Initialize the log file */ strcpy(log_file, "testlog.ru1"); file_ptr = fopen(log_file, "w"); if (file_ptr == NULL) return; fclose(file_ptr); /* Initialize the plot file */ strcpy(plt_file, "testplt.ru1"); file_ptr = fopen(plt_file, "w"); if (file_ptr == NULL) return; fclose(file_ptr); /* Get parameters */ movezparam_fill_param_struct(&movez_param); vscanparam_fill_param_struct(&vscan_param); bscanparam_fill_param_struct(&bscan_param); /* Initialize all systems */ movez_init(log_file, movez_param); vscan_init(log_file, vscan_param); bscan_init(log_file, plt_file, bscan_param); /* Initialize the user interface */ SetStdioWindowPosition(430, 15); SetStdioWindowSize(300, 995); vscanui_init(25, 15, vscan_param); bscanui_init(25, 350, bscan_param); bscanopui_init(25, 685); /* Done */ return; } /* ************************************************************** */ void bscanop_exit(void) { /* Exit all systems */ movez_exit(); vscan_exit(); bscan_exit(); /* Done */ return; } /* ************************************************************* */ void bscanop_generate_test_calib(void) { /* Declare variables */ char probe_name[80]; int i; int num_meas_val = 100; double meas_val[100]; double calib_out_val[100]; double true_val[100]; double error[100]; FILE* file_ptr; /* Generate fake calibration data */ calib_create_test_calib_data_file(); /* Have the calibration utility use the fake data */ calib_read_calib_data_file("test_calib_file.dat"); /* Check the probe name */ calib_get_probe_name(probe_name); if (strcmp(probe_name, "test_calib") != 0) printf("Problem with the calibration data.\n"); /* Plot the residuals of the calibration function */ calib_plot_residuals(); /* Generate fake measurement data */ for (i = 0; i < num_meas_val; i++) { meas_val[i] = 2. * (double)(i - (num_meas_val - 1) / 2.) / (double)((num_meas_val - 1) / 2.); } /* Apply the calibration */ calib_apply_calib_data(num_meas_val, meas_val, calib_out_val); /* Compare the calibrated output to the expected value */ for (i = 0; i < num_meas_val; i++) { calib_create_test_calib_data(meas_val[i], &true_val[i]); error[i] = true_val[i] - calib_out_val[i]; } /* Record the results */ file_ptr = fopen("test_calib_results.dat", "w"); if (file_ptr == NULL) return; /* Write the values to the plt file */ fprintf(file_ptr, "%% meas_val, true_val, calib_out_val, error\n"); for (i = 0; i < num_meas_val; i++) fprintf(file_ptr, "%f %f %f %f\n", meas_val[i], true_val[i], calib_out_val[i], error[i]); /* Close the plt file */ fclose(file_ptr); /* Done */ return; }