View on GitHub

IRAF Community Distribution

IRAF maintained by the community

Home | Installation | Packages | X11IRAF | PyRAF | Forum

variances of images and storing them in a file

smp wrote on Mar 01, 2010

Hi,

What my script does?
Follwoing procedure script finds std. deviation of each image.
Then square it to calculate variance of that image.
Then pass this variance to a text file.
This is done for all the images in the image-list.

What is my problem?
I get the text file containing variances (variance_of_all_images.txt),
but the I get all variance numbers in a line with some strange characters in between numbers.

The other file "stddev_of_all_images.txt" is okay.

procedure stddev_and_variance(input)

string input
struct *imglist

begin

        string input_file, imgfile, imname
        real sigma, var

        input_file = input

        imgfile = mktemp("tmp$t_input_")
        sections(input_file, option = "fullname", > imgfile)
        imglist = imgfile


        if(access(" stddev_of_all_images.txt"))
               { delete("stddev_of_all_images.txt ") }
        else{ print("\nfile not found: 1\n") }

        if(access(" variance_of_all_images.txt")) 
               { delete("variance_of_all_images.txt") }
        else{ print("\nfile not found: 2\n") }

         while(fscan(imglist,imname) != EOF)
          {
                sigma = 0.0
                var = 0.0

               imstat(images=imname,fields="stddev",format=no) | scan(sigma)    
                var = sigma*sigma

                printf(sigma//"\n", >> "stddev_of_all_images.txt") 

               printf(var//"\n", >> "variance_of_all_images.txt")

          }

end



Regards,
smp

Mike Fitzpatrick wrote on Mar 01, 2010

I think the problem is that you're using printf() which is expecting a format string, you should be using print() instead. For example



printf ("%g\n", sigma, >> "foo.txt")

or

print (sigma, >> "foo.txt")


-Mike

smp wrote on Mar 01, 2010

Thanks.
It worked.

Regards,
smp

Last post on Mar 01, 2010