---
jupytext:
formats: md:myst
text_representation:
extension: .md
format_name: myst
kernelspec:
display_name: Python 3
language: python
name: python3
---Section Arrays: Linear Transform¶
This program demonstrates an elemental function with multiple arguments in Fortran.¶
program linear_transform
implicit none
real, dimension(5) :: values
real, dimension(2) :: a = [ 1.1, 2.2 ], &
x = [ 0.5, 2.0 ], &
b = [ -1.2, 2.5 ]
integer :: i
call random_number(values)
print *, "The contents of the valus array is:"
print *, values
print *, "lin_transform(values, 2.0, 1.0) = "
print *, lin_transform(values, 2.0, 1.0)
print *, "lin_transform(x, a, b) = "
print *, lin_transform(x, a, b)
contains
elemental real function lin_transform(x, a, b)
implicit none
real, intent(in) :: x, a, b
lin_transform = a*x + b
end function lin_transform
end program linear_transformThe above program is compiled and run using Fortran Package Manager (fpm):
Build the Program using FPM (Fortran Package Manager)¶
import os
root_dir = os.getcwd()code_dir = root_dir + "/" + "Fortran_Code/Section_Arrays_Linear_Transform"os.chdir(code_dir)build_status = os.system("fpm build 2>/dev/null")Run the Program using FPM (Fortran Package Manager)¶
exec_status = os.system("fpm run 2>/dev/null") The contents of the valus array is:
0.282971740 0.587609768 0.963389933 0.764293790 0.139655590
lin_transform(values, 2.0, 1.0) =
1.56594348 2.17521954 2.92677975 2.52858758 1.27931118
lin_transform(x, a, b) =
-0.650000036 6.90000010
exec_status = os.system("fpm run 2>/dev/null") The contents of the valus array is:
0.424154580 0.590367556 1.86403990E-02 0.276004553 0.945034504
lin_transform(values, 2.0, 1.0) =
1.84830916 2.18073511 1.03728080 1.55200911 2.89006901
lin_transform(x, a, b) =
-0.650000036 6.90000010