25.06.2013 Views

Il Linguaggio Fortran 90/95

Il Linguaggio Fortran 90/95

Il Linguaggio Fortran 90/95

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

7.4 Allocazione dinamica della memoria con i puntatori 371<br />

TYPE(matrix) :: scale<br />

scale%row = A%row<br />

scale%col = A%col<br />

ALLOCATE(scale%array(A%row,A%col))<br />

scale%array = c*A%array<br />

END FUNCTION scale<br />

SUBROUTINE setm(row,column,array,A)<br />

TYPE(matrix), INTENT(OUT) :: A<br />

INTEGER, INTENT(IN) :: row, column<br />

REAL, DIMENSION(:,:), INTENT(IN) :: array<br />

A%row = row<br />

A%col = column<br />

ALLOCATE(A%array(A%row,A%col))<br />

A%array = array<br />

END SUBROUTINE setm<br />

SUBROUTINE remove(A)<br />

TYPE(matrix), INTENT(INOUT) :: A<br />

DEALLOCATE(A%array)<br />

END SUBROUTINE remove<br />

SUBROUTINE printm(A)<br />

TYPE(matrix), INTENT(IN) :: A<br />

INTEGER :: i, j<br />

DO i = 1,A%row<br />

PRINT*, (A%array(i,j), j=1,A%col)<br />

END DO<br />

END SUBROUTINE printm<br />

END MODULE matrici<br />

Naturalmente è possibile estendere questo modulo al fine di prevedere altre operazioni come<br />

il calcolo della trasposta, dell’inversa oppure del determinante. A tal fine si può fare uso, con<br />

lievi modifiche, di alcune procedure già riportate nei capitoli precedenti. Un programma utile<br />

a testare il modulo precedente potrebbe essere il seguente:<br />

PROGRAM test<br />

USE matrici<br />

IMPLICIT NONE<br />

TYPE(matrix) :: A, B, C<br />

REAL, DIMENSION(2,4) :: tmp<br />

tmp(1,:) = (/1.0, 2.0, 3.0, 4.0 /)<br />

tmp(2,:) = (/5.0, 6.0, 7.0, 8.0 /)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!