1
/*===========================================================================
2
Copyright (C) 1993-2011 European Southern Observatory (ESO)
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.
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.
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,
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
26
===========================================================================*/
28
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30
.AUTHOR R.M. van Hees IPG-ESO Garching
31
.KEYWORDS Graphics, bulk data frame, one-dimensional plotting
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)
49
#include <midas_def.h> Prototypes for MIDAS interfaces
50
#include <plot_def.h> General symbols for Plot routines
52
.VERSION 1.0 20-Aug-1993 FORTRAN --> ANSI-C RvH
56
------------------------------------------------------------*/
58
* Define _POSIX_SOURCE to indicate
59
* that this is a POSIX program
61
#define _POSIX_SOURCE 1
64
* definition of the used functions
72
* define some macros and constants
74
#include <midas_def.h>
78
#define MAXPIX 512 /* max frame dimension (X,Y) accessed at once */
79
#define MAXSIZ (MAXPIX * MAXPIX)
82
* here starts the code of the function
87
int actvals, chunks, imf, knul, last_row, naxis, size, stat, unit,
88
ndum[PLDIM2], npix[PLDIM2], sublo[PLDIM2], subhi[PLDIM2];
90
float amin, amax, greynes, *p_img, nrpix[2], area[4], image[4], wcfram[12],
93
double start[PLDIM2], step[PLDIM2];
95
char cmnd[21], ident[33], cunit[49], name[61], input[82], buff[81],
98
* initialised variables
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";
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 */
122
static char *axis[PLDIM2] = { "MANU", "MANU" };
125
* allocate memory for different character pointers and initialise a few
127
for ( ii = 0; ii < 4; ii++ ) label[ii] = osmmget(81);
129
(void) strcpy( label[0], "Position (" );
130
(void) strcpy( label[1], "Position (" );
131
(void) strcpy( label[2], "Image: " );
132
(void) strcpy( label[3], "Ident: " );
135
* start of executable code
137
(void) SCSPRO( "PLTGRA" ); /*contact with the MIDAS monitor*/
140
* plot or overplot mode
142
(void) SCKGETC( "MID$CMND", 1, 20, &actvals, cmnd );
143
if ( *cmnd == 'O' ) access = 1;
146
* find file name and read header information
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 );
154
* check frame parameters
156
if ( naxis < 2 || (npix[0] == 1 || npix[1] == 1) ) SCETER( 1, err_1dim );
159
* read rest descriptor
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 );
167
* Get the manual setting for the axes
169
PCKRDR( "XAXIS", 4, &actvals, wcfram );
170
PCKRDR( "YAXIS", 4, &actvals, wcfram+FOR_Y );
173
* read window coordinates and take action
175
(void) SCKGETC( "IN_B", 1, 60, &actvals, input );
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 );
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);
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;
197
BOXPTW( image, npix[0], start[0], step[0], area );
198
BOXPTW( image+2, npix[1], start[1], step[1], area+2 );
200
PCKWRR( "PIXEL", 4, image );
205
* get size of frame along X-axis
207
if ( fabs( *wcfram ) < PLT_EPS && fabs( *(wcfram+1) ) < PLT_EPS )
211
wcfram[2] = wcfram[3] = 0.0;
214
* get size of frame along Y-axis
216
if ( fabs( *(wcfram+FOR_Y) ) < PLT_EPS
217
&& fabs( *(wcfram+FOR_Y+1) ) < PLT_EPS )
219
wcfram[FOR_Y] = area[2];
220
wcfram[FOR_Y+1] = area[3];
222
GETFRM( axis[0], wcfram );
223
GETFRM( axis[1], wcfram + FOR_Y );
224
PCKWRR( "XWNDL", 4, wcfram );
225
PCKWRR( "YWNDL", 4, wcfram+FOR_Y );
227
else /* overplot mode*/
228
{ PCKRDR( "XWNDL", 4, &actvals, wcfram );
229
PCKRDR( "YWNDL", 4, &actvals, wcfram+FOR_Y );
231
* does overplot data fall within plotted frame?
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 );
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 );
246
* store min and max of frame
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] );
255
{ *(wcfram+FOR_Z) = *(wcfram+FOR_Z+2);
256
*(wcfram+FOR_Z+1) = *(wcfram+FOR_Z+3);
259
PCKWRR( "ZWNDL", 2, wcfram+FOR_Z );
262
* get the levels and smoothing parameter
264
(void) SCKGETC( "INPUTC", 1, 40, &actvals, 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 );
273
SORLEV( nlevl-1, glevl );
274
if ( nlevl > 2 ) options[1] = TRUE;
277
{ glevl[0] = wcfram[FOR_Z];
278
glevl[1] = wcfram[FOR_Z+1];
282
* check for more than one input level
285
{ SCTPUT( err_1lev );
286
glevl[0] = wcfram[FOR_Z];
287
glevl[1] = wcfram[FOR_Z+1];
291
* get the smooting parameter
293
(void) SCKRDI( "INPUTI", 1, 1, &actvals, &ismoot, &unit, &knul);
298
(void) SCKRDR( "INPUTR", 3, 1, &actvals, &greynes, &unit, &knul);
299
if ( greynes < 0.0 || greynes > 1.0 ) greynes = 1.0;
304
(void) SCKGETC( "INPUTC", 41, 80, &actvals, input );
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;
314
* setup graphic device according to MIDAS settings
316
PCOPEN( " ", " ", access, &plmode );
319
* determine number of pixels and number of chunks
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 );
328
* allocate virtual memory and scratch space
330
size = nrpix[0] * nrpix[1];
331
p_img = (float *) osmmget( size * sizeof( float ));
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 );
339
{ if ( ii > 0 ) image[3] += nrpix[1] - 1.0;
340
image[2] = MYMIN( last_row, image[3] + nrpix[1] - 1 );
343
* get size of chunk in w.c.
345
BOXPTW( image+2, npix[1], start[1], step[1], area+2 );
347
* extract chunck from original frame
349
GETDAT( imf, MAXSIZ, npix, image, ismoot, p_img );
353
PLGRA( p_img, image, area, step, glevl, nlevl, options, greynes );
355
* updating for the next loop
357
nrpix[1] = MYMIN( last_row - ii * nrpix[1], nrpix[1] );
358
size = nrpix[0] * nrpix[1];
360
(void) SCFCLO( imf );
363
* draw the axes and the label
365
if ( plmode >= 0 && access == 0 )
366
{ if ( strlen( cunit ) > (size_t) 32 )
367
{ (void) strcat( label[1], cunit+32 );
370
if ( strlen( cunit ) > (size_t) 16 ) (void) strcat( label[0], cunit+16 );
372
for ( ii = 0; ii < PLDIM2; ii++ )
373
{ (void) strcat( label[ii], ")" );
377
* plot axes and labels
379
PCFRAM( wcfram, wcfram+FOR_Y, label[0], label[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] );
387
else if ( plmode == 2 )
388
PLGRAI( plmode, name, ident, nlevl, glevl, options );
391
* close plot file and terminate graphic operations