fortran

Wrong length of a character array component after allocation

房东的猫 提交于 2021-02-05 07:11:06
问题 I would like to create a derived type containing allocatable character array components. However, when I try to allocate memory in subroutines, nothing happens. It may be more clear with the code example below: program test type t1 character(len=:), allocatable :: c(:) end type t1 type(t1) :: t call test_string1() call test_string2(t) contains subroutine test_string1() character(len=:), allocatable :: c(:) allocate( character(10) :: c(1) ) write(*, *) 'Size in string1: ', len(c) end

How to receive a string from a C function called by Fortran by iso_c_binding?

江枫思渺然 提交于 2021-02-05 06:21:29
问题 I want to call a C function from Fortran and receive a string of characters defined in the C function. I searched, but I couldn't find a working, straightforward answer, so far. Actually I have found a workaround: receiving an array of characters instead, then using the intrinsic function transfer to put the result into a Fortran string. Here is my working code. Fortran main program: program pr implicit none character(200) :: stringa call strfromc(stringa) write (6,*) 'FPR stringa: "', trim

Ambiguous interface when using optional arguments in Gfortran

白昼怎懂夜的黑 提交于 2021-02-05 06:03:31
问题 I've just stumbled across this error when compiling a bit of code that I've been using without problems for ages now. I'm using Gfortran 8.2 on Linux and I suspect that a compiler update has caused the issue. When I define an interface with an optional argument that has a different number of non-optional arguments, Gfortran complains that the interface is ambiguous. For example, if I compile the following, I get "Ambiguous interfaces in generic interface 'test' for ‘testinit1’ at (1) and

This FORTRAN code shouldn't compile. Is there a reason why it does?

邮差的信 提交于 2021-02-05 05:55:26
问题 The following code compiles, but I do not think that it should. As you can see, the output is garbage. This is a minimal failing example of something that bit me hard in a large project I work on. My question is - why does the compiler not complain? Is this a compiler limitation, or is this somehow "expected behaviour", and I've missed something? I'm using gfortran 4.6.3. module dataModule integer :: datum1 = int(1) integer :: datum2 = int(2) end module dataModule program moduleTest use

How to store a set of functions into a Fortran array

↘锁芯ラ 提交于 2021-02-04 21:44:34
问题 As we know that function name can be treated as parameters to pass in/out by other subroutines. I wonder if we have any tricks to save a list of functions into an array, which would be passed in and out for process. !-------for example. At somewhere we set any array type(Idonotknow)::Farray(N) Then set the value: Farray(1)%any=>fun1 Farray(2)%any=>fun2 ... Farray(N)%any=>funN where fun1,fun2...funN are something like Function fun1(input) implicit none statements End Function Finally we can

Implementing getarg subroutine call

China☆狼群 提交于 2021-02-04 21:44:11
问题 I've written a program in F90 which reads in a few input arrays from text files and then combines them through a function to a single output file. One of the input files is named for the day the data was collected using MMDDYY.tuvr and the output file is then named MMDDYY.fxi . I'd like to be able to input the MMDDYY of the data in the command line when running the program instead of having to manually change the code and compile each time, which is why I'm attempting to use getarg, but I

Implementing getarg subroutine call

落爺英雄遲暮 提交于 2021-02-04 21:43:46
问题 I've written a program in F90 which reads in a few input arrays from text files and then combines them through a function to a single output file. One of the input files is named for the day the data was collected using MMDDYY.tuvr and the output file is then named MMDDYY.fxi . I'd like to be able to input the MMDDYY of the data in the command line when running the program instead of having to manually change the code and compile each time, which is why I'm attempting to use getarg, but I

Implementing getarg subroutine call

霸气de小男生 提交于 2021-02-04 21:42:43
问题 I've written a program in F90 which reads in a few input arrays from text files and then combines them through a function to a single output file. One of the input files is named for the day the data was collected using MMDDYY.tuvr and the output file is then named MMDDYY.fxi . I'd like to be able to input the MMDDYY of the data in the command line when running the program instead of having to manually change the code and compile each time, which is why I'm attempting to use getarg, but I

gfortran can't find OpenMP library (omp_lib.mod) using MinGW

天涯浪子 提交于 2021-02-04 21:39:55
问题 I am trying to compile a Fortran code including OpenMP. I am replicating the use of OpenMP from a different code. It built successfully once yesterday and then the next time I built it I get the following error: ../MAXBRG3D.f90:3:4: USE OMP_LIB ! USED WITH OMP FUNCTIONS 1 Fatal Error: Can't open module file 'omp_lib.mod' for reading at (1): No such file or directory compilation terminated. subdir.mk:329: recipe for target 'MAXBRG3D.o' failed make: *** [MAXBRG3D.o] Error 1 The only changes I

Read text file line by line but only specific columns

心不动则不痛 提交于 2021-02-04 17:55:07
问题 How do we read a specific file line by line while skipping some columns in it? For example, I have a text file which has data, sorted out in 5 columns, but I need to read only two columns out of it, they can be first two or any other random combination (I mean, need a solution which would work with any combination of columns like first and third only). Code something like this open(1, file=data_file) read (1,*) ! to skip first line, with metadata lmax = 0 do while (.true.) ! read column 1 and