fortran90

Opening multiple files in Fortran 90

空扰寡人 提交于 2019-12-01 07:52:46
问题 I would like to open 10,000 files with file names starting from abc25000 until abc35000 and copy some information into each file. The code I have written is as below: PROGRAM puppy IMPLICIT NONE integer :: i CHARACTER(len=3) :: n1 CHARACTER(len=5) :: cnum CHARACTER(len=8) :: n2 loop1: do i = 25000 ,35000 !in one frame n1='abc' write(cnum,'(i5)') i n2=n1//cnum print*, n2 open(unit=i ,file=n2) enddo loop1 end This code is supposed to generate files starting from abc24000 until abc35000 but it

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

这一生的挚爱 提交于 2019-12-01 00:49:18
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? As noted in the question, the problem is that when a character expression of length shorter than the output field width the padding spaces appear before the character expression. What we

vim doesn't recognize columns beyond 72 with fortran90 code

妖精的绣舞 提交于 2019-11-30 23:47:36
I am editing a fortran90 code with vim. Note that I'm working with a *.f90 file, not *.f. vim doesn't recognize as legitimate code anything beyond column 72. This is an annoying problem because if a quote is opened at, say, column 50 but not closed until column 80, then vim colors all the following lines as part of the same quote. This would make sense if I was working with an old fortran77 file, but I'm clearly not. Is there any way to convince vim to recognize code beyond column 72? if I create a new .f90 file syntax is highlighted as if it is fortran 77 (fixed line length, comments in first

array of arrays in fortran

对着背影说爱祢 提交于 2019-11-30 23:44:38
I am trying to define a array of arrays. I have defined: integer,dimension(2,2):: & x=reshape(source= (/0,1,1,0/), shape=(/2,2/)), & y=reshape(source= (/1,0,0,1/), shape=(/2,2/)), & z=reshape(source= (/1,1,1,1/), shape=(/2,2/)) I want to define an array, say, s(3), of which, (x/y/z) are components, i.e. s(1)=x s(2)=y and s(3)=z how can I achieve that? The simplest approach might be to define s as a rank-3 array, perhaps integer, dimension(3,2,2) :: s and then you can write statements such as s(1,:,:) = x s(2,:,:) = y ... This is the 'natural' way to implement an array of arrays in Fortran. An

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

我们两清 提交于 2019-11-30 21:05:17
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 same length it works but I can't do that for obvious reasons. I have compiled both with gfortran and

array of arrays in fortran

╄→гoц情女王★ 提交于 2019-11-30 18:05:43
问题 I am trying to define a array of arrays. I have defined: integer,dimension(2,2):: & x=reshape(source= (/0,1,1,0/), shape=(/2,2/)), & y=reshape(source= (/1,0,0,1/), shape=(/2,2/)), & z=reshape(source= (/1,1,1,1/), shape=(/2,2/)) I want to define an array, say, s(3), of which, (x/y/z) are components, i.e. s(1)=x s(2)=y and s(3)=z how can I achieve that? 回答1: The simplest approach might be to define s as a rank-3 array, perhaps integer, dimension(3,2,2) :: s and then you can write statements

How to do block comment in fortran?

北慕城南 提交于 2019-11-30 17:22:49
I have seen /* block comment */ for block commenting in C++. I know I can do line commenting by using ! or c , but is there any option for block commenting in Fortran? No, the strange concept of block comments is alien to Fortran. Your editor or development environment might provide a way to comment a block of lines in one go. You can do a little hack though: go to 100 ! CHUNK OF CODE YOU WANT TO COMMENT OUT 100 continue Yeah, I know it's horrible but it works. :) muraly If your FORTRAN compiler supports preprocessor macros then a popular method is to use ( What exactly does an #if 0 .....

How to do block comment in fortran?

守給你的承諾、 提交于 2019-11-30 16:33:06
问题 I have seen /* block comment */ for block commenting in C++. I know I can do line commenting by using ! or c , but is there any option for block commenting in Fortran? 回答1: No, the strange concept of block comments is alien to Fortran. Your editor or development environment might provide a way to comment a block of lines in one go. 回答2: You can do a little hack though: go to 100 ! CHUNK OF CODE YOU WANT TO COMMENT OUT 100 continue Yeah, I know it's horrible but it works. :) 回答3: If your

Creating directory with name containing real number in FORTRAN

橙三吉。 提交于 2019-11-30 16:25:05
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 !Open file a.csv and b.csv with unit 1 & 2 !Write header information in file a.csv and b.csv close

Can GDB be used to print values of allocatable arrays of a derived type in Fortran 90? [duplicate]

老子叫甜甜 提交于 2019-11-30 14:46:55
This question already has an answer here: Fortran print allocatable array in gdb 3 answers I have the following data structure in a Fortran90 program: TYPE derivedType CHARACTER(100) :: name = ' ' INTEGER :: type = 0 REAL(KIND(1.0D0)) :: property = 0.0 END TYPE derivedType TYPE (derivedType), ALLOCATABLE, DIMENSION(:) :: arrayOfDerivedTypes When I try to debug and print values in GDB like: (gdb) p arrayOfDerivedTypes(1)%name I get non-sensical values (often strings of zeros, forward slashes and letters), or completely wrong values (like arrayOfDerivedTypes(1)%name = 9, when I know that it is =