Last active
March 30, 2019 09:41
-
-
Save nilforooshan/2ea207be89dec47bb6c49d6ec517e3a6 to your computer and use it in GitHub Desktop.
f90: Lazy to check whether your matrix is symetric or not! Try this program. The program will tell you where the matrix is asymetric. *.exe and *.out are the Windows and Linux executables.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| PROGRAM symetric | |
| IMPLICIT NONE | |
| ! Declarations | |
| INTEGER:: i, j, n, check1, check2=0 | |
| REAL,DIMENSION(:,:),ALLOCATABLE:: x | |
| CHARACTER(20):: input, exiit | |
| ! Opening prints | |
| PRINT*, | |
| PRINT*, | |
| PRINT*, 'This program is written by Mohammad A. Nilforooshan.' | |
| PRINT*, 'All rights reserved.' | |
| PRINT*, 'http://sites.google.com/site/mannprofile/' | |
| ! ASK for the input file, open and check it | |
| PRINT*, | |
| PRINT*, | |
| PRINT*, 'Type the name of the input file.' | |
| READ*, input | |
| OPEN(UNIT=10, FILE=input, STATUS='OLD', IOSTAT=check1) | |
| IF (check1/=0) THEN | |
| PRINT*, | |
| PRINT*, | |
| PRINT*, 'Error reading the input file' | |
| STOP | |
| END IF | |
| ! Ask for the size of the matrix | |
| PRINT*, | |
| PRINT*, | |
| PRINT*, 'Insert the size of the square matrix.' | |
| READ*, n | |
| ! Read the matrix | |
| ALLOCATE(x(n,n)) | |
| READ(10,*) ((x(i,j),j=1,n),i=1,n) | |
| ! Check where the matrix is asymetric | |
| PRINT*, | |
| DO i=1,n-1 | |
| j=i+1 | |
| IF (x(i,j)/=x(j,i)) THEN | |
| PRINT*, 'See (',i,',',j,'),(',j,',',i,')' | |
| check2=check2+1 | |
| END IF | |
| END DO | |
| ! Final report | |
| PRINT*, | |
| IF (check2==0) THEN | |
| PRINT*, 'The matric is symetric.' | |
| ELSE | |
| PRINT*, 'The matrix is asymetric.' | |
| END IF | |
| ! Finished | |
| PRINT*, | |
| PRINT*, | |
| PRINT*, 'Press any key to exit.' | |
| READ*, exiit | |
| IF (exiit=='a') THEN | |
| GO TO 77 | |
| END IF | |
| 77 END PROGRAM symetric |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment