[UP]


Manual Reference Pages  - list_init (3)

NAME

list_init(3f) - [M_generic_list] Initialize a head node SELF and optionally store the provided DATA. (LICENSE:MIT)

CONTENTS

Synopsis
Description
Author
See Also
Example

SYNOPSIS

subroutine list_init(self, data)

    type(list_node_t), pointer :: self
    integer, dimension(:), intent(in), optional :: data

DESCRIPTION

Initialize a head node SELF and optionally store the provided DATA.

AUTHOR

Fortran 95 Implementation by:

    JASON R. BLEVINS
    Department of Economics, Duke University
    May 18,2009

SEE ALSO

M_generic_list(3fm), list_free(3f) list_insert(3f), list_put(3f), list_get(3f), list_next(3f)

EXAMPLE

Sample program:

     ! program demo_list_init and module
     module data
       implicit none

private public :: data_t public :: data_ptr

! Data is stored in data_t type :: data_t real :: x end type data_t

! A container for storing data_t pointers type :: data_ptr type(data_t), pointer :: p end type data_ptr

end module data

program demo_list_init use M_generic_list use data implicit none type(list_node_t), pointer :: list => null() type(data_ptr) :: ptr ! Allocate a new data element allocate(ptr%p) ptr%p%x = 2.7183 ! Initialize the list with the first data element call list_init(list, transfer(ptr, list_data)) print *, ’Initializing list with data:’ , ptr%p ! Allocate a second data element allocate(ptr%p) ptr%p%x = 0.5772 ! Insert the second into the list call list_insert(list, transfer(ptr, list_data)) print *, ’Inserting node with data:’ , ptr%p ! Retrieve data from the second node and free memory ptr = transfer(list_get(list_next(list)), ptr) print *, ’Second node data:’ , ptr%p deallocate(ptr%p) ! Retrieve data from the head node and free memory ptr = transfer(list_get(list), ptr) print *, ’Head node data:’ , ptr%p deallocate(ptr%p) ! Free the list call list_free(list) end program demo_list_init

The test program produces the following output:

    Initializing list with data:    2.7183001
    Inserting node with data: 0.57720000
    Second node data: 0.57720000
    Head node data:   2.7183001


list_init (3) October 17, 2020
Generated by manServer 1.08 from 45528ea9-a3c3-41c1-bd86-b32287ea829e using man macros.