Hi everyone(adsbygoogle = window.adsbygoogle || []).push({});

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

**Physics Forums - The Fusion of Science and Community**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# FORTRAN 90 help- matrix-mul-add- input from user defined file name

Loading...

Similar Threads - FORTRAN help matrix | Date |
---|---|

Help identify this label (electrical/nuclear engineering equipment) | Feb 17, 2018 |

Fortran alternative to Matlab 'system' command | Jun 8, 2012 |

RFAC in Fortran | Feb 9, 2012 |

Strange indexing in Fortran Code | Feb 7, 2012 |

Fortran coding do loop | Sep 5, 2011 |

**Physics Forums - The Fusion of Science and Community**