File: VecIntAndReal.F90

package info (click to toggle)
gftl 1.3.0%2Bis-really-1.2.7-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 1,328 kB
  • sloc: pascal: 4,163; f90: 3,551; sh: 27; fortran: 16; makefile: 2
file content (50 lines) | stat: -rw-r--r-- 1,223 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
! 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
#include "types/integer.inc"
#include "templates/vector.inc"
end module IntegerVec_mod

module Real64Vec_mod
#include "types/real64.inc"
#include "templates/vector.inc"
end module Real64Vec_mod

program main

   use IntegerVec_mod,only :VectorInt=>Vector
   use Real64Vec_mod,only :VectorReal64=>Vector
   use 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