1
/*===========================================================================
2
Copyright (C) 1995-2005 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
===========================================================================*/
29
* HEADER : ag_vdef.c - Vers 3.6.002 - Sep 1993 - L. Fini, OAA
30
* - Vers 3.6.001 - Aug 1992 - L. Fini, OAA
50
/****************************************************************************/
51
/* aglparse (Internal AGL use) */
53
/* Analyzes the device identification string and returns device, input */
54
/* metafile and output metafile fields into output strings */
56
static void aglparse(devidn,device,flag,inpfil,outfil)
57
char *devidn; /* string to analyze */
58
char *device; /* device field (length MUST be<=PHNAMLNG) */
59
char *flag; /* don't erase optional flag (single character) */
60
char *inpfil; /* input m.file field (length MUST be<=PHNAMLNG) */
61
char *outfil; /* output m.file field (length MUST be<=PHNAMLNG) */
65
extern char *AG_SCAN();
72
field=AG_SCAN(devidn,':',PHNAMLNG,device); /* get device name */
74
pntr = strrchr(device,slash); /* Search slash and flag (if any) */
76
if(strlen(pntr)==2) { /* Just "/" followed by single 'n' */
77
int chr= *(pntr+1); /* is taken as flag */
79
if((chr=TOLOWER(chr))=='n')
88
field=AG_SCAN(field,'>',PHNAMLNG,inpfil); /* get input m.file name */
93
field=AG_SCAN(field,'\0',PHNAMLNG,outfil); /* get output m.file name */
97
/*****************************************************************************/
98
/* makevwp (Internal AGL Use) */
100
/* Allocate space for viewport structure and clear viewport status */
102
static void makevwp()
106
AGL_status.errstat=AGLNOERR;
108
AGL_status.vwpoint = (struct VWPDYN *)malloc((size_t)(sizeof(struct VWPDYN)));
110
if(AGL_status.vwpoint==NULL) {
111
AGL_status.errstat=MEMORYERR;
115
for(idvw = 0;idvw<MAXVWPTS;idvw++) /* Search a free slot */
116
if(AGL_status.vwpts[idvw] == NULL)
120
AGL_status.errstat=VWPOVFSEV;
124
AGL_status.curvwp=idvw;
125
AGL_status.vwpts[idvw] = AGL_status.vwpoint;
137
DY(flogx)=FALSE; DY(flogy)=FALSE;
139
DY(angfct)=0.017453293;
144
DY(filact)=NOMETAFILE;
145
DY(metamode)=SOFTMETAFILE;
154
/*****************************************************************************/
155
/*++ AG_VDEF (C callable) */
157
/* AG_VDEF Define viewport */
160
/* Define and activate a new viewport. If a viewport is currently active it */
161
/* is saved prior of activating the new one. After definition the graphic */
162
/* mode is NORMALIZED. */
164
/* The first time a viewport is activated on a given device, the device is */
165
/* allocated and initialized. Subsequent activation of viewports referencing */
166
/* the same device will not reinitialize it. The device is released when the */
167
/* last viewport referencing it is killed. */
169
int AG_VDEF (device,xa,xb,ya,yb,xlim,ylim)
171
/* Returns integer viewport identifier (or < 0 */
172
/* if an error occurs) */
174
char *device; /* Graphic device identification. It is a */
175
/* string with the following syntax: */
177
/* device[.aux][/n]:[inpmet][>outmet[/a]] */
181
/* device - Device name See below for naming */
184
/* aux - Auxiliary user information. This */
185
/* string is passed as such to the */
186
/* device driver to select special */
187
/* device dependent features. E.g.: */
188
/* it may be used by some drivers to */
189
/* select either portrait or land- */
190
/* scape orientation, and the like. */
191
/* Specifications for auxiliary info */
192
/* are given in the device specific */
195
/* /n - optional "no erase on init" flag. */
196
/* : - required separator. */
197
/* inpmet - optional input metafile name. If */
198
/* specified the named metafile is */
199
/* executed just after viewport acti- */
201
/* > Output metafile designator (requi- */
202
/* red if output metafile name is */
204
/* outmet - Optional output metafile name. If */
205
/* specified the named metafile is */
206
/* opened for output just after view- */
207
/* port activation and prior of input */
208
/* metafile execution. */
209
/* /a - Optional request for append mode */
210
/* opening of output metafile. */
212
double xa,xb,ya,yb; /* Viewport bounds (Normalized: 0.0-1.0). */
213
/* xa<xb, ya<yb. (xb-xa)>0.001, (yb-ya)>0.001 */
215
double xlim,ylim; /* Viewport dims (in cm). If 0.0 the device */
216
/* default values are assigned. The request */
217
/* will be accepted only at device initiali- */
218
/* zation (i.e. the first time a viewport is */
219
/* opened onto the device). Some devices may */
220
/* ignore the request (it is an optional driver*/
223
/* DEVICE NAME SPECIFICATION */
225
/* Device names may be either the special name tt: or a logical or physical */
226
/* name. Device name translation is performed according to the following */
229
/* 1. If the name is "tt:", no further translation is performed and it is */
230
/* assumed that the output must be sent to the current interactive ter- */
231
/* minal. A definition for the type of terminal must be found within the */
232
/* user defined file agldevs.dat, or in the system wide file agldevs.dat */
233
/* It may be specified either by an entry into the file agldevs.dat such */
235
/* tt:<devtype> (eg: tt:tkg.t4010, tt:vt125, etc.) */
237
/* If the entry is not found the environment variable (logical name) */
238
/* AGL3DEV is translated to get the device type (eg: tkg.t4010, vt125, */
239
/* etc.). If neither the entry is found into agldevs.dat nor the AGL3DEV */
240
/* variable is defined a severe error condition is raised. */
242
/* 2. Any other string is considered to be an environment variable (or logi-*/
243
/* cal name) and translated. */
245
/* 3. When no further translation is possible the resulting string (the */
246
/* original string, if it was a physical name) is used as device name. */
248
/* 4. An entry for the given device name must be found either in the user */
249
/* specific agldevs.dat file or in the sistem wide file with the same */
250
/* name, with specification of the type of device. If the entry is not */
251
/* found the device name is used as physical device for output and the */
252
/* environment variable (logical name) AGL3DEV is translated to get the */
253
/* device type. If neither the entry is found into agldevs.dat nor the */
254
/* AGL3DEV variable is defined a severe error condition is raised. */
256
/* By default the device is erased when the 1st viewport is opened onto */
257
/* unless disabled with "/n". */
259
/* The following examples shows various device specifications: */
261
/* tt: Send output to current interactive device, find */
262
/* device type into file agldevs.dat or into the */
263
/* environment variable AGL3DEV. */
264
/* tt/n: As above. Do not erase on opening. */
266
/* ps0.R90:>meta.tmp Translate environment variable (logical) ps0, use */
267
/* the resulting string (or "ps0" if no translation */
268
/* exists) as device name. Search for device type */
269
/* first into agldev.dat on the current directory */
270
/* then in the same file on the AGL standard direc- */
271
/* tory; if not found try to translate the environ- */
272
/* ment variable (logical) AGL3DEV. If successful */
273
/* open the device also sending to it the device */
274
/* specific string R90. */
275
/* Then open the output metafile meta.tmp for graphic*/
276
/* operations recording. */
279
static char *modnam = "VDEF";
280
double xal,yal,xbl,ybl;
281
char intdev[PHNAMLNG],inpfil[PHNAMLNG],outfil[PHNAMLNG];
286
AG_DMSG(modnam,(char *)0);
289
if ( AGL_status.errstat != AGLNOERR )
292
if(AGL_status.curvwp!=VWPEMPTY)
293
AGL_vflsh(); /* Empty current viewport buffer */
295
aglparse(device,intdev,&flag,inpfil,outfil); /* Analyze string syntax */
297
if(*intdev == '\0') {
298
AGL_puterr(NODEVICE,modnam);
303
AGL_status.ersonst=FALSE;
305
AGL_status.ersonst=TRUE;
307
xal=xa; xbl=xb; yal=ya; ybl=yb;
308
/* Test viewport bounds */
309
AGL_status.errstat=AGLNOERR;
311
if((xal<0.0)||(xal>1.0)) {
312
AGL_status.errstat = ILLBOUWNG;
315
if((xbl<0.0)||(xbl>1.0)) {
316
AGL_status.errstat = ILLBOUWNG;
319
if((yal<0.0)||(yal>1.0)) {
320
AGL_status.errstat = ILLBOUWNG;
323
if((ybl<0.0)||(ybl>1.0)) {
324
AGL_status.errstat = ILLBOUWNG;
328
if( xbl <= xal+0.001 ) {
329
AGL_status.errstat = ILLBOUWNG;
333
if( ybl <= yal+0.001 ) {
334
AGL_status.errstat = ILLBOUWNG;
339
if(AGL_status.errstat != AGLNOERR)
340
AGL_siger(modnam); /* test error conditions */
342
makevwp(); /* Create viewport structure */
344
if(AGL_status.errstat!=AGLNOERR) {
349
AGL_gdev(intdev,xlim,ylim); /* Init device */
351
if(AGL_status.errstat>=ERRTRSH) { /* Special error test */
352
AGL_fvwp(AGL_status.curvwp); /* Deallocate viewport */
353
AGL_siger(modnam); /* Signal error and return */
357
if(AGL_status.errstat!=AGLNOERR)
360
XVWLOW = xal; XVWUP = xbl; /* set viewport parameters */
361
YVWLOW = yal; YVWUP = ybl;
363
XCLOW = xal; XCLUP = xbl; /* set clipping area parameters */
364
YCLOW = yal; YCLUP = ybl;
366
XSVLOW = xal; XSVUP = xbl; /* set saved clip.area parameters */
367
YSVLOW = yal; YSVUP = ybl;
369
AGL_status.devid = DY(devidx);
371
DY(color) = DEFFOREGR(AGL_status.devid); /* Set default color */
372
DY(lstyle) = 0; /* Set solid line style */
373
AGL_sstyl(DOTLEN(AGL_status.devid));
374
AGL_sclr(); /* Set color on device */
375
AGL_swdt(0); /* Set width on device */
376
if(DY(UsrInit) != NULL)
378
AGL_sstat(); /* Set graphic status */
380
#ifndef NO_METAFILE_SUPPORT
382
if(*inpfil != '\0') {
383
AGL_push(modnam); /* Push routine name into stack */
384
AGL_mfex(inpfil); /* Execute the metafile */
385
AGL_pop(); /* Pop routine name from stack */
388
if(*outfil != '\0') { /* Open output metafile */
390
if(AGL_status.errstat != AGLNOERR)
395
sprintf(inpfil,"%d",AGL_status.curvwp);
396
AG_DMSG("Viewport id:",inpfil);
398
return(AGL_status.curvwp); /* Return viewport identifier */