Skip to content

Commit

Permalink
Add the VecIntAndReal example for v2
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilyBourne committed Oct 3, 2024
1 parent 8051e70 commit 3a97f72
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
13 changes: 13 additions & 0 deletions examples/v2/Vector/CMakeLists.txt
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)
71 changes: 71 additions & 0 deletions examples/v2/Vector/VecIntAndReal.F90
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

0 comments on commit 3a97f72

Please sign in to comment.