-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the VecIntAndReal example for v2
- Loading branch information
1 parent
8051e70
commit 3a97f72
Showing
2 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
cmake_minimum_required(VERSION 3.0) | ||
|
||
project(VectorExamples Fortran) | ||
|
||
find_package(GFTL REQUIRED) | ||
|
||
add_executable(VecIntAndReal.x VecIntAndReal.F90) | ||
#add_executable(VecMyType.x VecMyType.F90) | ||
#add_executable(VecMyPolyPtr.x VecMyPolyPtr.F90) | ||
|
||
target_link_libraries(VecIntAndReal.x GFTL::gftl-v2) | ||
#target_link_libraries(VecMyType.x GFTL::gftl-v2) | ||
#target_link_libraries(VecMyPolyPtr.x GFTL::gftl-v2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
! This is an example for integer and real vector. | ||
! It can be changed to any intrinsic type easliy. | ||
! 1) create a module for each type | ||
! 2) use alias when using different vector types | ||
|
||
module IntegerVec_mod | ||
#define T integer | ||
#define Vector VectorInt | ||
#define VectorIterator VectorIntIterator | ||
#include "vector/template.inc" | ||
#undef T | ||
#undef Vector | ||
#undef VectorIterator | ||
end module IntegerVec_mod | ||
|
||
module Real64Vec_mod | ||
use, intrinsic :: iso_fortran_env | ||
|
||
#define T real | ||
#define T_KINDLEN(context) (kind=real64) | ||
#include "vector/template.inc" | ||
#undef T | ||
#undef T_KINDLEN | ||
end module Real64Vec_mod | ||
|
||
module Real32Vec_mod | ||
use, intrinsic :: iso_fortran_env | ||
|
||
#define T real | ||
#define T_KINDLEN(context) (kind=real32) | ||
#include "vector/template.inc" | ||
#undef T | ||
#undef T_KINDLEN | ||
end module Real32Vec_mod | ||
|
||
program main | ||
|
||
use IntegerVec_mod | ||
use Real64Vec_mod,only :VectorReal64=>Vector | ||
use, intrinsic :: iso_fortran_env | ||
|
||
implicit none | ||
type (VectorInt) :: iv | ||
type (VectorReal64) :: rv | ||
real(real64) :: r | ||
|
||
iv=VectorInt() | ||
rv=VectorReal64() | ||
|
||
r = 1.0d0 | ||
call iv%push_back(1) | ||
call rv%push_back(r) | ||
call check(iv,1) | ||
call checkr(rv,r) | ||
contains | ||
|
||
subroutine check(iv, expected) | ||
type(VectorInt), intent(in) :: iv | ||
integer, intent(in) :: expected | ||
|
||
print*,"iv%at('",1,"') = ",iv%at(1),"(should be",expected,")" | ||
end subroutine check | ||
|
||
subroutine checkr(rv, expected) | ||
type(VectorReal64), intent(in) :: rv | ||
real(real64), intent(in) :: expected | ||
|
||
print*,"rv%at('",1,"') = ",rv%at(1),"(should be",expected,")" | ||
end subroutine checkr | ||
end program main | ||
|