Revision 27

View differences:

1.10/trunk/binaries/mac/raster/gdal/GDAL.framework/Versions/1.7/Programs/gcps2wld.py
1 1
#!/usr/bin/env python
2 2
#******************************************************************************
3
#  $Id: gcps2wld.py 18194 2009-12-06 20:07:45Z rouault $
3
#  $Id: gcps2wld.py 18953 2010-02-28 12:00:54Z rouault $
4 4
# 
5 5
#  Name:     gcps2wld
6 6
#  Project:  GDAL Python Interface
......
47 47
filename = sys.argv[1]
48 48
dataset = gdal.Open( filename )
49 49
if dataset is None:
50
    print('Unable to open ', filename)
50
    print('Unable to open %s' % filename)
51 51
    sys.exit(1)
52 52

  
53 53
gcps = dataset.GetGCPs()
1.10/trunk/binaries/mac/raster/gdal/GDAL.framework/Versions/1.7/Programs/gdal_merge.py
1 1
#!/usr/bin/env python
2 2
###############################################################################
3
# $Id: gdal_merge.py 18669 2010-01-27 02:07:32Z chaitanya $
3
# $Id: gdal_merge.py 18953 2010-02-28 12:00:54Z rouault $
4 4
#
5 5
# Project:  InSAR Peppers
6 6
# Purpose:  Module to extract data from many rasters into one output.
......
302 302
            i = i + 1
303 303
            band_type = gdal.GetDataTypeByName( argv[i] )
304 304
            if band_type == gdal.GDT_Unknown:
305
                print('Unknown GDAL data type: ', argv[i])
305
                print('Unknown GDAL data type: %s' % argv[i])
306 306
                sys.exit( 1 )
307 307

  
308 308
        elif arg == '-init':
......
341 341
            i = i + 4
342 342

  
343 343
        elif arg[:1] == '-':
344
            print('Unrecognised command option: ', arg)
344
            print('Unrecognised command option: %s' % arg)
345 345
            Usage()
346 346
            sys.exit( 1 )
347 347

  
1.10/trunk/binaries/mac/raster/gdal/GDAL.framework/Versions/1.7/Programs/gdal_polygonize.py
1 1
#!/usr/bin/env python
2 2
#******************************************************************************
3
#  $Id: gdal_polygonize.py 18306 2009-12-15 18:57:11Z rouault $
3
#  $Id: gdal_polygonize.py 18953 2010-02-28 12:00:54Z rouault $
4 4
# 
5 5
#  Project:  GDAL Python Interface
6 6
#  Purpose:  Application for converting raster data to a vector polygon layer.
......
130 130
src_ds = gdal.Open( src_filename )
131 131
    
132 132
if src_ds is None:
133
    print('Unable to open ', src_filename)
133
    print('Unable to open %s' % src_filename)
134 134
    sys.exit(1)
135 135

  
136 136
srcband = src_ds.GetRasterBand(src_band_n)
......
186 186
    fd = ogr.FieldDefn( dst_fieldname, ogr.OFTInteger )
187 187
    dst_layer.CreateField( fd )
188 188
    dst_field = 0
189
    
189
else:
190
    if dst_fieldname is not None:
191
        dst_field = dst_layer.GetLayerDefn().GetFieldIndex(dst_fieldname)
192
        if dst_field < 0:
193
            print("Warning: cannot find field '%s' in layer '%s'" % (dst_fieldname, dst_layername))
194

  
190 195
# =============================================================================
191 196
#	Invoke algorithm.
192 197
# =============================================================================
1.10/trunk/binaries/mac/raster/gdal/GDAL.framework/Versions/1.7/Programs/epsg_tr.py
1 1
#!/usr/bin/env python
2 2
#******************************************************************************
3
#  $Id: epsg_tr.py 18194 2009-12-06 20:07:45Z rouault $
3
#  $Id: epsg_tr.py 18953 2010-02-28 12:00:54Z rouault $
4 4
# 
5 5
#  Project:  CFS OGC MapServer
6 6
#  Purpose:  Script to create WKT and PROJ.4 dictionaries for EPSG GCS/PCS
......
57 57
        err = 1
58 58

  
59 59
    if err != 0 and report_error:
60
        print('Unable to lookup ',code,', either not a valid EPSG')
60
        print('Unable to lookup %d, either not a valid EPSG' % code)
61 61
        print('code, or it the EPSG csv files are not accessable.')
62 62
        sys.exit(2)
63 63
    else:
64 64
        if output_format == '-pretty_wkt':
65 65
            if gen_dict_line:
66
                print('EPSG:',code)
66
                print('EPSG:%d' % code)
67 67

  
68 68
            print(prj_srs.ExportToPrettyWkt())
69 69

  
......
72 72
            
73 73
        if output_format == '-wkt':
74 74
            if gen_dict_line:
75
                print('EPSG:',code)
75
                print('EPSG:%d' % code)
76 76
                    
77 77
            print(prj_srs.ExportToWkt())
78 78
                
1.10/trunk/binaries/mac/raster/gdal/GDAL.framework/Versions/1.7/Programs/esri2wkt.py
1 1
#!/usr/bin/env python
2 2
#******************************************************************************
3
#  $Id: esri2wkt.py 18194 2009-12-06 20:07:45Z rouault $
3
#  $Id: esri2wkt.py 18953 2010-02-28 12:00:54Z rouault $
4 4
# 
5 5
#  Project:  GDAL
6 6
#  Purpose:  Simple command line program for translating ESRI .prj files
......
51 51
prj_srs = osr.SpatialReference()
52 52
err = prj_srs.ImportFromESRI( prj_lines )
53 53
if err != 0:
54
    print('Error = ', err)
54
    print('Error = %d' % err)
55 55
else:
56 56
    print(prj_srs.ExportToPrettyWkt())
57 57

  
1.10/trunk/binaries/mac/raster/gdal/GDAL.framework/Versions/1.7/Programs/gdalchksum.py
1 1
#!/usr/bin/env python
2 2
#******************************************************************************
3
#  $Id: gdalchksum.py 18194 2009-12-06 20:07:45Z rouault $
3
#  $Id: gdalchksum.py 18953 2010-02-28 12:00:54Z rouault $
4 4
# 
5 5
#  Project:  GDAL
6 6
#  Purpose:  Application to checksum a GDAL image file.
......
82 82

  
83 83
ds = gdal.Open( filename )
84 84
if ds is None:
85
    print('Unable to open ', filename)
85
    print('Unable to open %s' % filename)
86 86
    sys.exit(1)
