- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi everyone,
just a little question about how fortran deal with char *:
I am trying to call a subroutine in fortran which will become as parameter a char * from c, as follows. The point is that fortran is not receiving the characters,and i have no idea why. If anyone could help me, it would be great.Thanks:
SUBROUTINE SETMOL(MOL)
!MS$ATTRIBUTES DLLEXPORT,STDCALL,ALIAS:'_Setmol@4'::SETMOL
CHARACTER(20) MOL
WRITE(*,*) "New configuration", MOL
END SUBROUTINE
!MS$ATTRIBUTES DLLEXPORT,STDCALL,ALIAS:'_Setmol@4'::SETMOL
CHARACTER(20) MOL
WRITE(*,*) "New configuration", MOL
END SUBROUTINE
JNIEXPORT
void JNICALL Java_Main_set_1molecule(JNIEnv *env, jobject jobj, jstring prompt){
int size = 20;//DEFINE A CONSTANT WITH THE VALUE OF THE MINIMUM LENGTH OF THE STRING const char * buf ;printf("Calling the c function ");
buf = (
char *)calloc(size,sizeof (char));buf = env->GetStringUTFChars(prompt,NULL);
printf("String c1: %s ", buf);
printf(" Calling fortran ");
Setmolecule(buf);
printf("Release the jstring: %s ", buf);
env->ReleaseStringUTFChars(prompt, buf);
printf("Ending C ");
}
Calling the c function
String c1: CO
Calling fortran
String c1: CO
Calling fortran
New configuration h
MOLE COMMAND
comando: MOLE
parametro: hj? l, p&p&
MOLE COMMAND
comando: MOLE
parametro: hj? l, p&p&
NOTE:
About the console emulation dealed with in the last post call "Calling a dll made with Fortran by C" i am keeping working on it, i`ve almost got the solution, now i am trying to force the c library to flush the stdout and redirect the output, instead of a file a textarea (it is what i got redirecting the output of the java VM). As soon as i finished i will post there the solution i reached. it could help anyone who will ahve to face with the same problem like me.
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Apart from the apparent naming difference (typo?) :
Fortran routine name SETMOL;
Calling routine calls Setmolecule
have you tried calling Setmolecule(&buf) ?
Les
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
or should that be Setmolecule(*buf) ?
(Sorry my mixed languageknowledge is limited, and Java knowledge = nil)
Les

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page