like abstract class to use character lists in fortran 2003 (gnu gcc 4.8 do not work with character(len=:).
program example_list
implicit none
type(integerlist) :: list_int
type(reallist) :: list_real
type(characterlist) :: list_char
type(mixlist) :: list_mix
class(*),pointer :: val
integer values(10)
integer i,n
type mytype
integer :: i
real :: r
end type mytype
type(mytype) :: ir=mytype(3,6.)
type charmylen
character(len=10) :: char10
end type charmylen
type(charmylen) :: mychar
print *,"display real list"
call list_char%append("hello world")
call list_char%append("bye bye baby")
print *,"display char list"
call list_char%display()
do i=1, 10
call list_int%append(i)
enddo
print *,"display integer list"
call list_int%display()
print *
call list_int%rewind()
i = 1
do while(list_int%element())
values(i) = list_int%current()
call list_int%next()
i = i + 1
end do
print *,"display integer vector from list"
print *, values
values =list_int%toarray()
print *,"display integer vector from list with toarray"
print *, values
call list_int%forward()
i = 1
do while(list_int%element())
values(i) = list_int%current()
call list_int%prev()
i = i + 1
end do
print *,"display inverse integer vector from list"
print *, values
print *,"seek return status =", list_int%seek(3)
print *,"list index 3 =", list_int%current()
print *,"delete(5) return status =", list_int%delete(5)
print *,"display integer vector with 5 removed"
call list_int%display()
print *,"display reverse integer vector with 5 removed"
call list_int%forward()
do while(list_int%element())
print*, "index:",list_int%currentindex()," value:",list_int%current()
call list_int%prev()
end do
print *,"delete(1) return status =", list_int%delete(1)
print *,"display integer vector with 1 removed"
call list_int%display()
n=list_int%countelements()
print *,"number of list elements=",n
print *,"delete(",n,")"
print *,"return status =", list_int%delete(n)
print *,"display integer vector with last removed"
call list_int%display()
print *,"delete return status =", list_int%delete()
print *,"display integer vector with everithings removed"
call list_int%display()
do i=1, 10
enddo
mychar%char10="ciao ciao"
print *,"display mix list"
print *,"print mix list with cast"
select type (x => val)
type is (integer)
print *,x
type is (real)
print *,x
type is (doubleprecision)
print *,x
type is (integer(kind=int_b))
print *,x
type is (character(*))
print *,x
type is (mytype)
print *,x%i,x%r
type is (charmylen)
print *,x%char10
end select
end do
end program example_list
Definition of constants to be used for declaring variables of a desired type.
class to use character lists in fortran 2003 WARNING !
class to use lists in fortran 2003.
class to use lists in fortran 2003.
class to use lists in fortran 2003.