- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I get error#6360 when I attempted to move this code from IVF10* to the eval edition of IVF11*
defined in a structure as so:
character (kind=1),dimension(1:256) :: jobname
write(6,*) ' Jobname = ',trim(adjustl(this%jobname))
Link Copied
7 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
And that's what should be expected.
vname is an array whose elements are strings of length = 1, and the function trim takes a scalar argument. Depending on what you want to do, declare vname to be a string of length 4, or apply trim and adjustl to an element of vname rather than to the array.
vname is an array whose elements are strings of length = 1, and the function trim takes a scalar argument. Depending on what you want to do, declare vname to be a string of length 4, or apply trim and adjustl to an element of vname rather than to the array.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm in a catch22. I'm calling a fortran routine from C.
If it is defined as so:
subroutine fortranRoutine(charvar) bind(C,name='fortranRoutine')
character(len=256) ,intent(in)::charvar
results in error #8532, character dummy argument with length other than 1 is not interoperable
However if I declare
character(len=1),intent(in)::charvar(1:256)
I'm not able to use charvar with trim(adjustl(charvar)) without producing the #6360 error.
I need something similar to the C "cast" to redefine the shape of charvar I think.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There are a couple of different ways to deal with it. TRANSFER is one, a combination of C_LOC and C_F_POINTER is another.
You're right that this is a hole in the C interoperability feature. While you can pass a CHARACTER(n) variable out to C with an interface declared as an array of CHARACTER(1), there's no corresponding way to "receive" such a thing.
You're right that this is a hole in the C interoperability feature. While you can pass a CHARACTER(n) variable out to C with an interface declared as an array of CHARACTER(1), there's no corresponding way to "receive" such a thing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ok, this compiles.
subroutine fortranRoutine(charvar) bind(C,name=fortranRoutine)
character(len=1),intent(in)::charver(1:256)
character(len=256)::scalar256,x
x=transfer(charvar,scalar256)
any other gotcha's? Is there a cleaner way?
subroutine fortranRoutine(charvar) bind(C,name=fortranRoutine)
character(len=1),intent(in)::charver(1:256)
character(len=256)::scalar256,x
x=transfer(charvar,scalar256)
any other gotcha's? Is there a cleaner way?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You could do away with scalar256 and write:
x = transfer(charvar,x)
This is the "cleanest" way I can think of.
x = transfer(charvar,x)
This is the "cleanest" way I can think of.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
[bash]module interop_test contains subroutine fortranRoutine(charvar) bind(C,name='fortranRoutine') use ISO_C_BINDING implicit none character(kind=C_CHAR),target :: charvar(256) character(kind=C_CHAR),pointer :: charvarString*(256) type(C_PTR) charvarAddress charvarAddress = C_LOC(charvar) call C_F_POINTER(charvarAddress,charvarString) write(*,'(a)') trim(charvarString) end subroutine fortranRoutine end module interop_test program interop_string use interop_test implicit none call fortranRoutine([character(256) :: 'Hello, world']) end program interop_string [/bash]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks! Learned a lot.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page