Simple way to implement a group of queues in Fortran?

后端 未结 3 884
旧巷少年郎
旧巷少年郎 2021-01-16 18:57

Suppose that I need to implement at least 5 queues in one procedure, each of it from a different defined type. How can achive this in a simple and short way?.

Anot

相关标签:
3条回答
  • 2021-01-16 19:31

    I have implemented the fortran template in Ruby, which is integrated in my CodeMate. The template syntax is similar to C++. I have implemented double linked list. The template definition snippets are as following:

    ...
    
    template:list_t <type elem_t>
    type list_t
        integer :: num_elem = 0
        type(elem_t), pointer :: head, tail
    contains
        ...
        procedure :: insert => list_insert
        ...
    end type list
    
    ...
    
    template:list_insert@list_t <type elem_t>
    subroutine list_insert(this, elem, ...)
    
        class(list_t), intent(inout) :: this
        type(elem_t), intent(out), pointer :: elem
    
        ...
    
    end subroutine list_insert
    

    And the template instance is as following:

    type(list_t<foo_t>) foo_list
    

    where foo_t is a user-defined type that extends list_elem_t<foo_t>. The you can insert element into foo_list by

    call foo_list%insert(elem, ...)
    

    I think my solution to Fortran template is natural.

    0 讨论(0)
  • 2021-01-16 19:33

    Have you considered unlimited polymorphic pointers? See, for ex., pp 269 ff in "Modern Fortran Explained".

    0 讨论(0)
  • 2021-01-16 19:43

    If you really want templates, there is Pyf95++. It brings templating and an STL for Fortran using a preprocessor. (for download here)

    A generic linked-list that uses transfer() can be found in FLIBS.

    (Otherwise with a bleeding edge compiler you can use unlimited polymorphism as suggested by Richard Lozes.)

    0 讨论(0)
提交回复
热议问题