IDL communicate with FORTRAN [message #9090] |
Tue, 27 May 1997 00:00 |
Gary Fu
Messages: 9 Registered: April 1997
|
Junior Member |
|
|
Hi,
The IDL User's Guide has an example about how IDL communicates with a
C program. What should I do, if I want to write in FORTRAN in this
example ?
Thanks.
Gary
************************************************************ ******
C program:
#include <stdio.h>
extern int errno; /* System error number */
extern char *sys_errlist[]; /* System error messages */
extern int sys_nerr; /* Length of sys_errlist */
main()
{
float *data, total = 0.0;
long i, n;
/* Make sure the output is not buffered */
setbuf(stdout, (char *) 0);
/* Find out how many points */
if (!fread(&n, sizeof(long), 1, stdin)) goto error;
/* Get memory for the array */
if (!(data = (float *) malloc((unsigned)
(n * sizeof(float))))) goto error;
/* Read the data */
if (!fread(data, sizeof(float), n, stdin)) goto error;
/* Calculate the average */
for (i=0; i < n; i++) total += data[i];
total /= (float) n;
/* Return the answer */
if (!fwrite(&total, sizeof(float), 1, stdout))
goto error;
return;
error:
fprintf(stderr, "test_pipe: %s\n",
sys_errlist[errno]);
}
************************************************************ ******
IDL program:
SPAWN, 'test_pipe', UNIT = UNIT, /NOSHELL
WRITEU, UNIT, 10L, FINDGEN(10)
READU, UNIT, ANSWER
PRINT, "Average = ", ANSWER
FREE_LUN, UNIT
Executing these statements gives the result:
Average = 4.50000
--
*****************************************
* Gary Fu, GSC (301) 286-7107 *
* email : "gfu@seadas.gsfc.nasa.gov" *
* NASA/Goddard Space Flight Center *
*****************************************
|
|
|