Index: frmts/cosar/makefile.vc
===================================================================
--- frmts/cosar/makefile.vc (revision 0)
+++ frmts/cosar/makefile.vc (revision 0)
@@ -0,0 +1,13 @@
+
+OBJ = cosar_dataset.obj
+
+GDAL_ROOT = ..\..
+
+!INCLUDE $(GDAL_ROOT)\nmake.opt
+
+default: $(OBJ)
+ xcopy /D /Y *.obj ..\o
+
+clean:
+ -del *.obj
+
Index: frmts/cosar/GNUmakefile
===================================================================
--- frmts/cosar/GNUmakefile (revision 0)
+++ frmts/cosar/GNUmakefile (revision 0)
@@ -0,0 +1,13 @@
+
+include ../../GDALmake.opt
+
+OBJ = cosar_dataset.o
+
+CPPFLAGS := $(GDAL_INCLUDE) $(CPPFLAGS)
+
+default: $(OBJ)
+
+clean:
+ rm -f *.o $(O_OBJ)
+
+install-obj: $(O_OBJ)
Index: frmts/cosar/COSAR.html
===================================================================
--- frmts/cosar/COSAR.html (revision 0)
+++ frmts/cosar/COSAR.html (revision 0)
@@ -0,0 +1,29 @@
+
+
+COSAR -- TerraSAR-X Complex SAR Data Product
+
+
+
+
+COSAR -- TerraSAR-X Complex SAR Data Product
+
+This driver provides the capability to read TerraSAR-X complex data. While
+most users will receive products in GeoTIFF format (representing detected
+radiation reflected from the targets, or geocoded data), ScanSAR products will be distributed in COSAR format.
+
+
Essentially, COSAR is an annotated binary matrix, with each sample held
+in 4 bytes (16 bytes real, 16 bytes imaginary) stored with the most significant
+byte first (Big Endian). Within a COSAR container there are one or more
+"bursts" which represent individual ScanSAR bursts. Note that if a Stripmap or
+Spotlight product is held in a COSAR container it is stored in a single
+burst.
+
+
Support for ScanSAR data is currently under way, due to the difficulties in fitting
+the ScanSAR "burst" identifiers into the GDAL model.
+
+
See Also:
+- DLR Document TX-GS-DD-3307 "Level 1b Product Format Specification."
+
+
+
+
Index: frmts/cosar/cosar_dataset.cpp
===================================================================
--- frmts/cosar/cosar_dataset.cpp (revision 0)
+++ frmts/cosar/cosar_dataset.cpp (revision 0)
@@ -0,0 +1,196 @@
+/* TerraSAR-X COSAR Format Driver
+ * (C)2007 Philippe P. Vachon
+ * ---------------------------------------------------------------------------
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+
+#include "gdal_priv.h"
+#include "cpl_port.h"
+#include "cpl_conv.h"
+#include "cpl_vsi.h"
+#include "cpl_string.h"
+#include
+
+/* Various offsets, in bytes */
+#define BIB_OFFSET 0 /* Bytes in burst, valid only for ScanSAR */
+#define RSRI_OFFSET 4 /* Range Sample Relative Index */
+#define RS_OFFSET 8 /* Range Samples, the length of a range line */
+#define AS_OFFSET 12 /* Azimuth Samples, the length of an azimth column */
+#define BI_OFFSET 16 /* Burst Index, the index number of the burst */
+#define RTNB_OFFSET 20 /* Rangeline total number of bytes, incl. annot. */
+#define TNL_OFFSET 24 /* Total Number of Lines */
+#define MAGIC1_OFFSET 28 /* Magic number 1: 0x43534152 */
+#define MAGIC2_OFFSET 32 /* Magic number 2: Version number */
+
+#define COSAR_MAGIC 0x43534152 /* String CSAR */
+#define FILLER_MAGIC 0x7F7F7F7F /* Filler value, we'll use this for a test */
+
+CPL_C_START
+void GDALRegister_COSAR(void);
+CPL_C_END
+
+class COSARDataset : public GDALDataset
+{
+ long nSize;
+public:
+ FILE *fp;
+/* ~COSARDataset(); */
+
+ static GDALDataset *Open( GDALOpenInfo * );
+ long GetSizeInBytes() { return nSize; }
+};
+
+class COSARRasterBand : public GDALRasterBand
+{
+ unsigned long nRTNB;
+ int nRSLength;
+ int nBurstNumber;
+public:
+ COSARRasterBand(COSARDataset *, unsigned long nRTNB);
+ virtual CPLErr IReadBlock(int, int, void *);
+};
+
+/*****************************************************************************
+ * COSARRasterBand Implementation
+ *****************************************************************************/
+
+COSARRasterBand::COSARRasterBand(COSARDataset *pDS, unsigned long nRTNB) {
+ this->nRTNB = nRTNB;
+ this->nRSLength = nRSLength;
+ nBurstNumber = 1;
+ nBlockXSize = pDS->GetRasterXSize();
+ nBlockYSize = 1;
+ eDataType = GDT_CInt16;
+}
+
+CPLErr COSARRasterBand::IReadBlock(int nBlockXOff, int nBlockYOff,
+ void *pImage) {
+
+ unsigned long nRSFV, nRSLV;
+ COSARDataset *pCDS = (COSARDataset *) poDS;
+
+ /* Find the line we want to be at */
+ /* To explain some magic numbers:
+ * 4 bytes for an entire sample (2 I, 2 Q)
+ * nBlockYOff + 4 = Y offset + 4 annotation lines at beginning
+ * of file
+ */
+
+ VSIFSeek(pCDS->fp,(this->nRTNB * (nBlockYOff + 4)), SEEK_SET);
+
+
+ /* Read RSFV and RSLV (TX-GS-DD-3307) */
+ VSIFRead(&nRSFV,1,4,pCDS->fp);
+ VSIFRead(&nRSLV,1,4,pCDS->fp);
+
+#ifdef CPL_LSB
+ nRSFV = CPL_SWAP32(nRSFV);
+ nRSLV = CPL_SWAP32(nRSLV);
+#endif
+
+ if (nRSLV - nRSFV < 0 || nRSFV >= this->nRTNB || nRSLV > this->nRTNB) {
+ /* throw an error */
+ CPLError(CE_Failure, CPLE_AppDefined,
+ "RSLV/RSFV values are not sane... oh dear.\n");
+ return CE_Failure;
+ }
+
+
+ /* zero out the range line */
+ for (int i = 0; i < this->nRasterXSize; i++) {
+ ((GUInt32 *)pImage)[i] = 0;
+ }
+ /* Read the valid samples: */
+ VSIFRead(((char *)pImage)+((nRSFV - 1)*4),1,((nRSLV-1)*4)-((nRSFV-1)*4),pCDS->fp);
+
+#ifdef CPL_LSB
+ GDALSwapWords( pImage, 2, nBlockXSize * nBlockYSize * 2, 2 );
+#endif
+
+
+ return CE_None;
+}
+
+
+/*****************************************************************************
+ * COSARDataset Implementation
+ *****************************************************************************/
+
+GDALDataset *COSARDataset::Open( GDALOpenInfo * pOpenInfo ) {
+ long nRTNB;
+ /* Check if we're actually a COSAR data set. */
+ if (!EQUALN((char *)pOpenInfo->pabyHeader+MAGIC1_OFFSET, "CSAR",4))
+ return NULL;
+
+
+ /* this is a cosar dataset */
+ COSARDataset *pDS;
+ pDS = new COSARDataset();
+
+ /* steal fp */
+ pDS->fp = pOpenInfo->fp;
+ pOpenInfo->fp = NULL;
+
+ /* Calculate the file size */
+ VSIFSeek(pDS->fp,0,SEEK_END);
+ pDS->nSize = VSIFTell(pDS->fp);
+
+ VSIFSeek(pDS->fp, RS_OFFSET, SEEK_SET);
+ VSIFRead(&pDS->nRasterXSize, 1, 4, pDS->fp);
+#ifdef CPL_LSB
+ pDS->nRasterXSize = CPL_SWAP32(pDS->nRasterXSize);
+#endif
+
+
+ VSIFRead(&pDS->nRasterYSize, 1, 4, pDS->fp);
+#ifdef CPL_LSB
+ pDS->nRasterYSize = CPL_SWAP32(pDS->nRasterYSize);
+#endif
+
+ VSIFSeek(pDS->fp, RTNB_OFFSET, SEEK_SET);
+ VSIFRead(&nRTNB, 1, 4, pDS->fp);
+#ifdef CPL_LSB
+ nRTNB = CPL_SWAP32(nRTNB);
+#endif
+
+ /* Add raster band */
+ pDS->SetBand(1, new COSARRasterBand(pDS, nRTNB));
+ return pDS;
+}
+
+
+/* register the driver with GDAL */
+void GDALRegister_COSAR() {
+ GDALDriver *pDriver;
+ if (GDALGetDriverByName("cosar") == NULL) {
+ pDriver = new GDALDriver();
+ pDriver->SetDescription("COSAR");
+ pDriver->SetMetadataItem( GDAL_DMD_LONGNAME,
+ "COSAR Annotated Binary Matrix (TerraSAR-X)");
+ pDriver->SetMetadataItem( GDAL_DMD_HELPTOPIC,
+ "COSAR.html");
+ pDriver->pfnOpen = COSARDataset::Open;
+ GetGDALDriverManager()->RegisterDriver(pDriver);
+ }
+}
+
Index: frmts/makefile.vc
===================================================================
--- frmts/makefile.vc (revision 11822)
+++ frmts/makefile.vc (working copy)
@@ -9,7 +9,8 @@
-DFRMT_nitf -DFRMT_pcidsk -DFRMT_airsar -DFRMT_rs2 \
-DFRMT_ilwis -DFRMT_msgn -DFRMT_rik -DFRMT_pcraster \
-DFRMT_leveller -DFRMT_sgi -DFRMT_idrisi -DFRMT_gsg \
- -DFRMT_palsar -DFRMT_ers -DFRMT_ingr -DFRMT_dimap -DFRMT_gff
+ -DFRMT_palsar -DFRMT_ers -DFRMT_ingr -DFRMT_dimap -DFRMT_gff \
+ -DFRMT_cosar
MOREEXTRA =
Index: frmts/gdalallregister.cpp
===================================================================
--- frmts/gdalallregister.cpp (revision 11822)
+++ frmts/gdalallregister.cpp (working copy)
@@ -311,6 +311,14 @@
GDALRegister_GS7BG();
#endif
+#ifdef FRMT_cosar
+ GDALRegister_COSAR();
+#endif
+
/* -------------------------------------------------------------------- */
/* Our test for the following is weak or expensive so we try */
/* them last. */
Index: gcore/gdal_frmts.h
===================================================================
--- gcore/gdal_frmts.h (revision 11822)
+++ gcore/gdal_frmts.h (working copy)
@@ -118,6 +118,8 @@
void CPL_DLL GDALRegister_PALSAR();
void CPL_DLL GDALRegister_DIMAP();
void CPL_DLL GDALRegister_GFF(void);
+void CPL_DLL GDALRegister_COSAR(void);
CPL_C_END
#endif /* ndef GDAL_FRMTS_H_INCLUDED */
Index: GDALmake.opt.in
===================================================================
--- GDALmake.opt.in (revision 11822)
+++ GDALmake.opt.in (working copy)
@@ -322,7 +322,7 @@
GDAL_FORMATS = gxf gtiff hfa aigrid aaigrid ceos ceos2 iso8211 xpm \
sdts raw dted mem jdem envisat elas fit vrt usgsdem l1b \
nitf bmp pcidsk airsar rs2 ilwis rmf rik leveller sgi \
- idrisi gsg ingr ers palsar dimap gff \
+ idrisi gsg ingr ers palsar dimap gff cosar\
@OPT_GDAL_FORMATS@
#