Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
[COLOR=#a020f0]module[/color] my_foo
[COLOR=#a020f0]contains[/color]
[COLOR=#2e8b57][b] real[/b][/color] [COLOR=#a020f0]function[/color] func(vec)
[COLOR=#2e8b57][b]implicit[/b][/color] [COLOR=#2e8b57][b]none[/b][/color]
[COLOR=#2e8b57][b] real[/b][/color], [COLOR=#2e8b57][b]dimension[/b][/color](:), [COLOR=#2e8b57][b]intent[/b][/color]([COLOR=#2e8b57][b]in[/b][/color]) :: vec
[COLOR=#2e8b57][b]integer[/b][/color] :: i
func[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]0[/color]
[COLOR=#804040][b]do[/b][/color] i[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]1[/color], [COLOR=#008080]size[/color](vec)
func [COLOR=#804040][b]=[/b][/color] func [COLOR=#804040][b]+[/b][/color] vec(i)
[COLOR=#804040][b]end do[/b][/color]
[COLOR=#a020f0]end function[/color] func
[COLOR=#a020f0]end module[/color] my_foo
[COLOR=#a020f0]program[/color] main
[COLOR=#2e8b57][b]implicit[/b][/color] [COLOR=#2e8b57][b]none[/b][/color]
[COLOR=#2e8b57][b]integer[/b][/color], [COLOR=#2e8b57][b]parameter[/b][/color] :: input_array_size [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]2[/color]
[COLOR=#2e8b57][b] real[/b][/color] :: input_array(input_array_size), output_result
[COLOR=#0000ff]! set input vector[/color]
input_array [COLOR=#804040][b]=[/b][/color] ([COLOR=#804040][b]/[/b][/color][COLOR=#ff00ff]1[/color]., [COLOR=#ff00ff]2[/color].[COLOR=#804040][b]/[/b][/color])
[COLOR=#0000ff]! call subroutine[/color]
[COLOR=#008080]call[/color] func_sub(input_array_size, input_array, output_result)
[COLOR=#0000ff]! print result[/color]
[COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'output_result = '[/color], output_result
[COLOR=#a020f0]end program[/color] main
[COLOR=#a020f0]subroutine[/color] func_sub(N, PP, F)
[COLOR=#0000ff]! use module which contains foo[/color]
[COLOR=#a020f0]use[/color] my_foo
[COLOR=#2e8b57][b]Implicit[/b][/color] [COLOR=#2e8b57][b]None[/b][/color]
[COLOR=#2e8b57][b]integer[/b][/color] :: N
[COLOR=#2e8b57][b] real[/b][/color] :: PP(N), F , func
F [COLOR=#804040][b]=[/b][/color] func(PP)
[COLOR=#a020f0]end Subroutine[/color] func_sub
$ gfortran subr_func.f95 -o subr_func
$ subr_func
output_result = 3.0000000
$ g95 subr_func.f95 -o subr_func
In file subr_func.f95:33
real :: PP(N), F , func
1
Error: Symbol 'func' at (1) already has basic type of REAL
[COLOR=#2e8b57][b] real[/b][/color] :: PP(N), F [COLOR=#0000ff]!, func[/color]
$ g95 subr_func.f95 -o subr_func
$ subr_func
output_result = 3.
It doesn't seem to simply calculate the norm of vector PP, reshaped as matrix vv.milenko76 said:It should calculate the square norm. Still I do not get it why is he doing inverse two times?