87 87

  
88 88
# Default values
1.10/trunk/binaries/mac/raster/gdal/GDAL.framework/Versions/1.7/Programs/gdal-config
4 4
CONFIG_PREFIX="/Library/Frameworks/GDAL.framework/Versions/1.7"
5 5
CONFIG_CFLAGS="-I/Library/Frameworks/GDAL.framework/Versions/1.7/Headers"
6 6
CONFIG_DATA="/Library/Frameworks/GDAL.framework/Versions/1.7/Resources/gdal"
7
CONFIG_VERSION="1.7.1"
7
CONFIG_VERSION="1.7.2"
8 8
CONFIG_OGR_ENABLED=yes
9 9
CONFIG_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 leveller sgi srtmhgt idrisi gsg ingr ers jaxapalsar dimap gff cosar pds adrg coasp tsx terragen blx msgn til r northwood saga wcs wms dods grib bsb jpeg2000 hdf5 hdf4 ogdi gif jpeg png netcdf pcraster fits  rik rasterlite wktraster"
10 10
usage()
1.10/trunk/binaries/mac/raster/gdal/GDAL.framework/Versions/1.7/Programs/f2py
1
#!/usr/bin/env python2.6
2
# See http://cens.ioc.ee/projects/f2py2e/
3
import os, sys
4
for mode in ["g3-numpy", "2e-numeric", "2e-numarray", "2e-numpy"]:
5
    try:
6
        i=sys.argv.index("--"+mode)
7
        del sys.argv[i]
8
        break
9
    except ValueError: pass
10
os.environ["NO_SCIPY_IMPORT"]="f2py"
11
if mode=="g3-numpy":
12
    print >> sys.stderr, "G3 f2py support is not implemented, yet."
13
    sys.exit(1)
14
elif mode=="2e-numeric":
15
    from f2py2e import main
16
elif mode=="2e-numarray":
17
    sys.argv.append("-DNUMARRAY")
18
    from f2py2e import main
19
elif mode=="2e-numpy":
20
    from numpy.f2py import main
21
else:
22
    print >> sys.stderr, "Unknown mode:",`mode`
23
    sys.exit(1)
24
main()
0 25

  
1.10/trunk/binaries/mac/raster/gdal/GDAL.framework/Versions/1.7/Programs/gdal_proximity.py
1 1
#!/usr/bin/env python
2 2
#******************************************************************************
3
#  $Id: gdal_proximity.py 18306 2009-12-15 18:57:11Z rouault $
3
#  $Id: gdal_proximity.py 18953 2010-02-28 12:00:54Z rouault $
4 4
# 
5 5
#  Name:     gdalproximity
6 6
#  Project:  GDAL Python Interface
......
58 58
dst_filename = None
59 59
dst_band_n = 1
60 60
creation_type = 'Float32'
61
quiet_flag = 0
61 62

  
62 63
gdal.AllRegister()
63 64
argv = gdal.GeneralCmdLineProcessor( sys.argv )
......
133 134
src_ds = gdal.Open( src_filename )
134 135
    
135 136
if src_ds is None:
136
    print('Unable to open ', src_filename)
137
    print('Unable to open %s' % src_filename)
137 138
    sys.exit(1)
138 139

  
139 140
srcband = src_ds.GetRasterBand(src_band_n)
1.10/trunk/binaries/mac/raster/gdal/GDAL.framework/Versions/1.7/Programs/gdalimport.py
1 1
#!/usr/bin/env python
2 2
#******************************************************************************
3
#  $Id: gdalimport.py 18194 2009-12-06 20:07:45Z rouault $
3
#  $Id: gdalimport.py 18953 2010-02-28 12:00:54Z rouault $
4 4
# 
5 5
#  Name:     gdalimport
6 6
#  Project:  GDAL Python Interface
......
47 47
    sys.exit(1)
48 48

  
49 49
def progress_cb( complete, message, cb_data ):
50
    print(cb_data, complete)
50
    print('%s %d' % (cb_data, complete))
51 51
    
52 52

  
53 53
filename = argv[1]
54 54
dataset = gdal.Open( filename )
55 55
if dataset is None:
56
    print('Unable to open ', filename)
56
    print('Unable to open %s' % filename)
57 57
    sys.exit(1)
58 58

  
59 59
geotiff = gdal.GetDriverByName("GTiff")
......
71 71
else:
72 72
    newfile = argv[2]
73 73

  
74
print('Importing to Tiled GeoTIFF file:', newfile)
74
print('Importing to Tiled GeoTIFF file: %s' % newfile)
75 75
new_dataset = geotiff.CreateCopy( newfile, dataset, 0,
76 76
                                  ['TILED=YES',],
77 77
                                  callback = progress_cb,
1.10/trunk/binaries/mac/raster/gdal/GDAL.framework/Versions/1.7/Programs/gdal_sieve.py
1 1
#!/usr/bin/env python
2 2
#******************************************************************************
3
#  $Id: gdal_sieve.py 18306 2009-12-15 18:57:11Z rouault $
3
#  $Id: gdal_sieve.py 18953 2010-02-28 12:00:54Z rouault $
4 4
# 
5 5
#  Project:  GDAL Python Interface
6 6
#  Purpose:  Application for applying sieve filter to raster data.
......
136 136
    src_ds = gdal.Open( src_filename, gdal.GA_ReadOnly )
137 137
    
138 138
if src_ds is None:
139
    print('Unable to open ', src_filename)
139
    print('Unable to open %s ' % src_filename)
140 140
    sys.exit(1)
141 141

  
142 142
srcband = src_ds.GetRasterBand(1)
1.10/trunk/binaries/mac/raster/gdal/GDAL.framework/Versions/1.7/Programs/rgb2pct.py
1 1
#!/usr/bin/env python
2 2
#******************************************************************************
3
#  $Id: rgb2pct.py 18194 2009-12-06 20:07:45Z rouault $
3
#  $Id: rgb2pct.py 18953 2010-02-28 12:00:54Z rouault $
4 4
# 
5 5
#  Name:     rgb2pct
6 6
#  Project:  GDAL Python Interface
......
91 91

  
92 92
src_ds = gdal.Open( src_filename )
93 93
if src_ds is None:
94
    print('Unable to open ', src_filename)
94
    print('Unable to open %s' % src_filename)
95 95
    sys.exit(1)
96 96

  
97 97
if src_ds.RasterCount < 3:
1.10/trunk/binaries/mac/raster/gdal/GDAL.framework/Versions/1.7/Programs/pct2rgb.py
1 1
#!/usr/bin/env python
2 2
#******************************************************************************
3
#  $Id: pct2rgb.py 18194 2009-12-06 20:07:45Z rouault $
3
#  $Id: pct2rgb.py 18953 2010-02-28 12:00:54Z rouault $
4 4
# 
5 5
#  Name:     pct2rgb
6 6
#  Project:  GDAL Python Interface
......
99 99

  
100 100
src_ds = gdal.Open( src_filename )
101 101
if src_ds is None:
102
    print('Unable to open ', src_filename)
102
    print('Unable to open %s ' % src_filename)
103 103
    sys.exit(1)
104 104

  
105 105
src_band = src_ds.GetRasterBand(band_number)
1.10/trunk/binaries/mac/raster/gdal/GDAL.framework/Versions/1.7/Programs/gdal_fillnodata.py
146 146
    src_ds = gdal.Open( src_filename, gdal.GA_ReadOnly )
147 147
    
148 148
if src_ds is None:
149
    print('Unable to open ', src_filename)
149
    print('Unable to open %s' % src_filename)
150 150
    sys.exit(1)
151 151

  
152 152
srcband = src_ds.GetRasterBand(src_band)
1.10/trunk/binaries/mac/raster/gdal/GDAL.framework/Versions/1.7/Programs/gdal_retile.py
1 1
#!/usr/bin/env python
2 2
###############################################################################
3
#  $Id: gdal_retile.py 18955 2010-02-28 12:13:25Z rouault $
3 4
#
4 5
# Purpose:  Module for retiling (merging) tiles and building tiled pyramids
5 6
# Author:   Christian Meuller, christian.mueller@nvoe.at
......
82 83
            return self.dict[name]
83 84
        result = gdal.Open(name)
84 85
        if result is None:
85
            print("Error openenig:",NameError)
86
            print("Error openenig:%s" % NameError)
86 87
            sys.exit(1)
87 88
        if len(self.queue)==self.cacheSize:
88 89
            toRemove = self.queue.pop(0)
......
103 104
    def __init__(self,xsize,ysize,tileWidth,tileHeight):
104 105
        self.tileWidth=tileWidth
105 106
        self.tileHeight=tileHeight
106
        self.countTilesX= xsize / tileWidth
107
        self.countTilesY= ysize / tileHeight
108
        self.lastTileWidth = xsize - self.countTilesX *  tileWidth
109
        self.lastTileHeight = ysize - self.countTilesY *  tileHeight
107
        self.countTilesX= int(xsize / tileWidth)
108
        self.countTilesY= int(ysize / tileHeight)
109
        self.lastTileWidth = int(xsize - self.countTilesX *  tileWidth)
110
        self.lastTileHeight = int(ysize - self.countTilesY *  tileHeight)
110 111

  
111 112
        if (self.lastTileWidth > 0 ):
112 113
            self.countTilesX=self.countTilesX+1
......
270 271
def getTileIndexFromFiles( inputTiles, driverTyp):
271 272

  
272 273
    if Verbose:
273
        print("Building internal Index for %d tile(s) ..." % len(inputTiles), end=' ')
274
        from sys import version_info
275
        if version_info >= (3,0,0):
276
            exec('print("Building internal Index for %d tile(s) ..." % len(inputTiles), end=" ")')
277
        else:
278
            exec('print "Building internal Index for %d tile(s) ..." % len(inputTiles), ')
274 279

  
275 280
    ogrTileIndexDS = createTileIndex("TileIndex",TileIndexFieldName,None,driverTyp);
276 281
    for inputTile in inputTiles:
......
708 713
            i+=1
709 714
            BandType = gdal.GetDataTypeByName( argv[i] )
710 715
            if BandType == gdal.GDT_Unknown:
711
                print('Unknown GDAL data type: ', argv[i])
716
                print('Unknown GDAL data type: %s' % argv[i])
712 717
                return 1
713 718
        elif arg == '-co':
714 719
            i+=1
......
748 753
            elif ResamplingMethodString=="lanczos":
749 754
                ResamplingMethod=GRA_Lanczos
750 755
            else:
751
                print("Unknown resampling method:" ,ResamplingMethodString)
756
                print("Unknown resampling method: %s" % ResamplingMethodString)
752 757
                return 1
753 758
        elif arg == '-levels':
754 759
            i+=1
755 760
            Levels=int(argv[i])
756 761
            if Levels<1:
757
                print("Invalid number of levels", Levels)
762
                print("Invalid number of levels : %d" % Levels)
758 763
                return 1
759 764
        elif arg == '-s_srs':
760 765
            i+=1
......
785 790
            i+=1
786 791
            CsvDelimiter=argv[i]
787 792
        elif arg[:1] == '-':
788
            print('Unrecognised command option: ', arg)
793
            print('Unrecognised command option: %s' % arg)
789 794
            Usage()
790 795
            return 1
791 796

  
......
814 819
                continue
815 820
            os.mkdir(leveldir)
816 821
            if (os.path.exists(leveldir)==False):
817
                print("Cannot create level dir:", leveldir)
822
                print("Cannot create level dir: %s" % leveldir)
818 823
                return 1
819 824
            if Verbose :
820
                print("Created level dir: ",leveldir)
825
                print("Created level dir: %s" % leveldir)
821 826

  
822 827

  
823 828
    Driver = gdal.GetDriverByName(Format)
1.10/trunk/binaries/mac/raster/gdal/GDAL.framework/Versions/1.7/Programs/gcps2vec.py
1 1
#!/usr/bin/env python
2 2
#******************************************************************************
3
#  $Id: gcps2vec.py 18194 2009-12-06 20:07:45Z rouault $
3
#  $Id: gcps2vec.py 18953 2010-02-28 12:00:54Z rouault $
4 4
# 
5 5
#  Project:  GDAL
6 6
#  Purpose:  Convert GCPs to a point layer.
......
94 94
# ----------------------------------------------------------------------------
95 95
ds = gdal.Open( in_file )
96 96
if ds is None:
97
    print('Unable to open ', filename)
97
    print('Unable to open %s' % filename)
98 98
    sys.exit(1)
99 99

  
100 100
gcp_srs = ds.GetGCPProjection()
1.10/trunk/binaries/mac/raster/gdal/GDAL.framework/Versions/1.7/Resources/Info.plist
7 7
	<key>CFBundleExecutable</key>
8 8
	<string>GDAL</string>
9 9
	<key>CFBundleGetInfoString</key>
10
	<string>GDAL/OGR 1.7.1-1</string>
10
	<string>GDAL/OGR 1.7.2-2</string>
11 11
	<key>CFBundleIdentifier</key>
12 12
	<string>org.gdal.gdal</string>
13 13
	<key>CFBundleInfoDictionaryVersion</key>
......
17 17
	<key>CFBundlePackageType</key>
18 18
	<string>FMWK</string>
19 19
	<key>CFBundleShortVersionString</key>
20
	<string>1.7.1</string>
20
	<string>1.7.2</string>
21 21
	<key>CFBundleSignature</key>
22 22
	<string>????</string>
23 23
	<key>CFBundleVersion</key>
24
	<string>GDAL/OGR 1.7.1-1</string>
24
	<string>GDAL/OGR 1.7.2-2</string>
25 25
</dict>
26 26
</plist>
1.10/trunk/binaries/mac/raster/gdal/GDAL.framework/Versions/1.7/Resources/doc/gdal/index.html
22 22
<h1>GDAL - Geospatial Data Abstraction Library</h1>
23 23
<p>
24 24
<center><b>Select language</b>: [English]<a href="index_ru.html">[Russian]</a><a href="index_br.html">[Portuguese]</a><a href="http://georezo.net/wiki/main:logiciels:gdal_ogr">[French/Francais]</a></center><p>
25
 <img src="gdalicon.png" alt="GDAL">  is a translator library for raster geospatial data formats that is released under an <a href="http://trac.osgeo.org/gdal/wiki/FAQGeneral#WhatlicensedoesGDALOGRuse">X/MIT</a> style <a href="http://www.opensource.org/">Open Source</a> license by the <a href="http://www.osgeo.org/">Open Source Geospatial Foundation</a>. As a library, it presents a <a class="el" href="gdal_datamodel.html">single abstract data model</a> to the calling application for all supported formats. It also comes with a variety of useful <a class="el" href="gdal_utilities.html">commandline utilities</a> for data translation and processing. The <a href="http://trac.osgeo.org/gdal/wiki/Release/1.7.1-News">NEWS</a> page describes the February 2010 GDAL/OGR 1.7.1 release.<p>
25
 <img src="gdalicon.png" alt="GDAL">  is a translator library for raster geospatial data formats that is released under an <a href="http://trac.osgeo.org/gdal/wiki/FAQGeneral#WhatlicensedoesGDALOGRuse">X/MIT</a> style <a href="http://www.opensource.org/">Open Source</a> license by the <a href="http://www.osgeo.org/">Open Source Geospatial Foundation</a>. As a library, it presents a <a class="el" href="gdal_datamodel.html">single abstract data model</a> to the calling application for all supported formats. It also comes with a variety of useful <a class="el" href="gdal_utilities.html">commandline utilities</a> for data translation and processing. The <a href="http://trac.osgeo.org/gdal/wiki/Release/1.7.2-News">NEWS</a> page describes the April 2010 GDAL/OGR 1.7.2 release.<p>
26 26
The related <a href="ogr/index.html">OGR</a> library (which lives within the GDAL source tree) provides a similar capability for simple features vector data.<p>
27 27
Master: <a href="http://www.gdal.org">http://www.gdal.org</a><br>
28 28
 Download: <a href="ftp://ftp.remotesensing.org/gdal">ftp at remotesensing.org</a>, <a href="http://download.osgeo.org/gdal">http at download.osgeo.org</a><h2><a class="anchor" name="index_userdocs">
1.10/trunk/binaries/mac/raster/gdal/GDAL.framework/Versions/1.7/Resources/gdal/stateplane.csv
33 33
1402,IOWA,SOUTH,2,NAD83,1402,26976
34 34
1501,KANSAS,NORTH,2,NAD83,1501,26977
35 35
1502,KANSAS,SOUTH,2,NAD83,1502,26978
36
1600,KENTUCKY,SINGLE ZONE,2,NAD83,1600,3088 
36 37
1601,KENTUCKY,NORTH,2,NAD83,1601,2205
37 38
1602,KENTUCKY,SOUTH,2,NAD83,1602,26980
38 39
1701,LOUISIANA,NORTH,2,NAD83,1701,26981
......
135 136
10404,CALIFORNIA,IV,2,NAD27,404,26744
136 137
10405,CALIFORNIA,V,2,NAD27,405,26745
137 138
10406,CALIFORNIA,VI,2,NAD27,406,26746
138
10407,CALIFORNIA,VII,2,NAD27,407,26747
139
10407,CALIFORNIA,VII,2,NAD27,407,26799
139 140
10501,COLORADO,NORTH,2,NAD27,501,26753
140 141
10502,COLORADO,CENTRAL,2,NAD27,502,26754
141 142
10503,COLORADO,SOUTH,2,NAD27,503,26755
1.10/trunk/binaries/mac/raster/gdal/GDAL.framework/Versions/1.7/Headers/cpl_atomic_ops.h
1 1
/**********************************************************************
2
 * $Id: cpl_atomic_ops.h 16035 2009-01-01 23:11:24Z tamas $
2
 * $Id: cpl_atomic_ops.h 19357 2010-04-10 09:27:35Z rouault $
3 3
 *
4 4
 * Name:     cpl_atomic_ops.h
5 5
 * Project:  CPL - Common Portability Library
......
69 69
  * @param ptr a pointer to an integer to increment
70 70
  * @return the pointed value AFTER the opeation: *ptr + 1
71 71
  */
72
#ifdef CPL_INLINE
72 73
CPL_INLINE int CPLAtomicInc(volatile int* ptr)
73 74
{
74 75
    return CPLAtomicAdd(ptr, 1);
75 76
}
77
#else
78
int CPL_DLL CPLAtomicInc(volatile int* ptr);
79
#endif
76 80

  
77 81
/** Decrement of 1 the pointed integer in a thread and SMP-safe way
78 82
  * and return the resulting value of the operation.
......
83 87
  * @param ptr a pointer to an integer to decrement
84 88
  * @return the pointed value AFTER the opeation: *ptr - 1
85 89
  */
90
#ifdef CPL_INLINE
86 91
CPL_INLINE int CPLAtomicDec(volatile int* ptr)
87 92
{
88 93
    return CPLAtomicAdd(ptr, -1);
89 94
}
95
#else
96
int CPL_DLL CPLAtomicDec(volatile int* ptr);
97
#endif
90 98

  
91 99
CPL_C_END
92 100

  
1.10/trunk/binaries/mac/raster/gdal/GDAL.framework/Versions/1.7/Headers/gdal_version.h
6 6
#ifndef GDAL_VERSION_MAJOR
7 7
#  define GDAL_VERSION_MAJOR    1
8 8
#  define GDAL_VERSION_MINOR    7
9
#  define GDAL_VERSION_REV      1
9
#  define GDAL_VERSION_REV      2
10 10
#  define GDAL_VERSION_BUILD    0
11 11
#endif
12 12

  
......
15 15
#endif
16 16

  
17 17
#ifndef GDAL_RELEASE_DATE
18
#  define GDAL_RELEASE_DATE     20100208
18
#  define GDAL_RELEASE_DATE     20100423
19 19
#endif
20 20
#ifndef GDAL_RELEASE_NAME
21
#  define GDAL_RELEASE_NAME     "1.7.1"
21
#  define GDAL_RELEASE_NAME     "1.7.2"
22 22
#endif
23 23

  
1.10/trunk/binaries/mac/raster/gdal/GDAL.framework/Versions/1.7/Python/site-packages/numpy/doc/structured_arrays.py
24 24
 >>> x[1]
25 25
 (2,3.,"World")
26 26

  
27
The interesting aspect is that we can reference the different fields of the
28
array simply by indexing the array with the string representing the name of
29
the field. In this case the fields have received the default names of 'f0', 'f1'
30
and 'f2'.
27
Conveniently, one can access any field of the array by indexing using the
28
string that names that field. In this case the fields have received the
29
default names 'f0', 'f1' and 'f2'.
31 30

  
32 31
 >>> y = x['f1']
33 32
 >>> y
......
40 39
       dtype=[('f0', '>i4'), ('f1', '>f4'), ('f2', '|S10')])
41 40

  
42 41
In these examples, y is a simple float array consisting of the 2nd field
43
in the record. But it is not a copy of the data in the structured array,
44
instead it is a view. It shares exactly the same data. Thus when we updated
45
this array by doubling its values, the structured array shows the
46
corresponding values as doubled as well. Likewise, if one changes the record,
47
the field view changes: ::
42
in the record. But, rather than being a copy of the data in the structured
43
array, it is a view, i.e., it shares exactly the same memory locations.
44
Thus, when we updated this array by doubling its values, the structured
45
array shows the corresponding values as doubled as well. Likewise, if one
46
changes the record, the field view also changes: ::
48 47

  
49 48
 >>> x[1] = (-1,-1.,"Master")
50 49
 >>> x
......
56 55
Defining Structured Arrays
57 56
==========================
58 57

  
59
The definition of a structured array is all done through the dtype object.
60
There are a **lot** of different ways one can define the fields of a
61
record. Some of variants are there to provide backward compatibility with
62
Numeric or numarray, or another module, and should not be used except for
63
such purposes. These will be so noted. One defines records by specifying
64
the structure by 4 general ways, using an argument (as supplied to a dtype
65
function keyword or a dtype object constructor itself) in the form of a:
66
1) string, 2) tuple, 3) list, or 4) dictionary. Each of these will be briefly
67
described.
58
One defines a structured array through the dtype object.  There are
59
**several** alternative ways to define the fields of a record.  Some of
60
these variants provide backward compatibility with Numeric, numarray, or
61
another module, and should not be used except for such purposes. These
62
will be so noted. One specifies record structure in
63
one of four alternative ways, using an argument (as supplied to a dtype
64
function keyword or a dtype object constructor itself).  This
65
argument must be one of the following: 1) string, 2) tuple, 3) list, or
66
4) dictionary.  Each of these is briefly described below.
68 67

  
69 68
1) String argument (as used in the above examples).
70
In this case, the constructor is expecting a comma
71
separated list of type specifiers, optionally with extra shape information.
69
In this case, the constructor expects a comma-separated list of type
70
specifiers, optionally with extra shape information.
72 71
The type specifiers can take 4 different forms: ::
73 72

  
74 73
  a) b1, i1, i2, i4, i8, u1, u2, u4, u8, f4, f8, c8, c16, a<n>
