# How to define a Fortran type equivalent object in Julia

**URL:** <https://discourse.julialang.org/t/how-to-define-a-fortran-type-equivalent-object-in-julia/65721>\
**Category:** General Usage\
**Created:** [August 3, 2021, 5:50am UTC](https://discourse.julialang.org/t/how-to-define-a-fortran-type-equivalent-object-in-julia/65721 "2021-08-03T05:50:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![CRquantum](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/crquantum/32/27824_2.png) [@CRquantum](https://discourse.julialang.org/u/CRquantum)\
**Post date:** [August 3, 2021, 5:50am UTC](https://discourse.julialang.org/t/how-to-define-a-fortran-type-equivalent-object-in-julia/65721/1 "2021-08-03T05:50:48Z")

</div>

I have a fortran type I defined as mean\_covar like below,

```
type :: mean_covar
    real(kind=r8), allocatable :: mu(:,:)
    real(kind=r8), allocatable :: sigma(:,:)
    real(kind=r8) :: w
end type

```

So that I can set some variable as type Mean\_covar.

I want to define the same thing in Julia, I know Julia has something called struct, with mutable property its fields can be changed. So I did a very simply thing like,

```
mutable struct Mean_covar
mu::Array{Float64,2}
sigma::Array{Float64,2}
w::Int64  
end

```

Then I define,

```
musigma = Mean_covar(Array{Float64,2}(undef,2,2),Array{Float64,2}(undef,2,2), 0.0)

```

so I can then set musigma.mu as any 2d array I want.

But I just wonder, does it has to be so cumbersome when defining musigma (need to set the value of each fields)? Can I just simply do

```
musigma::Mean_covar

```

But this give me an error,

```
UndefVarError: musigma not defined

```

Thank you very much!

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [August 3, 2021, 6:15am UTC](https://discourse.julialang.org/t/how-to-define-a-fortran-type-equivalent-object-in-julia/65721/2 "2021-08-03T06:15:27Z")

</div>

you can write a constrictor that by default gives you an object with uninitiated arrays, so you don’t have to pass the three variables manually everytime you make a new one.

---

<div class="post-metadata">

**Author:** ![amrods](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amrods/32/2543_2.png) [@amrods](https://discourse.julialang.org/u/amrods)\
**Post date:** [August 3, 2021, 7:47am UTC](https://discourse.julialang.org/t/how-to-define-a-fortran-type-equivalent-object-in-julia/65721/3 "2021-08-03T07:47:07Z")

</div>

[`Parameters.jl`](https://github.com/mauro3/Parameters.jl) also does that automatically.
