Welcome to iraf.net Tuesday, May 21 2024 @ 01:56 AM GMT
smp |
10/23/2008 11:41AM (Read 4845 times)
|
|
|
Status: offline
Registered: 07/27/2008
Posts: 70
|
Hi,In the following segment of procedure script, I am trying to create image names and pipe them to a string variable, one bye one.But I am getting the error:
Attempt to access undefined local variable `str'[code:1:ecbc94a136]
:
begin
string str
:
for(n=1;n<=5;n=n+1)
{
printf("left_%d.fits", n) | str
print(str)
}
:
end
[/code:1:ecbc94a136]So if I define 'str' , as follows:
[code:1:ecbc94a136]
:
begin
string str
str = "iraf"
:
for(n=1;n<=5;n=n+1)
{
printf("left_%d.fits", n) | str
print(str)
}
:
[/code:1:ecbc94a136]I do not get error. But now the output is not what I wanted:left_1.fits
iraf
left_2.fits
iraf
left_3.fits
iraf
left_4.fits
iraf
left_5.fits
irafInstead I want following output:
left_1.fits
left_2.fits
left_3.fits
left_4.fits
left_5.fitsPlease help me.
Thanks
|
|
|
|
Jason Quinn |
10/23/2008 11:41AM
|
|
|
Status: offline
Registered: 04/07/2006
Posts: 175
|
You'll want a newline ("\n") to end the printf and don't just pipe the output of printf to the variable but use a scan call.[code:1:8681668bc1]
:
begin
string str
int n
for(n=1;n<=5;n+=1)
{
printf("left_%d.fits\n", n) | scan(str)
print(str)
}
:
end
[/code:1:8681668bc1]But the way I would do it would be like this:[code:1:8681668bc1]
:
begin
string str
int n
:
for(n=1;n<=5;n+=1)
{
str="left_"//str(n)//".fits"
print(str)
}
:
[/code:1:8681668bc1]I also hate any n=n+1 type constructs and changed it to n+=1. I prefer even more n++ but IRAF doesn't have an increment operator.Jason
|
|
|
|
smp |
10/23/2008 11:41AM
|
|
|
Status: offline
Registered: 07/27/2008
Posts: 70
|
Hi,Thanks. Both the ways work well here. Second way is a cute one.
About the second way:
There are 4 double quotes.
I suppose that 1st and last are for first str i.e. 'str =' . Am I right?
Also 2nd double quote is followed by concatenation , while after str(n), concatenation is followed by double quote. I have not understood this sequence clearly. Will you please explain it?Regards
Swapnil
|
|
|
|
fitz |
10/23/2008 11:41AM
|
|
|
Status: offline
Registered: 09/30/2005
Posts: 4040
|
The '//' is the string concatenation operator in the CL, so the way to read the line is that the variable 'str' is the concatenation of the string "left_" with the string version of the variable 'n' with the string ".fits"-Mike
|
|
|
|
smp |
10/23/2008 11:41AM
|
|
|
Status: offline
Registered: 07/27/2008
Posts: 70
|
Hi,Thanks.Swapnil
|
|
|
|
| |
|
Content generated in: 0.27 seconds |
|