Silverfrost Forums

Welcome to our forums

daft question!

25 Jun 2013 3:21 #12488

For reasons too complex to go into, I want my own version of FCORE4. I've tried:

!ftn95$free
program coretest

  real*4        :: a(2)

  iad =  loc(a(1))
  a(1)  = 3.5
  a(2)  = 4.7
  call test (iad,2)
end 

subroutine test (iad, n)
  intrinsic fcore4

  call report1 (fkore4(iad), n)  
  call report1 (fcore4(iad), n)
  
end

subroutine report1 (a, n)
  real*4  :: a(n)
  write (*,*) 'a(1,2)', a(1),a(2)
  
end    
  
real*4 function fkore4 (iad)
  intrinsic fcore4

  fkore4  = fcore4(iad)
 
end

In the calls to 'report1', FCORE4 returns access to the entire array, but my FKORE4 only succeeds in returning the first element of the array. Is what I want to do possible?

K[/code]

26 Jun 2013 12:16 #12490

I think that in your call: call report1 (fkore4(iad), n)
The real*4 value of fkore4(iad) is being evaluated and the address of this value is being provided in the argument list.

While for : call report1 (fcore4(iad), n) FTN95 is effectively placing the address (=iad) on the stack for the argument list addresses for the call. I would expect that any of the *COREx 'intrinsics' could be used in this call.

FTN95 recognises FCORE4 and gives it special treatment, similar to how it handles: FCORE4(iad) = 3.5 You must use the form of *COREx that is compatible with the format of the bytes you wish to update. I do not know how to do this in a standard conforming way.

FTN95 recognises FCORE4 and treats it in a non-standard way, and not a general function, which is what your FKORE4 is. See 'Other machine-level facilities'

It is my understanding that all arguments of a fortran subroutine are called by reference, while FCORE4 is called by value, which allows the values from LOC to be used. STDCALL is FTN95's non-standard approach to enabling this, via VAL and REF. I presume the functionality of STDCALL has been enabled in F2003 and F2008, although I have not used it.

John

26 Jun 2013 5:27 #12491

This sounds about right apart from the last bit about STDCALL. For FTN95, STDCALL is not about VAL and REF but relates to who (the caller or the one called) has the responsibility to clean up the stack.

26 Jun 2013 5:43 #12492

ok, just thought i'd ask!

thanks

K

26 Jun 2013 6:12 #12494

Paul,

Have I mixed the function of C_EXTERNAL with STDCALL ?

Both have very simmilar syntax.

C_EXTERNAL UNIX_WRITE 'write' (VAL, REF, VAL): INTEGER4 STDCALL ESCAPE 'Escape' (VAL, VAL, VAL, REF, REF):INTEGER4

Is my understanding of the use of VAL and REF correct ? I can not see any other way to define their use. I can not see how the stack clean-up is differentiated in these definitions. I would appreciate some more explaination of how this is defined and when I should use these alternatives.

John

Please login to reply.