Subversion Repositories f9daq

Rev

Rev 248 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 248 Rev 264
1
#ifdef _CVI_
1
#ifdef _CVI_
2
#  include <ansi_c.h>
2
#  include <ansi_c.h>
3
# else _CVI_
3
# else _CVI_
4
#  include <stdlib.h>
4
#  include <stdlib.h>
5
#  include <stdio.h>
5
#  include <stdio.h>
6
#  include <string.h>
6
#  include <string.h>
7
#endif _CVI_
7
#endif _CVI_
8
 
8
 
9
#include "H3D.h"
9
#include "H3D.h"
10
#include "H2D.h"
10
#include "H2D.h"
11
#include "H1D.h" 
11
#include "H1D.h" 
12
 
12
 
13
#define H3DMAX 500
-
 
-
 
13
 
14
H3D *h3[H3DMAX];
14
H3D *h3[H3DMAX];
15
//int Printf(char *format, ...);
15
//int Printf(char *format, ...);
16
 
16
 
17
int _VI_FUNC  H3D_Clear(int h3d) {
17
int _VI_FUNC  H3D_Clear(int h3d) {
18
  if (!h3[h3d]) return -1;
18
  if (!h3[h3d]) return -1;
19
  memset(h3[h3d]->data, 0,h3[h3d]->size );
19
  memset(h3[h3d]->data, 0,h3[h3d]->size );
20
  h3[h3d]->min=0;
20
  h3[h3d]->min=0;
21
  h3[h3d]->max=0;
21
  h3[h3d]->max=0;
22
  h3[h3d]->nentries=0;
22
  h3[h3d]->nentries=0;
23
  return  0;
23
  return  0;
24
 
24
 
25
}
25
}
26
 
26
 
27
int _VI_FUNC  H3D_Print(int h3d) {
27
int _VI_FUNC  H3D_Print(int h3d) {
28
  if (!h3[h3d]) return -1;
28
  if (!h3[h3d]) return -1;
29
//Printf("PrintH3D nx=%d minx=%f stepx=%f ny=%d miny=%f stepy=%f size=%d\n", h3[h3d]->nx, h3[h3d]->minx, h3[h3d]->stepx, h3[h3d]->ny, h3[h3d]->miny, h3[h3d]->stepy, h3[h3d]->size ) ;
29
//Printf("PrintH3D nx=%d minx=%f stepx=%f ny=%d miny=%f stepy=%f size=%d\n", h3[h3d]->nx, h3[h3d]->minx, h3[h3d]->stepx, h3[h3d]->ny, h3[h3d]->miny, h3[h3d]->stepy, h3[h3d]->size ) ;
30
  return  0;
30
  return  0;
31
 
31
 
32
}
32
}
33
 
33
 
34
int _VI_FUNC  H3D_Exist(int h) {
34
int _VI_FUNC  H3D_Exist(int h) {
35
  if (h3[h]) return 1;
35
  if (h3[h]) return 1;
36
  else return 0;
36
  else return 0;
37
}
37
}
38
 
38
 
39
 
39
 
40
int _VI_FUNC  H3D_CalculateBin(int h, int axis, double value) {
40
int _VI_FUNC  H3D_CalculateBin(int h, int axis, double value) {
41
  int nx=1,xmin=0,dx=0;
41
  int nx=1,xmin=0,dx=0;
42
  int bin;
42
  int bin;
43
  switch (axis) {
43
  switch (axis) {
44
    case 0:
44
    case 0:
45
      nx = H3D_GetNbinsX(h);
45
      nx = H3D_GetNbinsX(h);
46
      xmin= H3D_GetMinX(h);
46
      xmin= H3D_GetMinX(h);
47
      dx = H3D_GetStepX(h);
47
      dx = H3D_GetStepX(h);
48
      break;
48
      break;
49
    case 1:
49
    case 1:
50
      nx = H3D_GetNbinsY(h);
50
      nx = H3D_GetNbinsY(h);
51
      xmin= H3D_GetMinY(h);
51
      xmin= H3D_GetMinY(h);
52
      dx = H3D_GetStepY(h);
52
      dx = H3D_GetStepY(h);
53
      break;
53
      break;
54
    case 2:
54
    case 2:
55
      nx = H3D_GetNbinsZ(h);
55
      nx = H3D_GetNbinsZ(h);
56
      xmin= H3D_GetMinZ(h);
56
      xmin= H3D_GetMinZ(h);
57
      dx = H3D_GetStepZ(h);
57
      dx = H3D_GetStepZ(h);
58
      break;
58
      break;
59
 
59
 
60
  }
60
  }
61
  if (dx==0) return -1;
61
  if (dx==0) return -1;
62
  if (value<xmin) return -1;
62
  if (value<xmin) return -1;
63
  bin = (int)((value-xmin)/dx);
63
  bin = (int)((value-xmin)/dx);
64
  if (bin>=nx) return -1;
64
  if (bin>=nx) return -1;
65
  else return bin;
65
  else return bin;
66
}
66
}
67
 
