! ! this is used to bind some type-dependent per-instance ! data to type(colvar_t) instances ! ! searches the list function get_priv(cv) result(ptr) NCSU_USE_AFAILED use ncsu_colvar_type implicit none type(colvar_t), intent(in) :: cv type(priv_t), pointer :: ptr ptr => priv_list do while (associated(ptr)) if (ptr%tag.eq.cv%tag) & exit ptr => ptr%next end do ncsu_assert(associated(ptr)) end function get_priv ! allocates and appends to the list function new_priv(cv) result(ptr) use ncsu_utils use ncsu_colvar_type implicit none type(colvar_t), intent(inout) :: cv type(priv_t), pointer :: ptr type(priv_t), pointer :: head integer :: error allocate(ptr, stat = error) if (error.ne.0) & NCSU_OUT_OF_MEMORY ptr%next => null() if (.not.associated(priv_list)) then ptr%tag = 0 priv_list => ptr else head => priv_list do while (associated(head%next)) head => head%next end do ptr%tag = head%tag + 1 head%next => ptr end if cv%tag = ptr%tag end function new_priv ! removes from the list and deallocates subroutine del_priv(cv) NCSU_USE_AFAILED use ncsu_colvar_type implicit none type(colvar_t), intent(in) :: cv type(priv_t), pointer :: curr, prev ncsu_assert(associated(priv_list)) curr => priv_list if (curr%tag.eq.cv%tag) then priv_list => curr%next else prev => curr curr => curr%next do while (associated(curr)) if (curr%tag.eq.cv%tag) then prev%next => curr%next exit end if prev => curr curr => curr%next end do end if ncsu_assert(associated(curr)) ncsu_assert(curr%tag.eq.cv%tag) deallocate(curr) end subroutine del_priv