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

« back to all changes in this revision

Viewing changes to libsrc/agl/hpgldrv.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
  Corresponding 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 : hpgldrv.c      - Vers 3.6.002  - Jul 1992 -  L. Fini, OAA
 
30
 
 
31
.VERSION
 
32
 
 
33
 090630         last modif
 
34
 */
 
35
 
 
36
/*****************************************************************************/
 
37
 
 
38
/* AGL 3.6 driver for HP-GL plotters                                         */
 
39
 
 
40
/* L.Fini - Oct 1991                                                         */
 
41
 
 
42
/* Note: This driver is based on a VAX/VMS FORTRAN version for AGL 2.xx      */
 
43
/*       contributed by Benacchio and Franceschini (Oss. di Padova)          */
 
44
 
 
45
/* This driver can control the output size and orientation, as directed in   */
 
46
/* the HP-GL manual. The settings are controlled by appending the mode spec  */
 
47
/* to the device identification string in the AG_VDEF call. E.g.: if the     */
 
48
/* device identification name is defined as hpg in your system the following */
 
49
/* selections can be made:                                                   */
 
50
 
 
51
/* AG_VDEF("hpg",...) (def) : use paper size A/A4 orientation Landscape      */
 
52
/* AG_VDEF("hpg.a",...)     : use paper size A/A4 orientation Landscape      */
 
53
/* AG_VDEF("hpg.b",...)     : use paper size A/A4 orientation Portrait       */
 
54
/* AG_VDEF("hpg.c",...)     : use paper size B/A3 orientation Landscape      */
 
55
/* AG_VDEF("hpg.d",...)     : use paper size B/A3 orientation Portrait       */
 
56
 
 
57
/* In the example it is shown how to use device specification to get the     */
 
58
/* allowed paper settings (the plotter must support the given size)          */
 
59
 
 
60
#include <aglsys.h>
 
61
 
 
62
#include <agl.h>
 
63
#include <aglerror.h>
 
64
#include <agldcom.h>
 
65
#include <agldcaps.h>
 
66
 
 
67
 
 
68
/*  The following entry points have been defined:                            */
 
69
 
 
70
/*  Function    Entry point                                                  */
 
71
 
 
72
/*  Initialize  AGLINHPG                                                     */
 
73
/*  Cursor en.  AGLCUHPG                                                     */
 
74
/*  Erase       AGLERHPG                                                     */
 
75
/*  Escape      AGLESHPG                                                     */
 
76
/*  Polyline    AGLPLHPG                                                     */
 
77
/*  Finish      AGLTEHPG                                                     */
 
78
/*  Flush buff. AGLSEHPG                                                     */
 
79
 
 
80
 
 
81
 
 
82
#define VERSCODE 36                     /* Declare driver as version 3.6     */
 
83
 
 
84
#define HPFLAGS  SEPALPHA | EXECOMMND
 
85
#define HPPLANES        6               /*  Set to number of pens           */
 
86
#define HPMAXLSTYL      6
 
87
#define HPMAXLWIDTH     1
 
88
 
 
89
                                /* No one can ensure color correspondance   */
 
90
                                /* Unless pens are installed on the plot in */
 
91
                                /* the following order:                     */
 
92
#define HPGBLACK        0
 
93
#define HPGRED          1
 
94
#define HPGGREEN        2
 
95
#define HPGBLUE         3
 
96
#define HPGYELLOW       4
 
97
#define HPGMAGENTA      5
 
98
 
 
99
                                /* Support is provided for 6 per plotters  */
 
100
                                /* CYAN is set equal to blue, white is a   */
 
101
                                /* "draw nothing" color                    */
 
102
#define HPGCYAN         3
 
103
#define HPGWHITE        (-1)
 
104
 
 
105
#define CHARMULT   16
 
106
 
 
107
#define TRUE  1
 
108
#define FALSE 0
 
109
 
 
110
/*                      A4L.   A4P.   A3L.   A3P.                             */
 
111
 
 
112
static int xpix[4]   = {10800, 7600,  15200, 10800 };
 
113
static int ypix[4]   = {7600,  10800, 10800, 15200 };
 
114
 
 
115
static float xlen[4] = {27.0,  19.0,  38.0,  27.0 };
 
116
static float ylen[4] = {19.0,  27.0,  27.0,  38.0 };
 
117
 
 
118
static int pencode[6] = { 1, 2, 4, 3, 5, 6 };
 
119
static int curpen;
 
120
 
 
121
static double xactlng,yactlng;
 
122
static double xfact,yfact;
 
123
 
 
124
static char *init0 = "IN;PS4;DF;SC;SP;";
 
125
static char *init1 = "IN;PS4;DF;SC;RO90;IP;IW;SP;";
 
126
static char *init2 = "IN;PS0;DF;SC;SP;";
 
127
static char *init3 = "IN;PS0;DF;SC;RO90;IP;IW;SP;";
 
128
 
 
129
static FILE *filpt;                         /* Internal file handler         */
 
130
static char *filnam = "hpglplot";
 
131
static int id;
 
132
 
 
133
static int untouched;
 
134
 
 
135
 
 
136
void AGLINHPG (AGLDVCOM)
 
137
struct bufcom *AGLDVCOM;
 
138
{
 
139
extern void AG_DMSG();
 
140
char *init;
 
141
 
 
142
 
 
143
 
 
144
init = init0;                           /* to initialize ... */
 
145
 
 
146
ERRCODE=AGLNOERR;
 
147
 
 
148
switch((int)IBUFFR(0)) {                /* Select function           */
 
149
        char auxbuf[15];                /* File name buffer          */
 
150
        char *pt;
 
151
 
 
152
        case 0:                         /* Hardware initialization   */
 
153
                strcpy(auxbuf,filnam);
 
154
                AG_NEWN(auxbuf);
 
155
 
 
156
                if(*auxbuf == '\0') {
 
157
                        ERRCODE=DEVOPNSEV;
 
158
                        return;
 
159
                }
 
160
 
 
161
                filpt=fopen(auxbuf,"w");        /* Open output file          */
 
162
 
 
163
                if(filpt==NULL) { 
 
164
                        AG_DMSG("Open error:",auxbuf);
 
165
                        ERRCODE=DEVOPNSEV; 
 
166
                        break; 
 
167
                }
 
168
      
 
169
                CHANNEL=fileno(filpt);
 
170
 
 
171
                AG_DMSG("Out to:",auxbuf);
 
172
 
 
173
                pt=CHARBUF;                     /* Get USRAUX string       */
 
174
                while(*pt++);                   /* Skip device name        */
 
175
                while(*pt++);                   /* Skip SYSAUX info        */
 
176
 
 
177
                if(*pt=='\0')
 
178
                        id=0;
 
179
                else
 
180
                        id = TOUPPER(*pt) - 'A';
 
181
 
 
182
                switch(id) {
 
183
                        case 0: init = init0; break;
 
184
                        case 1: init = init1; break;
 
185
                        case 2: init = init2; break;
 
186
                        case 3: init = init3; break;
 
187
                }
 
188
 
 
189
                strcpy(CHARBUF,auxbuf);         /* Copy filename to buffer   */
 
190
 
 
191
                untouched=TRUE;                 /* Compute scaling factors    */
 
192
 
 
193
                xactlng = RBUFFR(0); 
 
194
                xactlng = (xactlng<=xlen[id])?xactlng:xlen[id];
 
195
                xactlng = (xactlng<=0.0) ? xlen[id] : xactlng;
 
196
                yactlng = RBUFFR(1); 
 
197
                yactlng = (yactlng<=ylen[id])?yactlng:ylen[id];
 
198
                yactlng = (yactlng<=0.0) ? ylen[id] : yactlng;
 
199
 
 
200
                xfact = (xpix[id]-1)*(xactlng/xlen[id]);
 
201
                yfact = (ypix[id]-1)*(yactlng/ylen[id]);
 
202
 
 
203
                fputs(init,filpt);              /* Send init commands  */
 
204
                curpen=HPGBLACK;
 
205
                break;
 
206
 
 
207
        case 1:                         /* Pass back device characteristics  */
 
208
                *(CHARBUF) = '\0';
 
209
                RBUFFR(0) = xactlng;
 
210
                RBUFFR(1) = yactlng;
 
211
                IBUFFR(1) = HPFLAGS;
 
212
                IBUFFR(2) = HPPLANES;
 
213
                IBUFFR(3) = xpix[id];
 
214
                IBUFFR(4) = ypix[id];
 
215
                IBUFFR(5) = VERSCODE;
 
216
                IBUFFR(6) = HPMAXLWIDTH;
 
217
 
 
218
                IBUFFR(7) = HPGWHITE;   /* Default Background */
 
219
                IBUFFR(8) = HPGBLACK;   /* Default foreground */
 
220
                IBUFFR(9) = HPGBLACK;
 
221
                IBUFFR(10) = HPGRED;
 
222
                IBUFFR(11) = HPGGREEN;
 
223
                IBUFFR(12) = HPGBLUE;
 
224
                IBUFFR(13) = HPGYELLOW;
 
225
                IBUFFR(14) = HPGMAGENTA;
 
226
                IBUFFR(15) = HPGCYAN;
 
227
                IBUFFR(16) = HPGWHITE;
 
228
 
 
229
                RBUFFR(2) = CHARMULT;
 
230
                RBUFFR(6) = xlen[id];
 
231
                RBUFFR(7) = ylen[id];
 
232
                RBUFFR(8) = xlen[id];
 
233
                RBUFFR(9) = ylen[id];
 
234
                break;
 
235
 
 
236
        case 2:                         /* set color                 */
 
237
                curpen=IBUFFR(1);
 
238
                if(curpen>=0) 
 
239
                        fprintf(filpt,"SP%d;\n",pencode[curpen]);
 
240
                ERRCODE=AGLNOERR;
 
241
                break;
 
242
 
 
243
        case 3:                         /* set line style            */
 
244
                ERRCODE=AGLNOERR;
 
245
                break;
 
246
 
 
247
        case 4:                         /* set line width            */
 
248
                ERRCODE=UNSFEATINF;     /* Unsupported               */
 
249
                break;
 
250
 
 
251
        case 6:                 /* Coordinate roundoff       */
 
252
                break;          /* Unnecessary for high resol. devices */
 
253
}
 
254
}
 