67
 
68
int _VI_FUNC  H3D_Fill(int h3d,double x, double y, double z, double val) {
68
int _VI_FUNC  H3D_Fill(int h3d,double x, double y, double z, double val) {
69
 
69
 
70
  int ix,iy, iz;
70
  int ix,iy, iz;
71
  if (!h3[h3d]) return -1;
71
  if (!h3[h3d]) return -1;
72
 
72
 
73
  ix = H3D_CalculateBin(h3d,0,x);
73
  ix = H3D_CalculateBin(h3d,0,x);
74
  if (ix<0) return ix;
74
  if (ix<0) return ix;
75
 
75
 
76
  iy = H3D_CalculateBin(h3d,1,y);
76
  iy = H3D_CalculateBin(h3d,1,y);
77
  if (iy<0) return iy;
77
  if (iy<0) return iy;
78
 
78
 
79
  iz = H3D_CalculateBin(h3d,2,z);
79
  iz = H3D_CalculateBin(h3d,2,z);
80
  if (iz<0) return iz;
80
  if (iz<0) return iz;
81
 
81
 
82
 
82
 
83
  H3D_FillBin(h3d, ix, iy, iz, val);
83
  H3D_FillBin(h3d, ix, iy, iz, val);
84
  return 0;
84
  return 0;
85
}
85
}
86
 
86
 
87
int _VI_FUNC  H3D_GetBin(int h3d,int x, int y, int z) {
87
int _VI_FUNC  H3D_GetBin(int h3d,int x, int y, int z) {
88
  return x+h3[h3d]->nx *(y+z*h3[h3d]->ny);
88
  return x+h3[h3d]->nx *(y+z*h3[h3d]->ny);
89
}
89
}
90
 
90
 
91
int _VI_FUNC  H3D_FillBin(int h3d,int x, int y, int z, double val) {
91
int _VI_FUNC  H3D_FillBin(int h3d,int x, int y, int z, double val) {
92
 
92
 
93
  int idx;
93
  int idx;
94
  if (!h3[h3d]) {
94
  if (!h3[h3d]) {
95
//Printf("FillH3D error h3d is not initialized\n");
95
//Printf("FillH3D error h3d is not initialized\n");
96
    return -1;
96
    return -1;
97
  }
97
  }
98
 
98
 
99
  idx = H3D_GetBin(h3d,x,y,z);
99
  idx = H3D_GetBin(h3d,x,y,z);
100
  h3[h3d]->data[idx]+=val;
100
  h3[h3d]->data[idx]+=val;
101
//Printf("%d %d data %f %f\n",x,y,val, h3[h3d]->data[idx]);
101
//Printf("%d %d data %f %f\n",x,y,val, h3[h3d]->data[idx]);
102
  if (h3[h3d]->data[idx]>h3[h3d]->max) h3[h3d]->max= h3[h3d]->data[idx];
102
  if (h3[h3d]->data[idx]>h3[h3d]->max) h3[h3d]->max= h3[h3d]->data[idx];
103
  if (h3[h3d]->data[idx]<h3[h3d]->min) h3[h3d]->min= h3[h3d]->data[idx];
103
  if (h3[h3d]->data[idx]<h3[h3d]->min) h3[h3d]->min= h3[h3d]->data[idx];
104
  h3[h3d]->nentries++;
104
  h3[h3d]->nentries++;
105
  return 0;
105
  return 0;
106
}
106
}
107
 
107
 
108
double _VI_FUNC  H3D_GetBinContent(int h3d,int atx, int aty, int atz) {
108
double _VI_FUNC  H3D_GetBinContent(int h3d,int atx, int aty, int atz) {
109
 
109
 
110
  int idx;
110
  int idx;
111
  if (!h3[h3d]) return 0;
111
  if (!h3[h3d]) return 0;
112
  if (h3[h3d]->nx <= atx)  return 0;
112
  if (h3[h3d]->nx <= atx)  return 0;
113
  if (h3[h3d]->ny <= aty)  return 0;
113
  if (h3[h3d]->ny <= aty)  return 0;
114
  if (h3[h3d]->nz <= atz)  return 0;
114
  if (h3[h3d]->nz <= atz)  return 0;
115
  idx = H3D_GetBin(h3d,atx,aty,atz);
115
  idx = H3D_GetBin(h3d,atx,aty,atz);
116
  if (idx*sizeof(double) < h3[h3d]->size ) return h3[h3d]->data[idx];
116
  if (idx*sizeof(double) < h3[h3d]->size ) return h3[h3d]->data[idx];
117
 
117
 
118
 
118
 
119
  return 0;
119
  return 0;
120
}
120
}
121
 
