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

« back to all changes in this revision

Viewing changes to libsrc/agl/aglstat.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) 1995-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
  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
 * HEADER : aglstat.c      - Vers 3.6.001  - Aug 1993 -  L. Fini, OAA
 
30
 *                         - Vers 3.6.000  - Nov 1991 -  L. Fini, OAA
 
31
 *
 
32
 *
 
33
 * 090416       last modif
 
34
 */
 
35
 
 
36
 
 
37
 
 
38
 
 
39
 
 
40
/*                        Status modification routines                       */
 
41
 
 
42
 
 
43
 
 
44
#include <unistd.h>
 
45
 
 
46
#include <aglenvr.h>
 
47
#include <aglstat.h>
 
48
 
 
49
 
 
50
 
 
51
 
 
52
 
 
53
 
 
54
/*****************************************************************************/
 
55
/*                        aspect (Internal AGL use)                          */
 
56
 
 
57
/* Set a specified aspect ratio                                              */
 
58
 
 
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    */
 
62
 
 
63
/* The original aspect ratio can be restored by the function:                */
 
64
/*          AGL_sgeom(OFF)                                                   */
 
65
 
 
66
/* affects global variables xclow,xclup,yclow,yclup                          */
 
67
/* To recompute transform. parameters "setgsta" must be called               */
 
68
 
 
69
static void aspect(ratio)
 
70
double ratio;                   /* required aspect ratio                     */
 
71
                                /* 1.0e-4 < ratio < 1.0e+4                   */
 
72
{
 
73
double clratio;                         /* current clipp.area aspect ratio   */
 
74
AGL_status.errstat=AGLNOERR;
 
75
 
 
76
if((ratio<1.0e-3)||(ratio>1.0e+3)) { 
 
77
        AGL_status.errstat=(ASPECTWNG); 
 
78
        return; 
 
79
}
 
80
 
 
81
clratio = YXRATIO;
 
82
 
 
83
if(clratio<ratio) {                     /* left-rigth squeeze                */
 
84
        double dlta;
 
85
        dlta = (1.0-(clratio/ratio))*(XCLUP-XCLOW)*0.5;
 
86
        XCLOW += dlta;
 
87
        XCLUP -= dlta;
 
88
} else {                                /* top-bottom squeeze                */
 
89
        double dlta;
 
90
        dlta = (1.0-(ratio/clratio))*(YCLUP-YCLOW)*0.5;
 
91
        YCLOW += dlta;
 
92
        YCLUP -= dlta;
 
93
}
 
94
}
 
95
 
 
96
 
 
97
/***********************************************************************/
 
98
/*                                                                     */
 
99
/*                    AGL_sgeom (Internal AGL use)                     */
 
100
 
 
101
/* Set automatic aspect ratio control ON or OFF                        */
 
102
 
 
103
/* Automatic aspect ratio sets the clipping area aspect ratio equal to */
 
104
/* the aspect ratio of the currently defined user window               */
 
105
 
 
106
void AGL_sgeom(stat)
 
107
int stat;                             /* request status (ON or OFF)   */
 
108
{
 
109
if(stat == ON) {
 
110
        double ratio;
 
111
 
 
112
        AGL_status.errstat=AGLNOERR;
 
113
        if(!DY(window)) return;
 
114
 
 
115
        ratio = fabs((double)(YUSLOW-YUSUP))/
 
116
                fabs((double)(XUSLOW-XUSUP));
 
117
        aspect(ratio);
 
118
        if(AGL_status.errstat != AGLNOERR) return;
 
119
        DY(autoasp) = ON;
 
120
} else {                                /* Set automatic aspect control OFF  */
 
121
        XCLOW = XSVLOW; XCLUP = XSVUP;
 
122
        YCLOW = YSVLOW; YCLUP = YSVUP;
 
123
        DY(autoasp) = OFF;
 
124
}
 
125
}
 
126
 
 
127
 
 
128
 
 
129
 
 
130
 
 
131
 
 
132
/*****************************************************************************/
 
