comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » IDL communicate with FORTRAN
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
IDL communicate with FORTRAN [message #9090] Tue, 27 May 1997 00:00
Gary Fu is currently offline  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 *
*****************************************
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Warning -- Median "Feature"
Next Topic: v5 and insight on win95/p133

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 13:30:41 PDT 2025

Total time taken to generate the page: 1.61996 seconds