fortran90

Cannot print subsequent rows of array to file

久未见 提交于 2019-12-11 17:54:54
问题 I'm trying to write a rudimentary bit of code to print a 50*50 array called 'arr'. Unfortunately it so far only prints the first row of the array, although the formatting for that row is correct. I've attached the code below and was wondering if anyone could point out where I was going wrong? Thank you! program testing implicit none integer :: i, j integer, dimension (1:50, 1:50) :: arr arr = 1 do i=1,50 open(unit=6, file= "array.txt", action="write") write(6, '(2500I3)') (arr(i,j), j=1,50)

Real data type fortran 90

可紊 提交于 2019-12-11 14:25:28
问题 A simple question. A similar question was there, but I did not get the exact one I am looking for. I was just checking the limits of real data type in fortran 90 (using ifort compiler), reason being my actual code might reach that limit. To test, I simply gave a parameter mval1 (see code) and multiplied by 2. In ifort manual it says that the maximum value it can take is 10E38 and my value is much smaller than this. But while printing it is taking random digits towards the end (output is given

fortran write output: all variables in a line

老子叫甜甜 提交于 2019-12-11 13:48:56
问题 sorry, I try to write a file.dat whit a lot of columns (11) with different format (1.4e-12, 10...) when i try ro write the code i use the following fortran command: WRITE(7,*) id,t,a,e,inc,capom,omega,capm,mass,radius but each line in the original file is now write in multiply lines. From: 1222221 0.0 10.0 0.0 3.1415927 0.0 0.0 3.7828348 9.0E-9 4.0E-6 to: 1222221 0.000000000000000E+000 10.0000000000000 0.000000000000000E+000 0.000000000000000E+000 0.000000000000000E+000 0.000000000000000E+000

Are implied DO loops inefficient?

浪子不回头ぞ 提交于 2019-12-11 13:33:26
问题 I have an array initialization based on an implied do loop, given an odd size N . J=(N+1)/2 XLOC(1:N) = (/ (I-J, I=1,N) /) In the context of F90+ is it recommended to use the (/ .. /) syntax, or is more efficient to use a FORALL statement. Example: for N=19 then XLOC=(-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9) How else would you initialize this array? Edit 1 How would you initialize this array with more readable code? 回答1: For such a simple construct both are likely to lead to the same

n nested for loops in fortran90

孤街浪徒 提交于 2019-12-11 09:08:26
问题 i have read some topics on this, but i don't quite think it answers my question. if it does then please direct me to the correct topic and i will definitely look again. here is my problem: i want to write a for loop which will cycle through every possible combination of an array where the array is of length 'n'. that is, if n = 2 then my for loop would be do i1 = 1,2 do i2 = 1,2 ! do stuff here enddo enddo while if n = 3 then my array would look like do i1 = 1,3 do i2 = 1,3 do i3 = 1,3 ! do

Meaning of filelocation = “../”//filename

。_饼干妹妹 提交于 2019-12-11 08:28:27
问题 filelocation = "../"//filename PRINT *, "Attempting to open ", TRIM(filename) OPEN(fh1, FILE = filelocation, STATUS='old',IOSTAT = io) Can anyone tell me please what is the meaning of "../"// in the first line? 回答1: The string ../ is Linux for the parent directory of the current working directory . This may or may not work on a Windows machine. The two characters // represent the Fortran operator for string concatenation. So "../"//filename sets filelocation to refer to a file named filename

Subroutine not returning correct numerical values in assumed shape array due to index renaming in the main program

风格不统一 提交于 2019-12-11 08:28:24
问题 The argument of my fortran 95 subroutine is an assumed shape array with intent inout: the_subroutine(my_argument) real, dimension(:,:), intent(inout) :: my_argument (...) In the main program, I have an allocatable array. I allocate it and also rename indexes . Then I call the subroutine and pass that (correctly allocated) array to the subroutine: allocate(the_array( 5:1005 , 5:1005 )) call the_subroutine(my_argument=the_array) The subroutine does certain calculations and fills the array with

Array inside type array as function argument

心已入冬 提交于 2019-12-11 07:48:06
问题 I have the following program at hand program foo type bar real, dimension(2) :: vector end type type(bar), dimension(3) :: bararray call doSomething(bararray%vector) end program subroutine doSomething(v) real, dimension(3,2), intent(inout) :: v ... end subroutine Now this gives me a compilation error. Error: Two or more part references with nonzero rank must not be specified at (1) If I change the call to call doSomething((/bararray%vector(1), bararray%vector(2)/)) everything works out nicely

function returning array with no defined explicit shape

夙愿已清 提交于 2019-12-11 07:29:32
问题 I am wondering how to return an array from a function without any knowledge of the shape until runtime (including assumed shape arrays). I'll explain with examples. This works module foo contains function getArray(:) real :: getArray(3) integer :: i do i=1,3 getArray(i) = 10.0*i enddo end function end module program xx use foo real :: array(3) integer :: i array = getArray() print *, array end program This also works, because it makes use of automatic arrays module foo contains function

Trouble using function name as argument in Fortran

妖精的绣舞 提交于 2019-12-11 06:59:41
问题 I wanted to make it easier to change a certain function which will be used by a subroutine in a fortran project. However I can not get it to work. I have seen quite a few examples which use the external , however I am not sure if I have to use it, since I put all my function and subroutines in modules. Here is a simplified example of the problem I am dealing with: I have the program in a separate file: program test use Parameters use circArrayConstructer use velocity use RungeKutta4 implicit