gfortran

Different CHARACTER lengths (3/4) in array constructor, how to trim strings - fortran

纵饮孤独 提交于 2019-12-09 00:34:34
问题 According to an answer to a similar question, I have declared the characters as indicated here gfortran does not allow character arrays with varying component lengths . However I would like to use a trim function because I need to add spaces to manually pad the names and these variables are then used in another part of the code. Can I trim at the same time as creating the array? Error: Different CHARACTER lengths (3/4) in array constructor at (1) If I add random characters to make them the

fortran format specifier for complex number

末鹿安然 提交于 2019-12-09 00:34:22
问题 Can I specify a format specifier for a complex number in fortran? I have a simple program. program complx1 implicit none complex :: var1 var1 = (10,20) write (*,*) var1 write (*,'(F0.0)') var1 write (*,'(F0.0,A,F0.0)') real(var1), ' + i ' , aimag(var1) end program complx1 Output: ( 10.0000000 , 20.0000000 ) 10. 20. 10. + i 20. I wanted to use inbuilt format for a+bi with some format specifier, instead of one did manually (second last line of program). Obviously F0.0 did not work. Any ideas?

Function which returns multiple values

旧街凉风 提交于 2019-12-08 19:55:37
问题 In Fortran, is it possible to define a function which returns multiple values like below? [a, b] = myfunc(x, y) 回答1: That depends... With functions , it is not possible to have two distinct function results. However, you can have an array of length two returned from the function. function myfunc(x, y) implicit none integer, intent(in) :: x,y integer :: myfunc(2) myfunc = [ 2*x, 3*y ] end function If you need two return values to two distinct variables, use a subroutine instead: subroutine

Inline keyword gfortran

老子叫甜甜 提交于 2019-12-08 18:48:35
问题 Is there any Fortran keyword equivalent to the C "inline" keyword? If some compiler-specific keyword exist, is there any for gfortran? 回答1: In general, the Fortran specifications grant the compiler writers enormous scope in how to implement things, so a language-level construct that forced (or even hinted) specific optimizations would be very un-Fortran-y. What you typically do in modern Fortran is not specify optimizations, but tell the compiler things it can use to decide what optimizations

Gnuplot vector fortran

二次信任 提交于 2019-12-08 15:38:22
问题 How do you plot this program(fortran) in vector form in gnuplot?? the command: call execute_command_line("gnuplot plotvel.txt") does not seem to work. Nothing happens And what does using 1:2:3:4 mean?? in " plot "file.dat" using 1:2:3:4 with vectors filled head lw 3 " call execute_command_line("gnuplot plotvel.txt") 回答1: First of all, you are making a data file plotdata.txt at the beginning of the program, while trying to plot file.dat later, so that Gnuplot cannot find the latter. After

Fortran 90 with C/C++ style macro (e.g. # define SUBNAME(x) s ## x)

强颜欢笑 提交于 2019-12-08 13:44:45
问题 I am recently working with a F90 code project. I am using gfortran (linux and MinGW) to compile it. There is something interesting in file loct.F90. # define TYPE real(4) # define SUBNAME(x) s ## x # include "loct_inc.F90" # undef SUBNAME # undef TYPE # define TYPE real(8) # define SUBNAME(x) d ## x # include "loct_inc.F90" # undef SUBNAME # undef TYPE ... The loct_inc.F90 file looks like this: subroutine SUBNAME(loct_pointer_copy_1)(o, i) ... end subroutine SUBNAME(loct_pointer_copy_1)

Are there obvious sources for the Brew Doctor warnings I'm seeing?

为君一笑 提交于 2019-12-08 11:24:17
问题 I have recently installed Hombrew on Yosemite with Xcode installed and would like to better understand what brew doctor is warning me about. I understand that these warnings are nothing to worry about (until they are) and am not asking how or whether to respond to them; but I would like to do the best I can to understand the likely causes so that I can be prepared when issues come up (and also to head off issues that others in my office may encounter on similar systems). Are any of the items

How to call a function in Fortran that is defined in a separate file?

喜欢而已 提交于 2019-12-08 10:32:21
问题 I am trying to compile some really old code (1986 and before). This code references an external function. Today's compilers ask for far more code to make this work. And I keep failing. I now created a small hello world program, which demonstrates the problem. hello.for PROGRAM hello USE func PRINT *, "Hello World!" PRINT *, f () END PROGRAM hello func.for MODULE func PUBLIC f CONTAINS FUNCTION f () f='Hello Func' END FUNCTION END MODULE This has not only one, but two problems: How do I define

Errors in linking fortran code that imports a MAT-file [duplicate]

烂漫一生 提交于 2019-12-08 07:28:28
This question already has an answer here : Reading data from matlab files into C (1 answer) Closed 4 years ago . I have to import a MAT-file in a fortran program. I followed the example file but I am facing some problems while linking. The compilation happens fine. Minimal code: #include "fintrf.h" PROGRAM main USE ssa USE dmotifs USE param IMPLICIT NONE ! MAT-FILE Declarations ! INTEGER matOpen, matGetDir INTEGER matGetVariableInfo INTEGER mp, dir, adir(100), pa INTEGER mxGetM, mxGetN, matClose INTEGER ndir, i, clstat CHARACTER*32 names(100) !===========================! if(all(fnames(:)%fn

Fortran runtime error: End of file

浪尽此生 提交于 2019-12-08 07:09:05
问题 I'm trying to understand how the READ statement works in Fortran. To do this, I've written the following simple program: program main integer a,b,c open(unit=10,file='test.txt',status='old') read(10,*)a,b,c print*,a,b,c close(10) end program main I run this on the terminal (using a Mac): gfortran Main.f95; open a.out I get the following error: At line 5 of file Main.f95 (unit = 10, file = 'test.txt') Fortran runtime error: End of file I've looked for solutions all around the web and came upon