View on GitHub

IRAF Community Distribution

IRAF maintained by the community

Home | Installation | Packages | X11IRAF | PyRAF | Forum

openning a text file.

douglas brenner wrote on Oct 28, 2009

I need to generate a file name within a script and then open that file. How do I do that?
Thanks

Mike Fitzpatrick wrote on Oct 28, 2009

There are any number of ways to do it, basically you need to create a string variable for the filename. You can do this as e.g.


cl> fname = "file" // i          # append an integer to a literal string
cl> fname = "flist"              # create a file of image names
cl> file ("foo*.fits", > fname)


an so on. Once you have the filename, you can read it using the 'list' parameter. For example, if it is a list of filenames


list = fname
while (fscan (list, s1) != EOF) {
    imstat (s1)
}


If you have specific questions, please post the details of how you need to create the filename and what is in it.

-Mike

douglas brenner wrote on Oct 28, 2009

I want to read four integers at a time from a file.

procedure remake
begin
int lambda, i , col, row, fpcol, fprow
real j
string oldtxtmap
string txtfile = "/DATA/MAPS/PSuperLaser"
for (i = 0; i < 24; i += 1)
{
j = (1100 + i*27.88)/10
if ( abs(j - int (j)) > 0.5)
lambda = 10*(int(j + 1))
else
lambda = 10*int(j)
oldtxtmap = txtfile//str(lambda)//"M.txt"
print(oldtxtmap)
// while
fscanf(oldtxtmap, col, row, fpcol, prow)
printf( "%d %d, %d %d", col, row, fpcol, fprow)
}
end

douglas brenner wrote on Oct 28, 2009

Can't convert a string.

procedure remake

struct *oldtxtmap
begin

int lambda, i, col, row, fpcol, fprow
real j
string oldfitsmap, newfitsmap, newtxtmap
string fitsfile = "/DATA/PSFs/PREPROCESSED/SuperLaser"
string txtfile = "/DATA/MAPS/PSuperLaser"

for (i = 0; i < 24; i += 1)
{
j = (1100 + i*27.88)/10

if ( abs(j - int (j)) > 0.5)
lambda = 10*(int(j + 1))
else
lambda = 10*int(j)
print(lambda)
oldtxtmap = (struct*) txtfile//str(lambda)//"M.txt"

oldfitsmap = fitsfile//str(lambda)//".fits"
print(oldtxtmap," ", oldfitsmap)
fscan(oldtxtmap, col, row, fpcol, prow)
print( "%d %d, %d %d", col, row, fpcol, fprow)

}

end

Mike Fitzpatrick wrote on Oct 28, 2009

Try


string oldtxtmap
      :
oldtxtmap = txtfile//str(lambda)//"M.txt" 
list = oldtxtmap
      :
fscan (list, col, row, fpcol, prow)


-Mike

Last post on Oct 28, 2009