Subversion Repositories f9daq

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
326 f9daq 1
#include <userint.h>
2
#include "CAEN_V729_CVI.h"
3
#include "HDraw.h"
4
#include "H3D.h"
5
#include "H2D.h"
6
#include "H1D.h"
7
 
8
HColorMap *colormap = NULL;
9
 
10
int hmapinit=0;
11
 
12
int InitColors(void) {
13
  if (!hmapinit) {
14
    colormap = malloc(sizeof(HColorMap));
15
 
16
    colormap->numberofColors = 5;
17
    colormap->array = malloc(colormap->numberofColors*sizeof(ColorMapEntry));
18
 
19
    colormap->array[0].color = 0x0000ff; //BLUE
20
    colormap->array[1].color = 0x00ff00; //GREEN
21
    colormap->array[2].color = 0xffff00; //YELLOW
22
    colormap->array[3].color = 0xff8000; //ORANGE
23
    colormap->array[4].color = 0xff0000; //RED
24
 
25
    colormap->HiColor =colormap->array[colormap->numberofColors-1].color ;
26
    hmapinit=1;
27
 
28
    return 0;
29
  }
30
  return -1;
31
}
32
 
33
 
34
 
35
HColorMap *GetColorMapPtr(void) {
36
  return colormap;
37
}
38
 
39
 
40
int RangeColors( double min, double max) {
41
  int i;
42
  if (!hmapinit) InitColors();
43
 
44
//if (zerosuppress){
45
//  if (min>0) min=0;
46
//}
47
  if (colormap->numberofColors<2) return -1;
48
  for  (i=0; i<colormap->numberofColors; i++) {
49
 
50
    colormap->array[i].dataValue.valDouble=i*(max-min)/(colormap->numberofColors-1)+min;
51
    //sa02Printf("Colors %d ;%f %f %f\n",i, min,max,colormap->array[i].dataValue.valDouble );
52
 
53
  }
54
  return 0;
55
}
56
 
57
int H3DDrawSliceXY(int histogram,int slice,int panel, int control, int *plothandle) {
58
  int i=0;
59
  if (!H2DExist(histogram)) {
60
    printf("2D Histogram %d does not exist!\n",histogram);
61
    return 0;
62
  }
63
 
64
 
65
  if (H3DGetNbinsY(histogram)==1|| H3DGetNbinsX(histogram)==1) {
66
    if (H3DGetNbinsY(histogram)==1) {
67
      H1DInit(499,"projection","projection", H3DGetNbinsX(histogram), H3DGetMinX(histogram),H3DGetStepX(histogram));
68
      for (i=0; i < H3DGetNbinsX(histogram); i++ ) H1DSetBinContent(499,i,H3DGetBinContent(histogram,i,0,slice));
69
    } else {
70
      H1DInit(499,"projection","projection", H3DGetNbinsY(histogram), H3DGetMinY(histogram),H3DGetStepY(histogram));
71
      for (i=0; i < H3DGetNbinsY(histogram); i++ ) H1DSetBinContent(499,i,H3DGetBinContent(histogram,0,i,slice));
72
    }
73
    H1DDraw(499, panel, control, plothandle);
74
  } else {
75
 
76
    if (*plothandle> 0 ) DeleteGraphPlot (panel, control, *plothandle, VAL_IMMEDIATE_DRAW);
77
    RangeColors(H3DGetMin(histogram),H3DGetMax(histogram));
78
    *plothandle = PlotScaledIntensity (panel, control,
79
                                       H3DGetSliceXYData(histogram, slice),
80
                                       H3DGetNbinsX(histogram),
81
                                       H3DGetNbinsY(histogram),
82
                                       VAL_DOUBLE,
83
                                       H3DGetStepY(histogram),
84
                                       H3DGetMinY(histogram),
85
                                       H3DGetStepX(histogram),
86
                                       H3DGetMinX(histogram),
87
                                       colormap->array,
88
                                       colormap->HiColor,
89
                                       colormap->numberofColors, 1, 0);
90
  }
91
  ProcessSystemEvents ();
92
  return *plothandle;
93
 
94
}
95
 
