View on GitHub

IRAF Community Distribution

IRAF maintained by the community

Home | Installation | Packages | X11IRAF | PyRAF | Forum

read & write in file

ranisb wrote on Dec 02, 2008

Hi,
I am writing following procedure script.I have 3 science frames and one masterbias.this script will subtract biasmaster from each science frame and change file name "sci_bs_%d.fits and save in file 'objfile'.
The script is as following;
procedure trial(sciframes)
string sciframes {prompt = "images tobe reduce"}
struct *objlist

begin
int n
string objfile,filename,biasmaster
objlist = sciframes
biasmaster = "biasmaster.fits"
for (n=1;n<=3;n=n+1)
{
printf("sci_bs_%d.fits\n",n, > objfile)
}
objlist = objfile
while(fscan(objlist,filename) !=EOF)
{ print(filename) }
imarith(operand1=objlist,op="-",operand2=biasmaster,result="@"//objfile,verbose=no)
end

But it is giving following error,
cc> trial
images tobe reduce: sciimage_lis
ERROR on line 19: Attempt to access undefined local variable `objfile'.
trial ()
trial ()

Where I am wrong? I would be thankful for any solution as I 'm pretty stuck.

Regards,
Rani

James Turner wrote on Dec 02, 2008

When you do
printf("sci_bs_%d.fits\n",n, > objfile)

the variable objfile hasn't actually been assigned a value (filename) yet, it has just been defined as a variable. Did you mean to declare it as a parameter?

Cheers,

James.

ranisb wrote on Dec 02, 2008

Hi James,
you are right,I decleared 'objfile' as local string variable.
It will be great if you will give suggestions in my small script to get required output ,which I mention in my first post .
:(
regards,
Rani

ranisb wrote on Dec 02, 2008

hi,
Waiting for your reply and still didn't found any solution .
:cry:
I am sending my small script which will subtract biasmaster from each science frame and change file name "sci_bs_%d.fits and save in file 'objfile'.

procedure trial(sciframes)
string sciframes {prompt = "images tobe reduce"}
struct *objlist
#string objfile
begin
int n
string filename, biasmaster, objfile
# objlist = objfile
biasmaster = "biasmaster.fits"
for (n=1;n<=3;n=n+1)
{
printf("sci_bs_%d.fits\n",n, > "objfile")
}
objlist = objfile
while(fscan(objlist,filename) !=EOF)
{ print(filename) }
imarith(operand1=sciframes,op="-",operand2=biasmaster,result="@"//objfile,verbose=no)
end

Kindly write me solutions as eraly as possible. Also if you have any suggestion to do this task, write to me.
:(
Thanks and regards,
Rani

James Turner wrote on Dec 02, 2008

I think your problem is essentially the same as before. You are mixing up the variable name objfile with the filename "objfile". The value of the variable is still undefined when you do objlist = objfile. Maybe you meant to do objfile="objfile" somewhere?

Cheers,

James.

ranisb wrote on Dec 02, 2008

thanks for reply
Now I am confused with this variable and parameter declaration
:?
Can you please suggest me what changes should i do in my script which will subtract biasmaster from each science frame and change file name "sci_bs_%d.fits and save in file 'objfile'.
or do you have any other suggestion?
Please reply quick.

regards,

James Turner wrote on Dec 02, 2008

Hi Rani,

I don't really have time to write the script for you, but try putting
objfile="objfile"
after the line 'biasmaster = "biasmaster.fits"' and remove the quotation marks around '"objfile"' in the printf statement.

This will only work as written if you have 3 images, of course. To make it more general, you might want to count the number of images in the input list by adding something like
l_sciframes = sciframes
files l_sciframes > "sciframelist"

after ' biasmaster = "biasmaster.fits" and then using a "while(fscan..." like the one you already have to loop through the input images, instead of using the for loop over the output images with a fixed number of (3) iterations.

You'll need to verify that this works, since I'm just looking at the code and commenting on it without trying it out. If you are still unsure about the CL syntax, there is an introduction to writing scripts here:

http://iraf.net/irafdocs/script/

Hope that helps.

James.

ranisb wrote on Dec 02, 2008

Dear James,

Thank you very much for stolen time from your busy schedule ,for my script problem.

I did the chages you suggested but still the following error occuring,
cc> trial4
ERROR on line 19: cannot open `objfile' for writing
trial4 ()
trial4 ()

I am trying to resolve it.
I am greatly appreciated your help.

Regards,
Rani

James Turner wrote on Dec 02, 2008

ranisb


ERROR on line 19: cannot open `objfile' for writing
trial4 ()
trial4 ()

Isn't that because objfile already exists? You have to delete it first.

When I suggested doing "l_sciframes = sciframes" last time, I forgot to say to change "sciframes" to "l_sciframes" inside the imarith. Using "sciframes" just once in the script by copying it to a local variable prevents IRAF from prompting you for the variable several times if you haven't specified it on the command line.

Cheers,

James.

Last post on Dec 02, 2008