255
 
 
256
 
 
257
void AGLCUHPG(AGLDVCOM)
 
258
struct bufcom *AGLDVCOM;
 
259
{
 
260
ERRCODE=UNSFEATINF;
 
261
}
 
262
 
 
263
void AGLERHPG(AGLDVCOM)
 
264
struct bufcom *AGLDVCOM;
 
265
{
 
266
ERRCODE=UNSFEATINF;
 
267
}
 
268
 
 
269
void AGLESHPG(AGLDVCOM)
 
270
struct bufcom *AGLDVCOM;
 
271
{
 
272
ERRCODE=UNSFEATINF;
 
273
}
 
274
 
 
275
 
 
276
 
 
277
void AGLSEHPG(AGLDVCOM)
 
278
 struct bufcom *AGLDVCOM;
 
279
  {
 
280
   ERRCODE=AGLNOERR;
 
281
  }
 
282
 
 
283
 
 
284
void AGLTEHPG(AGLDVCOM)
 
285
struct bufcom *AGLDVCOM;
 
286
{
 
287
extern void AG_DMSG();
 
288
fprintf(filpt,"SP0;\n");
 
289
fclose(filpt);
 
290
AG_DMSG("Out file","closed");
 
291
CHANNEL=(-1);
 
292
IBUFFR(0)=untouched;
 
293
filpt=NULL;
 
294
}
 
295
 
 
296
void AGLPLHPG(AGLDVCOM)
 
297
struct bufcom *AGLDVCOM;
 
298
{
 
299
int i,n;
 
300
float *vectx, *vecty;
 
301
 
 
302
ERRCODE=AGLNOERR;
 
303
 
 
304
n=NPOINTS;
 
305
 
 
306
if(curpen<0) 
 
307
        return;
 
308
 
 
309
if(n<2)
 
310
        return;
 
311
 
 
312
untouched=FALSE;
 
313
 
 
314
vectx = VECTX;
 
315
vecty = VECTY;
 
316
 
 
317
fprintf(filpt,"PU%d,%d;\n",                     /* Move to first point     */
 
318
                 (int)((*vectx++)*xfact+0.5),
 
319
                 (int)((*vecty++)*yfact+0.5));
 
320
 
 
321
for(i=1;i<n;i++) {
 
322
        fprintf(filpt,"PD%d,%d;\n",
 
323
                      (int)((*vectx++)*xfact+0.5),
 
324
                      (int)((*vecty++)*yfact+0.5));
 
325
}
 
326
}
 
327