@@ -25,71 +25,8 @@ module proj_mod
25
25
final :: proj_final
26
26
end type proj_type
27
27
28
- type, bind(c) :: PJ_XYZT
29
- real (c_double) x
30
- real (c_double) y
31
- real (c_double) z
32
- real (c_double) t
33
- end type PJ_XYZT
34
-
35
- type, bind(c) :: PJ_UVWT
36
- real (c_double) u
37
- real (c_double) v
38
- real (c_double) w
39
- real (c_double) t
40
- end type PJ_UVWT
41
-
42
- type, bind(c) :: PJ_LPZT
43
- real (c_double) lam
44
- real (c_double) phi
45
- real (c_double) z
46
- real (c_double) t
47
- end type PJ_LPZT
48
-
49
- type, bind(c) :: PJ_XYZ
50
- real (c_double) x
51
- real (c_double) y
52
- real (c_double) z
53
- end type PJ_XYZ
54
-
55
- type, bind(c) :: PJ_UVW
56
- real (c_double) u
57
- real (c_double) v
58
- real (c_double) w
59
- end type PJ_UVW
60
-
61
- type, bind(c) :: PJ_LPZ
62
- real (c_double) lam
63
- real (c_double) phi
64
- real (c_double) z
65
- end type PJ_LPZ
66
-
67
- type, bind(c) :: PJ_XY
68
- real (c_double) x
69
- real (c_double) y
70
- end type PJ_XY
71
-
72
- type, bind(c) :: PJ_UV
73
- real (c_double) u
74
- real (c_double) v
75
- end type PJ_UV
76
-
77
- type, bind(c) :: PJ_LP
78
- real (c_double) lam
79
- real (c_double) phi
80
- end type PJ_LP
81
-
82
28
type, bind(c) :: PJ_COORD
83
29
real (c_double) v(4 )
84
- type (PJ_XYZT) xyzt
85
- type (PJ_UVWT) uvwt
86
- type (PJ_LPZT) lpzt
87
- type (PJ_XYZ) xyz
88
- type (PJ_UVW) uvw
89
- type (PJ_LPZ) lpz
90
- type (PJ_XY) xy
91
- type (PJ_UV) uv
92
- type (PJ_LP) lp
93
30
end type PJ_COORD
94
31
95
32
interface
@@ -115,13 +52,32 @@ subroutine proj_destroy(pj) bind(c)
115
52
type (c_ptr), value :: pj
116
53
end subroutine proj_destroy
117
54
55
+ type (PJ_COORD) function proj_coord(x, y, z, t) bind(c)
56
+ use , intrinsic :: iso_c_binding
57
+ import PJ_COORD
58
+ real (c_double), value :: x
59
+ real (c_double), value :: y
60
+ real (c_double), value :: z
61
+ real (c_double), value :: t
62
+ end function proj_coord
63
+
118
64
type (PJ_COORD) function proj_trans(pj, direction, coord) bind(c)
119
65
use , intrinsic :: iso_c_binding
120
66
import PJ_COORD
121
67
type (c_ptr), value :: pj
122
68
integer (c_int), value :: direction
123
69
type (PJ_COORD), value :: coord
124
70
end function proj_trans
71
+
72
+ integer (c_int) function proj_errno(pj) bind(c)
73
+ use , intrinsic :: iso_c_binding
74
+ type (c_ptr), value :: pj
75
+ end function proj_errno
76
+
77
+ type (c_ptr) function proj_errno_string(ierr) bind(c)
78
+ use , intrinsic :: iso_c_binding
79
+ integer (c_int), value :: ierr
80
+ end function proj_errno_string
125
81
end interface
126
82
127
83
contains
@@ -159,44 +115,25 @@ end subroutine proj_set_dst_crs
159
115
subroutine proj_transform (this , xi , yi , xo , yo )
160
116
161
117
class(proj_type), intent (inout ) :: this
162
- class( * ), intent (in ) :: xi
163
- class( * ), intent (in ) :: yi
164
- class( * ), intent (out ) :: xo
165
- class( * ), intent (out ) :: yo
118
+ real ( 8 ), intent (in ) :: xi
119
+ real ( 8 ), intent (in ) :: yi
120
+ real ( 8 ), intent (out ) :: xo
121
+ real ( 8 ), intent (out ) :: yo
166
122
167
123
type (PJ_COORD) pj_xi, pj_xo
168
124
169
125
if (.not. c_associated(this% pj)) then
170
126
this% pj = proj_create_crs_to_crs(this% ctx, this% src_crs, this% dst_crs, c_null_ptr)
127
+ if (proj_errno(this% pj) /= 0 ) then
128
+ write (* , * ) ' [Error]: Failed to create pj object!'
129
+ stop 1
130
+ end if
171
131
end if
172
132
173
- select type (xi)
174
- type is (real (4 ))
175
- pj_xi% lpzt% lam = xi
176
- type is (real (8 ))
177
- pj_xi% lpzt% lam = xi
178
- end select
179
- select type (yi)
180
- type is (real (4 ))
181
- pj_xi% lpzt% phi = yi
182
- type is (real (8 ))
183
- pj_xi% lpzt% phi = yi
184
- end select
185
- print * , pj_xi
133
+ pj_xi = proj_coord(xi, yi, 0.0d0 , 0.0d0 )
186
134
pj_xo = proj_trans(this% pj, PJ_FWD, pj_xi)
187
- print * , pj_xo
188
- select type (xo)
189
- type is (real (4 ))
190
- xo = pj_xo% xyzt% x
191
- type is (real (8 ))
192
- xo = pj_xo% xyzt% x
193
- end select
194
- select type (yo)
195
- type is (real (4 ))
196
- yo = pj_xo% xyzt% y
197
- type is (real (8 ))
198
- yo = pj_xo% xyzt% y
199
- end select
135
+ xo = pj_xo% v(1 )
136
+ yo = pj_xo% v(2 )
200
137
201
138
end subroutine proj_transform
202
139
@@ -209,4 +146,13 @@ subroutine proj_final(this)
209
146
210
147
end subroutine proj_final
211
148
149
+ function get_proj_error_message (ierr ) result(res)
150
+
151
+ integer , intent (in ) :: ierr
152
+ character , pointer :: res(:)
153
+
154
+ call c_f_pointer(proj_errno_string(ierr), res)
155
+
156
+ end function get_proj_error_message
157
+
212
158
end module proj_mod
0 commit comments