StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
displayMap.C
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <fcntl.h>
4 #include <sys/types.h>
5 #include <sys/stat.h>
6 #include <unistd.h>
7 #include <string.h>
8 #include <errno.h>
9 #include <math.h>
10 
11 int main(int, char *[])
12 {
13  struct stat statbuff;
14 
15  int ret;
16 
17  ret = stat("map.bin", &statbuff);
18  if(ret == -1) {
19  printf("Can't stat file map.bin (%s)\n", strerror(errno));
20  return 0;
21  }
22 
23  int sz = statbuff.st_size;
24  uint *buff = (uint *)malloc(sz);
25  float *fbuff = (float *)buff;
26 
27  if(!buff) {
28  printf("Can't allocate %d bytes\n",sz);
29  return 0;
30  }
31 
32  int fd = open("map.bin", O_RDONLY);
33  if(fd == -1) {
34  printf("Can't open file map.bin (%s)\n", strerror(errno));
35  return 0;
36  }
37 
38  ret = read(fd, buff, sz);
39  if(sz != ret) {
40  printf("Only read %d of %d bytes\n",ret,sz);
41  return 0;
42  }
43 
44  close(fd);
45 
46  // Print out buff...
47  int head_words = buff[1];
48 
49 #ifdef PRINTHEAD
50  for(int i=0;i<head_words;i++) {
51  printf("Head[%d] = %d (%f)\n",i,buff[i],fbuff[i]);
52  }
53 #endif
54 
55 #ifndef PRINTGRID
56  float dpad = fbuff[3];
57  float dtb = fbuff[4];
58  float maxtb = fbuff[5];
59 
60  int npgrid = (int) ceil(182./dpad);
61  int ntbgrid = (int) ceil(maxtb/dtb);
62 
63  typedef float map_t[45][npgrid+1][ntbgrid+1][3];
64  map_t *map = (map_t *)&buff[head_words+1];
65 
66  int sector = 3;
67  int pr = 20;
68 
69  for(int pg=0;pg<npgrid;pg++) {
70  for(int tg=0;tg<ntbgrid;tg++) {
71  float x = map[sector][pr][pg][tg][0];
72  float y = map[sector][pr][pg][tg][1];
73  float z = map[sector][pr][pg][tg][2];
74  //printf("pg=%d tg=%d %f %f\n",pg,tg,y,z);
75  printf("%f %f\n",y,z);
76  }
77  }
78 
79 
80 #endif
81 
82  free(buff);
83 }