121
 
122
 
122
 
123
int _VI_FUNC  H3D_Init(int h3d,char *name, char *title,
123
int _VI_FUNC  H3D_Init(int h3d,char *name, char *title,
124
                       int nx, double minx, double maxx,
124
                       int nx, double minx, double maxx,
125
                       int ny, double miny, double maxy,
125
                       int ny, double miny, double maxy,
126
                       int nz, double minz, double maxz) {
126
                       int nz, double minz, double maxz) {
127
 
127
 
128
  if (h3[h3d]) {
128
  if (h3[h3d]) {
129
 
129
 
130
    free(h3[h3d]->data);
130
    free(h3[h3d]->data);
131
    free(h3[h3d]);
131
    free(h3[h3d]);
132
    h3[h3d] = NULL;
132
    h3[h3d] = NULL;
133
  }
133
  }
134
  //printf("InitH3D hID=%d\n",h3d);
134
  //printf("InitH3D hID=%d\n",h3d);
135
  h3[h3d] = (H3D *) malloc(sizeof(H3D));
135
  h3[h3d] = (H3D *) malloc(sizeof(H3D));
136
//h2  =h3d;
136
//h2  =h3d;
137
 
137
 
138
  H3D_SetTitle(h3d,title);
138
  H3D_SetTitle(h3d,title);
139
  H3D_SetName(h3d,name);
139
  H3D_SetName(h3d,name);
140
  h3[h3d]->id=H3D_ID;
140
  h3[h3d]->id=H3D_ID;
141
  h3[h3d]->nx = nx;
141
  h3[h3d]->nx = nx;
142
  h3[h3d]->ny = ny;
142
  h3[h3d]->ny = ny;
143
  h3[h3d]->nz = nz;
143
  h3[h3d]->nz = nz;
144
 
144
 
145
  h3[h3d]->minx = minx;
145
  h3[h3d]->minx = minx;
146
  h3[h3d]->miny = miny;
146
  h3[h3d]->miny = miny;
147
  h3[h3d]->minz = minz;
147
  h3[h3d]->minz = minz;
148
 
148
 
149
  h3[h3d]->stepx = (nx>1)?(maxx-minx)/(nx):0;
149
  h3[h3d]->stepx = (nx>1)?(maxx-minx)/(nx):0;
150
  h3[h3d]->stepy = (nx>1)?(maxy-miny)/(ny):0;
150
  h3[h3d]->stepy = (nx>1)?(maxy-miny)/(ny):0;
151
  h3[h3d]->stepz = (nx>1)?(maxz-minz)/(nz):0;
151
  h3[h3d]->stepz = (nx>1)?(maxz-minz)/(nz):0;
152
 
152
 
153
  h3[h3d]->size = h3[h3d]->nx*h3[h3d]->ny*h3[h3d]->nz*sizeof(double);
153
  h3[h3d]->size = h3[h3d]->nx*h3[h3d]->ny*h3[h3d]->nz*sizeof(double);
154
  h3[h3d]->data = (double *) malloc(h3[h3d]->size);
154
  h3[h3d]->data = (double *) malloc(h3[h3d]->size);
155
  h3[h3d]->len=sizeof(H3D)-sizeof(double *)+h3[h3d]->size;
155
  h3[h3d]->len=sizeof(H3D)-sizeof(double *)+h3[h3d]->size;
156
  H3D_Clear(h3d);
156
  H3D_Clear(h3d);
157
  H3D_Print(h3d);
157
  H3D_Print(h3d);
158
//Printf("InitH3D 0x%x\n", h3d );
158
//Printf("InitH3D 0x%x\n", h3d );
159
  return  0;
159
  return  0;
160
 
160
 
161
}
161
}
162
 
162
 
163
 
163
 
