-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathread_input.cpp
More file actions
135 lines (111 loc) · 3.8 KB
/
read_input.cpp
File metadata and controls
135 lines (111 loc) · 3.8 KB
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
#ifndef READ_INPUT_CPP_INCLUDED
#define READ_INPUT_CPP_INCLUDED
void skipline(ifstream& file)
{//What it says in the tin. Skips a whole line, or what it is left if you filled some data before.
file.ignore(numeric_limits<streamsize>::max(), '\n');
}
const r_number* readExternalBackground(char* filename, const int N_nu)
{
r_number* I0 = new r_number[N_nu];
cout<<"Reading file "<<filename<<endl;
ifstream file;
file.open(filename);
//Skip first line
skipline(file);
for(int nu=0;nu<N_nu;++nu)
{
file>>I0[nu];
}
file.close();
return I0;
}
Table** readFiles(int argc, char** argv)
{/*
This routine reads the input you give to the exe. As
> ./code.exe N_R N_z N_nu "ExternalBackground.txt" "file-Alpha.txt" "file-Jota.txt"
First two parameters are the dimensions for R and z in BOTH files.
Last two parameters are the files needed to fill each table, following the enum in main EXCEPT the last one
So first file is 'Alpha' and second file is 'Jota'.
ExternalBackground.txt is filled with the previous function.
If the file does not respect N_R, N_z, code crashes with a segfault.
*/
//Get dimensions
const int Nx = (int) (todouble(argv[1]));
const int Ny = (int) (todouble(argv[2]));
const int N_nu = (int) (todouble(argv[3]));
//Init data files
Table** magnitude = new Table* [N_maps]; //This gets delete[] in main
for(int variable=0;variable<N_maps;++variable)
{
magnitude[variable] = new Table[N_nu];
for(int nu=0;nu<N_nu;++nu)
{
magnitude[variable][nu] = Table(Nx,Ny);
}
}
//Get data
for(int k=5;k<argc;++k) //Realize that the last magnitude table, corresponding to 'MeanIntensity' is not filled here (except X and Y), as it is the objective of the main function.
{
ifstream file;
file.open(argv[k]);
cout<<"Reading file "<<argv[k]<<endl;
//Skip first line
//file.ignore(numeric_limits<streamsize>::max(), '\n');
skipline(file);
r_number x,y;
r_number prev_x;
r_number z[N_nu];
int i=0; //x index
int j=0; //y index
bool first_iteration = true;
//float dummy;
while(!file.eof())
{
//Read first two elements of the line
file>>x;
file>>y;
//Get the indexes
if(first_iteration){first_iteration=false;} //First iteration comes with i,j previously declared
else if(x == prev_x){j++;}
else{i++;j=0;}
//Save the x for next iteration
prev_x = x;
for(int nu=0;nu<N_nu;++nu)
{
file>>z[nu];
//Fill the corresponding table
magnitude[k-5][nu].FillAll(x,y,z[nu],i,j);
//Fill x and y of 'MeanIntensity' table, I'm using z=0.0 in order to know if this table is not filled properly later (also, it initializes J for the main loop).
if(k==5)
{
magnitude[MeanIntensity][nu].FillAll(x,y,0.0,i,j);
magnitude[Flux][nu].FillAll(x,y,0.0,i,j);
magnitude[RadPressure][nu].FillAll(x,y,0.0,i,j);
}
}
//Skip what remains of that line
skipline(file);
/*cout<<magnitude[k-4][0].X(i)<<" "<<magnitude[k-4][0].Y(j)<<" ";
for(int nu=0;nu<N_nu;++nu)
{
cout<<magnitude[k-4][0].Z(i,j)<<" ";
}
cout<<" "<<i<<" "<<j<<endl;
//cin>>dummy;
*/
}
file.close();
//break;
}
//cout<<"Finished!"<<endl;
return magnitude;
}
void deleteTables(Table** allTables)
{
for(int variable=0;variable<N_maps;++variable)
{
delete[] allTables[variable];
}
delete[] allTables;
}
#endif