Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28592 Discussions

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

rre9518
Beginner
4,699 Views
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 Kudos
7 Replies
mecej4
Honored Contributor III
4,699 Views
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 Kudos
rre9518
Beginner
4,699 Views

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 Kudos
Steven_L_Intel1
Employee
4,699 Views
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 Kudos
rre9518
Beginner
4,699 Views
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 Kudos
Steven_L_Intel1
Employee
4,699 Views
You could do away with scalar256 and write:

x = transfer(charvar,x)

This is the "cleanest" way I can think of.
0 Kudos
JVanB
Valued Contributor II
4,699 Views
[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 Kudos
rre9518
Beginner
4,699 Views
Thanks! Learned a lot.
0 Kudos
Reply