/* ************************************************************** */ /* * Module BLHARPARAM * This module contains functions to assist in parameter handling * for the BLHAR module. * * Zachary Wolf * 11/23/99 */ /* ************************************************************** */ /* INCLUDES */ #include #include #include "blhar.h" /* ************************************************************* */ /* PRIVATE FUNCTION DECLARATIONS */ void blharparam_get_coil_param(char* coil_param_file, struct coil_param_struct* coil_param); void blharparam_error(char* message); /* ************************************************************** */ /* PUBLIC FUNCTIONS */ /* ************************************************************** */ /* * blharparam_fill_param_struct * This function fills the parameter structure using # defined * parameters. * * Zachary Wolf * 11/23/99 */ void blharparam_fill_param_struct(struct blhar_param_struct* blhar_param) { /* Include parameter definitions */ #include "param.h" /* Set the BL harmonics parameters */ blhar_param->num_har = BLHAR_NUM_HAR; blhar_param->num_main_harmonic = BLHAR_NUM_MAIN_HARMONIC; blhar_param->num_meas_ave = BLHAR_NUM_MEAS_AVE; blhar_param->integ_chan = BLHAR_INTEG_CHAN; blhar_param->num_rev_per_meas = BLHAR_NUM_REV_PER_MEAS; blhar_param->reference_radius = BLHAR_REFERENCE_RADIUS; blharparam_get_coil_param(BLHAR_COIL_PARAM_FILE, &(*blhar_param).coil_param); strcpy(blhar_param->magnet_view, BLHAR_MAGNET_VIEW); blhar_param->show_ui = BLHAR_SHOW_UI; /* Done */ return; } /* ************************************************************** */ /* PRIVATE FUNCTIONS */ /* ************************************************************** */ /* * blharparam_get_coil_param * This function opens the coil parameter file and reads in the * coil parameters. * * Input: * coil_param_file, character string giving the name of the coil parameter file * * Output: * coil_param, structure containing all the coil parameters * * Zachary Wolf * 6/25/99 */ void blharparam_get_coil_param(char* coil_param_file, struct coil_param_struct* coil_param) { /* Declare variables */ FILE* file_ptr; char buf[80]; int err; int i; /* Open the coil parameter file */ file_ptr = fopen (coil_param_file, "r"); if (file_ptr == NULL) { blharparam_error("Could not open coil parameter file."); return; } /* The first two lines of the file is a general header */ fgets(buf, 80, file_ptr); fgets(buf, 80, file_ptr); /* Type of magnet the strength coil is calibrated for */ fgets(buf, 80, file_ptr); if (strstr(buf, "str_coil_type") == NULL) { blharparam_error("Error reading str_coil_type!"); return; } err = fscanf(file_ptr, "%s\n", (*coil_param).str_coil_type); if (err != 1) { blharparam_error("Error reading str_coil_type!"); return; } /* Strength coil multiplexer channel */ fgets(buf, 80, file_ptr); if (strstr(buf, "str_coil_mux_chan") == NULL) { blharparam_error("Error reading str_coil_mux_chan!"); return; } err = fscanf(file_ptr, "%i\n", &coil_param->str_coil_mux_chan); if (err != 1) { blharparam_error("Error reading str_coil_mux_chan!"); return; } /* Strength coil constant */ fgets(buf, 80, file_ptr); if (strstr(buf, "str_coil_constant") == NULL) { blharparam_error("Error reading str_coil_constant!"); return; } err = fscanf(file_ptr, "%lf\n", &coil_param->str_coil_constant); if (err != 1) { blharparam_error("Error reading str_coil_constant!"); return; } /* Main coil radius */ fgets(buf, 80, file_ptr); if (strstr(buf, "main_coil_radius") == NULL) { blharparam_error("Error reading main_coil_radius!"); return; } err = fscanf(file_ptr, "%lf\n", &coil_param->main_coil_radius); if (err != 1) { blharparam_error("Error reading main_coil_radius!"); return; } /* Main coil number of turns */ fgets(buf, 80, file_ptr); if (strstr(buf, "main_coil_num_turns") == NULL) { blharparam_error("Error reading main_coil_num_turns!"); return; } err = fscanf(file_ptr, "%i\n", &coil_param->main_coil_num_turns); if (err != 1) { blharparam_error("Error reading main_coil_num_turns!"); return; } /* Main coil multiplexer channel */ fgets(buf, 80, file_ptr); if (strstr(buf, "main_coil_mux_chan") == NULL) { blharparam_error("Error reading main_coil_mux_chan!"); return; } err = fscanf(file_ptr, "%i\n", &coil_param->main_coil_mux_chan); if (err != 1) { blharparam_error("Error reading main_coil_mux_chan!"); return; } /* Bucked coil multiplexer channel */ fgets(buf, 80, file_ptr); if (strstr(buf, "bucked_coil_mux_chan") == NULL) { blharparam_error("Error reading bucked_coil_mux_chan!"); return; } err = fscanf(file_ptr, "%i\n", &coil_param->bucked_coil_mux_chan); if (err != 1) { blharparam_error("Error reading bucked_coil_mux_chan!"); return; } /* Coil to use for harmonics measurements */ fgets(buf, 80, file_ptr); if (strstr(buf, "coil_for_harmonics") == NULL) { blharparam_error("Error reading coil_for_harmonics!"); return; } err = fscanf(file_ptr, "%s\n", (*coil_param).coil_for_harmonics); if (err != 1) { blharparam_error("Error reading coil_for_harmonics!"); return; } /* Number of sensitivity factors */ fgets(buf, 80, file_ptr); if (strstr(buf, "num_sens_factors") == NULL) { blharparam_error("Error reading num_sens_factors!"); return; } err = fscanf(file_ptr, "%i\n", &coil_param->num_sens_factors); if (err != 1) { blharparam_error("Error reading num_sens_factors!"); return; } /* Main coil sensitivity factors */ fgets(buf, 80, file_ptr); if (strstr(buf, "main_coil_sens_factors") == NULL) { blharparam_error("Error reading main_coil_sens_factors!"); return; } for (i = 1; i <= coil_param->num_sens_factors; i++) { err = fscanf(file_ptr, "%lf\n", &coil_param->main_coil_sens_factors[i]); if (err != 1) { blharparam_error("Error reading main_coil_sens_factors!"); return; } } /* Bucked coil sensitivity factors */ fgets(buf, 80, file_ptr); if (strstr(buf, "bucked_coil_sens_factors") == NULL) { blharparam_error("Error reading bucked_coil_sens_factors!"); return; } for (i = 1; i <= coil_param->num_sens_factors; i++) { err = fscanf(file_ptr, "%lf\n", &coil_param->bucked_coil_sens_factors[i]); if (err != 1) { blharparam_error("Error reading bucked_coil_sens_factors!"); return; } } /* Close the coil parameter file */ fclose(file_ptr); /* Done */ return; } /* ************************************************************** */ /* * blharparam_error * This function handles errors for the BLHARPARAM module. * * Input: * message, string to display in standard I/O * * Zachary Wolf * 11/23/99 */ void blharparam_error(char* message) { /* Declare variables */ char buf[80]; /* Notify the operator of the error */ printf("\nERROR: %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); }