-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathB0Shim.cpp
96 lines (79 loc) · 2.51 KB
/
B0Shim.cpp
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
/*-----------------------------------------------------------
* FILE: B0Shim
* DESCRIPTION: Controller software for B0 shimming
*---------------------------------------------------------*/
#include "include/FileHandling.h"
#include "include/Controller.h"
#include "include/INIReader.h"
//-----------------------------------------------------------
// MAIN
//-----------------------------------------------------------
int main (int argc, char *argv[])
{
int status;
float dvals = 0.0; // Debug
char *configFile = (char *) "config.ini";
//------------------------------------------------
// Parse config file
INIReader reader (configFile);
if (reader.ParseError() < 0)
{
printf ("Error: could not open config file: %s\n", configFile);
return 1;
}
std::string shimFile = reader.Get ("Files", "shimvals", "shimvals.txt");
std::string preemphFolder = reader.Get ("Files", "preemphFilter", "");
float estTR = reader.GetReal ("Protocol", "estimateTR", 0.0);
//---------------------------
// Read shim values from file
int nslices, nchannels;
printf ("B0Shim: Reading shim values from: %s\n", shimFile.c_str());
// fmat shimvals = ImportAsciiMatrix (shimFile.c_str(), &nslices, &nchannels, 1);
fmat shimvals = ImportAsciiMatrix (shimFile.c_str(), &nslices, &nchannels, 0);
if (shimvals == NULL)
{
printf ("B0Shim (Error): Invalid/empty input shim file.");
return 1;
}
int r,c;
for (r = 0; r != nslices; ++r)
{
for(c = 0; c != nchannels; ++c)
printf("%f ", shimvals[r][c]);
printf("\n");
}
printf("\n");
//---------------------------
// Read preemphasis filter from text files
fcube preemphFilter = NULL;
int firOrd = 0;
if (!preemphFolder.empty())
{
printf ("%s\n", preemphFolder.c_str());
preemphFilter = (fcube) calloc (nchannels, sizeof (fmat));
char buffer[32];
int nOutputs;
for (int k = 0; k != nchannels; ++k)
{
sprintf (buffer, "%s/ch%i.csv", preemphFolder.c_str(), k);
preemphFilter[k] = ImportAsciiMatrix (buffer, &nOutputs, &firOrd, 0);
if (preemphFilter[k] == NULL)
{
printf ("Missing preemphasis filter file (%s): Replacing with zeros.\n", buffer);
preemphFilter[k] = CreateMatrix (nchannels, firOrd);
}
}
}
//---------------------------
// Run B0 Shimming
Controller ctrl (shimvals, nchannels, nslices, estTR);
ctrl.SetFilter (preemphFilter, firOrd >> 1);
ctrl.FieldCamera (5.0, 1);
// ctrl.DynamicShim (0);
free (shimvals);
if (preemphFilter != NULL)
{
free (preemphFilter);
}
return status;
}