Thanks for using Compiler Explorer
Sponsors
Jakt
C++
Ada
Analysis
Assembly
C
Carbon
C++ (Circle)
CIRCT
Clean
CMake
COBOL
C++ for OpenCL
MLIR
Cppx
Cppx-Blue
Cppx-Gold
Cpp2-cppfront
Crystal
C#
CUDA C++
D
Dart
Erlang
Fortran
F#
Go
Haskell
HLSL
Hook
ispc
Java
Julia
Kotlin
LLVM IR
LLVM MIR
Modula-2
Nim
Objective-C
Objective-C++
OCaml
OpenCL C
Pascal
Pony
Python
Racket
Ruby
Rust
Scala
Solidity
Swift
Toit
TypeScript Native
Visual Basic
Zig
fortran source #1
Output
Compile to binary object
Link to binary
Execute the code
Intel asm syntax
Demangle identifiers
Filters
Unused labels
Library functions
Directives
Comments
Horizontal whitespace
Compiler
AARCH64 gfortran 12.1.0
AARCH64 gfortran 12.2.0
AARCH64 gfortran 6.4
AARCH64 gfortran 7.3
AARCH64 gfortran 8.2
ARM (32bit) gfortran 12.2.0
ARM (32bit) gfortran 6.4
ARM (32bit) gfortran 7.3
ARM (32bit) gfortran 8.2
LOONGARCH64 gfortran 12.2.0
MIPS gfortran 12.1.0
MIPS gfortran 12.2.0
MIPS64 gfortran 12.1.0
MIPS64 gfortran 12.2.0
MIPS64el gfortran 12.1.0
MIPS64el gfortran 12.2.0
MIPSel gfortran 12.1.0
MIPSel gfortran 12.2.0
POWER gfortran 12.1.0
POWER gfortran 12.2.0
POWER64 gfortran 12.1.0
POWER64 gfortran 12.2.0
POWER64le gfortran 12.1.0
POWER64le gfortran 12.2.0
RISCV (32bit) gfortran 12.2.0
RISCV64 gfortran 12.2.0
SPARC LEON gfortran 12.2.0
SPARC gfortran 12.2.0
SPARC64 gfortran 12.2.0
flang-trunk (flang-new)
flang-trunk (old)
power64 AT12.0
power64 AT13.0
power64le AT12.0
power64le AT13.0
s390x gfortran 12.1.0
s390x gfortran 12.2.0
x86-64 gfortran (trunk)
x86-64 gfortran 10.1
x86-64 gfortran 10.2
x86-64 gfortran 10.3
x86-64 gfortran 10.4
x86-64 gfortran 11.1
x86-64 gfortran 11.2
x86-64 gfortran 11.3
x86-64 gfortran 12.1
x86-64 gfortran 12.2
x86-64 gfortran 4.9.4
x86-64 gfortran 5.5
x86-64 gfortran 6.3
x86-64 gfortran 7.1
x86-64 gfortran 7.2
x86-64 gfortran 7.3
x86-64 gfortran 8.1
x86-64 gfortran 8.2
x86-64 gfortran 8.3
x86-64 gfortran 8.4
x86-64 gfortran 8.5
x86-64 gfortran 9.1
x86-64 gfortran 9.2
x86-64 gfortran 9.3
x86-64 gfortran 9.4
x86-64 ifort 19.0.0
x86-64 ifort 2021.1.2
x86-64 ifort 2021.2.0
x86-64 ifort 2021.3.0
x86-64 ifort 2021.4.0
x86-64 ifort 2021.5.0
x86-64 ifort 2021.6.0
x86-64 ifort 2021.7.0
x86-64 ifort 2021.7.1
x86-64 ifx 2021.1.2
x86-64 ifx 2021.2.0
x86-64 ifx 2021.3.0
x86-64 ifx 2021.4.0
x86-64 ifx 2022.0.0
x86-64 ifx 2022.1.0
x86-64 ifx 2022.2.0
x86-64 ifx 2022.2.1
Options
Source code
module mygrid1 !! This module contains... use, intrinsic :: iso_fortran_env, only: real64 implicit none private public :: grid integer, parameter :: rk = real64 type :: grid !! 1D grid character(20) :: name = "x [-]" !! variable name real(rk), allocatable :: edges(:) !! vector(0:nc) of cell edges real(rk), allocatable :: center(:) !! vector(nc) of cell centers, \( x_i \) real(rk), allocatable :: width(:) !! vector(nc) of cell widths, \( x_{i+1/2} - x_{i-1/2} \) real(rk), pointer :: right(:) !! vector(nc) of right cell boundaries, , \( x_{i+1/2} \) integer :: ncells !! number of cells contains procedure, pass(self) :: new procedure, pass(self) :: left end type grid contains pure subroutine new(self, xmin, xmax, nc) ! Constructor grid1 class(grid), intent(inout), target :: self !! object real(rk), intent(in) :: xmin !! lower boundary of grid domain real(rk), intent(in) :: xmax !! upper boundary of grid domain integer, intent(in) :: nc !! number of grid cells real(rk) :: xedges(0:nc), rx integer :: i ! Compute linear mesh rx = (xmax - xmin)/nc do concurrent(i=0:nc) xedges(i) = xmin + rx*i end do ! Map values to grid object self%ncells = nc self%edges = xedges self%right => self%edges(1:nc) self%center = (self%left([(i, i=1, nc)]) + self%right)/2 self%width = self%right - self%left([(i, i=1, nc)]) end subroutine new elemental real(rk) function left(self,celli) class(grid), intent(in) :: self integer, intent(in) :: celli left = self%edges(celli-1) end function left end module mygrid1 program testgrid use mygrid1, only: grid use, intrinsic :: iso_fortran_env, only: real64 implicit none integer, parameter :: rk = real64 type(grid) :: gx real(rk) :: xmin, xmax, tmp integer :: nc xmin = 0._rk xmax = 100._rk nc = 4 call gx%new(xmin, xmax, nc) tmp = gx%left(1) print *, gx%left(1) tmp = gx%right(1) print *, gx%right end program
Become a Patron
Sponsor on GitHub
Donate via PayPal
Source on GitHub
Mailing list
Installed libraries
Wiki
Report an issue
How it works
Contact the author
CE on Mastodon
About the author
Statistics
Changelog
Version tree