From e9db2a0a5c84dde2f292a431c035890f8ff3c3d0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Michal=20Mal=C3=BD?= Date: Thu, 31 Jul 2014 11:56:30 +0200 Subject: [PATCH] Add a sampling rate workaround for older file formats --- libhpcs.c | 21 ++++++++++++++++++--- libhpcs.h | 9 +++++++-- libhpcs_p.h | 14 +++++--------- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/libhpcs.c b/libhpcs.c index a36f123..b418189 100644 --- a/libhpcs.c +++ b/libhpcs.c @@ -152,6 +152,8 @@ enum HPCS_RetCode hpcs_read_file(const char* filename, struct HPCS_MeasuredData* } } + guess_sampling_rate(mdata); + switch (mdata->file_type) { case HPCS_TYPE_CE_CCD: pret = read_signal(datafile, &mdata->data, &mdata->data_count, CE_CCD_STEP, mdata->sampling_rate, SIGTYPE_FLOATING); @@ -184,7 +186,7 @@ out: return ret; } -static enum HPCS_ParseCode autodetect_file_type(FILE* datafile, enum HPCS_File_Type* file_type, const bool p_means_pressure) +static enum HPCS_ParseCode autodetect_file_type(FILE* datafile, enum HPCS_FileType* file_type, const bool p_means_pressure) { char* type_id; enum HPCS_ParseCode pret; @@ -227,7 +229,7 @@ static enum HPCS_DataCheckCode check_for_marker(const char* const segment, size_ return DCHECK_NO_MARKER; } -static HPCS_step guess_current_step(struct HPCS_MeasuredData* const mdata) +static HPCS_step guess_current_step(const struct HPCS_MeasuredData* mdata) { if (strcmp(mdata->cs_ver, CHEMSTAT_VER_B0625) == 0) return CE_CURRENT_STEP; @@ -235,7 +237,7 @@ static HPCS_step guess_current_step(struct HPCS_MeasuredData* const mdata) return CE_WORK_PARAM_STEP; } -static bool guess_p_meaning(struct HPCS_MeasuredData* const mdata) +static bool guess_p_meaning(const struct HPCS_MeasuredData* mdata) { if (strcmp(mdata->cs_ver, CHEMSTAT_VER_B0625) == 0) return false; @@ -243,6 +245,19 @@ static bool guess_p_meaning(struct HPCS_MeasuredData* const mdata) return true; } +static void guess_sampling_rate(struct HPCS_MeasuredData* mdata) +{ + if (strcmp(mdata->cs_ver, CHEMSTAT_VER_B0625)) { + switch (mdata->file_type) { + case HPCS_TYPE_CE_DAD: + mdata->sampling_rate *= 10; + break; + default: + mdata->sampling_rate = 1.67; + } + } +} + 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 986ac1d..aea3e48 100644 --- a/libhpcs.h +++ b/libhpcs.h @@ -13,7 +13,7 @@ extern "C" { #define LIBHPCS_CC #endif -enum HPCS_File_Type { +enum HPCS_FileType { HPCS_TYPE_CE_CCD, HPCS_TYPE_CE_CURRENT, HPCS_TYPE_CE_DAD, @@ -32,6 +32,11 @@ enum HPCS_RetCode { HPCS_E_UNKNOWN_TYPE }; +enum HPCS_SignalType { + SIGTYPE_FIXED, + SIGTYPE_FLOATING +}; + struct HPCS_Date { uint32_t year; uint8_t month; @@ -63,7 +68,7 @@ struct HPCS_MeasuredData { double sampling_rate; struct HPCS_Wavelength dad_wavelength_msr; struct HPCS_Wavelength dad_wavelength_ref; - enum HPCS_File_Type file_type; + enum HPCS_FileType file_type; struct HPCS_TVPair* data; size_t data_count; }; diff --git a/libhpcs_p.h b/libhpcs_p.h index d24375d..e5d5bcf 100644 --- a/libhpcs_p.h +++ b/libhpcs_p.h @@ -17,12 +17,7 @@ enum HPCS_ParseCode { PARSE_W_NO_DATA }; -enum HPCS_SignalType { - SIGTYPE_FIXED, - SIGTYPE_FLOATING -}; - -enum HPCS_Wavelength_Type { +enum HPCS_WavelengthType { WAVELENGTH_MEASURED, WAVELENGTH_REFERENCE }; @@ -102,10 +97,11 @@ 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, const bool p_means_pressure); +static enum HPCS_ParseCode autodetect_file_type(FILE* datafile, enum HPCS_FileType* 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 HPCS_step guess_current_step(const struct HPCS_MeasuredData* mdata); +static bool guess_p_meaning(const struct HPCS_MeasuredData* mdata); +static void guess_sampling_rate(struct HPCS_MeasuredData* 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