1 /******************************************************************************
2 *
3 * Project: NTF Translator
4 * Purpose: Simple test harness.
5 * Author: Frank Warmerdam, warmerdam@pobox.com
6 *
7 ******************************************************************************
8 * Copyright (c) 1999, Frank Warmerdam
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 "ntf.h"
30 #include "cpl_vsi.h"
31 #include "cpl_string.h"
32
33 CPL_CVSID("$Id: ntfdump.cpp ff8146d84de7cba8e09d212d5481ea7d2ede3e98 2017-06-27 20:47:31Z Even Rouault $")
34
35 static void NTFDump( const char * pszFile, char **papszOptions );
36 static void NTFCount( const char * pszFile );
37
38 /************************************************************************/
39 /* main() */
40 /************************************************************************/
41
main(int argc,char ** argv)42 int main( int argc, char ** argv )
43
44 {
45 const char *pszMode = "-d";
46 char **papszOptions = NULL;
47
48 if( argc == 1 )
49 printf( "Usage: ntfdump [-s n] [-g] [-d] [-c] [-codelist] files\n" );
50
51 for( int i = 1; i < argc; i++ )
52 {
53 if( EQUAL(argv[i],"-g") )
54 papszOptions = CSLSetNameValue( papszOptions,
55 "FORCE_GENERIC", "ON" );
56 else if( EQUAL(argv[i],"-s") )
57 {
58 papszOptions = CSLSetNameValue( papszOptions,
59 "DEM_SAMPLE", argv[++i] );
60 }
61 else if( EQUAL(argv[i],"-codelist") )
62 {
63 papszOptions = CSLSetNameValue( papszOptions,
64 "CODELIST", "ON" );
65 }
66 else if( argv[i][0] == '-' )
67 pszMode = argv[i];
68 else if( EQUAL(pszMode,"-d") )
69 NTFDump( argv[i], papszOptions );
70 else if( EQUAL(pszMode,"-c") )
71 NTFCount( argv[i] );
72 }
73
74 return 0;
75 }
76
77 /************************************************************************/
78 /* NTFCount() */
79 /************************************************************************/
80
NTFCount(const char * pszFile)81 static void NTFCount( const char * pszFile )
82
83 {
84 FILE *fp = VSIFOpen( pszFile, "r" );
85 if( fp == NULL )
86 return;
87
88 int anCount[100] = {};
89
90 NTFRecord *poRecord = NULL;
91 do {
92 if( poRecord != NULL )
93 delete poRecord;
94
95 poRecord = new NTFRecord( fp );
96 anCount[poRecord->GetType()]++;
97 } while( poRecord->GetType() != 99 );
98
99 VSIFClose( fp );
100
101 printf( "\nReporting on: %s\n", pszFile );
102 for( int i = 0; i < 100; i++ )
103 {
104 if( anCount[i] > 0 )
105 printf( "Found %d records of type %d\n", anCount[i], i );
106 }
107 }
108
109 /************************************************************************/
110 /* NTFDump() */
111 /************************************************************************/
112
NTFDump(const char * pszFile,char ** papszOptions)113 static void NTFDump( const char * pszFile, char **papszOptions )
114
115 {
116 OGRNTFDataSource oDS;
117
118 oDS.SetOptionList( papszOptions );
119
120 if( !oDS.Open( pszFile ) )
121 return;
122
123 OGRFeature *poFeature = NULL;
124 while( (poFeature = oDS.GetNextFeature()) != NULL )
125 {
126 printf( "-------------------------------------\n" );
127 poFeature->DumpReadable( stdout );
128 delete poFeature;
129 }
130 }
131