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

« back to all changes in this revision

Viewing changes to libsrc/plot/pco.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) 1993-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 Massachusetts 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
.IDENTifer   PCO
 
30
.PURPOSE     Takes care of opening and closing graphics devices
 
31
.AUTHOR      R.M. van Hees IPG-ESO Garching
 
32
.KEYWORDS    High level plot interface
 
33
.LANGUAGE    C
 
34
.COMMENTS    holds PCOPEN and PCCLOS
 
35
.ENVIRONment MIDAS and AGL
 
36
             #include <agl.h>           Prototypes for AGL application programs
 
37
             #include <osparms.h>       Symbols used by the OS interfaces
 
38
             #include <plot_def.h>      Symbols used by the PLT interfaces
 
39
             #include <midas_def.h>     Prototypes for MIDAS interfaces
 
40
 
 
41
.VERSION     1.0  23-Sep-1993  FORTRAN --> C         RvH
 
42
 
 
43
 090630         last modif
 
44
------------------------------------------------------------*/
 
45
/*
 
46
 * Define _POSIX_SOURCE to indicate
 
47
 * that this is a POSIX program
 
48
 */
 
49
#define  _POSIX_SOURCE 1
 
50
 
 
51
/*
 
52
 * definition of the used functions in this module
 
53
 */
 
54
#include <stdio.h>
 
55
#include <string.h>
 
56
#include <stdlib.h>
 
57
#include <math.h>
 
58
#include <idinumd.h>
 
59
#include <midas_def.h>
 
60
 
 
61
/*
 
62
 * define some macros and constants
 
63
 */
 
64
#include <osparms.h>
 
65
#include <plot_def.h>
 
66
 
 
67
#undef  FATAL
 
68
#define FATAL           1                              /* error status FATAL */
 
69
 
 
70
#define MAXDEV          10            /* maximum number of different devices */
 
71
#define MAXLEN          80                  /* maximum length of device name */
 
72
 
 
73
/* The routine PCOPEN makes use of several static functions. 
 
74
 * They are used according to the following scheme:
 
75
 *
 
76
 *           graphic display        PCOPEN         image display
 
77
 *                                    |
 
78
 *                                  PCDEV
 
79
 *                                    |
 
80
 *                           <-------- ---------->
 
81
 *                    GRPCLP                       DISCLP
 
82
 *                                                   |
 
83
 *                                                 WC2PIX
 
84
 *                                                   |
 
85
 *                                    |            GETFRAME
 
86
 *                                  PCSET
 
87
 *                                    |
 
88
 *                                  PCTSET
 
89
 *                                    |
 
90
 *                                  PCWND
 
91
 */
 
92
                                  
 
93
/*
 
94
 * definition of struct dev, containing device name and AGL ID-number
 
95
 */
 
96
struct dev 
 
97
   { 
 
98
   char name[21];
 
99
   int  id;
 
100
   };
 
101
 
 
102
/*
 
103
 
 
104
*/
 
105
 
 
106
/*++++++++++++++++++++++++++++
 
107
.IDENTifer   PCDEV
 
108
.PURPOSE     get logical device name for current graphics window
 
109
             on both workstations and terminals
 
110
     input:   char *kname:  type of device
 
111
    output:   char *lname:  logical name of device
 
112
.RETURNS     
 
113
.COMMENTS    The length of the file AGL3CONFIG:agldevs.dat, also 
 
114
             defines the number of supported graphics devices. 
 
115
             This number should consist with the number of devices 
 
116
             declared in the file PLTDEV.INC
 
117
             static function also defined in low level routine GETDEV
 
118
------------------------------*/
 
119
#ifdef __STDC__
 
120
      static int PCDEV( char *kname, char *lname )
 
121
#else
 
122
      static int PCDEV( kname, lname )
 
123
      char *kname, *lname;
 
124
#endif
 
125
 
 
126
{
 
127
int  fid, found;
 
128
char devnam[84], *strtest;   
 
129
 
 
130
char *pldev = "AGL3CONFIG:agldevs.dat",
 
131
     *err_opn = "*** FATAL: PCDEV, Cannot open file with device definitions";
 
132
 
 
133
 
 
134
/* get rid of trailing blanks */
 
135
 
 
136
(void) strtok( kname, " " );
 
137
CGN_LOWSTR( kname );
 
138
 
 
139
 
 
140
/* read from AGLDEVS.dat */
 
141
 
 
142
if ( (fid = CGN_OPEN( pldev, READ )) == -1 ) SCETER( 1, err_opn );
 
143
 
 
144
 
 
145
/* keyword conversion or user input conversion */
 
146
 
 
147
if ( strncmp( kname+1, "_", 1 ) == 0 )
 
148
   strtest = kname+2;                                      /*full device name*/
 
149
else
 
150
   strtest = kname;                                      /*normal device name*/
 
151
 
 
152
found = FALSE;
 
153
while ( ! found && ( osaread( fid, devnam, MAXLEN )) >= 0 )
 
154
      { if ( ! (*devnam == '#') ) 
 
155
           { if ( ! strncmp( devnam, "unknown", 7 ) )
 
156
                { (void) strcpy( lname, "unknown" );
 
157
                  found = TRUE;
 
158
                }
 
159
             else
 
160
                { (void) strtok( devnam, ":");
 
161
                  if ( strcmp( strtest, devnam ) == 0 )
 
162
                     { (void) strcpy( lname, strtest );
 
163
                       found = TRUE;
 
164
                     }
 
165
                }
 
166
           }
 
167
      }
 
168
 
 
169
(void) osaclose(fid); 
 
170
 
 
171
if ( found == FALSE ) 
 
172
   {
 
173
   SCTPUT( "*** FATAL: PCDEV, Cannot find device definition" );
 
174
   return FATAL;
 
175
   }
 
176
else
 
177
   return ERR_NORMAL;
 
178
}
 
