comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Another "Array subscript for VECTOR must have same size as source expression." problem
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Another "Array subscript for VECTOR must have same size as source expression." problem [message #88462] Tue, 29 April 2014 11:27 Go to next message
laura.hike is currently offline  laura.hike
Messages: 87
Registered: September 2013
Member
Hi,

I know that the error above indicates that I'm trying to assign something into an array that doesn't fit the array dimensions. However, in this case, the error arises the _second_ time through a loop but not the first. I've tried several things and found that it's not the input data that's the problem, or the reinitialization of the variables. The file read statement also works properly. Any idea what's wrong?

Thanks,

Laura


Notes: bad = -9999.0
The error message is
% Array subscript for PLOTSTATS must have same size as source expression.
% Execution halted at: $MAIN$ 54
where line 54 is plotstats[*,i] = stats[0:4] about half way down in the code below.
stats[6] eq bad will not occur until the second time through the loop, but the error occurs
before that happens. (I checked the values of the read variables.)

;----------------------------------------------------------- --
txt1 = ' ' ; Dummy read variables.
site = ' '
season = ' '
n = 0
;----------------------------------------------------------- --
; Bar and whiskers plots for all sites individually.
nsites = 7
sites = strarr(nsites)
stats = fltarr(7)
seasons = strarr(nsites)
plotstats = fltarr(5,nsites)
means = fltarr(nsites)
npoints = intarr(nsites)

infile = indir + 'site.whiskerplot.stats.3hourly.surfrad.match.snow.LWcorr.so rt.txt'
openr, 3, infile ; Read past header. Number of header lines hard wired.
for i = 0, 4 do begin
readf, 3, txt1
endfor

for j = 0, 1 do begin ; For snow and all conditions.

plotstats[*,*] = bad
means[*] = bad
npoints[*] = 0

for i = 0, nsites-1 do begin

readf, 3, format = '(A7, 7F12.2, I10, A15)', site, stats, n, season
sites[i] = site
seasons[i] = season
npoints[i] = n
means[i] = stats[5]
plotstats[*,i] = stats[0:4]
if (stats[6] eq bad) then begin
plotstats[0,i] = bad ; Make all stat values bad. (This would be 0 otherwise.)
plotstats[4,i] = bad
endif else begin
plotstats[0,i] = means[i] - stats[6] ; Substitute mean+/-std. dev. for max and min.
plotstats[4,i] = means[i] + stats[6]
endelse

endfor

locations = indgen(nsites)+1
; if (j eq 0) then npoints1 = max(npoints)
npoints1 = max(npoints)
xwidth = npoints * 0.3 / npoints1 ; Width proportional to the number of points.
xvals = [-1,nsites+2]
titletext = 'Surface-CERES differences, corrected LW, ' + strtrim(seasons[0],2) + ' samples'
dummy = boxplot(locations, plotstats, mean_values = means, ytitle = 'Irradiance differences [Wm$^{-2}$]',yrange = [-100,80], width=x
width, thick=3, xtickname = ['', strtrim(sites,2), ' '], xtext_orientation=90, xminor = 0, xthick = 2, ythick = 2, title = titletext)
graphic = plot(xvals,yvals,overplot = 1,xrange = [0,nsites+1])

endfor
Re: Another "Array subscript for VECTOR must have same size as source expression." problem [message #88463 is a reply to message #88462] Tue, 29 April 2014 12:17 Go to previous messageGo to next message
wlandsman is currently offline  wlandsman
Messages: 743
Registered: June 2000
Senior Member
On Tuesday, April 29, 2014 2:27:58 PM UTC-4, laura...@gmail.com wrote:


> plotstats = fltarr(5,nsites)

The BOXPLOT documention says that the VALUES parameter should be dimensioned M x 5 -- it looks like you have the transpose

What make the problem hard to diagnose is that the BOXPLOT() function does not play nice with the input parameters


IDL> plotstats = findgen(5,12)
IDL> help,plotstats
PLOTSTATS FLOAT = Array[5, 12]
IDL> saa = boxplot(indgen(12),plotstats)
IDL> help,plotstats
PLOTSTATS FLOAT = Array[12, 5]

So it looks like BOXPLOT has transposed the input data, so the second time through the plotstats variable is dimensioned [12,5] whereas you are assuming that is dimensioned [5,12], giving the array subscript error. --Wayne
Re: Another "Array subscript for VECTOR must have same size as source expression." problem [message #88464 is a reply to message #88463] Tue, 29 April 2014 12:46 Go to previous messageGo to next message
laura.hike is currently offline  laura.hike
Messages: 87
Registered: September 2013
Member
Thanks! I actually did try changing the order of the dimensions in the definition of plotstats once, but I guess I didn't change the assignment statements in the loop. I know that IDL will change the type or size of an array if you assign the wrong things to it, but this is ridiculous behavior on the part of a function/subroutine. It would make a lot more sense for the routine to crash when the wrong inputs are used.
Re: Another "Array subscript for VECTOR must have same size as source expression." problem [message #88465 is a reply to message #88464] Tue, 29 April 2014 15:31 Go to previous message
chris_torrence@NOSPAM is currently offline  chris_torrence@NOSPAM
Messages: 528
Registered: March 2007
Senior Member
On Tuesday, April 29, 2014 1:46:32 PM UTC-6, laura...@gmail.com wrote:
> Thanks! I actually did try changing the order of the dimensions in the definition of plotstats once, but I guess I didn't change the assignment statements in the loop. I know that IDL will change the type or size of an array if you assign the wrong things to it, but this is ridiculous behavior on the part of a function/subroutine. It would make a lot more sense for the routine to crash when the wrong inputs are used.

Hi,
This has been fixed for IDL 8.3.1. BOXPLOT will still be nice and accept your 12x5 array (for backwards compatibility) but it won't mess up your input variable.
Thanks for catching it!
Cheers,
Chris
ExelisVIS
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Smooth and /EDGE_TRUNCATE
Next Topic: How to close 'failed' function graphics windows?

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 11:44:24 PDT 2025

Total time taken to generate the page: 0.00490 seconds