-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtransform.cpp
More file actions
164 lines (146 loc) · 5.1 KB
/
transform.cpp
File metadata and controls
164 lines (146 loc) · 5.1 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
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
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Purpose: Transform simulation data to another reference system
Changes log:
- Apr/7-JZ: Checked
* I have performed checks with a mock disk generated with
gendata.py, i.e. TEST_000.sim. We recommend to check when changes
be introduced in code
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*/
#include <dynamo.h>
int main(int argc,char *argv[])
{
//////////////////////////////////////////////////////////////
//PROGRAM VARIBALES
//////////////////////////////////////////////////////////////
char simfile[FSIZE]="",transfile[FSIZE]="";
char origin[130]="",velocity[130]="",orientation[130]="";
real list[3];
vector ro,vo,jo;
int rflabel;
//real list[3];
//////////////////////////////////////////////////////////////
//INITIALIZE
//////////////////////////////////////////////////////////////
TITLE(stdout,'*',"TRANSFORM TO ANOTHER COORDINATE SYSTEM");
//////////////////////////////////////////////////////////////
//SET OPTIONS AND USAGE
//////////////////////////////////////////////////////////////
SET_OPTIONS(":hvVs:t:o:e:j:l:");
SET_USAGE(
"=======================================================================================\n"
"Usage:\n\n"
"\t./program -s <simulation_file> [-t <transformation_file>]\n"
"\t -o <xo>,<yo>,<zo> -e <vox>,<voy>,<voz>\n"
"\t -j <jx>,<jy>,<jz> [-l <rf_label>]\n"
"\n"
"Read the data from <simulation_file>_and transform it to the reference frame centered at\n"
"<xo>,<yo>,<zo> with velocity <vox>,<voy>,<voz> and orientation according to the set of\n"
"axis <jx>,<jy>,<jz>.\n"
"A reference frame label <rf_label> can be set. Default 1.\n"
"=======================================================================================\n"
);
//////////////////////////////////////////////////////////////
//READ OPTIONS
//////////////////////////////////////////////////////////////
while(ITEROPTIONS){
switch(OPTION){
case 's':
strcpy(simfile,optarg);
break;
case 't':
strcpy(transfile,optarg);
break;
case 'o':
strcpy(origin,optarg);
break;
case 'e':
strcpy(velocity,optarg);
break;
case 'j':
strcpy(orientation,optarg);
break;
case 'l':
rflabel=atoi(optarg);
break;
//========================================
//COMMON
//========================================
case 'v':
VERBOSITY=1;
break;
case 'V':
VERBOSITY=2;
break;
//DETECT ERRORS
OPTION_ERRORS;
}
}
//////////////////////////////////////////////////////////////
//VALIDATE OPTIONS
//////////////////////////////////////////////////////////////
if(isBlank(simfile)){
fprintf(stderr,"Error: No simulation file name was provided\n");
PRINT_USAGE;
EXIT;
}
if(!fileExists(simfile)){
fprintf(stderr,"Error: Datafile '%s' does not exist\n",simfile);
PRINT_USAGE;
EXIT;
}
if(isBlank(transfile)){
strcpy(transfile,simfile);
}
if(isBlank(origin))
strcpy(origin,"0.0,0.0,0.0");
if(isBlank(velocity))
strcpy(velocity,"0.0,0.0,0.0");
if(isBlank(orientation))
strcpy(orientation,"0.0,0.0,1.0");
//ORIGIN AND ORIENTATION VECTOR
splitString(origin,",",list);
arrayVector(&ro,list);
splitString(velocity,",",list);
arrayVector(&vo,list);
splitString(orientation,",",list);
arrayVector(&jo,list);
//////////////////////////////////////////////////////////////
//REPORT INPUT INFORMATION
//////////////////////////////////////////////////////////////
if(VERBOSE(1)){
fprintf(stdout,"Simulation file: %s\n",simfile);
fprintf(stdout,"Origin: %s\n",vector2str(ro));
fprintf(stdout,"Velocity: %s\n",vector2str(vo));
fprintf(stdout,"Orientation: %s\n",vector2str(jo));
}
//////////////////////////////////////////////////////////////
//PROGRAM
//////////////////////////////////////////////////////////////
//==================================================
//READ THE SIMULATION DATA
//==================================================
particles parts;
SHeader sheader;
STPRINTF("Reading simulation data...\n");
parts=readSimulation(simfile,&sheader);
if(VERBOSE(2)) checkSimulation(sheader);
STPRINTF("\t%d particles read...\n",sheader.ntot);
//==================================================
//TRANSFORM
//==================================================
STPRINTF("Transforming data to new reference frame...\n");
VPRINTF(2)("Particle 0 before transformation: %s\n",particle2str(parts[0]));
transformSimulation(parts,&sheader,ro,vo,jo);
sheader.rf=rflabel;
VPRINTF(2)("Particle 0 after transformation: %s\n",particle2str(parts[0]));
if(VERBOSE(2)) checkSimulation(sheader);
//==================================================
//WRITE TRANSFORMATION
//==================================================
STPRINTF("Writing %d particles in file '%s'...",sheader.ntot,transfile);
writeSimulation(parts,sheader,transfile);
fprintf(stdout,"Done.\n");
return 0;
}