File: main.cpp

package info (click to toggle)
oscar 1.5.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 27,500 kB
  • sloc: cpp: 80,911; ansic: 6,910; python: 1,727; sh: 1,044; xml: 150; javascript: 74; makefile: 34; awk: 18
file content (198 lines) | stat: -rw-r--r-- 6,266 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/* Dump an STR.edf file */

#include <QApplication>
// #include <iostream>
#include <QDebug>
#include <QThread>

typedef float EventDataType;

#include "edfparser.h"

// using namespace std;

void dumpHeader( const EDFHeaderQT  hdr ) {
    qDebug() << "EDF Header:";
    qDebug() << "Version " << hdr.version << " Patient >" << hdr.patientident << "<";
    qDebug() << "Recording >" << hdr.recordingident << "<";
    qDebug() << "Date: " << hdr.startdate_orig.toString();
    qDebug() << "Header size (bytes): " << hdr.num_header_bytes;
    qDebug() << "EDF type: >" << hdr.reserved44 << "<";
    qDebug() << "Duration(secs): " << hdr.duration_Seconds;
    qDebug() << "Number of Signals: " << hdr.num_signals << "\n";
}

void ifprint( QString label, QString text) {
    if ( text.isEmpty() )
        return;
    qDebug() << label << ": " << text;
    return;
}

void dumpSignals( const QVector<EDFSignal>  sigs ) {
    int i = 1;
    for (auto sig: sigs) {
        qDebug() << "Signal #" << i++;
        qDebug() << "Label: " << sig.label;
        ifprint( "Transducer", sig.transducer_type );
        ifprint( "Dimension", sig.physical_dimension );
        qDebug() << "Physical min: " << sig.physical_minimum << " max: " << sig.physical_maximum;
        qDebug() << "Digital  min: " << sig.digital_minimum << " max: " << sig.digital_maximum;
        qDebug() << "Gain: " << sig.gain << " Offset: " << sig.offset;
        ifprint( "Pre-filter", sig.prefiltering );
        qDebug() << "Sample Count: " << sig.sampleCnt;
        qDebug() << "dataArray is at " << sig.dataArray << "\n";
    }
}

void usage() {
    qDebug() << "dumpSTR [ options ] filename";
    qDebug() << "Options";
    qDebug() << "\t-a Show all";
    qDebug() << "\t-f ### First day";
    qDebug() << "\t-l ### Last day";
    qDebug() << "\t-g ### First signal";
    qDebug() << "\t-m ### Last signal";
    qDebug() << "\t-s Signal list only";
    qDebug() << "\t-H Don't print the header";
    qDebug() << "\t-S Don't print signals list";
    qDebug() << "\t-h or -? This help message";
}

int main(int argc, char *argv[]) {

//    QString homeDocs = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)+"/";
//    QCoreApplication::setApplicationName(getAppName());
//    QCoreApplication::setOrganizationName(getDeveloperName());
//    QCoreApplication::setOrganizationDomain(getDeveloperDomain());

    int first = 0, last = 0;
    int firstSig = 1, lastSig = 0;

    QApplication a(argc, argv);
    QStringList args = a.arguments();
    
	if ( args.size() < 2 ) {
		qDebug() << args[0] << " needs a filename" ;
		exit(1);
	}
	
    QString filename = args[args.size()-1];
    bool showall = false, brief = false;
    bool skipHeader = false, skipSignals = false;

    for (int i = 1; i < args.size()-1; i++) {
        if (args[i] == "-f")
            first = args[++i].toInt();
        else if (args[i] == "-g")
            firstSig = args[++i].toInt();
        else if (args[i] == "-l")
            last = args[++i].toInt();
        else if (args[i] == "-m")
            lastSig = args[++i].toInt();
        else if (args[i] == "-a")
            showall = true;
        else if (args[i] == "-s")
            brief = true;
        else if (args[i] == "-H")
            skipHeader = true;
        else if (args[i] == "-S")
            skipSignals = true;
        else if ((args[i] == "-?") || (args[i] == "-h")) {
            usage();
            exit(0);
        }
    }

    EDFInfo str;
    if ( ! str.Open(filename) ) {
        qDebug() << "Failed to open" << filename;
        exit(-1);
    }
    if ( ! str.Parse() ) {
        qDebug() << "Parsing failed on" << filename;
        exit(-1);
    }

    QDate d2 = str.edfHdr.startdate_orig.date();
    if (d2.year() < 2000) {
        d2.setDate(d2.year() + 100, d2.month(), d2.day());
        str.edfHdr.startdate_orig.setDate(d2);
    }



    QDate date = str.edfHdr.startdate_orig.date(); // each STR.edf record starts at 12 noon
    int numDays = str.GetNumDataRecords();

    qDebug() << str.filename << " starts at " << date << " for " << numDays
                << " days, ending at " << date.addDays(numDays) << " with " << str.GetNumSignals() << " signals";

    if (args.size() == 2) {
        exit(0);
    }

    if ( ! skipHeader)
        dumpHeader( (str.edfHdr) );
    if ( ! skipSignals )
        dumpSignals( (str.edfsignals) );

    if ( brief )
        exit(0);
	
    int size = str.GetNumDataRecords();

    if (showall) {
        first = 0;
        last = size;
        firstSig = 1;
        lastSig = str.GetNumSignals();
    }
    if (lastSig == 0 )
        lastSig = str.GetNumSignals();

    if ((last == 0) || (last > size))
        last = size;

    date = date.addDays(first);
    // For each data record, representing 1 day each
    for (int rec = first; rec < last+1; ++rec, date = date.addDays(1)) {
		qDebug() << "Record no. " << rec << " Date: " << date.toString() ;
	    for (int j = firstSig-1; j < lastSig; j++ ) {
        //  qDebug() << "Signal #" << j;
	        EDFSignal sig = str.edfsignals[j];
//          if ( sig == nullptr ) {
//              qDebug() << "Bad sig pointer at signal " << j;
//              exit(2);
//          }
            if ( ! sig.label.contains("Annotations")) {
		        qint16 * sample = sig.dataArray;
//              qDebug() << "Sample pointer is " << sample;
                if (sample == nullptr) {
                    qDebug() << "Bad sample pointer at signal " << j;
                    exit(3);
                }
	            QString dataStr = "";
		        if (sig.sampleCnt == 1) {
//                  qDebug() << "Single sample is " << sample[rec];
		            dataStr.setNum(sample[rec]);
//                  qDebug() << "Datastr is " << dataStr;
                }
		        else {
		            for (int i = 0; i < sig.sampleCnt; i++ ) {
                        QString num;
                        num.setNum(sample[rec*sig.sampleCnt + i]);
		                dataStr.append(" ").append(num);
                    }
	            }
    	        qDebug() << "#" << j+1 << sig.label << dataStr;
            }
        }
	}
//  qDebug() << "Deleting the edf object";
//  delete &str;
	QThread::sleep(1);
    qDebug() << "Done";

    exit(0);
}