Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
公告
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29285 讨论

error #6360: A scalar-valued argument is required in this context [TRIM]

rre9518
初学者
6,506 次查看
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))

0 项奖励
7 回复数
mecej4
名誉分销商 III
6,506 次查看
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.
0 项奖励
rre9518
初学者
6,506 次查看

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.
0 项奖励
Steven_L_Intel1
6,506 次查看
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.
0 项奖励
rre9518
初学者
6,506 次查看
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?

0 项奖励
Steven_L_Intel1
6,506 次查看
You could do away with scalar256 and write:

x = transfer(charvar,x)

This is the "cleanest" way I can think of.
0 项奖励
JVanB
重要分销商 II
6,506 次查看
[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]
0 项奖励
rre9518
初学者
6,506 次查看
Thanks! Learned a lot.
0 项奖励
回复