NTC0394
Programmer
- Jun 19, 2013
- 21
I would like to modify the following program to fill the matriz on a sub-routine. But I would like to do it most general possible analising the possiblity that the matriz has no the same number of line and columns.
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
PROGRAM matriz_product_dynamic
! Example of dynamic dimensioning
! of bidimensional array
IMPLICIT none
INTEGER, ALLOCATABLE :: matriz ( :, : )
INTEGER :: siz_matriz, line, column
INTEGER :: situation_of_allocation
! Find the wanted size to a matriz
PRINT *, "what is the size of the matriz?"
READ *, siz_matriz
! allocate space enogh of matriz
ALLOCATE ( matriz(siz_matriz, &
siz_matriz), &
stat=situation_of_allocation )
! Variry if the space was allocated
IF(situation_of_allocation==0) THEN
! Fill the matriz
col: DO column = 1, siz_matriz
lin: DO line = 1, siz_matriz
matriz(line, column) = &
line * column
END DO lin
END DO col
! print in matriz one line at each time
DO line = 1, siz_matriz
PRINT *, (matriz( line, column ), &
column = 1, siz_matriz )
END DO
! release the memory when no longer necessary
DEALLOCATE ( matriz )
ELSE
PRINT *, " it was no possible allocate the memory for matriz "
END IF
END PROGRAM matriz_product_dynamic