- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
---------------------------- C call ----------------------------
extern "C" void __stdcall Setmolbyname(char *, int);
---------------------------- C call ----------------------------
---------------------------- Cfunc ----------------------------
JNIEXPORT void JNICALL Java_Main_set_1molecule_1name(JNIEnv *env, jobject jobj, jstring prompt)
{
int size = 20;//TEST ONLY --> DEFINE A CONSTANT WITH THE VALUE OF THE MINIMUM LENGTH OF THE STRING
char * buf ;
printf("Calling the c function ");
buf = (char *)calloc(size,sizeof (char));
buf = (char *)env->GetStringUTFChars(prompt,NULL);
printf("String c1: %s ", buf);
printf(" Calling fortran with the chain %s ", buf);
fflush(stdout);
Setmolbyname(buf, size);
//printf("Release the jstring: %s ", buf);
env->ReleaseStringUTFChars(prompt, buf);
//printf("Ending C ");
}
---------------------------- endCfunc ----------------------------
---------------------------- fortran func ----------------------------
SUBROUTINE SETMOLBYNAME(NEWMOLEC, i_Len)
!MS$ATTRIBUTES DLLEXPORT,STDCALL,ALIAS:'_Setmolbyname@8'::SETMOLBYNAME
INCLUDE 'COM_MASE.LVG'
CHARACTER*20 NEWMOLEC
INTEGER i_Len
WRITE(*,*) "Molec in fortran "
WRITE(*,*) NEWMOLEC
WRITE(*,*) "Molec in fortran "
DCOM ='MOLE'
RDCOM=NEWMOLEC
END SUBROUTINE
---------------------------- end fortran func ----------------------------
---------------------------- output ----------------------------
String c1: SIO
Calling fortran with the chain SIO
Molec in fortran
Molec in fortran
---------------------------- end output ----------------------------
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You would normally use strlen(), for example, to pass the actual length of the string, and use that length on the Fortran side. It looks here like you are trying to display the trailing null and subsequent uninitialized characters on the Fortran side.
I/O to the same stream by both C and Fortran, without precautions, is problematic. Maybe you could do it with a flush on the Fortran side as well.
Check the examples which come with your choice of Fortran and adhere more closely to them.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
!MS$ATTRIBUTES DLLEXPORT,STDCALL,ALIAS:'_Setmolbyname@8'::SETMOLBYNAME
Message Edited by patuco on 03-29-200601:54 AM

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