-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathop_cascade.f90
341 lines (262 loc) · 7.8 KB
/
op_cascade.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
module op_cascade
implicit none
private
interface
subroutine init_STEP_intf(fname) &
bind( C, name = "init_STEP")
use iso_c_binding, only : c_char
import
implicit none
character (c_char), intent(in) :: fname(*)
end subroutine init_STEP_intf
end interface
interface
subroutine init_IGES_intf(fname) &
bind( C, name = "init_IGES")
use iso_c_binding, only : c_char
import
implicit none
character (c_char), intent(in) :: fname(*)
end subroutine init_IGES_intf
end interface
interface
subroutine clean_statics_intf() &
bind( C, name = "clean_statics")
implicit none
end subroutine clean_statics_intf
end interface
interface
subroutine find_pts_on_database_intf(npts, pts, found, uv, tol) &
bind( C, name = "find_pts_on_database")
use iso_c_binding, only : c_int, c_double
import
implicit none
integer(c_int), value :: npts
real(c_double) :: pts(3 * npts)
integer(c_int) :: found(npts)
real(c_double) :: uv(2*npts)
real(c_double), value :: tol
end subroutine find_pts_on_database_intf
end interface
interface
subroutine uv2xyz_intf(CAD_face, uv, xyz) &
bind( C, name = "uv2xyz")
use iso_c_binding, only : c_int, c_double
import
implicit none
integer(c_int), value :: CAD_face
real(c_double) :: uv(2)
real(c_double) :: xyz(3)
end subroutine uv2xyz_intf
end interface
interface
subroutine xyz2uv_intf(CAD_face, xyz, uv, tol) &
bind( C, name = "xyz2uv")
use iso_c_binding, only : c_int, c_double
import
implicit none
integer(c_int), value :: CAD_face
real(c_double) :: xyz(3)
real(c_double) :: uv(2)
real(c_double), value :: tol
end subroutine xyz2uv_intf
end interface
interface
subroutine xyz2close_xyz_intf(CAD_face, xyz, close_xyz, tol) &
bind( C, name = "xyz2close_xyz")
use iso_c_binding, only : c_int, c_double
import
implicit none
integer(c_int), value :: CAD_face
real(c_double) :: xyz(3), close_xyz(3)
real(c_double), value :: tol
end subroutine xyz2close_xyz_intf
end interface
! Readers
public :: init_STEP_f90, init_IGES_f90
! Queries
public :: find_pts_on_database_f90, uv2xyz_f90, xyz2uv_f90, xyz2close_xyz_f90
! Cleanups
public :: clean_statics_f90
contains
subroutine init_STEP_f90(fname)
use iso_c_binding, only : c_char, c_null_char
implicit none
character(len = *), intent(in) :: fname
!local vars
character (kind = c_char, len = 255) :: fname_in
fname_in = trim(fname)//C_NULL_CHAR
! call C-func
call init_STEP_intf(fname_in)
! done here
end subroutine init_STEP_f90
subroutine init_IGES_f90(fname)
use iso_c_binding, only : c_char, c_null_char
implicit none
character(len = *), intent(in) :: fname
!local vars
character (kind = c_char, len = 255) :: fname_in
fname_in = trim(fname)//C_NULL_CHAR
! call C-func
call init_IGES_intf(fname_in)
! done here
end subroutine init_IGES_f90
subroutine clean_statics_f90()
implicit none
! call C-func
call clean_statics_intf()
! done here
end subroutine clean_statics_f90
subroutine find_pts_on_database_f90(npts, pts, found, uv, tol)
use iso_c_binding, only : c_int, c_double
implicit none
integer, intent(in) :: npts
real*8, dimension(:), intent(in) :: pts
integer, dimension(:), intent(out) :: found
real*8, dimension(:), intent(out) :: uv
real*8, intent(in) :: tol
!local vars
integer :: i
integer(c_int) :: npts_in
real(c_double) :: tol_in
real(c_double), allocatable :: pts_in(:)
integer(c_int), allocatable :: found_out(:)
real(c_double), allocatable :: uv_out(:)
! init
npts_in = npts
tol_in = tol
allocate(pts_in(size(pts)))
do i = 1, size(pts)
pts_in(i) = pts(i)
end do
allocate(found_out(size(found)))
found_out = 0
allocate(uv_out(size(uv)))
uv_out = 0.0d0
! call C-func
call find_pts_on_database_intf(npts_in, pts_in, found_out, uv_out, tol_in)
! fillout the return arrays and values
do i = 1, size(found)
found(i) = found_out(i)
end do
do i = 1, size(uv)
uv(i) = uv_out(i)
end do
! clean ups
if ( allocated(pts_in) ) deallocate(pts_in)
if ( allocated(found_out) ) deallocate(found_out)
if ( allocated(uv_out) ) deallocate(uv_out)
! done here
end subroutine find_pts_on_database_f90
subroutine uv2xyz_f90(CAD_face, uv, xyz)
use iso_c_binding, only : c_int, c_double
implicit none
integer, intent(in) :: CAD_face
real*8, dimension(:), intent(in) :: uv
real*8, dimension(:), intent(out) :: xyz
!local vars
integer :: i
integer(c_int) :: CAD_face_in
real(c_double) :: uv_in(2)
real(c_double) :: xyz_out(3)
! init
CAD_face_in = CAD_face
do i = 1, 2
uv_in(i) = uv(i)
end do
! call C-func
call uv2xyz_intf(CAD_face_in, uv_in, xyz_out)
! fillout the return arrays and values
do i = 1, 3
xyz(i) = xyz_out(i)
end do
! done here
end subroutine uv2xyz_f90
subroutine xyz2uv_f90(CAD_face, xyz, uv, tol)
use iso_c_binding, only : c_int, c_double
implicit none
integer, intent(in) :: CAD_face
real*8, dimension(:), intent(in) :: xyz
real*8, dimension(:), intent(out) :: uv
real*8, intent(in) :: tol
!local vars
integer :: i
integer(c_int) :: CAD_face_in
real(c_double) :: xyz_in(3)
real(c_double) :: uv_out(2)
real(c_double) :: tol_in
! init
CAD_face_in = CAD_face
do i = 1, 3
xyz_in(i) = xyz(i)
end do
tol_in = tol
! call C-func
call xyz2uv_intf(CAD_face_in, xyz_in, uv_out, tol_in)
! fillout the return arrays and values
do i = 1, 2
uv(i) = uv_out(i)
end do
! done here
end subroutine xyz2uv_f90
subroutine xyz2close_xyz_f90(CAD_face, xyz, close_xyz, tol)
use iso_c_binding, only : c_int, c_double
implicit none
integer, intent(in) :: CAD_face
real*8, dimension(:), intent(in) :: xyz
real*8, dimension(:), intent(out) :: close_xyz
real*8, intent(in) :: tol
!local vars
integer :: i
integer(c_int) :: CAD_face_in
real(c_double) :: xyz_in(3)
real(c_double) :: close_xyz_out(3)
real(c_double) :: tol_in
! init
CAD_face_in = CAD_face
do i = 1, 3
xyz_in(i) = xyz(i)
end do
tol_in = tol
! call C-func
call xyz2close_xyz_intf(CAD_face_in, xyz_in, close_xyz_out, tol_in)
! fillout the return arrays and values
do i = 1, 3
close_xyz(i) = close_xyz_out(i)
end do
! done here
end subroutine xyz2close_xyz_f90
end module op_cascade
! program tester
! use op_cascade
! implicit none
! ! local vars
! character(len = 255) :: fname_step = './crude_samples/store.step'
! character(len = 255) :: fname_iges = './crude_samples/store.iges'
! ! chose a point in 3D space for query
! integer :: npts
! real*8 :: pts(3)
! integer :: found(1)
! real*8 :: uv(2)
! real*8 :: tol
! npts = 1
! pts = (/0.373333d0, 0.433333d0, 0.118d0 /)
! found = 0
! uv = 0.0d0
! tol = 1.0d-1
! ! read STEP file and init.
! call init_STEP_f90(fname_step)
! ! do a query
! call find_pts_on_database_f90(npts, pts, found, uv, tol)
! ! show result
! print *, ' =========== in STEP file: =========== '
! print *, 'found(1) = ', found(1)
! print *, '(u, v) = (', uv(1), ', ', uv(2), ') '
! ! Now, test snapping function uv2xyz
! pts = (/ 0.0d0, 0.0d0, 0.0d0 /)
! call uv2xyz_f90(found(1), uv, pts)
! print *, 'snapped point = ', pts
! ! final cleanups
! call clean_statics_f90()
! ! done here
! end program tester