Fortran Help in Fortran: Get Assistance to Solve Integer Overflow Error

  • Thread starter Thread starter Davoodk
  • Start date Start date
  • Tags Tags
    Fortran
AI Thread Summary
The discussion centers around a Fortran program intended to generate a matrix from a large file containing 24,480 rows and 6,828 columns. The user encounters an "integer overflow" error while trying to read and assign each row as a vector in a matrix. Key points include the use of the % operator, which is valid in Fortran for accessing components of user-defined types, and confusion regarding the declaration of the genome variable both inside the user-defined type and as a standalone variable. Additionally, there are concerns about the overall structure of the program and potential compilation issues. Suggestions for resolving the error and improving the code structure are implied but not extensively detailed.
Davoodk
Messages
11
Reaction score
0
Hi,

i am truing to generate a matrix of my big file in which each line must be assigned as a vector into a matrix. on the other word, i have a big file by 24480 row and 6828 column, so i want to define that each row is been as a vector in a big matrix. using below program i was facing by an error which says "integer overflow".

PROGRAM Matrixgenome

IMPLICIT NONE
INTEGER::OPENSTATUS, j

CHARACTER*10000::row

TYPE anim
INTEGER::animal(10)
INTEGER::id
INTEGER::genome(1,6828)
END TYPE anim

TYPE (anim),ALLOCATABLE::animal(:)
INTEGER,ALLOCATABLE::length(:)
INTEGER,ALLOCATABLE::genome(:,:)
INTEGER,ALLOCATABLE::line(:)

!Allocate(animal(24480)) !for test

OPEN(UNIT=18, FILE="genome.txt", STATUS="OLD", IOSTAT=OPENSTATUS)
IF (OPENSTATUS>0) STOP "***CANNOT OPEN FILE***"




READ(18,fmt='(a6828)') row
length= len_trim(row)



rewind(18)
ALLOCATE(genome(10,6828))
ALLOCATE(line(6828))

DO j=1, 10
READ(18,fmt='(6828i1)') line(:)
!PRINT*, "length of row:", size(line)

animal(j)%id=j
animal(j)%genome(j,1:6828)=line(6828)
PRINT*, animal(j)
PRINT*, '(genome1)', genome(1,1:6828)

PRINT*, "size", size(animal(1)%genome(1,:))
WRITE(*, '(200i1)') animal(j)%genome(1,1:200)
END DO
DEALLOCATE(line)
DEALLOCATE(genome)

END PROGRAM Matrixgenome

So, how can i solve this error.

I am so grateful for any help
 
Technology news on Phys.org
Davoodk said:
Hi,

i am truing to generate a matrix of my big file in which each line must be assigned as a vector into a matrix. on the other word, i have a big file by 24480 row and 6828 column, so i want to define that each row is been as a vector in a big matrix. using below program i was facing by an error which says "integer overflow".

PROGRAM Matrixgenome

IMPLICIT NONE
INTEGER::OPENSTATUS, j

CHARACTER*10000::row

TYPE anim
INTEGER::animal(10)
INTEGER::id
INTEGER::genome(1,6828)
END TYPE anim

TYPE (anim),ALLOCATABLE::animal(:)
INTEGER,ALLOCATABLE::length(:)
INTEGER,ALLOCATABLE::genome(:,:)
INTEGER,ALLOCATABLE::line(:)

!Allocate(animal(24480)) !for test

OPEN(UNIT=18, FILE="genome.txt", STATUS="OLD", IOSTAT=OPENSTATUS)
IF (OPENSTATUS>0) STOP "***CANNOT OPEN FILE***"




READ(18,fmt='(a6828)') row
length= len_trim(row)



rewind(18)
ALLOCATE(genome(10,6828))
ALLOCATE(line(6828))

DO j=1, 10
READ(18,fmt='(6828i1)') line(:)
!PRINT*, "length of row:", size(line)

animal(j)%id=j
animal(j)%genome(j,1:6828)=line(6828)
PRINT*, animal(j)
PRINT*, '(genome1)', genome(1,1:6828)

PRINT*, "size", size(animal(1)%genome(1,:))
WRITE(*, '(200i1)') animal(j)%genome(1,1:200)
END DO
DEALLOCATE(line)
DEALLOCATE(genome)

END PROGRAM Matrixgenome

So, how can i solve this error.

I am so grateful for any help
Does the error provide a line number?

I'm not sure that the following code will compile.
Code:
animal(j)%id=j                    
animal(j)%genome(j,1:6828)=line(6828)
When I was writing Fortran code quite a few years ago, there was no % operator, and I was not able to find any description of it in a quick search I did. Are you using it as the mod operator as in C, C++, and related lanaguages?

I don't know what you're trying to do in the two lines above.
 
% is fine, it is part of fortran since fortran 90...it is used to refer to variables inside user defined types (like C structures, basically).

Other than that...they are so many things wrong with the program...I am just not in the mood to list them all...

Davoodk...you are confusing yourself by declaring genome inside the user defined "animal" type and then outside as a regular variable.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...

Similar threads

Replies
4
Views
8K
Replies
10
Views
25K
Replies
5
Views
3K
Replies
9
Views
9K
Replies
2
Views
4K
Replies
12
Views
2K
Back
Top