fortran2003

Problems with parametrized derived types in Fortran 2003

吃可爱长大的小学妹 提交于 2019-12-02 12:27:48
问题 I'm teaching myself Fortran 2003 to use for a research project I'm currently working on. I'm used to Fortran 90, but this project requires the use of parametrized types, and so I'm moving on to 2003. I was following this site's description of how to define a parametrized type, and wrote a very simple example program based on the site's example to test it out: module example implicit none type :: param_matrix(k,a,b) integer, kind :: k integer, len :: a integer, len :: b real(kind=k), dimension

Passing an allocatable character to a subroutine with unlimited polymorphic dummy argument in Fortran

痞子三分冷 提交于 2019-12-02 08:57:59
问题 I'm trying to write a routine that is able to convert a string into different kinds of data type, based on unlimited polymorphism. The idea is the user call this routine, passing the variable where it wants to store the data, and the routine to define the conversion based on the variable/argument type. An excerpt of this routine is here: subroutine GetAsScalar (this, value, status) !Arguments------------------------------------------------------------- class(TKeyword) :: this class(*) ::

Will the attempt to read an improper value into a variable change its value?

风格不统一 提交于 2019-12-02 05:59:20
问题 If the iostat keyword is present, a program does not stop if an I/O error occurs. Then, if I try to read an improper value into a scalar variable, i say, will this variable remain unchanged? The following seems to work: program test integer :: i, stat i = 1 do write (*, "('i = ')", advance='no') read (*, *, iostat=stat) i if (stat .eq. 0) then write (*, "('Valid integer. i has been set to ', I0)") i else write (*, "('Bad integer. i is still ', I0)") i end if end do end program test Can I rely

Fortran array with dynamic size, as easy the R function seq()

这一生的挚爱 提交于 2019-12-01 12:19:57
I would like to write Fortran code that works like the R function seq(). E.g.: x <- seq(0,1,0.1) will give the vector x <- c(0, 0.1, 0.2, ..., 1) I will run several simulations over which the length of the sequence will change, in R this is easily done, by just varying the second argument in seq(). I have tried to do something like this in Fortran with dynamical arrays and the function ALLOCATE to dynamically change the size of the array. This has not worked so far and lead to the error Program received signal SIGSEGV: Segmentation fault - invalid memory reference. Backtrace for this error: #0

Fortran array with dynamic size, as easy the R function seq()

穿精又带淫゛_ 提交于 2019-12-01 10:26:42
问题 I would like to write Fortran code that works like the R function seq(). E.g.: x <- seq(0,1,0.1) will give the vector x <- c(0, 0.1, 0.2, ..., 1) I will run several simulations over which the length of the sequence will change, in R this is easily done, by just varying the second argument in seq(). I have tried to do something like this in Fortran with dynamical arrays and the function ALLOCATE to dynamically change the size of the array. This has not worked so far and lead to the error

Hexadecimal Constants

我的未来我决定 提交于 2019-12-01 07:41:19
问题 I want to declare an integer parameter based on its hexadecimal representation. What are the differences between: INTEGER(kind=int32), PARAMETER :: a = Z'FFFFFFFF' INTEGER(kind=int32), PARAMETER :: b = int(Z'FFFFFFFF', kind=int32) INTEGER(kind=int32), PARAMETER :: c = transfer(Z'FFFFFFFF', 1_int32) (And yes, I know that this is just -1 .) gfortran seems to give me an integer overflow error during compile (helpfully telling me that I can ignore that with -fno-range-check ) for the above a and

Is there an alternative to GETCWD() in Fortran 2003-2008

萝らか妹 提交于 2019-12-01 06:20:25
The GNU Extension to the GNU Fortran compiler provides the subroutine GETCWD() that well, gets the current working directory. However, my code has to be portable to the ifort and nagfor compiler as well and I use F2003 features. So, is there an alternative to GETCWD() for F2003 and later? I have the standard here but it's quite sizeable and I've been going through it for a while now and haven't found anything useful... You can also use the ISO_C_Binding and call the corresponding C functions: cwd.c: #ifdef _WIN32 /* Windows */ #include <direct.h> #define GETCWD _getcwd #else /* Unix */

Difference between type and class in fortran 2003

旧街凉风 提交于 2019-11-30 18:36:28
I have been told for my PhD that I have to learn fortran 2003 language. I have never used and OOP program before nor fortran. I am trying to understand what the difference between type and class is. I know that classes are declared with the 'TYPE' keyword but I have also seen examples of the keyword 'CLASS' being used used so I am getting confused. Hope that makes sense. The keyword type is used to declare derived types -- best not to get into the habit of thinking, perhaps imported from foreign languages, that type is used for declaring something called classes . The keyword class is used, in

Difference between type and class in fortran 2003

烈酒焚心 提交于 2019-11-30 02:44:45
问题 I have been told for my PhD that I have to learn fortran 2003 language. I have never used and OOP program before nor fortran. I am trying to understand what the difference between type and class is. I know that classes are declared with the 'TYPE' keyword but I have also seen examples of the keyword 'CLASS' being used used so I am getting confused. Hope that makes sense. 回答1: The keyword type is used to declare derived types -- best not to get into the habit of thinking, perhaps imported from

Does the finalization routine need to be elemental in order to be called on the elements of allocatable array that goes out of scope?

北城以北 提交于 2019-11-29 15:44:44
If I have an allocatable array of a finalizable derived type, will the finalizer be called on every individual element when the array goes out of scope? Here is a small code example that illustrates the question: module LeakyTypeModule implicit none private type, public :: LeakyType real, pointer :: dontLeakMe(:) => null() contains procedure :: New final :: Finalizer end type contains subroutine New(self, n) class(LeakyType), intent(out) :: self integer , intent(in) :: n allocate(self%dontLeakMe(n)) self%dontLeakMe = 42.0 end subroutine subroutine Finalizer(self) type(LeakyType), intent(inout)