Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs have moved to the Altera Community. Existing Intel Community members can sign in with their current credentials.
29323 Discussions

Passing Argumets from C to Fortran ( urgent..!!)

rampy
Beginner
542 Views
Hi I have a pass arguments between Fortran and C . I am able to pass
arguments and characters from Fortran to C . But passing the arguments
after manipulating it in C , I am not able to pass it back to Fortran.
Here is my code

template.f90


PROGRAM PHREEQC_TEMPLATE

CHARACTER (LEN=10)::NAME1,NAME2,NAME3
REAL NO,PH,DUMMY, sum

WRITE(*,*)'Input Name1'
READ(*,*)NAME1
WRITE(*,*)'Input Name2'
READ(*,*)NAME2
WRITE(*,*)'Input Name3'
READ(*,*)NAME3
WRITE(*,*)'Input pH value'
READ(*,*)PH
WRITE(*,*)'Write Solution Number'
READ(*,*)NO



!DEC$ ATTRIBUTES ALIAS:"_get" :: GET
!DEC$ ATTRIBUTES ALIAS:"_conc" :: CONC

CALL GET(NAME1,NAME2,NAME3)
CALL CONC(NO,PH)
READ(*,*)DUMMY
END PROGRAM PHREEQC_TEMPLATE


C Code

#include
#include
#include
#include

void get(char fname1[],char fname2[],char fname3[])
{
char solution_name;
char pH;
printf("The char variables from Fortran to C is: ");
printf("%s ",fname1);
printf("%s ",fname2);
printf("%s ",fname3);
}

void conc(float* no, float* ph)
{
float num1= *no;
float num2= *ph;
float sum = 0;
sum = num1 + num2;
printf("%f ",num1);
printf("%f ",num2);
printf("%f ",sum);
}

I want to pass Sum back to Fortran. How can I do it. I am using Intel Fortran Compiler and Microsoft Visual Basic C

Rampy
0 Kudos
1 Reply
Jugoslav_Dujic
Valued Contributor II
542 Views
Erm, isn't it obvious that you can do it in the same way as you passed the inputs. Either:

float conc(...
...
return sum;}

or

void conc(float* no, float* ph, float* sum)
{*sum = *no + *ph}

would do.

By the way, you should (at least) char(0)-terminate the string arguments to GET. Fortran does not terminate strings with �, so you can easily get garbage appended at printf().
0 Kudos
Reply