enud
asked on
C to Fortran and vice versa
well if this isn't the right forum to ask this question then no one is!i have created a program in C that is a part of a big program made in Fortran.what i am supposed to do is to transfer some values from the C program to the Fortran program,and take the new values,back to the C program.
values C ------>Fortran ------>new value
new value Fortran------->C
can anyone tell me how i could do that?
PS:i can't redo the program in Fortran
values C ------>Fortran ------>new value
new value Fortran------->C
can anyone tell me how i could do that?
PS:i can't redo the program in Fortran
example with explanation here
http://www.cs.cf.ac.uk/Dave/C/node23.html
http://www.cs.cf.ac.uk/Dave/C/node23.html
thanks for the answer sunnycoder.please give me sometime to check this out!
ASKER
to sunnycoder:
hello again,
Well unfortunately i forgot to mention that the program is ment to be for windows platform.so if it isn't a problem please give me a more detailed example for a unix platform.I found that with some specific commands from multithreading and functions like createpipe(), i can emulate(if this is the right word:p) some of the function of the unix world such as fork() and pipe() but i can't follow the example you gave me.you assumed right that the values which need to be transferred are produced/read from stdout and stdin.So what i would like is one program in fortran that the output (just some numbers) are the input of a program made in C.
PS : of course if you can program it directly for windows platform you are my god!
hello again,
Well unfortunately i forgot to mention that the program is ment to be for windows platform.so if it isn't a problem please give me a more detailed example for a unix platform.I found that with some specific commands from multithreading and functions like createpipe(), i can emulate(if this is the right word:p) some of the function of the unix world such as fork() and pipe() but i can't follow the example you gave me.you assumed right that the values which need to be transferred are produced/read from stdout and stdin.So what i would like is one program in fortran that the output (just some numbers) are the input of a program made in C.
PS : of course if you can program it directly for windows platform you are my god!
C101 :
http:/Q_20817471.html
enud:
In Windows, the CreateProcess function enables the parent process to create an operating environment for a new process. The environment includes the working directory, window attributes, environment variables, execution priority and command line arguments. A handle is returned by the CreateProcess function, which enables the parent application to perform operations on the process and its environment while it is executing. Unlike UNIX, the executable file run by CreateProcess is not a copy of the parent process, and it has to be explicitly specified in the call to CreateProcess.
An alternative to CreateProcess is to use one of the spawn functions that is present in the standard C runtime.
Windows example: low-level pipe call
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <io.h>
#include <fcntl.h>
#include <process.h>
void main()
{
size_t data_out, data_in;
int file_pipes[2];
const char data[] = "ABCDE";
char buffer[BUFSIZ + 1];
memset(buffer, '\0', sizeof(buffer));
if (_pipe(file_pipes, 32, O_BINARY) == 0) {
data_out = write(file_pipes[1], data, strlen(data));
printf("Wrote %d bytes\n", data_out);
data_in = read(file_pipes[0], buffer, BUFSIZ);
printf("Read %d bytes: %s\n", data_in, buffer);
exit(EXIT_SUCCESS);
}
exit(EXIT_FAILURE);
}
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnucmg/html/UCMGch09.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ipc/base/using_pipes.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcsample98/html/vcsmpipcsample.asp
http:/Q_20817471.html
enud:
In Windows, the CreateProcess function enables the parent process to create an operating environment for a new process. The environment includes the working directory, window attributes, environment variables, execution priority and command line arguments. A handle is returned by the CreateProcess function, which enables the parent application to perform operations on the process and its environment while it is executing. Unlike UNIX, the executable file run by CreateProcess is not a copy of the parent process, and it has to be explicitly specified in the call to CreateProcess.
An alternative to CreateProcess is to use one of the spawn functions that is present in the standard C runtime.
Windows example: low-level pipe call
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <io.h>
#include <fcntl.h>
#include <process.h>
void main()
{
size_t data_out, data_in;
int file_pipes[2];
const char data[] = "ABCDE";
char buffer[BUFSIZ + 1];
memset(buffer, '\0', sizeof(buffer));
if (_pipe(file_pipes, 32, O_BINARY) == 0) {
data_out = write(file_pipes[1], data, strlen(data));
printf("Wrote %d bytes\n", data_out);
data_in = read(file_pipes[0], buffer, BUFSIZ);
printf("Read %d bytes: %s\n", data_in, buffer);
exit(EXIT_SUCCESS);
}
exit(EXIT_FAILURE);
}
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnucmg/html/UCMGch09.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ipc/base/using_pipes.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcsample98/html/vcsmpipcsample.asp
ASKER
I understand the stuff with C++ and how i can create a server and a client application and how by using pipes,take the output from the one process as input to the other.what i still don't understand is how i can create two programs,from which one of them is writen in C and the other in fortran and still make them communicate with each other.Which should be the server and which the client.should i create a function in fortran (say func1()) which i'll call using pipes from the program made in C?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I assume that the values which need to be transferred are produced/read from stdout and stdin ...
now to transfer the values,
pipe()
pipe()
fork()
//in child close read end of pipe1 and write and of pipe2
//in parent close write end of pipe1 and read end of pipe2
//usual close and dups()
exec the fortran program in the child
Cheers!
Sunny:o)