12 printf(
"\n usage: %s <Rick's ASCII map name> <1|2|3|4|5>\n\n", exe);
13 printf(
" -> converts Rick's ASCII file into the SolenoidMap{12345}.dat\n");
14 printf(
" file which can be later imported by PandaRoot\n\n");
19 int main(
int argc,
char **argv)
21 if (argc != 3)
usage(argv[0]);
24 unsigned id = atoi(argv[2]);
25 if (!
id ||
id > 5)
usage(argv[0]);
28 char *fname = argv[1], qname[FILENAME_MAX];
30 snprintf(qname, FILENAME_MAX-1,
"SolenoidMap%d.dat",
id);
33 FILE *fin = fopen(fname,
"r"), *fout = fopen(qname,
"w");
37 printf(
"Failed to open '%s' for reading!\n", fname);
43 printf(
"Failed to open '%s' for writing!\n", qname);
50 unsigned dummy, nodes[3] = {0, 0, 0};
54 if (fscanf(fin,
"%d %d %d %d\n", nodes+0, nodes+1, nodes+2, &dummy) != 4)
56 printf(
"File '%s' has wrong format!\n", fname);
63 unsigned lnum = nodes[0]*nodes[1]*nodes[2];
70 for(
unsigned ip=0;
ip<7;
ip++)
80 for(
unsigned ip=0;
ip<lnum;
ip++)
82 if (fscanf(fin,
"%f %f %f %f %f %f\n", x+0, x+1, x+2, B+0, B+1, B+2) != 6)
84 printf(
"File '%s' has wrong format!\n", fname);
89 memcpy(frecs[
ip].B, B, 3*
sizeof(
float));
92 for(
unsigned iq=0; iq<3; iq++)
94 if (!
ip || x[iq] < xmin[iq]) xmin[iq] = x[iq];
95 if (!
ip || x[iq] > xmax[iq]) xmax[iq] = x[iq];
100 fprintf(fout,
"Solenoid\n");
101 fprintf(fout,
"G\n");
102 for(
unsigned iq=0; iq<3; iq++)
103 fprintf(fout,
"%6.1f %6.1f %3d\n", xmin[iq], xmax[iq], nodes[iq]);
106 for(
unsigned ip=0;
ip<lnum;
ip++)
108 struct frec *fptr = frecs +
ip;
110 fprintf(fout,
"%10.3f %10.3f %10.3f\n", fptr->
B[0], fptr->
B[1], fptr->
B[2]);