replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - Passing .NET arrays to FTN95 functions
forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Passing .NET arrays to FTN95 functions

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
Emanuele



Joined: 21 Oct 2009
Posts: 78
Location: Bologna (Italy)

PostPosted: Tue Mar 30, 2010 4:23 pm    Post subject: Passing .NET arrays to FTN95 functions Reply with quote

To expand the discussion around the topic by Developer1 ( http://forums.silverfrost.com/viewtopic.php?t=1618 ), please consider the following examples.
I wrote a VB main program which populate an array 'e' and pass it to a FTN95 subroutine with a vector 'd'.

Code:
 Sub Main()
        Dim d(9), e(9, 9) As Single

        For j = 0 To 9
            For i = 0 To 9
                e(i, j) = CSng(i * j)
            Next
            d(j) = 0
        Next

        FortranFunctions.Add(e, d)
End Sub


The FTN95 subroutine take s the array 'E' and assign to vector 'D' elements the second column elements of matrix 'E' plus 2.

Code:
 SUBROUTINE DIRECTCALL_ADD(E,D)
    ASSEMBLY_INTERFACE(NAME="Add")
   
    REAL, intent(in):: E(:,:)
    REAL, intent(out):: D(:)
       
    do i = 1, ubound(E,1)
        D(i) = E(i,2) + 2.0
    end do
END


This works fine!
Now I tried to use a function instead of a subroutine to make the same thing.
The modified VB code,

Code:
 Sub Main()
        Dim d(9), e(9, 9) As Single

        For j = 0 To 9
            For i = 0 To 9
                e(i, j) = CSng(i * j)
            Next
            d(j) = 0
        Next

        d = FortranFunctions.Add(e)
End Sub


and the FTN,

Code:
 REAL FUNCTION DIRECTCALL_ADD(E) RESULT(D)
    ASSEMBLY_INTERFACE(NAME="Add")
   
    REAL, intent(in):: E(:,:)
    REAL:: D(ubound(E,1))
       
    do i = 1, ubound(E,1)
        D(i) = E(i,2) + 2.0
    end do
END


In this case I got an unhandled exception: the message told 'System.ExecutionEngineException', without any other details.
I'm using VS 2008 with FTN95 5.50 (Academic).

Can someone explain this behaviour? Thank you in advance for any suggestion.


Last edited by Emanuele on Wed Mar 31, 2010 1:10 pm; edited 1 time in total
Back to top
View user's profile Send private message
Emanuele



Joined: 21 Oct 2009
Posts: 78
Location: Bologna (Italy)

PostPosted: Wed Mar 31, 2010 1:08 pm    Post subject: Reply with quote

I corrected some copy and paste errors in the second code box! Sorry.
Back to top
View user's profile Send private message
JohnCampbell



Joined: 16 Feb 2006
Posts: 2615
Location: Sydney

PostPosted: Thu Apr 08, 2010 9:26 am    Post subject: Reply with quote

Why be so cute with the array dimensions. You could easily include the dimensions as arguments to the function, although increasing the argument list.
Even in ftn95, you often need to include an interface definition, which can play havock with /check and probably interfacing with VB or C++.

Make the calling interface more transparent and I'm sure a lot of the problems would disappear.

John
Code:
 Sub Main()
        Dim d(9), e(9, 9) As Single

        For j = 0 To 9
            For i = 0 To 9
                e(i, j) = CSng(i * j)
            Next
            d(j) = 0
        Next

        FortranFunctions.Add(e, d, 9)
End Sub

 SUBROUTINE DIRECTCALL_ADD(E,D,n)
    ASSEMBLY_INTERFACE(NAME="Add")
   
    integer n
    REAL E(n,n)
    REAL D(n)
       
    do i = 1, n
        D(i) = E(i,2) + 2.0
    end do
END
Back to top
View user's profile Send private message
Emanuele



Joined: 21 Oct 2009
Posts: 78
Location: Bologna (Italy)

PostPosted: Fri Apr 09, 2010 9:35 am    Post subject: Reply with quote

Dear John,
Thank you for the reply. There was no troubles using the subroutine statement, but the problem arose with function statement. Furthermore, by adopting your code I got compiler errors like, "Array E is not of assumed shape, and so cannot appear as an argument to a routine containing an ASSEMBLY_INTERFACE".

Consider that my job often consists in assembling old pieces of code (not written by me, of course)!

Finally what did you mean exactly, when writing
Quote:
Make the calling interface more transparent
?

Thanks for patience!
Back to top
View user's profile Send private message
JohnCampbell



Joined: 16 Feb 2006
Posts: 2615
Location: Sydney

PostPosted: Mon Apr 12, 2010 12:00 am    Post subject: Reply with quote

Emanuele,

My suggestion was to simplify the function interface by providing the dimensions explicitly, rather than implicitly, as different languages can handle the implicit dimension transfers in different ways. The management of simplified argument lists then removes a lot of uncertainty that can occur, both with different compilers and compiler options. My suggestion was of the form :-
Code:
 SUBROUTINE ADD (E, D, n)
   
    REAL, intent(in):: E(n,n)
    REAL:: D(n)
       
    do i = 1, n
        D(i) = E(i,2) + 2.0
    end do

END

This simplified argument list removes any problems with the order of arguments, such as the use of implicit dimensions and the return array result.
In your original example, how were you expecting fortran to return the function result "D", which is an array ?
Why ask for trouble then complain ?

John
Back to top
View user's profile Send private message
Emanuele



Joined: 21 Oct 2009
Posts: 78
Location: Bologna (Italy)

PostPosted: Mon Apr 12, 2010 6:54 pm    Post subject: Reply with quote

Dear John,
Thanks for patience.
Quote:
This simplified argument list removes any problems with the order of arguments, such as the use of implicit dimensions and the return array result.

The code you wrote doesn't work; compiler returns the following error, "Array E is not of assumed shape, and so cannot appear as an argument to a routine containing an ASSEMBLY_INTERFACE", the same for D.
Quote:
In your original example, how were you expecting fortran to return the function result "D", which is an array ?

In case of one-dimensional arrays it works fine.
Quote:
Why ask for trouble then complain ?

That's the cruel fate of people who works on others' code trying to assamble a program... and lacking of experience, of course!!
Back to top
View user's profile Send private message
JohnCampbell



Joined: 16 Feb 2006
Posts: 2615
Location: Sydney

PostPosted: Tue Apr 13, 2010 12:50 am    Post subject: Reply with quote

Emanuele,

The last example I gave did compile for me. Your again reporting the previous error
Quote:
"Array E is not of assumed shape, and so cannot appear as an argument to a routine containing an ASSEMBLY_INTERFACE"
I think misses the point I am trying to make, that you should avoid the need for an INTERFACE definition.
My understanding is that INTERFACE definitions define additional information related to the argument list. I am not sure that this extended argument list is handled in the same way between FTN95, C and VB, and is certainly risking trouble if you add SDBG and /check into the mix.
Do you have access to the VB code ? My recommendation is, if your intention is to get the program to work, rather than describe a possible interface error with implicit array functions, then keep it simple and remove any ambiguity. I am a strong proponent of KISS.

John
Back to top
View user's profile Send private message
Developer1



Joined: 18 Mar 2010
Posts: 4

PostPosted: Thu Apr 15, 2010 11:02 am    Post subject: Reply with quote

Hi,

I tried to add an integer to the passing arguments. However, this does not change the problem that the second (or better the last) array passed as an argument is recognised as "invalid".
Also passing the integer in second position i.e. arrayA, integer, arrayB leaves arrayB "invalid".

Cheers,
Alex
Back to top
View user's profile Send private message
MABROUKI



Joined: 10 Mar 2008
Posts: 2

PostPosted: Thu Aug 05, 2010 3:58 pm    Post subject: ARRAY-VALUED FUNCTION.SEE COMPAQ FORTRAN 6.6 FUNCTION HELP Reply with quote

PLEASE MODIFIE YOUR FUNCTION DECLARATION LIKE THIS:

FUNCTION DIRECTCALL_ADD(E,D,N)
ASSEMBLY_INTERFACE(NAME="Add")
INTEGER :: N,I
REAL :: E(:,Smile
REAL :: D(Smile
REAL :: DIRECTCALL_ADD(SIZE(D))

DO I = 1, N
D(I) = E(I,2) + 2.0
DIRECTCALL_ADD(I)=D(I)
END DO
END FUNCTION DIRECTCALL_ADD

EXCUSE MY ENGLISH.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group