What does “%” mean / do in Fortran?

后端 未结 3 811
长发绾君心
长发绾君心 2020-12-28 17:05

I am trying to read some Fortran code, but can not determine what the % (percentage sign) does.

It is in a line like:

   x = a%rho * g *         


        
3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-28 17:27

    In Fortran 90 they allow you to create structures like in C++. It basically acts as the dot (.) operator.

    From http://www.lahey.com/lookat90.htm :

    Structures (Derived Types)

    You can group your data using derived types. This enables users to combine intrinsic types (including arrays and pointers) into new types whose individual components can be accessed using the percent sign as a delimiter. (Derived types are known as records in VAX Fortran.) ! Example using derived types and modules.

    module pipedef
       type pipe                          ! Define new type 'pipe', which
         real diameter                    ! is made up of two reals, an
         real flowrate                    ! integer, and a character.
         integer length
         character(len=10) :: flowtype
       end type pipe
    end module pipedef
    
    program main
       use pipedef                ! Associate module pipedef with main.
       type(pipe) water1, gas1    ! Declare two variables of type 'pipe'.
       water1 = pipe(4.5,44.8,1200,"turbulent") ! Assign value to water1.
       gas1%diameter = 14.9                     ! Assign value to parts
       gas1%flowrate = 91.284                   ! of gas1.
       gas1%length = 2550
       gas1%flowtype = 'laminar'
       .
       .
       .
    end program
    

提交回复
热议问题