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

« back to all changes in this revision

Viewing changes to prim/display/src/coord.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) 19994-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
.IDENTIFIER  COORD
 
30
.LANGUAGE    C
 
31
.AUTHOR      K. Banse                   IPG-ESO Garching
 
32
.KEYWORDS    ImageDisplay, cursor
 
33
.PURPOSE     Read the position of the two cursors on the ImageDisplay
 
34
             and get density of relevant pixel.
 
35
             Store xworld, yworld + intensity of cursor in descriptor 
 
36
             or table or not at all
 
37
.ALGORITHM   Use enabled cursor(s) and read screen pixels, get real pixels 
 
38
             and world coord when the ENTER button is pressed on the cursor 
 
39
             board. Exit by pressing ENTER with enabled cursor(s) off.
 
40
             Max. no. of coords is read from CURSOR(1), if this maximum is 
 
41
             reached, we exit automatically!
 
42
             The real pixels, world coordinates + intensity are written to 
 
43
             key OUTPUTR(10,...)
 
44
             Total no. of coords. read is stored in OUTPUTI(1).
 
45
             Screen pixels are written to CURSOR(1,...4) within CURPOS.
 
46
.INPUT/OUTPUT
 
47
  the following keywords are used:
 
48
 
 
49
  DAZHOLD/I/1/14        cursor(s) enabled, cursor form(s),
 
50
                        split screen mode + other info
 
51
  P1/C/1/15             OR optional descriptor name where world coordinates
 
52
                          + pixel values should be stored
 
53
                        OR table name, if data should go to a table
 
54
                        OR ?, if data only to be displayed on terminal
 
55
  P2/C/1/2              = A or ?, for appending values to descriptor
 
56
                          or table or creating new descriptor/table
 
57
                        = ID for using identifiers in tables
 
58
                        = NO[,start_no]  for automatic numbering in tables
 
59
                          start_no an optional starting number
 
60
  P3/C/1/3              mark flag,
 
61
                        (1:1) = Y for putting cross on screen, else no
 
62
                                in case of P2 = ID or NO
 
63
                        (2:2) = Y for writing also the identifier into
 
64
                                the overlay channel
 
65
                        (3:3) = Y or Z for on-demand or continuous polling
 
66
 
 
67
  INPUTI/I/15/1         holds zoom factor, if we work with zoom window
 
68
  OUTPUTR/R/10/10       gets real pix, wld coords + intens for each cursor
 
69
  OUTPUTI/I/1/1         receives total no. of coordinates obtained
 
70
  CURSOR/I/1/4          (1) holds max. no. of coords reading on input
 
71
                        (1,,,4) will be filled with last cursor pos. 
 
72
 
 
73
.ENVIRONment MIDAS and IDI
 
74
             #include <midas_def.h>   Prototypes for MIDAS interfaces
 
75
             #include <idinumd.h>     Global variables for DISPLAY interfaces
 
76
 
 
77
.VERSIONS    1.00       940615  F77 -> C of COORD.FOR,    RvH
 
78
 
 
79
 090709         last modif
 
80
------------------------------------------------------------*/
 
81
 
 
82
/* Define _POSIX_SOURCE to indicate that this is a POSIX program */
 
83
 
 
84
#define  _POSIX_SOURCE 1
 
85
 
 
86
#include <stdio.h>
 
87
#include <midas_def.h>
 
88
#include <idinumd.h>
 
89
#include <proto_II.h>
 
90
 
 
91
#ifndef TRUE
 
92
#define TRUE            1
 
93
#define FALSE           0
 
94
#endif
 
95
 
 
96
#define JUST_OUTPUT     0
 
97
#define TBL_OUTPUT      1
 
98
#define DES_OUTPUT      2
 
99
 
 
100
#define INIT             1
 
101
#define WORK             0
 
102
#define CLOSE           -1
 
103
 
 
104
 
 
105
static int  imno;
 
106
static int  ra_flag, tra_flag, cooco[2];
 
107
 
 
108
static char  inframe[64];
 
109
static char infofile[] = "/tmp/get_cur.info";
 
110
 
 
111
extern int  logview_init(), display_it(), WR_SCREEN();
 
112
 
 
113
/*
 
114
 
 
115
*/
 
116
 
 
117
/*++++++++++++++++++++++++++++++
 
118
.PURPOSE  write cursor output in to descriptor
 
119
------------------------------*/
 
120
 
 
121
#ifdef __STDC__
 
122
      static void WR_DESCR(int *flag, char *frame, char *descr, int ncurs,
 
123
                            int circfl, float *xyinfoA, float *xyinfoB )
 
124
#else
 
125
      static void WR_DESCR(flag,frame,descr,ncurs,circfl,xyinfoA,xyinfoB)
 
126
      char  *frame, *descr;
 