133
/*                              testlog (AGL internal use)                   */
 
134
 
 
135
/* tests log transformation validity                                         */
 
136
 
 
137
static int testlog(code)        /* Returns TRUE/FALSE                        */
 
138
int code;                       /* Axis selection (X_AXIS/Y_AXIS)            */
 
139
{
 
140
switch(code) {
 
141
        case X_AXIS: 
 
142
                return( (XUSUP>0.0) && (XUSLOW>0) );
 
143
        case Y_AXIS: 
 
144
                return( (YUSUP>0.0) && (YUSLOW>0) );
 
145
}
 
146
return FALSE;
 
147
}
 
148
 
 
149
 
 
150
 
 
151
 
 
152
 
 
153
 
 
154
 
 
155
/*****************************************************************************/
 
156
/*                              AGL_vflsh (AGL internal use)                  */
 
157
 
 
158
/* Forces output of current device buffer                                    */
 
159
 
 
160
void AGL_vflsh()
 
161
{
 
162
DEFINE_AGLDVCOM;
 
163
 
 
164
if(AGL_status.vwpoint==NULL) 
 
165
        AGL_status.errstat=(NOVWPERR);
 
166
else {
 
167
        CHANNEL = DY(curchan);
 
168
        SENDFUNCT(AGLDVCOM);            /* Empty viewport buffer             */
 
169
        AGL_status.errstat=ERRCODE;
 
170
}
 
171
}
 
172
 
 
173
 
 
174
 
 
175
/*****************************************************************************/
 
176
/*                              execmd (AGL internal use)                    */
 
177
 
 
178
/* Executes a device specific command (O.S. command)                         */
 
179
 
 
180
static void execmd(cmd)
 
181
char *cmd;                    /* Command string to execute                  */
 
182
{
 
183
extern void AG_DMSG();
 
184
 
 
185
AGL_status.errstat=AGLNOERR;
 
186
 
 
187
if ( *cmd=='\0') return;
 
188
 
 
189
AG_DMSG("Exec:",cmd);
 
190
 
 
191
if(SYSTEM(cmd)<0) 
 
192
        AGL_status.errstat = DEVCMDWNG;
 
193
}
 
194
 
 
195
 
 
196
 
 
197
 
 
198
 
 
199
 
 
200
/*****************************************************************************/
 
201
/*                              AGL_dstop (AGL internal use)                   */
 
202
 
 
203
/* Closes operations on the given device                                     */
 
204
 
 
205
void AGL_dstop(slot)
 
206
int slot;                          /* Device slot                           */
 
207
{
 
208
DEFINE_AGLDVCOM;
 
209
extern void AG_DMSG();
 
210
int (*termf)();
 
211
 
 
212
CHANNEL=GRCHAN(slot);
 
213
 
 
214
AG_DMSG("Close:",DEVNAM(slot));
 
215
 
 
216
IBUFFR(0)=FALSE;
 
217
termf = *(DRVADDR(slot)+5);
 
218
termf(AGLDVCOM);
 
219
ACTREQST(slot)=0;               /* clear device request counter          */
 
220
 
 
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));
 
226
        }
 
227
} else
 
228
        execmd ( DEVCOMMND(slot) );     /* execute device command            */
 
229
 
 
230
AGL_status.errstat = MAX(AGL_status.errstat,ERRCODE);
 
231
}
 
232
 
 
233
 
 
234
 
 
235
 
 
236
/*****************************************************************************/
 
237
/*                          AGL_fvwp (Internal AGL Use)                      */
 
238
 
 
239
/* Deallocates space for viewport structure (also clear viewport pointers)   */
 
240
 
 
241
void AGL_fvwp(vwpid)                    /* Returns error code                */
 
242
int vwpid;
 
243
{
 
244
if(AGL_status.vwpts[vwpid] != NULL) {
 
245
        free((char *)AGL_status.vwpts[vwpid]);
 
246
        AGL_status.vwpts[vwpid] = NULL;
 
247
}
 
248
AGL_status.vwpoint = NULL;
 
249
AGL_status.curvwp=VWPEMPTY;
 
250
}
 
