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