1.10/trunk/binaries/mac/raster/gdal/GDAL.framework/Versions/1.7/Python/site-packages/numpy/doc/__init__.py
20 20

  
21 21
You can view them by
22 22

  
23
>>> help(doc.TOPIC)
23
>>> help(np.doc.TOPIC)
24 24

  
25 25
""" % '\n- '.join([''] + __all__)
26 26

  
1.10/trunk/binaries/mac/raster/gdal/GDAL.framework/Versions/1.7/Python/site-packages/numpy/doc/broadcasting.py
13 13
broadcasting is a bad idea because it leads to inefficient use of memory
14 14
that slows computation.
15 15

  
16
NumPy operations are usually done element-by-element, which requires two
17
arrays to have exactly the same shape::
16
NumPy operations are usually done on pairs of arrays on an
17
element-by-element basis.  In the simplest case, the two arrays must
18
have exactly the same shape, as in the following example:
18 19

  
19 20
  >>> a = np.array([1.0, 2.0, 3.0])
20 21
  >>> b = np.array([2.0, 2.0, 2.0])
......
38 39
without actually making copies, so that broadcasting operations are as
39 40
memory and computationally efficient as possible.
40 41

  
41
The second example is more effective than the first, since here broadcasting
42
moves less memory around during the multiplication (``b`` is a scalar,
43
not an array).
42
The code in the second example is more efficient than that in the first
43
because broadcasting moves less memory around during the multiplication
44
(``b`` is a scalar rather than an array).
44 45

  
45 46
General Broadcasting Rules
46 47
==========================
......
107 108
  B      (1d array):  4 # trailing dimensions do not match
108 109

  
109 110
  A      (2d array):      2 x 1
110
  B      (3d array):  8 x 4 x 3 # second from last dimensions mismatch
111
  B      (3d array):  8 x 4 x 3 # second from last dimensions mismatched
111 112

  
112 113
An example of broadcasting in practice::
113 114

  
1.10/trunk/binaries/mac/raster/gdal/GDAL.framework/Versions/1.7/Python/site-packages/numpy/doc/creation.py
76 76

  
77 77
indices() will create a set of arrays (stacked as a one-higher dimensioned
78 78
array), one per dimension with each representing variation in that dimension.
79
An examples illustrates much better than a verbal description: ::
79
An example illustrates much better than a verbal description: ::
80 80

  
81 81
 >>> np.indices((3,3))
82 82
 array([[[0, 0, 0], [1, 1, 1], [2, 2, 2]], [[0, 1, 2], [0, 1, 2], [0, 1, 2]]])
1.10/trunk/binaries/mac/raster/gdal/GDAL.framework/Versions/1.7/Python/site-packages/numpy/doc/byteswapping.py
1
'''
2

  
3
=============================
4
 Byteswapping and byte order
5
=============================
6

  
7
Introduction to byte ordering and ndarrays
8
==========================================
9

  
10
The ``ndarray`` is an object that provide a python array interface to data
11
in memory.
12

  
13
It often happens that the memory that you want to view with an array is
14
not of the same byte ordering as the computer on which you are running
15
Python.
16

  
17
For example, I might be working on a computer with a little-endian CPU -
18
such as an Intel Pentium, but I have loaded some data from a file
19
written by a computer that is big-endian.  Let's say I have loaded 4
20
bytes from a file written by a Sun (big-endian) computer.  I know that
21
these 4 bytes represent two 16-bit integers.  On a big-endian machine, a
22
two-byte integer is stored with the Most Significant Byte (MSB) first,
23
and then the Least Significant Byte (LSB). Thus the bytes are, in memory order:
24

  
25
#. MSB integer 1
26
#. LSB integer 1
27
#. MSB integer 2
28
#. LSB integer 2
29

  
30
Let's say the two integers were in fact 1 and 770.  Because 770 = 256 *
31
3 + 2, the 4 bytes in memory would contain respectively: 0, 1, 3, 2.
32
The bytes I have loaded from the file would have these contents:
33

  
34
>>> big_end_str = chr(0) + chr(1) + chr(3) + chr(2)
35
>>> big_end_str
36
'\\x00\\x01\\x03\\x02'
37

  
38
We might want to use an ``ndarray`` to access these integers.  In that
39
case, we can create an array around this memory, and tell numpy that
40
there are two integers, and that they are 16 bit and big-endian:
41

  
42
>>> import numpy as np
43
>>> big_end_arr = np.ndarray(shape=(2,),dtype='>i2', buffer=big_end_str)
44
>>> big_end_arr[0]
45
1
46
>>> big_end_arr[1]
47
770
48

  
49
Note the array ``dtype`` above of ``>i2``.  The ``>`` means 'big-endian'
50
(``<`` is little-endian) and ``i2`` means 'signed 2-byte integer'.  For
51
example, if our data represented a single unsigned 4-byte little-endian
52
integer, the dtype string would be ``<u4``.
53

  
54
In fact, why don't we try that?
55

  
56
>>> little_end_u4 = np.ndarray(shape=(1,),dtype='<u4', buffer=big_end_str)
57
>>> little_end_u4[0] == 1 * 256**1 + 3 * 256**2 + 2 * 256**3
58
True
59

  
60
Returning to our ``big_end_arr`` - in this case our underlying data is
61
big-endian (data endianness) and we've set the dtype to match (the dtype
62
is also big-endian).  However, sometimes you need to flip these around.
63

  
64
Changing byte ordering
65
======================
66

  
67
As you can imagine from the introduction, there are two ways you can
68
affect the relationship between the byte ordering of the array and the
69
underlying memory it is looking at:
70

  
71
* Change the byte-ordering information in the array dtype so that it
72
  interprets the undelying data as being in a different byte order.
73
  This is the role of ``arr.newbyteorder()``
74
* Change the byte-ordering of the underlying data, leaving the dtype
75
  interpretation as it was.  This is what ``arr.byteswap()`` does.
76

  
77
The common situations in which you need to change byte ordering are:
78

  
79
#. Your data and dtype endianess don't match, and you want to change
80
   the dtype so that it matches the data.
81
#. Your data and dtype endianess don't match, and you want to swap the
82
   data so that they match the dtype
83
#. Your data and dtype endianess match, but you want the data swapped
84
   and the dtype to reflect this
85

  
86
Data and dtype endianness don't match, change dtype to match data
87
-----------------------------------------------------------------
88

  
89
We make something where they don't match:
90

  
91
>>> wrong_end_dtype_arr = np.ndarray(shape=(2,),dtype='<i2', buffer=big_end_str)
92
>>> wrong_end_dtype_arr[0]
93
256
94

  
95
The obvious fix for this situation is to change the dtype so it gives
96
the correct endianness:
97

  
98
>>> fixed_end_dtype_arr = wrong_end_dtype_arr.newbyteorder()
99
>>> fixed_end_dtype_arr[0]
100
1
101

  
102
Note the the array has not changed in memory:
103

  
104
>>> fixed_end_dtype_arr.tostring() == big_end_str
105
True
106

  
107
Data and type endianness don't match, change data to match dtype
108
----------------------------------------------------------------
109

  
110
You might want to do this if you need the data in memory to be a certain
111
ordering.  For example you might be writing the memory out to a file
112
that needs a certain byte ordering.
113

  
114
>>> fixed_end_mem_arr = wrong_end_dtype_arr.byteswap()
115
>>> fixed_end_mem_arr[0]
116
1
117

  
118
Now the array *has* changed in memory:
119

  
120
>>> fixed_end_mem_arr.tostring() == big_end_str
121
False
122

  
123
Data and dtype endianness match, swap data and dtype
124
----------------------------------------------------
125

  
126
You may have a correctly specified array dtype, but you need the array
127
to have the opposite byte order in memory, and you want the dtype to
128
match so the array values make sense.  In this case you just do both of
129
the previous operations:
130

  
131
>>> swapped_end_arr = big_end_arr.byteswap().newbyteorder()
132
>>> swapped_end_arr[0]
133
1
134
>>> swapped_end_arr.tostring() == big_end_str
135
False
136

  
137
'''
1.10/trunk/binaries/mac/raster/gdal/GDAL.framework/Versions/1.7/Python/site-packages/numpy/doc/constants.py
7 7

  
8 8
%(constant_list)s
9 9
"""
10
import textwrap
10
#
11
# Note: the docstring is autogenerated.
12
#
13
import textwrap, re
11 14

  
12 15
# Maintain same format as in numpy.add_newdocs
13 16
constants = []
......
18 21
    """
19 22
    IEEE 754 floating point representation of (positive) infinity.
20 23

  
21
    Returns
22
    -------
23
    y : A floating point representation of positive infinity.
24
    Use `inf` because `Inf`, `Infinity`, `PINF` and `infty` are aliases for
25
    `inf`. For more details, see `inf`.
24 26

  
25
    Notes
26
    -----
27
    Numpy uses the IEEE Standard for Binary Floating-Point for Arithmetic
28
    (IEEE 754). This means that Not a Number is not equivalent to infinity.
29
    Also that positive infinity is not equivalent to negative infinity. But
30
    infinity is equivalent to positive infinity.
27
    See Also
28
    --------
29
    inf
31 30

  
32
    Use numpy.inf because Inf, Infinity, PINF, infty are equivalent
33
    definitions of numpy.inf.
34

  
35 31
    """)