251
 
 
252
 
 
253
 
 
254
 
 
255
 
 
256
 
 
257
/***********************************************************************/
 
258
/*                    AGL_sstat (internal AGL use)                     */
 
259
 
 
260
/* This routine is called in order to recompute transformation parame- */
 
261
/* ters and to set the graphic status in the following cases:          */
 
262
 
 
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.                  */
 
269
 
 
270
/* Recomputed paremeters are held in the global variables:             */
 
271
/*    aglfcx, aglfcy, aglofx, aglofy                                   */
 
272
 
 
273
/* Method:                                                             */
 
274
 
 
275
/*   Let (xi,yi) and (xo,yo) be the input and output coordinates to be */
 
276
/*   transformed, then:                                                */
 
277
 
 
278
/*     xo = XCLOW + (xi-xbot)*(XCLUP-XCLOW)/(xtop-xbot)                */
 
279
/*     yo = YCLOW + (yi-ybot)*(YCLUP-YCLOW)/(ytop-ybot)                */
 
280
 
 
281
/*     where input and output rectangules are defined as follows:      */
 
282
 
 
283
/*                Input     ----transf.----->     Output               */
 
284
/*      ytop --+---------+--         YCLUP ----+---------+--           */
 
285
/*             |         |                     |         |             */
 
286
/*             | (xi,yi) |                     | (xo,yo) |             */
 
287
/*      ybot --+---------+--         YCLOW ----+---------+--           */
 
288
/*            xbot      xtop                 XCLOW     XCLUP           */
 
289
 
 
290
/*     In order to increase efficiency, the above relationships can be */
 
291
/*     rewritten as follows:                                           */
 
292
 
 
293
/*         xo = aglfcx * xi + aglofx                                   */
 
294
/*         yo = aglfcy * yi + aglofy                                   */
 
295
 
 
296
/*     where:                                                          */
 
297
 
 
298
/*         aglfcx = (XCLUP-XCLOW)/(xtop-xbot)                          */
 
299
/*         aglofx = XCLOW  - aglfcx * xbot                             */
 
300
/*         aglfcy = (YCLUP-YCLOW)/(ytop-ybot)                          */
 
301
/*         aglofy = YCLOW -  aglfcy * ybot                             */
 
302
 
 
303
/*  Values chosen for (xbot,xtop,ybot,ytop) depend on the transforma-  */
 
304
/*  tion in effect: either user window bounds or their logarithms may  */
 
305
/*  be used.                                                           */
 
306
 
 
307
 
 
308
void AGL_sstat()
 
309
{
 
310
double xbot,xtop,ybot,ytop;
 
311
 
 
312
if(DY(modeflag)!=NORMAL) {
 
313
        double denom;
 
314
 
 
315
        if ( DY(flogx) && testlog(X_AXIS) ) {
 
316
                xtop = log((double)XUSUP); xbot = log((double)XUSLOW);
 
317
                AGL_status.xlogon = TRUE;
 
318
        } else {
 
319
                xtop = XUSUP; xbot = XUSLOW;
 
320
                AGL_status.xlogon = FALSE;
 
321
        }
 
322
 
 
323
        if( DY(flogy) && testlog(Y_AXIS) ) {
 
324
                ytop = log((double)YUSUP); ybot = log((double)YUSLOW);
 
325
                AGL_status.ylogon = TRUE;
 
326
        } else {
 
327
                ytop = YUSUP; ybot = YUSLOW;
 
328
                AGL_status.ylogon = FALSE;
 
329
        }
 
330
 
 
331
        if(DY(modeflag)==SPECIAL) {
 
332
                if(DY(UsrTransf) == NULL) {
 
333
                        AGL_status.errstat=MODEERR;
 
334
                        DY(modeflag)=USER;
 
335
                        AGL_status.UTransf=FALSE;
 
336
                } else {
 
337
                        (*DY(UsrInit))();       /* Init. user transformation */
 
338
                        AGL_status.UTransf=TRUE;
 
339
                }
 
340
        } else
 
341
                AGL_status.UTransf=FALSE;
 
342
                
 
343
                                    /* Compute transformation params    */
 
344
        
 
345
        denom=xtop-xbot;
 
346
        if(denom!=0) {
 
347
                AGL_status.aglfcx = (XCLUP-XCLOW-0.0002)/denom;
 
348
                AGL_status.aglofx = XCLOW  - AGL_status.aglfcx * xbot + 0.0001;
 
349
        }
 
350
        denom=ytop-ybot;
 
351
        if(denom!=0) {
 
352
                AGL_status.aglfcy = (YCLUP-YCLOW-0.0002)/denom;
 
353
                AGL_status.aglofy = YCLOW -  AGL_status.aglfcy * ybot + 0.0001;
 
354
        }
 
355
}
 
356
}
 
