fortran

Compilation error: Invalid character in name at (1)

吃可爱长大的小学妹 提交于 2021-02-17 03:54:07
问题 I wrote program test implicit none integer, parameter :: N = 3 real(8), parameter :: & A(N,N) = reshape( (/1.5d0,1d0,1d0,1d0,1.5d0,2d0,1d0,1d0,3d0/), shape(A) ) & b(N) = (/ 5d0,-3d0,8d0 /) print *, A end program saved as test.f, and got compilation error with gfortran -ffree-form -Wall -Werror -ffree-line-length-none test.f . test.f:6:24: A(N,N) = reshape( (/1.5d0,1d0,1d0,1d0,1.5d0,2d0,1d0,1d0,3d0/), shape(A) ) & 1 Error: Invalid character in name at (1) test.f:9:12: print *, A 1 Error:

Passing Variables from a Shell-Script to a Fortran 90 Program

大兔子大兔子 提交于 2021-02-17 02:56:11
问题 I'm stuck on this little problem. I was wondering if it is possible to pass a variable of a bash-shell script to a f90 code? 回答1: I am pretty sure it was discussed here before, but I cannot find an exact duplicate. You can pass arguments directly as arguments to the program ./program arg1 arg2 you can retrieve the values in the program as character strings in Fortran 2003 using subroutines GET_COMMAND ARGUMENT and COMMAND_ARGUMENT_COUNT. Click on the links to get useful examples. In older

我的FP感悟

自作多情 提交于 2021-02-16 23:20:42
FP概要: 我主要总结了以下5点: 函数是一等公民: 函数的参数是函数,返回值是函数,类型还是函数... 舍弃语句,拥抱表达式: 表达式就一定有返回值。 无副作用: 不修改外部系统的状态。 immutable: 没有变量,一切不可变,循环用递归实现。 引用透明: 相同输入产生相同输出,需要的信息都通过参数传递,方便单元测试. 就以上几点,我编了一首打油诗: 函数编程很强大 一等公民都是它 外部变量不依赖 返回确保串行化 串行化什么意思呢? 同样计算 (1+2)*3/4 ,java代码如下: int a = 1 + 2 int b = a * 3 int c = b / 4 而Scala写出来如下: val r = subtract(multiply(add(1, 2), 3), 4) 如此,就可以很简单的改写为: val r = add(1, 2).multiply(3).subtract(4) 其中的美妙自己体会吧~~~ 那么这么做的意义呢? 代码简洁 接近自然语言 函数单纯,易于测试 immutable,并发简单可控 热升级 如果代码包含了任何的var,则是指令式风格,如果全是val则可能是函数式风格。 函数的结果类型是Unit的是有副作用的,而结果类型有明确返回类型的则可能是没有副作用的。 函数内部依赖外部数据而不是输入参数(也就是闭包)的是有副作用的,

Controlling newlines when writing out arrays in Fortran

喜夏-厌秋 提交于 2021-02-16 15:10:52
问题 So I have some code that does essentially this: REAL, DIMENSION(31) :: month_data INTEGER :: no_days no_days = get_no_days() month_data = [fill array with some values] WRITE(1000,*) (month_data(d), d=1,no_days) So I have an array with values for each month, in a loop I fill the array with a certain number of values based on how many days there are in that month, then write out the results into a file. It took me quite some time to wrap my head around the whole 'write out an array in one go'

subroutine argument with unknown rank (shape) in fortran

廉价感情. 提交于 2021-02-16 08:34:22
问题 I am wondering how to best handle in Fortran a subroutine that takes an argument of unknown rank. For instance: Real * 8 :: array1(2,2),array2(2,2,3) call mysubroutine(array1) call mysubroutine(array2) As for now, I always need to fix the shape (number of rank) in the subroutine. For instance, the intrinsic subroutine random_number ( array ) can do. (But maybe it is not coded in Fortran?) 回答1: You have to write a specific subroutine for each array rank, but you create a generic interface so

Fortran DO loop, warning to use integer only

删除回忆录丶 提交于 2021-02-15 11:08:55
问题 I installed gfortran on my Ubuntu 15.04 system. While compiling Fortran code, the DO loop asks to take integer parameters only and not real values or variables. That includes the loop variable and the step expression. Why can't it take real values too? The following is a program taken from here, exercise 3.5 of the section nested do loops . program xytab implicit none !constructs a table of z=x/y for values of x from 1 to 2 and !y from 1 to 4 in steps of .5 real :: x, y, z print *, ' x y z'

Unable to compile .f (fortran file) in codeblocks 13.12

安稳与你 提交于 2021-02-15 07:14:53
问题 I am trying to execute give fortran code in Code::Blocks on Windows 8 program main write (*,*) "hi" stop end The error I am getting is G:\Study\Programs\bairstow.o:bairstow.f undefined reference to `_gfortran_st_write' G:\Study\Programs\bairstow.o:bairstow.f undefined reference to `_gfortran_transfer_character_write' G:\Study\Programs\bairstow.o:bairstow.f undefined reference to `_gfortran_st_write_done' G:\Study\Programs\bairstow.o:bairstow.f undefined reference to `_gfortran_stop_string' G:

How to reverse a chain of characters?

最后都变了- 提交于 2021-02-15 07:12:14
问题 I have to create a program that reverses phrases . For example: when I write hello guys , I want syug olleh This is what I have for the moment but I don't know how to reverse the characters in the board phraseT : program reversing implicit none character(len=20),dimension(1:20)::phraseT character(len=20)::phrase,reverse integer::i,x write(*,*)"write a phrase :" read(*,'(a)')phrase x=len(trim(phrase)) nomT(1:20)=" " do i=1,x nomT(i:i)=trim(phrase(i:i)) end do write(*,*)nomT end program

How to reverse a chain of characters?

社会主义新天地 提交于 2021-02-15 07:08:45
问题 I have to create a program that reverses phrases . For example: when I write hello guys , I want syug olleh This is what I have for the moment but I don't know how to reverse the characters in the board phraseT : program reversing implicit none character(len=20),dimension(1:20)::phraseT character(len=20)::phrase,reverse integer::i,x write(*,*)"write a phrase :" read(*,'(a)')phrase x=len(trim(phrase)) nomT(1:20)=" " do i=1,x nomT(i:i)=trim(phrase(i:i)) end do write(*,*)nomT end program

How to reverse a chain of characters?

社会主义新天地 提交于 2021-02-15 07:08:44
问题 I have to create a program that reverses phrases . For example: when I write hello guys , I want syug olleh This is what I have for the moment but I don't know how to reverse the characters in the board phraseT : program reversing implicit none character(len=20),dimension(1:20)::phraseT character(len=20)::phrase,reverse integer::i,x write(*,*)"write a phrase :" read(*,'(a)')phrase x=len(trim(phrase)) nomT(1:20)=" " do i=1,x nomT(i:i)=trim(phrase(i:i)) end do write(*,*)nomT end program