36 32

  
37 33
add_newdoc('numpy', 'Infinity',
38 34
    """
39 35
    IEEE 754 floating point representation of (positive) infinity.
40 36

  
41
    Returns
42
    -------
43
    y : A floating point representation of positive infinity.
37
    Use `inf` because `Inf`, `Infinity`, `PINF` and `infty` are aliases for
38
    `inf`. For more details, see `inf`.
44 39

  
45
    Notes
46
    -----
47
    Numpy uses the IEEE Standard for Binary Floating-Point for Arithmetic
48
    (IEEE 754). This means that Not a Number is not equivalent to infinity.
49
    Also that positive infinity is not equivalent to negative infinity. But
50
    infinity is equivalent to positive infinity.
40
    See Also
41
    --------
42
    inf
51 43

  
52
    Use numpy.inf because Inf, Infinity, PINF, infty are equivalent
53
    definitions of numpy.inf.
54

  
55 44
    """)
56 45

  
57 46
add_newdoc('numpy', 'NAN',
58 47
    """
59 48
    IEEE 754 floating point representation of Not a Number (NaN).
60 49

  
61
    Returns
62
    -------
63
    y : A floating point representation of Not a Number.
50
    `NaN` and `NAN` are equivalent definitions of `nan`. Please use
51
    `nan` instead of `NAN`.
64 52

  
65 53
    See Also
66 54
    --------
67
    isnan : Shows which elements are Not a Number.
68
    isfinite : Shows which elements are finite (not one of
69
               Not a Number, positive infinity and negative infinity)
70

  
71
    Notes
72
    -----
73
    Numpy uses the IEEE Standard for Binary Floating-Point for Arithmetic
74
    (IEEE 754). This means that Not a Number is not equivalent to infinity.
75

  
76
    NaN and NAN are equivalent definitions of numpy.nan. Please use
77
    numpy.nan instead of numpy.NAN.
78

  
79

  
80
    Examples
81
    --------
82
    >>> np.NAN
83 55
    nan
84
    >>> np.log(-1)
85
    nan
86
    >>> np.log([-1, 1, 2])
87
    array([        NaN,  0.        ,  0.69314718])
88 56

  
89 57
    """)
90 58

  
......
94 62

  
95 63
    Returns
96 64
    -------
97
    y : A floating point representation of negative infinity.
65
    y : float
66
        A floating point representation of negative infinity.
98 67

  
99 68
    See Also
100 69
    --------
......
116 85
    Also that positive infinity is not equivalent to negative infinity. But
117 86
    infinity is equivalent to positive infinity.
118 87

  
119

  
120 88
    Examples
121 89
    --------
122 90
    >>> np.NINF
......
132 100

  
133 101
    Returns
134 102
    -------
135
    y : A floating point representation of negative zero.
103
    y : float
104
        A floating point representation of negative zero.
136 105

  
137 106
    See Also
138 107
    --------
......
154 123
    Numpy uses the IEEE Standard for Binary Floating-Point for Arithmetic
155 124
    (IEEE 754). Negative zero is considered to be a finite number.
156 125

  
157

  
158 126
    Examples
159 127
    --------
160 128
    >>> np.NZERO
161 129
    -0.0
162 130
    >>> np.PZERO
163 131
    0.0
132

  
164 133
    >>> np.isfinite([np.NZERO])
165 134
    array([ True], dtype=bool)
166 135
    >>> np.isnan([np.NZERO])
