aboutsummaryrefslogtreecommitdiff
path: root/pkg/utilities/nttools/threed/tiimage/design1.txt
blob: 8726f47547b6546368ac7e6164d4e00a4eaf3c4a (plain) (blame)
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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353


          Design of 3-D table translator for image insertion
          --------------------------------------------------


 Author: I. Busko


 Revision history:
 01/16/97  -  First version.



1. Specifications / requirements:

This task will perform the inverse operation performed by task tximage.
It will insert (in the tainsert task sense) one or more 1-D images into 
rows of an existing 3-D table. Alternatively, it will create a 3-D table 
from information taken either from a template 3-D table, or, if this table 
is not supplied, from the input images themselves. Each image in the input 
list is inserted as an array into a single cell at the specified row in the output table. 

Actions necessary to process the most complicated cases (e.g. when the
image length does not match the table array size) will be similar to the 
ones described for task titable.

If the output table does exist, insertion may take place in two ways. If the
output table name contains a column selector that selects a single column
in the table, all input images will be inserted in that column, starting
at the row pointed by task parameter "row". In a similar way as in task
titable, if "row" is negative or INDEF the task will look for the ORIG_ROW
keyword in the image header and use that keyword value for row number.
The second mode of insertion in an existing table is used if no matching
column selector is found in the output table name. In this case the task
will look for the columnar information written in the input image header by 
task tximage, and use that information to place the image in the proper 
column. If no columnar information exists in the header, or if the column 
name in there does not match any column in the output table, the image is 
skipped and the user warned. The "row" parameter processing works the same 
way in this second mode.

If the output table does not exist, the task will look for a template table
where to take column information from. If the template exists, the insertion
operation will be performed in an analogous way as above. Notice that the
result may be a single-column table if the template has a valid (matching)
column selector in its name, or a sparse table if not, because only the 
actual input images will be stored in an otherwise empty table (the template 
data is not copied into the output, only the column descriptors).

If the template is missing, the task will attempt to retrieve columnar
information from the input image headers and build the output table with
enough columns and rows to fit all images in the list. Only images that
have columnar information in their headers can be processed, though. If
no images are found with the proper header keywords, no output takes place.
Notice that this task will not be able to handle the most generic case in
which a number of unspecified 1-D images with no proper header keywords 
are input to create a 3-D table from scratch (without a template).

The basic matching criterion is based on the column name. An error results 
when datatypes in input image and output column do not agree.

The task will be named "tiimage" following a former proposal for naming
the 3-D table utilities.



2. Language:

SPP, to allow the use of the generic datatype compiling facility, and to
reuse significant amounts of code already developed for other tasks in this
suite.



3. Task parameters:

Name     Type                  What

input    image list/template   list of 1D image names
outtable file name             3-D table name with optional column selector
                               (modified in place or created from scratch).
template file name             template 3-D table name with optional column 
                               selector
row      int                   row in output table where to begin insertion.



4. Data structures:

The main data structure is a pointer-type column descriptor array. This 
array is filled by information taken from the several possible sources
described above, and used by the tbtables routines to create and fill up
the output.



5. Code structure:

MAIN PROCEDURE:
- Read task parameters (clget).
- Decide which mode to use: mode = TMMODE (output name, template name)
- SWITCH mode
- CASE 1, 2: Output table exists.
   - Break output table name into bracketed selectors (rdselect).
   - Open output table (tbtopn with root name, READ_WRITE).
   - Create array with either the single selected column pointer or all
     column pointers (malloc, tcs_open).
   - Alloc array of column pointers for output table.
   - LOOP over all matched columns in tcs_ column array
      - Translate pointer from tcs_ format to tbtables format (tcs_column)
   - ENDLOOP
   - TMLOOP (table pointer, column pointer array, rowpar, image list, mode).
   - Close output table (tbtclo)
   - Free array (mfree)
- END CASE 
- CASE 3, 4: Output table does not exist but template table does exist.
   - Break output table name into bracketed selectors (rdselect).
   - Open output table (tbtopn with root name, NEW_FILE).
   - Break template table name into bracketed selectors (rdselect).
   - Open template table (tbtopn with root name, READ_ONLY).
   - Create array with either the single selected column pointer or all
     column pointers from template table (malloc, tcs_open).
   - Alloc array of column pointers for output table.
   - LOOP over all matched columns in template tcs_ column array
      - Create column in output table (tcs_column, tbcinf, tbcdef)
   - ENDLOOP
   - Create output table (tbtcre).
   - TMLOOP (table pointer, column pointer array, rowpar, image list, mode)
   - Close template table (tbtclo)
   - Close output table (tbtclo)
   - Free arrays (mfree)
- CASE 5: Neither output nor template table exist.
   - Alloc memory for strings.
   - Alloc memory for column pointer array, assuming the worst case of each
     input image in the list belonging to a separate, independent column.
   - Open output table (tbtopn with root name, NEW_FILE).
   - IFNOTERROR TMSCAN (table pointer, column pointer array, image list)
      - Set mode = 2 to force TMLOOP to read column data from headers.
      - Create output table (tbtcre).
      - TMLOOP (table pointer, column pointer array, rowpar, image list, mode)
   - ENDIF
   - Close output table (tbtclo)
   - Free arrays (mfree)
- END CASE 
- CASE -1
   - Print error msg.
   - Abort.
- END SWITCH
END MAIN



