1

I was reading a Fortran code, came across the following code, couldn't understand what it does.

m%AllOuts( BAzimuth(k) ) = m%BEMT_u(indx)%psi(k)*R2D

I know that % here works like a pipe indicator to access values in a way similar to a dictionary in Python. I have a dictionary m let's say and the first key is AllOuts, but what does anything inside parentheses mean? Is it like another dictionary?

6
  • For completeness can you include the definition of m and any associated types. Commented Nov 30, 2020 at 13:48
  • You might want to read this answer about derived types in Fortran. Commented Nov 30, 2020 at 14:10
  • I added in the comments below @JAlex Thanks for your response. Commented Dec 1, 2020 at 6:16
  • @thisismihir please edit the question to add the definition of m so that someone else can be helped in the future. Comments are not the right place for this. Commented Dec 1, 2020 at 13:31
  • @JAlex m%AllOuts( RtAeroPwr ) = m%BEMT_u(indx)%omega * m%AllOuts( RtAeroMxh ) How can I print the values of m%BEMT_u(indx)%omega and m%AllOuts( RtAeroMxh ) They are probably arrays. How can I print them? I tried this print *, m%AllOuts( RtAeroMxh ), m%AllOuts, m%BEMT_u Had few errors. Should I share the errors? Commented Dec 1, 2020 at 19:42

1 Answer 1

4

The percent sign is not denoting a dictionary. There are no native dictionaries in Fortran.

The percent sign denotes the component of a type. For example:

! Declare a type
type :: rectangle
    integer :: x, y
    character(len=8) :: color
end type rectangle

! Declare a variable of this type
type(rectangle) :: my_rect

! Use the type

my_rect % x = 4
my_rect % y = 3
my_rect % color = 'red'

print *, "Area: ", my_rect % x * my_rect % y

The parentheses could either indicate the index of an array, or the arguments of a call.

So, for example:

integer, dimension(10) :: a

a(8) = 16     ! write the number 16 to the 8th element of array a

Or, as a prodedure:

print *, my_pow(2, 3)

...

contains

function my_pow(a, b)
    integer, intent(in) :: a, b
    my_pow = a ** b
end function my_pow

In order to figure out what m is, you'd need to look at the declaration of m, which would be something like

type(sometype) :: m

or

class(sometype) :: m

Then you'd need to find out the type declaration, which would be something like

type :: sometype
    ! component declarations in here
end type

Now one of the components, BEMT_u, is almost certainly an array of a different type, which you'd also need to look up.

Sign up to request clarification or add additional context in comments.

3 Comments

One may have to look for other types of things to determine what m is. m could be implicitly typed, or it could be a selector in one of several constructs. And if it's not a local entity it could be from a quite distant host or module.
This helps a lot @chw21. Thanks for this. I looked for m, I came across the following TYPE(AD_MiscVarType), INTENT(IN ) :: m ! misc variables But this is inside subroutines. Now when I looked for AD_MiscVarType, I came across this TYPE, PUBLIC :: AD_MiscVarType:: AD_MiscVarType REAL(ReKi) , DIMENSION(:), ALLOCATABLE :: AllOuts I'm not sure what type of AD_MiscVarType is being allocated twice.
@francescalus @chw21 m%AllOuts( RtAeroPwr ) = m%BEMT_u(indx)%omega * m%AllOuts( RtAeroMxh ) How can I print the values of m%BEMT_u(indx)%omega and m%AllOuts( RtAeroMxh ) They are probably arrays. How can I print them? I tried this print *, m%AllOuts( RtAeroMxh ), m%AllOuts, m%BEMT_u Had few errors. Should I share the errors?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.