IDL_FileOpen problem? [message #20344] |
Tue, 13 June 2000 00:00  |
Nando Iavarone
Messages: 48 Registered: December 1998
|
Member |
|
|
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Dear all,
<br>I have some problems reading files using DLM under win platform.
<br>I am using IDL 5.2.1 and VisualC++ compiler.
<p>I wrote a little file called 'foo', using the simple
<p>IDL> data = dindgen(10)
<br>IDL> openW, 1, 'foo'
<br>IDL> writeU, 1, data
<br>IDL> close, 1
<p>After it I need to read them from a c-function in a DLM.
<br>
<br>
<p>- The code below works fine on unix platform (SGI and linux) but
it can't read data if used on WIN 98, NT.
<br>Anyone knows what's happening? A flag problem in the open?
<br>Note that after the IDL_FileOpen the same procedure is repeated using
simple fopen, and all is ok.
<p>- The documentation about the IDL_FileOpen (IDL - External Development
Guide) does not match the prototype definition in the file external.h.
This is for EDG 5.0, 5.1, 5.2,5.3
<br>
<br>
<p>This is the simple testmodule.c of the IDL distribution suitably modified.
This means you already have the makefile (or the win batch) to compile
it.
<br>
<p>Thank you for your help,
<br>
Nando.
<br>
<br>
<p>#include <stdio.h>
<br>#include "export.h"
<p>/* Handy macro */
<br>#define ARRLEN(arr) (sizeof(arr)/sizeof(arr[0]))
<p>/*
<br> * Define message codes and their corresponding printf(3) format
<br> * strings. Note that message codes start at zero and each one
is
<br> * one less that the previous one. Codes must be monotonic and
<br> * contiguous.
<br> */
<br>static IDL_MSG_DEF msg_arr[] =
<br>{
<br>#define M_TM_INPRO
0
<br> { "M_TM_INPRO", "%NThis is from a loadable
module procedure." },
<br>#define M_TM_INFUN
-1
<br> { "M_TM_INFUN", "%NThis is from a loadable
module function." },
<br>};
<br>
<br>
<p>/*
<br> * The load function fills in this message block handle with the
<br> * opaque handle to the message block used for this module. The
other
<br> * routines can then use it to throw errors from this block.
<br> */
<br>static IDL_MSG_BLOCK msg_block;
<br>
<br>
<p>/* Implementation of the TESTPRO IDL procedure */
<p>static void testpro(int argc, IDL_VPTR *argv)
<br>{
<p> FILE *fPtr=NULL;
<br>
<br> int err = 0;
<br> int i = 0;
<br> int lun=10;
<p> char tmpstr[100];
<br> char chararr[100];
<p> double dblarr[10];
<br> double buf[10];
<p> IDL_VPTR idlErr;
<br> IDL_VPTR ArgV[2];
<br> IDL_VPTR Lun;
<br> IDL_VPTR tmp;
<p> IDL_FILE_STAT FileStat;
<p> IDL_LONG dim[IDL_MAX_ARRAY_DIM];
<br>
<p>
<br> tmp = IDL_StrToSTRING("starting testpro\n");
<br> IDL_Print(1,&tmp,NULL);
<p>
<br> Lun &nb sp;
= IDL_Gettmp();
<br> Lun->type = IDL_TYP_LONG;
<br> Lun->value.l = lun;
<br> ArgV[0] = Lun;
<br> ArgV[1] = IDL_StrToSTRING("foo");
<br>
<br> /* read */
<br> IDL_Print(1, &ArgV[1], NULL);
<br> err = IDL_FileOpen(2, ArgV, NULL, IDL_OPEN_R, IDL_F_DOS_BINARY,
TRUE, 0);
<br> if (err == FALSE)
<br> {
<br> tmp = IDL_StrToSTRING("can't
open......\n");
<br> IDL_Print(1,&tmp,NULL);
<br> return ;
<br> }
<br>
<br> IDL_FileStat(lun, &FileStat);
<br> err = fread(dblarr, 10*sizeof(double), 1, FileStat.fptr);
<br>
<br> if (err != 1)
<br> {
<br> tmp = IDL_StrToSTRING("can't
read......\n");
<br> IDL_Print(1,&tmp,NULL);
<br> /* return; */
<br> }
<br>
<br> tmp = IDL_StrToSTRING("after fread\n");
<br> IDL_Print(1,&tmp,NULL);
<br> IDL_FileClose(1, &ArgV[0], NULL);
<p> dim[0]=10;
<br> tmp = IDL_ImportArray(1, dim, IDL_TYP_DOUBLE, (UCHAR*)dblarr,
NULL, NULL);
<br> IDL_Print(1, &tmp, NULL);
<br>
<p>
<br> /* fopen */
<p> if( (fPtr = fopen(
"foo", "rb" )) == NULL )
<br> {
<br>
tmp = IDL_StrToSTRING("can't fopen ......\n");
<br>
IDL_Print(1,&tmp,NULL);
<br> }
<br> else
<br> {
<br>
err = fread(dblarr, 10*sizeof(double), 1, fPtr);
<br>
if (err != 1)
<br>
{
<br>
tmp = IDL_StrToSTRING("can't read......\n");
<br>
IDL_Print(1,&tmp,NULL);
<br>
/* return; */
<br>
}
<br>
tmp = IDL_ImportArray(1, dim, IDL_TYP_DOUBLE, (UCHAR*)dblarr, NULL, NULL);
<br>
IDL_Print(1, &tmp, NULL);
<p>
fclose(fPtr);
<br> }
<br>
<p> /* cleanup */
<br> IDL_Deltmp(Lun);
<br> IDL_Deltmp(tmp);
<br>}
<br>
<br>
<p>/* Implementation of the TESTFUN IDL function */
<br>static IDL_VPTR testfun(int argc, IDL_VPTR *argv)
<br>{
<p> IDL_MessageFromBlock(msg_block, M_TM_INFUN, IDL_MSG_RET);
<br> return IDL_StrToSTRING("TESTFUN");
<br>}
<br>
<br>
<p>int IDL_Load(void)
<br>{
<br> /*
<br> * These tables contain information on the functions and
procedures
<br> * that make up the TESTMODULE DLM. The information contained
in these
<br> * tables must be identical to that contained in testmodule.dlm.
<br> */
<br> static IDL_SYSFUN_DEF function_addr[] = {
<br> { testfun, "TESTFUN", 0, IDL_MAXPARAMS, 0},
<br> };
<p> static IDL_SYSFUN_DEF procedure_addr[] = {
<br> { (IDL_FUN_RET) testpro, "TESTPRO", 0, IDL_MAX_ARRAY_DIM,
0},
<br> };
<br>
<p> /*
<br> * Create a message block to hold our messages. Save its
handle where
<br> * the other routines can access it.
<br> */
<br> if (!(msg_block = IDL_MessageDefineBlock("Testmodule", ARRLEN(msg_arr),
<br>
msg_arr)))
<br> return IDL_FALSE;
<p> /*
<br> * Register our routine. The routines must be specified
exactly the same
<br> * as in testmodule.dlm.
<br> */
<br> return IDL_AddSystemRoutine(function_addr, TRUE, ARRLEN(function_addr))
<br> && IDL_AddSystemRoutine(procedure_addr,
FALSE, ARRLEN(procedure_addr));
<br>}
<br>
<pre>--
Nando Iavarone
Advanced Computer System - SPACE DIVISION
via Lazzaro Belli, 23
00040 Frascati - RM
Tel: +39-6-944091 (switchboard)
9440968 (direct)
E-mail:
f.iavarone@acsys.it
FrdndVrn@altavista.net</pre>
</html>
|
|
|