FortranGIS  Version2.5
proj.F90
1 ! Copyright 2011 Davide Cesari <dcesari69 at gmail dot com>
2 !
3 ! This file is part of FortranGIS.
4 !
5 ! FortranGIS is free software: you can redistribute it and/or modify
6 ! it under the terms of the GNU Lesser General Public License as
7 ! published by the Free Software Foundation, either version 3 of the
8 ! License, or (at your option) any later version.
9 !
10 ! FortranGIS is distributed in the hope that it will be useful, but
11 ! WITHOUT ANY WARRANTY; without even the implied warranty of
12 ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ! Lesser General Public License for more details.
14 !
15 ! You should have received a copy of the GNU Lesser General Public
16 ! License along with FortranGIS. If not, see
17 ! <http://www.gnu.org/licenses/>.
18 
51 MODULE proj
52 use,INTRINSIC :: iso_c_binding
53 IMPLICIT NONE
54 
58 TYPE,bind(c) :: pj_object
59  PRIVATE
60  TYPE(c_ptr) :: ptr = c_null_ptr
61 END TYPE pj_object
62 
66 TYPE(pj_object),PARAMETER :: pj_object_null=pj_object(c_null_ptr)
67 
71 TYPE,bind(c) :: pjuv_object
72  REAL(kind=c_double) :: u=huge(1.0_c_double)
73  REAL(kind=c_double) :: v=huge(1.0_c_double)
74 END TYPE pjuv_object
75 
76 REAL(kind=c_double),PARAMETER :: pj_deg_to_rad=.0174532925199432958d0
77 REAL(kind=c_double),PARAMETER :: pj_rad_to_deg=57.29577951308232d0
78 
82 INTERFACE pj_associated
83  MODULE PROCEDURE pj_associated_object
84 END INTERFACE pj_associated
85 
88 INTERFACE
89  FUNCTION pj_init_plus(name) BIND(C,name='pj_init_plus')
90  import
91  CHARACTER(kind=c_char) :: name(*)
92  TYPE(pj_object) :: pj_init_plus
93  END FUNCTION pj_init_plus
94 END INTERFACE
95 
96 INTERFACE
97  FUNCTION pj_transform(src, dst, point_count, point_offset, x, y, z) &
98  bind(c,name='pj_transform')
99  import
100  TYPE(pj_object),VALUE :: src
101  TYPE(pj_object),VALUE :: dst
102  INTEGER(kind=c_long),VALUE :: point_count
103  INTEGER(kind=c_int),VALUE :: point_offset
104  REAL(kind=c_double) :: x(*)
105  REAL(kind=c_double) :: y(*)
106  REAL(kind=c_double) :: z(*)
107  INTEGER(kind=c_int) :: pj_transform
108  END FUNCTION pj_transform
109 END INTERFACE
110 
111 INTERFACE
112  FUNCTION pj_datum_transform(src, dst, point_count, point_offset, x, y, z) &
113  bind(c,name='pj_datum_transform')
114  import
115  TYPE(pj_object),VALUE :: src
116  TYPE(pj_object),VALUE :: dst
117  INTEGER(kind=c_long),VALUE :: point_count
118  INTEGER(kind=c_int),VALUE :: point_offset
119  REAL(kind=c_double) :: x(*)
120  REAL(kind=c_double) :: y(*)
121  REAL(kind=c_double) :: z(*)
122  INTEGER(kind=c_int) :: pj_datum_transform
123  END FUNCTION pj_datum_transform
124 END INTERFACE
125 
126 INTERFACE
127  FUNCTION pj_fwd(val, proj) BIND(C,name='pj_fwd')
128  import
129  TYPE(pjuv_object),VALUE :: val
130  TYPE(pj_object),VALUE :: proj
131  TYPE(pjuv_object) :: pj_fwd
132  END FUNCTION pj_fwd
133 END INTERFACE
134 
135 INTERFACE
136  FUNCTION pj_inv(val, proj) BIND(C,name='pj_inv')
137  import
138  TYPE(pjuv_object),VALUE :: val
139  TYPE(pj_object),VALUE :: proj
140  TYPE(pjuv_object) :: pj_inv
141  END FUNCTION pj_inv
142 END INTERFACE
143 
144 INTERFACE
145  FUNCTION pj_geocentric_to_geodetic(a, es, point_count, point_offset, x, y, z) &
146  bind(c,name='pj_geocentric_to_geodetic')
147  import
148  REAL(kind=c_double),VALUE :: a
149  REAL(kind=c_double),VALUE :: es
150  INTEGER(kind=c_long),VALUE :: point_count
151  INTEGER(kind=c_int),VALUE :: point_offset
152  REAL(kind=c_double) :: x(*)
153  REAL(kind=c_double) :: y(*)
154  REAL(kind=c_double) :: z(*)
155  INTEGER(kind=c_int) :: pj_geocentric_to_geodetic
156  END FUNCTION pj_geocentric_to_geodetic
157 END INTERFACE
158 
159 INTERFACE
160  FUNCTION pj_geodetic_to_geocentric(a, es, point_count, point_offset, x, y, z) &
161  bind(c,name='pj_geodetic_to_geocentric')
162  import
163  REAL(kind=c_double),VALUE :: a
164  REAL(kind=c_double),VALUE :: es
165  INTEGER(kind=c_long),VALUE :: point_count
166  INTEGER(kind=c_int),VALUE :: point_offset
167  REAL(kind=c_double) :: x(*)
168  REAL(kind=c_double) :: y(*)
169  REAL(kind=c_double) :: z(*)
170  INTEGER(kind=c_int) :: pj_geodetic_to_geocentric
171  END FUNCTION pj_geodetic_to_geocentric
172 END INTERFACE
173 
174 INTERFACE
175  FUNCTION pj_compare_datums(srcdefn, dstdefn) BIND(C,name='pj_compare_datums')
176  import
177  TYPE(pj_object),VALUE :: srcdefn
178  TYPE(pj_object),VALUE :: dstdefn
179  INTEGER(kind=c_int) :: pj_compare_datums
180  END FUNCTION pj_compare_datums
181 END INTERFACE
182 
183 INTERFACE
184  FUNCTION pj_is_latlong(proj) BIND(C,name='pj_is_latlong')
185  import
186  TYPE(pj_object),VALUE :: proj
187  INTEGER(kind=c_int) :: pj_is_latlong
188  END FUNCTION pj_is_latlong
189 END INTERFACE
190 
191 INTERFACE
192  FUNCTION pj_is_geocent(proj) BIND(C,name='pj_is_geocent')
193  import
194  TYPE(pj_object),VALUE :: proj
195  INTEGER(kind=c_int) :: pj_is_geocent
196  END FUNCTION pj_is_geocent
197 END INTERFACE
198 
199 INTERFACE
200  FUNCTION pj_get_def(proj, options) BIND(C,name='pj_get_def')
201  import
202  TYPE(pj_object),VALUE :: proj
203  INTEGER(kind=c_int) :: options
204  TYPE(c_ptr) :: pj_get_def
205  END FUNCTION pj_get_def
206 END INTERFACE
207 
208 
209 INTERFACE
210  FUNCTION pj_latlong_from_proj(proj) BIND(C,name='pj_latlong_from_proj')
211  import
212  TYPE(pj_object),VALUE :: proj
213  TYPE(pj_object) :: pj_latlong_from_proj
214  END FUNCTION pj_latlong_from_proj
215 END INTERFACE
216 
217 !INTERFACE
218 ! FUNCTION pj_apply_gridshift(c, i, point_count, point_offset, x, y, z) &
219 ! BIND(C,name='pj_apply_gridshift')
220 ! IMPORT
221 ! CHARACTER(kind=c_char) :: c(*)
222 ! INTEGER(kind=c_int),VALUE :: i
223 ! INTEGER(kind=c_long),VALUE :: point_count
224 ! INTEGER(kind=c_int),VALUE :: point_offset
225 ! REAL(kind=c_double) :: x(*)
226 ! REAL(kind=c_double) :: y(*)
227 ! REAL(kind=c_double) :: z(*)
228 ! INTEGER(kind=c_int) :: pj_apply_gridshift
229 ! END FUNCTION pj_apply_gridshift
230 !END INTERFACE
231 !
232 !INTERFACE
233 ! SUBROUTINE pj_deallocate_grids() BIND(C,name='pj_deallocate_grids')
234 ! END SUBROUTINE pj_deallocate_grids
235 !END INTERFACE
236 
237 INTERFACE
238  SUBROUTINE pj_free(proj) BIND(C,name='pj_free')
239  import
240  TYPE(pj_object),VALUE :: proj
241  END SUBROUTINE pj_free
242 END INTERFACE
243 
244 !void pj_pr_list(projPJ);
245 !void pj_set_finder( const char *(*)(const char *) );
246 !void pj_set_searchpath ( int count, const char **path );
247 !projPJ pj_init(int, char **);
248 !char *pj_get_def(projPJ, int);
249 !void *pj_malloc(size_t);
250 !void pj_dalloc(void *);
251 !char *pj_strerrno(int);
252 !int *pj_get_errno_ref(void);
253 !const char *pj_get_release(void);
254 
255 CONTAINS
256 
260 FUNCTION pj_associated_object(arg1, arg2) RESULT(associated_)
261 TYPE(pj_object),INTENT(in) :: arg1
262 TYPE(pj_object),INTENT(in),OPTIONAL :: arg2
263 LOGICAL :: associated_
264 IF(PRESENT(arg2)) THEN
265  associated_ = c_associated(arg1%ptr, arg2%ptr)
266 ELSE
267  associated_ = c_associated(arg1%ptr)
268 ENDIF
269 END FUNCTION pj_associated_object
270 
271 ! Fortran specific version of some functions
278 FUNCTION pj_transform_f(src, dst, x, y, z)
279 TYPE(pj_object),VALUE :: src
280 TYPE(pj_object),VALUE :: dst
281 REAL(kind=c_double) :: x(:)
282 REAL(kind=c_double) :: y(:)
283 REAL(kind=c_double),OPTIONAL :: z(:)
284 INTEGER(kind=c_int) :: pj_transform_f
285 
286 REAL(kind=c_double),POINTER :: dummyz(:)
287 
288 IF (PRESENT(z)) THEN
289  pj_transform_f = pj_transform(src, dst, &
290  int(min(SIZE(x),SIZE(y),SIZE(z)), kind=c_long), 1_c_int, x, y, z)
291 ELSE
292  NULLIFY(dummyz)
293  pj_transform_f = pj_transform(src, dst, &
294  int(min(SIZE(x),SIZE(y)), kind=c_long), 1_c_int, x, y, dummyz)
295 ENDIF
296 
297 END FUNCTION pj_transform_f
298 
299 
305 FUNCTION pj_datum_transform_f(src, dst, x, y, z)
306 TYPE(pj_object),VALUE :: src
307 TYPE(pj_object),VALUE :: dst
308 REAL(kind=c_double) :: x(:)
309 REAL(kind=c_double) :: y(:)
310 REAL(kind=c_double),OPTIONAL :: z(:)
311 INTEGER(kind=c_int) :: pj_datum_transform_f
312 
313 REAL(kind=c_double),POINTER :: dummyz(:)
314 
315 IF (PRESENT(z)) THEN
316  pj_datum_transform_f = pj_datum_transform(src, dst, &
317  int(min(SIZE(x),SIZE(y),SIZE(z)), kind=c_long), 1_c_int, x, y, z)
318 ELSE
319  NULLIFY(dummyz)
320  pj_datum_transform_f = pj_datum_transform(src, dst, &
321  int(min(SIZE(x),SIZE(y)), kind=c_long), 1_c_int, x, y, dummyz)
322 ENDIF
323 
324 END FUNCTION pj_datum_transform_f
325 
326 
332 FUNCTION pj_geocentric_to_geodetic_f(a, es, x, y, z)
333 REAL(kind=c_double),VALUE :: a
334 REAL(kind=c_double),VALUE :: es
335 REAL(kind=c_double) :: x(:)
336 REAL(kind=c_double) :: y(:)
337 REAL(kind=c_double) :: z(:)
338 INTEGER(kind=c_int) :: pj_geocentric_to_geodetic_f
339 
340 pj_geocentric_to_geodetic_f = &
341  pj_geocentric_to_geodetic(a, es, &
342  int(min(SIZE(x),SIZE(y),SIZE(x)), kind=c_long), 1_c_int, x, y, z)
343 
344 END FUNCTION pj_geocentric_to_geodetic_f
345 
346 
352 FUNCTION pj_geodetic_to_geocentric_f(a, es, x, y, z)
353 REAL(kind=c_double),VALUE :: a
354 REAL(kind=c_double),VALUE :: es
355 REAL(kind=c_double) :: x(:)
356 REAL(kind=c_double) :: y(:)
357 REAL(kind=c_double) :: z(:)
358 INTEGER(kind=c_int) :: pj_geodetic_to_geocentric_f
359 
360 pj_geodetic_to_geocentric_f = &
361  pj_geodetic_to_geocentric(a, es, &
362  int(min(SIZE(x),SIZE(y),SIZE(x)), kind=c_long), 1_c_int, x, y, z)
363 
364 END FUNCTION pj_geodetic_to_geocentric_f
365 
366 
367 END MODULE proj
Initialize a projection from a string.
Definition: proj.F90:100
Fortran 2003 interface to the proj.4 https://github.com/OSGeo/proj.4 library.
Definition: proj.F90:62
Object describing a coordinate pair.
Definition: proj.F90:82
Object describing a cartographic projection.
Definition: proj.F90:69
Test whether an opaque object is valid.
Definition: proj.F90:93