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

« back to all changes in this revision

Viewing changes to prim/plot/libsrc/plerr.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) 1993-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
.IDENTifer   PLERR
 
30
.AUTHOR      R.M. van Hees IPG-ESO Garching
 
31
.KEYWORDS    low level plot routine
 
32
.LANGUAGE    C
 
33
.PURPOSE     Overplot error bars from one or two columns of a TABLE
 
34
        input: int   tid    Table identifier
 
35
               int   nrow   number of rows
 
36
               int   *col   column index
 
37
               int   *ilog  logarithm flag: 0) Lineair, 1) LOG10, 2) LN
 
38
                     int    loc    orientation of the error bar:
 
39
                                       1) pos X, 3) neg X, 5) both
 
40
                                       2) pos Y, 4) neg Y, 6) both
 
41
               char *bar    cross bar (y) or not (n)
 
42
 
 
43
.COMMENTS    none
 
44
.ENVIRONment MIDAS and AGL
 
45
             #include <agl.h>           Prototypes for AGL application programs
 
46
             #include <midas_def.h>     Prototypes for MIDAS interfaces
 
47
             #include <plot_def.h>      Symbols used by the PLT interfaces
 
48
 
 
49
.VERSION     1.1     10-Sep-1993   FORTRAN --> ANSI-C    RvH
 
50
 
 
51
090422          last modif
 
52
------------------------------------------------------------*/
 
53
/*
 
54
 * Define _POSIX_SOURCE to indicate
 
55
 * that this is a POSIX program
 
56
 */
 
57
#define  _POSIX_SOURCE 1
 
58
 
 
59
/*
 
60
 * definition of the used functions in this module
 
61
 */
 
62
#include <stdio.h>
 
63
#include <string.h>
 
64
#include <math.h>
 
65
 
 
66
#include <midas_def.h>
 
67
 
 
68
/*
 
69
 * define some macros and constants
 
70
 */
 
71
#include <plot_def.h>
 
72
 
 
73
/*
 
74
 * here start the code of the function
 
75
 */
 
76
void PLERR( tid, nrow, col, ilog, loc, bar )
 
77
char *bar;
 
78
int tid, nrow, *col, *ilog, loc;
 
79
 
 
80
{
 
81
register int ii, jj, nc;
 
82
int    actvals, isel, inull, ltype, nopoint, stat;
 
83
 
 
84
float  xmin, ymin, xerr, yerr, xbar[2], ybar[2], xval[2], yval[2], 
 
85
       xn[2], yn[2], xch[3], ych[3], pval[3], wcfram[8];
 
86
 
 
87
char   buff[81];
 
88
 
 
89
/*
 
90
 * pick up the frame settings
 
91
 */
 
92
PCKRDR( "XWNDL", 4, &actvals, wcfram );
 
93
PCKRDR( "YWNDL", 4, &actvals, wcfram+FOR_Y );
 
94
 
 
95
xmin = MYMIN( *wcfram, wcfram[1] );
 
96
ymin = MYMIN( wcfram[FOR_Y], wcfram[FOR_Y+1] );
 
97
                     
 
98
/*
 
99
 * initialise plot settings to normal
 
100
 */
 
101
(void) AG_IGET( "lstyl", &ltype );
 
102
AG_SSET( "lstyl=0" );                               /*set line style to solid*/
 
103
 
 
104
AG_TGET( "M", xch, ych );
 
105
xerr = xch[0] / 1.5;
 
106
yerr = ych[1] / 2.0;
 
107
 
 
108
for ( ii = 1; ii <= nrow; ii++ )
 
109
    { nopoint = FALSE;
 
110
      stat = TCSGET( tid, ii, &isel );
 
111
      if ( isel )
 
112
         { 
 
113
/*
 
114
 * pick up the values for resp. X-pos, Y-pos, Error bar:
 
115
 */
 
116
           for ( nc = 0; nc < 3; nc++ )
 
117
               { if ( col[nc] == 0 ) 
 
118
                    pval[nc] = ii;
 
119
                else if ( ! nopoint )
 
120
                    { stat = TCERDR( tid, ii, col[nc], pval+nc, &inull );
 
121
                      if ( inull || stat != ERR_NORMAL ) nopoint = TRUE;
 
122
                    }
 
123
               }
 
124
           if ( pval[2] < 0.0 ) pval[2] *= -1;
 
125
 
 
126
           if ( ! nopoint )
 
127
              { switch ( loc ) 
 
128
                   { case 1:                         /* error bars in pos. X */
 
129
                         xval[0] = *pval;
 
130
                         xval[1] = *pval + pval[2];
 
131
                         yval[0] = yval[1] = pval[1];
 
132
                         break;
 
133
                     case 3:                         /* error bars in neg. X */
 
134
                         xval[0] = *pval;
 
135
                         xval[1] = *pval - pval[2];
 
136
                         yval[0] = yval[1] = pval[1];
 
137
                         break;
 
138
                     case 5:                     /* two error bars in X dir. */
 
139
                         xval[0] = *pval - pval[2];
 
140
                         xval[1] = *pval + pval[2];
 
141
                         yval[0] = yval[1] = pval[1];
 
142
                         break;
 
143
                     case 2:                         /* error bars in pos. Y */
 
144
                         xval[0] = xval[1] = *(pval);
 
145
                         yval[0] = pval[1];
 
146
                         yval[1] = pval[1] + pval[2];
 
147
                         break;
 
148
                     case 4:                         /* error bars in neg. Y */
 
149
                         xval[0] = xval[1] = *(pval);
 
150
                         yval[0] = pval[1];
 
151
                         yval[1] = pval[1] - pval[2];
 
152
                         break;
 
153
                     case 6:                     /* two error bars in Y dir. */
 
154
                         xval[0] = xval[1] = *(pval);
 
155
                         yval[0] = pval[1] - pval[2];
 
156
                         yval[1] = pval[1] + pval[2];
 
157
                         break;
 
158
                   }
 
159
                if ( ! nopoint && ilog[0] != 0 )            /* log. X-values */
 
160
                   { if ( xval[1] > 0.0) 
 
161
                        { if ( xval[0] <= 0) xval[0] = xmin;
 
162
                          for ( jj = 0; jj < PLDIM2; jj++ )
 
163
                              { if ( xval[jj] > 0.0) 
 
164
                                   {
 
165
                                   if ( ilog[0] == 1 )
 
166
                                      xval[jj] = (float) log10( xval[jj] );
 
167
                                   else
 
168
                                      xval[jj] = (float) log( xval[jj] );
 
169
                                   }
 
170
                              }
 
171
                        }
 
172
                     else
 
173
                        nopoint = TRUE;
 
174
                   }
 
175
 
 
176
                if ( ! nopoint && ilog[1] != 0 )            /* log. Y-values */
 
177
                   { if ( yval[1] > 0.0) 
 
178
                        { if (yval[0] <= 0) yval[0] = ymin;
 
179
                          for ( jj = 0; jj < PLDIM2; jj++ )
 
180
                              { if ( yval[jj] > 0) 
 
181
                                   {
 
182
                                   if ( ilog[1] == 1 )
 
183
                                      yval[jj] = (float) log10( yval[jj] );
 
184
                                   else
 
185
                                      yval[jj] = (float) log( yval[jj] );
 
186
                                   }
 
187
                              }
 
188
                        }
 
189
                     else
 
190
                        nopoint = TRUE;
 
191
                   }
 
192
/*
 
193
 * check on logarithmic axes settings
 
194
 */
 
195
                if ( wcfram[3] < 0 )
 
196
                   { if ( xval[1] <= 0 )
 
197
                        nopoint = TRUE;
 
198
                     else if ( *xval <= 0 )
 
199
                        { if ( CGN_NINT( wcfram[3] ) == -1 )
 
200
                             *xval = (float) pow( 10.0, xmin );
 
201
                          else
 
202
                             *xval = (float) exp( xmin );
 
203
                        }
 
204
                   }
 
205
                if ( wcfram[FOR_Y+3] < 0 )
 
206
                   { if ( yval[1] <= 0 )
 
207
                        nopoint = TRUE;
 
208
                     else if ( *yval <= 0 )
 
209
                        { if ( CGN_NINT( wcfram[FOR_Y+3] ) == -1 )
 
210
                             *yval = (float) pow( 10.0, ymin );
 
211
                          else
 
212
                             *yval = (float) exp( ymin );
 
213
                        }
 
214
                   }
 
215
              }
 
216
/*
 
217
 * start the plotting
 
218
 */
 
219
           if ( ! nopoint )
 
220
              { AG_GPLL( xval, yval, 2 );
 
221
/*
 
222
 * draw the error bar
 
223
 */
 
224
                if ( *bar == 'y' || *bar == 'Y' ) 
 
225
                   { switch ( loc )
 
226
                        { case 5:
 
227
                              AG_VU2N( xval[0], yval[0], xn, yn );
 
228
                              *(xn+1) = *xn;
 
229
                              *yn     -= yerr / 2;
 
230
                              *(yn+1) = *yn + yerr;
 
231
                              AG_VN2U( *xn, *yn, xbar, ybar );
 
232
                              AG_VN2U( *(xn+1), *(yn+1), xbar+1, ybar+1 );
 
233
                              AG_GPLL( xbar, ybar, 2 );
 
234
                          case 1:
 
235
                          case 3:
 
236
                              AG_VU2N( xval[1], yval[0], xn, yn );
 
237
                              *(xn+1) = *xn;
 
238
                              *yn     -= yerr / 2;
 
239
                              *(yn+1) = *yn + yerr;
 
240
                              AG_VN2U( *xn, *yn, xbar, ybar );
 
241
                              AG_VN2U( *(xn+1), *(yn+1), xbar+1, ybar+1 );
 
242
                              AG_GPLL( xbar, ybar, 2 );
 
243
                              break;
 
244
                          case 6:
 
245
                              AG_VU2N( xval[0], yval[0], xn, yn );
 
246
                              *xn     -= xerr / 2;
 
247
                              *(xn+1) = *xn + xerr;
 
248
                              *(yn+1) = *yn;
 
249
                              AG_VN2U( *xn, *yn, xbar, ybar );
 
250
                              AG_VN2U( *(xn+1), *(yn+1), xbar+1, ybar+1 );
 
251
                              AG_GPLL( xbar, ybar, 2 );
 
252
                          case 2:
 
253
                          case 4:
 
254
                              AG_VU2N( xval[0], yval[1], xn, yn );
 
255
                              *xn     -= xerr / 2;
 
256
                              *(xn+1) = *xn + xerr;
 
257
                              *(yn+1) = *yn;
 
258
                              AG_VN2U( *xn, *yn, xbar, ybar );
 
259
                              AG_VN2U( *(xn+1), *(yn+1), xbar+1, ybar+1 );
 
260
                              AG_GPLL( xbar, ybar, 2 );
 
261
                              break;
 
262
                        }
 
263
                   }
 
264
              }
 
265
         }
 
266
    }
 
267
if ( ltype > 0 )
 
268
   { (void) sprintf( buff, "lstyl=%1d", ltype );
 
269
     AG_SSET( buff );
 
270
   }
 
271
}
 
272