PROCEDURE TMMODE: Detect mode of operation.
    Input parameters: file name, template name (in full)
    Return value: mode

   - IF output exists (access)
      - mode = TMM1 (output file name, output type)
      - IF mode == -1
         - Print error msg.
         - return mode = -1 (error)
      - ENDIF
   - ELSE IF template does exist (access)
      - mode = TMM1 (template file name, template type)
      - IF mode == -1
         - Print error msg.
         - return mode = -1 (error)
      - ENDIF
   - ELSE
      mode = 5
   - ENDIF
   return mode
END PROCEDURE



PROCEDURE TMM1: Verify status of file and column selector.
    Input parameters: file name, file type (output or template)
    Return value: mode

   - IF file is not a table (whatfile). 
      - return mode = -1 (error)
   - ENDIF
   - Get bracket selector from file name (rdselect).
   - Open  table (tbtopn with root name, READ_ONLY).
   - Get its total number of columns (tbpsta).
   - Create array of column pointers from column selector (malloc, tcs_open).
   - Close output table (tbtclo)
   - Free array (mfree)
   - IF output file type
      - IF one column matched
         - return mode = 1
      - ELSE
         - return mode = 2
      - ENDIF
   - ELSE IF template file type
      - IF one column matched
         - return mode = 3
      - ELSE
         - return mode = 4
      - ENDIF
   - ENDIF
      return mode = -1 (error)
END PROCEDURE



PROCEDURE TMLOOP: Scan input list and insert each image in turn.
    Input parameters: table pointer, column pointer array,row, image list,mode

   - Initialize row counter.
   - Initialize successful image counter.
   - Open input list (imtopen)
   - LOOP over input list (imtlen).
      - Get image name (imtgetim).
      - IFERROR Open input image (immap).
         - Warn user.
         - Skip image.
      - ENDIF
      - IF mode == 2 or mode == 4, look into image header for columnar info 
           and do the copy.
         - IFERROR TMHC (table pointer, column pointer array, row, rowpar, 
                         imio pointer)
            - Close and skip image.
         - ENDIF
         - bump row and image counters.
      - ELSE IF mode == 1 or mode == 3, just copy into single, fixed column.
         - IFERROR TMCOPY (table pointer, column pointer, row, rowpar, 
                           imio pointer)
            - Warn user.
            - Close and skip image.
         - ENDIF
         - bump row and image counters.
      - ENDIF
      - Close image (imunmap)
   - ENDLOOP
   - IF successful image counter == 0
      - Print error msg.
   - ENDIF
   - Close input list (imtclose)
END PROCEDURE



PROCEDURE TMSCAN: Scan input list and create column pointer array from
                  information stored in image headers.
    Input parameters: table pointer, column pointer array, its size, image list
    Output parameter: actual number of matched columns.

   - Initialize column counter.
   - Open input list (imtopen)
   - LOOP over input list (imtlen).
      - Get image name (imtgetim).
      - IFERROR Open input image (immap).
         - Warn user.
         - Skip image.
      - ENDIF
      - IFERROR TMHEADER (imio pointer, column name, units, fmt, datatype, 
                          lendata
         - Warn user.
         - Skip image.
      - ENDIF
      - IF there are defined columns (column counter > 0):
         - match = false
         - LOOP over defined columns
            - Get column name (tbcinf)
            - IF column name from table matches column name from header:
               - match = true
               - break
            - ENDIF
         - ENDLOOP
         - IF no match, this is a new column:
            - Define new column in array (tbcdef)
            - Bump column counter
         - ENDIF
      - ELSE
         - Define first new column in array (tbcdef)
         - Bump column counter
      - ENDIF
   - ENDLOOP
   - Close input list (imtclose)
   - IF column counter == 0
      - Error.
   - Create output table (tbtcre).
END PROCEDURE



PROCEDURE TMHC: Get column name from image header and copy image into table.
    Input parameters: table pointer, column pointer array, row, rowpar, 
                      imio pointer

   - salloc space for column name.
   - IFERROR TMHEADER (imio pointer, column name, etc.)
      - Warn, return
   - ENDIF
   - match = false
   - LOOP over table columns.
      - IF column names match:
         - IFERROR TMCOPY (table pointer, column pointer, row, rowpar, 
                           imio pointer)
            - Warn, return.
         - ENDIF
         - match = true
      - ENDIF
   - ENDLOOP
   - IF no match
      - Warn, return.
   - ENDIF
   - sfree
END PROCEDURE



PROCEDURE TMCOPY: Copy image into designated row/column.
    Input parameters: table pointer, column pointer, row, rowpar, imio pointer

   - Get table (tbcigi) and image (IM_PIXTYPE) pixel type.
   - IF pixel type mismatch:
      - Warn, return
   - ENDIF
   - Look for ORIG_ROW keyword (imaccf, imgeti). If found, and if "row" 
     parameter is negative or INDEF, supersede row counter. 
   - Get column array size (tbcinf) and image size (IM_NDIM, IM_LEN).
   - Choose the minimum of these as the array size to be written to table.
   - Read pixels in buffer (imgl1$t).                     ^
   - Write buffer into designated row/column (tbapt$t).   |
   - IF image is larger than array:                       |  This goes into
      - Warn user.                                        |  a generic data
   - ELSE IF image is smaller than array:                 |  type procedure
      - Set remaining elements to INDEF (tbapt$t).        |
      - Warn user.                                        |
   - ENDIF                                                v
END PROCEDURE



PROCEDURE TMHEADER: Decode column info in image header. 
    Input parameter: imio pointer
    Output parameter: column name, units, fmt, datatype, lendata

   - Look for COLDATA keyword (imaccf, imgstr).
   - IF not found:
      return error.
   - ENDIF
   - Parse and get parameters (sscan, gargwrd, gargi)
   - IF error in nscan value:
      return error.
   - ENDIF
END PROCEDURE