View on GitHub

IRAF Community Distribution

IRAF maintained by the community

Home | Installation | Packages | X11IRAF | PyRAF | Forum

strange problem in printing variables in procedure script

christian wrote on Apr 25, 2008

Hi Folks,

first of all let me thank you for this wonderfull Forum. I have allready found a lot of answers for my newby questions in here :) ... That said here we go with my resent problem 8)

I have written my first procedure script and so far everything works fine except from the ouput file i want to generate. Here the part of the code that is responsible for this:

real distance
real stddev


...

                result = distance // "_____" // stddev
                print (distance // "_____" // stddev)
                print (result, >> "result")


The values of "stddev" and "distance" come from some very simpel calculations so I don't think this is the Problem. However what i get (in the terminal and the file) ist something like that:

2.9306321843589<0.03920643
2.795_____0.03413983
2.721257981155<0.03597416
2.7144548255589<0.0433135


So from time to time i get exactely what I want (like in the second row) but most of the time i get strange Stuff like the "<" sign in the middle of the both values.

Maybe it has something to do with the number of decimales or with the real type ?

I hope this question is not to noobish :) but at the moment i'm pretty stuck... so I would be thankfull for any advice.

Greetings
christian

Mike Fitzpatrick wrote on Apr 25, 2008

I'm assuming that 'result' is a string variable?

From the code snippets it appears like it should work as you expect, if I had to
guess I'd say that the 'result' variable was being overwritten elsewhere in the script. It would help to see the entire script (please post it or mail it to fitz@iraf.net)

Cheers,
-Mike

christian wrote on Apr 25, 2008

yep it is a string...
here the complete code ... hope its not to confusing :)




procedure test1 (data, boxsize_mas, peakx, peaky, n, tmp, maxpix)

file data
real boxsize_mas
int peakx,peaky,n
string tmp
int maxpix

############################Versteckte Variablen#######################

struct *hallo

int n1 = 43
int n2 = 75
int n3 = 200


begin

############################Bermerkungen###############################

# reset clobber = yes # damit die temporäre Datei immer wieder überschrieben werden kann

############################Variablen##################################

int box = 0
int i, j
struct peak
struct stddev_tmp
file mbox
real peak_r
real distance
real stddev
real xbox_min, xbox_max, ybox_min, ybox_max
string result

###########################Hauptteil##################################

hallo = tmp

switch (n)
        {
        case 1 : box = int (boxsize_mas / n1)
        case 2 : box = int (boxsize_mas / n2)
        case 3 : box = int (boxsize_mas / n3)
        }

imstat (data, fields="max", lower=INDEF, upper=INDEF, binwidth=0.1, format=no, > "testfile2") #gibt Ergebnis in Datei aus


if (fscan (hallo, peak) != EOF)
        print (peak)

peak_r = real (peak)

 for (i=1; i <= maxpix; i+=10){
  for (j=1; j <= maxpix; j+=10){

        switch (n)
                {
                case 1 : distance = n1 * (sqrt((peakx - i) * (peakx - i) + (peaky - j) * (peaky - j) )) / 1000
                case 2 : distance = n2 * (sqrt((peakx - i) * (peakx - i) + (peaky - j) * (peaky - j) )) / 1000
                case 3 : distance = n3 * (sqrt((peakx - i) * (peakx - i) + (peaky - j) * (peaky - j) )) / 1000
                }

        xbox_min = i - box
        ybox_min = j - box
        xbox_max = i + box
        ybox_max = j + box

        if (xbox_min >= 1 && ybox_min >= 1 && xbox_max <= maxpix && ybox_max <= maxpix)
                {
                mbox = data // "[" // int(xbox_min) // ":" // int(xbox_max) // "," // int(ybox_min) // ":" // int(ybox_max) \
// "]"
                imstat(mbox, fields="stddev", lower=INDEF, upper=INDEF, binwidth=0.1, format=no, >> "testfile2")
                if (fscan (hallo, stddev_tmp) != EOF) stddev = real (stddev_tmp)
                result = distance // "_____" // stddev
                print (distance // "_____" // stddev)
                print (result, >> "dynamic_result")
                }
#       print (distance)
        }
}

end


sorry for the chaos in the code... this one is for testing some stuff before the beginning of the real work 8)

Greetings
christian

Mike Fitzpatrick wrote on Apr 25, 2008

Sorry, but I was able to run the script with some made up values and I didn't
see the problem, and there's nothing obviously wrong in reading the script. I do wonder why you declare e.g. 'peak' to be a struct and then convert it to a real instead of reading into the real variable directly, but that's not the problem.

FWIW, here's the commandline I used:

cl>  test dev$wpix 10 100 100 1 /tmp/hallo 100


where the /tmp/hallo file just contained two lines of some real number.

-Mike

christian wrote on Apr 25, 2008

So this is though.... you get at the end realy a textfile "dynamic_result" where you have just two real numbers separated by "_____" ? And also you get the same output on the terminal ? :shock: ... This is what i'm trying for hours now and it doesn't matter what i plug in as separator of my two real numbers i get just some strange stuff between them...

Any suggestions ?

Greetings
christian

btw...thanks a lot for the fast help and your trouble

Mike Fitzpatrick wrote on Apr 25, 2008

What version of IRAF are you using? I found the following in the changelog after remembering some issue with string concatenation:


pkg/cl/binop.c
        The concat operator could create garbage in the output string when
        the first operand was not a string.  The problem is that the operands
        are popped from the stack in reverse order, but when the first op
        is recast as a string it then gets a string storage area which can
        overwrite the pointer of the second op.  The popop() program comments
        even warn that the string should be used before another pushop() (as
        is done in opcast()) or else the string will be clobbered.  Added code
        to preserve the second string (3/22/04, MJF)


I confirmed that in v2.12 and older systems your script will not run, in the latest v2.14 version it works just fine.

Cheers,
-Mike

christian wrote on Apr 25, 2008

Maybe thats it....i am currently working with version 2.11.3 :!:
I will try my script with the new 2.14 version asap :)

Thanks a lot for your help :!:

christian

Last post on Apr 25, 2008