179
 
 
180
/*
 
181
 
 
182
*/
 
183
 
 
184
/*+++++++++++++++++++++++++++++++
 
185
.IDENTifer   GRPCLP
 
186
.PURPOSE     find and write viewport CLIP values, on graphics display
 
187
     input:   int   plmode :  plot mode
 
188
              char  *device:  name of plotting device
 
189
    output:   float *clpl  :  clip limits
 
190
.COMMENTS    static function
 
191
-------------------------------*/
 
192
#ifdef __STDC__
 
193
      static void GRPCLP( int plmode, char *device, float *clpl )
 
194
#else
 
195
      static void GRPCLP( plmode, device, clpl )
 
196
      char  *device; 
 
197
      int   plmode;
 
198
      float *clpl; 
 
199
#endif
 
200
{
 
201
int    actvals, xy, qdszy[2], knul, unit ;
 
202
 
 
203
float  aspect, xmxcl, maxcl[PLDIM2], devmm[PLDIM2], dval[PLDIM2], 
 
204
       frmwc[PLDIM2], frmcl[PLDIM2], frmmm[PLDIM2], 
 
205
       offset[PLDIM2], offusr[PLDIM2], scale[PLDIM3],
 
206
       scusr[PLDIM2], wndl[4];
 
207
 
 
208
char   frame[5], cmnd[21], text[81], *offcoo[2], *scacoo[2],
 
209
       *errmmoff[PLDIM2], *errscoff[PLDIM2], *errnooff[PLDIM2], 
 
210
       *errmmsca[PLDIM2], *errscsca[PLDIM2], *errnosca[PLDIM2],
 
211
       *errsiz[PLDIM2]; 
 
212
 
 
213
char *errtrm   = "*** FATAL: (GRPCLP) terminal unknown to system", 
 
214
     *errmin   = "           smallest possible scale:%13.6g units/mm",
 
215
     *errlarge = "           largest possible size: %6.1f mm";
 
216
 
 
217
errmmoff[0] = "*** FATAL: maximum offset in x: %6.1f mm";
 
218
errmmoff[1] = "*** FATAL: maximum offset in y: %6.1f mm";
 
219
errscoff[0] = "*** FATAL: maximum offset in x: %6d screen pixels";
 
220
errscoff[1] = "*** FATAL: maximum offset in y: %6d screen pixels";
 
221
errnooff[0] = "*** FATAL: norm. offset in x must be between 0 and 1";
 
222
errnooff[1] = "*** FATAL: norm. offset in y must be between 0 and 1";
 
223
 
 
224
errmmsca[0] = "*** FATAL: maximum axis size in x: %6.1f mm";
 
225
errmmsca[1] = "*** FATAL: maximum axis size in y: %6.1f mm";
 
226
errscsca[0] = "*** FATAL: maximum axis size in x: %6d screen pixels";
 
227
errscsca[1] = "*** FATAL: maximum axis size in y: %6d screen pixels";
 
228
errnosca[0] = "*** FATAL: norm.axis size in x must be between 0 and 1";
 
229
errnosca[1] = "*** FATAL: norm.axis size in y must be between 0 and 1";
 
230
 
 
231
errsiz[0]   = "*** FATAL: plot too large in x direction";
 
232
errsiz[1]   = "*** FATAL: plot too large in y direction";
 
233
 
 
234
PCKRDR( "XWNDL", 4, &actvals, wndl );
 
235
frmwc[0] = (float) fabs( *(wndl+1) - *wndl );
 
236
PCKRDR( "YWNDL", 4, &actvals, wndl );
 
237
frmwc[1] = (float) fabs( *(wndl+1) - *wndl );
 
238
 
 
239
for ( xy = 0; xy < PLDIM2; xy++ ) offcoo[xy] = osmmget(5);
 
240
for ( xy = 0; xy < PLDIM2; xy++ ) scacoo[xy] = osmmget(5);
 
241
 
 
242
/* 
 
243
 * get terminal characteristics, if failed exit
 
244
 */
 
245
if ( ( AG_RGET( "ASPE", &aspect ) != 1 ) || ( AG_RGET( "DEVD", dval ) != 2 ) )
 
246
   SCETER( 1, errtrm );
 
247
for ( xy = 0; xy < PLDIM2; xy++ ) devmm[xy] = 10 * dval[xy];
 
248
 
 
249
/*
 
250
 * determine scaling parameters
 
251
 */
 
252
(void) SCKGETC( "MID$CMND", 1, 20, &actvals, cmnd );
 
253
if ( plmode != 2 || strncmp( QUAL, "AXES", 4 ) == 0 )
 
254
   { clpl[0] = 0.15;
 
255
     clpl[1] = 0.95;
 
256
     clpl[2] = 0.1;
 
257
     clpl[3] = 0.95;
 
258
   }
 
259
else                                                   /* plot mode equals 2 */
 
260
   { clpl[0] = 0.15;
 
261
     clpl[1] = 0.8;
 
262
     clpl[2] = 0.1;
 
263
     clpl[3] = 0.95;
 
264
   }
 
265
 
 
266
/*
 
267
 * read the x and Y coordinate unit for x and y offset
 
268
 */
 
269
PCKRDR( "XOFF", 1, &actvals, offusr );
 
270
PCKRDR( "YOFF", 1, &actvals, offusr+1 );
 
271
PCKRDC( "CXOF", 4, &actvals, offcoo[0] );
 
272
PCKRDC( "CYOF", 4, &actvals, offcoo[1] );
 
273
PCKRDR( "OFFS", 2, &actvals, offset );
 
274
 
 
275
for ( xy = 0; xy < PLDIM2; xy++ )
 
276
/*
 
277
 * set offset in mm
 
278
 */
 
279
   if ( strncmp( offcoo[xy], "MM", 2 ) == 0 ) 
 
280
       { offset[xy] = MYMAX( offusr[xy], offset[xy] );
 
281
         if ( offset[xy] + 999  > PLT_EPS )
 
282
            { if ( offset[xy] > devmm[xy] )
 
283
                 { (void) sprintf( text, errmmoff[xy], devmm[xy] );
 
284
                  SCETER( 3, text);
 
285
                 }
 
286
              else 
 
287
                 { if ( xy == FOR_X )
 
288
                      clpl[0] = offset[0] / devmm[0];
 
289
                   else
 
290
                      clpl[2] = offset[1] / devmm[1];
 
291
                 }
 
292
            }
 
293
       }
 
294
/*
 
295
 * set offset in screen coordinates
 
296
 */
 
297
   else if ( strncmp( offcoo[xy], "SC", 2 ) == 0 ) 
 
298
       { (void) SCKRDI( "IDIDEV", 32, 2, &actvals, qdszy, &unit, &knul);
 
299
         if ( offset[xy] > qdszy[xy] )
 
300
            { (void) sprintf( text, errscoff[xy], qdszy[xy] );
 
301
              SCETER( 3, text);
 
302
            }
 
303
         else 
 
304
            {
 
305
            if ( xy == FOR_X )
 
306
                clpl[0] = offset[0]/qdszy[0];
 
307
             else
 
308
                clpl[2] = offset[1]/qdszy[1];
 
309
            }
 
310
       }
 
311
/*
 
312
 * set offset in normlized coordinates
 
313
 */
 
314
   else if ( strncmp( offcoo[xy], "NO", 2 ) == 0 )                      
 
315
       { if ( offset[xy] < 0.0 || offset[xy] > 1.0 )
 
316
            { (void) strcpy(text, errnooff[xy]);
 
317
              SCETER( 3, text);
 
318
            }
 
319
         else 
 
320
            { if ( xy == FOR_X )
 
321
                 clpl[0] = offset[0];
 
322
              else
 
323
                 clpl[2] = offset[1];
 
324
            }
 
325
       }
 
326
 
 
327
/* 
 
328
 * else we assume mm offset
 
329
 */
 
330
   else
 
331
 
 
332
       { offset[xy] = MYMAX( offusr[xy], offset[xy] );
 
333
         if ( offset[xy] + 999  > PLT_EPS )
 
334
            { if ( offset[xy] > devmm[xy] )
 
335
                 { (void) sprintf( text, errmmoff[xy], devmm[xy] );
 
336
                  SCETER( 3, text);
 
337
                 }
 
338
              else 
 
339
                 { if ( xy == FOR_X )
 
340
                      clpl[0] = offset[0] / devmm[0];
 
341
                   else
 
342
                      clpl[2] = offset[1] / devmm[1];
 
343
                 }
 
344
            }
 
345
       }
 
346
 
 
347
/*
 
348
 * X and Y scaling and position:
 
349
 */
 
350
PCKRDC( "FRAME", 4, &actvals, frame );
 
351
PCKRDR( "XSCA", 1, &actvals, scusr );
 
352
PCKRDR( "YSCA", 1, &actvals, scusr+1 );
 
353
PCKRDC( "CXSC", 4, &actvals, scacoo[0] );
 
354
PCKRDC( "CYSC", 4, &actvals, scacoo[1] );
 
355
PCKRDR( "SCAL", 3, &actvals, scale );
 
356
 
 
357
for ( xy = 0; xy < PLDIM2; xy++ )
 
358
/* 
 
359
 * scale via command line or preset
 
360
 */
 
361
    {if ( fabs( scale[xy] ) > PLT_EPS )
 
362
         { if ( ( strncmp( scacoo[xy], "MM", 2 ) == 0 ) 
 
363
               || ( scale[xy] < 0.0 ) )     /* scale in mm. or in neg. numbers*/ 
 
364
             { if ( fabs(scale[xy]) > devmm[xy] )
 
365
                   { (void) sprintf( text, errmmsca[xy], devmm[xy] );
 
366
                   SCETER( 3, text);
 
367
                   }
 
368
                else
 
369
                   frmmm[xy] = (float) fabs( scale[xy]);       /*viewport size*/
 
370
             }
 
371
 
 
372
           else if ( strncmp( scacoo[xy], "SC", 2 ) == 0 )    /*screen. coord.*/
 
373
             { (void) SCKRDI( "IDIDEV", 32, 2, &actvals, qdszy, &unit, &knul);
 
374
               if ( scale[xy] > qdszy[xy] )
 
375
                   { (void) sprintf( text, errscsca[xy], qdszy[xy] );
 
376
                   SCETER( 3, text);
 
377
                   }
 
378
                else 
 
379
                   frmmm[xy] = scale[xy]/qdszy[xy]*devmm[xy];  /*viewport size*/
 
380
  
 
381
             }
 
382
 
 
383
          else if ( strncmp( scacoo[xy], "NO", 2 ) == 0  )        /*norm.coord*/       
 
384
             { if ( scale[xy] < 0.0 || scale[xy] > 1.0 )
 
385
                  { (void) strcpy(text, errnosca[xy]);
 
386
                   SCETER( 3, text);
 
387
                  }
 
388
               else 
 
389
                   frmmm[xy] = scale[xy]*devmm[xy];                           
 
390
 
 
391
             }
 
392
 
 
393
          else                                           /*scale in wo per mm*/
 
394
             frmmm[xy] = fabs( frmwc[xy]/scale[xy] );
 
395
                         
 
396
 
 
397
          frmcl[xy] = (float) fabs(frmmm[xy]/devmm[xy]);   
 
398
         }
 
399
 
 
400
/* 
 
401
 *scale via PLRGRAP
 
402
 */
 
403
      else if ( fabs( scusr[xy]) > PLT_EPS )
 
404
         { if ( scusr[xy] < 0.0 )                               /*scale in mm*/
 
405
              frmmm[xy] = (float) fabs( scusr[xy] );          /*viewport size*/
 
406
           else
 
407
              frmmm[xy] = frmwc[xy] / scusr[xy];             /*scale in wo/mm*/
 
408
           frmcl[xy] = (float) fabs( frmmm[xy] / devmm[xy]); /*norm.view size*/
 
409
         }
 
410
 
 
411
      else                                      /*no scale given; use default*/
 
412
         { if ( xy == FOR_X )
 
413
              { if ( strncmp( frame, "SQ", 2 ) == 0 )
 
414
                   { xmxcl = clpl[1];
 
415
                     clpl[1] = clpl[0] + aspect* (clpl[3] - clpl[2]);
 
416
                     if ( clpl[1] > xmxcl )
 
417
                        { clpl[1] = xmxcl;
 
418
                          clpl[2] = clpl[3]-(clpl[1]-clpl[0])/aspect;
 
419
                        }
 
420
                   }
 
421
                frmcl[xy]  = clpl[1] - clpl[0];
 
422
                frmmm[xy]  = devmm[xy] * frmcl[xy];
 
423
              }
 
424
           else
 
425
              { frmcl[xy]  = clpl[3] - clpl[2];
 
426
                frmmm[xy]  = devmm[xy] * frmcl[xy];
 
427
              }
 
428
         }
 
429
 
 
430
      if ( xy == FOR_X )
 
431
         maxcl[xy] = clpl[1] - clpl[0];
 
432
      else
 
433
         maxcl[xy] = clpl[3] - clpl[2];
 
434
 
 
435
/*
 
436
 * check the size 
 
437
 */
 
438
      if ( frmcl[xy] > maxcl[xy]+0.01 && 
 
439
           strncmp( device, "VERSATEC", 8 ) != 0 )
 
440
         { if ( scale[xy] < 0.0 )
 
441
              (void) sprintf( text, errlarge, maxcl[xy] * devmm[xy] );
 
442
           else
 
443
              (void) sprintf( text, errmin, frmwc[xy]/( maxcl[xy] * devmm[xy]));
 
444
           SCTPUT( errsiz[xy] );
 
445
           SCETER( 1, text );
 
446
         }
 
447
      else                                                     /* size is ok */
 
448
         { if ( xy == FOR_X )
 
449
              clpl[1] = clpl[0] + frmcl[xy];
 
450
           else
 
451
              { if ( fabs( offset[1] + 999 ) > PLT_EPS )
 
452
                   clpl[3] = clpl[2] + frmcl[xy];
 
453
                else
 
454
                   clpl[2] = clpl[3] - frmcl[xy];
 
455
              }
 
456
          }
 
457
    }
 
458
 
 
459
for ( xy = 0; xy < PLDIM2; xy++ ) 
 
460
    scale[xy] = (float) fabs( frmwc[xy]/frmmm[xy]);
 
461
 
 
462
PCKWRR( "SCAL", 2, scale );                                     /*store scale*/
 
463
PCKWRR( "CLPL", 4, clpl );                                /*store clip values*/
 
464
 
 
465
for ( xy = 0; xy < PLDIM2; xy++ ) osmmfree(offcoo[xy]);
 
466
for ( xy = 0; xy < PLDIM2; xy++ ) osmmfree(scacoo[xy]);
 
467
 
 
468
return;
 
469
}
 
