# Help in fortran

• Fortran

## Main Question or Discussion Point

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

## Answers and Replies

Related Programming and Computer Science News on Phys.org
Mark44
Mentor
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.