fortran90

Test whether a directory exists or not

倖福魔咒の 提交于 2019-12-04 13:29:18
问题 I'm trying to verify that a directory exists using Fortan90. On various sites I found: logical :: dir_e inquire(file='./docs/.', exist=dir_e) if ( dir_e ) then write(*,*) "dir exists!" else ! workaround: it calls an extern program... call system('mkdir docs') end if However, inquire returns False whether or not the directory exists and if I execute this code twice, I get an error message cannot make dir, file already exists If I use: inquire(file='./docs/test', exist=dir_e) with an existing

Removing whitespace in string

淺唱寂寞╮ 提交于 2019-12-04 13:00:17
I have the following code: program main character (len=15) :: abc = "te st tex t" print *, trim(abc) end program main Which outputs: te st tex t I excepted all the whitespace to be removed but it wasn't. How can I remove all the whitespace from the string? Trim will remove spaces only at the edges, not in the middle (this is common behaviour on almost all languages/libraries). If you want to remove all spaces in the string, you will have to create your own function to do this, iterating through the string. Ex.: program Test implicit none ! Variables character(len=200) :: string ! Body of Test

Write data to file in columns (Fortran)

偶尔善良 提交于 2019-12-04 05:43:00
I need to write some data to file in Fortran 90. How should I use WRITE (*,*) input to have the values grouped in columns ? WRITE always puts a new line after each call, that's the problem. code example: open (unit = 4, file = 'generated_trajectories1.dat', form='formatted') do time_nr=0, N write (4,*) dble(time_nr)*dt, initial_traj(time_nr) end do And now the point is to have it written in separate columns. You can use implied DO loops to write values as single records. Compare the following two examples: integer :: i do i=1,10 write(*,'(2I4)') i, 2*i end do It produces: 1 2 2 4 3 6 ... Using

integer, do loop, fortran, error

风格不统一 提交于 2019-12-04 05:35:53
问题 I have the following fortran code defined under. I am trying to change the length of the do loop if i change the value of n. When i try to compile i get the error: ‘a’ argument of ‘floor’ intrinsic at (1) must be REAL. But when i change q and w to be defined as real i get another error message. How can i fix this? q and w is clearly a integer when i use floor(...) subroutine boundrycon(n,bc,u,v) !input integer :: n,bc !output real(8) :: u(n+2,n+2), v(n+2,n+2) !lokale integer :: j,i,w,q n=30 q

How to get rid of unwanted spacing in Fortran's print output?

爷,独闯天下 提交于 2019-12-04 03:54:34
问题 It may look like a trivial issue, but I couldn't find any answer through googling. I have this little program : Program Test_spacing_print Integer:: N Real:: A,B N=4; A=1.0; B=100.0 print*,'N =',N print*,'A =',A,' B =',B print '(2(A3,F8.2,1X))' ,'A =',A,' B =',B print 20, A,B 20 format('A =',F8.2,x,'B =',F8.2) End Program Test_spacing_print which gives me the output: N = 4 A = 1.00000000 B = 100.000000 A = 1.00 B 100.00 A = 1.00 B = 100.00 I want to get rid of the unwanted space that I get

keeping array limits in fortran during subroutine call

我只是一个虾纸丫 提交于 2019-12-04 03:27:09
问题 I have the following program module test contains subroutine foo() integer, allocatable :: a(:) allocate(a(-5:5)) call bar(a) print *, a end subroutine subroutine bar(a) integer, intent(out) :: a(:) a = 0 a(-4) = 3 ! here a(2) = 3 end subroutine end module program x use test call foo() end program In the line marked with "here" I am doing something wrong. The fact is that when I receive the array a (in the caller allocated from -5 to +5), the callee uses conventional numbering (1 to n),

Fortran 90 Presence Of Optional Arguments

怎甘沉沦 提交于 2019-12-04 00:48:03
问题 I do not understand the behavior of the present() intrinsic function with pgf90 7.2. I wrote a 20 line sample program to test this, but the results still make no sense to me. Observe: subroutine testopt(one,two,three,four,five) implicit none integer, intent(in) :: one,two integer, intent(out) :: three integer, intent(in), optional :: four integer, intent(out), optional :: five three = one + two print *,"present check: ",present(four),present(five) if (present(four) .and. present(five)) then

vim doesn't recognize columns beyond 72 with fortran90 code

一笑奈何 提交于 2019-12-03 21:35:50
问题 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? 回答1: if

The mysterious nature of Fortran 90 modules

∥☆過路亽.° 提交于 2019-12-03 12:44:29
Fortran 90 modules are evanescent creatures. I was using a (singular) module for a while with some success (compiling using Intel Visual Fortran and Visual Studio 2010). Then I wrote another module and tried to USE it in another function, before receiving this error: error #7002: Error in opening the compiled module file. Check INCLUDE paths. So I deleted the offending module. But now I receive the same error after when trying to access my original module! How can I locate these mysterious creatures? Why does one module work but not two? I'm assuming that I need to delete and recompile them,

Fortran 90 compiling issue: undefined reference to <modulename>

↘锁芯ラ 提交于 2019-12-03 12:03:24
I'm having trouble trying to compile a simple fortran program which uses a module in the same directory. I have 2 files: test1.f90 which contains the program and modtest.f90 which contains the module. This is test1.f90: program test use modtest implicit none print*,a end program test This is modtest.f90: module modtest implicit none save integer :: a = 1 end module modtest Both files are in the same directory. I compile modtest.f90 and test.f90 like this: gfortran -c modtest.f90 gfortran -o test1 test1.f90 But then I get this error: /tmp/cckqu8c3.o: In function `MAIN__': test1.f90:(.text+0x50)