fortran90

Arrays of pointers

天大地大妈咪最大 提交于 2019-11-27 12:05:34
I am trying to implement an array of pointers, so that I can loop over the elements. However I am not sure how to do this correctly: TYPE(domain),POINTER :: d01,d02,d03 TYPE(domain),DIMENSION(:),POINTER :: dom ... dom(1) => d01 dom(2) => d02 dom(3) => d03 ... and then: ... IF(ASSOCIATED(dom(2),d02))THEN ... The compiler (pgf90 10.6-0 64-bit target on x86-64 Linux -tp istanbul-64) gives me this error message: PGF90-S-0074-Illegal number or type of arguments to associated - keyword argument pointer (test_ptr.f90: 10) 0 inform, 0 warnings, 1 severes, 0 fatal for MAIN As far as I understand, there

Standard input and output units in Fortran 90?

时光总嘲笑我的痴心妄想 提交于 2019-11-27 11:10:51
问题 How can I read and write to the standard input, output and error streams stdin , stdout and stderr in Fortran? I've heard writing to stderr , for example, used to be write(5, fmt=...) , with 5 the unit for stderr , and I know the way to write to stdout is to use write(*, fmt=...) . How do I read and write to the standard input and output units with the ifort compiler? Compiler version: Intel(R) Fortran Compiler for applications running on Intel(R) 64, Version 10.0 Build 20070426 Package ID: l

Looping over variable file names [duplicate]

假如想象 提交于 2019-11-27 09:52:00
This question already has an answer here: Convert integers to strings to create output filenames at run time 9 answers I am using Fortran to do calculation on huge data set which was split into many files. The names of the files are: maltoLyo12per-reimage-set1.traj maltoLyo12per-reimage-set2.traj maltoLyo12per-reimage-set3.traj The code I wrote to do the calculation is as below: fileLoop: do j = 31, 34 OPEN(unit=31,status='old',file=fileplace//'maltoLyo12per-reimage-set1.traj') OPEN(unit=32,status='old',file=fileplace//'maltoLyo12per-reimage-set2.traj') OPEN(unit=33,status='old',file=fileplace

Fortran IF statement with numbers/labels rather than another statement

拜拜、爱过 提交于 2019-11-27 09:31:27
What does this Fortran code mean: IF (J1-3) 20, 20, 21 21 J1 = J1 - 3 20 IF (J2-3) 22, 22, 23 23 J2 = J2 - 3 22 CONTINUE I've seen in old project and I don't have any idea what this IF with numbers (labels) means. This is an arithmetic if statement from FORTRAN 77. Adapted from the FORTRAN 77 specification (emphasis mine): The form of an arithmetic IF statement is: IF (e) s1 , s2 , s2 where: e is an integer, real, or double precision expression s1 , s2 , and s3 are each the statement label of an executable statement that appears in the same program unit as the arithmetic IF statement. The same

Defining a function returning an array

荒凉一梦 提交于 2019-11-27 09:20:14
I have the following code: Program function_as_an_array implicit none integer:: i integer, parameter:: N=10 real*8:: x(N),y(N),f(N) do i=1,N x(i)=float(i) end do call func(f,N,x) open(unit=20, file='test.dat') do i=1,N y(i)=f(i) write(20,*) x(i),y(i) end do close(20) Stop End Program function_as_an_array Subroutine func(f,N,x) implicit none integer i,N real*8:: x(N),f(N) do i=1,N f(i)=x(i)**2 end do end Subroutine func I want to make the program indeed be meant for "function as an arrray", i.e. I would like to replace the Subroutine func by a function f and get the same result (In the main

How to write at specific lines in fortran

白昼怎懂夜的黑 提交于 2019-11-27 08:47:32
问题 I want to copy a file from a folder and write at specific lines of the file using fortran. I am using Windows, GNU fortran compiler. Here is sample file and code. file1.txt 1 * 2 ** 3 *** 4 **** 5 ***** 6 ****** 7 ******* 8 ******** 9 ********* 10 ********** Here is code: I defined some variables. Only if two criteria match (particular variable value and line number), I want to write in the new text in the file. I tried using system command to copy, but it fails. Can anyone tell me correct

Assumed string length input into a Fortran function

為{幸葍}努か 提交于 2019-11-27 08:23:42
问题 I am writing the following simple routine: program scratch character*4 :: word word = 'hell' print *, concat(word) end program scratch function concat(x) character*(*) x concat = x // 'plus stuff' end function concat The program should be taking the string 'hell' and concatenating to it the string 'plus stuff'. I would like the function to be able to take in any length string (I am planning to use the word 'heaven' as well) and concatenate to it the string 'plus stuff'. Currently, when I run

Converting a string to an integer in Fortran 90

痴心易碎 提交于 2019-11-27 07:41:29
问题 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? 回答1: You can read a string into an integer variable: module str2int_mod contains elemental subroutine str2int(str,int,stat) implicit none ! Arguments

Function in fortran, passing array in, receiving array out

。_饼干妹妹 提交于 2019-11-27 05:30:00
I have this function, depicted below. It passes in two vectors with three values each, and should pass out one vector with three values as well. I call the function like this: Fr = Flux(W(:,i),W(:,i+1)) What I have realized through messing around with the code, trying pure functions, and modules, and researching the error statement (that I will include at the bottom), is that fortran is reading my function Flux, and thinks that the input vectors are an attempt to call an entry from the array. That is my best guess as to what is going on. I asked around the lab and most people suggested using

Procedure with assumed-shape dummy argument must have an explicit interface [duplicate]

∥☆過路亽.° 提交于 2019-11-27 05:13:26
This question already has an answer here: Module calling an external procedure with implicit interface 1 answer I am completely new to Fortran 90 and I am trying to understand how to pass an array to a function. I looked on the web and I could not find any clear and simple enough example, so I decided to post here. I would like the function be able to work on an array of any length (the length of the array should not be one of the parameters of the functions). I tried to write a simple example of a function that returns the sum of the elements of an array: function mysum(arr) implicit none