Subdomain Posts
Fortran | 12 hours ago
Fortran | 19 hours ago
Fortran | 19 hours ago
Fortran | 22 hours ago
Fortran | 22 hours ago
Fortran | 23 hours ago
Fortran | 23 hours ago
Fortran | 1 day ago
Fortran | 1 day ago
Fortran | 1 day ago
Recent Posts
None | 16 sec ago
None | 48 sec ago
JavaScript | 1 min ago
C | 2 min ago
None | 2 min ago
None | 2 min ago
None | 3 min ago
C | 3 min ago
None | 3 min ago
None | 3 min ago
Sitereport
Find cool info about any domain on the internet?
visit sitereport
Free Subdomains
Want a pastebin.com sub-domain for your community?
learn more...
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
Learn a little bit about the new Pastebin.com on our help page. hide message
By josh on the 22nd of Dec 2009 12:26:14 AM Download | Raw | Embed | Report
  1. !!!     Fortran and my clumsy attempts to manipulate and display matricies, "why?" you ask, because otherwise I would have to actually revise ofc
  2. !!!
  3. program assign_and_print_matrix
  4.  
  5. implicit none
  6.  
  7. INTEGER, PARAMETER                              ::      ISIZE = (3)             !a single variable to define the size of potentially many matricies
  8. integer, DIMENSION(ISIZE,ISIZE) ::      ARRAY1, ARRAY2, ARRAY3, array4, trans_array3
  9. integer                                                 ::      i,j                                                                     !loop variables                                        
  10. integer, dimension(2)                   ::      size_array3, shape_array3
  11.  
  12. !array1 = (/1,2,3/)             !putting in values for a matrix, only valid for 1 dimensional array
  13. !nested do loops required for more than 1 dimension!
  14.  
  15. array1  =       0               !initialise the array to zero is a good practice as it removes any previous array operations done above
  16. array2  =       0
  17.        
  18. 1 format ("row number = ",i2)
  19. 2 format ("collumn number = ",i2)
  20. 3 format ("value of (",i1,i1,") = ",i4)
  21. 4 format (i3,i3,i3)
  22. 5 format (i3," ",i3," ",i3)
  23. 6 format ("The shape is "i2, i2)
  24. 7 format ("The Size is "i2,i2)
  25.  
  26.  
  27. write(*,*) "STARTING ARRAY1!"
  28.  
  29. do      i = 1, 3
  30.         do      j = 1,3
  31.                         array1(i,j) = i                                 !putting a value in each element, elements are assigned down each collumn sequentially.
  32.                         write(*,FMT=3) j,i,array1(i,j)
  33.                         write(*,*) ""
  34.         end do
  35. end do
  36.  
  37. write(*,*) "FINISHED ARRAY1!"
  38.  
  39. do i = 1,3
  40.         do j= 1,3
  41.                 IF (j .eq. 3) write (*,FMT=4,ADVANCE="YES") array1(i,j)
  42.                 IF (j .eq. 3) exit
  43.                 write (*,FMT=4,ADVANCE="NO") array1(i,j)
  44.         end do
  45. end do
  46.  
  47.  
  48. write(*,*) "STARTING ARRAY2!"
  49.  
  50. do      i = 1, 3
  51.         do      j = 1,3
  52.                         array2(i,j) = i*j
  53.                         !write(*,FMT=1) i
  54.                         !write(*,FMT=2) j
  55.                         write(*,FMT=3) j,i,array2(i,j)
  56.                         write(*,*) ""
  57.         end do
  58. end do
  59.  
  60. write(*,*) "FINISHED ARRAY2!"
  61.  
  62.  
  63.  
  64. do i = 1,3
  65.         do j= 1,3
  66.                 IF (j .eq. 3) write (*,FMT=4,ADVANCE="YES") array2(i,j)
  67.                 IF (j .eq. 3) exit
  68.                 write (*,FMT=4,ADVANCE="NO") array2(i,j)
  69.         end do
  70. end do
  71.  
  72.  
  73.  
  74.  
  75. write(*,*) "Multiply the matricies!"
  76.  
  77. array3 = MATMUL(array1, array2)
  78.  
  79. !write out as a matrix
  80. do i = 1,3
  81.         do j= 1,3
  82.                 IF (j .eq. 3) write (*,FMT=4,ADVANCE="YES") array3(i,j)
  83.                 IF (j .eq. 3) exit
  84.                 write (*,FMT=4,ADVANCE="NO") array3(i,j)
  85.         end do
  86. end do
  87.  
  88. write(*,*) ""
  89. write(*,*)"array3's (1,3) has been augmented to 22"
  90. array3(1,3) = 22
  91. write(*,*) array3(1,3)
  92. write(*,*) ""
  93.  
  94. !write out as a matrix
  95. do i = 1,3
  96.         do j= 1,3
  97.                 IF (j .eq. 3) write (*,FMT=4,ADVANCE="YES") array3(i,j)
  98.                 IF (j .eq. 3) exit
  99.                 write (*,FMT=4,ADVANCE="NO") array3(i,j)
  100.         end do
  101. end do
  102.  
  103.  
  104. write(*,*) "some other properties of array3"
  105. shape_array3 = shape(array3)
  106. size_array3 = shape(array3)
  107. !trans_array3 = transpose(array3)
  108.  
  109. write(*,*) ""
  110. write (*,6) shape_array3
  111. write(*,7),size_array3
  112.  
  113. do i = 1,3
  114.         do j= 1,3
  115.                 array4(j,i) = array3(i,j)
  116.                 write(*,*) array4(j,i)
  117.         end do
  118. end do
  119.  
  120.  
  121. write(*,*) "write out transposed matrix notice 22 has moved!"
  122. do i = 1,3
  123.         do j= 1,3
  124.                 IF (j .eq. 3) write (*,FMT=4,ADVANCE="YES") array4(i,j)
  125.                 IF (j .eq. 3) exit
  126.                 write (*,FMT=4,ADVANCE="NO") array4(i,j)
  127.         end do
  128. end do
  129.  
  130.  
  131.  
  132.  
  133. end
Submit a correction or amendment below. Make A New Post
To highlight particular lines, prefix each line with @h@
Syntax highlighting:
Post expiration:
Post exposure:
Name / Title:
Email: