- #1

- 3

- 0

## Main Question or Discussion Point

Hi everyone

I am completely new to the Fortran. I have to make a program in fortran 90 to either add or multiply the matrix on user demand and ask user to enter the file name inorder to read the desired matrices.

I came up with the the following code which does not read the program and produces runtime error before the open statement.

And i am gonna make subroutines for each case(add and multiply)

Can anyone help me identify the right way of making the source code in order to read the user defined input from input file and put the matrix on tothe screen as it is defined in the input file.

Following the formatting to input matrix

rowsa, colsa

2, 5, 6

8, 9, 7

Also fortran only does 10 * 10 matrix so how do i make sure it reads every entry of the program properly.

! Ask user for the desired operation

WRITE(*,*) "Enter the desired operation to perform as sum or multiply "

Read (*,*) operation

! Ask user to open file for the first matrix

WRITE(*,*) ""

WRITE(*,*) ""

WRITE(*,*) "Enter file name for the first matrix"

Read (*,*) inputA

OPEN (UNIT=20, file='inputA', STATUS='OLD')

! Read dimension of matrix A

READ (20,*) rowsA,colsA

! Read each matrix(array) elements

Do i= 1,rowsA

Do j=1,colsA

READ (11,*) A

WRITE (*,*) "The first matrix is ",A

End do

End do

close (20)

! Ask user to open file for the Second matrix

WRITE(*,*) ""

WRITE(*,*) ""

WRITE(*,*) "Enter file name for the second matrix"

Read (*,*) inputB

OPEN (UNIT=30, file='inputB', STATUS='OLD')

! Read dimension of matrix A

READ (30,*) rowsB,colsB

! Read each matrix(array) elements

Do i= 1,rowsB

Do j=1,colsB

READ (30,*) B

WRITE (*,*) "The second matrix is ",B

End do

End do

close (30)

END PROGRAM MAT_add_multiply

Thanks very much.

Muzzy

I am completely new to the Fortran. I have to make a program in fortran 90 to either add or multiply the matrix on user demand and ask user to enter the file name inorder to read the desired matrices.

I came up with the the following code which does not read the program and produces runtime error before the open statement.

And i am gonna make subroutines for each case(add and multiply)

Can anyone help me identify the right way of making the source code in order to read the user defined input from input file and put the matrix on tothe screen as it is defined in the input file.

Following the formatting to input matrix

rowsa, colsa

2, 5, 6

8, 9, 7

Also fortran only does 10 * 10 matrix so how do i make sure it reads every entry of the program properly.

! Ask user for the desired operation

WRITE(*,*) "Enter the desired operation to perform as sum or multiply "

Read (*,*) operation

! Ask user to open file for the first matrix

WRITE(*,*) ""

WRITE(*,*) ""

WRITE(*,*) "Enter file name for the first matrix"

Read (*,*) inputA

OPEN (UNIT=20, file='inputA', STATUS='OLD')

! Read dimension of matrix A

READ (20,*) rowsA,colsA

! Read each matrix(array) elements

Do i= 1,rowsA

Do j=1,colsA

READ (11,*) A

WRITE (*,*) "The first matrix is ",A

End do

End do

close (20)

! Ask user to open file for the Second matrix

WRITE(*,*) ""

WRITE(*,*) ""

WRITE(*,*) "Enter file name for the second matrix"

Read (*,*) inputB

OPEN (UNIT=30, file='inputB', STATUS='OLD')

! Read dimension of matrix A

READ (30,*) rowsB,colsB

! Read each matrix(array) elements

Do i= 1,rowsB

Do j=1,colsB

READ (30,*) B

WRITE (*,*) "The second matrix is ",B

End do

End do

close (30)

END PROGRAM MAT_add_multiply

Thanks very much.

Muzzy