164
int _VI_FUNC  H3D_SliXY(int histogram,int slice, int direction) {      
164
int _VI_FUNC  H3D_SliXY(int histogram,int slice, int direction) {      
165
 
165
 
166
if (!H3D_Exist(histogram)) {
166
if (!H3D_Exist(histogram)) {
167
    printf("3D Histogram %d does not exist!\n",histogram);
167
    printf("3D Histogram %d does not exist!\n",histogram);
168
    return -1;
168
    return -1;
169
  }
169
  }
170
 
170
 
171
  int hid=499;
171
  int hid=499;
-
 
172
        int i=0;
-
 
173
        int j=0;
172
  switch (direction){
174
  switch (direction){
173
    case 0:// xy
175
    case 0:// xy
174
      H2D_Init(hid,"projectionXY","projectionXY",
176
      H2D_Init(hid,"projectionXY","projectionXY",
175
               H3D_GetNbinsX(histogram), H3D_GetMinX(histogram),H3D_GetMaxX(histogram),
177
               H3D_GetNbinsX(histogram), H3D_GetMinX(histogram),H3D_GetMaxX(histogram),
176
               H3D_GetNbinsY(histogram), H3D_GetMinY(histogram),H3D_GetMaxY(histogram)
178
               H3D_GetNbinsY(histogram), H3D_GetMinY(histogram),H3D_GetMaxY(histogram)
177
              );
179
              );
178
      for (int i=0; i < H3D_GetNbinsX(histogram); i++ )
180
      for (i=0; i < H3D_GetNbinsX(histogram); i++ )
179
        for (int j=0; j < H3D_GetNbinsY(histogram); j++ )
181
        for (j=0; j < H3D_GetNbinsY(histogram); j++ )
180
          H2D_SetBinContent(hid,i,j,H3D_GetBinContent(histogram,i,j,slice));
182
          H2D_SetBinContent(hid,i,j,H3D_GetBinContent(histogram,i,j,slice));
181
      break;
183
      break;
182
    case 1:// xz
184
    case 1:// xz
183
      H2D_Init(hid,"projectionXZ","projectionXZ",
185
      H2D_Init(hid,"projectionXZ","projectionXZ",
184
               H3D_GetNbinsX(histogram), H3D_GetMinX(histogram),H3D_GetMaxX(histogram),
186
               H3D_GetNbinsX(histogram), H3D_GetMinX(histogram),H3D_GetMaxX(histogram),
185
               H3D_GetNbinsZ(histogram), H3D_GetMinZ(histogram),H3D_GetMaxZ(histogram)
187
               H3D_GetNbinsZ(histogram), H3D_GetMinZ(histogram),H3D_GetMaxZ(histogram)
186
              );
188
              );
187
      for (int i=0; i < H3D_GetNbinsX(histogram); i++ )
189
      for (i=0; i < H3D_GetNbinsX(histogram); i++ )
188
        for (int j=0; j < H3D_GetNbinsZ(histogram); j++ )
190
        for (j=0; j < H3D_GetNbinsZ(histogram); j++ )
189
          H2D_SetBinContent(hid,i,j,H3D_GetBinContent(histogram,i,slice,j));
191
          H2D_SetBinContent(hid,i,j,H3D_GetBinContent(histogram,i,slice,j));
190
      break;
192
      break;
191
    case 2:// yz
193
    case 2:// yz
192
    default:
194
    default:
193
      H2D_Init(hid,"projectionYZ","projectionYZ",
195
      H2D_Init(hid,"projectionYZ","projectionYZ",
194
               H3D_GetNbinsY(histogram), H3D_GetMinY(histogram),H3D_GetMaxY(histogram),
196
               H3D_GetNbinsY(histogram), H3D_GetMinY(histogram),H3D_GetMaxY(histogram),
195
               H3D_GetNbinsZ(histogram), H3D_GetMinZ(histogram),H3D_GetMaxZ(histogram)
197
               H3D_GetNbinsZ(histogram), H3D_GetMinZ(histogram),H3D_GetMaxZ(histogram)
196
              );
198
              );
197
      for (int i=0; i < H3D_GetNbinsY(histogram); i++ )
199
      for (i=0; i < H3D_GetNbinsY(histogram); i++ )
198
        for (int j=0; j < H3D_GetNbinsZ(histogram); j++ )
200
        for (j=0; j < H3D_GetNbinsZ(histogram); j++ )
199
          H2D_SetBinContent(hid,i,j,H3D_GetBinContent(histogram,slice,i,j));
201
          H2D_SetBinContent(hid,i,j,H3D_GetBinContent(histogram,slice,i,j));
200
     
202
     
201
      break;
203
      break;
202
  }
204
  }
203
  return hid;
205
  return hid;
204
}
206
}
205
 
207
 
206
double  _VI_FUNC H3D_GetMaxX(int h){
208
double  _VI_FUNC H3D_GetMaxX(int h){
207
  return h3[h]->minx+(h3[h]->nx)*h3[h]->stepx;
209
  return h3[h]->minx+(h3[h]->nx)*h3[h]->stepx;
208
}
210
}
209
 
211
 
210
double  _VI_FUNC H3D_GetMaxY(int h){
212
double  _VI_FUNC H3D_GetMaxY(int h){
211
  return h3[h]->miny+(h3[h]->ny)*h3[h]->stepy;
213
  return h3[h]->miny+(h3[h]->ny)*h3[h]->stepy;
212
}
214
}
213
 
215
 
214
double  _VI_FUNC H3D_GetMaxZ(int h){
216
double  _VI_FUNC H3D_GetMaxZ(int h){
215
  return h3[h]->minz+(h3[h]->nz)*h3[h]->stepz;
217
  return h3[h]->minz+(h3[h]->nz)*h3[h]->stepz;
216
}
218
}
217
 
219
 
218
double _VI_FUNC  H3D_GetXBinCenter(int h3d,int xbin) {
220
double _VI_FUNC  H3D_GetXBinCenter(int h3d,int xbin) {
219
  return h3[h3d]->minx+(xbin+0.5)*h3[h3d]->stepx;
221
  return h3[h3d]->minx+(xbin+0.5)*h3[h3d]->stepx;
220
}
222
}
221
 
223
 
222
double _VI_FUNC  H3D_GetYBinCenter(int h3d,int ybin) {
224
double _VI_FUNC  H3D_GetYBinCenter(int h3d,int ybin) {
223
  return h3[h3d]->miny+(ybin+0.5)*h3[h3d]->stepy;
225
  return h3[h3d]->miny+(ybin+0.5)*h3[h3d]->stepy;
224
}
226
}
225
 
227
 
226
double _VI_FUNC  H3D_GetZBinCenter(int h3d,int zbin) {
228
double _VI_FUNC  H3D_GetZBinCenter(int h3d,int zbin) {
227
  return h3[h3d]->minz+(zbin+0.5)*h3[h3d]->stepz;
229
  return h3[h3d]->minz+(zbin+0.5)*h3[h3d]->stepz;
228
}
230
}
229
 
231
 
230
 
232
 
231
int _VI_FUNC  H3D_Write2File(int h3d,FILE *fp) {
233
int _VI_FUNC  H3D_Write2File(int h3d,FILE *fp) {
232
 
234
 
233
  if (!fp) return -1;
235
  if (!fp) return -1;
234
//printf("H3D sizeof(H3D)=%lu len-datasize=%d len=%lu datasize=%d\t",sizeof(H3D)-sizeof(double *),h3[h3d]->len-h3[h3d]->size,h3[h3d]->len,h3[h3d]->size);
236
//printf("H3D sizeof(H3D)=%lu len-datasize=%d len=%lu datasize=%d\t",sizeof(H3D)-sizeof(double *),h3[h3d]->len-h3[h3d]->size,h3[h3d]->len,h3[h3d]->size);
235
//printf("H3D sz=%d %d\n",sizeof(double),sizeof(double *));
237
//printf("H3D sz=%d %d\n",sizeof(double),sizeof(double *));
236
  fwrite (h3[h3d], 1, sizeof(H3D)-sizeof(double *), fp);
238
  fwrite (h3[h3d], 1, sizeof(H3D)-sizeof(double *), fp);
237
  fwrite (h3[h3d]->data, 1, h3[h3d]->size, fp);
239
  fwrite (h3[h3d]->data, 1, h3[h3d]->size, fp);
238
  return  0;
240
  return  0;
239
}
241
}
240
 
242
 
241
int _VI_FUNC  H3D_Write(int h3d,const char *fname,const char *opt) {
243
int _VI_FUNC  H3D_Write(int h3d,const char *fname,const char *opt) {
242
  FILE *fp=fopen(fname,opt);
244
  FILE *fp=fopen(fname,opt);
243
  H3D_Write2File(h3d,fp);
245
  H3D_Write2File(h3d,fp);
244
  fclose(fp);
246
  fclose(fp);
245
  return  0;
247
  return  0;
246
}
248
}
247
 
249
 
248
 
250
 
249
 
251
 
250
 
252
 
251
int _VI_FUNC  H3D_SetTitle(int h3d,char *title) {
253
int _VI_FUNC  H3D_SetTitle(int h3d,char *title) {
252
  sprintf(h3[h3d]->title,"%s",title);
254
  sprintf(h3[h3d]->title,"%s",title);
253
  return 0;
255
  return 0;
254
}
256
}
255
 
257
 
256
 
258
 
257
int _VI_FUNC  H3D_SetTitleX(int h3d,char *title) {
259
int _VI_FUNC  H3D_SetTitleX(int h3d,char *title) {
258
  sprintf(h3[h3d]->titlex,"%s",title);
260
  sprintf(h3[h3d]->titlex,"%s",title);
259
  return 0;
261
  return 0;
260
}
262
}
261
 
263
 
262
 
264
 
263
int _VI_FUNC  H3D_SetTitleY(int h3d,char *title) {
265
int _VI_FUNC  H3D_SetTitleY(int h3d,char *title) {
264
  sprintf(h3[h3d]->titley,"%s",title);
266
  sprintf(h3[h3d]->titley,"%s",title);
265
  return 0;
267
  return 0;
266
}
268
}
267
 
269
 
268
int _VI_FUNC  H3D_SetTitleZ(int h3d,char *title) {
270
int _VI_FUNC  H3D_SetTitleZ(int h3d,char *title) {
269
  sprintf(h3[h3d]->titlez,"%s",title);
271
  sprintf(h3[h3d]->titlez,"%s",title);
270
  return 0;
272
  return 0;
271
}
273
}
272
 
274
 
273
 
275
 
274
int _VI_FUNC  H3D_SetName(int h3d,char *title) {
276
int _VI_FUNC  H3D_SetName(int h3d,char *title) {
275
  sprintf(h3[h3d]->name,"%s",title);
277
  sprintf(h3[h3d]->name,"%s",title);
276
  return 0;
278
  return 0;
277
}
279
}
278
 
280
 
279
int _VI_FUNC  H3D_GetNbinsY(int h) {
281
int _VI_FUNC  H3D_GetNbinsY(int h) {
280
  if (h3[h]) return h3[h]->ny;
282
  if (h3[h]) return h3[h]->ny;
281
  else return 0;
283
  else return 0;
282
}
284
}
283
 
285
 
284
int _VI_FUNC  H3D_GetNbinsX(int h) {
286
int _VI_FUNC  H3D_GetNbinsX(int h) {
285
  if (h3[h]) return h3[h]->nx;
287
  if (h3[h]) return h3[h]->nx;
286
  else return 0;
288
  else return 0;
287
}
289
}
288
 
290
 
289
int _VI_FUNC  H3D_GetNbinsZ(int h) {
291
int _VI_FUNC  H3D_GetNbinsZ(int h) {
290
  if (h3[h]) return h3[h]->nz;
292
  if (h3[h]) return h3[h]->nz;
291
  else return 0;
293
  else return 0;
292
}
294
}
293
 
295
 
294
 
296
 
295
 
297
 
296
double _VI_FUNC  H3D_GetMinX(int h) {
298
double _VI_FUNC  H3D_GetMinX(int h) {
297
  if (h3[h]) return h3[h]->minx;
299
  if (h3[h]) return h3[h]->minx;
298
  else return 0;
300
  else return 0;
299
}
301
}
300
 
302
 
301
double _VI_FUNC  H3D_GetMinY(int h) {
303
double _VI_FUNC  H3D_GetMinY(int h) {
302
  if (h3[h]) return h3[h]->miny;
304
  if (h3[h]) return h3[h]->miny;
303
  else return 0;
305
  else return 0;
304
}
306
}
305
 
307
 
306
double _VI_FUNC  H3D_GetMinZ(int h) {
308
double _VI_FUNC  H3D_GetMinZ(int h) {
307
  if (h3[h]) return h3[h]->minz;
309
  if (h3[h]) return h3[h]->minz;
308
  else return 0;
310
  else return 0;
309
}
311
}
310
 
312
 
311
 
313
 
312
 
314
 
313
 
315
 
314
double _VI_FUNC  H3D_GetStepX(int h) {
316
double _VI_FUNC  H3D_GetStepX(int h) {
315
  if (h3[h]) return h3[h]->stepx;
317
  if (h3[h]) return h3[h]->stepx;
316
  else return 0;
318
  else return 0;
317
}
319
}
318
 
320
 
319
double _VI_FUNC  H3D_GetStepY(int h) {
321
double _VI_FUNC  H3D_GetStepY(int h) {
320
  if (h3[h]) return h3[h]->stepy;
322
  if (h3[h]) return h3[h]->stepy;
321
  else return 0;
323
  else return 0;
322
}
324
}
323
 
