Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8982189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:31:21+00:00 2026-06-15T20:31:21+00:00

In a Fortran 2003 module I’m defining a type called t_savepoint and, later, I

  • 0

In a Fortran 2003 module I’m defining a type called t_savepoint and, later, I want to define an interface for a subroutine called fs_initializesavepoint, which takes an object of type t_savepoint as only argument.

Here is the code for the whole module:

module m_serialization

    implicit none

    type :: t_savepoint
        integer :: savepoint_index
        real    :: savepoint_value
    end type t_savepoint

    interface

        subroutine fs_initializesavepoint(savepoint)
            type(t_savepoint) :: savepoint
        end subroutine fs_initializesavepoint


    end interface

end module m_serialization

The reason why I want such an interface is that later on I will make this fortran module interoperate with C.

If I try to compile it (gfortran-4.7.0), I get the following error message:

            type(t_savepoint) :: savepoint
                                          1
Error: The type of 'savepoint' at (1) has not been declared within the interface

The error disappears if I move the definition of the type inside the subroutine; but if then I want to use the same type within many subroutines, should I repeat the definition in all of them?

Thank you in advance.

EDIT: a solution would be to move the definition of the type onto another module and then to use it in every subroutine. However I don’t like this solution too much, because the type t_savepoint and the subroutines are part of the same conceptual topic.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T20:31:23+00:00Added an answer on June 15, 2026 at 8:31 pm

    Rightly or wrongly in an interface block you don’t have access to the environment by host association. To fix this you need to import the datatype exlicitly:

    [luser@cromer stackoverflow]$ cat type.f90
    module m_serialization
    
      implicit none
    
      type :: t_savepoint
         integer :: savepoint_index
         real    :: savepoint_value
      end type t_savepoint
    
      interface
    
         subroutine fs_initializesavepoint(savepoint)
           Import :: t_savepoint
           type(t_savepoint) :: savepoint
         end subroutine fs_initializesavepoint
    
    
      end interface
    
    end module m_serialization
    [luser@cromer stackoverflow]$ gfortran -c type.f90
    

    This is f2003.

    However I suspect the way you have put this suggests you are not going about coding this up the best way. Better is simply to put the routine itself in the module. Then you don’t need bother with the interface at all:

    module m_serialization
    
      implicit none
    
      type :: t_savepoint
         integer :: savepoint_index
         real    :: savepoint_value
      end type t_savepoint
    
    Contains
    
      Subroutine fs_initializesavepoint(savepoint)
    
        type(t_savepoint) :: savepoint 
    
        Write( *, * ) savepoint%savepoint_index, savepoint%savepoint_value
    
      End Subroutine fs_initializesavepoint
    
    end module m_serialization
    [luser@cromer stackoverflow]$ gfortran -c type.f90
    

    Given that modules are really designed to deal with connected entities this is really the way to do it in Fortran. It also has the advantage of only requiring a f95 compiler, so is universally available (though admittedly import is commonly implemented)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In fortran 2003, is it possible to define a derived type which has a
I have a Fortran subroutine which uses BLAS' subroutines dgemm, dgemv and ddot, which
I have a Fortran module which I am trying to compile with f2py (listed
The following Fortran Code: module Mod implicit none TYPE derivedtype procedure(procInterface),POINTER,PASS::f END TYPE derivedtype
I take an example from Fortran 95/2003 explained by Metcalf et al, since m
I am writing a Fortran program which involves a very large number of exponential
I have a fortran dll, and I want to know the assemblies that it
In the book Fortran 95/2003 for Scientists and Engineers , there is much talk
I'm programming in fortran and I could use a nice interface to a debugger.
I have the following FORTRAN SUBROUTINE SETPATHS(INPUT) !DEC$ ATTRIBUTES DLLEXPORT::SetPaths CHARACTER*20 INPUT CHARACTER*20 DIRECTORY

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.