~ubuntu-branches/debian/jessie/eso-midas/jessie

« back to all changes in this revision

Viewing changes to libsrc/agl/ag_hist.c

  • Committer: Package Import Robot
  • Author(s): Ole Streicher
  • Date: 2014-04-22 14:44:58 UTC
  • Revision ID: package-import@ubuntu.com-20140422144458-okiwi1assxkkiz39
Tags: upstream-13.09pl1.2+dfsg
ImportĀ upstreamĀ versionĀ 13.09pl1.2+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*===========================================================================
 
2
  Copyright (C) 1995-2009 European Southern Observatory (ESO)
 
3
 
 
4
  This program is free software; you can redistribute it and/or 
 
5
  modify it under the terms of the GNU General Public License as 
 
6
  published by the Free Software Foundation; either version 2 of 
 
7
  the License, or (at your option) any later version.
 
8
 
 
9
  This program is distributed in the hope that it will be useful,
 
10
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
  GNU General Public License for more details.
 
13
 
 
14
  You should have received a copy of the GNU General Public 
 
15
  License along with this program; if not, write to the Free 
 
16
  Software Foundation, Inc., 675 Massachusetss Ave, Cambridge, 
 
17
  MA 02139, USA.
 
18
 
 
19
  Corresponding concerning ESO-MIDAS should be addressed as follows:
 
20
        Internet e-mail: midas@eso.org
 
21
        Postal address: European Southern Observatory
 
22
                        Data Management Division 
 
23
                        Karl-Schwarzschild-Strasse 2
 
24
                        D 85748 Garching bei Muenchen 
 
25
                        GERMANY
 
26
===========================================================================*/
 
27
 
 
28
/*
 
29
 * HEADER : ag_hist.c      - Vers 3.6.000  - Oct 1991 -  L. Fini, Oss. Arcetri
 
30
 *
 
31
 * AGL high level routine. Histogram generation
 
32
 
 
33
 .VERSION
 
34
 
 
35
 090630         last modif
 
36
 */
 
37
 
 
38
#include <aglenvr.h>
 
39
 
 
40
 
 
41
static void drwbin(xvaux,yvaux,xcurr,xnext,ynext,yzero,mode)
 
42
float xvaux[],yvaux[];
 
43
float xcurr,xnext,ynext,yzero;
 
44
int mode;
 
45
{
 
46
xvaux[1] = xcurr+(xnext-xcurr)*0.5;
 
47
yvaux[1] = yvaux[0];
 
48
(void)AG_GPLL(xvaux,yvaux,2);
 
49
 
 
50
xvaux[0]=xvaux[1];
 
51
 
 
52
if(mode!=0) {
 
53
        float max,min;
 
54
        if(yvaux[1]<yzero) {
 
55
                max=yzero;
 
56
                min=yvaux[1];
 
57
        } else {
 
58
                min=yzero;
 
59
                max=yvaux[1];
 
60
        }
 
61
        if(ynext<min)
 
62
                min=ynext;
 
63
        else if(ynext>max)
 
64
                max=ynext;
 
65
        yvaux[0]=min;
 
66
        yvaux[1]=max;
 
67
} else {
 
68
        yvaux[0]=yvaux[1];
 
69
        yvaux[1]=ynext;
 
70
}
 
71
 
 
72
(void)AG_GPLL(xvaux,yvaux,2);
 
73
 
 
74
yvaux[0]=ynext;
 
75
}
 
76
  
 
77
 
 
78
/*****************************************************************************/
 
79
/*++                          AG_HIST (User callable)                        */
 
80
 
 
81
/* AG_HIST                                                                   */
 
82
 
 
83
 
 
84
/* This module draws various forms of histogram plots from a couple of       */
 
85
/* coordinate vectors.                                                       */
 
86
 
 
87
/* NOTE: a window must be defined and the mode USER must be selected before  */
 
88
/*       calling AG_HIST (see: AG_WDEF and AG_SSET).                         */
 
89
 
 
90
/* Here follows a typical calling sequence for histogram plotting:           */
 
91
 
 
92
/*    AG_VDEF (.......)          Define graphic device                       */
 
93
/*    AG_AXES(x0,x1,y0,y1,sel)   Define and draw axes                        */
 
94
/*    AG_HIST(xv,yv,np,0,0)      Draw the histogram from data in vectors     */
 
95
/*                               xv,yv (length=np)                           */
 
96
/*    AG_CLS()                   Close AGL                                   */
 
97
 
 
98
 
 
99
void AG_HIST(xv,yv,np,mode,join)
 
100
 
 
101
float xv[],yv[];              /* Coordinate arrays                           */
 
102
 
 
103
int np;                       /* Array length                                */
 
104
 
 
105
int mode;                     /* Histogram type selection.                   */
 
106
                              /* Types available are the following:          */
 
107
 
 
108
                              /* mode=0  simple staircase.                   */
 
109
                              /* mode=1  staircase steps joined to x-axis.   */
 
110
                              /* mode<=2 data points joined to x-axis with   */
 
111
                              /*         boxes (current line width and style)*/
 
112
                              /*         with width starting from 0 (simple  */
 
113
                              /*         line) and increasing with mode      */
 
114
                              /*         value in steps of small character   */
 
115
                              /*         width                               */
 
116
int join;                     /* Flag to join more than one call into a      */
 
117
                              /* single histogram (used with modes: 0, 1)    */
 
118
                              /* join=0 : histogram closed at both ends.     */
 
119
                              /*          (used when all data points are     */
 
120
                              /*           plotted with a single call)       */
 
121
                              /* join=1 : histogram opened at the right end  */
 
122
                              /*          (used for the first block of an    */
 
123
                              /*           histogram built with many calls)  */
 
124
                              /* join=2 : histogram opened at the left end   */
 
125
                              /*          (used for the final block of an    */
 
126
                              /*           histogram built with many calls)  */
 
127
                              /* join=3 : histogram opened at both ends      */
 
128
                              /*          (used for the middle blocks of an  */
 
129
                              /*           histogram built with many calls)  */
 
130
                              /* N.B.: when using the join feature to plot a */
 
131
                              /*       long histogram built up with pieces   */
 
132
                              /*       DO NOT intermix calls to other AGL    */
 
133
                              /*       routines between calls to AG_HIST.    */
 
134
                                                                         /*--*/ 
 
135
{
 
136
static char *modnam = "HIST";
 
137
static float xvaux[4],yvaux[4];
 
138
static float xcurr,xnext,ynext,yzero;
 
139
float delta=0.0;
 
140
int i;
 
141
 
 
142
AG_DMSG(modnam,(char *)0);
 
143
  
 
144
AGL_push(modnam);
 
145
 
 
146
if(mode>0) {
 
147
        float wndl[4];
 
148
        (void)AG_RGET("wndl",wndl);
 
149
/*
 
150
        yzero=wndl[2];
 
151
*/
 
152
        yzero=0;
 
153
}
 
154
 
 
155
if(np>0) {
 
156
        if(mode<2) {
 
157
                if((join&02)==0) {
 
158
                        delta = (xv[1]-xv[0])*0.5;      /* deal with left  */
 
159
                        xvaux[0] = xv[0]-delta;         /* edge of histogram */
 
160
  
 
161
                        if(mode==0)
 
162
                                yvaux[0] = yv[0];
 
163
                        else {
 
164
                                yvaux[0] = yzero;
 
165
                                xvaux[1] = xvaux[0];
 
166
                                yvaux[1] = yv[0];
 
167
                                AG_GPLL(xvaux,yvaux,2);
 
168
                                yvaux[0] = yvaux[1];
 
169
                        }
 
170
                } else {
 
171
                        xnext=xv[0];            /* xcurr is the last point  */
 
172
                        ynext=yv[0];            /* of previous block        */
 
173
                        drwbin(xvaux,yvaux,xcurr,xnext,ynext,yzero,mode);
 
174
                }
 
175
 
 
176
                for(i=0; i<np-1; i++) {         /* This for the central part */
 
177
                        register int ii=i+1;
 
178
                        xcurr=xv[i];
 
179
                        xnext=xv[ii];
 
180
                        ynext=yv[ii];
 
181
                        drwbin(xvaux,yvaux,xcurr,xnext,ynext,yzero,mode);
 
182
                }
 
183
                xcurr=xv[np-1];                 /* needed for joining        */
 
184
 
 
185
        } else {                                /* Modes >= 2                 */
 
186
                int bw = mode-2;
 
187
                if(bw==0) {
 
188
                        for(i=0; i<np; i++) {
 
189
                                xvaux[0]=xv[i];
 
190
                                yvaux[0]=yzero;
 
191
                                xvaux[1]=xvaux[0];
 
192
                                yvaux[1]=yv[i];
 
193
                                (void)AG_GPLL(xvaux,yvaux,2);
 
194
                        }
 
195
                } else {
 
196
                        float fv[2],hbin;
 
197
 
 
198
                        (void)AG_RGET("nchdim",fv);
 
199
                        (void)AG_SSET("normal");
 
200
                        hbin = fv[0]/4.0*bw;
 
201
                        for(i=0; i<np; i++) {
 
202
                                AG_VU2N(xv[i],yzero,xvaux,yvaux);
 
203
                                AG_VU2N(xv[i],yv[i],xvaux+1,yvaux+1);
 
204
                                xvaux[2] = xvaux[0]+hbin;
 
205
                                xvaux[3] = xvaux[0]+hbin;
 
206
                                xvaux[0] -= hbin;
 
207
                                xvaux[1] -= hbin;
 
208
                                yvaux[2] = yvaux[1];
 
209
                                yvaux[3] = yvaux[0];
 
210
                                (void)AG_GPLL(xvaux,yvaux,4);
 
211
                        }
 
212
                }
 
213
        }
 
214
}
 
215
      
 
216
if(((join&01)==0)&&(mode<2)) {          /* deal with right edge of histogram */
 
217
        xnext=xcurr+2.0*delta;
 
218
        ynext=yvaux[0];
 
219
        drwbin(xvaux,yvaux,xcurr,xnext,ynext,yzero,mode);
 
220
}
 
221
AGL_pop();
 
222
}