Last active
March 30, 2019 10:09
-
-
Save nilforooshan/2b7480c4e1de37c43343a59276e78627 to your computer and use it in GitHub Desktop.
f90: Calculate Hadamard transform of two matrices. *.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 hadamard | |
| IMPLICIT NONE | |
| ! Declarations | |
| INTEGER:: i, j, m, n, err10, err11 | |
| REAL,DIMENSION(:,:),ALLOCATABLE:: a, b, c | |
| CHARACTER(20):: infile1, infile2, outfile, 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 files, open and check them | |
| PRINT*, | |
| PRINT*, | |
| PRINT*, 'Type the name of the first input file.' | |
| READ*, infile1 | |
| OPEN(UNIT=10, FILE=infile1, STATUS='OLD', IOSTAT=err10) | |
| IF (err10/=0) THEN | |
| PRINT*, | |
| PRINT*, | |
| PRINT*, 'Error reading the input file' | |
| STOP | |
| END IF | |
| PRINT*, | |
| PRINT*, | |
| PRINT*, 'Type the name of the second input file.' | |
| READ*, infile2 | |
| OPEN(UNIT=11, FILE=infile2, STATUS='OLD', IOSTAT=err11) | |
| IF (err11/=0) THEN | |
| PRINT*, | |
| PRINT*, | |
| PRINT*, 'Error reading the input file' | |
| STOP | |
| END IF | |
| ! Ask for the size of the matrices | |
| PRINT*, | |
| PRINT*, | |
| PRINT*, 'Insert the number of rows.' | |
| READ*, m | |
| PRINT*, 'Insert the number of columns.' | |
| READ*, n | |
| IF (n>40) THEN | |
| PRINT*, | |
| PRINT*, | |
| PRINT*, 'Sorry, up to 40 columns is supprted!' | |
| PRINT*, 'Contact the programmer to get space for more columns.' | |
| STOP | |
| END IF | |
| ! Read the first matrix | |
| ALLOCATE(a(m,n)) | |
| READ(10,*) ((a(i,j),j=1,n),i=1,m) | |
| ! Read the second matrix | |
| ALLOCATE(b(m,n)) | |
| READ(11,*) ((b(i,j),j=1,n),i=1,m) | |
| ! Generate the third matrix | |
| ALLOCATE(c(m,n)) | |
| DO i=1,m | |
| DO j=1,n | |
| c(i,j)=a(i,j)*b(i,j) | |
| END DO | |
| END DO | |
| ! Ask for the name of the output file | |
| PRINT*, | |
| PRINT*, | |
| PRINT*, 'Type the name of the output file.' | |
| READ*, outfile | |
| ! Write in the output file | |
| OPEN(UNIT=12, FILE=outfile, STATUS='UNKNOWN') | |
| DO i=1,m | |
| WRITE(12,'(40F12.4)') (c(i,j), j=1,n) | |
| END DO | |
| ! Finished | |
| PRINT*, | |
| PRINT*, | |
| PRINT*, 'Press any key to exit.' | |
| READ*, exiit | |
| IF (exiit=='a') THEN | |
| GO TO 109 | |
| END IF | |
| 109 END PROGRAM hadamard |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment