1
C===========================================================================
2
C Copyright (C) 1995,2003 European Southern Observatory (ESO)
4
C This program is free software; you can redistribute it and/or
5
C modify it under the terms of the GNU General Public License as
6
C published by the Free Software Foundation; either version 2 of
7
C the License, or (at your option) any later version.
9
C This program is distributed in the hope that it will be useful,
10
C but WITHOUT ANY WARRANTY; without even the implied warranty of
11
C MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
C GNU General Public License for more details.
14
C You should have received a copy of the GNU General Public
15
C License along with this program; if not, write to the Free
16
C Software Foundation, Inc., 675 Massachusetts Ave, Cambridge,
19
C Correspondence concerning ESO-MIDAS should be addressed as follows:
20
C Internet e-mail: midas@eso.org
21
C Postal address: European Southern Observatory
22
C Data Management Division
23
C Karl-Schwarzschild-Strasse 2
24
C D 85748 Garching bei Muenchen
26
C===========================================================================
30
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
33
C program AVESUB version 3.00 881028
34
C K. Banse ESO - Garching
37
C statistics, subimage
40
C calculate the average value (and rms) according to different methods
41
C of an area defined by the cursor rectangle or a table or by coordinates
44
C This info may also be stored either in a descriptor or a table...
48
C The following keywords are used:
49
C IN_A/C/1/60 input frame
50
C IN_B/C/1/60 input specs,
51
C = +, for cursor input
52
C = name or name/TABLE for table input
53
C ACTION/C/1/1 averaging method,
54
C K for kappa-sigma clipping,
55
C M for median, A for simple average
56
C INPUTC/C/1/50 specs for data storage
57
C = :label for table or table,:label (a)
58
C = descr for descriptor (b)
59
C = + for just display of data
60
C INPUTC/C/51/1 (b) append flag for descriptor,
61
C = A, append data to descriptor
62
C = +, start again at position 1 in descr
63
C (a) center flag for table
64
C = C, add also columns with center points
67
C OUTPUTR/R/1/5 last displayed results
68
C OUTPUTI/I/1/1 no. of loops in program
71
C 3.00 use new IDI interfaces
75
C--------------------------------------------------------------------------
79
INTEGER FELEM,IAV,INFLAG,ISTOP
80
INTEGER KAPITR,LEAP,NMAL,NROW,NN,N
81
INTEGER OUTFLG,STAT1,STAT2,STAT
82
INTEGER TPIX(2),MAXSIZ
83
INTEGER TBCOLN(7),OUTCOL
84
INTEGER SUBPIX(2,2),IPIXS(4),NPON(5)
85
INTEGER ICUR1(2),ICUR2(2)
87
INTEGER NAXIS,NPIX(2),IMNOA
88
INTEGER TABNUL(7),COOS(4),CURSOF
89
INTEGER UNI(1),NULO,TID
92
CHARACTER*80 FRAME,TABLE
93
CHARACTER DESCR*48,APPFLG*1
94
CHARACTER CUNIT*48,IDENT*72,CBUF*80,ACTION*1
96
CHARACTER OUTUNI*16,OUTLAB(7)*16,DRAWY*8
98
REAL PCUR1(6),PCUR2(6),PCEN(3),RDUM
99
REAL BGR,BGVL(5),RMSV(5),AVAREA
100
REAL REAL1(5),RBUF(10)
102
DOUBLE PRECISION START(2),STEP(2)
106
INCLUDE 'MID_INCLUDE:ST_DEF.INC'
108
INCLUDE 'MID_INCLUDE:IDIDEV.INC'
109
INCLUDE 'MID_INCLUDE:IDIMEM.INC'
114
DATA COOS /-1,-1,-1,-1/, CURSOF /0/
116
DATA INFO /'switch cursor(s) on - next time we exit... '/
118
DATA OUTLAB /'XSTART ','YSTART ','XEND ','YEND ',
119
+ ' ','XCEN ','YCEN '/
122
DATA CUNIT /' '/, IDENT /' '/, DESCR /' '/
123
DATA CBUF /' '/, FRAME /' '/, TABLE /' '/
125
INCLUDE 'MID_INCLUDE:ST_DAT.INC'
127
C set up MIDAS environment + enable automatic error abort
128
CALL STSPRO('AVESUB')
131
CALL STKRDC('ACTION',1,1,1,IAV,ACTION,UNI,NULO,STAT)
132
IF (INDEX('AKM',ACTION).LE.0) ACTION = 'A' !default to A(verage)
133
CALL STKRDI('INPUTI',1,2,IAV,NPON,UNI,NULO,STAT)
135
IF (ACTION.EQ.'M') THEN
137
CALL STFXMP(MAXSIZ,D_R4_FORMAT,PNTRX,STAT)
138
ELSE IF (ACTION.EQ.'K') THEN !for kappa-sigma clipping
142
C get the subarea input options
143
CALL STKRDC('IN_B',1,1,80,IAV,TABLE,UNI,NULO,STAT)
144
IF (TABLE(1:1).EQ.'+') THEN
145
INFLAG = 1 !INFLAG = 1 for cursor
146
DRAWY(1:7) = 'N YY?C0'
147
CALL STKRDC('P4',1,1,1,IAV,DRAWY(2:2),UNI,NULO,STAT)
149
CALL STKRDC('IN_A',1,1,80,IAV,FRAME,UNI,NULO,STAT)
150
CALL CLNFRA(FRAME,FRAME,0)
151
CALL STIGET(FRAME,D_R4_FORMAT,F_I_MODE,F_IMA_TYPE,
152
+ 2,NAXIS,NPIX,START,STEP,IDENT,
153
+ CUNIT,PNTRA,IMNOA,STAT)
155
+ CALL STETER(77,'1-dim frames currently not supported...')
156
CALL CLNTAB(TABLE,TABLE,0)
157
INFLAG = 2 !INFLAG = 2 for table
160
C get descriptor or table label for storage of data + output_options
162
OUTFLG = 1 !OUTFLG = 1 for descriptor or nothing
163
CALL STKRDC('INPUTC',1,1,51,IAV,CBUF,UNI,NULO,STAT)
165
IF (APPFLG .EQ. 'c') THEN !take care of lower case options
167
ELSE IF (APPFLG .EQ. 'a') THEN
171
IF (CBUF(1:1).EQ.'+') GOTO 500 !neither table nor descriptor
173
C test for :label or table,:label or #no. or table,#no.
174
IF (INDEX(CBUF,'#') .GT. 0)
175
+ CALL STETER(73,'We need a column label, no # sign, please.')
177
IF (CBUF(1:1).EQ.':') THEN
182
CALL STETER(76,'Invalid syntax (missing table name)...')
183
ELSE IF (N.GT.1) THEN
184
CALL CLNTAB(CBUF(1:N-1),TABLE,0)
185
N = N + 1 !skip the ','
187
GOTO 400 !it's a descriptor
191
C handle table storage
192
OUTFLG = 2 !OUTFLG = 2 for table
193
OUTLAB(5) = CBUF(N+1:50)
194
IF (INFLAG.EQ.1) THEN !cursor input
197
IF (OUTLAB(5).EQ.OUTLAB(N))
198
+ CALL STETER(78,'Invalid column label !')
202
C for cursor input create table with 100 rows
203
IF (APPFLG.EQ.'C') THEN
208
CALL TBTINI(TABLE,0,F_O_MODE,OUTCOL,100,TID,STAT)
210
CALL TBCINI(TID,D_R4_FORMAT,1,'E12.5',OUTUNI,OUTLAB(N),
215
IF (N.GT.1) !for table input is table,:label not allowed...
216
+ CALL STETER(79,'No table name possible in out_specs... ')
219
C for existing table, test, if label(s) already there
220
CALL TBTOPN(TABLE,F_IO_MODE,TID,STAT)
221
IF (APPFLG.EQ.'C') THEN
227
CALL TBLSER(TID,OUTLAB(N),TBCOLN(N),STAT)
228
IF (TBCOLN(N).LE.0) !No. We have to define it...
229
+ CALL TBCINI(TID,D_R4_FORMAT,1,'E12.5',OUTUNI,OUTLAB(N),
234
C handle descriptor storage
235
400 DESCR(1:48) = CBUF(1:48)
236
IF (APPFLG.EQ.'A') THEN !see, if data is to be appended
242
C branch according to input option
243
500 NMAL = 0 !init counter
244
IF (INFLAG.EQ.2) GOTO 2000
246
C a) cursor defined subimage(s) - attach Image Display + get all info
249
CALL SETCUR(QDSPNO,2,1,2,COOS,STAT) !set up cursor rectangle
252
C input cursor positions and check status
253
1000 CALL GETCUR(DRAWY,FRAME, !draw box in overlay channel
254
+ ICUR1,PCUR1(3),PCUR1(5),RDUM,STAT1,
255
+ ICUR2,PCUR2(3),PCUR2(5),RDUM,STAT2)
257
C check cursor status
258
IF ( (STAT1.EQ.0) .AND. (STAT2.EQ.0) ) THEN
260
IF (CURSOF.EQ.1) GOTO 9000
261
CALL STTPUT(INFO,STAT)
266
GOTO 9000 !cursor loop terminated ...
270
NMAL = NMAL + 1 !update counter
278
C finally map displayed frame
279
CALL STIGET(FRAME,D_R4_FORMAT,F_I_MODE,F_IMA_TYPE,2,
280
+ NAXIS,NPIX,START,STEP,
281
+ IDENT,CUNIT,PNTRA,IMNOA,STAT)
284
C b) table defined subimage(s)
286
2000 IF (OUTFLG.NE.2) CALL TBTOPN(TABLE,F_IO_MODE,TID,STAT)
287
CALL TBIGET(TID,N,NROW,N,N,N,STAT) !get total no. of rows
289
CALL TBLSER(TID,OUTLAB(N),TBCOLN(N),STAT)
293
2100 IF (NMAL.GE.NROW) GOTO 9000
295
CALL TBSGET(TID,NMAL,SELFLG,STAT) !only use selected rows
296
IF (.NOT.SELFLG) GOTO 2100
298
C get next row of values
299
CALL TBRRDR(TID,NMAL,4,TBCOLN,REAL1(1),TABNUL,STAT)
300
PCUR1(3) = (REAL1(1)-START(1))/STEP(1) + 1.
301
PCUR1(4) = (REAL1(2)-START(2))/STEP(2) + 1.
302
PCUR2(3) = (REAL1(3)-START(1))/STEP(1) + 1.
303
PCUR2(4) = (REAL1(4)-START(2))/STEP(2) + 1.
305
C -----------------------------------
306
C common section for option a) and b)
307
C -----------------------------------
309
3000 SUBPIX(1,1) = PCUR1(3)
310
SUBPIX(2,1) = PCUR1(4)
311
SUBPIX(1,2) = PCUR2(3)
312
SUBPIX(2,2) = PCUR2(4)
314
IF (APPFLG.EQ.'C') THEN
315
N = (SUBPIX(1,1)+SUBPIX(1,2)+1) / 2
316
PCEN(2) = (N-1)*STEP(1) + START(1)
317
N = (SUBPIX(2,1)+SUBPIX(2,2)+1) / 2
318
PCEN(3) = (N-1)*STEP(2) + START(2)
321
C and finally let's do the averaging
323
IF (ACTION.EQ.'K') THEN
324
IPIXS(1) = SUBPIX(1,1)
325
IPIXS(2) = SUBPIX(1,2)
326
IPIXS(3) = SUBPIX(2,1)
327
IPIXS(4) = SUBPIX(2,2)
330
CALL BGVAL(1,MADRID(PNTRA),NPIX(1),NPIX(2),IPIXS,KAPITR,
331
+ 2,LEAP,BGVL,RMSV,NPON,ISTOP,N)
336
TPIX(1) = SUBPIX(1,2) - SUBPIX(1,1) + 1 !get size of subimage
337
TPIX(2) = SUBPIX(2,2) - SUBPIX(2,1) + 1
338
IF ((ACTION.EQ.'M').AND.(TPIX(1)*TPIX(2).GT.MAXSIZ)) THEN
339
CALL STTPUT('subimage too large for internal buffers -'//
340
+ ' skipped...',STAT)
341
IF (INFLAG.EQ.1) NMAL = NMAL - 1 !modify counter
344
BGR = AVAREA(ACTION,MADRID(PNTRA),NPIX(1),SUBPIX,TPIX,
349
IF (NMAL.EQ.1) THEN !here for the 1. time...?
350
CBUF(1:) = ' xstart ystart xend '//
352
CALL STTPUT(CBUF,STAT)
355
WRITE(CBUF,20000) (REAL1(N),N=1,5)
356
CALL STTPUT(CBUF,STAT)
358
C fill table, if applicable
359
IF (OUTFLG.EQ.2) THEN
360
IF (INFLAG.EQ.2) THEN !table input
362
IF (APPFLG.EQ.'C') THEN
366
ENDIF !row already exists
367
CALL TBRWRR(TID,NMAL,N,TBCOLN(5),PCEN,STAT)
372
IF (APPFLG.EQ.'C') THEN
376
CALL TBRWRR(TID,NMAL,OUTCOL,TBCOLN,RBUF,STAT)
380
C fill descriptor, if applicable
381
IF (DESCR(1:1).NE.'+') THEN
382
CALL STDWRR(IMNOA,DESCR,REAL1,FELEM,5,UNI,STAT)
387
C store info also in keyword OUTPUTR
388
CALL STKWRR('OUTPUTR',REAL1(1),1,5,UNI,STAT)
392
7000 GOTO (1000,2100),INFLAG
395
9000 IF ((TID.NE.-1) .AND. (OUTFLG.EQ.2)) THEN
396
CALL TBSINI(TID,STAT)
397
CALL TBTCLO(TID,STAT)
400
C save no. of coordinates obtained for subsequent applications
401
CALL STKWRI('OUTPUTI',NMAL,1,1,UNI,STAT)
403
IF (INFLAG.EQ.1) CALL DTCLOS(QDSPNO)
407
20000 FORMAT(1X,5G15.7)