45 #if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
58 #include <QRegularExpression>
68 using namespace INVERSELIB;
69 using namespace FIFFLIB;
84 static fiff_int_t swap_int (fiff_int_t source)
86 unsigned char *csource = (
unsigned char *)(&source);
88 unsigned char *cresult = (
unsigned char *)(&result);
90 cresult[0] = csource[3];
91 cresult[1] = csource[2];
92 cresult[2] = csource[1];
93 cresult[3] = csource[0];
99 static float swap_float (
float source)
101 unsigned char *csource = (
unsigned char *)(&source);
103 unsigned char *cresult = (
unsigned char *)(&result);
105 cresult[0] = csource[3];
106 cresult[1] = csource[2];
107 cresult[2] = csource[1];
108 cresult[3] = csource[0];
114 namespace INVERSELIB {
125 float single_errors[5];
126 float error_matrix[5][5];
146 : dataname(p_ECDSet.dataname)
147 , m_qListDips(p_ECDSet.m_qListDips)
161 m_qListDips.append(p_ecd);
170 QFile inputFile(fileName);
171 if (inputFile.open(QIODevice::ReadOnly|QIODevice::Text))
173 QTextStream in(&inputFile);
176 QString line = in.readLine();
177 QStringList list = line.split(QRegularExpression(
"\\s+"));
179 if(list[0].contains(
"#") || list.size() != 11) {
185 one.
time = list[1].toFloat() / 1000.0f;
186 one.
rd[X] = list[3].toFloat() / 1000.0f;
187 one.
rd[Y] = list[4].toFloat() / 1000.0f;
188 one.
rd[Z] = list[5].toFloat() / 1000.0f;
189 one.
Q[X] = list[7].toFloat() / 1e9f;
190 one.
Q[Y] = list[8].toFloat() / 1e9f;
191 one.
Q[Z] = list[9].toFloat() / 1e9f;
192 one.
good = list[10].toFloat() / 100.0f;
198 printf(
"Read %d dipoles in dip format from %s\n",set.
size(),fileName.toUtf8().data());
201 printf(
"Not able to read from: %s\n", fileName.toUtf8().data());
220 if (fileName.isEmpty() || this->size() == 0)
223 if ((out = fopen(fileName.toUtf8().data(),
"w")) == NULL) {
224 printf(fileName.toUtf8().data());
228 for (
k = 0, nsave = 0;
k < this->
size(); k++) {
229 one = m_qListDips[
k];
231 one_out.dipole = swap_int(1);
232 one_out.begin = swap_float(one.
time);
233 for (p = 0; p < 3; p++) {
234 one_out.r0[p] = swap_float(0.0);
235 one_out.rd[p] = swap_float(one.
rd[p]);
236 one_out.Q[p] = swap_float(one.
Q[p]);
238 one_out.goodness = swap_float(one.
good);
239 one_out.errors_computed = swap_int(0);
240 one_out.khi2 = swap_float(one.
khi2);
241 if (fwrite(&one_out,
sizeof(
bdipEcdRec),1,out) != 1) {
242 printf(
"Failed to write a dipole");
248 if (fclose(out) != 0) {
250 printf(fileName.toUtf8().data());
253 printf(
"Save %d dipoles in bdip format to %s\n",nsave,fileName.toUtf8().data());
259 unlink(fileName.toUtf8().data());
273 if (fileName.isEmpty() || this->size() == 0)
275 if ((out = fopen(fileName.toUtf8().data(),
"w")) == NULL) {
276 printf(fileName.toUtf8().data());
279 fprintf(out,
"# CoordinateSystem \"Head\"\n");
280 fprintf (out,
"# %7s %7s %8s %8s %8s %8s %8s %8s %8s %6s\n",
281 "begin",
"end",
"X (mm)",
"Y (mm)",
"Z (mm)",
"Q(nAm)",
"Qx(nAm)",
"Qy(nAm)",
"Qz(nAm)",
"g/%");
282 for (
k = 0, nsave = 0;
k < this->
size(); k++) {
283 one = this->m_qListDips[
k];
285 fprintf(out,
" %7.1f %7.1f %8.2f %8.2f %8.2f %8.3f %8.3f %8.3f %8.3f %6.1f\n",
287 1000*one.
rd[X],1000*one.
rd[Y],1000*one.
rd[Z],
288 1e9*one.
Q.norm(),1e9*one.
Q[X],1e9*one.
Q[Y],1e9*one.
Q[Z],100.0*one.
good);
292 fprintf(out,
"## Name \"%s dipoles\" Style \"Dipoles\"\n",
"ALL");
293 if (fclose(out) != 0) {
295 printf(fileName.toUtf8().data());
298 printf(
"Save %d dipoles in dip format to %s\n",nsave,fileName.toUtf8().data());
304 unlink(fileName.toUtf8().data());
314 if (idx>=m_qListDips.length())
316 qWarning(
"Warning: Required ECD doesn't exist! Returning ECD '0'.");
319 return m_qListDips[idx];
326 if (idx >= m_qListDips.length())
328 qWarning(
"Warning: Required ECD doesn't exist! Returning ECD '0'.");
331 return m_qListDips[idx];
338 this->m_qListDips.append(p_ecd);