]> Devoid-pointer.net GitWeb - libHPCS.git/commitdiff
Add a sampling rate workaround for older file formats
authorMichal Malý <madcatxster@devoid-pointer.net>
Thu, 31 Jul 2014 09:56:30 +0000 (11:56 +0200)
committerMichal Malý <madcatxster@devoid-pointer.net>
Thu, 31 Jul 2014 09:56:30 +0000 (11:56 +0200)
libhpcs.c
libhpcs.h
libhpcs_p.h

index a36f12362a6e1b07d87e57dddc001f3e9de84881..b41818990f448c72ba77909964f4e4cfbe58e84d 100644 (file)
--- 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;
index 986ac1d61e9472ce96b5dad07884d036d7d838d5..aea3e48d8772ef1c4a269b24ee95e35e8b6d90d8 100644 (file)
--- 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;
 };
index d24375da3c9060f302cab73070a462403c23f89c..e5d5bcf5a60386e47d389ff5dbb8aa438d9b9ac8 100644 (file)
@@ -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);