Welcome to iraf.net Tuesday, April 30 2024 @ 08:26 PM GMT


 Forum Index > Help Desk > General IRAF New Topic Post Reply
 Arrays in CL
   
esemenko
 04/10/2007 05:11PM (Read 7451 times)  
++---
Junior

Status: offline


Registered: 10/02/2006
Posts: 16
Hello!
I would like to read list of files from @file to some array. But I don't know exactly number of records in @file.
That is I need something like
[code:1:1d756ab059]
string sarray[]
int ii = 0
list = 'somefile'
while (fscan(list, s1) != EOF) {
sarray[ii] = s1
ii = ii + 1
}
[/code:1:1d756ab059]
where size of sarray increasing dynamically. How can I do this?And the second question. Is there any method to know nomber of elements in array or image? I need something like a n_elements in IDL or $#array in PERL.Thanks.

Cheers, Eugene.
 
Profile Email Website
 Quote
fitz
 04/10/2007 05:11PM  
AAAAA
Admin

Status: offline


Registered: 09/30/2005
Posts: 4040
Sorry, variable/dynamic arrays aren't permitted. I could easily adda new builtin function to return the declared size and dimensionality of an array but presumably any script using that array should probably already know that.-Mike

 
Profile Email
 Quote
esemenko
 04/10/2007 05:11PM  
++---
Junior

Status: offline


Registered: 10/02/2006
Posts: 16
Well, but how can I create array in the case if exact number of elements is unknown. Actually I have @file where number of records is unknown. I can of cource make a loop with counter and obtain N_elements in this way. I can make something like a $cat "@file" | wc -l, but I don't know how initiate a variable with value obtained from bash environment. I thank that more convenient method exist.

Cheers, Eugene.
 
Profile Email Website
 Quote
fitz
 04/10/2007 05:11PM  
AAAAA
Admin

Status: offline


Registered: 09/30/2005
Posts: 4040
The COUNT task can tell you how many lines are in a file, but you still can't use this within a script to declare an array based on the value (i.e. that's what I meant by 'variable sized' arrays. The best you can do is declare an array to be some number larger than you expect to use, and then perhaps use COUNT to make sure you won't overflow it. Optimally though you'd write your script so that you wouldn't need to store the file as an array internally in the first place.-Mike

 
Profile Email
 Quote
   
Content generated in: 0.13 seconds
New Topic Post Reply

Normal Topic Normal Topic
Sticky Topic Sticky Topic
Locked Topic Locked Topic
New Post New Post
Sticky Topic W/ New Post Sticky Topic W/ New Post
Locked Topic W/ New Post Locked Topic W/ New Post
View Anonymous Posts 
Anonymous users can post 
Filtered HTML Allowed 
Censored Content 
dog allergies remedies cialis 20 mg chilblain remedies


Privacy Policy
Terms of Use

User Functions

Login