Help in Fortran: Get Assistance to Solve Integer Overflow Error

  • Fortran
  • Thread starter Davoodk
  • Start date
  • Tags
    Fortran
In summary: You have to decide which one you want...and also, you are accessing the array line(6828) outside its bound. You declared it as line(:).In summary, the conversation is about a person trying to generate a matrix from a large file. They are facing an "integer overflow" error and are looking for help in solving the issue. The code provided has several errors and the person is asking for clarification on the use of the % operator in Fortran.
  • #1
Davoodk
11
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
  • #2
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.
 
  • #3
% 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.
 

What is an integer overflow error in Fortran?

An integer overflow error in Fortran occurs when the result of a calculation exceeds the maximum value that can be stored in an integer variable. This can lead to unexpected and incorrect results in your program.

Why do I need help to solve an integer overflow error in Fortran?

Solving an integer overflow error in Fortran can be challenging and may require advanced knowledge of the language. It may also involve debugging and identifying the specific line of code causing the error. Seeking assistance can save time and ensure a more accurate solution.

How can I prevent integer overflow errors in my Fortran code?

To prevent integer overflow errors in Fortran, you can use larger data types for your variables, such as INTEGER*8 or REAL*8. You can also check the values of your variables before performing calculations to ensure they do not exceed the maximum value.

Are there any tools or resources available to help me with integer overflow errors in Fortran?

Yes, there are various tools and resources available to help with integer overflow errors in Fortran, such as debuggers, online forums, and documentation. You can also seek assistance from other programmers or experts in the language.

Can I use the same approach to solve all integer overflow errors in Fortran?

No, the approach to solving an integer overflow error in Fortran may vary depending on the code and the specific error. It is important to carefully analyze the code and understand the cause of the error before attempting to fix it. Seeking assistance can also help determine the best approach for a particular error.

Similar threads

  • Programming and Computer Science
Replies
4
Views
625
  • Programming and Computer Science
Replies
4
Views
8K
  • Programming and Computer Science
Replies
12
Views
7K
  • Programming and Computer Science
Replies
10
Views
25K
  • Advanced Physics Homework Help
Replies
12
Views
2K
  • Programming and Computer Science
Replies
5
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Programming and Computer Science
Replies
11
Views
7K
  • Programming and Computer Science
Replies
2
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
3K
Back
Top