fortran90

How can I assign a number or value of variable into a character in Fortran77/90

夙愿已清 提交于 2019-12-19 10:04:53
问题 Suppose, I'm using a real variable x. I want to assign as a character so that I can use it for printing different filenames depending on the values of x in a do-loop. My present code is: program test_print real*8:: x character*40:: chr_x x=1.d0 do i=1,6 write(chr_x,*) x open (unit=10, file="test_x_"//trim(adjustl(chr_x))//".dat") write(10,*)i,x x=x+0.2d0 ! Update x close(10) end do stop end program test_print Now this generates files with filenames: test_x_1.0000000000000000.dat test_x_1

Format: add trailing spaces to character output to left-justify

你。 提交于 2019-12-19 04:15:09
问题 How do you format a string to have constant width and be left-justified? There is the Aw formatter, where w denotes desired width of character output, but it prepends the spaces if w > len(characters) , instead of appending them. When I try 44 format(A15) print 44, 'Hi Stack Overflow' I get > Hi Stack Overflow< instead of >Hi Stack Overflow < Is there any simple Fortran formatting solution that solves this? 回答1: As noted in the question, the problem is that when a character expression of

Format: add trailing spaces to character output to left-justify

六月ゝ 毕业季﹏ 提交于 2019-12-19 04:15:07
问题 How do you format a string to have constant width and be left-justified? There is the Aw formatter, where w denotes desired width of character output, but it prepends the spaces if w > len(characters) , instead of appending them. When I try 44 format(A15) print 44, 'Hi Stack Overflow' I get > Hi Stack Overflow< instead of >Hi Stack Overflow < Is there any simple Fortran formatting solution that solves this? 回答1: As noted in the question, the problem is that when a character expression of

Creating directory with name containing real number in FORTRAN

核能气质少年 提交于 2019-12-18 18:06:52
问题 In my program I need to store result files for different cases. I have decided to create separate directories to store these result files. To explain the exact situation here is a pseudo code. do i=1,N ! N cases of my analysis U=SPEED(i) call write_files(U) !Create a new directory for this case and Open files (1 = a.csv, 2 = b.csv) to write data call postprocess() !Write data in files (a.csv, b.csv) call close_files() !Close all files (1,2) end do subroutine write_files(i) !Make directory i

Function Returning an array in Fortran

做~自己de王妃 提交于 2019-12-18 12:12:09
问题 It is my understanding that you can return an array from a function in Fortran, but for some reason my code is only returning the first value in the array I am asking it to return. This is the function: function polynomialMult(npts,x,y) integer npts double precision x(npts), results(npts + 1), y(npts,npts) polynomialMult = x(1:npts) + 1 end function and this is where I'm calling it C(1:numPoints) = polynomialMult(numPoints,x,f) print *, C(1:numPoints)` right now it doesn't do anything useful

Stack overflow in Fortran 90

橙三吉。 提交于 2019-12-18 11:58:51
问题 I have written a fairly large program in Fortran 90. It has been working beautifully for quite a while, but today I tried to step it up a notch and increase the problem size (it is a research non-standard FE-solver, if that helps anyone...) Now I get the "stack overflow" error message and naturally the program terminates without giving me anything useful to work with. The program starts with setting up all relevant arrays and matrices, and after that is done it prints a few lines of stats

Simple program, that only produce zeros, bug? [duplicate]

北城余情 提交于 2019-12-18 09:35:02
问题 This question already has an answer here : Why are the elements of an array formatted as zeros when they are multiplied by 1/2 or 1/3? (1 answer) Closed 2 years ago . Why does this fortran program produce only zeros? When I print it out i get -0.00000 everywhere! What have I done wrong? In matlab it runs perfectly. I dont see any reason why its not working to be honest! It seems like its the fraction that messes it up. if I set x equal to some decimal number it works. program main implicit

GFortran and CodeBlocks issue with Modules and Multiple Files

南楼画角 提交于 2019-12-18 07:14:07
问题 I am working with GFortran and CodeBlocks but I'm having an issue about Modules and Multiple files. i keep getting this error: Fatal Error: Can't open module file 'mesh.mod' for reading at (1): No such file or directory For some reason, GFortran is not building the 'mesh.mod' file. This problem does not occur when I put all the code in a single .f90 file. Bellow is an example of code that this error happens. main.f90 MODULE MESH IMPLICIT NONE INTEGER :: IMAX,JMAX,NMAX REAL(8), ALLOCATABLE ::

Fortran 90 how to write very long output lines of different length

↘锁芯ラ 提交于 2019-12-18 06:57:27
问题 I've spent hours scouring the internet for a solution to this problem and can't find anything. I have been trying to write unformatted output to a CSV output file with multiple very long lines of varying length and multiple data types. I'm trying to first write a long header that indicates the variables that will be written below, separated by commas. Then on the lines below that, I am writing the values specified in the header. However, with sequential access, the long output lines are

How to make some generic programming in fortran 90/95 working with intrinsic types

a 夏天 提交于 2019-12-18 06:55:04
问题 I would like to program some procedure that will work with different types. I am planning to use the "include" method used in flibs described here and here. I give here a simple exemple. ! -------------------------------------------------------------- ! module data_type type ivalue integer :: v end type type rvalue real(8) :: v end type end module data_type ! -------------------------------------------------------------- ! module imod use data_type, only: T => ivalue include "template.f90"