Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loop problem

Status
Not open for further replies.

AiProgramDo

Programmer
Feb 2, 2011
3
US
I am new to Fortran 90, but have programmed in other languages. I am working on reading data into an array, and have a nested do loop that is acting strangely:

INTEGER (KIND = 4) :: i,j ! Loop counters
INTEGER (KIND = 4) :: k ! Number of pixels
INTEGER (KIND = 2) :: b ! Number of bands
INTEGER (KIND = 2), ALLOCATABLE :: BVVarray :),:) !k,b

!Get input file name, k and b code goes here, and works fine
! k = 1048576, b = 6

ALLOCATE (BVVarray (k,b))
BVVarray = 0

open (unit = 2, file = InputFileName, &
form = "binary", status = "old", action = "read")

ReadBands: do j = 1,b
ReadBVs: do i = 1,k

read (unit = 2) BVVarray (i,j)

ENDDO ReadBVs
ENDDO ReadBands

When I execute this code, j gets assigned -872415231. I don't get it! Any suggestions?

I have been able to make this code work with i as the outside loop, however, it does not read the file in the order I need it to. I need to read b sets of k, not k sets of b.

Thanks!
 
I got my program to work, but I don't understand why. The following line was just before the loops in my program:

PRINT *, "Reading input file into memory..."

When I commented it out, the loops ran like a charm. What happened there???
 
Uncomment k and b initialization, huh?...
 
That was only commented out in my note to the forum. I actually take in k and b from user input, and was just noting their values in the code I posted in case that was part of the problem. Thanks, though.

I did get everything to work though...see my note dated 2 Feb 11 if you want to let me know why taking out a print statement helped my program to run...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top