......
174 143
    """
175 144
    IEEE 754 floating point representation of Not a Number (NaN).
176 145

  
177
    Returns
178
    -------
179
    y : A floating point representation of Not a Number.
146
    `NaN` and `NAN` are equivalent definitions of `nan`. Please use
147
    `nan` instead of `NaN`.
180 148

  
181 149
    See Also
182 150
    --------
183

  
184
    isnan : Shows which elements are Not a Number.
185
     isfinite : Shows which elements are finite (not one of
186
               Not a Number, positive infinity and negative infinity)
187

  
188
    Notes
189
    -----
190
    Numpy uses the IEEE Standard for Binary Floating-Point for Arithmetic
191
    (IEEE 754). This means that Not a Number is not equivalent to infinity.
192

  
193
    NaN and NAN are equivalent definitions of numpy.nan. Please use
194
    numpy.nan instead of numpy.NaN.
195

  
196

  
197
    Examples
198
    --------
199
    >>> np.NaN
200 151
    nan
201
    >>> np.log(-1)
202
    nan
203
    >>> np.log([-1, 1, 2])
204
    array([        NaN,  0.        ,  0.69314718])
205 152

  
206 153
    """)
207 154

  
......
209 156
    """
210 157
    IEEE 754 floating point representation of (positive) infinity.
211 158

  
212
    Returns
213
    -------
214
    y : A floating point representation of positive infinity.
159
    Use `inf` because `Inf`, `Infinity`, `PINF` and `infty` are aliases for
160
    `inf`. For more details, see `inf`.
215 161

  
216
    Notes
217
    -----
218
    Numpy uses the IEEE Standard for Binary Floating-Point for Arithmetic
219
    (IEEE 754). This means that Not a Number is not equivalent to infinity.
220
    Also that positive infinity is not equivalent to negative infinity. But
221
    infinity is equivalent to positive infinity.
162
    See Also
163
    --------
164
    inf
222 165

  
223
    Use numpy.inf because Inf, Infinity, PINF, infty are equivalent
224
    definitions of numpy.inf.
225

  
226 166
    """)