357
 
 
358
 
 
359
 
 
360
 
 
361
/************************************************************************/
 
362
/*                      AGL_swdt (internal AGL use)                     */
 
363
 
 
364
/* This routine commands the current driver to set the current line     */
 
365
/* width                                                                */
 
366
 
 
367
void AGL_swdt(width)
 
368
int width;                      /* width to set. It is assumed that the */
 
369
                                /* value is correct for the device      */
 
370
{
 
371
DEFINE_AGLDVCOM;
 
372
if(AGL_status.vwpoint==NULL) { 
 
373
        AGL_status.errstat=(NOVWPERR); 
 
374
        return; 
 
375
}
 
376
IBUFFR(0)=4; IBUFFR(1)=width; CHANNEL=DY(curchan);
 
377
INITFUNCT(AGLDVCOM);
 
378
AGL_status.errstat=(ERRCODE);
 
379
}
 
380
 
 
381
/************************************************************************/
 
382
/*                      AGL_sclr (internal AGL use)                     */
 
383
 
 
384
/* This routine commands the current driver to set the current color    */
 
385
 
 
386
void AGL_sclr()
 
387
{
 
388
DEFINE_AGLDVCOM;
 
389
 
 
390
if(AGL_status.vwpoint==NULL) { 
 
391
        AGL_status.errstat=NOVWPERR; 
 
392
        return; 
 
393
}
 
394
 
 
395
IBUFFR(0)=2; 
 
396
IBUFFR(1)=DY(color); 
 
397
CHANNEL=DY(curchan);
 
398
INITFUNCT(AGLDVCOM);
 
399
AGL_status.errstat=ERRCODE;
 
400
}
 
401
 
 
402
 
 
403
/**************************************************************************/
 
404
/*                     AGL_sgbl (internal AGL use)                        */
 
405
 
 
406
/* Sets the global status according various status flags (called by CDEF) */
 
407
/* and WDEF                                                               */
 
408
 
 
409
void AGL_sgbl()
 
410
{
 
411
int maxerr=AGLNOERR;
 
412
AGL_status.errstat=AGLNOERR;
 
413
 
 
414
if(DY(window)) {
 
415
        if(DY(autoasp)==ON) {                   /* Set automatic aspect ratio */
 
416
                AGL_sgeom(ON);
 
417
                if(AGL_status.errstat != AGLNOERR) {
 
418
                        DY(autoasp)=OFF;
 
419
                        maxerr=AGL_status.errstat;
 
420
                }
 
421
        }
 
422
 
 
423
        if(DY(flogx)) {
 
424
                if( !testlog(X_AXIS)) {
 
425
                        DY(flogx)=FALSE;
 
426
                        maxerr = MAX(maxerr,NOLOGERR);
 
427
                }
 
428
        }
 
429
 
 
430
        if(DY(flogy)) {
 
431
                if( !testlog(Y_AXIS)) {
 
432
                        DY(flogy)=FALSE;
 
433
                        maxerr = MAX(maxerr,NOLOGERR);
 
434
                }
 
435
        }
 
436
 
 
437
        AGL_sstat();                    /* Set graphic status params       */
 
438
}
 
439
AGL_status.errstat=maxerr;
 
440
}