470
 
 
471
/*
 
472
 
 
473
*/
 
474
 
 
475
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
476
.IDENTifer   GETFRAME
 
477
.PURPOSE     Get name of frame displayed on current active display channel
 
478
    output:    char *frame
 
479
.RETURNS     0 = o.k., else nothing loaded into channel
 
480
.COMMENTS    static function, also defined in PLOTAXES
 
481
------------------------------------------------------------*/
 
482
#ifdef __STDC__
 
483
      static int GETFRAME( char *frame )
 
484
#else
 
485
      static int GETFRAME( frame )
 
486
      char *frame;
 
487
#endif
 
488
 
 
489
{
 
490
int iav;
 
491
 
 
492
 
 
493
/* get the name of the frame loaded in the current image display */
 
494
 
 
495
(void) SCKGETC("IDIMEMC",1,80,&iav,frame);
 
496
 
 
497
if (truelen(frame) == 0) 
 
498
   return 1;
 
499
else
 
500
   return ERR_NORMAL;
 
501
}
 
502
 
 
503
/*
 
504
 
 
505
*/
 
506
 
 
507
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
508
.IDENTifer   WC2PIX
 
509
.PURPOSE     converts world coordinates to screen pixels
 
510
     input:   float *wcpix:  pixel in world coordimates
 
511
    output:   float *scpix:  pixel in screen coordinates
 
512
.COMMENTS    static function
 
513
------------------------------------------------------------*/
 
514
#ifdef __STDC__
 
515
      static void WC2PIX( float *wcpix, float *scpix )
 
516
#else
 
517
      static void WC2PIX( wcpix, scpix )
 
518
      float *wcpix, *scpix;
 
519
#endif
 
520
{
 
521
int     iac, imf, knul, qdszy, dzmemi[13], unit;
 
522
float   cx, cy, imgpix[2];
 
523
double  start[2], step[2];
 
524
char    frame[82];
 
525
 
 
526
char *err_fram  = "*** FATAL: no frame loaded in the display channel";
 
527
 
 
528
/*
 
529
 * get the name of the loaded frame and it's characteristics
 
530
 */
 
531
if ( GETFRAME( frame ) != 0 ) SCETER( 1, err_fram );
 
532
(void) SCFOPN( frame, D_R4_FORMAT, 0, F_IMA_TYPE, &imf );
 
533
(void) SCDRDD( imf, "START", 1, PLDIM2, &iac, start, &unit, &knul );
 
534
(void) SCDRDD( imf, "STEP" , 1, PLDIM2, &iac, step , &unit, &knul );
 
535
(void) SCFCLO( imf );
 
536
 
 
537
/*
 
538
 * get display parameters
 
539
 */
 
540
(void) SCKRDI( "IDIMEMI", 1, 13, &iac, dzmemi, &unit, &knul);
 
541
(void) SCKRDI( "IDIDEV", 3, 1, &iac, &qdszy, &unit, &knul);
 
542
 
 
543
/*
 
544
 * calculate image pixel
 
545
 */
 
546
imgpix[0] = (float) ((wcpix[0] - start[0])/step[0] + 1);
 
547
imgpix[1] = (float) ((wcpix[1] - start[1])/step[1] + 1);
 
548
 
 
549
/*
 
550
 * take care of one real pixel + scaling
 
551
 */
 
552
if ( SCALX < 0 ) 
 
553
   cx = - (imgpix[0] - (float) SFPX ) * (float) SCALX;
 
554
else
 
555
   cx =   (imgpix[0] - (float) SFPX ) / (float) SCALX;
 
556
cx += SSPX;
 
557
 
 
558
if ( SCALY < 0 ) 
 
559
   cy = - (imgpix[1] - (float) SFPY ) * (float) SCALY;
 
560
else
 
561
   cy =   (imgpix[1] - (float) SFPY ) / (float) SCALY;
 
562
cy += SSPY;
 
563
 
 
564
scpix[0] = ( cx - SCROLX ) * ZOOMX;
 
565
scpix[1] = ( cy - SCROLY ) * ZOOMY + qdszy - 1;
 
566
 
 
567
return;
 
568
}
 
569
 
 
570
/*
 
571
 
 
572
*/
 
573
 
 
574
/*++++++++++++++++++++++++++++++
 
575
.IDENTifer   DISCLP
 
576
.PURPOSE     find and write viewport CLIP values, on image display
 
577
     output:  float *clpl  :  clip limits
 
578
.COMMENTS    static function
 
579
--------------------------------*/
 
580
#ifdef __STDC__
 
581
      static void DISCLP( float *clpl )
 
582
#else
 
583
      static void DISCLP( clpl )
 
584
      float *clpl;
 
585
#endif
 
586
{
 
587
int    actvals, imf, knul, unit, xy, scale[PLDIM2], scrpx[PLDIM2];
 
588
 
 
589
float  frmmm[PLDIM2], frmpx[PLDIM2], offmm[PLDIM2], wcpix1[PLDIM2],
 
590
       wndl[8], scpix1[PLDIM2], scpix2[PLDIM2], wcpix2[PLDIM2];
 
591
double step[2];
 
592
char   frame[82];
 
593
 
 
594
char   *err_fram  = "*** FATAL: no frame loaded in the display channel";
 
595
 
 
596
/*
 
597
 * get the name of the loaded frame and it's characteristics
 
598
 */
 
599
if ( GETFRAME( frame ) != 0 ) SCETER( 1, err_fram );
 
600
(void) SCFOPN( frame, D_R4_FORMAT, 0, F_IMA_TYPE, &imf );
 
601
(void) SCDRDD( imf, "STEP" , 1, PLDIM2, &actvals, step , &unit, &knul );
 
602
(void) SCFCLO( imf );
 
603
 
 
604
/*
 
605
 * get display parameters
 
606
 */
 
607
(void) SCKRDI( "IDIDEV", 2, 2, &actvals, scrpx, &unit, &knul);
 
608
(void) SCKRDI( "IDIMEMI", 8, 2, &actvals, scale, &unit, &knul);
 
609
 
 
610
/*
 
611
 * do pixel convertion
 
612
 */
 
613
PCKRDR( "XWNDL", 2, &actvals, wndl );
 
614
PCKRDR( "YWNDL", 2, &actvals, wndl+2 );
 
615
/*
 
616
wcpix1[0] = (float) (wndl[0] + step[0]/2.0);
 
617
wcpix1[1] = (float) (wndl[2] + step[1]/2.0);
 
618
wcpix2[0] = (float) (wndl[1] + step[0]/2.0);
 
619
wcpix2[1] = (float) (wndl[3] + step[1]/2.0);
 
620
*/
 
621
 
 
622
wcpix1[0] = (float) (wndl[0]);
 
623
wcpix1[1] = (float) (wndl[2]);
 
624
wcpix2[0] = (float) (wndl[1]);
 
625
wcpix2[1] = (float) (wndl[3]);
 
626
 
 
627
WC2PIX( wcpix1, scpix1 );
 
628
WC2PIX( wcpix2, scpix2 );
 
629
 
 
630
/*
 
631
 * make the box 1/2 pixel larger
 
632
 */
 
633
if (scale[0] < 0.0)
 
634
   {
 
635
   scpix1[0] -= 0.5 * scale[0];
 
636
   scpix2[0] -= 0.5 * scale[0];
 
637
   }
 
638
if (scale[1] < 0.0)
 
639
   { 
 
640
   scpix1[1] -= 0.5 * scale[1];
 
641
   scpix2[1] -= 0.5 * scale[1];
 
642
   }
 
643
 
 
644
/* 
 
645
 * get terminal characteristics
 
646
 */
 
647
for ( xy = 0; xy < PLDIM2; xy++ ) 
 
648
    { frmpx[xy] = (float) fabs((double)  scpix2[xy] - scpix1[xy] ) + 1;
 
649
      frmmm[xy] = frmpx[xy] / scrpx[xy];
 
650
      offmm[xy] = scpix1[xy] / scrpx[xy];
 
651
    }
 
652
/*
 
653
 * set the clip coordinates
 
654
 */
 
655
clpl[0] = MYMAX( offmm[0], 0.0 );
 
656
clpl[1] = MYMIN( offmm[0] + (float) fabs((double) frmmm[0] ), 1.0 );
 
657
clpl[2] = MYMAX( offmm[1], 0.0 );
 
658
clpl[3] = MYMIN( offmm[1] + (float) fabs((double) frmmm[1] ), 1.0 );
 
659
 
 
660
PCKWRR( "CLPL", 4, clpl );                               /*store clip values*/
 
661
}
 
662
 
 
663
/*
 
664
 
 
665
*/
 
666
 
 
667
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
668
.IDENTifer   PCWND
 
669
.PURPOSE     Set the plot window in world coordinates
 
670
   input:     float *wcfram  plot window limits in world coordinated
 
671
 
 
672
.COMMENTS    static function, also defined as low level plot interface
 
673
------------------------------------------------------------*/
 
674
#ifdef __STDC__
 
675
      static void PCWND( float *wcfram )
 
676
#else
 
677
      static void PCWND( wcfram )
 
678
      float *wcfram;
 
679
#endif
 
680
{
 
681
float  wndl[4];
 
682
 
 
683
/*
 
684
 * copy input array because we are going to change it
 
685
 */
 
686
wndl[0] = wcfram[0];
 
687
wndl[1] = wcfram[1];
 
688
wndl[2] = wcfram[4];
 
689
wndl[3] = wcfram[5];
 
690
 
 
691
/*
 
692
 * set the window
 
693
 */
 
694
if ( wcfram[3] <= -2.0 )                                /* logarithmic x-axis*/
 
695
   { wndl[0] = exp( wcfram[0] );
 
696
     wndl[1] = exp( wcfram[1] );
 
697
   }
 
698
else if ( wcfram[3] < 0.0 )
 
699
   { wndl[0] = pow( 10.0, wcfram[0] );
 
700
     wndl[1] = pow( 10.0, wcfram[1] );
 
701
   }
 
702
 
 
703
if ( wcfram[7] <= -2.0 )                                /* logarithmic y-axis*/
 
704
   { wndl[2] = exp( wcfram[4] );
 
705
     wndl[3] = exp( wcfram[5] );
 
706
   }
 
707
else if ( wcfram[7] < 0.0 )
 
708
   { wndl[2] = pow( 10.0, wcfram[4] );
 
709
     wndl[3] = pow( 10.0, wcfram[5] );
 
710
   }
 
711
/* 
 
712
 *define window
 
713
 */
 
714
AG_WDEF( wndl[0], wndl[1], wndl[2], wndl[3] );
 
715
AG_SSET( "liny" );
 
716
AG_SSET( "linx" );
 
717
if ( wcfram[3] < 0 ) AG_SSET( "logx" );
 
718
if ( wcfram[7] < 0 ) AG_SSET( "logy" );
 
719
 
 
720
return;
 
721
}
 
722
 
 
723
/*
 
724
 
 
725
*/
 
726
 
 
727
/*++++++++++++++++++++++++++++++
 
728
.IDENTifer   PCSET
 
729
.PURPOSE     does a complete setup of the plot parameters and AGL
 
730
.COMMENTS    static function
 
731
-------------------------------*/
 
732
#ifdef __STDC__
 
733
      static void PCSET( void )
 
734
#else
 
735
      static void PCSET()
 
736
#endif
 
737
{
 
738
int    actvals, color, font, ltype, lwidth, twidth, ncol;
 
739
float  wcfram[8];
 
740
char   clmod[5], text[81];
 
741
 
 
742
/*
 
743
 * set character font
 
744
 */
 
745
PCKRDI( "FONT", 1, &actvals, &font );
 
746
(void) sprintf( text, "font=%1d", font );
 
747
AG_SSET( text );
 
748
 
 
749
/* 
 
750
 * set line style
 
751
 */
 
752
PCKRDI( "LTYPE", 1, &actvals, &ltype );
 
753
if ( ltype > 0 )
 
754
   { (void) sprintf( text, "lstyl=%1d", ltype - 1 );
 
755
     AG_SSET( text );
 
756
   }
 
757
/*
 
758
 * set line width
 
759
 */
 
760
PCKRDI( "LWIDTH", 1, &actvals, &lwidth );
 
761
(void) sprintf( text, "lwidt=%1d", lwidth - 1 );
 
762
AG_SSET( text );
 
763
 
 
764
/*
 
765
 * set line width for text
 
766
 */
 
767
PCKRDI( "TWIDTH", 1, &actvals, &twidth );
 
768
(void) sprintf( text, "twidt=%1d", twidth );
 
769
AG_SSET( text );
 
770
 
 
771
/*
 
772
 * determine character and symbol sizes for the MIDAS layout
 
773
 */
 
774
PCTSET();
 
775
 
 
776
/*
 
777
 * set color
 
778
 */
 
779
(void) AG_IGET( "ncol", &ncol);
 
780
PCKRDI( "COLOR", 1, &actvals, &color );
 
781
if ( ncol == 1 && color > 1 ) color = 1;
 
782
(void) sprintf( text, "color=%1d", color );
 
783
AG_SSET( text );
 
784
 
 
785
/*
 
786
 * color mode
 
787
 */
 
788
PCKRDC( "COLMODE", 4, &actvals, clmod );
 
789
if ( strncmp( clmod, "X", 1 ) == 0 )
 
790
   AG_SSET( "mode=Xor" );
 
791
else
 
792
   AG_SSET( "mode=Sub" );
 
793
/*
 
794
 * do a complete "manual" setting, which gives a default frame!!
 
795
 */
 
796
PCKRDR( "XWNDL", 4, &actvals, wcfram );
 
797
PCKRDR( "YWNDL", 4, &actvals, wcfram+FOR_Y );
 
798
PCWND( wcfram );
 
799
 
 
800
return;
 
801
}
 
802
 
 
803
/*
 
804
 
 
805
*/
 
806
 
 
807
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
808
.IDENTifier  PCOPEN
 
809
.PURPOSE     Sets up the graphic device according to plot mode
 
810
      input:  char *devnam:  name of device to be activated
 
811
              char *plname:  name of meta file
 
812
              int  access :  access mode: -1 = cursor,
 
813
                                           1 = over plot,
 
814
                                           0 = new plot.
 
815
  in/output:  int  *plmode: plot mode: 0 = no axis & no info,
 
816
                                       1 = draw axes & some info,
 
817
                                       2 = draw axes & full info, 
 
818
                                      -1 take value from keyword PMODE
 
819
 
 
820
.COMMENTS    PCOPEN activates a given device, or the current (by MIDAS) 
 
821
             defined device if no device name is given. A given device has
 
822
             to be present in the AGLDEVS.dat file.
 
823
 
 
824
             PCOPEN does not open or append to a meta file if PLNAME
 
825
             equals "NO"ne. If no name or a file name (without ".plt" 
 
826
             extention) is given PCOPEN will open or append to a meta file
 
827
             (see access mode). Default for the name of the meta file is 
 
828
             the name of the activated device extended with MIDAS session 
 
829
             number with extention ".plt".
 
830
 
 
831
             PCOPEN reads the MIDAS graphics keywords, opens this device
 
832
             (on graphics or image display) according to the MIDAS settings.
 
833
             The coordinate box have to be defined BEFORE PCOPEN !!! 
 
834
             Use the MIDAS routine PCKWRR, with parameters: XWNDL and YWNDL.
 
835
------------------------------------------------------------*/
 
836
void PCOPEN( devnam, plname, access, plmode )
 
837
char *devnam, *plname;
 
838
int  access, *plmode; 
 
839
 
 
840
{
 
841
int   actvals, amode, bcolor, iac, idev, meta, newdev, pmode;
 
842
float ocount, rdef, clpl[4];
 
843
char  *pntr, session[3], debug[5], erase[5], action[9], cmnd[21], 
 
844
      device[21], dname[21], plmeta[81], text[81];
 
845
 
 
846
static int    nrdev = 0;
 
847
static struct dev  devtbl[MAXDEV];
 
848
      
 
849
char *errpmode = "*** FATAL: PCOPEN, unknown plot mode ...",
 
850
     *errdev   = "*** FATAL: PCOPEN, unknown or unavailable device",
 
851
     *errhlp   = "                   use HELP [printers]",
 
852
     *errmxdev = "*** FATAL: PCOPEN, too many different devices opened (> 4)",
 
853
     *errplt   = "*** FATAL: PCOPEN, no graphics device ==> No CURSOR",
 
854
     *errnopl  = "*** FATAL: PCOPEN, no existing plot file to append",
 
855
     *errnoex  = "*** FATAL: PCOPEN, no existing plot for graphics cursor";
 
856
/*
 
857
 * initialize device and meta-file name
 
858
 */
 
859
*device = *plmeta = '\0';
 
860
(void) strncat( device, devnam, 20 );
 
861
(void) strncat( plmeta, plname, 80 );
 
862
(void) SCKGETC( "MID$SESS", 11, 2, &iac, session );
 
863
PCKRDR( "OCOUNT", 1, &actvals, &ocount );
 
864
 
 
865
/*
 
866
 * Check plot mode
 
867
 */
 
868
if ( *plmode == -1 )                             /* plmode = -1 => use PMODE */
 
869
   { PCKRDI( "PMODE", 1, &actvals, &pmode );
 
870
     *plmode = pmode;
 
871
   }
 
872
/*
 
873
 * and check its value
 
874
 */
 
875
if ( *plmode < 0 && *plmode > 2 ) SCETER( 2, errpmode );
 
876
 
 
877
/*
 
878
 * debug mode
 
879
 */
 
880
PCKRDC( "DEBUG", 4, &actvals, debug );
 
881
if ( strncmp( debug, "ON", 2 ) == 0 )
 
882
   AG_SSET( "msgw;debu=1;errf=aglerr.log" );
 
883
else
 
884
   AG_SSET( "msgn;debu=0" );
 
885
 
 
886
/*
 
887
 * get device name
 
888
 */
 
889
if ( truelen( device ) == 0 )                        /* a device name given? */
 
890
   (void) SCKGETC( "MID$PLOT", 1, 20, &iac, device );
 
891
 
 
892
if ( PCDEV( device, dname ) != ERR_NORMAL || 
 
893
     strncmp( dname, "unknown", 7 ) == 0 )
 
894
   { SCTPUT( errdev );
 
895
     SCETER( 3, errhlp );
 
896
   }
 
897
 
 
898
newdev = TRUE;
 
899
if ( nrdev == 0 )                               /* are there devices opened? */
 
900
   { nrdev = 1;
 
901
     idev = 0;
 
902
     (void) strcpy( devtbl[idev].name, dname );
 
903
   }
 
904
else
 
905
   { for ( idev = 0; idev < nrdev; idev++ )
 
906
         if ( strcmp( dname, devtbl[idev].name ) == 0 ) break;
 
907
 
 
908
     if ( idev == nrdev )                                        /*new device*/
 
909
        { if ( ++nrdev > MAXDEV ) SCETER( 4, errmxdev );
 
910
          (void) strcpy( devtbl[idev].name, dname );
 
911
        }
 
912
     else
 
913
        newdev = FALSE;
 
914
   }
 
915
/*
 
916
 * set the access mode according to plot, overplot and cursor command
 
917
 */
 
918
(void) SCKGETC( "MID$CMND", 1, 20, &iac, cmnd );
 
919
if ( access == -1 )                              /*reserved for cursor*/
 
920
   { if ( strncmp( dname,"graph",5 ) != 0 && strncmp( dname,"image",5 ) != 0 )
 
921
        SCETER( 4, errplt );
 
922
     amode = -1;
 
923
   }
 
924
else if ( access == 1 )                                    /*overplot command*/
 
925
   { if ( strncmp( QUAL, "AX", 2 ) == 0 )                              /*axes*/
 
926
        amode = 2;
 
927
     else if ( strncmp( COMM, "LAB", 3 ) == 0 )              /*label graphics*/
 
928
        amode = 3;
 
929
     else                                                              /*data*/
 
930
        amode = 4;
 
931
   }
 
932
else                                                           /*plot command*/
 
933
   { PCKRDC( "CLEAR", 4, &actvals, erase );
 
934
     if ( strncmp( QUAL, "AX", 2 ) == 0 )                              /*axes*/
 
935
        { if ( strncmp( erase, "ON", 2 ) == 0 || ocount < 1)
 
936
             amode = 1;                                               /*erase*/
 
937
          else 
 
938
             amode = 2;                                            /*no erase*/
 
939
        }
 
940
     else                                                     /*data plotting*/
 
941
        { if ( strncmp( erase, "ON", 2 ) == 0 || ocount < 1)
 
942
             amode = 5;                                               /*erase*/
 
943
          else                                                     
 
944
             amode = 6;                                            /*no erase*/
 
945
        }
 
946
   }
 
947
/* 
 
948
 * get the plot file
 
949
 */
 
950
meta = FALSE;                                        /* default: no meta file*/
 
951
if ( amode > 0 )
 
952
   { if ( strncmp( plmeta, "no", 2 ) != 0 )
 
953
        { meta = TRUE;
 
954
          if ( amode == 1 || amode == 5 )                      /*new plotfile*/
 
955
             { if ( truelen( plmeta ) == 0 )            /*called with no name*/
 
956
                  { (void) strcpy( plmeta, dname );
 
957
                    if ( (pntr = strchr( plmeta, '.' )) == NULL )
 
958
                       (void) strcat( plmeta, session );
 
959
                    else
 
960
                       (void) strcpy( pntr, session );                       
 
961
                  }
 
962
               if ( (pntr = strchr( plmeta, '.' )) == NULL )
 
963
                  (void) strcat( plmeta, ".plt" );
 
964
               else
 
965
                  (void) strcpy( pntr, ".plt" );
 
966
               PCKWRC( "PLNAM", plmeta );
 
967
               ocount = 0.0;
 
968
             }
 
969
          else                                                /*overplot mode*/
 
970
             { PCKRDC( "PLNAM", 80, &actvals, plmeta );
 
971
               if ( ocount == 0.0 ) SCETER( 5, errnopl );
 
972
             }
 
973
        }
 
974
   }
 
975
/*
 
976
 * define default viewport setting
 
977
 */
 
978
clpl[0] = clpl[2] = 0.0;
 
979
clpl[1] = clpl[3] = 1.0;
 
980
/*
 
981
 * open viewport for device
 
982
 */
 
983
switch (amode)
 
984
   { case 1:                                     /*PLOT AXES*/
 
985
     case 5:                                     /*PLOT DATA erase*/
 
986
         (void) strcat( dname, ":" );
 
987
         break;
 
988
     case -1:                                    /*GET GCURSOR*/
 
989
         if ( ocount == 0.0 ) SCETER( 6, errnoex );           /*none existing*/
 
990
         PCKRDR( "CLPL", 4, &actvals, clpl );
 
991
     case 3:                                     /*LABEL GRAPH*/
 
992
         if ( ocount == 0.0 ) break;
 
993
     case 2:                                     /*OVER AXES*/
 
994
     case 4:                                     /*OVER DATA*/
 
995
     case 6:                                     /*PLOT DATA no-erase*/
 
996
         (void) strcat( dname, "/n:" );
 
997
         (void) strcat( plmeta, "/a" );
 
998
         break;
 
999
   }
 
1000
if ( newdev ) 
 
1001
    devtbl[idev].id = AG_VDEF( dname, 
 
1002
                              clpl[0], clpl[1], clpl[2], clpl[3], 0., 0. );
 
1003
else
 
1004
   AG_VSEL( devtbl[idev].id );
 
1005
 
 
1006
if ( meta ) 
 
1007
   { AG_MCLS();                            /* close the still open meta file */
 
1008
     AG_MOPN( plmeta );                                    /* and open a new */
 
1009
   }
 
1010
 
 
1011
if ( amode > 0 )
 
1012
   { if ( amode == 3 || amode == 4 )
 
1013
        PCKRDR( "CLPL", 4, &actvals, clpl );
 
1014
     else
 
1015
        { if ( ! newdev )
 
1016
             { PCKWRR( "SCALES", 0, &rdef );
 
1017
               PCKWRR( "OFFSET", 0, &rdef );
 
1018
             }          
 
1019
          (void) SCKGETC( "ACTION", 1, 4, &iac, action );
 
1020
          if ( strncmp( action, "DISP", 4 ) == 0 )
 
1021
             DISCLP( clpl );
 
1022
          else
 
1023
             GRPCLP( *plmode, device, clpl );
 
1024
        }
 
1025
     ocount += 1;
 
1026
     PCKWRR( "OCOUNT", 1, &ocount );
 
1027
   }
 
1028
else
 
1029
   PCKRDR( "CLPL", 4, &actvals, clpl );
 
1030
 
 
1031
AG_CDEF( clpl[0], clpl[1], clpl[2], clpl[3] );
 
1032
 
 
1033
if ( amode == 1 || amode == 5 )
 
1034
   { PCKRDI( "BCOLOR", 1, &actvals, &bcolor );
 
1035
     (void) sprintf( text, "back=%1d", bcolor );
 
1036
     AG_SSET( text );
 
1037
   }
 
1038
PCSET();
 
1039
 
 
1040
return;
 
1041
}
 
1042
 
 
1043
/*
 
1044
 
 
1045
*/
 
1046
 
 
1047
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
1048
.IDENTifer   PCCLOS
 
1049
.PURPOSE     Close plot file, and terminate graphic operations
 
1050
------------------------------------------------------------*/
 
1051
void PCCLOS()
 
1052
{
 
1053
/*
 
1054
 * terminate orderly the AGL operations
 
1055
 */
 
1056
AG_CLS();
 
1057
 
 
1058
return;
 
1059
}
 
1060