Problem with "Index out of range" error.

Hello,

I am trying to create a code that firstly creates a dataset that simulates a radar measurements of a cloud in the atmosphere. Then I want to convert it into data with real height and range. However, this is not the problem. I get an "Index out of range" error for the RealCloud wave. When I debug me code it seems that it stucks in the RealCloudConv function, and it doesn't return the value into RCloud in fake2real function. Could anyone help me please?

This is my whole code (there are 4 different functions. The first is the basic. The two last are secondary functions and there is no problem with them. The problem in the last command of the first function or somewhere in the second function.

Function Fake2Real(HoRes,VeRes) // Calculates real height and real range of radar values in two different matrices

variable HoRes,VeRes

variable Perimeter, RadiusOfRange, RangeColumns, i, j, HeightRaws, Rad, EarthRadius, a, b, c, d

variable  RealHeightMax, RealRangeMax

make/O/N=(60/VeRes,200/HoRes) RealRange

make/O/N=(60/VeRes,200/HoRes) RealHeight

make/O/N=(60/VeRes,200/HoRes) cloud=0

wave cloud20

LoadWave/J/D/O/M/W/K=0/N=cloud2 "\\\\nask.man.ac.uk\\home$:Desktop:FakeCloud.csv"

RangeColumns = 200/HoRes  //200 is the total range of the radar

HeightRaws = 60/VeRes

Perimeter=44050

EarthRadius = 6371

Rad=Deg2Rad(VeRes)

    For (i=0; i<RangeColumns; i+=1)
       
        For (j=0; j<HeightRaws; j+=1)

        RadiusOfRange = ((i+1)*HoRes*360)/Perimeter

        RealRange[j][i]= (RadiusOfRange*2*pi*6371)/360
       
        RealHeight[j][i]= ((RealRange[j][i])*sin(Rad))+((RealRange[j][i]^2)/(2*EarthRadius))*(HeightRaws-j)
           
        EndFor
    EndFor
   
   
RealRangeMax=round(Maximum(HeightRaws,RangeColumns,RealRange))

RealHeightMax=round(Maximum(HeightRaws,RangeColumns,RealHeight))

Make/O/N=(RealHeightMax, RealRangeMax) RCloud=0

RCloud=RealCloudConv(cloud20, RealRange, RealHeight, VeRes, HoRes, RealHeightMax, RealRangeMax)


End

//-------------------------------------------------------------------------------------------------------------------------//3

Function RealCloudConv(cloud1, RealRange1, RealHeight1, VeRes1, HoRes1, RealHeightMax1, RealRangeMax1)

wave cloud1, RealRange1, RealHeight1

variable VeRes1, HoRes1, RealHeightMax1, RealRangeMax1

variable i, j, raws, columns, col, raw, realcols, RealRangeMax, RealHeightMax

raws=dimsize(cloud1,0)
columns=dimsize(cloud1,1)

make/O/N=(RealHeightMax1, RealRangeMax1) RealCloud=0 //60/VeRes1,200/HoRes1

    For (i=0; i<raws; i+=1)
       
        For (j=0; j<columns; j+=1)
       
            col=round(RealRange1[i][j])
            raw=round(RealHeight1[i][j])
       
            RealCloud[raw][col] = cloud1[i][j]     
       
        EndFor 
   
    EndFor
   
return RealCloud
   
End


//--------------------------------------------------------------------------------------------------------------------------//
//SECONDARY FUNCTIONS//
//--------------------------------------------------------------------------------------------------------------------------//

Function Maximum(raws1,columns1,matrix)

wave matrix

variable raws1,columns1

variable max1, i, j

max1=0

for (i=0; i<raws1; i+=1)
    for(j=0; j<columns1; j+=1)
        if (matrix[i][j]>max1)
            max1=matrix[i][j]
        endif
    endfor
endfor

return max1

end

//------------------------------------------------------------------------------------------------------------------------//

Function Deg2Rad(VRes)   //Converts degrees to radians

variable VRes

variable radians

radians=VRes*0.005555556*pi

return radians

End

Could you maybe use the igor tags and cut the line length to 120 character?
This will make the code much easier to read.

One mistake is that RealCloudConv returns a wave but declares the return type to be a variable.
Hello and thank you for your reply. I got it. You mean Function/wave.

Thanks a lot.
Functions return a numeric variable unless otherwise specified. Have a look at
displayhelptopic "Function"

Igor tags are "igor" and "/igor" each enclosed in "<" and ">".
HJ