127
      int   *flag, ncurs, circfl;
 
128
      float *xyinfoA, *xyinfoB;
 
129
#endif
 
130
 
 
131
{
 
132
register int ii;
 
133
 
 
134
int  actvals;
 
135
int  unit = 0;
 
136
 
 
137
char output[2];
 
138
 
 
139
 
 
140
/* saved variables */
 
141
 
 
142
static int   mxrec = 10,
 
143
             felem, fid, indx, ncols, norec;
 
144
static float rbuff[60];                    /* max. 2 * 3 * mxrec data points */
 
145
 
 
146
 
 
147
if (*flag == INIT)
 
148
   { 
 
149
   indx = norec = 0;
 
150
   *flag = WORK;
 
151
 
 
152
   if ( ncurs == 2 )
 
153
      {
 
154
      if ( circfl )                                /* circle */
 
155
         {
 
156
         ncols = 4;
 
157
         if ( xyinfoB[3] > 0.0 ) ncols ++;              /* also Radius2 */
 
158
         if ( xyinfoB[4] > 0.0 ) ncols ++;              /* also Radius3 */
 
159
         }
 
160
      else
 
161
         ncols = 6;
 
162
      }
 
163
   else
 
164
      ncols = 3;
 
165
         
 
166
   (void) SCKGETC( "P2", 1, 1, &actvals, output );   /* get output_option */
 
167
   if ((*output == 'a') || (*output ==  'A'))
 
168
      felem = -1;                               /* append the data */
 
169
   else
 
170
      felem = 1;
 
171
 
 
172
 
 
173
   /* open frame to write in descriptor */
 
174
 
 
175
   (void) SCFOPN( frame, D_R4_FORMAT, 0, F_IMA_TYPE, &fid );
 
176
   }
 
177
 
 
178
 
 
179
/*  Do the actual writing into the descriptor */
 
180
 
 
181
if ( *flag == WORK )
 
182
   {
 
183
   for (ii=0; ii<3; ii++) rbuff[indx++] = xyinfoA[ii+4];
 
184
   if ( ncurs == 2 ) 
 
185
      {
 
186
      if (circfl)
 
187
         {
 
188
         rbuff[indx++] = xyinfoB[2];
 
189
         if (ncols >= 5) rbuff[indx++] = xyinfoB[3];
 
190
         if (ncols >= 6) rbuff[indx++] = xyinfoB[4];
 
191
         }
 
192
      else
 
193
         {
 
194
         for (ii=0; ii<3; ii++) rbuff[indx++] = xyinfoB[ii+4];
 
195
         }
 
196
      }
 
197
 
 
198
   if ( ++norec == mxrec )                /* we buffer the output */
 
199
      {
 
200
      (void) SCDWRR(fid,descr,rbuff,felem,(ncols*norec),&unit);
 
201
      felem = -1;
 
202
      indx = norec = 0;
 
203
      }
 
204
   }
 
205
 
 
206
if ( *flag == CLOSE )
 
207
   {
 
208
   if (norec > 0)     
 
209
      (void) SCDWRR(fid,descr,rbuff,felem,(ncols*norec),&unit);
 
210
   (void) SCFCLO( fid );
 
211
   }
 
212
}
 
213
/*
 
214
 
 
215
*/
 
216
 
 
217
/*++++++++++++++++++++++++++++++
 
218
.PURPOSE  write cursor output in to table
 
219
------------------------------*/
 
220
 
 
221
 
 
222
#ifdef __STDC__
 
223
      static void WR_TABLE( int *flag, char *table, int ncurs, int circfl,
 
224
                            float *xyinfoA, float *xyinfoB, char *labl )
 
225
#else
 
226
      static void WR_TABLE( flag, table, ncurs, circfl, 
 
227
                            xyinfoA, xyinfoB, labl )
 
228
      char  *table, *labl;
 
229
      int   *flag, ncurs, circfl;
 
230
      float *xyinfoA, *xyinfoB;
 
231
#endif
 
