fortran90

Converting a string to an integer in Fortran 90

允我心安 提交于 2019-11-28 13:31:31
I know that IACHAR(s) returns the code for the ASCII character in the first character position of the string s, but I need to convert the entire string to an integer. I also have a few number of strings (around 30 strings, each consists of at most 20 characters). Is there any way to convert each one of them to a unique integer in Fortran 90? You can read a string into an integer variable: module str2int_mod contains elemental subroutine str2int(str,int,stat) implicit none ! Arguments character(len=*),intent(in) :: str integer,intent(out) :: int integer,intent(out) :: stat read(str,*,iostat

OpenMP private array - Segmentation fault: 11

余生颓废 提交于 2019-11-28 11:45:06
When I try to parallelize my program in Fortran90 by OpenMP, I get a segmentation fault error. !$OMP PARALLEL DO NUM_THREADS(4) & !$OMP PRIVATE(numstrain, i) do irep = 1, nrep do i=1, 10 PRINT *, numstrain(i) end do end do !$OMP END PARALLEL DO I find that if I comment out "PRINT *, numstrain(i)" or remove openmp flags it works without error. I think it is because memory access conflict happens when I access numstrain(i) in parallel. I already declared i and numstrain as private variables. Could someone please give me some idea why it is the case? Thank you so much. :) UPDATE: I modified the

What is the purpose of result variables in Fortran?

怎甘沉沦 提交于 2019-11-28 11:28:50
In Fortran, there are two standard ways to return a result from a function. The first one is by assigning the return value of the function to the function name. function foo() integer :: foo foo = 10 end function foo The second form, standardized in Fortran 90 is through a "result" variable. function foo result(res) integer :: res res = 10 end function foo Calling either form of the function returns the value 10. My question is, what was the rationale of the Fortran 90 committee for introducing result variables? Were they standardizing a common practice? Or were they allowing programs to be

Using do loop in a Fortran 90 program to read different number of lines for n frames?

喜你入骨 提交于 2019-11-28 11:04:20
问题 There is a file that has,say, 1000 frames. Each frame contains different number of lines.Each line has two columns of integers.But,I do not know how many number of lines each frame contains. Every frame is separated by one blank line.I want to read these values and store them in an array. But,I cannot allocate the array size as I do not know how many lines every frame has. So, I have two questions: How can I use a "do" loop to read the different number of lines in a fortran90 program ? I

write in array format in fortran

ⅰ亾dé卋堺 提交于 2019-11-28 11:01:06
问题 I try to write an output file.dat with an nxn matrix format . I write the code but the output is a column of value f. Now the problem is: how can i change the output-format of the file to write? from: 1 2 4 5 ... to: 1,2,3,4 // 5,6,8,.. // program eccen implicit none integer, parameter:: grid=800 integer::i,j,k,n,m real*8,allocatable::f(:,:) real*8::xx(grid),yy(grid),mval,Mxval real*8,allocatable::x(:),y(:) open(10,file='3d_disk.txt') n=0 DO READ(10,*,END=100) n=n+1 END DO 100 continue rewind

Is Fortran unable to do the addition between 865398.78 and -865398.78? Why the answer is -0.03?

倾然丶 夕夏残阳落幕 提交于 2019-11-28 10:56:20
问题 In the code below I am adding together 865398.78 and -865398.78. I expect to get 0, but instead I get -0.03. Source Code: program main real(8) :: x open(10,file="test.txt") read(10,*)x print *,"x=",x x=x+865398.78 print *,"x+865398.78=",x end program Result: x= -865398.780000000 x+865398.78= -3.000000002793968E-002 Am I wrong with the usage of "read" codes or something else? 回答1: The number 865398.78 is represented in single precision in your code. Single precision can handle about 7

Can not install gfortran via homebrew

守給你的承諾、 提交于 2019-11-28 10:49:52
I got this message when i tried to install gfortran. ~$ brew install gfortran Error: No available formula for gfortran GNU Fortran is now provided as part of GCC, and can be installed with: brew install gcc My question is how to install gfortran with homebrew or port? or If now GNU Fortran is a part of GCC How can i compile fortran code using gcc? I'm not sure may be i've misunderstood something i remember that the last time i still can use gfortran to compile my code but now it doesn't work. Further information: when i use command brew list i still see that gfortran is there but can not use

Dynamic output format setting

回眸只為那壹抹淺笑 提交于 2019-11-28 10:20:25
问题 I tried to make the output format dynamically in the sense that the number of variables to be printed out could be varied dynamically. I had done some experiment with the following two methods (see the context below), but both of them led to a error message like this: forrtl: error (63): output conversion error, unit 1016, file /panfs/roc/Node_ 16.txt The first method uses a string to specify the output format, for example, real a(4) = [1 2 3 4] int size = 4 write(string,'(a,i3,a)') '(a,'

Include both .f and .F90 file in Fortran main file header

梦想的初衷 提交于 2019-11-28 09:53:06
问题 I am using some F77 fixed format code with my F90 program. I am trying to include both kinds of code in my main program. Here's how I have arranged my code: Header files: File Name:include.inc include 'module_variables.F90' include 'message.F90' include 'module_common_functions.f90' include 'module_input_gdf.F90' ... Relavant LAPACK files File Name: lapack.inc include 'xerbla.f' include 'strsm.f' include 'slaswp.f' include 'sgetrs.f' include 'sgetrf.f' ... Now my main program looks like:

Usage of Fortran statement functions

僤鯓⒐⒋嵵緔 提交于 2019-11-28 09:29:42
问题 I read about statement functions, such as the example: C(F) = 5.0*(F - 32.0)/9.0 Isn't this the same as: C = 5.0*(F - 32.0)/9.0 i.e. without the function part, or maybe I'm missing something? If they're not the same, when do I need to use a statement function? 回答1: C = 5.0*(F - 32.0)/9.0 is just assignment to a variable C , it can be anywhere and is evaluated once every time when the program flow reaches it. C(F) = 5.0*(F - 32.0)/9.0 is a statement function, and can be evaluated any time it