45 #if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
67 using namespace INVERSELIB;
68 using namespace FIFFLIB;
83 static fiff_int_t swap_int (fiff_int_t source)
85 unsigned char *csource = (
unsigned char *)(&source);
87 unsigned char *cresult = (
unsigned char *)(&result);
89 cresult[0] = csource[3];
90 cresult[1] = csource[2];
91 cresult[2] = csource[1];
92 cresult[3] = csource[0];
98 static float swap_float (
float source)
100 unsigned char *csource = (
unsigned char *)(&source);
102 unsigned char *cresult = (
unsigned char *)(&result);
104 cresult[0] = csource[3];
105 cresult[1] = csource[2];
106 cresult[2] = csource[1];
107 cresult[3] = csource[0];
113 namespace INVERSELIB {
124 float single_errors[5];
125 float error_matrix[5][5];
145 : dataname(p_ECDSet.dataname)
146 , m_qListDips(p_ECDSet.m_qListDips)
160 m_qListDips.append(p_ecd);
169 QFile inputFile(fileName);
170 if (inputFile.open(QIODevice::ReadOnly|QIODevice::Text))
172 QTextStream in(&inputFile);
175 QString line = in.readLine();
176 QStringList list = line.split(QRegExp(
"\\s+"));
178 if(list[0].contains(
"#") || list.size() != 11) {
184 one.
time = list[1].toFloat() / 1000.0f;
185 one.
rd[X] = list[3].toFloat() / 1000.0f;
186 one.
rd[Y] = list[4].toFloat() / 1000.0f;
187 one.
rd[Z] = list[5].toFloat() / 1000.0f;
188 one.
Q[X] = list[7].toFloat() / 1e9f;
189 one.
Q[Y] = list[8].toFloat() / 1e9f;
190 one.
Q[Z] = list[9].toFloat() / 1e9f;
191 one.
good = list[10].toFloat() / 100.0f;
197 printf(
"Read %d dipoles in dip format from %s\n",set.
size(),fileName.toUtf8().data());
200 printf(
"Not able to read from: %s\n", fileName.toUtf8().data());
219 if (fileName.isEmpty() || this->size() == 0)
222 if ((out = fopen(fileName.toUtf8().data(),
"w")) == NULL) {
223 printf(fileName.toUtf8().data());
227 for (
k = 0, nsave = 0;
k < this->
size(); k++) {
228 one = m_qListDips[
k];
230 one_out.dipole = swap_int(1);
231 one_out.begin = swap_float(one.
time);
232 for (p = 0; p < 3; p++) {
233 one_out.r0[p] = swap_float(0.0);
234 one_out.rd[p] = swap_float(one.
rd[p]);
235 one_out.Q[p] = swap_float(one.
Q[p]);
237 one_out.goodness = swap_float(one.
good);
238 one_out.errors_computed = swap_int(0);
239 one_out.khi2 = swap_float(one.
khi2);
240 if (fwrite(&one_out,
sizeof(
bdipEcdRec),1,out) != 1) {
241 printf(
"Failed to write a dipole");
247 if (fclose(out) != 0) {
249 printf(fileName.toUtf8().data());
252 printf(
"Save %d dipoles in bdip format to %s\n",nsave,fileName.toUtf8().data());
258 unlink(fileName.toUtf8().data());
272 if (fileName.isEmpty() || this->size() == 0)
274 if ((out = fopen(fileName.toUtf8().data(),
"w")) == NULL) {
275 printf(fileName.toUtf8().data());
278 fprintf(out,
"# CoordinateSystem \"Head\"\n");
279 fprintf (out,
"# %7s %7s %8s %8s %8s %8s %8s %8s %8s %6s\n",
280 "begin",
"end",
"X (mm)",
"Y (mm)",
"Z (mm)",
"Q(nAm)",
"Qx(nAm)",
"Qy(nAm)",
"Qz(nAm)",
"g/%");
281 for (
k = 0, nsave = 0;
k < this->
size(); k++) {
282 one = this->m_qListDips[
k];
284 fprintf(out,
" %7.1f %7.1f %8.2f %8.2f %8.2f %8.3f %8.3f %8.3f %8.3f %6.1f\n",
286 1000*one.
rd[X],1000*one.
rd[Y],1000*one.
rd[Z],
287 1e9*one.
Q.norm(),1e9*one.
Q[X],1e9*one.
Q[Y],1e9*one.
Q[Z],100.0*one.
good);
291 fprintf(out,
"## Name \"%s dipoles\" Style \"Dipoles\"\n",
"ALL");
292 if (fclose(out) != 0) {
294 printf(fileName.toUtf8().data());
297 printf(
"Save %d dipoles in dip format to %s\n",nsave,fileName.toUtf8().data());
303 unlink(fileName.toUtf8().data());
313 if (idx>=m_qListDips.length())
315 qWarning(
"Warning: Required ECD doesn't exist! Returning ECD '0'.");
318 return m_qListDips[idx];
325 if (idx >= m_qListDips.length())
327 qWarning(
"Warning: Required ECD doesn't exist! Returning ECD '0'.");
330 return m_qListDips[idx];
337 this->m_qListDips.append(p_ecd);