227 167

  
228 168
add_newdoc('numpy', 'PZERO',
......
231 171

  
232 172
    Returns
233 173
    -------
234
    y : A floating point representation of positive zero.
174
    y : float
175
        A floating point representation of positive zero.
235 176

  
236 177
    See Also
237 178
    --------
......
251 192
    Notes
252 193
    -----
253 194
    Numpy uses the IEEE Standard for Binary Floating-Point for Arithmetic
254
    (IEEE 754).
195
    (IEEE 754). Positive zero is considered to be a finite number.
255 196

  
256

  
257 197
    Examples
258 198
    --------
259 199
    >>> np.PZERO
260 200
    0.0
261 201
    >>> np.NZERO
262 202
    -0.0
203

  
263 204
    >>> np.isfinite([np.PZERO])
264 205
    array([ True], dtype=bool)
265 206
    >>> np.isnan([np.PZERO])
......
292 233

  
293 234
    Returns
294 235
    -------
295
    y : A floating point representation of positive infinity.
236
    y : float
237
        A floating point representation of positive infinity.
296 238

  
297 239
    See Also
298 240
    --------
......
314 256
    Also that positive infinity is not equivalent to negative infinity. But
315 257
    infinity is equivalent to positive infinity.
316 258

  
317
    Inf, Infinity, PINF, infty are equivalent definitions of numpy.inf.
259
    `Inf`, `Infinity`, `PINF` and `infty` are aliases for `inf`.
318 260

  
319

  
320 261
    Examples
321 262
    --------
322 263
    >>> np.inf
323 264
    inf
324
    >>> np.array([1])/0.
265
    >>> np.array([1]) / 0.
325 266
    array([ Inf])
326 267

  
327 268
    """)
......
330 271
    """
331 272
    IEEE 754 floating point representation of (positive) infinity.
332 273

  
333
    Returns
334
    -------
335
    y : A floating point representation of positive infinity.
274
    Use `inf` because `Inf`, `Infinity`, `PINF` and `infty` are aliases for
275
    `inf`. For more details, see `inf`.
336 276

  
337
    Notes
338
    -----
339
    Numpy uses the IEEE Standard for Binary Floating-Point for Arithmetic
340
    (IEEE 754). This means that Not a Number is not equivalent to infinity.
341
    Also that positive infinity is not equivalent to negative infinity. But
342
    infinity is equivalent to positive infinity.
277
    See Also
278
    --------
279
    inf
343 280

  
344
    Use numpy.inf because Inf, Infinity, PINF, infty are equivalent
345
    definitions of numpy.inf.
346

  
347 281
    """)
348 282

  
349 283
add_newdoc('numpy', 'nan',
......
365 299
    Numpy uses the IEEE Standard for Binary Floating-Point for Arithmetic
366 300
    (IEEE 754). This means that Not a Number is not equivalent to infinity.
367 301

  
368
    NaN and NAN are equivalent definitions of numpy.nan.
302
    `NaN` and `NAN` are aliases of `nan`.
369 303

  
370

  
371 304
    Examples
372 305
    --------
373 306
    >>> np.nan
......
381 314

  
382 315
add_newdoc('numpy', 'newaxis',
383 316
    """
317
    A convenient alias for None, useful for indexing arrays.
318

  
384 319
    See Also
385 320
    --------
386 321
    `numpy.doc.indexing`
......
392 327
    >>> x = np.arange(3)
393 328
    >>> x
394 329
    array([0, 1, 2])
395
    >>> x[:,newaxis]
330
    >>> x[:, newaxis]
396 331
    array([[0],
397 332
    [1],
398 333
    [2]])
399
    >>> x[:,newaxis,newaxis]
334
    >>> x[:, newaxis, newaxis]
400 335
    array([[[0]],
401 336
    [[1]],
402 337
    [[2]]])
403
    >>> x[:,newaxis] * x
338
    >>> x[:, newaxis] * x
404 339
    array([[0, 0, 0],
405 340
    [0, 1, 2],
406 341
    [0, 2, 4]])
407 342

  
408
    Outer product, same as outer(x,y):
343
    Outer product, same as ``outer(x, y)``:
409 344

  
410
    >>> y = np.arange(3,6)
411
    >>> x[:,newaxis] * y
345
    >>> y = np.arange(3, 6)
346
    >>> x[:, newaxis] * y
412 347
    array([[ 0,  0,  0],
413 348
    [ 3,  4,  5],
414 349
    [ 6,  8, 10]])
415 350

  
416
    x[newaxis,:] is equivalent to x[newaxis] and x[None]:
351
    ``x[newaxis, :]`` is equivalent to ``x[newaxis]`` and ``x[None]``:
417 352

  
418
    >>> x[newaxis,:].shape
353
    >>> x[newaxis, :].shape
419 354
    (1, 3)
420 355
    >>> x[newaxis].shape
421 356
    (1, 3)
422 357
    >>> x[None].shape
423 358
    (1, 3)
424
    >>> x[:,newaxis].shape
359
    >>> x[:, newaxis].shape
425 360
    (3, 1)
426 361

  
427 362
    """)
......
430 365
    constants_str = []
431 366
    constants.sort()
432 367
    for name, doc in constants:
433
        constants_str.append(""".. const:: %s\n    %s""" % (
434
            name, textwrap.dedent(doc).replace("\n", "\n    ")))
368
        s = textwrap.dedent(doc).replace("\n", "\n    ")
369

  
370
        # Replace sections by rubrics
371
        lines = s.split("\n")
372
        new_lines = []
373
        for line in lines:
374
            m = re.match(r'^(\s+)[-=]+\s*$', line)
375
            if m and new_lines:
376
                prev = textwrap.dedent(new_lines.pop())
377
                new_lines.append('%s.. rubric:: %s' % (m.group(1), prev))
378
                new_lines.append('')
379
            else:
380
                new_lines.append(line)
381
        s = "\n".join(new_lines)
382

  
383
        # Done.
384
        constants_str.append(""".. const:: %s\n    %s""" % (name, s))
435 385
    constants_str = "\n".join(constants_str)
436 386

  
437 387
    __doc__ = __doc__ % dict(constant_list=constants_str)
438 388
    del constants_str, name, doc
389
    del line, lines, new_lines, m, s, prev
439 390

  
440 391
del constants, add_newdoc
1.10/trunk/binaries/mac/raster/gdal/GDAL.framework/Versions/1.7/Python/site-packages/numpy/doc/subclassing.py
11 11

  
12 12
Introduction
13 13
------------
14
Subclassing ndarray is relatively simple, but you will need to
15
understand some behavior of ndarrays to understand some minor
16
complications to subclassing.  There are examples at the bottom of the
17
page, but you will probably want to read the background to understand
18
why subclassing works as it does.
19 14

  
15
Subclassing ndarray is relatively simple, but it has some complications
16
compared to other Python objects.  On this page we explain the machinery
17
that allows you to subclass ndarray, and the implications for
18
implementing a subclass.
19

  
20 20
ndarrays and object creation
21 21
============================
22
The creation of ndarrays is complicated by the need to return views of
23
ndarrays, that are also ndarrays.  For example:
24 22

  
23
Subclassing ndarray is complicated by the fact that new instances of
24
ndarray classes can come about in three different ways.  These are:
25

  
26
#. Explicit constructor call - as in ``MySubClass(params)``.  This is
27
   the usual route to Python instance creation.
28
#. View casting - casting an existing ndarray as a given subclass
29
#. New from template - creating a new instance from a template
30
   instance. Examples include returning slices from a subclassed array,
31
   creating return types from ufuncs, and copying arrays.  See
32
   :ref:`new-from-template` for more details
33

  
34
The last two are characteristics of ndarrays - in order to support
35
things like array slicing.  The complications of subclassing ndarray are
36
due to the mechanisms numpy has to support these latter two routes of
37
instance creation.
38

  
39
.. _view-casting:
40

  
41
View casting
42
------------
43

  
44
*View casting* is the standard ndarray mechanism by which you take an
45
ndarray of any subclass, and return a view of the array as another
46
(specified) subclass:
47

  
25 48
>>> import numpy as np
49
>>> # create a completely useless ndarray subclass
50
>>> class C(np.ndarray): pass
51
>>> # create a standard ndarray
26 52
>>> arr = np.zeros((3,))
27
>>> type(arr)
28
<type 'numpy.ndarray'>
29
>>> v = arr[1:]
30
>>> type(v)
31
<type 'numpy.ndarray'>
32
>>> v is arr
53
>>> # take a view of it, as our useless subclass
54
>>> c_arr = arr.view(C)
55
>>> type(c_arr)
56
<class 'C'>
57

  
58
.. _new-from-template:
59

  
60
Creating new from template
61
--------------------------
62

  
63
New instances of an ndarray subclass can also come about by a very
64
similar mechanism to :ref:`view-casting`, when numpy finds it needs to
65
create a new instance from a template instance.  The most obvious place
66
this has to happen is when you are taking slices of subclassed arrays.
67
For example:
68

  
69
>>> v = c_arr[1:]
70
>>> type(v) # the view is of type 'C'
71
<class 'C'>
72
>>> v is c_arr # but it's a new instance
33 73
False
34 74

  
35
So, when we take a view (here a slice) from the ndarray, we return a
36
new ndarray, that points to the data in the original.  When we
37
subclass ndarray, taking a view (such as a slice) needs to return an
38
object of our own class.  There is machinery to do this, but it is
39
this machinery that makes subclassing slightly non-standard.
75
The slice is a *view* onto the original ``c_arr`` data.  So, when we
76
take a view from the ndarray, we return a new ndarray, of the same
77
class, that points to the data in the original.
40 78

  
41
To allow subclassing, and views of subclasses, ndarray uses the
42
ndarray ``__new__`` method for the main work of object initialization,
43
rather then the more usual ``__init__`` method.
79
There are other points in the use of ndarrays where we need such views,
80
such as copying arrays (``c_arr.copy()``), creating ufunc output arrays
81
(see also :ref:`array-wrap`), and reducing methods (like
82
``c_arr.mean()``.
44 83

  
45
``__new__`` and ``__init__``
46
============================
84
Relationship of view casting and new-from-template
85
--------------------------------------------------
47 86

  
48
``__new__`` is a standard python method, and, if present, is called
49
before ``__init__`` when we create a class instance. Consider the
50
following::
87
These paths both use the same machinery.  We make the distinction here,
88
because they result in different input to your methods.  Specifically,
89
:ref:`view-casting` means you have created a new instance of your array
90
type from any potential subclass of ndarray.  :ref:`new-from-template`
91
means you have created a new instance of your class from a pre-existing
92
instance, allowing you - for example - to copy across attributes that
93
are particular to your subclass.
51 94

  
95
Implications for subclassing
96
----------------------------
97

  
98
If we subclass ndarray, we need to deal not only with explicit
99
construction of our array type, but also :ref:`view-casting` or
100
:ref:`new-from-template`.  Numpy has the machinery to do this, and this
101
machinery that makes subclassing slightly non-standard.
102

  
103
There are two aspects to the machinery that ndarray uses to support
104
views and new-from-template in subclasses.
105

  
106
The first is the use of the ``ndarray.__new__`` method for the main work
107
of object initialization, rather then the more usual ``__init__``
108
method.  The second is the use of the ``__array_finalize__`` method to
109
allow subclasses to clean up after the creation of views and new
110
instances from templates.
111

  
112
A brief Python primer on ``__new__`` and ``__init__``
113
=====================================================
114

  
115
``__new__`` is a standard Python method, and, if present, is called
116
before ``__init__`` when we create a class instance. See the `python
117
__new__ documentation
118
<http://docs.python.org/reference/datamodel.html#object.__new__>`_ for more detail.
119

  
120
For example, consider the following Python code:
121

  
122
.. testcode::
123

  
52 124
  class C(object):
53 125
      def __new__(cls, *args):
126
          print 'Cls in __new__:', cls
54 127
          print 'Args in __new__:', args
55 128
          return object.__new__(cls, *args)
129

  
56 130
      def __init__(self, *args):
131
          print 'type(self) in __init__:', type(self)
57 132
          print 'Args in __init__:', args
58 133

  
59
  C('hello')
134
meaning that we get:
60 135

  
61
The code gives the following output::
136
>>> c = C('hello')
137
Cls in __new__: <class 'C'>
138
Args in __new__: ('hello',)
139
type(self) in __init__: <class 'C'>
140
Args in __init__: ('hello',)
62 141

  
63
  cls is: <class '__main__.C'>
64
  Args in __new__: ('hello',)
65
  self is : <__main__.C object at 0xb7dc720c>
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff