1
/*===========================================================================
2
Copyright (C) 1995-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 Massachusetss 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
===========================================================================*/
29
* HEADER : aglstat.c - Vers 3.6.001 - Aug 1993 - L. Fini, OAA
30
* - Vers 3.6.000 - Nov 1991 - L. Fini, OAA
40
/* Status modification routines */
54
/*****************************************************************************/
55
/* aspect (Internal AGL use) */
57
/* Set a specified aspect ratio */
59
/* Aspect ratio control is performed by redefining the clipping area so that */
60
/* the new clipping area is contained in the previous one and its aspect */
61
/* ratio is the same as the ratio between Y and X axis of the user window */
63
/* The original aspect ratio can be restored by the function: */
66
/* affects global variables xclow,xclup,yclow,yclup */
67
/* To recompute transform. parameters "setgsta" must be called */
69
static void aspect(ratio)
70
double ratio; /* required aspect ratio */
71
/* 1.0e-4 < ratio < 1.0e+4 */
73
double clratio; /* current clipp.area aspect ratio */
74
AGL_status.errstat=AGLNOERR;
76
if((ratio<1.0e-3)||(ratio>1.0e+3)) {
77
AGL_status.errstat=(ASPECTWNG);
83
if(clratio<ratio) { /* left-rigth squeeze */
85
dlta = (1.0-(clratio/ratio))*(XCLUP-XCLOW)*0.5;
88
} else { /* top-bottom squeeze */
90
dlta = (1.0-(ratio/clratio))*(YCLUP-YCLOW)*0.5;
97
/***********************************************************************/
99
/* AGL_sgeom (Internal AGL use) */
101
/* Set automatic aspect ratio control ON or OFF */
103
/* Automatic aspect ratio sets the clipping area aspect ratio equal to */
104
/* the aspect ratio of the currently defined user window */
107
int stat; /* request status (ON or OFF) */
112
AGL_status.errstat=AGLNOERR;
113
if(!DY(window)) return;
115
ratio = fabs((double)(YUSLOW-YUSUP))/
116
fabs((double)(XUSLOW-XUSUP));
118
if(AGL_status.errstat != AGLNOERR) return;
120
} else { /* Set automatic aspect control OFF */
121
XCLOW = XSVLOW; XCLUP = XSVUP;
122
YCLOW = YSVLOW; YCLUP = YSVUP;
132
/*****************************************************************************/
133
/* testlog (AGL internal use) */
135
/* tests log transformation validity */
137
static int testlog(code) /* Returns TRUE/FALSE */
138
int code; /* Axis selection (X_AXIS/Y_AXIS) */
142
return( (XUSUP>0.0) && (XUSLOW>0) );
144
return( (YUSUP>0.0) && (YUSLOW>0) );
155
/*****************************************************************************/
156
/* AGL_vflsh (AGL internal use) */
158
/* Forces output of current device buffer */
164
if(AGL_status.vwpoint==NULL)
165
AGL_status.errstat=(NOVWPERR);
167
CHANNEL = DY(curchan);
168
SENDFUNCT(AGLDVCOM); /* Empty viewport buffer */
169
AGL_status.errstat=ERRCODE;
175
/*****************************************************************************/
176
/* execmd (AGL internal use) */
178
/* Executes a device specific command (O.S. command) */
180
static void execmd(cmd)
181
char *cmd; /* Command string to execute */
183
extern void AG_DMSG();
185
AGL_status.errstat=AGLNOERR;
187
if ( *cmd=='\0') return;
189
AG_DMSG("Exec:",cmd);
192
AGL_status.errstat = DEVCMDWNG;
200
/*****************************************************************************/
201
/* AGL_dstop (AGL internal use) */
203
/* Closes operations on the given device */
206
int slot; /* Device slot */
209
extern void AG_DMSG();
212
CHANNEL=GRCHAN(slot);
214
AG_DMSG("Close:",DEVNAM(slot));
217
termf = *(DRVADDR(slot)+5);
219
ACTREQST(slot)=0; /* clear device request counter */
221
if(IBUFFR(0)) { /* If IBUFR(0) returns TRUE, then the */
222
if(FILNAM(slot) != '\0') { /* file was not actually written and */
223
/* it should be deleted */
224
AG_DMSG("Empty file removed:",FILNAM(slot));
225
REMOVE(FILNAM(slot));
228
execmd ( DEVCOMMND(slot) ); /* execute device command */
230
AGL_status.errstat = MAX(AGL_status.errstat,ERRCODE);
236
/*****************************************************************************/
237
/* AGL_fvwp (Internal AGL Use) */
239
/* Deallocates space for viewport structure (also clear viewport pointers) */
241
void AGL_fvwp(vwpid) /* Returns error code */
244
if(AGL_status.vwpts[vwpid] != NULL) {
245
free((char *)AGL_status.vwpts[vwpid]);
246
AGL_status.vwpts[vwpid] = NULL;
248
AGL_status.vwpoint = NULL;
249
AGL_status.curvwp=VWPEMPTY;
257
/***********************************************************************/
258
/* AGL_sstat (internal AGL use) */
260
/* This routine is called in order to recompute transformation parame- */
261
/* ters and to set the graphic status in the following cases: */
263
/* - when defining the viewport */
264
/* - when defining the clipping area, */
265
/* - when changing the aspect ratio */
266
/* - when defining the user window, */
267
/* - when switching between normalized and user mode, */
268
/* - when switching between log and linear transf. */
270
/* Recomputed paremeters are held in the global variables: */
271
/* aglfcx, aglfcy, aglofx, aglofy */
275
/* Let (xi,yi) and (xo,yo) be the input and output coordinates to be */
276
/* transformed, then: */
278
/* xo = XCLOW + (xi-xbot)*(XCLUP-XCLOW)/(xtop-xbot) */
279
/* yo = YCLOW + (yi-ybot)*(YCLUP-YCLOW)/(ytop-ybot) */
281
/* where input and output rectangules are defined as follows: */
283
/* Input ----transf.-----> Output */
284
/* ytop --+---------+-- YCLUP ----+---------+-- */
286
/* | (xi,yi) | | (xo,yo) | */
287
/* ybot --+---------+-- YCLOW ----+---------+-- */
288
/* xbot xtop XCLOW XCLUP */
290
/* In order to increase efficiency, the above relationships can be */
291
/* rewritten as follows: */
293
/* xo = aglfcx * xi + aglofx */
294
/* yo = aglfcy * yi + aglofy */
298
/* aglfcx = (XCLUP-XCLOW)/(xtop-xbot) */
299
/* aglofx = XCLOW - aglfcx * xbot */
300
/* aglfcy = (YCLUP-YCLOW)/(ytop-ybot) */
301
/* aglofy = YCLOW - aglfcy * ybot */
303
/* Values chosen for (xbot,xtop,ybot,ytop) depend on the transforma- */
304
/* tion in effect: either user window bounds or their logarithms may */
310
double xbot,xtop,ybot,ytop;
312
if(DY(modeflag)!=NORMAL) {
315
if ( DY(flogx) && testlog(X_AXIS) ) {
316
xtop = log((double)XUSUP); xbot = log((double)XUSLOW);
317
AGL_status.xlogon = TRUE;
319
xtop = XUSUP; xbot = XUSLOW;
320
AGL_status.xlogon = FALSE;
323
if( DY(flogy) && testlog(Y_AXIS) ) {
324
ytop = log((double)YUSUP); ybot = log((double)YUSLOW);
325
AGL_status.ylogon = TRUE;
327
ytop = YUSUP; ybot = YUSLOW;
328
AGL_status.ylogon = FALSE;
331
if(DY(modeflag)==SPECIAL) {
332
if(DY(UsrTransf) == NULL) {
333
AGL_status.errstat=MODEERR;
335
AGL_status.UTransf=FALSE;
337
(*DY(UsrInit))(); /* Init. user transformation */
338
AGL_status.UTransf=TRUE;
341
AGL_status.UTransf=FALSE;
343
/* Compute transformation params */
347
AGL_status.aglfcx = (XCLUP-XCLOW-0.0002)/denom;
348
AGL_status.aglofx = XCLOW - AGL_status.aglfcx * xbot + 0.0001;
352
AGL_status.aglfcy = (YCLUP-YCLOW-0.0002)/denom;
353
AGL_status.aglofy = YCLOW - AGL_status.aglfcy * ybot + 0.0001;
361
/************************************************************************/
362
/* AGL_swdt (internal AGL use) */
364
/* This routine commands the current driver to set the current line */
368
int width; /* width to set. It is assumed that the */
369
/* value is correct for the device */
372
if(AGL_status.vwpoint==NULL) {
373
AGL_status.errstat=(NOVWPERR);
376
IBUFFR(0)=4; IBUFFR(1)=width; CHANNEL=DY(curchan);
378
AGL_status.errstat=(ERRCODE);
381
/************************************************************************/
382
/* AGL_sclr (internal AGL use) */
384
/* This routine commands the current driver to set the current color */
390
if(AGL_status.vwpoint==NULL) {
391
AGL_status.errstat=NOVWPERR;
399
AGL_status.errstat=ERRCODE;
403
/**************************************************************************/
404
/* AGL_sgbl (internal AGL use) */
406
/* Sets the global status according various status flags (called by CDEF) */
412
AGL_status.errstat=AGLNOERR;
415
if(DY(autoasp)==ON) { /* Set automatic aspect ratio */
417
if(AGL_status.errstat != AGLNOERR) {
419
maxerr=AGL_status.errstat;
424
if( !testlog(X_AXIS)) {
426
maxerr = MAX(maxerr,NOLOGERR);
431
if( !testlog(Y_AXIS)) {
433
maxerr = MAX(maxerr,NOLOGERR);
437
AGL_sstat(); /* Set graphic status params */
439
AGL_status.errstat=maxerr;