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

Home » Public Forums » archive » Re: Name of arrays
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Name of arrays [message #79346 is a reply to message #79260] Mon, 20 February 2012 13:27 Go to previous messageGo to previous message
Russell[1] is currently offline  Russell[1]
Messages: 101
Registered: August 2011
Senior Member
On Feb 20, 4:46 am, Israel Rodriguez Hermelo <israelherm...@gmail.com>
wrote:
> On Feb 19, 5:00 pm, David Fanning <n...@idlcoyote.com> wrote:
>
>
>
>
>
>
>
>
>
>> Israel Rodriguez Hermelo writes:
>>> Why did you say that's a slippery slope? Is there a better solution?
>>> I'm already using it with no problems.
>
>> I see a lot of people who are just getting started with
>> programming wanting to name their variables like this.
>> It seems cool, but in the end it just leads to unmaintainable
>> programs. A variable is a variable. The variable named "a" is
>> just as good as the variable named "b". Yes, variables should
>> have good names in programs. But just give them a name
>> (e.g., "theseMonths") in the program module where you need them.
>> Don't go looking for them all over God's creation!
>
>> Cheers,
>
>> David
>
>> --
>> David Fanning, Ph.D.
>> Fanning Software Consulting, Inc.
>> Coyote's Guide to IDL Programming:http://www.idlcoyote.com/
>> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
>
> Thank you for your advice David. I'll try to avoid using
> scope_varfecht then.
> My problem however is not simply that I want to have pretty names for
> my variables. The problem is that I don't know a priori the number of
> arrays that I will need nor their size.
> For example, in some cases the input data might correspond to the
> months of February and July, but in other cases might correspond to
> January, March and April.
>
>  MONTH = [ 'FEBRUARY' , 'JULY' , 'SEPTEMBER' ]
>
> To deal with this, I was trying:
>
>  Nmonths=N_ELEMENTS(MONTH)
>
>  for i=0, Nmonths-1 do begin
>
>    readcol, MONTH(i)+'_data.txt', TEMPERATURE
>
>    Ndays=N_ELEMENTS(TEMPERATURE)
>
>   (scope_varfetch(MONTH(r)+'TEMPERATURE', /enter))=fltarr(Ndays)
>
>  endfor
>
> I see why you wrote that scope_varfecht makes the leads to
> unmaintainable
> programs and I would prefer any other solution but I've been looking
> for it in the forum and I haven't found any. Do you have any
> suggestion?
> Thanks in advance!
>
> Regards,
>
> Israel

This is where you should use the pointers. Consider the following:

months=['Jan','Feb','Sep']
x=ptr_new(months)
help,(*x)

But, months can change on-the-fly and contain any data type

data=[{month:'Jan',numberofdays:31},{month:'Feb',numberofday s:28}]
x=ptr_new(data)
help,(*x),/str

and so on. Since you can do any operation on (*x) that you would do
on say months=['Jan','Feb','Sep'], this usage means you can
arbitrarily define the variables and access the data. Now, it's true
that as of IDL 8.* they have introduced new variable types to do this,
but until IDL 8 is standard everywhere, you might consider remaining
with pointers (for backwards compatibility).

Russell
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: tracking clusters through multiple timesteps
Next Topic: Issue with console of workbench 8.0

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

Current Time: Fri Oct 10 00:00:20 PDT 2025

Total time taken to generate the page: 0.87940 seconds