1 /******************************************************************************
2  *
3  * Project:  SDTS Translator
4  * Purpose:  Implementation of SDTS_XREF class for reading XREF module.
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 "sdts_al.h"
30 
31 CPL_CVSID("$Id: sdtsxref.cpp 7e07230bbff24eb333608de4dbd460b7312839d0 2017-12-11 19:08:47Z Even Rouault $")
32 
33 /************************************************************************/
34 /*                             SDTS_XREF()                              */
35 /************************************************************************/
36 
SDTS_XREF()37 SDTS_XREF::SDTS_XREF() :
38     pszSystemName(CPLStrdup("")),
39     pszDatum(CPLStrdup("")),
40     nZone(0)
41 {}
42 
43 /************************************************************************/
44 /*                             ~SDTS_XREF()                             */
45 /************************************************************************/
46 
~SDTS_XREF()47 SDTS_XREF::~SDTS_XREF()
48 {
49     CPLFree( pszSystemName );
50     CPLFree( pszDatum );
51 }
52 
53 /************************************************************************/
54 /*                                Read()                                */
55 /*                                                                      */
56 /*      Read the named file to initialize this structure.               */
57 /************************************************************************/
58 
Read(const char * pszFilename)59 int SDTS_XREF::Read( const char * pszFilename )
60 
61 {
62 /* -------------------------------------------------------------------- */
63 /*      Open the file, and read the header.                             */
64 /* -------------------------------------------------------------------- */
65     DDFModule oXREFFile;
66     if( !oXREFFile.Open( pszFilename ) )
67         return FALSE;
68 
69 /* -------------------------------------------------------------------- */
70 /*      Read the first record, and verify that this is an XREF record.  */
71 /* -------------------------------------------------------------------- */
72     DDFRecord *poRecord = oXREFFile.ReadRecord();
73     if( poRecord == nullptr )
74         return FALSE;
75 
76     if( poRecord->GetStringSubfield( "XREF", 0, "MODN", 0 ) == nullptr )
77         return FALSE;
78 
79 /* -------------------------------------------------------------------- */
80 /*      Read fields of interest.                                        */
81 /* -------------------------------------------------------------------- */
82 
83     CPLFree( pszSystemName );
84     pszSystemName =
85         CPLStrdup( poRecord->GetStringSubfield( "XREF", 0, "RSNM", 0 ) );
86 
87     CPLFree( pszDatum );
88     pszDatum =
89         CPLStrdup( poRecord->GetStringSubfield( "XREF", 0, "HDAT", 0 ) );
90 
91     nZone = poRecord->GetIntSubfield( "XREF", 0, "ZONE", 0 );
92 
93     return TRUE;
94 }
95