From c4014a528b4568b6fb6301e7e0bf1bb047bda7a2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Michal=20Mal=C3=BD?= Date: Sat, 12 Jul 2014 01:26:07 +0200 Subject: [PATCH] Use the ChemStation version tag to diffentiate file types whose ID changed between different versions --- libhpcs.c | 30 ++++++++++++++++++++++++++---- libhpcs.h | 2 ++ libhpcs_p.h | 14 +++++++++++--- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/libhpcs.c b/libhpcs.c index fe4ecd6..1b348e7 100644 --- a/libhpcs.c +++ b/libhpcs.c @@ -136,7 +136,7 @@ enum HPCS_RetCode hpcs_read_file(const char* filename, struct HPCS_MeasuredData* ret = HPCS_E_PARSE_ERROR; goto out; } - pret = autodetect_file_type(datafile, &mdata->file_type); + pret = autodetect_file_type(datafile, &mdata->file_type, guess_p_meaning(mdata)); if (pret != PARSE_OK) { PR_DEBUG("Cannot determine the type of file\n"); ret = HPCS_E_PARSE_ERROR; @@ -157,14 +157,16 @@ enum HPCS_RetCode hpcs_read_file(const char* filename, struct HPCS_MeasuredData* pret = read_floating_signal(datafile, &mdata->data, &mdata->data_count, CE_CCD_STEP, mdata->sampling_rate); break; case HPCS_TYPE_CE_CURRENT: - pret = read_fixed_signal(datafile, &mdata->data, &mdata->data_count, CE_CURRENT_STEP, mdata->sampling_rate); + pret = read_fixed_signal(datafile, &mdata->data, &mdata->data_count, guess_current_step(mdata), mdata->sampling_rate); break; case HPCS_TYPE_CE_DAD: pret = read_fixed_signal(datafile, &mdata->data, &mdata->data_count, CE_DAD_STEP, mdata->sampling_rate); break; case HPCS_TYPE_CE_POWER: + case HPCS_TYPE_CE_PRESSURE: + case HPCS_TYPE_CE_TEMPERATURE: case HPCS_TYPE_CE_VOLTAGE: - pret = read_fixed_signal(datafile, &mdata->data, &mdata->data_count, CE_PWR_VOLT_STEP, mdata->sampling_rate); + pret = read_fixed_signal(datafile, &mdata->data, &mdata->data_count, CE_WORK_PARAM_STEP, mdata->sampling_rate); break; case HPCS_TYPE_UNKNOWN: ret = HPCS_E_UNKNOWN_TYPE; @@ -182,7 +184,7 @@ out: return ret; } -static enum HPCS_ParseCode autodetect_file_type(FILE* datafile, enum HPCS_File_Type* file_type) +static enum HPCS_ParseCode autodetect_file_type(FILE* datafile, enum HPCS_File_Type* file_type, const bool p_means_pressure) { char* type_id; enum HPCS_ParseCode pret; @@ -202,6 +204,10 @@ static enum HPCS_ParseCode autodetect_file_type(FILE* datafile, enum HPCS_File_T *file_type = HPCS_TYPE_CE_CURRENT; else if (hpce_id == FILE_TYPE_HPCE_POWER) *file_type = HPCS_TYPE_CE_POWER; + else if (hpce_id == FILE_TYPE_HPCE_POWER_PRESSURE) + *file_type = p_means_pressure ? HPCS_TYPE_CE_PRESSURE : HPCS_TYPE_CE_POWER; + else if (hpce_id == FILE_TYPE_HPCE_TEMPERATURE) + *file_type = HPCS_TYPE_CE_TEMPERATURE; else if (hpce_id == FILE_TYPE_HPCE_VOLTAGE) *file_type = HPCS_TYPE_CE_VOLTAGE; else @@ -223,6 +229,22 @@ static enum HPCS_DataCheckCode check_for_marker(const char* const segment, size_ return DCHECK_E_NO_MARKER; } +static HPCS_step guess_current_step(struct HPCS_MeasuredData* const mdata) +{ + if (strcmp(mdata->cs_ver, CHEMSTAT_VER_B0625) == 0) + return CE_CURRENT_STEP; + + return CE_WORK_PARAM_STEP; +} + +static bool guess_p_meaning(struct HPCS_MeasuredData* const mdata) +{ + if (strcmp(mdata->cs_ver, CHEMSTAT_VER_B0625) == 0) + return false; + + return true; +} + static enum HPCS_ParseCode read_dad_wavelength(FILE* datafile, struct HPCS_Wavelength* const measured, struct HPCS_Wavelength* const reference) { char* start_idx, *interv_idx, *end_idx, *temp, *str; diff --git a/libhpcs.h b/libhpcs.h index 93352e4..904d126 100644 --- a/libhpcs.h +++ b/libhpcs.h @@ -10,6 +10,8 @@ enum HPCS_File_Type { HPCS_TYPE_CE_CURRENT, HPCS_TYPE_CE_DAD, HPCS_TYPE_CE_POWER, + HPCS_TYPE_CE_PRESSURE, + HPCS_TYPE_CE_TEMPERATURE, HPCS_TYPE_CE_VOLTAGE, HPCS_TYPE_UNKNOWN }; diff --git a/libhpcs_p.h b/libhpcs_p.h index 86ad51d..8151d6e 100644 --- a/libhpcs_p.h +++ b/libhpcs_p.h @@ -1,3 +1,4 @@ +#include #include enum HPCS_DataCheckCode { @@ -31,8 +32,10 @@ const char* FILE_TYPE_ID_DAD = "DAD"; const char* FILE_TYPE_ID_HPCE = "HPCE"; const char FILE_TYPE_HPCE_CCD = 'L'; const char FILE_TYPE_HPCE_CURRENT = 'C'; +const char FILE_TYPE_HPCE_POWER_PRESSURE = 'P'; +const char FILE_TYPE_HPCE_POWER = 'E'; +const char FILE_TYPE_HPCE_TEMPERATURE = 'T'; const char FILE_TYPE_HPCE_VOLTAGE = 'V'; -const char FILE_TYPE_HPCE_POWER = 'P'; /* Char and text values */ const char* WAVELENGTH_MEASURED_TEXT = "Sig="; @@ -60,7 +63,7 @@ const char* MON_DEC_STR = "Dec"; const HPCS_step CE_CURRENT_STEP = 0.01; const HPCS_step CE_CCD_STEP = 0.0000596046450027643; const HPCS_step CE_DAD_STEP = 0.000476837158203; -const HPCS_step CE_PWR_VOLT_STEP = 0.001; +const HPCS_step CE_WORK_PARAM_STEP = 0.001; /* Offsets containing data of interest in .ch files */ const HPCS_offset DATA_OFFSET_FILE_DESC = 0x15B; @@ -75,6 +78,9 @@ const HPCS_offset DATA_OFFSET_Y_UNITS = 0x104C; const HPCS_offset DATA_OFFSET_DEVSIG_INFO = 0x1075; const HPCS_offset DATA_OFFSET_DATA_START = 0x1800; +/* Known ChemStation format versions */ +const char* CHEMSTAT_VER_B0625 = "B.06.25 [0003]"; + /* Values of markers found in .ch files */ const char BIN_MARKER_A = 0x10; const char BIN_MARKER_END = 0x00; @@ -91,8 +97,10 @@ const char* HPCS_E_PARSE_ERROR_STR = "Cannot parse the specified file, it might const char* HPCS_E_UNKNOWN_TYPE_STR = "The specified file contains an unknown type of measurement."; const char* HPCS_E__UNKNOWN_EC_STR = "Unknown error code."; -static enum HPCS_ParseCode autodetect_file_type(FILE* datafile, enum HPCS_File_Type* file_type); +static enum HPCS_ParseCode autodetect_file_type(FILE* datafile, enum HPCS_File_Type* file_type, const bool p_means_pressure); static enum HPCS_DataCheckCode check_for_marker(const char* const segment, size_t* const next_marker_idx); +static HPCS_step guess_current_step(struct HPCS_MeasuredData* const mdata); +static bool guess_p_meaning(struct HPCS_MeasuredData* const mdata); static enum HPCS_ParseCode read_dad_wavelength(FILE* datafile, struct HPCS_Wavelength* const measured, struct HPCS_Wavelength* const reference); static uint8_t month_to_number(const char* const month); static enum HPCS_ParseCode read_date(FILE* datafile, struct HPCS_Date* const date); -- 2.43.5