fortran90

Function has no implicit type

喜夏-厌秋 提交于 2019-11-28 01:51:29
I am trying to learn to work with functions. I have the following code: program main implicit none write(*,*) test(4) end program integer function test(n) implicit none integer, intent(in) :: n integer :: i, ans ans=1 do i=1,n ans=ans*i enddo test=ans end function test When I compile (with gfortran 4.1.2), I get the following error: In file test.f90:4 write(*,*) test(4) 1 Error: Function 'test' at (1) has no IMPLICIT type Move the line end program to the end of your source file and, in its place, write the line contains As you have written your program it has no knowledge of the function test

Module calling an external procedure with implicit interface

孤人 提交于 2019-11-28 00:33:35
The following code, combining module procedures and external procedures : module module_dummy implicit none contains subroutine foo(a) real, intent(inout) :: a(:) call bar(a) end subroutine foo end module module_dummy program main use module_dummy implicit none integer, parameter :: nelems = 100000000 real, allocatable :: a(:) allocate( a(nelems) ) a = 0.0 call foo(a) print *, a(1:10) deallocate(a) end program main subroutine bar(a) implicit none real, intent(inout) :: a(:) a = 1.0 end subroutine bar seems to fail either: with a segmentation fault printing a block of 0.000 instead of a block

Passing strings for execution in Fortran subroutines

為{幸葍}努か 提交于 2019-11-28 00:30:24
In the following subroutine I would like to pass a string variables named str . If it is 'poly' , 'gaus' , 'slat' , then it has a predefined action ( fval = see code below ). I would like to have the user specify a function to use and pass that as a string variable. That is ... If str = '3*cos(i*t)' , then i would like to have fval be equal to 3*cos(i*t) . How can I get Fortran to interpret the string entered as a command to be executed by Fortran? subroutine f(fval, i, t, str) implicit none integer, parameter :: ikind = selected_int_kind(8) integer, parameter :: dbl = selected_real_kind(15

gfortran does not allow character arrays with varying component lengths

試著忘記壹切 提交于 2019-11-28 00:16:13
See the example below program test character(10),dimension(5):: models = (/"feddes.swp", "jarvis89.swp", "jarvis10.swp" , "pem.swp", "van.swp"/) end The following error is returned: Different CHARACTER lengths (10/12) in array constructor at (1) There is no error with ifort compiler. Why does it happen with gfortran and is there any way to circumvent this problem? francescalus You have some lengths 12 in the constructor, so it may be better to use length 12. Also, use instead character(len=12), dimension(5) :: models = [character(len=12) :: "feddes.swp", & "jarvis89.swp", "jarvis10.swp", "pem

Best way to write a large array to file in fortran? Text vs Other

被刻印的时光 ゝ 提交于 2019-11-27 19:30:20
I wanted to know what the best way to write a large fortran array ( 5000 x 5000 real single precision numbers) to a file. I am trying to save the results of a numerical calculation for later use so they do not need to be repeated. From calculation 5000 x 5000 x 4bytes per number number is 100 Mb, is it possible to save this in a form that is only 100Mb? Is there a way to save fortran arrays as a binary file and read it back in for later use? I've noticed that saving numbers to a text file produces a file much larger than the size of the data type being saved. Is this because the numbers are

How can I implement a linked list in fortran 2003-2008

≯℡__Kan透↙ 提交于 2019-11-27 18:35:58
问题 I need to implement a link list data structure for my molecular dynamics code in fortran 2003/2008 I am using the newest fortran compilers (Intel). How do I come about implement the linked list in the best way possible I would prefer a lock-free no wait implementation if possible in Fortran. Thank you. 回答1: It is easiest if you create a user defined type with your data items and the pointer to the next item. This is assuming a singly-linked list. e.g., type MyList_type integer :: FirstItem

What are the ways to pass a set of variable values through the subroutine to a function without common block?

梦想与她 提交于 2019-11-27 16:23:56
I do not want to use common blocks in my program. My main program calls a subroutine which calls a function. The function needs variables from the subroutine. What are the ways to pass the set of information from the subroutine to the function? program ... call CONDAT(i,j) end program SUBROUTINE CONDAT(i,j) common /contact/ iab11,iab22,xx2,yy2,zz2 common /ellip/ b1,c1,f1,g1,h1,d1,b2,c2,f2,g2,h2,p2,q2,r2,d2 call function f(x) RETURN END function f(x) common /contact/ iab11,iab22,xx2,yy2,zz2 common /ellip/ b1,c1,f1,g1,h1,d1,b2,c2,f2,g2,h2,p2,q2,r2,d2 end What you care about here is association :

How to debug Fortran 90 compile error “There is no specific subroutine for the generic 'foo' at (1)”?

纵饮孤独 提交于 2019-11-27 16:22:09
I am trying to write Fortran 2003 bindings to CUFFT library using iso_c_bindings module, but I have problems with cufftPlanMany subroutine (similar to sfftw_plan_many_dft in FFTW library). The bindings itself look like this: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! ! cufftResult cufftPlanMany(cufftHandle *plan, int rank, int *n, ! int *inembed, int istride, int idist, ! int *onembed, int ostride, int odist, ! cufftType type, int batch) ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! interface cufftPlanMany subroutine cufftPlanMany(plan

Fortran intent(inout) versus omitting intent

僤鯓⒐⒋嵵緔 提交于 2019-11-27 13:06:09
Good practice dictates that subroutine arguments in Fortran should each have a specified intent (i.e. intent(in) , intent(out) or intent(inout) as described this question ): subroutine bar (a, b) real, intent(in) :: a real, intent(inout) :: b b = b + a ... However, not specifying an intent is valid Fortran: subroutine bar (a, b) real, intent(in) :: a real :: b b = b + a ... Are there any real differences beyond compile time checking for an argument specified as intent(inout) and an argument without a specified intent? Is there anything I should worry about if I'm retrofitting intents to older,

How do you USE Fortran 90 module data

拥有回忆 提交于 2019-11-27 12:20:46
Let's say you have a Fortran 90 module containing lots of variables, functions and subroutines. In your USE statement, which convention do you follow: explicitly declare which variables/functions/subroutines you're using with the , only : syntax, such as USE [module_name], only : variable1, variable2, ... ? Insert a blanket USE [module_name] ? On the one hand, the only clause makes the code a bit more verbose. However, it forces you to repeat yourself in the code and if your module contains lots of variables/functions/subroutines, things begin to look unruly. Here's an example: module