96
 
97
 
98
 
99
 
100
int H2DDraw(int histogram,int panel, int control, int *plothandle) {
101
  int i=0;
102
  if (!H2DExist(histogram)) {
103
    printf("2D Histogram %d does not exist!\n",histogram);
104
    return 0;
105
  }
106
 
107
 
108
  if (H2DGetNbinsY(histogram)==1|| H2DGetNbinsX(histogram)==1) {
109
    if (H2DGetNbinsY(histogram)==1) {
110
      H1DInit(499,"projection","projection", H2DGetNbinsX(histogram), H2DGetMinX(histogram),H2DGetStepX(histogram));
111
      for (i=0; i < H2DGetNbinsX(histogram); i++ ) H1DSetBinContent(499,i,H2DGetBinContent(histogram,i,0));
112
    } else {
113
      H1DInit(499,"projection","projection", H2DGetNbinsY(histogram), H2DGetMinY(histogram),H2DGetStepY(histogram));
114
      for (i=0; i < H2DGetNbinsY(histogram); i++ ) H1DSetBinContent(499,i,H2DGetBinContent(histogram,0,i));
115
    }
116
    H1DDraw(499, panel, control, plothandle);
117
  } else {
118
    if (*plothandle> 0 ) DeleteGraphPlot (panel, control, *plothandle, VAL_IMMEDIATE_DRAW);
119
    double min = H2DGetMin(histogram);
120
    double max = H2DGetMax(histogram);
121
    RangeColors(min,max);
122
    *plothandle = PlotScaledIntensity (panel, control,
123
                                       H2DGetData(histogram),
124
                                       H2DGetNbinsX(histogram),
125
                                       H2DGetNbinsY(histogram),
126
                                       VAL_DOUBLE,
127
                                       H2DGetStepY(histogram),
128
                                       H2DGetMinY(histogram),
129
                                       H2DGetStepX(histogram),
130
                                       H2DGetMinX(histogram),
131
                                       colormap->array,
132
                                       colormap->HiColor,
133
                                       colormap->numberofColors, 1, 0);
134
  }
135
  ProcessSystemEvents ();
136
  return *plothandle;
137
 
138
}
139
 
140
 
141
unsigned int hcolors[8]={VAL_RED, VAL_GREEN, VAL_BLUE, VAL_CYAN, VAL_MAGENTA, VAL_YELLOW, VAL_GRAY, VAL_BLACK};
142
 
143
int H1DDraw(int histogram,int panel, int control, int *plothandle) {
144
  if (!H1DExist(histogram)) {
145
    printf("1D Histogram %d does not exist!\n",histogram);
146
    return 0;
147
  }
148
  if (*plothandle> 0 ) DeleteGraphPlot (panel, control, *plothandle, VAL_IMMEDIATE_DRAW);
149
 
150
  *plothandle = PlotWaveform (panel, control, H1DGetData(histogram), H1DGetNbinsX(histogram), VAL_DOUBLE, 1, 0, H1DGetMinX(histogram), H1DGetStepX(histogram), VAL_FAT_LINE, VAL_SMALL_SOLID_SQUARE, VAL_SOLID, 1,
151
                                                          hcolors[histogram%8]);
152
  ProcessSystemEvents ();
153
  return *plothandle;
154
 
155
}
156
 
157
int EstimatedFinish(int panel, int slider,int txt, time_t tstart, double fraction) {
158
 
159
  time_t t, tend=tstart;
160
  time(&t);
161
  if (fraction>0) tend= ((double)(t-tstart))/fraction + tstart;
162
  SetCtrlVal(panel, txt, ctime(&tend));
163
  SetCtrlVal(panel, slider, 100*fraction);
164
 
165
  return 0;
166
 
167
}
168
 
169