1
/*===========================================================================
2
Copyright (C) 1993-2009 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
33
.PURPOSE Plots vectors (polarisation map) from 2 two-dimensional FRAME
34
in/output: IN_A/C/1/60 = input frame with intensisty information
35
IN_B/C/1/60 = input frame with position angle information
36
INPUTC/C/1/72 = coord_string (default: whole frame)
37
INPUTR/R/1/3 = scale of vector [units/mm]
38
position angle range (default: 0,360)
39
INPUTI/I/1/2 = smooting parameter (default: 1)
40
head (default: 1, the vector get an arrow)
44
#include <midas_def.h> Prototypes for MIDAS interfaces
45
#include <plot_def.h> General symbols for Plot routines
47
.VERSION 1.1 25-Nov-1993 Removed restrictions on frame size, RvH
48
1.0 10-Sep-1993 FORTRAN --> C RvH
51
------------------------------------------------------------*/
53
* Define _POSIX_SOURCE to indicate
54
* that this is a POSIX program
56
#define _POSIX_SOURCE 1
59
* definition of the used functions
67
* define some macros and constants
69
#include <midas_def.h>
73
#define MAXPIX 512 /* max frame dimension (X,Y) accessed at once */
74
#define MAXSIZ (MAXPIX * MAXPIX)
77
* here starts the code of the function
82
int actvals, chunks, head, imfA, imfB, knul, last_row, naxis,
83
size, stat, unit, ndum[PLDIM2], npixA[PLDIM2], npixB[PLDIM2],
84
sublo[PLDIM2], subhi[PLDIM2];
86
float amin, amax, *p_imgA, *p_imgB, scar, nrpix[2], ranp[4], area[4],
89
double startA[PLDIM2], stepA[PLDIM2], startB[PLDIM2], stepB[PLDIM2];
91
char cmnd[21], nameA[61], nameB[61], cunitA[49], identA[33], identB[33],
94
* initialised variables
96
char *err_start = "*** FATAL: START descriptor of the frames differ",
97
*err_step = "*** FATAL: STEP descriptor of the frames differ",
98
*err_npix = "*** FATAL: NPIX descriptor of the frames differ",
99
*err_1dim = "*** FATAL: the frames have only one dimension",
100
*err_coord = "*** FATAL: invalid coordinate input ...",
101
*err_xcuts = "*** FATAL: range in x has no overlap with current graph abscissa - NO PLOT",
102
*err_ycuts = "*** FATAL: range in y has no overlap with current graph abscissa - NO PLOT";
104
static char *axis[PLDIM2] = { "MANU", "MANU" };
106
int access = 0, /* parameter for PCOPEN: plot mode */
107
plmode = -1, /* plot mode taken from keyword PMODE */
108
ismoot = 1; /* Default no smooting of the data */
110
* allocate memory for different character pointers and initialise a few
112
for ( ii = 0; ii < 4; ii++ ) label[ii] = osmmget(81);
114
(void) strcpy( label[0], "Position (" );
115
(void) strcpy( label[1], "Position (" );
118
* start of executable code
120
(void) SCSPRO( "PLTVEC" ); /*contact with the MIDAS monitor*/
121
(void) SCKGETC( "MID$CMND", 1, 20, &actvals, cmnd );
122
if ( *cmnd == 'O' ) access = 1;
125
* find file name and size information of first frame
127
(void) SCKGETC( "IN_A", 1, 60, &actvals, nameA );
128
(void) SCFOPN( nameA, D_R4_FORMAT, 0, F_IMA_TYPE, &imfA );
129
(void) SCDRDI( imfA, "NAXIS", 1, 1, &actvals, &naxis, &unit, &knul );
130
(void) SCDRDI( imfA, "NPIX" , 1, PLDIM2, &actvals, npixA , &unit, &knul );
131
if ( naxis < 2 || (npixA[0] == 1 || npixA[1] == 1) ) SCETER( 1, err_1dim );
134
* find file name and size information of second frame
136
(void) SCKGETC( "IN_B", 1, 60, &actvals, nameB );
137
(void) SCFOPN( nameB, D_R4_FORMAT, 0, F_IMA_TYPE, &imfB );
138
(void) SCDRDI( imfB, "NPIX" , 1, PLDIM2, &actvals, npixB , &unit, &knul );
139
if ( npixA[0] != npixB[0] || npixA[1] != npixB[1] ) SCETER( 2, err_npix );
142
* read descriptor of first frame
144
(void) SCDRDD( imfA, "START", 1, PLDIM2, &actvals, startA, &unit, &knul );
145
(void) SCDRDD( imfA, "STEP" , 1, PLDIM2, &actvals, stepA , &unit, &knul );
146
(void) SCDGETC( imfA, "IDENT", 1, 32, &actvals, identA );
147
(void) SCDGETC( imfA, "CUNIT", 1, 48, &actvals, cunitA );
150
* read descriptor of second frame
152
(void) SCDRDD( imfB, "START", 1, PLDIM2, &actvals, startB, &unit, &knul );
153
(void) SCDRDD( imfB, "STEP" , 1, PLDIM2, &actvals, stepB , &unit, &knul );
154
(void) SCDGETC( imfB, "IDENT", 1, 32, &actvals, identB );
157
* do both frames overlap?
159
if ( startA[0] != startB[0] || startA[1] != startB[1] ) SCETER( 3, err_start );
160
if ( stepA[0] != stepB[0] || stepA[1] != stepB[1] ) SCETER( 4, err_step );
163
* Get the manual setting for the axes
165
PCKRDR( "XAXIS", 4, &actvals, wcfram );
166
PCKRDR( "YAXIS", 4, &actvals, wcfram+FOR_Y );
169
* read window coordinates and take action
171
(void) SCKGETC( "INPUTC", 1, 60, &actvals, input );
173
if ( *input == 'm' || *input == 'M' ) /* manual scaling */
174
{ BOXWTP( wcfram, npixA[0], startA[0], stepA[0], image );
175
BOXWTP( wcfram+FOR_Y, npixA[1], startA[1], stepA[1], image+2 );
178
{ if ( *input == 'c' || *input == 'C' ) /* display input */
179
{ (void) SCKRDR( "OUTPUTR", 10, 1, &actvals, image, &unit, &knul);
180
(void) SCKRDR( "OUTPUTR", 11, 1, &actvals, image+2, &unit, &knul);
181
(void) SCKRDR( "OUTPUTR", 15, 1, &actvals, image+1, &unit, &knul);
182
(void) SCKRDR( "OUTPUTR", 16, 1, &actvals, image+3, &unit, &knul);
184
else /* automatic scaling */
185
{ stat = Convcoo(1,imfA,input,PLDIM2,ndum,sublo,subhi);
186
if ( stat != ERR_NORMAL ) SCETER( 5, err_coord );
187
image[0] = sublo[0] + 1;
188
image[1] = subhi[0] + 1;
189
image[2] = sublo[1] + 1;
190
image[3] = subhi[1] + 1;
193
BOXPTW( image, npixA[0], startA[0], stepA[0], area );
194
BOXPTW( image+2, npixA[1], startA[1], stepA[1], area+2 );
196
PCKWRR( "PIXEL", 4, image );
201
* get size of frame along X-axis
203
if ( fabs( *wcfram ) < PLT_EPS && fabs( *(wcfram+1) ) < PLT_EPS )
204
{ wcfram[0] = area[2];
206
wcfram[2] = wcfram[3] = 0.0;
209
* get size of frame along Y-axis
211
if ( fabs( *(wcfram+FOR_Y) ) < PLT_EPS
212
&& fabs( *(wcfram+FOR_Y+1) ) < PLT_EPS )
214
wcfram[FOR_Y] = area[2];
215
wcfram[FOR_Y+1] = area[3];
216
wcfram[FOR_Y+2] = wcfram[FOR_Y+3] = 0.0;
218
GETFRM( axis[0], wcfram );
219
GETFRM( axis[1], wcfram + FOR_Y );
220
PCKWRR( "XWNDL", 4, wcfram );
221
PCKWRR( "YWNDL", 4, wcfram+FOR_Y );
223
else /* overplot mode*/
224
{ PCKRDR( "XWNDL", 4, &actvals, wcfram );
225
PCKRDR( "YWNDL", 4, &actvals, wcfram+FOR_Y );
227
* does overplot data fall within plotted frame?
229
amin = MYMIN( *wcfram, *(wcfram + 1) );
230
amax = MYMAX( *wcfram, *(wcfram + 1) );
231
if ( ( MYMAX( area[0], area[1] ) < amin ) ||
232
( MYMIN( area[0], area[1] ) > amax ) )
233
SCETER( 6, err_xcuts );
235
amin = MYMIN( *(wcfram + FOR_Y), *(wcfram + FOR_Y + 1) );
236
amax = MYMAX( *(wcfram + FOR_Y), *(wcfram + FOR_Y + 1) );
237
if ( ( MYMAX( area[2], area[3] ) < amin ) ||
238
( MYMIN( area[2], area[3] ) > amax ) )
239
SCETER( 7, err_ycuts );
244
(void) SCDRDR( imfA, "LHCUTS", 1, 4, &actvals, wcfram+FOR_Z, &unit, &knul);
245
(void) SCKRDR( "INPUTR", 2, 4, &actvals, ranp, &unit, &knul);
246
if ( fabs(ranp[0]) > PLT_EPS || fabs(ranp[1]) > PLT_EPS )
247
{ wcfram[FOR_Z] = ranp[0];
248
wcfram[FOR_Z+1]= ranp[1];
252
if ( wcfram[FOR_Z] == wcfram[FOR_Z+1] )
253
{ wcfram[FOR_Z] = wcfram[FOR_Z+2];
254
wcfram[FOR_Z+1] = wcfram[FOR_Z+3];
257
ranp[0] = wcfram[FOR_Z];
258
ranp[1] = wcfram[FOR_Z+1];
259
PCKWRR( "ZWNDL", 2, wcfram+FOR_Z);
260
(void) SCKRDR( "INPUTR", 1, 1, &actvals, &scar, &unit, &knul);
262
* the intensity scale
265
{ if ( wcfram[FOR_Z] == wcfram[FOR_Z+1] )
266
scar = wcfram[FOR_Z] / 10.0;
268
scar = ( wcfram[FOR_Z+1] - wcfram[FOR_Z] ) / 10.0;
271
* get the other input parameters
273
(void) SCKRDI( "INPUTI", 1, 1, &actvals, &ismoot, &unit, &knul);
274
(void) SCKRDI( "INPUTI", 2, 1, &actvals, &head, &unit, &knul);
277
* setup graphic device according to MIDAS settings
279
PCOPEN( " ", " ", access, &plmode );
282
* determine number of pixels and number of chunks
284
nrpix[0] = (int) fabs( image[1] - image[0] ) + 1;
285
nrpix[1] = (int) fabs( image[3] - image[2] ) + 1;
286
last_row = MYMAX( image[2], image[3]);
287
chunks = (int) ceil( (double) nrpix[0] * nrpix[1] / MAXSIZ );
288
nrpix[1] = (int) ceil( (double) nrpix[1] / chunks );
291
* allocate virtual memory and scratch space
293
size = nrpix[0] * nrpix[1];
294
p_imgA = (float *) osmmget( size * sizeof( float ));
295
p_imgB = (float *) osmmget( size * sizeof( float ));
297
for ( ii = 0; ii < chunks; ii++ )
298
{ if ( image[3] > image[2] ) /* size of chunk p.c.*/
299
{ if ( ii > 0 ) image[2] += nrpix[1] - 1.0;
300
image[3] = MYMIN( last_row, image[2] + nrpix[1] - 1 );
303
{ if ( ii > 0 ) image[3] += nrpix[1] - 1.0;
304
image[2] = MYMIN( last_row, image[3] + nrpix[1] - 1 );
307
* get size of chunk in w.c.
309
BOXPTW( image+2, npixA[1], startA[1], stepA[1], area+2 );
311
* extract chunck from original frame
313
GETDAT( imfA, MAXSIZ, npixA, image, ismoot, p_imgA );
314
GETDAT( imfB, MAXSIZ, npixB, image, ismoot, p_imgB );
318
PLVEC( p_imgA, p_imgB, image, area, stepA, scar, ranp, head );
320
* updating for the next loop
322
nrpix[1] = MYMIN( last_row - ii * nrpix[1], nrpix[1] );
323
size = nrpix[0] * nrpix[1];
325
(void) SCFCLO( imfA );
326
(void) SCFCLO( imfB );
329
* draw the axes and the label
331
if ( plmode >= 0 && access == 0 )
332
{ if ( strlen( cunitA ) > (size_t) 32 )
333
{ (void) strncat( label[0], cunitA+32, 16 );
336
if ( strlen( cunitA ) > (size_t) 16 )
337
(void) strcat( label[1], cunitA+16 );
339
for ( ii = 0; ii < PLDIM2; ii++ )
340
{ (void) strcat( label[ii], ")" );
344
* plot axes and labels
346
PCFRAM( wcfram, wcfram+FOR_Y, label[0], label[1] );
349
{ (void) sprintf( label[2], "Frames: %s + %s", nameA, nameB );
350
(void) sprintf( label[3], "Ident: %s + %s", identA, identB );
351
PLIDEN( plmode, label[2], label[3] );
353
else if ( plmode == 2 )
354
PLVECI( plmode, nameA, identA, nameB, identB, scar, ranp );
357
* close plot file and terminate graphic operations