[gdal-dev] calling GDALExtractRPCInfo in fortran‏

Jintro luna jintro_luna at hotmail.com
Tue Feb 18 11:13:18 PST 2014




Hi all,

I need to read a Geotiff (DEM) file in one of my fortran 
programs. GDAL has been extremely useful so far, I managed to open and 
read the file and this all seems to go well. However, when I try to get 
information on the file, I run into problems. I know that 
GDALExtractRPCInfo expects a C pointer as its first input argument, but 
I'm a bit lost on how to define such a pointer in fortran (I'm 
embarrassed to admit, but I have never used C before). I had a look at 
the fortranc functions, but could only find functions to define 
c_ptr_ptr types, which didn't solve the problem.

I assume there 
is a very basic solution to this, but after half a day of browsing the 
web, I'm still stuck. Your help would be very much appreciated. My code 
is below.

PROGRAM DEM_test
USE,INTRINSIC :: iso_c_binding
USE fortranc
USE gdal

IMPLICIT none
character*200 :: infile
character(kind=c_char), target:: c_infile
TYPE(GDALRPCInfo) :: info
TYPE(gdaldataseth) :: ds
TYPE(gdalrasterbandh) :: band
TYPE(c_ptr) ptr1

INTEGER(kind=c_int) :: i2,j2,ierr,nraster
REAL,ALLOCATABLE :: z(:,:)

 CALL gdalallregister()

 infile='/windows/C/Users/bertw/Desktop/Data/DEMS/Canada/aster_gdem_50m_ncaa.tif'//CHAR(0)


 ds = gdalopen(TRIM(infile)//CHAR(0), GA_ReadOnly)
 IF (.NOT.gdalassociated(ds)) THEN
   PRINT*,'Error opening dataset on file ',TRIM(infile)
   STOP 1
 ENDIF

 i2=gdalgetrasterxsize(ds)
 j2=gdalgetrasterysize(ds)
 nraster=gdalgetrastercount(ds)
 allocate(z(i2,j2))

 band = gdalgetrasterband(ds, 1)
 ierr = gdalrasterio_f(band, GF_Read, 0, 0, z)
 write(6,*) 'ok' !<---- runs fine up to here

 c_infile=infile 
 write(6,*) c_infile  ! <--- part of the problem seems to be that only  the first character is copied to c_infile
 ptr1=c_loc(c_infile)
 ierr=GDALExtractRPCInfo( ptr1,info)
 write(6,*) info
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20140218/c9e8d415/attachment.html>


More information about the gdal-dev mailing list