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

« back to all changes in this revision

Viewing changes to prim/plot/src/plotgra.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-2011 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 Massachusetts Ave, Cambridge, 
 
17
  MA 02139, USA.
 
18
 
 
19
  Correspondence 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
.IDENTIFIER  PLOTGRA
 
30
.AUTHOR      R.M. van Hees IPG-ESO Garching
 
31
.KEYWORDS    Graphics, bulk data frame, one-dimensional plotting
 
32
.LANGUAGE    C
 
33
.PURPOSE     Plot or overplot a gray scale map
 
34
  in/output: IN_A/C/1/60   = input frame
 
35
             IN_B/C/1/60   = coord_string
 
36
             P3/R/1/4      = scales in X and Y and offset X and Y
 
37
                             (default is auto scaling to device filling)
 
38
             INPUTC/C/1/40  = gray scales
 
39
             INPUTC/C/41/40 = options: option1[,option2[,option3]]
 
40
                  LOG  = logarythmic greyness     (default: LINear)
 
41
                  NEG  = inverse grey scale       (default: original values)
 
42
                  ABS  = abs. values are taken    (default: not absolute)
 
43
                  STAP = greyness increases stepw.(default: CONtinuous)
 
44
             INPUTI/I/1/1   = size of the smoothing box
 
45
             INPUTR/R/3/1   = greyness of the plot (0.0 --> 1.0)
 
46
 
 
47
.COMMENTS    none
 
48
.ENVIRONment MIDAS
 
49
             #include <midas_def.h>     Prototypes for MIDAS interfaces
 
50
             #include <plot_def.h>      General symbols for Plot routines
 
51
 
 
52
.VERSION     1.0     20-Aug-1993   FORTRAN --> ANSI-C    RvH
 
53
 
 
54
 110930         last modif
 
55
 
 
56
------------------------------------------------------------*/
 
57
/*
 
58
 * Define _POSIX_SOURCE to indicate
 
59
 * that this is a POSIX program
 
60
 */
 
61
#define _POSIX_SOURCE 1
 
62
 
 
63
/*
 
64
 * definition of the used functions
 
65
 */
 
66
#include <stdio.h>
 
67
#include <string.h>
 
68
#include <stdlib.h>
 
69
#include <math.h>
 
70
 
 
71
/*
 
72
 * define some macros and constants
 
73
 */
 
74
#include <midas_def.h>
 
75
#include <plot_def.h>
 
76
 
 
77
#define MAXLEV          50
 
78
#define MAXPIX          512    /* max frame dimension (X,Y) accessed at once */
 
79
#define MAXSIZ          (MAXPIX * MAXPIX)
 
80
 
 
81
/*
 
82
 * here starts the code of the function
 
83
 */
 
84
int main()
 
85
{
 
86
register int ii;
 
87
int     actvals, chunks, imf, knul, last_row, naxis, size, stat, unit, 
 
88
        ndum[PLDIM2], npix[PLDIM2], sublo[PLDIM2], subhi[PLDIM2];
 
89
 
 
90
float   amin, amax, greynes, *p_img, nrpix[2], area[4], image[4], wcfram[12],
 
91
        glevl[MAXLEV];
 
92
 
 
93
double  start[PLDIM2], step[PLDIM2];
 
94
 
 
95
char    cmnd[21], ident[33], cunit[49], name[61], input[82], buff[81], 
 
96
        *label[4], *cbuff;
 
97
/*
 
98
 * initialised variables
 
99
 */
 
100
char  *err_usrin = "*** FATAL: error detected in USRINP",
 
101
      *err_1dim = "*** FATAL: frame has only one dimension",
 
102
      *err_1lev = "*** WARNING: only one level given, will use min. and max. in frame",
 
103
      *err_flat = "*** WARNING: zero dynamic range in data at %13.8g",
 
104
      *err_coord = "*** FATAL: invalid coordinate input ...",
 
105
      *err_xcuts = "*** FATAL: range in x has no overlap with current graph abscissa - NO PLOT",
 
106
      *err_ycuts = "*** FATAL: range in y has no overlap with current graph abscissa - NO PLOT";
 
107
 
 
108
int   access =  0,                        /* parameter for PCOPEN: plot mode */
 
109
      plmode = -1,                     /* plot mode taken from keyword PMODE */
 
110
      nlevl  =  0,                     /* Default number of contours is zero */
 
111
      ismoot =  1;                        /* Default no smooting of the data */
 
112
static int  options[] = { FALSE, FALSE, FALSE, FALSE, FALSE };
 
113
                                       /* The defaults for gray_options are: */
 
114
                                       /*   0) lineair increasing grayness   */
 
115
                                       /*   1) cont. increasing gray scales  */
 
116
                                       /*   2) leave signs unchanged         */
 
117
                                       /*   3) do NOT take absolute values   */
 
118
                                       /*   4) intensities above highest     */
 
119
                                       /*      contour, get the grayness     */
 
120
                                       /*      of the highest level          */
 
121
 
 
122
static char *axis[PLDIM2] = { "MANU", "MANU" };
 
123
 
 
124
/*
 
125
 * allocate memory for different character pointers and initialise a few
 
126
 */
 
127
for ( ii = 0; ii < 4; ii++ ) label[ii] = osmmget(81);
 
128
 
 
129
(void) strcpy( label[0], "Position (" );
 
130
(void) strcpy( label[1], "Position (" );
 
131
(void) strcpy( label[2], "Image: " );
 
132
(void) strcpy( label[3], "Ident: " );
 
133
 
 
134
/*
 
135
 * start of executable code
 
136
 */
 
137
(void) SCSPRO( "PLTGRA" );                   /*contact with the MIDAS monitor*/
 
138
 
 
139
/*
 
140
 * plot or overplot mode
 
141
 */
 
142
(void) SCKGETC( "MID$CMND", 1, 20, &actvals, cmnd );
 
143
if ( *cmnd == 'O' ) access = 1;
 
144
 
 
145
/*
 
146
 * find file name and read header information
 
147
 */
 
148
(void) SCKGETC( "IN_A", 1, 60, &actvals, name );
 
149
(void) SCFOPN( name, D_R4_FORMAT, 0, F_IMA_TYPE, &imf );
 
150
(void) SCDRDI( imf, "NAXIS", 1, 1, &actvals, &naxis, &unit, &knul );
 
151
(void) SCDRDI( imf, "NPIX" , 1, PLDIM2, &actvals, npix , &unit, &knul );
 
152
 
 
153
/*
 
154
 * check frame parameters
 
155
 */
 
156
if ( naxis < 2 || (npix[0] == 1 || npix[1] == 1) ) SCETER( 1, err_1dim );
 
157
 
 
158
/*
 
159
 * read rest descriptor
 
160
 */
 
161
(void) SCDRDD( imf, "START", 1, PLDIM2, &actvals, start, &unit, &knul );
 
162
(void) SCDRDD( imf, "STEP" , 1, PLDIM2, &actvals, step , &unit, &knul );
 
163
(void) SCDGETC( imf, "IDENT", 1, 32, &actvals, ident );
 
164
(void) SCDGETC( imf, "CUNIT", 1, 48, &actvals, cunit );
 
165
 
 
166
/*
 
167
 * Get the manual setting for the axes
 
168
 */
 
169
PCKRDR( "XAXIS", 4, &actvals, wcfram );
 
170
PCKRDR( "YAXIS", 4, &actvals, wcfram+FOR_Y );
 
171
 
 
172
/*
 
173
 * read window coordinates and take action
 
174
 */
 
175
(void) SCKGETC( "IN_B", 1, 60, &actvals, input );
 
176
 
 
177
if ( *input == 'm' || *input == 'M' )                      /* manual scaling */
 
178
   { BOXWTP( wcfram,       npix[0], start[0], step[0], image );
 
179
     BOXWTP( wcfram+FOR_Y, npix[1], start[1], step[1], image+2 );
 
180
   }
 
181
else
 
182
   { if ( *input == 'c' || *input == 'C' )                  /* display input */
 
183
        { (void) SCKRDR( "OUTPUTR", 10, 1, &actvals, image, &unit, &knul);
 
184
          (void) SCKRDR( "OUTPUTR", 11, 1, &actvals, image+2, &unit, &knul); 
 
185
          (void) SCKRDR( "OUTPUTR", 15, 1, &actvals, image+1, &unit, &knul);
 
186
          (void) SCKRDR( "OUTPUTR", 16, 1, &actvals, image+3, &unit, &knul);
 
187
        }
 
188
     else                                               /* automatic scaling */
 
189
        { stat = Convcoo(1,imf,input,PLDIM2,ndum,sublo,subhi);
 
190
          if ( stat != ERR_NORMAL ) SCETER( 2, err_coord );
 
191
          image[0] = sublo[0] + 1;
 
192
          image[1] = subhi[0] + 1;
 
193
          image[2] = sublo[1] + 1;
 
194
          image[3] = subhi[1] + 1;
 
195
        }
 
196
   }
 
197
BOXPTW( image,   npix[0], start[0], step[0], area );
 
198
BOXPTW( image+2, npix[1], start[1], step[1], area+2 );
 
199
 
 
200
PCKWRR( "PIXEL", 4, image );
 
201
 
 
202
if ( access == 0 )
 
203
   { 
 
204
/*
 
205
 * get size of frame along X-axis
 
206
 */
 
207
     if ( fabs( *wcfram ) < PLT_EPS && fabs( *(wcfram+1) ) < PLT_EPS )
 
208
        { axis[0] = "AUTO";
 
209
          wcfram[0] = area[0];
 
210
          wcfram[1] = area[1]; 
 
211
          wcfram[2] = wcfram[3] = 0.0;
 
212
        }
 
213
/*
 
214
 * get size of frame along Y-axis
 
215
 */
 
216
     if ( fabs( *(wcfram+FOR_Y) ) < PLT_EPS 
 
217
          && fabs( *(wcfram+FOR_Y+1) ) < PLT_EPS )
 
218
        { axis[1] = "AUTO";
 
219
          wcfram[FOR_Y]   = area[2];
 
220
          wcfram[FOR_Y+1] = area[3]; 
 
221
        }
 
222
     GETFRM( axis[0], wcfram );
 
223
     GETFRM( axis[1], wcfram + FOR_Y );
 
224
     PCKWRR( "XWNDL", 4, wcfram );
 
225
     PCKWRR( "YWNDL", 4, wcfram+FOR_Y );
 
226
   }
 
227
else                                                         /* overplot mode*/
 
228
   { PCKRDR( "XWNDL", 4, &actvals, wcfram );
 
229
     PCKRDR( "YWNDL", 4, &actvals, wcfram+FOR_Y );
 
230
/*
 
231
 * does overplot data fall within plotted frame? 
 
232
 */
 
233
     amin = MYMIN( *wcfram, *(wcfram + 1) );
 
234
     amax = MYMAX( *wcfram, *(wcfram + 1) );
 
235
     if ( ( MYMAX( area[0], area[1] ) < amin ) ||
 
236
          ( MYMIN( area[0], area[1] ) > amax ) )
 
237
        SCETER( 3, err_xcuts );
 
238
 
 
239
     amin = MYMIN( *(wcfram + FOR_Y), *(wcfram + FOR_Y+1) );
 
240
     amax = MYMAX( *(wcfram + FOR_Y), *(wcfram + FOR_Y+1) );
 
241
     if ( ( MYMAX( area[2], area[3] ) < amin ) ||
 
242
          ( MYMIN( area[2], area[3] ) > amax ) )
 
243
        SCETER( 4, err_ycuts );
 
244
   }
 
245
/*
 
246
 * store min and max of frame
 
247
 */
 
248
(void) SCDRDR( imf, "LHCUTS", 1, 4, &actvals, wcfram+FOR_Z, &unit, &knul);
 
249
if ( wcfram[FOR_Z] >= wcfram[FOR_Z+1] )
 
250
   { if ( wcfram[FOR_Z+2] >= wcfram[FOR_Z+3] )
 
251
        { (void) sprintf( buff, err_flat, wcfram[FOR_Z] );
 
252
          SCTPUT( buff );
 
253
        }
 
254
     else
 
255
        { *(wcfram+FOR_Z)   = *(wcfram+FOR_Z+2);
 
256
          *(wcfram+FOR_Z+1) = *(wcfram+FOR_Z+3);
 
257
        } 
 
258
   }
 
259
PCKWRR( "ZWNDL", 2, wcfram+FOR_Z );
 
260
 
 
261
/*
 
262
 * get the levels and smoothing parameter
 
263
 */
 
264
(void) SCKGETC( "INPUTC", 1, 40, &actvals, input );
 
265
CGN_LOWSTR( input );
 
266
if ( strncmp( input, "def", 3 ) != 0 )
 
267
   { cbuff = (char *) glevl;
 
268
     if ( USRINP( 'r', input, MAXLEV, cbuff, &nlevl ) != ERR_NORMAL )
 
269
        SCETER( 5, err_usrin );
 
270
/*
 
271
 * sort them
 
272
 */
 
273
     SORLEV( nlevl-1, glevl );
 
274
     if ( nlevl > 2 ) options[1] = TRUE;
 
275
   }
 
276
else
 
277
   { glevl[0] = wcfram[FOR_Z];
 
278
     glevl[1] = wcfram[FOR_Z+1];
 
279
     nlevl    = 2;
 
280
   }
 
281
/*
 
282
 * check for more than one input level
 
283
 */
 
284
if ( nlevl < 1 )
 
285
   { SCTPUT( err_1lev );
 
286
     glevl[0] = wcfram[FOR_Z];
 
287
     glevl[1] = wcfram[FOR_Z+1];
 
288
     nlevl    = 2;
 
289
   }
 
290
/*
 
291
 * get the smooting parameter
 
292
 */
 
293
(void) SCKRDI( "INPUTI", 1, 1, &actvals, &ismoot, &unit, &knul);
 
294
 
 
295
/*
 
296
 * get the greyness
 
297
 */
 
298
(void) SCKRDR( "INPUTR", 3, 1, &actvals, &greynes, &unit, &knul);
 
299
if ( greynes < 0.0 || greynes > 1.0 ) greynes = 1.0;
 
300
 
 
301
/*
 
302
 * get options
 
303
 */
 
304
(void) SCKGETC( "INPUTC", 41, 80, &actvals, input );
 
305
CGN_LOWSTR( input );
 
306
 
 
307
if ( strin( input, "log" ) )  options[0] = TRUE;
 
308
if ( strin( input, "step" ) ) options[1] = TRUE;
 
309
if ( strin( input, "neg" ) )  options[2] = TRUE;
 
310
if ( strin( input, "abs" ) )  options[3] = TRUE;
 
311
if ( strin( input, "cut" ) )  options[4] = TRUE;
 
312
 
 
313
/*
 
314
 * setup graphic device according to MIDAS settings
 
315
 */
 
316
PCOPEN( " ", " ", access, &plmode );
 
317
 
 
318
/*
 
319
 * determine number of pixels and number of chunks
 
320
 */
 
321
nrpix[0] = (int) fabs( image[1] - image[0] ) + 1;
 
322
nrpix[1] = (int) fabs( image[3] - image[2] ) + 1;
 
323
last_row = MYMAX( image[2], image[3]);
 
324
chunks   = (int) ceil( (double) nrpix[0] * nrpix[1] / MAXSIZ );
 
325
nrpix[1] = (int) ceil( (double) nrpix[1] / chunks );
 
326
 
 
327
/*
 
328
 * allocate virtual memory and scratch space
 
329
 */
 
330
size  = nrpix[0] * nrpix[1];
 
331
p_img = (float *) osmmget( size * sizeof( float ));
 
332
 
 
333
for ( ii = 0; ii < chunks; ii++ )
 
334
    { if ( image[3] > image[2] )                        /* size of chunk p.c.*/
 
335
         { if ( ii > 0 ) image[2] += nrpix[1] - 1.0;
 
336
           image[3] = MYMIN( last_row, image[2] + nrpix[1] - 1 );
 
337
         }
 
338
      else
 
339
         { if ( ii > 0 ) image[3] += nrpix[1] - 1.0;
 
340
           image[2] = MYMIN( last_row, image[3] + nrpix[1] - 1 );
 
341
         }
 
342
/*
 
343
 * get size of chunk in w.c.
 
344
 */
 
345
      BOXPTW( image+2, npix[1], start[1], step[1], area+2 );      
 
346
/*
 
347
 * extract chunck from original frame
 
348
 */
 
349
      GETDAT( imf, MAXSIZ, npix, image, ismoot, p_img );
 
350
/*
 
351
 * do it!!
 
352
 */
 
353
      PLGRA( p_img, image, area, step, glevl, nlevl, options, greynes );
 
354
/*
 
355
 * updating for the next loop
 
356
 */
 
357
      nrpix[1] = MYMIN( last_row - ii * nrpix[1], nrpix[1] );
 
358
      size  = nrpix[0] * nrpix[1];
 
359
    }
 
360
(void) SCFCLO( imf );
 
361
 
 
362
/*
 
363
 * draw the axes and the label
 
364
 */
 
365
if ( plmode >= 0 && access == 0 )
 
366
   { if ( strlen( cunit ) > (size_t) 32 )
 
367
        { (void) strcat( label[1], cunit+32 );
 
368
          *(cunit+32) = '\0';
 
369
        }
 
370
     if ( strlen( cunit ) > (size_t) 16 ) (void) strcat( label[0], cunit+16 );
 
371
 
 
372
     for ( ii = 0; ii < PLDIM2; ii++ )
 
373
         { (void) strcat( label[ii], ")" );
 
374
           LABSTR( label[ii] );
 
375
         }
 
376
/*
 
377
 * plot axes and labels
 
378
 */
 
379
     PCFRAM( wcfram, wcfram+FOR_Y, label[0], label[1] );
 
380
 
 
381
     if ( plmode == 1 )
 
382
        { (void) strcat( label[2], name );
 
383
          (void) strcat( label[3], ident );
 
384
          WEDGE( step, glevl, nlevl, options, greynes );
 
385
          PLIDEN( plmode, label[2], label[3] );
 
386
        }
 
387
     else if ( plmode == 2 )
 
388
        PLGRAI( plmode, name, ident, nlevl, glevl, options );
 
389
   }
 
390
/*
 
391
 * close plot file and terminate graphic operations
 
392
 */
 
393
PCCLOS();
 
394
 
 
395
return SCSEPI();
 
396
}