Welcome to iraf.net Wednesday, May 22 2024 @ 12:07 AM GMT
Gaba_p |
04/14/2009 02:26PM (Read 1468 times)
|
|
|
Status: offline
Registered: 10/10/2008
Posts: 104
|
Hi (me again),I'm trying to assign values read from a file to variables with different names (in a procedure script). Maybe an example will explain better what I want to do:procedure ()struct *listbeginint i
string variablelist = 'file1'
i = 1
while (fscan (list, variable + i) != EOF) {
i = i + 1
}endMy goal is to end up with: variable1 = xxx, variable2 = yyy, variable3 = zzz, etc.; where the values to store in the 'variables' are stored in the 'file1' file:xxx
yyy
zzz
...I hope I made myself clear.
Cheers!
|
|
|
|
fitz |
04/14/2009 02:26PM
|
|
|
Status: offline
Registered: 09/30/2005
Posts: 4040
|
Variables can't be created dynamically as you are doing (i.e. you only declare 'variable', not 'variable1', 'variable2', etc). If you have some small number of things to read (e.g. 3-5) then the simplest thing is something like[code:1:06d7a4a38b]
list = "myfile"
fscan (list, variable1)
fscan (list, variable2)
:
[/code:1:06d7a4a38b]Another way is to use an array of values, e.g.[code:1:06d7a4a38b]
string var[5] list = "zin"
for (i=1; fscan(list,s1) != EOF; i=i+1)
var[i] = s1
for (i=1; i <= 5; i=i+1)
print (var[i])
[/code:1:06d7a4a38b]Note arrays are 1-indexed and you cannot scan into them directly. You'll also have to know how many strings to expect so you can declare the array with some max value. If the values on the lines have some meaning you might be better off with the first option where you can have meaningful variable names to use in the script. -Mike
|
|
|
|
| |
|
Content generated in: 0.09 seconds |
|