mixing fortran and c
Martin Dunschen
duns1222 at w203zrz.zrz.tu-berlin.de
Sat Feb 16 02:53:48 AEST 1991
Hi all you high experienced C/FORTRAN programmers !
We have a problem which is probably solved by some of you.
We try to combine Fortran and C. All these things in Fortran,
like COMMON Blocks, alternate returns, call by reference vs. call by value
are no problems to us anymore.
But the last remaining thing is:
HOW TO PASS STRINGS ?
It seems, that the Fortran subroutine does not know, how long
are the given strings. Below are a few programs for testing purpose, two
C-procedures and a fortran subroutine.
The solution is perhaps something like giving the length of the strings in a way
to the subroutine, or adding a special character, which tells the subroutine
where the string stops.
Thanks in advance, Martin.
+---------------------------------------------------------------------------+
| e-mail : dunschen at zrzsp9.fb12.tu-berlin.de |
| |
| Martin Dunschen |
| Institute of Naval Architecture |
| Salzufer 17-19 |
| D-1000 Berlin 10 |
| Germany |
| |
+---------------------------------------------------------------------------+
CUT HERE --- CUT HERE --- CUT HERE --- CUT HERE --- CUT HERE --- CUT HERE ---
#include <string.h>
/* main program for testing the passing of strings from c to fortran */
main ()
{
strtst ("TESTING","CASE");
}
/* procedure, called by main, parameters are the strings */
strtst (str1, str2)
char* str1;
char* str2;
{
char *stest1, *stest2;
printf ("str1= %s\n str2= %s\n", str1, str2);
printf ("length str1 %d\n", strlen( str1));
printf ("length str2 %d\n", strlen( str2));
getchar ();
/* Try to add a sign to the strings, so that FORTRAN knows where to stop */
strcat (str1, "\n");
strcat (str2, "\n");
printf ("str1= %s ", str1);
printf ("str2= %s ", str2);
getchar ();
/* call the fortran subroutine, passing pointers to strings */
strf_ (str1, str2);
}
c------ CUT HERE ------
subroutine strf (str1, str2)
character *(*) str1, str2
print*, 'strf : ', str1, len(str1)
print*, 'strf : ', str2, len(str2)
end
More information about the Comp.lang.c
mailing list