325
 
324
double _VI_FUNC  H3D_GetStepZ(int h) {
326
double _VI_FUNC  H3D_GetStepZ(int h) {
325
  if (h3[h]) return h3[h]->stepz;
327
  if (h3[h]) return h3[h]->stepz;
326
  else return 0;
328
  else return 0;
327
}
329
}
328
 
330
 
329
 
331
 
330
 
332
 
331
 
333
 
332
double _VI_FUNC  H3D_GetMin(int h) {
334
double _VI_FUNC  H3D_GetMin(int h) {
333
  if (h3[h]) return h3[h]->min;
335
  if (h3[h]) return h3[h]->min;
334
  else return 0;
336
  else return 0;
335
}
337
}
336
 
338
 
337
double _VI_FUNC  H3D_GetMax(int h) {
339
double _VI_FUNC  H3D_GetMax(int h) {
338
  if (h3[h]) return h3[h]->max;
340
  if (h3[h]) return h3[h]->max;
339
  else return 0;
341
  else return 0;
340
}
342
}
341
 
343
 
342
double *  _VI_FUNC  H3D_GetSliceXYData(int h, int slice) {
344
double *  _VI_FUNC  H3D_GetSliceXYData(int h, int slice) {
343
  if (h3[h]) return (h3[h]->data+slice*h3[h]->nx*h3[h]->ny);
345
  if (h3[h]) return (h3[h]->data+slice*h3[h]->nx*h3[h]->ny);
344
  else return NULL;
346
  else return NULL;
345
}
347
}
346
 
348
 
347
double *  _VI_FUNC  H3D_GetData(int h) {
349
double *  _VI_FUNC  H3D_GetData(int h) {
348
  if (h3[h]) return h3[h]->data;
350
  if (h3[h]) return h3[h]->data;
349
  else return NULL;
351
  else return NULL;
350
}
352
}
351
 
353
 
352
 
354
 
353
#ifdef _CVI_
355
#ifdef _CVI_
354
// defined only in CVI
356
// defined only in CVI
355
static HColorMap *colormap = NULL;
357
static HColorMap *colormap = NULL;
356
 
358
 
357
 
359
 
358
HColorMap * _VI_FUNC  H3D_GetColorMap(void) {
360
HColorMap * _VI_FUNC  H3D_GetColorMap(void) {
359
  return colormap;
361
  return colormap;
360
}
362
}
361
 
363
 
362
 
364
 
363
int _VI_FUNC  H3D_SetRangeColors( double min, double max) {
365
int _VI_FUNC  H3D_SetRangeColors( double min, double max) {
364
  int i;
366
  int i;
365
 
367
 
366
 
368
 
367
  if (colormap == NULL) {
369
  if (colormap == NULL) {
368
    colormap = malloc(sizeof(HColorMap));
370
    colormap = malloc(sizeof(HColorMap));
369
 
371
 
370
    colormap->numberofColors = 5;
372
    colormap->numberofColors = 5;
371
    colormap->array = malloc(colormap->numberofColors*sizeof(ColorMapEntry));
373
    colormap->array = malloc(colormap->numberofColors*sizeof(ColorMapEntry));
372
 
374
 
373
    colormap->array[0].color = 0x0000ff; //BLUE
375
    colormap->array[0].color = 0x0000ff; //BLUE
374
    colormap->array[1].color = 0x00ff00; //GREEN
376
    colormap->array[1].color = 0x00ff00; //GREEN
375
    colormap->array[2].color = 0xffff00; //YELLOW
377
    colormap->array[2].color = 0xffff00; //YELLOW
376
    colormap->array[3].color = 0xff8000; //ORANGE
378
    colormap->array[3].color = 0xff8000; //ORANGE
377
    colormap->array[4].color = 0xff0000; //RED
379
    colormap->array[4].color = 0xff0000; //RED
378
 
380
 
379
    colormap->HiColor =colormap->array[colormap->numberofColors-1].color ;
381
    colormap->HiColor =colormap->array[colormap->numberofColors-1].color ;
380
  }
382
  }
381
  if (colormap->numberofColors<2) return -1;
383
  if (colormap->numberofColors<2) return -1;
382
  double fx = (max-min)/(colormap->numberofColors-1);
384
  double fx = (max-min)/(colormap->numberofColors-1);
383
  for  (i=0; i<colormap->numberofColors; i++) {
385
  for  (i=0; i<colormap->numberofColors; i++) {
384
    colormap->array[i].dataValue.valDouble=i*fx+min;
386
    colormap->array[i].dataValue.valDouble=i*fx+min;
385
  }
387
  }
386
  return 0;
388
  return 0;
387
}
389
}
388
 
