Changeset 13182

Show
Ignore:
Timestamp:
12/01/07 14:47:15 (7 months ago)
Author:
warmerdam
Message:

major update provided by Bruce Payne

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/warmerdam/1.4-esri/gdal/frmts/raw/envidataset.cpp

    r12325 r13182  
    3535 
    3636CPL_C_START 
    37 void   GDALRegister_ENVI(void); 
     37void GDALRegister_ENVI(void); 
    3838CPL_C_END 
    3939 
     
    228228    int         ReadHeader( FILE * ); 
    229229    int         ProcessMapinfo( const char * ); 
    230     void        ProcessRPCinfo( const char * ); 
     230    void        ProcessRPCinfo( const char * ,int ,int); 
     231    void        ProcessStatsFile(); 
     232    long        byteSwapLong(long); 
     233    float       byteSwapFloat(float); 
     234    double      byteSwapDouble(double); 
    231235    void        SetENVIDatum( OGRSpatialReference *, const char * ); 
    232236    void        SetENVIEllipse( OGRSpatialReference *, char ** ); 
     
    239243 
    240244  public: 
    241                ENVIDataset(); 
    242                ~ENVIDataset(); 
     245            ENVIDataset(); 
     246            ~ENVIDataset(); 
    243247 
    244248    virtual void    FlushCache( void ); 
     
    306310    RawDataset::FlushCache(); 
    307311 
    308     if ( !bHeaderDirty
     312    if ( !bHeaderDirty
    309313        return; 
    310314 
     315    /* Retrieve the old system locale so we can restore it later. */ 
     316    char *strLocale, strLocaleReset[1024]; 
     317    strLocale = setlocale(LC_NUMERIC, NULL); 
     318    /* Make a copy as the return value does change.  */ 
     319    strncpy(strLocaleReset, strLocale, 1024); 
     320    /* Set to a default numeric locale with radix character '.'. */ 
     321    strLocale = setlocale(LC_NUMERIC, "C"); 
    311322    VSIFSeek( fp, 0, SEEK_SET ); 
    312  
    313323/* -------------------------------------------------------------------- */ 
    314324/*      Rewrite out the header.                                           */ 
     
    318328    const char  *pszInterleaving; 
    319329    char** catNames; 
    320      
     330 
    321331#ifdef CPL_LSB 
    322332    iBigEndian = 0; 
     
    333343    GDALRasterBand* band = GetRasterBand(1); 
    334344    catNames = band->GetCategoryNames(); 
     345 
    335346    VSIFPrintf( fp, "header offset = 0\n"); 
    336347    if (0 == catNames) 
     
    338349    else 
    339350        VSIFPrintf( fp, "file type = ENVI Classification\n" ); 
     351 
    340352    int iENVIType = GetEnviType(band->GetRasterDataType()); 
    341353    VSIFPrintf( fp, "data type = %d\n", iENVIType ); 
     
    357369    VSIFPrintf( fp, "interleave = %s\n", pszInterleaving); 
    358370    VSIFPrintf( fp, "byte order = %d\n", iBigEndian ); 
    359  
    360371 
    361372/* -------------------------------------------------------------------- */ 
     
    414425/* -------------------------------------------------------------------- */ 
    415426    WriteProjectionInfo(); 
     427 
     428 
    416429    VSIFPrintf( fp, "band names = {\n" ); 
    417430    for ( int i = 1; i <= nBands; i++ ) 
     
    426439    } 
    427440    VSIFPrintf( fp, "}\n" ); 
     441 
     442    /* Reset to the system locale. */ 
     443    setlocale(LC_NUMERIC, strLocaleReset); 
     444 
    428445} 
    429446 
     
    725742                    osCommaDatum.c_str(), osOptionalUnits.c_str() ); 
    726743 
    727         VSIFPrintf( fp, "projection info = {9, %.16g, %.16g, %.16g, %.16g, %.16g, %.16g, %.16g, %.16g%s, Albers Conical Equal Area}\n", 
     744       VSIFPrintf( fp, "projection info = {9, %.16g, %.16g, %.16g, %.16g, %.16g, %.16g, %.16g, %.16g%s, Albers Conical Equal Area}\n", 
    728745                    dfA, dfB,  
    729746                    oSRS.GetNormProjParm(SRS_PP_LATITUDE_OF_ORIGIN,0.0), 
     
    932949    else if( EQUAL(pszENVIDatumName, "Geocentric Datum of Australia 1994") ) 
    933950        poSRS->SetWellKnownGeogCS( "EPSG:4283" ); 
     951    else if( EQUAL(pszENVIDatumName, "Australian Geodetic 1984") ) 
     952        poSRS->SetWellKnownGeogCS( "EPSG:4203" ); 
    934953    else if( EQUAL(pszENVIDatumName, "Nouvelle Triangulation Francaise IGN") ) 
    935954        poSRS->SetWellKnownGeogCS( "EPSG:4275" ); 
     
    10331052            SetENVIDatum( &oSRS, papszFields[9] ); 
    10341053        else 
    1035             oSRS.SetWellKnownGeogCS( "WGS84" ); 
     1054            oSRS.SetWellKnownGeogCS( "NAD27" ); 
    10361055    } 
    10371056    else if( EQUALN(papszFields[0],"State Plane (NAD 27)",19) 
     
    12221241/************************************************************************/ 
    12231242 
    1224 void ENVIDataset::ProcessRPCinfo( const char *pszRPCinfo ) 
     1243void ENVIDataset::ProcessRPCinfo( const char *pszRPCinfo,  
     1244                                 int numCols, int numRows) 
    12251245{ 
    12261246    char        **papszFields; 
     
    12371257    } 
    12381258         
    1239     snprintf(sVal, sizeof(sVal),  "%.16f",atof(papszFields[0])); 
     1259    snprintf(sVal, sizeof(sVal),  "%.16g",atof(papszFields[0])); 
    12401260    SetMetadataItem("RPC_LINE_OFF",sVal); 
    1241     snprintf(sVal, sizeof(sVal),  "%.16f",atof(papszFields[5])); 
     1261    snprintf(sVal, sizeof(sVal),  "%.16g",atof(papszFields[5])); 
    12421262    SetMetadataItem("RPC_LINE_SCALE",sVal); 
    1243     snprintf(sVal, sizeof(sVal),  "%.16f",atof(papszFields[1])); 
     1263    snprintf(sVal, sizeof(sVal),  "%.16g",atof(papszFields[1])); 
    12441264    SetMetadataItem("RPC_SAMP_OFF",sVal); 
    1245     snprintf(sVal, sizeof(sVal),  "%.16f",atof(papszFields[6])); 
     1265    snprintf(sVal, sizeof(sVal),  "%.16g",atof(papszFields[6])); 
    12461266    SetMetadataItem("RPC_SAMP_SCALE",sVal); 
    1247     snprintf(sVal, sizeof(sVal),  "%.16f",atof(papszFields[2])); 
     1267    snprintf(sVal, sizeof(sVal),  "%.16g",atof(papszFields[2])); 
    12481268    SetMetadataItem("RPC_LAT_OFF",sVal); 
    1249     snprintf(sVal, sizeof(sVal),  "%.16f",atof(papszFields[7])); 
     1269    snprintf(sVal, sizeof(sVal),  "%.16g",atof(papszFields[7])); 
    12501270    SetMetadataItem("RPC_LAT_SCALE",sVal); 
    1251     snprintf(sVal, sizeof(sVal),  "%.16f",atof(papszFields[3])); 
     1271    snprintf(sVal, sizeof(sVal),  "%.16g",atof(papszFields[3])); 
    12521272    SetMetadataItem("RPC_LONG_OFF",sVal); 
    1253     snprintf(sVal, sizeof(sVal),  "%.16f",atof(papszFields[8])); 
     1273    snprintf(sVal, sizeof(sVal),  "%.16g",atof(papszFields[8])); 
    12541274    SetMetadataItem("RPC_LONG_SCALE",sVal); 
    1255     snprintf(sVal, sizeof(sVal),  "%.16f",atof(papszFields[4])); 
     1275    snprintf(sVal, sizeof(sVal),  "%.16g",atof(papszFields[4])); 
    12561276    SetMetadataItem("RPC_HEIGHT_OFF",sVal); 
    1257     snprintf(sVal, sizeof(sVal),  "%.16f",atof(papszFields[9])); 
     1277    snprintf(sVal, sizeof(sVal),  "%.16g",atof(papszFields[9])); 
    12581278    SetMetadataItem("RPC_HEIGHT_SCALE",sVal); 
    12591279 
    12601280    sVal[0] = '\0';  
    12611281    for(int i = 0; i < 20; i++ ) 
    1262        snprintf(sVal+strlen(sVal), sizeof(sVal),  "%.16f ",  
     1282       snprintf(sVal+strlen(sVal), sizeof(sVal),  "%.16g ",  
    12631283           atof(papszFields[10+i])); 
    12641284    SetMetadataItem("RPC_LINE_NUM_COEFF",sVal); 
     
    12661286    sVal[0] = '\0';  
    12671287    for(int i = 0; i < 20; i++ ) 
    1268        snprintf(sVal+strlen(sVal), sizeof(sVal),  "%.16f ", 
     1288       snprintf(sVal+strlen(sVal), sizeof(sVal),  "%.16g ", 
    12691289           atof(papszFields[30+i])); 
    12701290    SetMetadataItem("RPC_LINE_DEN_COEFF",sVal); 
     
    12721292    sVal[0] = '\0';  
    12731293    for(int i = 0; i < 20; i++ ) 
    1274        snprintf(sVal+strlen(sVal), sizeof(sVal),  "%.16f ", 
     1294       snprintf(sVal+strlen(sVal), sizeof(sVal),  "%.16g ", 
    12751295           atof(papszFields[50+i])); 
    12761296    SetMetadataItem("RPC_SAMP_NUM_COEFF",sVal); 
     
    12781298    sVal[0] = '\0';  
    12791299    for(int i = 0; i < 20; i++ ) 
    1280        snprintf(sVal+strlen(sVal), sizeof(sVal),  "%.16f ", 
     1300       snprintf(sVal+strlen(sVal), sizeof(sVal),  "%.16g ", 
    12811301           atof(papszFields[70+i])); 
    12821302    SetMetadataItem("RPC_SAMP_DEN_COEFF",sVal); 
    12831303         
    1284     snprintf(sVal, sizeof(sVal), "%.16f",  
    1285         atof(papszFields[3]) - atof(papszFields[8]) / 2.0 ); 
     1304    snprintf(sVal, sizeof(sVal), "%.16g",  
     1305        atof(papszFields[3]) - atof(papszFields[8])); 
    12861306    SetMetadataItem("RPC_MIN_LONG",sVal); 
    12871307 
    1288     snprintf(sVal, sizeof(sVal), "%.16f",  
    1289         atof(papszFields[3]) + atof(papszFields[8]) / 2.0 ); 
     1308    snprintf(sVal, sizeof(sVal), "%.16g",  
     1309        atof(papszFields[3]) + atof(papszFields[8]) ); 
    12901310    SetMetadataItem("RPC_MAX_LONG",sVal); 
    12911311 
    1292     snprintf(sVal, sizeof(sVal), "%.16f", 
    1293         atof(papszFields[2]) - atof(papszFields[7]) / 2.0 ); 
     1312    snprintf(sVal, sizeof(sVal), "%.16g", 
     1313        atof(papszFields[2]) - atof(papszFields[7])); 
    12941314    SetMetadataItem("RPC_MIN_LAT",sVal); 
    12951315 
    1296     snprintf(sVal, sizeof(sVal), "%.16f", 
    1297         atof(papszFields[2]) + atof(papszFields[7]) / 2.0 ); 
     1316    snprintf(sVal, sizeof(sVal), "%.16g", 
     1317        atof(papszFields[2]) + atof(papszFields[7])); 
    12981318    SetMetadataItem("RPC_MAX_LAT",sVal); 
    12991319 
    1300 
     1320    /*   Handle the chipping case where the image is a subset. */ 
     1321    double rowOffset, colOffset; 
     1322    rowOffset = atof(papszFields[90]); 
     1323    colOffset = atof(papszFields[91]); 
     1324    if (rowOffset || colOffset) 
     1325    { 
     1326        SetMetadataItem("ICHIP_SCALE_FACTOR", "1"); 
     1327        SetMetadataItem("ICHIP_ANAMORPH_CORR", "0"); 
     1328        SetMetadataItem("ICHIP_SCANBLK_NUM", "0"); 
     1329 
     1330        SetMetadataItem("ICHIP_OP_ROW_11", "0.5"); 
     1331        SetMetadataItem("ICHIP_OP_COL_11", "0.5"); 
     1332        SetMetadataItem("ICHIP_OP_ROW_12", "0.5"); 
     1333        SetMetadataItem("ICHIP_OP_COL_21", "0.5"); 
     1334        snprintf(sVal, sizeof(sVal), "%.16g", numCols - 0.5); 
     1335        SetMetadataItem("ICHIP_OP_COL_12", sVal); 
     1336        SetMetadataItem("ICHIP_OP_COL_22", sVal); 
     1337        snprintf(sVal, sizeof(sVal), "%.16g", numRows - 0.5); 
     1338        SetMetadataItem("ICHIP_OP_ROW_21", sVal); 
     1339        SetMetadataItem("ICHIP_OP_ROW_22", sVal); 
     1340 
     1341        snprintf(sVal, sizeof(sVal), "%.16g", rowOffset + 0.5); 
     1342        SetMetadataItem("ICHIP_FI_ROW_11", sVal); 
     1343        SetMetadataItem("ICHIP_FI_ROW_12", sVal); 
     1344        snprintf(sVal, sizeof(sVal), "%.16g", colOffset + 0.5); 
     1345        SetMetadataItem("ICHIP_FI_COL_11", sVal); 
     1346        SetMetadataItem("ICHIP_FI_COL_21", sVal); 
     1347        snprintf(sVal, sizeof(sVal), "%.16g", colOffset + numCols - 0.5); 
     1348        SetMetadataItem("ICHIP_FI_COL_12", sVal); 
     1349        SetMetadataItem("ICHIP_FI_COL_22", sVal); 
     1350        snprintf(sVal, sizeof(sVal), "%.16g", rowOffset + numRows - 0.5); 
     1351        SetMetadataItem("ICHIP_FI_ROW_21", sVal); 
     1352        SetMetadataItem("ICHIP_FI_ROW_22", sVal); 
     1353    } 
     1354    CSLDestroy(papszFields); 
     1355
     1356 
     1357void ENVIDataset::ProcessStatsFile() 
     1358
     1359    CPLString   osStaFilename; 
     1360    FILE        *fpStaFile; 
     1361 
     1362    osStaFilename = CPLResetExtension( pszHDRFilename, "sta" ); 
     1363    fpStaFile = VSIFOpen( osStaFilename, "rb" ); 
     1364 
     1365    if (!fpStaFile) 
     1366        return; 
     1367 
     1368    long lTestHeader[10],lOffset; 
     1369 
     1370    if( VSIFRead( lTestHeader, sizeof(long), 10, fpStaFile ) != 10 ) 
     1371    { 
     1372        VSIFClose( fpStaFile ); 
     1373        return; 
     1374    } 
     1375 
     1376    int isFloat; 
     1377    isFloat = (byteSwapLong(lTestHeader[0]) == 1111838282); 
     1378 
     1379    unsigned long nb,i; 
     1380    float * fStats; 
     1381    double * dStats, dMin, dMax, dMean, dStd; 
     1382         
     1383    nb=byteSwapLong(lTestHeader[3]); 
     1384    VSIFSeek(fpStaFile,40+(nb+1)*4,SEEK_SET); 
     1385 
     1386    if (VSIFRead(&lOffset,sizeof(long),1,fpStaFile) == 1) 
     1387    { 
     1388        VSIFSeek(fpStaFile,40+(nb+1)*8+byteSwapLong(lOffset)+nb,SEEK_SET); 
     1389        // This should be the beginning of the statistics 
     1390        if (isFloat) 
     1391        { 
     1392            fStats = (float*)calloc(nb*4,4); 
     1393            if (VSIFRead(fStats,4,nb*4,fpStaFile) == nb*4) 
     1394            { 
     1395                for (i=0;i<nb;i++) 
     1396                { 
     1397                    GetRasterBand(i+1)->SetStatistics( 
     1398                        byteSwapFloat(fStats[i]), 
     1399                        byteSwapFloat(fStats[nb+i]), 
     1400                        byteSwapFloat(fStats[2*nb+i]),  
     1401                        byteSwapFloat(fStats[3*nb+i])); 
     1402                } 
     1403            } 
     1404            free(fStats); 
     1405        } 
     1406        else 
     1407        { 
     1408            dStats = (double*)calloc(nb*4,8); 
     1409            if (VSIFRead(dStats,8,nb*4,fpStaFile) == nb*4) 
     1410            { 
     1411                for (i=0;i<nb;i++) 
     1412                { 
     1413                    dMin = byteSwapDouble(dStats[i]); 
     1414                    dMax = byteSwapDouble(dStats[nb+i]); 
     1415                    dMean = byteSwapDouble(dStats[2*nb+i]); 
     1416                    dStd = byteSwapDouble(dStats[3*nb+i]); 
     1417                    if (dMin != dMax && dStd != 0)  
     1418                        GetRasterBand(i+1)->SetStatistics(dMin,dMax,dMean,dStd); 
     1419                } 
     1420            } 
     1421            free(dStats); 
     1422        } 
     1423    } 
     1424    VSIFClose( fpStaFile ); 
     1425
     1426long ENVIDataset::byteSwapLong(long swapMe) 
     1427
     1428#ifndef CPL_LSB 
     1429    return swapMe; 
     1430#endif 
     1431  return ((swapMe&0xFF)<<24)+((swapMe&(0xFF00))<<8)+ 
     1432    ((swapMe&(0xFF0000))>>8)+((swapMe&(0xFF000000))>>24); 
     1433
     1434 
     1435float ENVIDataset::byteSwapFloat(float swapMe) 
     1436
     1437#ifndef CPL_LSB 
     1438    return swapMe; 
     1439#endif 
     1440  long foo,bar; 
     1441  float retval; 
     1442  memmove(&foo, &swapMe,4); 
     1443  bar = byteSwapLong(foo); 
     1444  memmove(&retval, &bar,4); 
     1445 
     1446  return retval; 
     1447
     1448 
     1449double ENVIDataset::byteSwapDouble(double swapMe) 
     1450
     1451#ifndef CPL_LSB 
     1452    return swapMe; 
     1453#endif 
     1454 
     1455  char dblArrSrc[8],dblArrDest[8]; 
     1456  double retval; 
     1457  int i; 
     1458 
     1459  memmove(dblArrSrc, &swapMe, 8); 
     1460 
     1461  for (i=0;i<8;i++) 
     1462    dblArrDest[i]=dblArrSrc[7-i]; 
     1463 
     1464  memmove(&retval,dblArrDest, 8); 
     1465  return retval; 
     1466
     1467 
    13011468 
    13021469/************************************************************************/ 
     
    14221589    { 
    14231590        osHdrFilename = CPLFormFilename( NULL, poOpenInfo->pszFilename,  
    1424                                           "hdr" ); 
     1591                                         "hdr" ); 
    14251592        fpHeader = VSIFOpen( osHdrFilename, pszMode ); 
    14261593    } 
     
    14291596    { 
    14301597        osHdrFilename = CPLFormFilename( NULL, poOpenInfo->pszFilename,  
    1431                                           "HDR" ); 
     1598                                         "HDR" ); 
    14321599        fpHeader = VSIFOpen( osHdrFilename, pszMode ); 
    14331600    } 
     
    14881655 
    14891656/* -------------------------------------------------------------------- */ 
     1657/*      Has the user selected the .sta (stats) file to open?            */ 
     1658/* -------------------------------------------------------------------- */ 
     1659    if( EQUAL(CPLGetExtension(poOpenInfo->pszFilename), "sta") ) 
     1660    { 
     1661        delete poDS; 
     1662        CPLError( CE_Failure, CPLE_AppDefined,  
     1663                  "The selected file is an ENVI statistics file.\n" 
     1664                  "To open ENVI datasets, the data file should be selected\n" 
     1665                  "instead of the .sta file.  Please try again selecting\n" 
     1666                  "the data file corresponding to the statistics file:\n" 
     1667                  "  %s\n",  
     1668                  poOpenInfo->pszFilename ); 
     1669        return NULL; 
     1670    } 
     1671 
     1672/* -------------------------------------------------------------------- */ 
    14901673/*      Extract required values from the .hdr.                          */ 
    14911674/* -------------------------------------------------------------------- */ 
     
    15461729            break; 
    15471730 
    1548           case 6: 
     1731            /*  Removed JBP, ITT-VIS 11/29/2007.  Complex data does not display properly 
     1732                in the ArcGIS application so we are removing it from the supported types list. 
     1733                This is a bit of a big hammer as it may remove functionality from some 
     1734                direct GDAL users, but this data is extremely problematic from an ArcGIS 
     1735                standpoint.   */ 
     1736/*          case 6: 
    15491737            eType = GDT_CFloat32; 
    15501738            break; 
    15511739 
    1552           case 9: 
     1740            case 9: 
    15531741            eType = GDT_CFloat64; 
    15541742            break; 
    1555  
     1743*/ 
    15561744          case 12: 
    15571745            eType = GDT_UInt16; 
     
    15671755            delete poDS; 
    15681756            CPLError( CE_Failure, CPLE_AppDefined,  
    1569                       "The file has a 'data type' value of '%s'.  This value\n" 
    1570                       "isn't recognised by the GDAL ENVI driver.", 
    1571                       CSLFetchNameValue(poDS->papszHeader,"data_type" ) ); 
     1757                      "The file does not have a value for the data_type\n" 
     1758                      "that is recognised by the GDAL ENVI driver."); 
    15721759            return NULL; 
    15731760        } 
     
    16181805        { 
    16191806            delete poDS; 
    1620                        CPLError( CE_Failure, CPLE_OpenFailed,  
     1807            CPLError( CE_Failure, CPLE_OpenFailed,  
    16211808                      "File %s is marked as compressed in the ENVI .hdr\n" 
    16221809                      "GDAL does not support auto-decompression of ENVI data\n" 
     
    16441831    if( poDS->fpImage == NULL ) 
    16451832    { 
    1646            delete poDS; 
     1833        delete poDS; 
    16471834        CPLError( CE_Failure, CPLE_OpenFailed,  
    16481835                  "Failed to re-open %s within ENVI driver.\n",  
     
    16811868    else 
    16821869    { 
    1683            delete poDS; 
     1870        delete poDS; 
    16841871        CPLError( CE_Failure, CPLE_AppDefined,  
    16851872                  "The interleaving type of the file (%s) is not supported.", 
    16861873                  pszInterleave ); 
    1687            return NULL; 
     1874        return NULL; 
    16881875    } 
    16891876     
     
    16951882    { 
    16961883        poDS->SetBand( i + 1, 
    1697             new RawRasterBand(poDS, i + 1, poDS->fpImage, 
    1698                               nHeaderSize + nBandOffset * i, 
    1699                               nPixelOffset, nLineOffset, eType, 
    1700                              bNativeOrder, TRUE) ); 
     1884                       new RawRasterBand(poDS, i + 1, poDS->fpImage, 
     1885                                         nHeaderSize + nBandOffset * i, 
     1886                                         nPixelOffset, nLineOffset, eType, 
     1887                                         bNativeOrder, TRUE) ); 
    17011888    } 
    17021889 
    17031890/* -------------------------------------------------------------------- */ 
    17041891/*      Apply band names if we have them.                               */ 
    1705 /* -------------------------------------------------------------------- */ 
    1706     if( CSLFetchNameValue( poDS->papszHeader, "band_names" ) != NULL ) 
    1707     { 
     1892/*      Use wavelength for more descriptive information if possible     */ 
     1893/* -------------------------------------------------------------------- */ 
     1894    if( CSLFetchNameValue( poDS->papszHeader, "band_names" ) != NULL || 
     1895        CSLFetchNameValue( poDS->papszHeader, "wavelength" ) != NULL) 
     1896    { 
     1897        char pszBandId[1024], pszBandName[1024], pszWavelength[1024]; 
    17081898        char    **papszBandNames =  
    17091899            poDS->SplitList( CSLFetchNameValue( poDS->papszHeader,  
    17101900                                                "band_names" ) ); 
    1711  
    1712         for( i = 0; i < MIN(CSLCount(papszBandNames),nBands); i++ ) 
    1713             poDS->GetRasterBand(i + 1)->SetDescription( papszBandNames[i] ); 
    1714  
     1901        char    **papszWL =  
     1902            poDS->SplitList( CSLFetchNameValue( poDS->papszHeader,  
     1903                                                "wavelength" ) ); 
     1904 
     1905        const char *pszWLUnits = NULL; 
     1906        if (papszWL)  
     1907        { 
     1908            /* If WL information is present, process wavelength units */ 
     1909            pszWLUnits = CSLFetchNameValue( poDS->papszHeader,  
     1910                                            "wavelength_units" ); 
     1911            if (pszWLUnits) 
     1912            { 
     1913                /* Don't show unknown or index units */ 
     1914                if (EQUAL(pszWLUnits,"Unknown") || 
     1915                    EQUAL(pszWLUnits,"Index") ) 
     1916                    pszWLUnits=0; 
     1917            } 
     1918        } 
     1919 
     1920        for( i = 0; i < nBands; i++ ) 
     1921        { 
     1922            /* First set up the wavelength names and units if available */ 
     1923            if (papszWL && CSLCount(papszWL) > i)  
     1924            { 
     1925                snprintf(pszWavelength, sizeof(pszWavelength) ,"%s", papszWL[i]); 
     1926                if (pszWLUnits)  
     1927                { 
     1928                    strncat(pszWavelength," ", sizeof(pszWavelength)); 
     1929                    strncat(pszWavelength,pszWLUnits, sizeof(pszWavelength));  
     1930                } 
     1931            } 
     1932            else pszWavelength[0] = '\0'; 
     1933 
     1934            /* Build the final name for this band */ 
     1935            if (papszBandNames && CSLCount(papszBandNames) > i) 
     1936            {    
     1937                snprintf(pszBandName, sizeof(pszBandName),  "%s", papszBandNames[i]); 
     1938                if (strlen(pszWavelength) > 0)  
     1939                { 
     1940                    strncat(pszBandName," (", sizeof(pszBandName)); 
     1941                    strncat(pszBandName, pszWavelength, sizeof(pszBandName)); 
     1942                    strncat(pszBandName,")", sizeof(pszBandName)); 
     1943                } 
     1944            } 
     1945            else   /* WL but no band names */ 
     1946                strncpy(pszBandName, pszWavelength, sizeof(pszBandName)); 
     1947 
     1948            /* Description is for internal GDAL usage */ 
     1949            poDS->GetRasterBand(i + 1)->SetDescription( pszBandName ); 
     1950 
     1951            /* Metadata field named Band_1, etc. needed for ArcGIS integration */ 
     1952            snprintf(pszBandId, sizeof(pszBandId),  "Band_%i", i+1); 
     1953            poDS->SetMetadataItem(pszBandId, pszBandName); 
     1954        } 
    17151955        CSLDestroy( papszBandNames ); 
    17161956    } 
    1717      
    17181957/* -------------------------------------------------------------------- */ 
    17191958/*      Apply class names if we have them.                              */ 
     
    17612000/* -------------------------------------------------------------------- */       
    17622001    if( CSLFetchNameValue(poDS->papszHeader,"data_ignore_value" ) != NULL ) 
    1763        
     2002   
    17642003        for( i = 0; i < poDS->nBands; i++ ) 
    17652004            ((RawRasterBand*)poDS->GetRasterBand(i+1))->StoreNoDataValue(atof( 
    1766                 CSLFetchNameValue(poDS->papszHeader,"data_ignore_value"))); 
    1767         } 
     2005                                                                             CSLFetchNameValue(poDS->papszHeader,"data_ignore_value"))); 
     2006    } 
     2007 
     2008/* -------------------------------------------------------------------- */ 
     2009/*      Read the stats file if it is present                            */ 
     2010/* -------------------------------------------------------------------- */       
     2011    poDS->ProcessStatsFile(); 
    17682012 
    17692013/* -------------------------------------------------------------------- */ 
     
    17802024/*      Look for RPC mapinfo                                            */ 
    17812025/* -------------------------------------------------------------------- */ 
    1782     if( CSLFetchNameValue( poDS->papszHeader, "rpc_info" ) != NULL ) 
    1783     { 
    1784                 poDS->ProcessRPCinfo(  
    1785                         CSLFetchNameValue(poDS->papszHeader,"rpc_info") ); 
     2026    if( !poDS->bFoundMapinfo && 
     2027        CSLFetchNameValue( poDS->papszHeader, "rpc_info" ) != NULL ) 
     2028    { 
     2029        poDS->ProcessRPCinfo(  
     2030            CSLFetchNameValue(poDS->papszHeader,"rpc_info"),  
     2031            poDS->nRasterXSize, poDS->nRasterYSize); 
    17862032    } 
    17872033     
     
    17962042    poDS->SetDescription( poOpenInfo->pszFilename ); 
    17972043    poDS->TryLoadXML(); 
    1798      
     2044 
    17992045    return( poDS ); 
    18002046} 
     
    19502196 
    19512197void GDALRegister_ENVI() 
    1952  
    19532198{ 
    19542199    GDALDriver  *poDriver; 
     
    19852230    } 
    19862231} 
    1987