This is an example of how to use basic manipulate function of the vector module. More details about this example.
00001 00014 program vector_manip 00015 00016 use mod_vector ! use vector module 00017 #include "fml_constants.h" 00018 implicit none 00019 !********************************************* declaration 00020 integer, parameter :: v1_size = 6 !size of v1 00021 integer, parameter :: v2_size = 6 !size of v1 00022 integer :: i 00023 ! declaration of vector v1 00024 type(vector) :: v1; 00025 ! declaration of vector v2 00026 type(vector) :: v2; 00027 ! declaration of vector v_res 00028 type(vector) :: v_res; 00029 00030 !********************************************* body 00031 !indication: p_notcast is defined in fml_constants.h (adapt the format) 00032 ! init of a vector v1 00033 call init(v1,v1_size); !init:=v_init 00034 ! init of a vector v2 00035 call init(v2,v2_size); !init:=v_init 00036 00037 !initialize v1 by random values between 1.0 and 10.0 00038 call random(v1,low=p_notcast(1.0),high=p_notcast(10.0)) !random:=vc_random 00039 !initialize v2 00040 do i=1,v2_size 00041 call set(v2, i, p_notcast(i**2)); !v2(i)=i^2 (set:=v_set) 00042 end do 00043 00044 print*, "********************************************* display initial data" 00045 print*; !newline 00046 write(*,fmt='(A3)',advance='no')"v1="; !(advance='no' => without newline line) 00047 call print(v1); !print v1 (print:=v_print) 00048 write(*,fmt='(A3)',advance='no')"v2="; !(advance='no' => without newline line) 00049 call print(v2); !print v2 (print:=v_print) 00050 00051 print*, "********************************************* basic functions" 00052 00053 print*, ">>>>>>>>>>>>>nb negative value of v1: =", v_nbnegative(v1); !get:=v_get 00054 print*, ">>>>>>>>>>>>>new nb positive value of v1: =", v_nbpositive(v1); !get:=v_get 00055 call set(v1,1,-get(v1,1)) ! v1(1)=-v1(1) (set:=v_set, get:=v_get) 00056 write(*,fmt='(A9)',advance='no')"* new v1="; !(advance='no' => without newline line) 00057 call print(v1); !print v1 (print:=v_print) 00058 print*, ">>>>>>>>>>>>>get value: v1(3)=", get(v1,3); !get:=v_get 00059 print*, ">>>>>>>>>>>>>new nb negative value of v1: =", v_nbnegative(v1); !get:=v_get 00060 print*, ">>>>>>>>>>>>>new nb positive value of v1: =", v_nbpositive(v1); !get:=v_get 00061 print*, ">>>>>>>>>>>>>new nb positive value of v1: =", v_nbpositive(v1); !get:=v_get 00062 print*, ">>>>>>>>>>>>>nb nil value of v1: =", v_nbzeros(v1); 00063 print*, ">>>>>>>>>>>>>nb nil value of v1: =", v_nbzeros(v1); 00064 print*, ">>>>>>>>>>>>>min value of v1: =", min(v1); !min:=v_min 00065 print*, ">>>>>>>>>>>>>max value of v1: =", max(v1); !max:=v_max 00066 print*, ">>>>>>>>>>>>>min value of v2: =", min(v2); !min:=v_min 00067 print*, ">>>>>>>>>>>>>max value of v2: =", max(v2); !max:=v_max 00068 00069 print*, "********************************************* vector mathematics proprieties" 00070 print*, ">>>>>>>>>>>>>norm 2 of v1: =", .norm.v1; !or norm(v1), norm(v1,2) 00071 print*, ">>>>>>>>>>>>>norm 2 of v2: =", norm(v2,2); !norm:=v_norm 00072 print*, ">>>>>>>>>>>>>norm 10 of v2: =", norm(v2,type_norm=10); !norm:=v_norm 00073 print*, ">>>>>>>>>>>>>norm infty of v1: =", norm(v2,infty); !norm:=v_norm 00074 print*; 00075 print*, ">>>>>>>>>>>>>v1 dot v2 : =", v1.dot.v2 ! or dot(v1,v2) dot:=v_dot 00076 print*; 00077 print*, ">>>>>>>>>>>>>v1 - v2 : ="; 00078 v_res=v1-v2 ! or v_minus(v1,v2) 00079 call print(v_res); 00080 print*, ">>>>>>>>>>>>>v1 + v2 : ="; 00081 v_res=v1+v2 ! or v_add(v1,v2) 00082 call print(v_res); 00083 print*, ">>>>>>>>>>>>>2*v2="; 00084 v_res=p_notcast(2.0)*v2 ! or v_prod_scalar2(2,v2) 00085 call print(v_res); 00086 print*, ">>>>>>>>>>>>>v1*5="; 00087 v_res=v1*p_notcast(5.0) ! or v_prod_scalar1(v1,5) 00088 call print(v_res); 00089 print*, ">>>>>>>>>>>>>v2/10="; 00090 v_res=v1/p_notcast(10.0) ! or v_div_scalar(v2,10) 00091 call print(v_res); 00092 00093 !sauv v2 00094 call print(v2,"vector_v2.dat"); 00095 print*;print*, "... ... ... ... ... ... ... deallocate vector" 00096 call destruct(v1) ! destruct the vector v1 (don't forget to destruct the vector) 00097 call destruct(v2) ! destruct the vector v2 00098 call destruct(v_res) ! destruct the vector v_res 00099 print*; 00100 end program vector_manip