/
read_parameters2.c
175 lines (160 loc) · 6.96 KB
/
read_parameters2.c
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
#include "dec.h"
#include "cosmic_rays.h"
#include "runge_kutta.h"
#include "read_parameters.h"
#include "read_parameters2.h"
#include "synchrotron.h"
#include "jet.h"
/*************************************************************************/
/* Read parameters from command line input, given by main as char array */
/* reads values between the searched variable and the # character */
char regit(char input[], char *buf, char var[])
{
char *pch = strstr(input,var);
char temp[100]={'\0'};
strncpy(temp,pch,50);
char *chr=strchr(temp,'#');
int len = strlen(var);
strncpy(buf,temp+len,chr-temp-len);
return 0;
}
//returns a float variable
double getfloat(char input[], char *regstr)
{
char buf[50] = {'\0'};
double var_d=0;
regit(input,buf,regstr);
sscanf(buf,"%lg",&var_d);
return var_d;
}
//returns an int variable
int getint(char input[], char *regstr)
{
char buf[50] = {'\0'};
int var_i=0;
regit(input,buf,regstr);
sscanf(buf,"%d",&var_i);
return var_i;
}
void read_parameters2(char input[])
{
/* Include some fundamental constants */
c_light = 2.99792458e10;//[cm s^-1]
kpc = 3.085677582e21;//[cm]
pi = 3.141565492;
sigma_t = 6.6524616e-25;//[cm^2]
m_electron = 9.1093897e-28;//[g]
e_elem = 1.60217733e-19;
/*--------------------------------------------------------------------------*/
/*Setup of the 2-dimensional grid*/
/*--------------------------------------------------------------------------*/
grid_size = getint(input,"grid_size=");
/*--------------------------------------------------------------------------*/
nu_channel = getfloat(input,"nu_channel=");
/*--------------------------------------------------------------------------*/
grid_delta = getint(input,"grid_delta=");
/*--------------------------------------------------------------------------*/
z_halo_kpc = getfloat(input,"z_halo=");
/*--------------------------------------------------------------------------*/
first_data_point_at_0kpc = getint(input,"first_data_point_at_0kpc=");
/*--------------------------------------------------------------------------*/
normalize_intensities = getint(input,"normalize_intensities=");
/*--------------------------------------------------------------------------*/
/*Output */
/*--------------------------------------------------------------------------*/
nu_1 = getfloat(input,"nu_1=");
/*--------------------------------------------------------------------------*/
nu_2 = getfloat(input,"nu_2=");
/*--------------------------------------------------------------------------*/
nu_3 = getfloat(input,"nu_3=");
/*--------------------------------------------------------------------------*/
nu_4= getfloat(input,"nu_4=");
/*--------------------------------------------------------------------------*/
mode = getint(input,"mode=");
/*--------------------------------------------------------------------------*/
epsilon = getint(input,"epsilon=");
/*--------------------------------------------------------------------------*/
FWHM_effective_beam= getfloat(input,"FWHM_effective_beam=");
/*--------------------------------------------------------------------------*/
/*Setup of the advection and diffusion model*/
/*--------------------------------------------------------------------------*/
gamma_in= getfloat(input,"gamma_in=");
/*--------------------------------------------------------------------------*/
rad_field= getfloat(input,"rad_field=");
/*--------------------------------------------------------------------------*/
V0= getfloat(input,"V0=");
/*--------------------------------------------------------------------------*/
velocity_field = getint(input,"velocity_field=");
/*--------------------------------------------------------------------------*/
h_V= getfloat(input,"h_V=");
/*--------------------------------------------------------------------------*/
adiabatic_losses = getint(input,"adiabatic_losses=");
/*--------------------------------------------------------------------------*/
D0= getfloat(input,"D0=");
/*--------------------------------------------------------------------------*/
mu_diff= getfloat(input,"mu_diff=");
/*--------------------------------------------------------------------------*/
V_rot = getfloat(input,"V_rot=");
/*--------------------------------------------------------------------------*/
/*Magnetic field setup*/
/*--------------------------------------------------------------------------*/
galaxy_mode = getint(input,"galaxy_mode=");
/*--------------------------------------------------------------------------*/
z1= getfloat(input,"z1=");
/*--------------------------------------------------------------------------*/
B0= getfloat(input,"B0=");
/*--------------------------------------------------------------------------*/
B1= getfloat(input,"B1=");
/*--------------------------------------------------------------------------*/
h_B1= getfloat(input,"h_B1=");
/*--------------------------------------------------------------------------*/
h_B2= getfloat(input,"h_B2=");
/*--------------------------------------------------------------------------*/
beta= getfloat(input,"beta=");
/*--------------------------------------------------------------------------*/
R0= getfloat(input,"R0=");
/*--------------------------------------------------------------------------*/
/*#Use a magnetic field model (needs edit of the source files)*/
/*--------------------------------------------------------------------------*/
model = getint(input,"model=");
/*--------------------------------------------------------------------------*/
initialize_model = getint(input,"initialize_model=");
/*--------------------------------------------------------------------------*/
model_north = getint(input,"model_north=");
/*--------------------------------------------------------------------------*/
update_model = getint(input,"update_model=");
/*--------------------------------------------------------------------------*/
xi= getfloat(input,"xi=");
/*--------------------------------------------------------------------------*/
/****************************************************************************/
z_halo = z_halo_kpc * kpc;
if (nu_channel < 2)
{
printf("You need at least to separate frequencies to compute\n");
printf("the spectral index: nu_channel has to be >= 2! Stop.\n");
exit (0);
}
if (nu_2 <= nu_1)
{
printf ("Error: nu_2 <= nu_1. Stop.\n");
exit(0);
}
if (model == 1 || initialize_model == 1)
{
if (model_north == 1)
number_of_data_points = set_radius_north ();
else
number_of_data_points = set_radius_south ();
if (update_model == 1)
read_intensity_model ();
if (mod[number_of_data_points].z > z_halo_kpc)
{
printf("Halo size is smaller than model size. Stop.\n");
printf("Halo_size = %g kpc, Model size = %g kpc\n", z_halo_kpc, mod[number_of_data_points].z);
exit(0);
}
}
grid_size = (int) 2.0 * grid_size;
h_grav = 18.0;
// fclose(f);
}