[go: up one dir, main page]

Menu

[r377]: / gr_scat / src / scatter.cc  Maximize  Restore  History

Download this file

83 lines (70 with data), 2.3 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
#include "ndisc.h"
#define DTOR PI/180
int main(int argc, char *argv[]) {
Ndisc *system;
FILE *finit; //file containing initial conditions
FILE *fout; //output file
FILE *fint; //file for intermediate results
char line[MAX_LINE_LENGTH];
char *get_res;
float x, y, ang; //initial conditions
char noise_type; //noise type, 'n'=none, 'g'=gauss., 'w'=white
char std; //noise standard deviation
float t; //time delay
long n; //number of deflections
if (argc < 4) {
printf("scatter system init final [traj]\n");
printf("\n");
printf("where:\n");
printf(" system = file describing scattering system\n");
printf(" init = file containing list of initial conditions\n");
printf(" final = output file for final conditions\n");
printf(" traj = optional output file describing trajectories\n");
return 1;
}
system=new Ndisc(argv[1]);
finit=fopen(argv[2], "r");
fout=fopen(argv[3], "w");
if (argc==4) {
while (!feof(finit)) {
get_res=fgets(line, MAX_LINE_LENGTH, finit);
if (get_res==NULL || line[0]=='\n') continue;
//printf("%s\n", line);
sscanf(line, "%f %f %f %c %f", &x, &y, &ang, &noise_type, &std);
ang=ang*DTOR; //convert to radians
if (noise_type=='g') {
system->set_noise(GAUSS);
system->scatter_noisy(&x, &y, &ang, &t, &n, std);
} else if (noise_type=='w') {
system->set_noise(WHITE);
system->scatter_noisy(&x, &y, &ang, &t, &n, std);
} else {
system->scatter(&x, &y, &ang, &t, &n);
}
fprintf(fout, "%f %f %f %f %d\n", x, y, ang/DTOR, t, n);
}
} else {
fint=fopen(argv[4], "w");
while (!feof(finit)) {
get_res=fgets(line, MAX_LINE_LENGTH, finit);
if (get_res==NULL|| line[0]=='\n') continue;
sscanf(line, "%f %f %f %c %f", &x, &y, &ang, &noise_type, &std);
if (noise_type=='g') {
system->set_noise(GAUSS);
} else if (noise_type=='w') {
system->set_noise(WHITE);
} else {
std=0;
}
ang=ang*DTOR;
system->scatter_out(&x, &y, &ang, &t, &n, std, fint);
fprintf(fout, "%f %f %f %f %d\n", x, y, ang/DTOR, t, n);
}
fclose(fint);
}
//clean up:
fclose(finit);
fclose(fout);
delete system;
return 0;
}