1 /* ****************************************************************************
2  * $Id: mkcatalog.cpp 16861 2009-04-26 19:22:29Z rouault $
3  *
4  * Project:  ISO8211 Library
5  * Purpose:  Test ISO8211 writing capability.
6  * Author:   Frank Warmerdam, warmerdam@pobox.com
7  *
8  ******************************************************************************
9  * Copyright (c) 2003, Frank Warmerdam <warmerdam@pobox.com>
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining a
12  * copy of this software and associated documentation files (the "Software"),
13  * to deal in the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15  * and/or sell copies of the Software, and to permit persons to whom the
16  * Software is furnished to do so, subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be included
19  * in all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  * DEALINGS IN THE SOFTWARE.
28  ****************************************************************************/
29 
30 #include "iso8211.h"
31 
32 CPL_CVSID("$Id: mkcatalog.cpp 16861 2009-04-26 19:22:29Z rouault $");
33 
34 
35 /************************************************************************/
36 /*                               mk_s57()                               */
37 /************************************************************************/
38 
mk_s57()39 void mk_s57()
40 
41 {
42     DDFModule  oModule;
43     DDFFieldDefn *poFDefn;
44 
45     oModule.Initialize();
46 
47 /* -------------------------------------------------------------------- */
48 /*      Create the '0000' definition.                                   */
49 /* -------------------------------------------------------------------- */
50     poFDefn = new DDFFieldDefn();
51 
52     poFDefn->Create( "0000", "", "0001DSIDDSIDDSSI0001DSPM0001VRIDVRIDATTVVRIDVRPCVRIDVRPTVRIDSGCCVRIDSG2DVRIDSG3D0001FRIDFRIDFOIDFRIDATTFFRIDNATFFRIDFFPCFRIDFFPTFRIDFSPCFRIDFSPT", dsc_elementary, dtc_char_string );
53 
54     oModule.AddField( poFDefn );
55 
56 /* -------------------------------------------------------------------- */
57 /*      Create the '0001' definition.                                   */
58 /* -------------------------------------------------------------------- */
59     poFDefn = new DDFFieldDefn();
60 
61     poFDefn->Create( "0001", "ISO 8211 Record Identifier", "",
62                      dsc_elementary, dtc_bit_string,
63                      "(b12)" );
64 
65     oModule.AddField( poFDefn );
66 
67 /* -------------------------------------------------------------------- */
68 /*      Create the DSID field.                                          */
69 /* -------------------------------------------------------------------- */
70     poFDefn = new DDFFieldDefn();
71 
72     poFDefn->Create( "DSID", "Data set identification field", "",
73                      dsc_vector, dtc_mixed_data_type );
74 
75     poFDefn->AddSubfield( "RCNM", "b11" );
76     poFDefn->AddSubfield( "RCID", "b14" );
77     poFDefn->AddSubfield( "EXPP", "b11" );
78     poFDefn->AddSubfield( "INTU", "b11" );
79     poFDefn->AddSubfield( "DSNM", "A" );
80     poFDefn->AddSubfield( "EDTN", "A" );
81     poFDefn->AddSubfield( "UPDN", "A" );
82     poFDefn->AddSubfield( "UADT", "A(8)" );
83     poFDefn->AddSubfield( "ISDT", "A(8)" );
84     poFDefn->AddSubfield( "STED", "R(4)" );
85     poFDefn->AddSubfield( "PRSP", "b11" );
86     poFDefn->AddSubfield( "PSDN", "A" );
87     poFDefn->AddSubfield( "PRED", "A" );
88     poFDefn->AddSubfield( "PROF", "b11" );
89     poFDefn->AddSubfield( "AGEN", "b12" );
90     poFDefn->AddSubfield( "COMT", "A" );
91 
92     oModule.AddField( poFDefn );
93 
94 /* -------------------------------------------------------------------- */
95 /*      Create the DSSI field.                                          */
96 /* -------------------------------------------------------------------- */
97     poFDefn = new DDFFieldDefn();
98 
99     poFDefn->Create( "DSSI", "Data set structure information field", "",
100                      dsc_vector, dtc_mixed_data_type );
101 
102     poFDefn->AddSubfield( "DSTR", "b11" );
103     poFDefn->AddSubfield( "AALL", "b11" );
104     poFDefn->AddSubfield( "NALL", "b11" );
105     poFDefn->AddSubfield( "NOMR", "b14" );
106     poFDefn->AddSubfield( "NOCR", "b14" );
107     poFDefn->AddSubfield( "NOGR", "b14" );
108     poFDefn->AddSubfield( "NOLR", "b14" );
109     poFDefn->AddSubfield( "NOIN", "b14" );
110     poFDefn->AddSubfield( "NOCN", "b14" );
111     poFDefn->AddSubfield( "NOED", "b14" );
112     poFDefn->AddSubfield( "NOFA", "b14" );
113 
114     oModule.AddField( poFDefn );
115 
116 /* -------------------------------------------------------------------- */
117 /*      Create the DSPM field.                                          */
118 /* -------------------------------------------------------------------- */
119     poFDefn = new DDFFieldDefn();
120 
121     poFDefn->Create( "DSPM", "Data set parameter field", "",
122                      dsc_vector, dtc_mixed_data_type );
123 
124     poFDefn->AddSubfield( "RCNM", "b11" );
125     poFDefn->AddSubfield( "RCID", "b14" );
126     poFDefn->AddSubfield( "HDAT", "b11" );
127     poFDefn->AddSubfield( "VDAT", "b11" );
128     poFDefn->AddSubfield( "SDAT", "b11" );
129     poFDefn->AddSubfield( "CSCL", "b14" );
130     poFDefn->AddSubfield( "DUNI", "b11" );
131     poFDefn->AddSubfield( "HUNI", "b11" );
132     poFDefn->AddSubfield( "PUNI", "b11" );
133     poFDefn->AddSubfield( "COUN", "b11" );
134     poFDefn->AddSubfield( "COMF", "b14" );
135     poFDefn->AddSubfield( "SOMF", "b14" );
136     poFDefn->AddSubfield( "COMT", "A" );
137 
138     oModule.AddField( poFDefn );
139 
140 /* -------------------------------------------------------------------- */
141 /*      Create the VRID field.                                          */
142 /* -------------------------------------------------------------------- */
143     poFDefn = new DDFFieldDefn();
144 
145     poFDefn->Create( "VRID", "Vector record identifier field", "",
146                      dsc_vector, dtc_mixed_data_type );
147 
148     poFDefn->AddSubfield( "RCNM", "b11" );
149     poFDefn->AddSubfield( "RCID", "b14" );
150     poFDefn->AddSubfield( "RVER", "b12" );
151     poFDefn->AddSubfield( "RUIN", "b11" );
152 
153     oModule.AddField( poFDefn );
154 
155 /* -------------------------------------------------------------------- */
156 /*      Create the ATTV field.                                          */
157 /* -------------------------------------------------------------------- */
158     poFDefn = new DDFFieldDefn();
159 
160     poFDefn->Create( "ATTV", "Vector record attribute field", "",
161                      dsc_vector, dtc_mixed_data_type );
162 
163     /* how do I mark this as repeating? */
164     poFDefn->AddSubfield( "ATTL", "b12" );
165     poFDefn->AddSubfield( "ATVL", "A" );
166 
167     oModule.AddField( poFDefn );
168 
169 /* -------------------------------------------------------------------- */
170 /*      Create the SG2D field.                                          */
171 /* -------------------------------------------------------------------- */
172     poFDefn = new DDFFieldDefn();
173 
174     poFDefn->Create( "SG2D", "2-D coordinate field", "*",
175                      dsc_vector, dtc_mixed_data_type );
176 
177     /* how do I mark this as repeating? */
178     poFDefn->AddSubfield( "YCOO", "b24" );
179     poFDefn->AddSubfield( "XCOO", "b24" );
180 
181     oModule.AddField( poFDefn );
182 
183 /* -------------------------------------------------------------------- */
184 /*      Create the SG3D field.                                          */
185 /* -------------------------------------------------------------------- */
186     poFDefn = new DDFFieldDefn();
187 
188     poFDefn->Create( "SG3D", "3-D coordinate (sounding array) field", "*",
189                      dsc_vector, dtc_mixed_data_type );
190 
191     /* how do I mark this as repeating? */
192     poFDefn->AddSubfield( "YCOO", "b24" );
193     poFDefn->AddSubfield( "XCOO", "b24" );
194     poFDefn->AddSubfield( "VE3D", "b24" );
195 
196     oModule.AddField( poFDefn );
197 
198 /* -------------------------------------------------------------------- */
199 
200 // need to add: VRPC, VRPT, SGCC, FRID, FOID, ATTF, NATF, FFPC,
201 // FFPT, FSPC, and FSPT
202 
203 /* -------------------------------------------------------------------- */
204 /*      Create file.                                                    */
205 /* -------------------------------------------------------------------- */
206     oModule.Dump( stdout );
207 
208     oModule.Create( "out.000" );
209 
210 /* -------------------------------------------------------------------- */
211 /*      Create a record.                                                */
212 /* -------------------------------------------------------------------- */
213     DDFRecord *poRec = new DDFRecord( &oModule );
214     DDFField *poField;
215 
216     poField = poRec->AddField( oModule.FindFieldDefn( "0001" ) );
217     poRec->SetFieldRaw( poField, 0, "\1\0\036", 3 );
218 
219     poField = poRec->AddField( oModule.FindFieldDefn( "DSID" ) );
220 
221     poRec->SetIntSubfield   ( "DSID", 0, "RCNM", 0, 10 );
222     poRec->SetIntSubfield   ( "DSID", 0, "RCID", 0, 1 );
223     poRec->SetIntSubfield   ( "DSID", 0, "EXPP", 0, 1 );
224     poRec->SetIntSubfield   ( "DSID", 0, "INTU", 0, 4 );
225     poRec->SetStringSubfield( "DSID", 0, "DSNM", 0, "GB4X0000.000" );
226     poRec->SetStringSubfield( "DSID", 0, "EDTN", 0, "2" );
227     poRec->SetStringSubfield( "DSID", 0, "UPDN", 0, "0" );
228     poRec->SetStringSubfield( "DSID", 0, "UADT", 0, "20010409" );
229     poRec->SetStringSubfield( "DSID", 0, "ISDT", 0, "20010409" );
230     poRec->SetFloatSubfield ( "DSID", 0, "STED", 0, 3.1 );
231     poRec->SetIntSubfield   ( "DSID", 0, "PRSP", 0, 1 );
232     poRec->SetStringSubfield( "DSID", 0, "PSDN", 0, "" );
233     poRec->SetStringSubfield( "DSID", 0, "PRED", 0, "2.0" );
234     poRec->SetIntSubfield   ( "DSID", 0, "PROF", 0, 1 );
235     poRec->SetIntSubfield   ( "DSID", 0, "AGEN", 0, 540 );
236     poRec->SetStringSubfield( "DSID", 0, "COMT", 0, "" );
237 
238     poField = poRec->AddField( oModule.FindFieldDefn( "DSSI" ) );
239 
240     poRec->SetIntSubfield   ( "DSSI", 0, "DSTR", 0, 2 );
241     poRec->SetIntSubfield   ( "DSSI", 0, "AALL", 0, 1 );
242     poRec->SetIntSubfield   ( "DSSI", 0, "NALL", 0, 1 );
243     poRec->SetIntSubfield   ( "DSSI", 0, "NOMR", 0, 22 );
244     poRec->SetIntSubfield   ( "DSSI", 0, "NOCR", 0, 0 );
245     poRec->SetIntSubfield   ( "DSSI", 0, "NOGR", 0, 2141 );
246     poRec->SetIntSubfield   ( "DSSI", 0, "NOLR", 0, 15 );
247     poRec->SetIntSubfield   ( "DSSI", 0, "NOIN", 0, 512 );
248     poRec->SetIntSubfield   ( "DSSI", 0, "NOCN", 0, 2181 );
249     poRec->SetIntSubfield   ( "DSSI", 0, "NOED", 0, 3192 );
250     poRec->SetIntSubfield   ( "DSSI", 0, "NOFA", 0, 0 );
251 
252     poRec->Write();
253     delete poRec;
254 
255 /* -------------------------------------------------------------------- */
256 /*      Create a record.                                                */
257 /* -------------------------------------------------------------------- */
258     poRec = new DDFRecord( &oModule );
259 
260     poField = poRec->AddField( oModule.FindFieldDefn( "0001" ) );
261     poRec->SetFieldRaw( poField, 0, "\2\0\036", 3 );
262 
263     poField = poRec->AddField( oModule.FindFieldDefn( "DSPM" ) );
264 
265     poRec->SetIntSubfield   ( "DSPM", 0, "RCNM", 0, 20 );
266     poRec->SetIntSubfield   ( "DSPM", 0, "RCID", 0, 1 );
267     poRec->SetIntSubfield   ( "DSPM", 0, "HDAT", 0, 2 );
268     poRec->SetIntSubfield   ( "DSPM", 0, "VDAT", 0, 17 );
269     poRec->SetIntSubfield   ( "DSPM", 0, "SDAT", 0, 23 );
270     poRec->SetIntSubfield   ( "DSPM", 0, "CSCL", 0, 52000 );
271     poRec->SetIntSubfield   ( "DSPM", 0, "DUNI", 0, 1 );
272     poRec->SetIntSubfield   ( "DSPM", 0, "HUNI", 0, 1 );
273     poRec->SetIntSubfield   ( "DSPM", 0, "PUNI", 0, 1 );
274     poRec->SetIntSubfield   ( "DSPM", 0, "COUN", 0, 1 );
275     poRec->SetIntSubfield   ( "DSPM", 0, "COMF", 0, 1000000 );
276     poRec->SetIntSubfield   ( "DSPM", 0, "SOMF", 0, 10 );
277 
278     poRec->Write();
279     delete poRec;
280 
281 /* -------------------------------------------------------------------- */
282 /*      Create a record.                                                */
283 /* -------------------------------------------------------------------- */
284     poRec = new DDFRecord( &oModule );
285 
286     poField = poRec->AddField( oModule.FindFieldDefn( "0001" ) );
287     poRec->SetFieldRaw( poField, 0, "\3\0\036", 3 );
288 
289     poField = poRec->AddField( oModule.FindFieldDefn( "VRID" ) );
290 
291     poRec->SetIntSubfield   ( "VRID", 0, "RCNM", 0, 110 );
292     poRec->SetIntSubfield   ( "VRID", 0, "RCID", 0, 518 );
293     poRec->SetIntSubfield   ( "VRID", 0, "RVER", 0, 1 );
294     poRec->SetIntSubfield   ( "VRID", 0, "RUIN", 0, 1 );
295 
296     poField = poRec->AddField( oModule.FindFieldDefn( "SG3D" ) );
297 
298     poRec->SetIntSubfield   ( "SG3D", 0, "YCOO", 0, -325998702 );
299     poRec->SetIntSubfield   ( "SG3D", 0, "XCOO", 0, 612175350 );
300     poRec->SetIntSubfield   ( "SG3D", 0, "VE3D", 0, 174 );
301 
302     poRec->SetIntSubfield   ( "SG3D", 0, "YCOO", 1, -325995189 );
303     poRec->SetIntSubfield   ( "SG3D", 0, "XCOO", 1, 612228812 );
304     poRec->SetIntSubfield   ( "SG3D", 0, "VE3D", 1, 400 );
305 
306     poRec->Write();
307 
308     delete poRec;
309 }
310 
311 /************************************************************************/
312 /*                             mk_catalog()                             */
313 /************************************************************************/
314 
mk_catalog()315 void mk_catalog()
316 
317 {
318     DDFModule  oModule;
319     DDFFieldDefn *poFDefn;
320 
321     oModule.Initialize();
322 
323 /* -------------------------------------------------------------------- */
324 /*      Create the '0000' definition.                                   */
325 /* -------------------------------------------------------------------- */
326     poFDefn = new DDFFieldDefn();
327 
328     poFDefn->Create( "0000", "", "0001CATD",
329                      dsc_elementary,
330                      dtc_char_string );
331 
332     oModule.AddField( poFDefn );
333 
334 /* -------------------------------------------------------------------- */
335 /*      Create the '0000' definition.                                   */
336 /* -------------------------------------------------------------------- */
337     poFDefn = new DDFFieldDefn();
338 
339     poFDefn->Create( "0001", "ISO 8211 Record Identifier", "",
340                      dsc_elementary, dtc_bit_string,
341                      "(b12)" );
342 
343     oModule.AddField( poFDefn );
344 
345 /* -------------------------------------------------------------------- */
346 /*      Create the CATD field.                                          */
347 /* -------------------------------------------------------------------- */
348     poFDefn = new DDFFieldDefn();
349 
350     poFDefn->Create( "CATD", "Catalog Directory field", "",
351                      dsc_vector, dtc_mixed_data_type );
352 
353     poFDefn->AddSubfield( "RCNM", "A(2)" );
354     poFDefn->AddSubfield( "RCID", "I(10)" );
355     poFDefn->AddSubfield( "FILE", "A" );
356     poFDefn->AddSubfield( "LFIL", "A" );
357     poFDefn->AddSubfield( "VOLM", "A" );
358     poFDefn->AddSubfield( "IMPL", "A(3)" );
359     poFDefn->AddSubfield( "SLAT", "R" );
360     poFDefn->AddSubfield( "WLON", "R" );
361     poFDefn->AddSubfield( "NLAT", "R" );
362     poFDefn->AddSubfield( "ELON", "R" );
363     poFDefn->AddSubfield( "CRCS", "A" );
364     poFDefn->AddSubfield( "COMT", "A" );
365 
366     oModule.AddField( poFDefn );
367 
368     oModule.Dump( stdout );
369 
370     oModule.Create( "out.ddf" );
371 
372 /* -------------------------------------------------------------------- */
373 /*      Create a record.                                                */
374 /* -------------------------------------------------------------------- */
375     DDFRecord *poRec = new DDFRecord( &oModule );
376     DDFField *poField;
377 
378     poField = poRec->AddField( oModule.FindFieldDefn( "0001" ) );
379     poRec->SetFieldRaw( poField, 0, "\0\0\036", 3 );
380 
381     poField = poRec->AddField( oModule.FindFieldDefn( "CATD" ) );
382     poRec->SetStringSubfield( "CATD", 0, "RCNM", 0, "CD" );
383     poRec->SetIntSubfield   ( "CATD", 0, "RCID", 0, 1 );
384     poRec->SetStringSubfield( "CATD", 0, "FILE", 0, "CATALOG.030" );
385     poRec->SetStringSubfield( "CATD", 0, "VOLM", 0, "V01X01" );
386     poRec->SetStringSubfield( "CATD", 0, "IMPL", 0, "ASC" );
387     poRec->SetStringSubfield( "CATD", 0, "COMT", 0,
388                               "Exchange Set Catalog file" );
389     poRec->Write();
390     delete poRec;
391 
392 /* -------------------------------------------------------------------- */
393 /*      Create a record.                                                */
394 /* -------------------------------------------------------------------- */
395     poRec = new DDFRecord( &oModule );
396 
397     poField = poRec->AddField( oModule.FindFieldDefn( "0001" ) );
398     poRec->SetFieldRaw( poField, 0, "\1\0\036", 3 );
399 
400     poField = poRec->AddField( oModule.FindFieldDefn( "CATD" ) );
401     poRec->SetStringSubfield( "CATD", 0, "RCNM", 0, "CD" );
402     poRec->SetIntSubfield   ( "CATD", 0, "RCID", 0, 2 );
403     poRec->SetStringSubfield( "CATD", 0, "FILE", 0, "No410810.000" );
404     poRec->SetStringSubfield( "CATD", 0, "VOLM", 0, "V01X01" );
405     poRec->SetStringSubfield( "CATD", 0, "IMPL", 0, "BIN" );
406     poRec->SetFloatSubfield ( "CATD", 0, "SLAT", 0, 59.000005 );
407     poRec->SetFloatSubfield ( "CATD", 0, "WLON", 0, 4.999996 );
408     poRec->SetFloatSubfield ( "CATD", 0, "NLAT", 0, 59.500003 );
409     poRec->SetFloatSubfield ( "CATD", 0, "ELON", 0, 5.499997 );
410     poRec->SetStringSubfield( "CATD", 0, "CRCS", 0, "555C3AD4" );
411     poRec->Write();
412     delete poRec;
413 }
414 
415 /* **********************************************************************/
416 /*                                main()                                */
417 /* **********************************************************************/
418 
main(int nArgc,char ** papszArgv)419 int main( int nArgc, char ** papszArgv )
420 
421 {
422     mk_s57();
423 }
424 
425