]> Devoid-pointer.net GitWeb - libHPCS.git/commitdiff
Read start of the scans block from file header
authorMichal Malý <madcatxster@devoid-pointer.net>
Tue, 23 Aug 2016 09:18:03 +0000 (11:18 +0200)
committerMichal Malý <madcatxster@devoid-pointer.net>
Tue, 23 Aug 2016 09:18:03 +0000 (11:18 +0200)
libhpcs.c
libhpcs_p.h

index 8677e87b090d96157e8b3d8aa445bd5ca0bef4de..9b1ab0a47cabf7a51d92646c4a03f9833b58c983 100644 (file)
--- a/libhpcs.c
+++ b/libhpcs.c
@@ -115,6 +115,7 @@ enum HPCS_RetCode hpcs_read_mdata(const char* filename, struct HPCS_MeasuredData
        enum HPCS_ChemStationVer cs_ver;
        double signal_step;
        double signal_shift;
+       size_t scans_start;
 
        if (mdata == NULL)
                return HPCS_E_NULLPTR;
@@ -176,7 +177,14 @@ enum HPCS_RetCode hpcs_read_mdata(const char* filename, struct HPCS_MeasuredData
                goto out;
        }
 
-       pret = read_signal(datafile, &mdata->data, &mdata->data_count, signal_step, signal_shift, gentype);
+       pret = read_scans_start(datafile, &scans_start);
+       if (pret != PARSE_OK) {
+               PR_DEBUG("Cannot read scans start offset\n");
+               ret = HPCS_E_PARSE_ERROR;
+               goto out;
+       }
+
+       pret = read_signal(datafile, &mdata->data, &mdata->data_count, scans_start, signal_step, signal_shift);
        if (pret != PARSE_OK) {
                PR_DEBUG("Cannot parse data in the file\n");
                ret = HPCS_E_PARSE_ERROR;
@@ -906,8 +914,30 @@ out:
        return ret;
 }
 
+static enum HPCS_ParseCode read_scans_start(FILE* datafile, size_t *scans_start)
+{
+       size_t r;
+       int32_t _start;
+
+       fseek(datafile, DATA_SCANS_START, SEEK_SET);
+       if (feof(datafile))
+               return PARSE_E_OUT_OF_RANGE;
+       if (ferror(datafile))
+               return PARSE_E_CANT_READ;
+
+       r = fread(&_start, LARGE_SEGMENT_SIZE, 1, datafile);
+       if (r != 1)
+               return PARSE_E_CANT_READ;
+
+       be_to_cpu_val(_start);
+
+       *scans_start = (_start - 1) * 512;
+
+       return PARSE_OK;
+}
+
 static enum HPCS_ParseCode read_signal(FILE* datafile, struct HPCS_TVPair** pairs, size_t* pairs_count,
-                                      const double signal_step, const double signal_shift, const enum HPCS_GenType gentype)
+                                      const size_t scans_start, const double signal_step, const double signal_shift)
 {
         size_t alloc_size = (size_t)((60 * 25));
        bool read_file = true;
@@ -915,12 +945,11 @@ static enum HPCS_ParseCode read_signal(FILE* datafile, struct HPCS_TVPair** pair
        size_t segments_read = 0;
        size_t data_segments_read = 0;
        size_t next_marker_idx = 0;
-       const HPCS_offset data_start_offset = OLD_FORMAT(gentype) ? DATA_OFFSET_DATA_START_OLD : DATA_OFFSET_DATA_START;
        char raw[2];
        size_t r;
        enum HPCS_DataCheckCode dret;
 
-       fseek(datafile, data_start_offset, SEEK_SET);
+       fseek(datafile, scans_start, SEEK_SET);
        if (feof(datafile))
                return PARSE_E_OUT_OF_RANGE;
        if (ferror(datafile))
index 84832157cb82e830d79ce1de0a12e1abf15b5760..7b0255698e339816f3d57c98933b40aad2728fc3 100644 (file)
@@ -83,6 +83,7 @@ const double CE_WORK_PARAM_SAMPRATE = 1.67;
 
 /* Offsets containing data of interest in .ch files */
 const HPCS_offset DATA_OFFSET_GENTYPE = 0x000;
+const HPCS_offset DATA_SCANS_START = 0x108;
 const HPCS_offset DATA_OFFSET_XMIN = 0x11A;
 const HPCS_offset DATA_OFFSEt_XMAX = 0x11E;
 const HPCS_offset DATA_OFFSET_FILE_DESC = 0x15B;
@@ -190,8 +191,9 @@ static enum HPCS_ParseCode read_file_header(FILE* datafile, enum HPCS_ChemStatio
 static enum HPCS_ParseCode read_file_type_description(FILE* datafile, char** const description, const enum HPCS_GenType gentype);
 static enum HPCS_ParseCode read_generic_type(FILE* datafile, enum HPCS_GenType* gentype);
 static enum HPCS_ParseCode read_method_info_file(HPCS_UFH fh, struct HPCS_MethodInfo* minfo);
+static enum HPCS_ParseCode read_scans_start(FILE* datafile, size_t *scans_start);
 static enum HPCS_ParseCode read_signal(FILE* datafile, struct HPCS_TVPair** pairs, size_t* pairs_count,
-                                      const double sigal_step, const double signal_shift, const enum HPCS_GenType gentype);
+                                      const size_t scans_start, const double sigal_step, const double signal_shift);
 static enum HPCS_ParseCode read_string_at_offset(FILE* datafile, const HPCS_offset, char** const result, const bool read_as_wchar);
 static enum HPCS_ParseCode read_timing(FILE* datafile, struct HPCS_TVPair*const pairs, double *sampling_rate, const size_t data_count);
 static void remove_trailing_newline(HPCS_NChar* s);