forked from Starlink/cfitsio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iter_b.f
193 lines (152 loc) · 5.55 KB
/
iter_b.f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
program f77iterate_b
C external work function is passed to the iterator
external str_iter
integer ncols
parameter (ncols=2)
integer units(ncols), colnum(ncols), datatype(ncols)
integer iotype(ncols), offset, rows_per_loop, status
character*70 colname(ncols)
integer iunit, blocksize
character*80 fname
C include f77.inc -------------------------------------
C Codes for FITS extension types
integer IMAGE_HDU, ASCII_TBL, BINARY_TBL
parameter (
& IMAGE_HDU = 0,
& ASCII_TBL = 1,
& BINARY_TBL = 2 )
C Codes for FITS table data types
integer TBIT,TBYTE,TLOGICAL,TSTRING,TSHORT,TINT
integer TFLOAT,TDOUBLE,TCOMPLEX,TDBLCOMPLEX
parameter (
& TBIT = 1,
& TBYTE = 11,
& TLOGICAL = 14,
& TSTRING = 16,
& TSHORT = 21,
& TINT = 31,
& TFLOAT = 42,
& TDOUBLE = 82,
& TCOMPLEX = 83,
& TDBLCOMPLEX = 163 )
C Codes for iterator column types
integer InputCol, InputOutputCol, OutputCol
parameter (
& InputCol = 0,
& InputOutputCol = 1,
& OutputCol = 2 )
C End of f77.inc -------------------------------------
status = 0
fname = 'iter_b.fit'
iunit = 15
C both columns are in the same FITS file
units(1) = iunit
units(2) = iunit
C open the file and move to the correct extension
call ftopen(iunit,fname,1,blocksize,status)
call ftmnhd(iunit, BINARY_TBL, 'iter_test', 0, status)
C define the desired columns by name
colname(1) = 'Avalue'
colname(2) = 'Lvalue'
C leave column numbers undefined
colnum(1) = 0
colnum(2) = 0
C define the desired datatype for each column: TSTRING & TLOGICAL
datatype(1) = TSTRING
datatype(2) = TLOGICAL
C define whether columns are input, input/output, or output only
C Both in/out
iotype(1) = InputOutputCol
iotype(2) = InputOutputCol
C use default optimum number of rows and process all the rows
rows_per_loop = 0
offset = 0
C apply the function to each row of the table
print *,'Calling iterator function...', status
call ftiter( ncols, units, colnum, colname, datatype, iotype,
& offset, rows_per_loop, str_iter, 0, status )
call ftclos(iunit, status)
C print out error messages if problem
if (status.ne.0) call ftrprt('STDERR', status)
stop
end
C--------------------------------------------------------------------------
C
C Sample iterator function.
C
C--------------------------------------------------------------------------
subroutine str_iter(totalrows, offset, firstrow, nrows, ncols,
& units, colnum, datatype, iotype, repeat, status,
& userData, stringCol, logicalCol )
integer totalrows,offset,firstrow,nrows,ncols,status
integer units(*),colnum(*),datatype(*),iotype(*),repeat(*)
integer userData
character*(*) stringCol(*)
logical logicalCol(*)
integer ii
C include f77.inc -------------------------------------
C Codes for FITS extension types
integer IMAGE_HDU, ASCII_TBL, BINARY_TBL
parameter (
& IMAGE_HDU = 0,
& ASCII_TBL = 1,
& BINARY_TBL = 2 )
C Codes for FITS table data types
integer TBIT,TBYTE,TLOGICAL,TSTRING,TSHORT,TINT
integer TFLOAT,TDOUBLE,TCOMPLEX,TDBLCOMPLEX
parameter (
& TBIT = 1,
& TBYTE = 11,
& TLOGICAL = 14,
& TSTRING = 16,
& TSHORT = 21,
& TINT = 31,
& TFLOAT = 42,
& TDOUBLE = 82,
& TCOMPLEX = 83,
& TDBLCOMPLEX = 163 )
C Codes for iterator column types
integer InputCol, InputOutputCol, OutputCol
parameter (
& InputCol = 0,
& InputOutputCol = 1,
& OutputCol = 2 )
C End of f77.inc -------------------------------------
if (status .ne. 0) return
C --------------------------------------------------------
C Initialization procedures: execute on the first call
C --------------------------------------------------------
if (firstrow .eq. 1) then
if (ncols .ne. 2) then
status = -1
return
endif
if (datatype(1).ne.TSTRING .or. datatype(2).ne.TLOGICAL) then
status = -2
return
endif
print *,'Total rows, No. rows = ',totalrows, nrows
endif
C -------------------------------------------
C Main loop: process all the rows of data
C -------------------------------------------
C NOTE: 1st element of array is the null pixel value!
C Loop over elements 2 to nrows+1, not 1 to nrows.
do 10 ii=2,nrows+1
print *, stringCol(ii), logicalCol(ii)
if( logicalCol(ii) ) then
logicalCol(ii) = .false.
stringCol(ii) = 'changed to false'
else
logicalCol(ii) = .true.
stringCol(ii) = 'changed to true'
endif
10 continue
C -------------------------------------------------------
C Clean up procedures: after processing all the rows
C -------------------------------------------------------
if (firstrow + nrows - 1 .eq. totalrows) then
C no action required in this case
endif
return
end