
SIMPLY FORTRAN FREEZING CODE
The first thing I did earlier in the week is commenting out DLLEXPORT and compile in Linux, but the code will not work. Now I puzzled how the codes (they are legacy codes and don't use bind and VALUE) could work in Mac, P.S.> Are you at Penn State? Go Nittany Lions! Printf("errMsg after function call: %s\n", errMsg) ĮrrMsg before calling Fortran function addsize: There!īy the way, you have mixed-mode arithmetic in your Fortran code computing answer that adds an integer with two floating point variables and then casts back to an integer - is this really what you intended? This can cause unexpected behavior unless one is very careful. Result = addsize(maxn, delta, conf, (long)ERR_MSG_LENGTH, errMsg) Printf("errMsg before calling Fortran function addsize: %s\n", errMsg) Strncpy(errMsg, "There!", (size_t)ERR_MSG_LENGTH) LenMsg = min( msgLen-1, len_trim(errmsg) )Īnswer = int( maxn + delta + conf ) ! the sample sizeĮxtern long addsize(long maxn, double delta, double conf, long msgLen, char *Msg) Integer(c_long), value, intent(in) :: msgLenĬharacter(kind=c_char,len=1), intent(inout) :: Msg(msgLen)Ĭharacter(kind=c_char,len=:), allocatable :: errmsg Real(c_double), value, intent(in) :: conf Real(c_double), value, intent(in) :: delta Integer(c_long), value, intent(in) :: maxn Use, intrinsic :: iso_c_binding, only : c_char, c_null_char, c_long, c_doubleįunction addsize( maxn, delta, conf, msgLen, Msg ) result( answer ) bind(c, name='addsize') This might help you figure out what is going on. Can you take this as-is and build execute on your system without any code changes and see what output you get? Post here if your output is different. It works on my system and gives the output shown below. So why don't we try something different? Listed below is a somewhat simplified version of code for what you are trying to do that tries to use standard Fortran and C. Must something wrong in the interface between c and Steve said, it would appear the code you have posted should work, however it is spread across several messages and it's unclear if there are any differences between what you show here and in your actual system which could be causing the problem. Well, when I comment out call to Fortran, c code works fine and c code is so simple. Somehow I couldn't get it to work, is anything wrong in the code? Thanks! Real (C_DOUBLE), intent(in) :: delta, conf Subroutine addsize( maxn, delta, conf, sum ) bind(c, name='addsize')

Long add(long maxn, double delta, double conf, char *errMsg)įor (i=0 ((char) iarr ) != '\0' ++i) errMsg = (char) iarr īut when I tried to call Fortran add function from C, I have trouble:Įxtern addsize(long maxn, double delta, double conf, long * sum)

so file from C and call it from Ruby On Rails,
SIMPLY FORTRAN FREEZING HOW TO
I am trying to learn how to call Fortran from C, I am able to create.
