This is an example of how to use basic manipulate function of the matrix module. More details about this example.
00001 00014 program matrix_manip 00015 00016 use mod_matrix ! use matrix module 00017 #include "fml_constants.h" 00018 implicit none 00019 !********************************************* declaration 00020 integer, parameter :: m1_rows = 4, m1_cols = 4 !size of m1 00021 integer, parameter :: m2_rows = 4, m2_cols = 5 !size of m1 00022 integer, parameter :: m3_rows = 4, m3_cols = 5 !size of m1 00023 ! declaration of matrix m1 00024 type(matrix) :: m1; 00025 ! declaration of matrix m2 00026 type(matrix) :: m2; 00027 ! declaration of matrix m3 00028 type(matrix) :: m3; 00029 ! declaration of matrix m4 00030 type(matrix) :: m4; 00031 ! declaration of matrix m_res 00032 type(matrix) :: m_res; 00033 00034 !********************************************* body 00035 !indication: p_notcast is defined in fml_constants.h (adapt the format) 00036 ! init of a matrix m3 00037 call init(m3,m3_rows,m3_cols); !init:=m_init 00038 ! init of a matrix m2 00039 call init(m2,m2_rows,m2_cols); !init:=m_init 00040 00041 !initialize m1 by random values between 1.0 and 10.0 00042 call random(m2,low=p_notcast(1.0),high=p_notcast(10.0)) !random:=vc_random 00043 !initialize m3 by random values between 2.0 and 6.0 00044 call random(m3,low=p_notcast(2.0),high=p_notcast(6.0)) !random:=vc_random 00045 00046 m1=m_identity(m1_rows) !identity matrix 00047 m4=mc_diag(vect_data=(/p_notcast(1.0),p_notcast(3.0),p_notcast(4.0),p_notcast(-5.0),p_notcast(8.0)/)) 00048 00049 00050 print*, "********************************************* display initial data" 00051 print*; !newline 00052 00053 print*, "m1="; 00054 call print(m1); !print m1 (print:=m_print) 00055 print*, "m2="; 00056 call print(m2); !print m2 (print:=m_print) 00057 print*, "m3="; 00058 call print(m3); !print m3 (print:=m_print) 00059 print*, "m4="; 00060 call print(m4); !print m4 (print:=m_print) 00061 00062 print*, "********************************************* basic functions" 00063 m_res=p_notcast(2.0)*m2 !multiplication by a scalar 00064 print*, "2*m3="; 00065 call print(m_res) 00066 00067 m_res=m3/p_notcast(2.0) !division by a scalar 00068 print*, "m3/2="; 00069 call print(m_res) 00070 00071 m_res=m2+m3 !addition 00072 print*, "m2+m3="; 00073 call print(m_res) 00074 00075 m_res=m2-m3 !soustraction 00076 print*, "m2-m3="; 00077 call print(m_res) 00078 00079 m_res=m1*m3 00080 print*, "m1*m3="; 00081 call print(m_res) 00082 00083 print*, "********************************************* matrix mathematics proprieties" 00084 print*, "diag(m2)="; 00085 call print(diag(m2)) 00086 print*, "diag(m2,2)="; 00087 call print(diag(m2,2)) 00088 print*, "diag(m2,-2)="; 00089 call print(diag(m2,-2)) 00090 print*, "triu(m2)="; 00091 call print(triu(m2)) !upper triangular matrix of m2 00092 print*, "tril(m2)="; 00093 call print(tril(m2)) !lower triangular matrix of m2 00094 print*, "tril(m2,-1)="; 00095 call print(tril(m2,-1)) !lower triangular matrix of m2 (left translation) 00096 00097 !sauv m2 00098 call print(m2,"matrix_m2.dat"); 00099 print*;print*, "... ... ... ... ... ... ... deallocate matrix" 00100 call destruct(m1) ! destruct the matrix m1 (don't forget to destruct the matrix) 00101 call destruct(m2) ! destruct the matrix m2 00102 call destruct(m3) ! destruct the matrix m3 00103 call destruct(m4) ! destruct the matrix m4 00104 call destruct(m_res) ! destruct the matrix m_res 00105 print*; 00106 end program matrix_manip