232
 
 
233
{
 
234
register int ii;
 
235
int    actvals, idum, tindx, m, begin, unit;
 
236
static int  dim3_plane;
 
237
 
 
238
float  rdum, rbuff[10];
 
239
static float  zplane;
 
240
 
 
241
double   ddum;
 
242
 
 
243
char   idstr[10], buff[24], cbuf[3][24], tbunit[20], output[84];
 
244
 
 
245
 
 
246
/* initialized variables */
 
247
 
 
248
static char *info_iden = "enter identifier (with cursor in display window!): ";
 
249
static char *tblabl[3][10] = 
 
250
   { {"X_coord","Y_coord","Value","X_coordpix","Y_coordpix"," "," "," "," "},
 
251
     {"Xstart","Ystart","Value1","Xend","Yend","Value2",
 
252
      "Xstartpix","Ystartpix","Xendpix","Yendpix"},
 
253
     {"X_coord","Y_coord","Value","Radius1","Radius2","Radius3",
 
254
      "X_coordpix","Y_coordpix"," "," "} };
 
255
static char *zlabl[2] = {"Z_coord","Z_coordpix"};
 
256
 
 
257
char tlabel[10][20];
 
258
 
 
259
static int  col_id, col_nr, ap_flag = -1, no_flag = -1, id_flag = -1,
 
260
            tid, ncols, nooff, napp, nrow, colref[10];
 
261
static char oldstr[10];
 
262
 
 
263
 
 
264
 
 
265
if ( *flag == INIT )
 
266
   {
 
267
   int  naxis;
 
268
 
 
269
   *flag = WORK;
 
270
   tra_flag = 0;
 
271
   
 
272
   if ( ncurs == 2 )                        /* 3,6 columns for 1,2 cursors */
 
273
      {
 
274
      if ( circfl )                                /* circle */
 
275
         {
 
276
         ncols = 6;
 
277
         tindx = 2;
 
278
         for (ii=0; ii<4; ii++)
 
279
            (void) strcpy(&tlabel[ii][0],tblabl[tindx][ii]);
 
280
         idum = 4;
 
281
         if ( xyinfoB[3] > 0.0 ) 
 
282
            {
 
283
            ncols ++;                           /* also Radius2 */
 
284
            (void) strcpy(&tlabel[idum++][0],tblabl[tindx][4]);
 
285
            }
 
286
         if ( xyinfoB[4] > 0.0 ) 
 
287
            {
 
288
            ncols ++;                           /* also Radius3 */
 
289
            (void) strcpy(&tlabel[idum++][0],tblabl[tindx][5]);
 
290
            }
 
291
         (void) strcpy(&tlabel[idum++][0],tblabl[tindx][6]);
 
292
         (void) strcpy(&tlabel[idum][0],tblabl[tindx][7]);
 
293
         }
 
294
      else                                         /* rectangle */
 
295
         {
 
296
         ncols = 10;
 
297
         tindx = 1;
 
298
         for (ii=0; ii<ncols; ii++)
 
299
            (void) strcpy(&tlabel[ii][0],tblabl[tindx][ii]);
 
300
         }
 
301
      }
 
302
   else                                              /* single cursor */
 
303
      {
 
304
      ncols = 5;
 
305
      tindx = 0;
 
306
 
 
307
      for (ii=0; ii<ncols; ii++)
 
308
         (void) strcpy(&tlabel[ii][0],tblabl[tindx][ii]);
 
309
      }
 
310
 
 
311
   if ((ra_flag == 1) && (tindx != 1))          /* not for rectangle yet... */
 
312
      {
 
313
      (void) strcpy(tlabel[0],"RA ");
 
314
      (void) strcpy(tlabel[1],"DEC ");
 
315
      tra_flag = 1;
 
316
      }
 
317
 
 
318
 
 
319
   /* Get character string with flags for "A"ppend, "ID"entifier or "NO" */
 
320
 
 
321
   (void) SCKGETC("P2",1,12,&actvals,output);   /* get output_option */
 
322
   CGN_UPSTR(output);
 
323
 
 
324
 
 
325
   /* either create new table or append values to existing one */
 
326
 
 
327
   begin = 0;
 
328
   m = (int) strlen(output);
 
329
   for (ii=0; ii<3; ii++)
 
330
      {
 
331
      cbuf[ii][0] = '\0';
 
332
      idum = CGN_EXTRSS(output,m,'+',&begin,&cbuf[ii][0],20);
 
333
      if (cbuf[ii][0] == 'A') ap_flag = 1;
 
334
      if (cbuf[ii][0] == 'I') id_flag = 1;
 
335
      if (cbuf[ii][0] == 'N') no_flag = ii;
 
336
      }
 
337
 
 
338
 
 
339
   (void) SCDRDI(imno,"NAXIS",1,1,&actvals,&naxis,&unit,&m);
 
340
   if (naxis > 2)               /* test, if a cube is loaded */
 
341
      {
 
342
      dim3_plane = ZPLANE;                      /* frame z-pixel */
 
343
      (void) SCDRDD(imno,"START",3,1,&actvals,&ddum,&unit,&m);
 
344
      zplane = (float)ddum;
 
345
      (void) SCDRDD(imno,"STEP",3,1,&actvals,&ddum,&unit,&m);
 
346
      rdum = (float)ddum;
 
347
      zplane += (dim3_plane-1) * rdum;  /* world coords */
 
348
      }
 
349
   else
 
350
      dim3_plane = 0;
 
351
 
 
352
 
 
353
   if (ap_flag == -1)           /* create new table */
 
354
      {
 
355
 
 
356
      /* create a (ncols+10)*100 table to have enough space for later use */
 
357
 
 
358
      (void) TCTINI(table,F_TRANS,F_O_MODE,ncols+10,100,&tid);
 
359
      for (ii=0; ii<ncols; ii++)
 
360
         {
 
361
         (void) strcpy(buff,&tlabel[ii][0]);
 
362
         if (CGN_INDEXS(buff,"Rad") > 0)
 
363
            (void) strcpy(tbunit,"Pixels");
 
364
         else if (*buff == 'V')     
 
365
            (void) strcpy(tbunit," ");
 
366
         else 
 
367
            {
 
368
            if (CGN_INDEXS(buff,"pix") > 0)
 
369
               (void) strcpy(tbunit,"Frame Pixels");
 
370
            else
 
371
               (void) strcpy(tbunit,"World Coords");
 
372
            }
 
373
         if (tra_flag == 1)             /* single cursor */
 
374
            {
 
375
            if (ii == 0)
 
376
               (void) TCCINI(tid,D_R4_FORMAT,1,"S11.6",tbunit,buff,colref+ii);
 
377
            else if (ii == 1)
 
378
               (void) TCCINI(tid,D_R4_FORMAT,1,"S13.6",tbunit,buff,colref+ii);
 
379
            else
 
380
               (void) TCCINI(tid,D_R4_FORMAT,1,"G12.6",tbunit,buff,colref+ii);
 
381
            }
 
382
         else
 
383
            (void) TCCINI(tid,D_R4_FORMAT,1,"G12.6",tbunit,buff,colref+ii);
 
384
         } 
 
385
 
 
386
      if (dim3_plane != 0)
 
387
         {
 
388
         (void) TCCINI(tid,D_R4_FORMAT,1,"G12.6","World Coords","Z_coord",
 
389
                       colref+ncols);
 
390
         (void) TCCINI(tid,D_R4_FORMAT,1,"G12.6","Frame Pixels","Z_coordpix",
 
391
                       colref+ncols+1);
 
392
         }
 
393
 
 
394
      if (no_flag != -1)                /* handle optional number column */
 
395
         {
 
396
         nooff = 0;
 
397
         (void) TCCINI(tid,D_I4_FORMAT,1,"I8"," ","No",&col_nr);
 
398
         idum = CGN_INDEXC(&cbuf[no_flag][0],',');
 
399
         if ( idum > 0)
 
400
            {
 
401
            actvals = CGN_CNVT(&cbuf[no_flag][idum+1],1,1,&nooff,&rdum,&ddum);
 
402
            if ( actvals <= 0 ) nooff = 0;
 
403
            }
 
404
         if (id_flag != -1)             /* ID + NO is not possible */
 
405
            SCTPUT("ID and NO flag not o.k. - only NO: column supported.");
 
406
         }
 
407
      else
 
408
         (void) TCCINI(tid,D_C_FORMAT,8,"a8"," ","Ident",&col_id);
 
409
      
 
410
      nrow = 0;
 
411
      }
 
412
 
 
413
 
 
414
 
 
415
   else         /* open existing table and search for the required columns */
 
416
      {
 
417
      (void) TCTOPN( table, F_IO_MODE, &tid );
 
418
      for (ii=0; ii<ncols; ii++)
 
419
         {
 
420
         (void) strcpy(buff,&tlabel[ii][0]);
 
421
         (void) TCLSER(tid,buff,colref+ii);
 
422
         if (colref[ii] <= 0)
 
423
            {
 
424
            sprintf(output,
 
425
            "Missing column (label = %s) in input table, will be created...",
 
426
            buff);
 
427
            SCTPUT(output);
 
428
            if (*buff == 'R')
 
429
               (void) strcpy(tbunit,"Pixels ");
 
430
            else if (*buff == 'V')
 
431
               (void) strcpy(tbunit," ");
 
432
            else 
 
433
               {
 
434
               if (CGN_INDEXS(buff,"pix") > 0)
 
435
                  (void) strcpy(tbunit,"Frame Pixels");
 
436
               else
 
437
                  (void) strcpy(tbunit,"World Coords");
 
438
               }
 
439
            (void) TCCINI(tid,D_R4_FORMAT,1,"G12.6",tbunit,buff,colref+ii);
 
440
            }
 
441
         }
 
442
 
 
443
      if (dim3_plane != 0)
 
444
         {
 
445
         ii = ncols;
 
446
         (void) TCLSER(tid,zlabl[0],colref+ii);
 
447
         if (colref[ii] <= 0)
 
448
            (void) TCCINI(tid,D_R4_FORMAT,1,"G12.6","World Coords","Z_coord",
 
449
                          colref+ii);
 
450
         ii ++;
 
451
         (void) TCLSER(tid,zlabl[1],colref+ii);
 
452
         if (colref[ii] <= 0)
 
453
            (void) TCCINI(tid,D_R4_FORMAT,1,"G12.6","Frame Pixels",
 
454
                         "Z_coordpix",colref+ii);
 
455
         }
 
456
 
 
457
      if (no_flag != -1)                /* handle optional number column */
 
458
         {
 
459
         (void) TCLSER(tid,"No",&col_nr);
 
460
         if (col_nr <= 0)
 
461
            (void) TCCINI(tid,D_I4_FORMAT,1,"I8"," ","No",&col_nr);
 
462
         nooff = 0;
 
463
         idum = CGN_INDEXC(&cbuf[no_flag][0],',');
 
464
         if ( idum > 0)
 
465
            {
 
466
            actvals = CGN_CNVT(&cbuf[no_flag][idum+1],1,1,&nooff,&rdum,&ddum);
 
467
            if ( actvals <= 0 ) nooff = 0;
 
468
            }
 
469
         if (id_flag != -1)             /* ID + NO is not possible */
 
470
            SCTPUT("ID and NO flag not o.k. - only NO: column supported.");
 
471
         }
 
472
      else
 
473
         {
 
474
         (void) TCLSER(tid,"Ident",&col_id);
 
475
         if (col_id <= 0)
 
476
            (void) TCCINI(tid,D_C_FORMAT,8,"a8"," ","Ident",&col_id);
 
477
         }
 
478
 
 
479
      /* We append after the last row in the table */
 
480
 
 
481
      (void) TCIGET( tid, &idum, &nrow, &idum, &idum, &idum );
 
482
      }
 
483
 
 
484
   napp = nrow;
 
485
   }
 
486
 
 
487
 
 
488
/* Do the actual writing in the table */
 
489
 
 
490
if ( *flag == WORK )
 
491
   {
 
492
   nrow++;                                           /* write in a new row */
 
493
   for (ii=0; ii<3; ii++)
 
494
      rbuff[ii] = *(xyinfoA+4+ii);
 
495
   if (tra_flag == 1) rbuff[0] /= 15.0;
 
496
 
 
497
   if (ncurs == 0)
 
498
      {
 
499
      rbuff[3] = *(xyinfoA+2);
 
500
      rbuff[4] = *(xyinfoA+3);
 
501
      (void) TCRWRR(tid,nrow,5,colref,rbuff);
 
502
      }
 
503
   else
 
504
      {
 
505
      if ( circfl )                                /* circle */
 
506
         {
 
507
         rbuff[3] = *(xyinfoB+2);
 
508
         if (ncols >= 7)
 
509
            rbuff[4] = *(xyinfoB+3);
 
510
         if (ncols >= 8)
 
511
            rbuff[5] = *(xyinfoB+4);
 
512
           
 
513
         rbuff[ncols-2] = *(xyinfoA+2);
 
514
         rbuff[ncols-1] = *(xyinfoA+3);
 
515
         (void) TCRWRR(tid,nrow,ncols,colref,rbuff);
 
516
         }
 
517
      else
 
518
         {
 
519
         for (ii=0; ii<3; ii++)
 
520
            rbuff[3+ii] = *(xyinfoB+4+ii);
 
521
         rbuff[6] = *(xyinfoA+2);
 
522
         rbuff[7] = *(xyinfoA+3);
 
523
         rbuff[8] = *(xyinfoB+2);
 
524
         rbuff[9] = *(xyinfoB+3);
 
525
         (void) TCRWRR(tid,nrow,10,colref,rbuff);
 
526
         }
 
527
      }
 
528
 
 
529
   if (dim3_plane != 0)
 
530
      {
 
531
      rbuff[0] = zplane;
 
532
      rbuff[1] = (float) dim3_plane;
 
533
      (void) TCRWRR(tid,nrow,2,colref+ncols,rbuff);
 
534
      }
 
535
 
 
536
   /* handle optional number and ident column */
 
537
 
 
538
   if (no_flag != -1)
 
539
      {
 
540
      idum = ++nooff;
 
541
      (void) TCRWRI(tid,nrow,1,&col_nr,&idum);
 
542
      (void) sprintf(labl,"%-d",idum);
 
543
      }
 
544
   else
 
545
      {
 
546
      if (id_flag != -1) 
 
547
         {
 
548
         SCTDIS(info_iden,-1);
 
549
         actvals = 8;                          /* max. number of characters */
 
550
         Cgetstr(idstr,&actvals);
 
551
         if ( actvals < 1 ) 
 
552
            (void) strcpy(idstr,oldstr);
 
553
         else
 
554
            (void) strcpy(oldstr,idstr);
 
555
         SCTDIS(buff,-9);
 
556
         }
 
557
      else
 
558
         {
 
559
         idum = napp + cooco[1];
 
560
         sprintf(idstr,"ID%4.4d",idum);
 
561
         }
 
562
      (void) TCEWRC(tid,nrow,col_id,idstr);
 
563
      (void) strcpy( labl, idstr ); 
 
564
      }
 
565
 
 
566
   }
 
567
 
 
568
 
 
569
if (*flag == CLOSE)
 
570
   {
 
571
   (void) sprintf(output,"Created via GET/CURSOR with image: %s",inframe);
 
572
   (void) SCDWRC(tid,"HISTORY",1,output,-1,80,&unit);
 
573
   (void) TCTCLO(tid);
 
574
   }
 
575
}
 
