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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
|
include <error.h>
include <imhdr.h>
include <imio.h>
include <math/gsurfit.h>
# Data structure.
define MGS_SZNAME 99 # Length of mgs name string
define MGS_LEN 56 # Length of structure
define MGS_GS Memi[$1] # GSURFIT pointer
define MGS_X Memi[$1+1] # Pointer to line of x values
define MGS_Y Memi[$1+2] # Pointer to line of y values
define MGS_Z Memi[$1+3] # Pointer to line of z values
define MGS_NC Memi[$1+4] # Number of columns
define MGS_REFIM Memi[$1+5] # Reference image pointer
define MGS_NAME Memc[P2C($1+6)] # Map name
# MGS_GLR -- Get a line of data.
pointer procedure mgs_glr (mgs, line)
pointer mgs #I Map pointer
int line #I Line
int nc
pointer x, y, z, gs
begin
if (mgs == NULL)
call error (1, "Map is undefined")
gs = MGS_GS(mgs)
x = MGS_X(mgs)
y = MGS_Y(mgs)
z = MGS_Z(mgs)
nc = MGS_NC(mgs)
call amovkr (real(line), Memr[y], nc)
call gsvector (gs, Memr[x], Memr[y], Memr[z], nc)
return (z)
end
# MGS_OPEN -- Open mgs.
pointer procedure mgs_open (name, refim, gsin)
char name[ARB] #I Name
pointer refim #I Reference image
pointer gsin #I GSURFIT pointer
pointer mgs #O Map pointer returned
int i, nc, nl
real gsgetr()
pointer gs
errchk mgs_ggs
begin
nc = IM_LEN(refim,1)
nl = IM_LEN(refim,2)
call calloc (mgs, MGS_LEN, TY_STRUCT)
MGS_REFIM(mgs) = refim
call strcpy (name, MGS_NAME(mgs), MGS_SZNAME)
MGS_NC(mgs) = nc
iferr {
gs = gsin
if (gs == NULL) {
call mgs_ggs (refim, name, gs)
MGS_GS(mgs) = gs
}
if (1 < gsgetr (gs, GSXMIN) || nc > gsgetr (gs, GSXMAX) ||
1 < gsgetr (gs, GSYMIN) || nl > gsgetr (gs, GSYMAX))
call error (2, "Map and data images have different sizes")
MGS_GS(mgs) = gs
call malloc (MGS_X(mgs), nc, TY_REAL)
call malloc (MGS_Y(mgs), nc, TY_REAL)
call malloc (MGS_Z(mgs), nc, TY_REAL)
do i = 1, nc
Memr[MGS_X(mgs)+i-1] = i
} then {
call mgs_close (mgs)
call erract (EA_ERROR)
}
return (mgs)
end
# MGS_CLOSE -- Close mgs.
procedure mgs_close (mgs)
pointer mgs #I Map pointer
begin
if (mgs == NULL)
return
if (MGS_GS(mgs) != NULL)
call gsfree (MGS_GS(mgs))
call mfree (MGS_X(mgs), TY_REAL)
call mfree (MGS_Y(mgs), TY_REAL)
call mfree (MGS_Z(mgs), TY_REAL)
call mfree (mgs, TY_STRUCT)
end
# MGS_GETS -- Get string parameter.
procedure mgs_gets (mgs, param, val, maxchar)
pointer mgs #I Map pointer
char param[ARB] #I Parameter
char val[ARB] #O Parameter string value
int maxchar #I Maximum number of characters to return
begin
call error (1, "mgs_gets: unknown parameter")
end
# MGS_SETS -- Set string parameter.
procedure mgs_sets (mgs, param, val)
pointer mgs #I Map pointer
char param[ARB] #I Parameter
char val[ARB] #O Parameter string value
begin
call error (1, "mgs_sets: unknown parameter")
end
# MGS_GETI -- Get integer parameter.
procedure mgs_geti (mgs, param, val)
pointer mgs #I Map pointer
char param[ARB] #I Parameter
int val #O Value
bool streq()
begin
if (streq (param, "gsurfit"))
val = MGS_GS(mgs)
else
call error (1, "mgs_geti: unknown parameter")
end
# MGS_SETI -- Set integer parameter.
procedure mgs_seti (mgs, param, val)
pointer mgs #I Map pointer
char param[ARB] #I Parameter
int val #I Value
bool streq()
begin
if (streq (param, "gsurfit")) {
call mgs_pgs (MGS_REFIM(mgs), MGS_NAME(mgs), val)
call gsfree (MGS_GS(mgs))
MGS_GS(mgs) = val
} else
call error (1, "mgs_seti: unknown parameter")
end
# MGS_GETR -- Get real parameter.
procedure mgs_getr (mgs, param, val)
pointer mgs #I Map pointer
char param[ARB] #I Parameter
real val #O Value
begin
call error (1, "mgs_getr: unknown parameter")
end
# MGS_SETR -- Set real parameter.
procedure mgs_setr (mgs, param, val)
pointer mgs #I Map pointer
char param[ARB] #I Parameter
real val #I Value
begin
call error (1, "mgs_setr: unknown parameter")
end
# MAP_PGS -- Put mgs surface fit.
procedure mgs_pgs (im, key, gs)
pointer im #I Image pointer
char key[ARB] #I Keyword root
pointer gs #I Surface fit pointer
int i, nc, fd, gsgeti(), stropen()
pointer sp, kw, card, coeffs, strbuf, cp, cp1, cp2
begin
if (IM_SECTUSED(im) == YES)
return
call smark (sp)
call salloc (kw, 80, TY_CHAR)
call salloc (card, 68, TY_CHAR)
nc = gsgeti (gs, GSNSAVE)
call salloc (coeffs, nc, TY_REAL)
call gssave (gs, Memr[coeffs])
# Convert coeffs to a string. Last character will be space.
call salloc (strbuf, 20*nc, TY_CHAR)
call aclrc (Memc[strbuf], 20*nc)
fd = stropen (Memc[strbuf], 20*nc, WRITE_ONLY)
do i = 1, nc {
call fprintf (fd, "%g ")
call pargr (Memr[coeffs+i-1])
}
call close (fd)
i = 1
cp1 = strbuf
for (cp=cp1; Memc[cp] != EOS; cp=cp+1) {
if (Memc[cp] == ' ')
cp2 = cp
if (cp - cp1 + 1 == 68) {
call sprintf (Memc[kw], 8, "%.6s%02d")
call pargstr (key)
call pargi (i)
i = i + 1
Memc[cp2] = EOS
call imastr (im, Memc[kw], Memc[cp1])
cp1 = cp2 + 1
cp = cp1
}
}
if (cp - cp1 + 1 > 0) {
call sprintf (Memc[kw], 8, "%.6s%02d")
call pargstr (key)
call pargi (i)
i = i + 1
Memc[cp2] = EOS
call imastr (im, Memc[kw], Memc[cp1])
}
repeat {
call sprintf (Memc[kw], 8, "%.6s%02d")
call pargstr (key)
call pargi (i)
i = i + 1
iferr (call imdelf (im, Memc[kw]))
break
}
call sfree (sp)
end
# MAP_GGS -- Get mgs surface fit.
procedure mgs_ggs (im, key, gs)
pointer im #I Image pointer
char key[ARB] #I Keyword root
pointer gs #O Surface fit pointer
int i, j, nc, ctor()
pointer sp, kw, card, coeffs
begin
if (IM_SECTUSED(im) == YES)
call error (1, "No surface fit with an image section")
call smark (sp)
call salloc (kw, 8, TY_CHAR)
call salloc (card, 68, TY_CHAR)
call malloc (coeffs, 100, TY_REAL)
iferr {
nc = 0
do i = 1, ARB {
call sprintf (Memc[kw], 8, "%.6s%02d")
call pargstr (key)
call pargi (i)
iferr (call imgstr (im, Memc[kw], Memc[card], 68))
break
j = 1
while (ctor (Memc[card], j, Memr[coeffs+nc]) != 0) {
nc = nc + 1
if (mod (nc, 100) == 0)
call realloc (coeffs, nc+100, TY_REAL)
}
}
if (nc == 0)
call error (1, "Surface fit not found")
call gsrestore (gs, Memr[coeffs])
call mfree (coeffs, TY_REAL)
} then {
call mfree (coeffs, TY_REAL)
call erract (EA_ERROR)
}
call sfree (sp)
end
|