Help in Fortran: Get Assistance to Solve Integer Overflow Error

  • Context: Fortran 
  • Thread starter Thread starter Davoodk
  • Start date Start date
  • Tags Tags
    Fortran
Click For Summary
SUMMARY

The forum discussion addresses an "integer overflow" error encountered while generating a matrix from a large file in Fortran. The user attempts to read a file with 24,480 rows and 6,828 columns into a defined structure using the program "Matrixgenome." Key issues identified include improper allocation of the "genome" array and confusion regarding the use of the "%" operator for accessing components of user-defined types, which is valid in Fortran 90 and later. Recommendations include correcting the allocation and ensuring proper indexing when assigning values to the "genome" array.

PREREQUISITES
  • Understanding of Fortran programming, specifically Fortran 90 or later.
  • Familiarity with user-defined types and allocation in Fortran.
  • Knowledge of file I/O operations in Fortran.
  • Basic concepts of matrix manipulation and indexing in programming.
NEXT STEPS
  • Review Fortran 90 user-defined types and their usage.
  • Learn about dynamic memory allocation in Fortran, focusing on the ALLOCATABLE attribute.
  • Investigate file I/O best practices in Fortran, particularly for large datasets.
  • Explore debugging techniques for integer overflow errors in Fortran programs.
USEFUL FOR

This discussion is beneficial for Fortran developers, particularly those working with large datasets, as well as educators teaching advanced programming concepts in Fortran.

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.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 4 ·
Replies
4
Views
9K
  • · Replies 10 ·
Replies
10
Views
26K
Replies
12
Views
9K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 9 ·
Replies
9
Views
9K
  • · Replies 11 ·
Replies
11
Views
8K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K