Skip to content

Commit c7af1cf

Browse files
committed
Test transform
1 parent e88f764 commit c7af1cf

File tree

3 files changed

+42
-95
lines changed

3 files changed

+42
-95
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build

src/proj_mod.F90

+39-93
Original file line numberDiff line numberDiff line change
@@ -25,71 +25,8 @@ module proj_mod
2525
final :: proj_final
2626
end type proj_type
2727

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-
8228
type, bind(c) :: PJ_COORD
8329
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
9330
end type PJ_COORD
9431

9532
interface
@@ -115,13 +52,32 @@ subroutine proj_destroy(pj) bind(c)
11552
type(c_ptr), value :: pj
11653
end subroutine proj_destroy
11754

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+
11864
type(PJ_COORD) function proj_trans(pj, direction, coord) bind(c)
11965
use, intrinsic :: iso_c_binding
12066
import PJ_COORD
12167
type(c_ptr), value :: pj
12268
integer(c_int), value :: direction
12369
type(PJ_COORD), value :: coord
12470
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
12581
end interface
12682

12783
contains
@@ -159,44 +115,25 @@ end subroutine proj_set_dst_crs
159115
subroutine proj_transform(this, xi, yi, xo, yo)
160116

161117
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
166122

167123
type(PJ_COORD) pj_xi, pj_xo
168124

169125
if (.not. c_associated(this%pj)) then
170126
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
171131
end if
172132

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)
186134
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)
200137

201138
end subroutine proj_transform
202139

@@ -209,4 +146,13 @@ subroutine proj_final(this)
209146

210147
end subroutine proj_final
211148

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+
212158
end module proj_mod

src/proj_test.F90

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ program proj_test
2121
call p%init(src_crs, dst_crs)
2222
lon = 105.5837
2323
lat = 36.14387
24-
print *, x, y
2524
call p%transform(lon, lat, x, y)
26-
print *, x, y
25+
call assert_equal(x, 0.0d0, __FILE__, __LINE__)
26+
call assert_equal(y, 0.0d0, __FILE__, __LINE__)
2727

2828
call test_suite_report(test_suite)
2929

0 commit comments

Comments
 (0)