576
 
 
577
/*
 
578
 
 
579
*/
 
580
 
 
581
int main()
 
582
 
 
583
{
 
584
int   actvals, circfl, color, coomax, forma, give_info, go_on, knul, noc, 
 
585
      statA, statB, trncur, usr_lev, xpos, ypos, zoomwn;
 
586
int   store, dazhld[2], ibuff[5];
 
587
register int  nr;
 
588
static int  coords[4] = { -1, -1, -1, -1 };    /* initial position of cursor */
 
589
 
 
590
float xyinfoA[7], xyinfoB[7];
 
591
 
 
592
char  draw[4], cursfl[8], labl[9], cbuff[61], outname[61], output[81];
 
593
char *info_usr = "switch cursor(s) on - next time we exit...";
 
594
 
 
595
int outflg = FALSE,                             /* output to standard output */
 
596
    conly  = FALSE,
 
597
    scrfl  = INIT,
 
598
    tblfl  = INIT,
 
599
    desfl  = INIT,
 
600
    unit = 0;
 
601
 
 
602
 
 
603
 
 
604
 
 
605
ra_flag = 0;
 
606
labl[0] = '\0';
 
607
for (nr=0; nr<7; nr++)
 
608
   {
 
609
   xyinfoA[nr] = xyinfoB[nr] = 0.0;
 
610
   }
 
611
 
 
612
 
 
613
/* initialize MIDAS and global display variables */
 
614
 
 
615
(void) SCSPRO("Coord");
 
616
 
 
617
 
 
618
DCOPEN(1);
 
619
CONCHA_C(QDSPNO,QOVCH,1,0);     /* Clear overlay-channel if necessary */
 
620
 
 
621
 
 
622
/* get main control block for ImageDisplay + keyword DAZHOLD */
 
623
 
 
624
(void) SCKRDI( "DAZHOLD", 1, 2, &actvals, dazhld, &unit, &knul );
 
625
forma = dazhld[1];
 
626
circfl = FALSE;  
 
627
 
 
628
 
 
629
/* get cursor(s) involved */
 
630
 
 
631
(void) SCKRDI( "CURSOR", 1, 2, &actvals, ibuff, &unit, &knul );
 
632
noc = ibuff[1];
 
633
if (noc == 2) 
 
634
   {
 
635
   if (dazhld[0] != 2)          /* if last curs shape was for single cursor */
 
636
      forma = 1;                /* we default to rectangle */
 
637
   else if (forma == 2)
 
638
      circfl = TRUE;            /* circular ROI */
 
639
   }
 
640
else
 
641
   {
 
642
   noc = 0;                     /* no support for single cursor #1 ... */
 
643
   if (dazhld[0] > 1)           /* if last curs shape was for two cursors */
 
644
      forma = 3;                /* we default to open cross */
 
645
   }
 
646
 
 
647
coomax = *ibuff;
 
648
if ( coomax < 0 )     
 
649
   {
 
650
   conly = TRUE;
 
651
   scrfl = CLOSE;                       /* No info given on standard output */
 
652
   coomax = 1;
 
653
   }
 
654
 
 
655
 
 
656
/* get marker flag for drawing cross (and identifier) */
 
657
 
 
658
(void) strcpy(cursfl,"Y Y ?C0");                /* default to NoZoomWindow */
 
659
(void) SCKGETC("P3",1,3,&actvals,draw);
 
660
CGN_UPSTR(draw);
 
661
cursfl[3] = draw[2];   
 
662
if (cursfl[3] == 'Z')               /* on-demand or continuous cursor read */
 
663
   {
 
664
   cursfl[1] = 'N';                         /* no marks in continuous mode */
 
665
   noc = 0;                                /* force to only one cursor ... */
 
666
   circfl = FALSE;                                   /* rectangular cursor */
 
667
   coomax = 100000000;                            /* put it to 100 000 000 */
 
668
   }
 
669
else
 
670
   cursfl[1] = *draw;                 /* this is the mark flag for the cross */
 
671
 
 
672
 
 
673
/* Read keyword DAZIN, 
 
674
   it contains resp.: zoom factor and auxilary window dimensions  */
 
675
 
 
676
(void) SCKRDI("DAZIN",1,5,&actvals,ibuff,&unit,&knul);
 
677
 
 
678
if ((zoomwn = *ibuff) <= 0)                     /* no zoom window */
 
679
   trncur = noc;                      /* true cursor no. */
 
680
else                                            /* zoom window */
 
681
   {
 
682
   if ((ibuff[1] == 0) || (ibuff[2] == 0)) 
 
683
      SCETER( 31, "FATAL: invalid window_specs..." );
 
684
 
 
685
 
 
686
   /* Ok, x,y dimension auxilary window not zero */
 
687
 
 
688
   cursfl[4] = 'Z';                     /* that indicates zooming */
 
689
   if (noc == 0)     
 
690
      trncur = 0;
 
691
   else
 
692
      {
 
693
      if (! circfl)             /* pass also cursor no. of zoom window */
 
694
         cursfl[6] = '2';
 
695
      else                            /* indicate, that it's a circle... */
 
696
         cursfl[6] = '7';
 
697
      trncur = 2;
 
698
      }
 
699
   noc = 0;                       /* force to single cursor in main window */
 
700
   forma = 3;
 
701
 
 
702
 
 
703
   /* for novice users display help */
 
704
 
 
705
   (void) SCKRDI( "ERROR", 2, 1,&actvals, &usr_lev, &unit, &knul );
 
706
   }
 
707
 
 
708
/* start up parallel logviewer or `classical' terminal I/O */
 
709
 
 
710
if (zoomwn < 1)
 
711
   {
 
712
   infofile[0] = '\0';  /* no parallel display */
 
713
   (void) logview_init(infofile);
 
714
   }
 
715
else
 
716
   {
 
717
   (void) logview_init(infofile);
 
718
   if ( usr_lev == 1 ) auxhelp( 0 );
 
719
   }
 
720
 
 
721
 
 
722
/* init cursor(s) in main window */
 
723
 
 
724
if ( noc == 2 )     
 
725
   {
 
726
   color = 0;                                      /* define cursor colour */
 
727
   if ( forma == -1 ) forma = 1;
 
728
   }
 
729
else
 
730
   {
 
731
   color = 2;
 
732
   if ( forma == -1 ) forma = 3;
 
733
   }
 
734
(void) SETCUR_C(QDSPNO,noc,forma,color,coords);
 
735
 
 
736
 
 
737
/* Set output flag and name of output table or descriptor */
 
738
 
 
739
(void) SCKGETC("P1",1,60,&actvals,outname);
 
740
if (*outname == '?')
 
741
   outflg = JUST_OUTPUT;
 
742
else
 
743
   {
 
744
   int  idum;
 
745
 
 
746
   idum = CGN_INDEXS(outname,",d");
 
747
   if (idum < 0) idum = CGN_INDEXS(outname,",D");
 
748
 
 
749
   if (idum > 0)
 
750
      {
 
751
      outflg = DES_OUTPUT;
 
752
      outname[idum] = '\0';
 
753
      }
 
754
   else
 
755
      {
 
756
      outflg = TBL_OUTPUT;
 
757
      (void) strcpy(cbuff,outname);
 
758
      CGN_FRAME(cbuff,3,outname,0);
 
759
      }
 
760
   }
 
761
 
 
762
cooco[0] = 0;                           /* counter for cursor reading */
 
763
cooco[1] = 0;                           /* counter for data storing */
 
764
(void) strcpy(inframe," ");             /* necessary for calls of GetCursor */
 
765
 
 
766
 
 
767
/* read cursor position(s) */
 
768
 
 
769
give_info = go_on = TRUE;
 
770
while ((go_on) && (*cooco < coomax))
 
771
   { 
 
772
Cursor_loop:
 
773
   GetCursor(cursfl,inframe,xyinfoA,&statA,xyinfoB,&statB);
 
774
 
 
775
   if ((statA == -9) && (*cooco == 0)) 
 
776
      goto Cursor_loop;                 /* first entry & no keybd-input */
 
777
 
 
778
   if ( (trncur == 0 && statA == 0)
 
779
        || 
 
780
        (trncur == 2 && statA == 0 && statB == 0) )
 
781
      {
 
782
      if ( give_info && *cooco == 0 )
 
783
         {
 
784
         SCTDIS(output,-9);
 
785
         SCTDIS(info_usr,80);
 
786
         (void) strcpy(inframe," ");
 
787
         give_info = FALSE;
 
788
         }
 
789
      else
 
790
         {
 
791
         if (cursfl[3] != 'Z') 
 
792
            SCTDIS(" ",0);
 
793
         else
 
794
            SCTDIS(output,-9);        /* erase last line */
 
795
         go_on = FALSE;
 
796
         }
 
797
      }
 
798
 
 
799
 
 
800
   /* we got cursor input - increment counter */
 
801
 
 
802
   else
 
803
      {
 
804
      (*cooco)++;                    /* increment cursor read counter */
 
805
      if (*cooco == 1)
 
806
         {
 
807
         int  kk;
 
808
         double  dd1[3], dd2[3];
 
809
 
 
810
         (void) SCFOPN(inframe,D_OLD_FORMAT,0,F_IMA_TYPE,&imno);
 
811
         kk = fp2wc(0,imno,dd1,dd2);
 
812
         if (kk == 0) ra_flag = 1;
 
813
         }
 
814
 
 
815
        
 
816
      store = 0;
 
817
      if ((cursfl[3] != 'Z') || (statA < 0)) 
 
818
         {
 
819
         cooco[1]++;
 
820
         if (outflg != JUST_OUTPUT) store = 1;
 
821
 
 
822
 
 
823
         /* store info in keyword OUTPUTR[10,...,20] */
 
824
 
 
825
         (void) SCKWRR("OUTPUTR",xyinfoA+2,10,5,&unit);
 
826
         if (trncur == 2) (void) SCKWRR("OUTPUTR",xyinfoB+2,15,5,&unit);
 
827
 
 
828
 
 
829
         if (outflg == TBL_OUTPUT)              /* fill table */
 
830
            WR_TABLE(&tblfl,outname,trncur,circfl,xyinfoA,xyinfoB,labl);
 
831
 
 
832
 
 
833
         else if (outflg == DES_OUTPUT) /* fill descriptor */
 
834
            WR_DESCR(&desfl,inframe,outname,trncur,circfl,xyinfoA,xyinfoB);
 
835
 
 
836
 
 
837
         /* if desired, draw label or number in overlay plane */
 
838
 
 
839
         if ( draw[1] == 'Y')     
 
840
            {                        /* move one char. to the right */
 
841
            xpos = CGN_NINT( xyinfoA[0] ) + 9;
 
842
            ypos = CGN_NINT( xyinfoA[1] );
 
843
            if ( trncur == 2 ) ypos += 9;
 
844
 
 
845
            (void) IIGTXT_C(QDSPNO,QOVCH,labl,xpos,ypos,0,0,255,0);
 
846
            }
 
847
         }
 
848
 
 
849
 
 
850
      /* in all cases, display line with complete info */
 
851
 
 
852
      WR_SCREEN(&scrfl,cursfl,trncur,circfl,ra_flag,xyinfoA,xyinfoB,labl);
 
853
      if (store == 1)
 
854
         {
 
855
         labl[0] = '\0';                /* clear label + advance one line */
 
856
         }
 
857
      }
 
858
 
 
859
   }               /* end of the while-loop */
 
860
 
 
861
 
 
862
/* That's it folks...  */
 
863
 
 
864
if (cooco[1] > 0)                       /* something was entered */
 
865
   {
 
866
   if ( outflg == TBL_OUTPUT )     
 
867
      {
 
868
      tblfl = CLOSE;
 
869
      WR_TABLE(&tblfl,outname,trncur,circfl,xyinfoA,xyinfoB,labl);
 
870
      }
 
871
   else if (outflg == DES_OUTPUT)
 
872
      {
 
873
      desfl = CLOSE;
 
874
      WR_DESCR(&desfl,inframe,outname,trncur,circfl,xyinfoA,xyinfoB);
 
875
      }
 
876
 
 
877
   ibuff[0] = CGN_NINT(xyinfoA[0]);
 
878
   ibuff[1] = CGN_NINT(xyinfoA[1]);
 
879
   ibuff[2] = CGN_NINT(xyinfoB[0]);
 
880
   ibuff[3] = CGN_NINT(xyinfoB[1]);
 
881
   }
 
882
 
 
883
else if (conly)                 /* if Cursor only, get coords any way */
 
884
   (void) IICRCP_C(QDSPNO,-1,noc,ibuff,ibuff+1,ibuff+2);
 
885
 
 
886
 
 
887
(void) SCKWRI("CURSOR",ibuff,1,4,&unit);
 
888
 
 
889
 
 
890
/* Save no. of coordinates obtained for subsequent applications */
 
891
 
 
892
(void) SCKWRI("OUTPUTI",cooco+1,1,1,&unit);
 
893
      
 
894
if ( zoomwn > 0 )                          /* reset cursor setup */
 
895
   SETCUR_C(QDSPNO,trncur,dazhld[1],2,coords);
 
896
 
 
897
DCCLOS(QDSPNO);
 
898
(void) display_it("EOF",0);
 
899
 
 
900
if ( cursfl[1] == 'Y') (void) Crefrovr();                 /* refresh overlay */
 
901
return SCSEPI();
 
902
}