Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Rémy Mozul
FortHon
Commits
aac09fda
Commit
aac09fda
authored
Jul 22, 2014
by
Mozul Rémy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
correction in string assignment
parent
68da62ce
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
6 deletions
+25
-6
fortran_shared_db/dtype.pyx
fortran_shared_db/dtype.pyx
+13
-1
fortran_shared_db/mod_dtype.f90
fortran_shared_db/mod_dtype.f90
+5
-4
fortran_shared_db/test.py
fortran_shared_db/test.py
+7
-1
No files found.
fortran_shared_db/dtype.pyx
View file @
aac09fda
...
...
@@ -4,6 +4,7 @@ import numpy as np
import
cython
as
ct
from
libc.string
cimport
strcpy
from
dtype
cimport
C_param
,
C_datatype
,
getOne
,
display
,
change
np
.
import_array
()
...
...
@@ -23,10 +24,21 @@ cdef class P_datatype(object):
self
.
rtab
=
np
.
PyArray_SimpleNewFromData
(
1
,
[
self
.
f_image
.
itab
[
0
]],
np
.
NPY_DOUBLE
,
self
.
f_image
.
rtab
)
self
.
f_image_ptr
=
addOne
(
nn
,
rv
,
iv
)
# beurk
self
.
f_image
.
nickname
[
30
]
=
'
\0
'
for
i
in
range
(
self
.
f_image
.
itab
[
1
]):
self
.
f_image
.
weird
[
i
].
field
[
30
]
=
'
\0
'
self
.
f_image_ptr
.
nickname
[
30
]
=
'
\0
'
for
i
in
range
(
self
.
f_image_ptr
.
itab
[
1
]):
self
.
f_image_ptr
.
weird
[
i
].
field
[
30
]
=
'
\0
'
def
cythonChange
(
self
,
nn
,
rv
,
iv
):
#&self.f_image.nickname[0] = nn
#this is not possible because char[30] is a non-lvalue
#self.f_image.nickname = nn
strcpy
(
self
.
f_image
.
nickname
,
nn
)
self
.
f_image
.
rsingle
=
rv
self
.
f_image
.
isingle
=
iv
strcpy
(
self
.
f_image_ptr
.
nickname
,
nn
)
self
.
f_image_ptr
.
rsingle
=
rv
self
.
f_image_ptr
.
isingle
=
iv
...
...
fortran_shared_db/mod_dtype.f90
View file @
aac09fda
...
...
@@ -220,12 +220,12 @@ contains
type
(
c_ptr
),
value
::
nn
!
character
(
kind
=
c_char
,
len
=
30
),
pointer
::
nname
integer
(
kind
=
4
)
::
i
integer
(
kind
=
4
)
::
i
,
j
type
(
T_dt_link
)
,
pointer
::
dl
call
c_f_pointer
(
cptr
=
nn
,
fptr
=
nname
)
i
=
0
do
while
(
i
<
30
.and.
nname
(
i
+1
:
i
+1
)
/
=
c_null_char
)
i
=
1
do
while
(
i
<
30
.and.
nname
(
i
:
i
)
/
=
c_null_char
)
i
=
i
+
1
end
do
mydatas
(
id
)
%
nickname
(
1
:
i
)
=
nname
(
1
:
i
)
...
...
@@ -235,7 +235,7 @@ contains
mydatas
(
id
)
%
isingle
=
iv
dl
=>
Root
do
i
=
1
,
id
-1
do
j
=
1
,
id
-1
if
(
associated
(
dl
%
n
)
)
then
dl
=>
dl
%
n
else
...
...
@@ -243,6 +243,7 @@ contains
return
end
if
end
do
dl
%
d
%
nickname
(
1
:
i
)
=
nname
(
1
:
i
)
dl
%
d
%
nickname
(
i
+1
:)
=
''
...
...
fortran_shared_db/test.py
View file @
aac09fda
import
dtype
dat
=
dtype
.
P_datatype
(
1
,
'new from p'
,
12.
,
5
)
dat
=
dtype
.
P_datatype
(
1
,
'new from p'
,
1.
,
1
)
#dat.fortranChange('fortran change', 13.,6)
#dat.fortranContent()
#dat.cythonContent()
dat
.
cythonChange
(
'cython change'
,
144.
,
12
)
#dat.fortranContent()
dat
.
cythonContent
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment