1
/*===========================================================================
2
Copyright (C) 1995-2009 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
===========================================================================*/
28
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
29
.COPYRIGHT: Copyright (c) 1994 European Southern Observatory,
33
.AUTHOR K. Banse IPG-ESO Garching
34
.KEYWORDS ImageDisplay
35
.PURPOSE load an image into image display
39
call as DCLOAD(imno,name,dattyp,icent,cuts,scale,chan_flag)
42
int imno : image no. of input image
43
char *name : name of the image
44
int dattyp : data type (as D_xx_FORMAT)
45
int icen[4] : fixpoint: screen pixels + frame pixels
46
float cuts[2] : low + high cut in z-dir.
47
int scale[3] : scaling factors for image in x,y
48
[0,1] if > 1: make image smaller
49
if < 1: make image larger
50
[2] flag for using max (= 3), using min (= 2),
51
for averaging (= 1) or not (= 0)
53
int chan_flag : = 0, load into QIMCH
54
= 1, load into QIMCH and following channels
55
only applicable to 3dim image loading
59
.COMMENT uses MIDAS keywords: MID$DISP, MID$SPEC & SIZIN
61
#include <midas_def.h> Prototypes for MIDAS interfaces
62
#include <idinumd.h> Global variables for DISPLAY interfaces
64
.VERSIONS 1.00 940413 from LODIMA.FOR RvH
67
------------------------------------------------------------*/
69
/* Define _POSIX_SOURCE to indicate that this is a POSIX program */
71
#define _POSIX_SOURCE 1
73
#include <midas_def.h>
86
#define DEFMEMSIZE 512
88
#define MYMIN(a,b) ((a) > (b) ? (b) : (a))
89
#define MYMAX(a,b) ((b) > (a) ? (b) : (a))
95
void DCLOAD(imno,name,dattyp,icent,cuts,scale,chan_flag)
97
int imno, dattyp, *icent, *scale, chan_flag;
104
int actvals, dsplfl, flag, idum, kcount;
105
int knul, offs, size, splmod, unit, dazhld[11], khelp[15], mapsiz[2];
106
int stat, qsize[2], npix[3], splcx[4][5], splcy[4][5];
108
int idiserver; /* = 1, do it in the IDIserver directly;
109
= 0, send data via IDI interfaces */
111
double ddum, step[3], start[3];
113
char outfra[120], cbuff[24], ourname[120];
121
for (nr=0; nr<15; nr++) khelp[nr] = 0;
123
nr = CGN_INDEXC(name,']'); /* look for name[...] first */
126
if (name[nr+1] == ',')
132
idum = CGN_INDEXC(name,','); /* look for name,f_plane,l_plane */
134
(void) SCDRDI(imno,"NAXIS",1,1,&actvals,&naxis,&unit,&knul);
135
if (naxis > 3) naxis = 3; /* limit to 3-dims */
139
(void) strncpy(ourname,name,idum); /* copy only name */
140
ourname[idum] = '\0';
143
SCTPUT("2-dim image, no plane_specs should be given...");
146
(void) strcpy(outfra,&name[idum+1]);
147
if ((outfra[0] == 'a') || (outfra[0] == 'A'))
151
nr = CGN_INDEXC(outfra,','); /* image,all,delay_time */
155
stat = CGN_CNVT(&outfra[nr],1,1,&khelp[13],cuts,&ddum);
160
nr = CGN_INDEXS(outfra,"..");
166
stat = CGN_CNVT(outfra,1,3,&khelp[11],cuts,&ddum);
169
(void) sprintf(outfra,
170
"invalid plane no.s (= %s) ...",&name[idum+1]);
174
khelp[12] = khelp[11]; /* single plane */
180
(void) strcpy(ourname,name);
185
SCTPUT ("1. plane of image cube will be loaded...");
190
/* get descriptors of input frame */
192
for (nr=0; nr<3; nr++)
199
(void) SCDRDI(imno,"NPIX",1,naxis,&actvals,npix,&unit,&knul);
200
(void) SCDRDD(imno,"START",1,naxis,&actvals,start,&unit,&knul);
201
(void) SCDRDD(imno,"STEP",1,naxis,&actvals,step,&unit,&knul);
202
size = *npix * npix[1];
206
if ( (khelp[11] == -1) || (khelp[11] > npix[2]) )
208
else if (khelp[11] < 1)
210
if ( (khelp[12] == -1) || (khelp[12] > npix[2]) )
212
else if (khelp[12] < 1)
217
else /* only allow as many planes as channels */
218
{ /* from QIMCH on exist */
221
kcount = QLSTCH - QIMCH; /* no of available channels */
222
nr = kcount + (khelp[11] - 1); /* last possible plane to load */
223
if (khelp[12] > nr) khelp[12] = nr;
228
/* test, if we should load into a frame */
230
(void) SCKGETC("MID$DISP",1,22,&actvals,cbuff);
231
if ((*cbuff != 'I') && (*cbuff != 'i'))
233
(void) strcpy(outfra,cbuff+2);
234
if ((*cbuff != 'F') && (*cbuff != 'f'))
237
(void) SCKGETC("MID$SESS",11,2,&actvals,cbuff);
238
(void) strcpy(&cbuff[2],".ima");
239
(void) strcat(outfra,cbuff);
240
(void) SCKWRC("IN_B",1,outfra,1,30,&unit); /* save name... */
241
(void) SCKRDI("IDIDEV",49,2,&actvals,qsize,&unit,&knul);
242
if (qsize[0] <= 0) qsize[0] = DEFMEMSIZE;
243
if (qsize[1] <= 0) qsize[1] = DEFMEMSIZE;
248
qsize[0] = npix[0] * (-scale[0]);
249
else if (scale[0] > 1)
250
qsize[0] = npix[0] / scale[0];
254
qsize[1] = npix[1] * (-scale[1]);
255
else if (scale[1] > 1)
256
qsize[1] = npix[1] / scale[1];
266
/* determine map buffer space, and start to fill array KHELP */
269
(void) SCKRDI("SIZIN",1,2,&actvals,mapsiz,&unit,&knul);
270
if (*mapsiz < *npix) /* for image with long lines... */
276
khelp[1] = MYMIN( *mapsiz, size );
277
khelp[2] = mapsiz[1];
280
/* no. of lines needed to average (work on) */
283
khelp[1] = MYMAX( khelp[1],*npix * scale[1]);
286
/* determine size of "display_frame" + load the image into it */
290
int outno, kcen[2], mpix[2];
296
kcen[0] = icent[0]; /* determine size of output frame */
298
kcen[1] = qsize[0]/2;
301
SIZER_C(qsize[0],npix[0],scale[0],scale[2],kcen,
302
dazhld,dazhld+1,dazhld+2,dazhld+3);
305
kcen[1] = qsize[1]/2;
308
SIZER_C(qsize[1],npix[1],scale[1],scale[2],kcen,
309
dazhld+5,dazhld+6,dazhld+7,dazhld+8);
313
size = mpix[0] * mpix[1];
315
(void) SCFCRE(outfra,D_I1_FORMAT,F_O_MODE,F_IMA_TYPE,size,&outno);
317
idum = 2; /* will be 2-dim frame */
318
(void) SCDWRI(outno,"NAXIS",&idum,1,1,&unit);
319
(void) SCDWRI(outno,"NPIX",mpix,1,idum,&unit);
320
(void) SCDWRD(outno,"STEP",step,1,idum,&unit);
323
/* get original identifier */
325
memset((void *)cunit,32,(size_t)72);
326
(void) strncpy(cunit,"hardcopy of frame ",18);
327
(void) SCDWRC(outno,"IDENT",1,cunit,1,72,&unit);
328
(void) strcpy(cunit,"screen pixels ");
329
(void) strcpy(cunit+16, "screen pixels ");
330
(void) strcpy(cunit+32, "screen intens. ");
331
(void) SCDWRC(outno,"CUNIT",1,cunit,1,48, &unit);
332
(void) SCDWRC(outno,"ROOT_FRAME",1,ourname,1,60,&unit);
333
(void) SCDWRR(outno,"ROOT_CUTS",cuts,1,2,&unit);
336
/* Write a 2-dimensional image into a frame serving as Virtual Display */
338
WIMGB_C(imno,khelp,npix,cuts,scale,outno,dazhld);
340
ocuts[0] = ocuts[2] = 0.;
341
ocuts[1] = ocuts[3] = 255.; /* try highest value */
342
(void) SCDWRR(outno,"LHCUTS",ocuts,1,4,&unit);
345
/* new start & end values for the X-axis */
347
*start += (dazhld[3]-1) * (*step); /* start values */
349
offs = *mpix / (- (*scale)) - 1;
352
if ( scale[2] == 0 ) /* no averaging */
353
offs = (*mpix-1) * (*scale);
355
offs = ((*mpix) * (*scale)) - 1;
357
*end = (*start) + (offs * (*step)); /* end value */
360
/* new start + end values for the Y-axis */
362
start[1] += (dazhld[8] - 1) * step[1];
364
offs = mpix[1]/ (- scale[1]) - 1;
367
if ( scale[2] == 0 ) /* no averaging */
368
offs = (mpix[1] - 1) * scale[1];
370
offs = mpix[1] * scale[1] - 1;
372
end[1] = (start[1] + offs) * step[1]; /* end value */
374
(void) SCDWRD(outno,"START",start,1,2,&unit);
375
(void) SCDWRD(outno,"END",end,1,2,&unit);
376
} /* The job is done!! */
381
We are really going to load into a display.
382
Get split mode + addresses + memories per pixel as well as "active" channel
389
(void) SCKRDI("DAZHOLD",1,11,&actvals,dazhld,&unit,&knul);
391
if (icent[2] == -1) icent[2] = QMSZX/2;
392
if (icent[3] == -1) icent[3] = QMSZY/2;
395
SPLCNT_C( splcx, splcy ); /* calculate split addresses */
398
for (nr=0; nr<4; nr++)
400
for (mr=0; mr<5; mr++)
407
SCETER(6,"DCLOAD: no image loading into overlay possible in X11");
413
{ /* check for compressed files */
417
idum = (int) strlen(ourname) - 1;
418
if ((ourname[idum] == 'Z') && (ourname[idum-1] == '.'))
421
(void) strncpy(outfra,ourname,idum);
425
else if ((ourname[idum] == 'z') && (ourname[idum-1] == 'g')
426
&& (ourname[idum-2] == '.'))
429
(void) strncpy(outfra,ourname,idum);
434
(void) SCFINF(ourname,5,kdum);
436
if (kdum[0] > 0) /* we have an extracted frame... */
438
(void) SCFNAME(imno,outfra,100); /* get name of son */
440
(void) SCPSET(F_DEL_PARM,kdum); /* don't delete son */
441
(void) SCFCLO(imno); /* close father + son */
442
namepntr = outfra; /* point to name of son */
450
khelp[2] = MYMAX(mapsiz[0],mapsiz[1]); /* we can allocate! */
451
stat = IIXWIM_C(QDSPNO,QIMCH,namepntr,khelp,LOADDR,
452
npix,icent,cuts,scale);
453
if (stat != 0) /* we had problems... */
454
out_error(stat,ourname);
455
(void) IIEGDB_C(QDSPNO,1,QIMCH,dzmemc,dzmemi,dzmemr);
459
WIMGA_C(QDSPNO,QIMCH,imno,khelp,LOADDR,npix,icent,cuts,scale);
460
ZOOMX = ZOOMY = 1; /* update IDIMEM data */
470
if (QMSZX > QDSZX) /* take care of larger channels */
472
SCROLX = QMSZX/2 - QDSZX/2;
480
SCROLY = QMSZY/2 + QDSZY/2;
489
*npix = SSPX + NSX/2;
490
SCROLX = *npix - splcx[QIMCH][splmod];
491
npix[1] = SSPY + NSY/2;
492
SCROLY = QMSZY - 1 + npix[1] - splcy[QIMCH][splmod];
495
if ( flag ) (void) Cdazscr(QDSPNO,QIMCH,&SCROLX,&SCROLY);
498
/* update refscale only for image channels... */
500
if (QIMCH != QOVCH) Cdazvis(QDSPNO,QIMCH,1,dazhld[7]);
503
/* store xsta,ysta,xend,yend,locut,hicut,min,max
504
in global variable dzmemr */
506
if (khelp[9] != 2) /* only if not OVERWRITE */
508
dzmemr[0] = (float) (*start + (SFPX-1) * *step);
509
dzmemr[1] = (float) (start[1] + (SFPY-1) * step[1]);
511
offs = NSX / (- *scale) - 1;
514
if ( scale[2] == 0 ) /* no averaging */
515
offs = (NSX-1) * (*scale);
517
offs = NSX * (*scale) - 1;
519
dzmemr[2] = (float) (*start + (SFPX + offs - 1) * *step);
522
offs = NSY / (- scale[1]) - 1;
525
if ( scale[2] == 0 ) /* no averaging */
526
offs = (NSY - 1) * scale[1];
528
offs = NSY * scale[1] - 1;
531
dzmemr[3] = (float) (start[1] + (SFPY + offs - 1) * step[1]);
537
if (khelp[10] == 2) /* update channel info */
542
for (nr=0; nr<kcount; nr++)
564
void out_error(stat,name)
574
sprintf(otto,"XWIMG: overflow in output buffer...");
579
sprintf(otto,"XWIMG: averaging only supported for real data!");
584
sprintf(otto,"XWIMG: frame %s could not be accessed...",name);