This is an example of how an exception can caught with the matrix module. More details about this example.
00001 00014 program matrix_exception 00015 #include "fml_constants.h" 00016 use mod_matrix ! use matrix module 00017 implicit none 00018 00019 !********************************************* declaration 00020 integer, parameter :: m1_rows = 6, m1_cols = 4 !size of m1 00021 integer, parameter :: m2_rows = 4, m2_cols = 5 !size of m1 00022 ! declaration of matrix m1 00023 type(matrix) :: m1; 00024 ! declaration of matrix m2 00025 type(matrix) :: m2; 00026 ! declaration of matrix m_res 00027 type(matrix) :: m_res; 00028 !********************************************* body 00029 00030 ! init of a matrix m1 00031 call init(m1,m1_rows,m1_cols); !init:=m_init 00032 ! init of a matrix m2 00033 call init(m2,m2_rows,m2_cols); !init:=m_init 00034 00035 !initialize m1 by random values between 1.0 and 10.0 00036 !p_notcast is defined on fml_constants.h 00037 call random(m1,low=p_notcast(1.0),high=p_notcast(10.0)) !random:=mc_random 00038 00039 print*, "********************************************* try to addition m1+m2" 00040 m_res=m1+m2 !must throw an exception because m1%size != m2%size 00041 00042 call destruct(m1) ! destruct the matrix m1 (don't forget to destruct the matrix) 00043 call destruct(m2) ! destruct the matrix m2 (don't forget to destruct the matrix) 00044 end program matrix_exception