390
 
389
int  _VI_FUNC  H3D_DrawSliceXY(int histogram,int slice,int direction, int panel, int control, int *plothandle) {
391
int  _VI_FUNC  H3D_DrawSliceXY(int histogram,int slice,int direction, int panel, int control, int *plothandle) {
390
 
392
 
391
 
393
 
392
 
394
 
393
  if (H3D_GetNbinsY(histogram)==1|| H3D_GetNbinsX(histogram)==1) {
395
  if (H3D_GetNbinsY(histogram)==1|| H3D_GetNbinsX(histogram)==1) {
394
    if (H3D_GetNbinsY(histogram)==1) {
396
    if (H3D_GetNbinsY(histogram)==1) {
395
      H1D_Init(499,"projection","projection", H3D_GetNbinsX(histogram), H3D_GetMinX(histogram),H3D_GetMaxX(histogram));
397
      H1D_Init(499,"projection","projection", H3D_GetNbinsX(histogram), H3D_GetMinX(histogram),H3D_GetMaxX(histogram));
396
      for (int i=0; i < H3D_GetNbinsX(histogram); i++ ) H1D_SetBinContent(499,i,H3D_GetBinContent(histogram,i,0,slice));
398
      for (int i=0; i < H3D_GetNbinsX(histogram); i++ ) H1D_SetBinContent(499,i,H3D_GetBinContent(histogram,i,0,slice));
397
    } else {
399
    } else {
398
      H1D_Init(499,"projection","projection", H3D_GetNbinsY(histogram), H3D_GetMinY(histogram),H3D_GetMaxY(histogram));
400
      H1D_Init(499,"projection","projection", H3D_GetNbinsY(histogram), H3D_GetMinY(histogram),H3D_GetMaxY(histogram));
399
      for (int i=0; i < H3D_GetNbinsY(histogram); i++ ) H1D_SetBinContent(499,i,H3D_GetBinContent(histogram,0,i,slice));
401
      for (int i=0; i < H3D_GetNbinsY(histogram); i++ ) H1D_SetBinContent(499,i,H3D_GetBinContent(histogram,0,i,slice));
400
    }
402
    }
401
    H1D_Draw(499, panel, control, plothandle);
403
    H1D_Draw(499, panel, control, plothandle);
402
  } else {
404
  } else {
403
 
405
 
404
    if (*plothandle> 0 ) DeleteGraphPlot (panel, control, *plothandle, VAL_IMMEDIATE_DRAW);
406
    if (*plothandle> 0 ) DeleteGraphPlot (panel, control, *plothandle, VAL_IMMEDIATE_DRAW);
405
    H3D_SetRangeColors(H3D_GetMin(histogram),H3D_GetMax(histogram));
407
    H3D_SetRangeColors(H3D_GetMin(histogram),H3D_GetMax(histogram));
406
    *plothandle = PlotScaledIntensity (panel, control,
408
    *plothandle = PlotScaledIntensity (panel, control,
407
                                       H3D_GetSliceXYData(histogram, slice),
409
                                       H3D_GetSliceXYData(histogram, slice),
408
                                       H3D_GetNbinsX(histogram),
410
                                       H3D_GetNbinsX(histogram),
409
                                       H3D_GetNbinsY(histogram),
411
                                       H3D_GetNbinsY(histogram),
410
                                       VAL_DOUBLE,
412
                                       VAL_DOUBLE,
411
                                       H3D_GetStepY(histogram),
413
                                       H3D_GetStepY(histogram),
412
                                       H3D_GetYBinCenter(histogram,0),
414
                                       H3D_GetYBinCenter(histogram,0),
413
                                       H3D_GetStepX(histogram),
415
                                       H3D_GetStepX(histogram),
414
                                       H3D_GetXBinCenter(histogram,0),
416
                                       H3D_GetXBinCenter(histogram,0),
415
                                       colormap->array,
417
                                       colormap->array,
416
                                       colormap->HiColor,
418
                                       colormap->HiColor,
417
                                       colormap->numberofColors, 1, 0);
419
                                       colormap->numberofColors, 1, 0);
418
  }
420
  }
419
  ProcessSystemEvents ();
421
  ProcessSystemEvents ();
420
  return *plothandle;
422
  return *plothandle;
421
 
423
 
422
}
424
}
423
#endif
425
#endif
424
 
426