macro array value limit

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

macro array value limit

Michael Doube-2
Dear List,

I've encountered a strange behaviour in a macro I'm writing.

I want to parse a comma-separated list of values and plot them in an
image. To scale the plot, I have to find the maximum value.  So, I've
pushed the value into an array, and while doing so done an if loop to
reassign a 'max' value to the new, bigger value.

What happens is that in the if loop, values bigger than 9.99 and 9999
are ignored. The arrays do contain bigger values, but somehow they are
excluded from the 'if'. I can print out values bigger than 9.99 and 9999
(if I simply print the arrays as soon as they are parsed). This means
that when the true maximum of the array should be 11.38 (for example),
if I print my max (from the if loop) it is reported as 9.99.

ImageJ version 1.37r, Java 1.3.1_13, WinXP


Mike

----------
//Open the array file which must be a csv list in (angle, value \n) format
string = File.openAsString("");

//Split the CSV file into an array of lines
lines = split(string, "\n");

//initialise some variables
theta = newArray(lengthOf(lines));
r = newArray(lengthOf(lines));
rmax = 0;

//Put the csv into 2 arrays
//Find the maximum radius (to determine the outer boundary)
for (n=0; n<lengthOf(lines); n++){
    thetar= split(lines[n], "\,");
    theta[n] = thetar[0];
    r[n] = thetar[1];

//check that the csv has been parsed properly
    print(theta[n],r[n]);

//find the maximum value of r
    if (r[n] > rmax){
        rmax = r[n];
    }
}
print(rmax);

--
Michael Doube  BPhil BVSc MRCVS
PhD Student
Dental Institute
Queen Mary, University of London
New Rd
London  E1 1BB
United Kingdom

Phone +44 (0)20 7377 7000 ext 2681
Reply | Threaded
Open this post in threaded view
|

Re: macro array value limit

Gabriel Landini
On Thursday 26 October 2006 16:08, Michael Doube wrote:
> What happens is that in the if loop, values bigger than 9.99 and 9999
> are ignored. The arrays do contain bigger values, but somehow they are
> excluded from the 'if'. I can print out values bigger than 9.99 and 9999
> (if I simply print the arrays as soon as they are parsed). This means
> that when the true maximum of the array should be 11.38 (for example),
> if I print my max (from the if loop) it is reported as 9.99.
>
> ImageJ version 1.37r, Java 1.3.1_13, WinXP

Did try this on the latest version of IJ (which is 1.37u)?

Another suggestion is to make sure that the splitting is parsed from string
into a number correctly by using any of these macro functions:

parseFloat(string)
parseInt(string)
parseInt(string, radix)

Cheers,

G.
Reply | Threaded
Open this post in threaded view
|

Re: macro array value limit

Michael Doube-2
Hi Gabriel,

Yes, using parseFloat(string) fixed the problem.

Cheers,

Mike

Gabriel Landini wrote:

> On Thursday 26 October 2006 16:08, Michael Doube wrote:
>  
>> What happens is that in the if loop, values bigger than 9.99 and 9999
>> are ignored. The arrays do contain bigger values, but somehow they are
>> excluded from the 'if'. I can print out values bigger than 9.99 and 9999
>> (if I simply print the arrays as soon as they are parsed). This means
>> that when the true maximum of the array should be 11.38 (for example),
>> if I print my max (from the if loop) it is reported as 9.99.
>>
>> ImageJ version 1.37r, Java 1.3.1_13, WinXP
>>    
>
> Did try this on the latest version of IJ (which is 1.37u)?
>
> Another suggestion is to make sure that the splitting is parsed from string
> into a number correctly by using any of these macro functions:
>
> parseFloat(string)
> parseInt(string)
> parseInt(string, radix)
>
> Cheers,
>
> G.
>  

--
Michael Doube  BPhil BVSc MRCVS
PhD Student
Dental Institute
Queen Mary, University of London
New Rd
London  E1 1BB
United Kingdom

Phone +44 (0)20 7377 7000 ext 2681