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

Home » Public Forums » archive » [Q] readf into an array error
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
[Q] readf into an array error [message #5725] Fri, 02 February 1996 00:00
Iarla Kilbane-Dawe is currently offline  Iarla Kilbane-Dawe
Messages: 7
Registered: May 1995
Junior Member
Hello,

why does IDL give me an error when I try to do?

a=fltarr(10)
i = 0
readf,unit,a(i)

Many thanks,


Iarla.

____________________________________________________________ _________

Iarla Kilbane-Dawe Email: iarla@atm.ch.cam.ac.uk
Centre for Atmospheric Science Phone: ++44 (01223) 336524
Cambridge University Fax: ++44 (01223) 336473
____________________________________________________________ _________
Re: [Q] readf into an array error [message #5729 is a reply to message #5725] Fri, 02 February 1996 00:00 Go to previous message
Ken Knighton is currently offline  Ken Knighton
Messages: 44
Registered: May 1995
Member
> why does IDL give me an error when I try to do?
>
> a=fltarr(10)
> i = 0
> readf,unit,a(i)
>

I'm not sure why IDL gives you an error, but

readf, unit,a(i)

is not going to read anything. a(i) is an expression rather than a
variable. The readf statement requires a named variable in order to
read anything. Try using

a=fltarr(10)
i=0
b=0.0
readf, unit, b
a(i)=b

This is actually mentioned somewhere in the i/o chapter of the user's
manual.

Also, you might want to look at the ASSOC() function and associated i/o.
Because you are reading an array, this might be a better solution.

Ken Knighton knighton@gav.gat.com knighton@cts.com
General Atomics
San Diego, CA
Re: [Q] readf into an array error [message #5732 is a reply to message #5725] Fri, 02 February 1996 00:00 Go to previous message
peter is currently offline  peter
Messages: 80
Registered: February 1994
Member
Iarla Kilbane-Dawe (iarla@atm.ch.cam.ac.uk) wrote:

: Hello,

: why does IDL give me an error when I try to do?

: a=fltarr(10)
: i = 0
: readf,unit,a(i)

This is due to the argument passing mechanism used in IDL. If an array
is passed to a function, it is passed by reference. If a subarray is
passed, it is passed by value, and thus cannot be overwritten.

To accomplish what you want, you need to do

temp = a(i)
readf,unit,temp
a(i) = temp

It is ugly! The syntax gives no clue what is happening, and the
manual is exceptionally obscure.

Peter

--------------------------------
Peter Webb, HP Labs Medical Dept
E-Mail: peter_webb@hpl.hp.com
Phone: (415) 813-3756
Re: [Q] readf into an array error [message #5734 is a reply to message #5725] Fri, 02 February 1996 00:00 Go to previous message
M.W.Gardner is currently offline  M.W.Gardner
Messages: 7
Registered: November 1995
Junior Member
Iarla Kilbane-Dawe <iarla@atm.ch.cam.ac.uk> wrote:

> why does IDL give me an error when I try to do?
>
> a=fltarr(10)
> i = 0
> readf,unit,a(i)
>

Iarla, what error do you get and what exactly are you attempting to do ?

if you haven't defined the unit you get "% READF: Variable is undefined: UNIT"

if unit is defined (eg given a number say 1) and has not been defined in an
open statement you get "% READF: File unit is not open: 1"

If you are trying to read from a file a ten element array then open you file,
read in the data, and close the file like so :

a=fltarr(10)
open,unit,'filename',/get_lun
read,unit,a
close,unit
free_lun,unit

and that should do it. If you don't want to do this then ignore all that and
let me know what you want to do !

Anyway, I hope that helps, if not provide some more info if I have missed the
point.

Matt
--
-----> Matt Gardner EMAIL->m.W.gardner@uea.ac.uk PHONE->+44- 1603-592041
School of Environmental Science,University of East Anglia,Norwich,NR4 7TJ,UK
------------------------------------------------------------ ------------------
opinions are mine - http://www.uea.ac.uk/~e449
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: call_external with common blocks?
Next Topic: Q:Unable to allocate memory?

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

Current Time: Thu Oct 09 19:41:45 PDT 2025

Total time taken to generate the page: 0.96174 seconds