Sophie

Sophie

distrib > Mandriva > 9.0 > i586 > by-pkgid > d67485fb8ce60f8952179bbde3b5d022 > files > 106

libgdal0-devel-1.1.7-2mdk.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><meta name="robots" content="noindex">
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>gdalopen.cpp Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body bgcolor="#ffffff">
<!-- Generated by Doxygen 1.2.3-20001105 on Thu Mar 28 09:47:30 2002 -->
<center>
<a class="qindex" href="index.html">Main Page</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="annotated.html">Compound List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; <a class="qindex" href="globals.html">File Members</a> &nbsp; <a class="qindex" href="pages.html">Related Pages</a> &nbsp; </center>
<hr><h1>gdalopen.cpp</h1><div class="fragment"><pre>00001 <font class="comment">/******************************************************************************</font>
00002 <font class="comment"> * Copyright (c) 1998, Frank Warmerdam</font>
00003 <font class="comment"> *</font>
00004 <font class="comment"> * Permission is hereby granted, free of charge, to any person obtaining a</font>
00005 <font class="comment"> * copy of this software and associated documentation files (the "Software"),</font>
00006 <font class="comment"> * to deal in the Software without restriction, including without limitation</font>
00007 <font class="comment"> * the rights to use, copy, modify, merge, publish, distribute, sublicense,</font>
00008 <font class="comment"> * and/or sell copies of the Software, and to permit persons to whom the</font>
00009 <font class="comment"> * Software is furnished to do so, subject to the following conditions:</font>
00010 <font class="comment"> *</font>
00011 <font class="comment"> * The above copyright notice and this permission notice shall be included</font>
00012 <font class="comment"> * in all copies or substantial portions of the Software.</font>
00013 <font class="comment"> *</font>
00014 <font class="comment"> * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS</font>
00015 <font class="comment"> * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,</font>
00016 <font class="comment"> * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL</font>
00017 <font class="comment"> * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER</font>
00018 <font class="comment"> * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING</font>
00019 <font class="comment"> * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER</font>
00020 <font class="comment"> * DEALINGS IN THE SOFTWARE.</font>
00021 <font class="comment"> ******************************************************************************</font>
00022 <font class="comment"> *</font>
00023 <font class="comment"> * gdalopen.c</font>
00024 <font class="comment"> *</font>
00025 <font class="comment"> * GDALOpen() function, and supporting functions.</font>
00026 <font class="comment"> *</font>
00027 <font class="comment"> * </font>
00028 <font class="comment"> * $Log: gdalopen_cpp-source.html,v $
00028 <font class="comment"> * Revision 1.10  2002/04/16 13:11:48  warmerda
00028 <font class="comment"> * updated
00028 <font class="comment"> *</font>
00029 <font class="comment"> * Revision 1.12  2001/12/12 17:21:21  warmerda</font>
00030 <font class="comment"> * Use CPLStat instead of VSIStat().</font>
00031 <font class="comment"> *</font>
00032 <font class="comment"> * Revision 1.11  2001/08/20 13:40:28  warmerda</font>
00033 <font class="comment"> * modified message on failure to open if not a file</font>
00034 <font class="comment"> *</font>
00035 <font class="comment"> * Revision 1.10  2001/07/18 04:04:30  warmerda</font>
00036 <font class="comment"> * added CPL_CVSID</font>
00037 <font class="comment"> *</font>
00038 <font class="comment"> * Revision 1.9  2001/01/03 05:32:20  warmerda</font>
00039 <font class="comment"> * avoid depending on VSIStatBuf file size for 2GB issues</font>
00040 <font class="comment"> *</font>
00041 <font class="comment"> * Revision 1.8  2000/04/21 21:55:53  warmerda</font>
00042 <font class="comment"> * set filename as description of GDALDatasets.</font>
00043 <font class="comment"> *</font>
00044 <font class="comment"> * Revision 1.7  2000/01/10 15:43:06  warmerda</font>
00045 <font class="comment"> * Fixed debug statement.</font>
00046 <font class="comment"> *</font>
00047 <font class="comment"> * Revision 1.6  2000/01/10 15:31:02  warmerda</font>
00048 <font class="comment"> * Added debug statement in GDALOpen.</font>
00049 <font class="comment"> *</font>
00050 <font class="comment"> * Revision 1.5  1999/11/11 21:59:07  warmerda</font>
00051 <font class="comment"> * added GetDriver() for datasets</font>
00052 <font class="comment"> *</font>
00053 <font class="comment"> * Revision 1.4  1999/10/01 14:44:02  warmerda</font>
00054 <font class="comment"> * added documentation</font>
00055 <font class="comment"> *</font>
00056 <font class="comment"> * Revision 1.3  1999/04/21 04:00:34  warmerda</font>
00057 <font class="comment"> * Initialize fp to NULL.</font>
00058 <font class="comment"> *</font>
00059 <font class="comment"> * Revision 1.2  1998/12/31 18:52:45  warmerda</font>
00060 <font class="comment"> * Use CPL memory functions (they are safe), and fixed up header reading.</font>
00061 <font class="comment"> *</font>
00062 <font class="comment"> * Revision 1.1  1998/12/03 18:31:45  warmerda</font>
00063 <font class="comment"> * New</font>
00064 <font class="comment"> *</font>
00065 <font class="comment"> */</font>
00066 
00067 <font class="preprocessor">#include "gdal_priv.h"</font>
00068 <font class="preprocessor">#include "<a class="code" href="cpl_conv_h.html">cpl_conv.h</a>"</font>
00069 
00070 CPL_CVSID(<font class="stringliteral">"$Id: gdalopen_cpp-source.html,v 1.10 2002/04/16 13:11:48 warmerda Exp $"</font>);
00071 
00072 <font class="comment">/************************************************************************/</font>
00073 <font class="comment">/* ==================================================================== */</font>
00074 <font class="comment">/*                             GDALOpenInfo                             */</font>
00075 <font class="comment">/* ==================================================================== */</font>
00076 <font class="comment">/************************************************************************/</font>
00077 
00078 <font class="comment">/************************************************************************/</font>
00079 <font class="comment">/*                            GDALOpenInfo()                            */</font>
00080 <font class="comment">/************************************************************************/</font>
00081 
00082 GDALOpenInfo::GDALOpenInfo( <font class="keyword">const</font> <font class="keywordtype">char</font> * pszFilenameIn, GDALAccess eAccessIn )<font class="keyword"></font>
00083 <font class="keyword"></font>
00084 <font class="keyword"></font>{
00085     pszFilename = <a class="code" href="cpl_conv_h.html#a6">CPLStrdup</a>( pszFilenameIn );
00086 
00087     nHeaderBytes = 0;
00088     pabyHeader = NULL;
00089     bStatOK = FALSE;
00090     eAccess = eAccessIn;
00091     fp = NULL;
00092     
00093 <font class="comment">/* -------------------------------------------------------------------- */</font>
00094 <font class="comment">/*      Collect information about the file.                             */</font>
00095 <font class="comment">/* -------------------------------------------------------------------- */</font>
00096     <font class="keywordflow">if</font>( CPLStat( pszFilename, &amp;sStat ) == 0 )
00097     {
00098         bStatOK = TRUE;
00099 
00100         <font class="keywordflow">if</font>( VSI_ISREG( sStat.st_mode ) )
00101         {
00102             pabyHeader = (GByte *) <a class="code" href="cpl_conv_h.html#a4">CPLCalloc</a>(1025,1);
00103 
00104             fp = VSIFOpen( pszFilename, <font class="stringliteral">"rb"</font> );
00105 
00106             <font class="keywordflow">if</font>( fp != NULL )
00107             {
00108                 nHeaderBytes = VSIFRead( pabyHeader, 1, 1024, fp );
00109 
00110                 VSIRewind( fp );
00111             }
00112         }
00113     }
00114 }
00115 
00116 <font class="comment">/************************************************************************/</font>
00117 <font class="comment">/*                           ~GDALOpenInfo()                            */</font>
00118 <font class="comment">/************************************************************************/</font>
00119 
00120 GDALOpenInfo::~GDALOpenInfo()<font class="keyword"></font>
00121 <font class="keyword"></font>
00122 <font class="keyword"></font>{
00123     VSIFree( pabyHeader );
00124     CPLFree( pszFilename );
00125 
00126     <font class="keywordflow">if</font>( fp != NULL )
00127         VSIFClose( fp );
00128 }
00129 
00130 <font class="comment">/************************************************************************/</font>
00131 <font class="comment">/*                              GDALOpen()                              */</font>
00132 <font class="comment">/************************************************************************/</font>
00133 
<a name="l00149"></a><a class="code" href="class_GDALDataset.html#l2">00149</a> GDALDatasetH <a class="code" href="gdal_h.html#a60">GDALOpen</a>( <font class="keyword">const</font> <font class="keywordtype">char</font> * pszFilename, GDALAccess eAccess )<font class="keyword"></font>
00150 <font class="keyword"></font>
00151 <font class="keyword"></font>{
00152     <font class="keywordtype">int</font>         iDriver;
00153     <a class="code" href="class_GDALDriverManager.html">GDALDriverManager</a> *poDM = GetGDALDriverManager();
00154     GDALOpenInfo oOpenInfo( pszFilename, eAccess );
00155 
00156     <a class="code" href="cpl_error_h.html#a19">CPLErrorReset</a>();
00157     
00158     <font class="keywordflow">for</font>( iDriver = 0; iDriver &lt; poDM-&gt;GetDriverCount(); iDriver++ )
00159     {
00160         <a class="code" href="class_GDALDriver.html">GDALDriver</a>      *poDriver = poDM-&gt;<a class="code" href="class_GDALDriverManager.html#a3">GetDriver</a>( iDriver );
00161         <a class="code" href="class_GDALDataset.html">GDALDataset</a>     *poDS;
00162 
00163         poDS = poDriver-&gt;pfnOpen( &amp;oOpenInfo );
00164         <font class="keywordflow">if</font>( poDS != NULL )
00165         {
00166             poDS-&gt;SetDescription( pszFilename );
00167 
00168             <font class="keywordflow">if</font>( poDS-&gt;poDriver == NULL )
00169                 poDS-&gt;poDriver = poDriver;
00170 
00171             <a class="code" href="cpl_error_h.html#a29">CPLDebug</a>( <font class="stringliteral">"GDAL"</font>, <font class="stringliteral">"GDALOpen(%s) succeeds as %s.\n"</font>,
00172                       pszFilename, poDriver-&gt;pszLongName );
00173 
00174             <font class="keywordflow">return</font> (GDALDatasetH) poDS;
00175         }
00176 
00177         <font class="keywordflow">if</font>( <a class="code" href="cpl_error_h.html#a20">CPLGetLastErrorNo</a>() != 0 )
00178             <font class="keywordflow">return</font> NULL;
00179     }
00180 
00181     <font class="keywordflow">if</font>( oOpenInfo.bStatOK )
00182         <a class="code" href="cpl_error_h.html#a17">CPLError</a>( CE_Failure, CPLE_OpenFailed,
00183                   <font class="stringliteral">"`%s' not recognised as a supported file format.\n"</font>,
00184                   pszFilename );
00185     <font class="keywordflow">else</font>
00186         <a class="code" href="cpl_error_h.html#a17">CPLError</a>( CE_Failure, CPLE_OpenFailed,
00187                   <font class="stringliteral">"`%s' does not exist in the file system,\n"</font>
00188                   <font class="stringliteral">"and is not recognised as a supported dataset name.\n"</font>,
00189                   pszFilename );
00190               
00191     <font class="keywordflow">return</font> NULL;
00192 }
00193 
</div></pre><hr><address><small>Generated at Thu Mar 28 09:47:30 2002 for GDAL by
<a href="http://www.stack.nl/~dimitri/doxygen/index.html">
<img src="doxygen.gif" alt="doxygen" align="middle" border=0 
width=110 height=53></a>1.2.3-20001105 written by <a href="mailto:dimitri@stack.nl">Dimitri van Heesch</a>,
 &copy;&nbsp;1997-2000</small></address>
</body>
</html>