Debian Codegraph @

src/read_data_snsph_utils.c

raw
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <error.h>
4 #include <string.h>
5
6 #include <SDF.h>
7 #include <SDFread.h>
8 #include <bigmalloc.h>
9
10 typedef struct {
11 double x, y, z;
12 float vx, vy, vz;
13 float mass;
14 float u;
15 float rho;
16 float h;
17 } body;
18
19
20 void readsdf_(char *filename, int *len, float *dat, int *maxpart,
21 int *maxcol, int *ierr)
22 {
23 int xconf, yconf, zconf, vxconf, vyconf, vzconf, mconf, uconf,
24 rhoconf, hconf;
25 int gnobj, nobj, i;
26 body *p;
27 SDF *sdfp;
28 char fname[128];
29
30 strncpy(fname, filename, *len);
31 fname[*len] = '\0';
32
33 if ( (sdfp = SDFopen(NULL, fname)) == NULL ) {
34 fprintf(stderr, "%s: %s", fname, SDFerrstring);
35 exit(2);
36 }
37
38 SDFread(sdfp, (void **)(&p), &gnobj, &nobj, sizeof(body),
39 "x", offsetof(body, x), &xconf,
40 "y", offsetof(body, y), &yconf,
41 "z", offsetof(body, z), &zconf,
42 "vx", offsetof(body, vx), &vxconf,
43 "vy", offsetof(body, vy), &vyconf,
44 "vz", offsetof(body, vz), &vzconf,
45 "mass", offsetof(body, mass), &mconf,
46 "u", offsetof(body, u), &uconf,
47 "rho", offsetof(body, rho), &rhoconf,
48 "h", offsetof(body, h), &hconf,
49 NULL);
50 SDFclose(sdfp);
51
52 if (!xconf || !yconf || !zconf || !vxconf || !vyconf || !vzconf ||
53 !mconf || !uconf || !rhoconf || !hconf) {
54 fprintf(stderr, "No %s%s%s%s%s%s%s%s%s%s in %s\n",
55 (xconf==0)? "x " : "",
56 (yconf==0)? "y " : "",
57 (zconf==0)? "z " : "",
58 (vxconf==0)? "vx " : "",
59 (vyconf==0)? "vy " : "",
60 (vzconf==0)? "vz " : "",
61 (mconf==0)? "m " : "",
62 (uconf==0)? "u " : "",
63 (rhoconf==0)? "rho " : "",
64 (hconf==0)? "h " : "",
65 fname);
66 exit(3);
67 }
68
69 printf("nobj = %d\n", nobj);
70
71 for(i = 0; i < nobj; ++i) {
72 dat[i] = p[i].x;
73 dat[(*maxpart)+i] = p[i].y;
74 dat[2* (*maxpart)+i] = p[i].z;
75 dat[3* (*maxpart)+i] = p[i].vx;
76 dat[4* (*maxpart)+i] = p[i].vy;
77 dat[5* (*maxpart)+i] = p[i].vz;
78 dat[6* (*maxpart)+i] = p[i].mass;
79 dat[7* (*maxpart)+i] = p[i].u;
80 dat[8* (*maxpart)+i] = p[i].rho;
81 dat[9* (*maxpart)+i] = p[i].h;
82 }
83
84 Free(p);
85
86 *ierr = xconf || yconf || zconf || vxconf || vyconf || vzconf || mconf ||
87 uconf || rhoconf || hconf;
88 }
89
90
91 int getcol_()
92 {
93 return 10;
94 }
95
96
97 void getdata_(char *filename, int *len, int *nobj, float *tpos, float *gamma)
98 {
99 SDF *sdfp;
100 char fname[128];
101
102 strncpy(fname, filename, *len);
103 fname[*len] = '\0';
104
105 if ( (sdfp = SDFopen(NULL, fname)) == NULL ) {
106 fprintf(stderr, "%s: %s", fname, SDFerrstring);
107 exit(2);
108 }
109
110 SDFgetintOrDie(sdfp, "npart", nobj);
111 SDFgetfloatOrDie(sdfp, "tpos", tpos);
112 SDFgetfloatOrDie(sdfp, "gamma", gamma);
113
114 SDFclose(sdfp);
115 }