FAQ Database Discussion Community


Using allocatable/assumed-size arrays with namelist read write

io,fortran,intel-fortran,fortran2003
I am using VS2012 and Intel Visual Fortran 2015. According to https://software.intel.com/en-us/forums/topic/269585, it is now allowed to use allocatable and assumed-size arrays with namelist read and write; however, I am still getting the error "A namelist-group-object must not be an assumed-size array". example code: subroutine writeGrid(fname, grid) character*(*) :: fname...

Percentage of various Floating Point Operations in SPEC CPU Benchmarks

c++,math,floating-point,fortran,benchmarking
I am looking at the SPEC CPU2006 benchmark website for floating-point: SPEC 2006 Floating Point I noticed that all of the benchmarks are listed but I couldn't find any information in regards to the percentage of basic floating point operations such as add/sub, mult, sqrt, div, etc. How would I...

Can I declare only specific elements of an array as constant? (C/C++/Fortran)

c++,c,arrays,fortran,constants
Scenario: I pass e.g. a 2D matrix as argument in a function and I would like to be able to read and change all the elements, BUT I would like to prevent any accidental writting in let's say the last column. So I would like somehow to tell the compiler...

How to read a text file into an array in Fortran

arrays,fortran
Is there any way to condense this code? . . real*4 a4,e4,inc4,capom4,omega4,capm4 integer*2 id2 real*8 array(1e7,8) . . row=0 do n=1,nleft+nbod2-1 row=row+1 read(iu) id2,a4,e4,inc4,capom4,omega4,capm4 array(row,1)=id2 array(row,2)=a4 array(row,3)=e4 array(row,4)=inc4 array(row,5)=capom4 array(row,6)=omega4 array(row,7)=capm4 end do . . I've tried about five different ways starting with an implied DO loop and all result...

Fortran READ(*,*), WRITE(*,*) arguments

fortran
This question has been covered somewhat in previous SO questions. However, previous discussions seem somewhat incomplete. Fortran has several I/O statements. There is READ(*,*) and WRITE(*,*), etc. The first asterisk (*) is the standard asterisk designating an input or output from the keyboard to/from the screen. My question is about...

Fortran: makefile error

makefile,fortran,fortran90
I have a fortran main program called solidsolver.f90, and a module called read_mesh.f90. The module contains two subroutines and is used in the main program. I can compile them manually but not with a makefile. My makefile is named makefile.makefile, and it gives me an error: make: *** No targets...

Fortran Seg Fault when assigning Matrices

matrix,segmentation-fault,fortran,derived-types
[UPDATE] the code and a few sentences were changed to reflect a realization explained in my second comment. The code should compile with the line below, however, I have an older gfortran and may not be seeing some errors that you might. gfortran BLU_implementation_copy.f90 -o BLU_implementation_copy.x I'm getting an incredibly...

how to stop a fortran program abnormally

fortran,fortran90
When an exception occurs I would like to terminate abnormally my program. Right now, when an exception happens a write statement with an explanatory sentence is called, and then a stop statement is called. I am debugging the program with idb (intel debugger), when the exception happens I get the...

How can a segfault happen at runtime only because of linking unused modules?

gcc,fortran,gfortran
I get a segmentation fault from a memory allocation statement just because I have linked some unrelated procedures to the binary. I have a very simple Fortran program: program whatsoever !USE payload_modules double precision,allocatable:: Vmat(:,:,:) allocate(Vmat(2,2,2)) Vmat=1 write(*,*) Vmat deallocate (Vmat) ! some more lines of code using procedures from...

Using move_alloc in a derived type

fortran,alloc,derived-types
I have written a derived type that stores a multidimensional array. The array will be read from a file to an array b. I then want to transfer b to the derived type Space using member a. The advantage for mvalloc is not having to allocate two large arrays which...

Link OSX Homebrew Gfortran against libc++

osx,fortran,libc++
I have a project with a large C++ component that I was able to successfully compile with clang on OSX (Apple LLVM version 6.1.0 (clang-602.0.49) (based on LLVM 3.6.0svn). Since OSX does not provide a Fortran compiler I installed gfortran via Homebrew. Compilation works fine, however I can not link...

Use Fortran-code in C

c,fortran,fortran-iso-c-binding
I try to use a fortran-routine in C, but I doesn't work. I don't know where I made a mistake. Here my Fortran-code including the Integration-Module, which I want to use in C: module integration implicit none contains function Integrate(func, a,b, intsteps) result(integral) interface real function func(x) real, intent(in) ::...

Syntax highlighting Fortran code in IPython notebook

fortran,syntax-highlighting,ipython-notebook
I want to include some Fortran code in my IPython notebook. How do I get the code snippet to be syntax highlighted ?

FORTRAN unformatted file write by each process

fortran,mpi,binaryfiles
In my parallel program, there was a big matrix. Each process computed and stored a part of it. Then the program wrote the matrix to a file by letting each process wrote its own part of the matrix in the correct order. The output file is in "unformatted" form. But...

Fortran subroutine overloading with submodules

fortran,intel-fortran
I'm learning Fortran and using the Intel compiler. Here is some code that I wrote. I want to define the print_array interface in the arraytools module, and all the specific implementations (e.g. print_array_rp) should go into a seperate sub-module. The following works, but if I split the implementation into a...

Assigning values of an array in a loop

arrays,loops,fortran,fortran90,gfortran
In my code: DO i=1,numJog,1 IF(val(i) .EQV. .TRUE.)THEN DO j=1,contVenc,1 result(j) = i END DO END IF END DO Where val is a logical array, and result is a integer array. For example, if val is: F T F T Then, i=2 and i=4. But the result array just write...

error: 'x' argument pf 'dtime' intrinsic at <1> must be of kind 4

fortran,gfortran
My understanding of programming is very limited so I hope I am making sense. I made a change to a fixed variable in a program (the program is called NAFnoise; I was using the .exe but it came with the source code and I made the change there). The program...

Confusion about kinds in FORTRAN

fortran,precision,hdf5,double-precision
I have been in the process of writing a FORTRAN code for numerical simulations of an applied physics problem for more than two years and I've tried to follow the conventions described in Fortran Best Practices. More specifically, I defined a parameter as integer, parameter:: dp=kind(0.d0) and then used it...

Argument Type Problems

casting,compiler-errors,fortran
Why am I getting the following error d = Atan ( 1_Real32 / 110443_Real32 ) 1 Error: 'x' argument of 'atan' intrinsic at (1) must be REAL or COMPLEX The funny thing is that I get no problems when I use d = Atan ( Real(1,Real32) / Real(110443,Real32) ) ...

Accessing open files globally in Fortran

file-io,fortran,gfortran
Is there any means to accessing (reading, writing to) files that are opened in some other source code by just passing the unit number?

Scope of subroutine parameters in FORTRAN 77

fortran,fortran77
I have a subroutine that declares i and passes it to other small subroutines. Within those small subroutines there are declared other variables with the same name, i.e i, and it is internally used. Once out of the small subroutines, one would expect to have the same i value that...

Unexpected Statement Function at 1 in Fortran

fortran,fortran77
I am new to Fortran and writing this small program to write out 100 ordered pairs for a circle. But I get the error mentioned above and I don't know how to resolve. implicit real*8(a-h,o-z) parameter(N=100) parameter(pi = 3.14159265358979d0) integer*8 k dtheta=2*pi/N r=1.0d0 x00=0.0d0 y00=0.0d0 do k=0,N-1 xb(k)=r*cos(k*dtheta)-x00 yb(k)=r*sin(k*dtheta)-y00 enddo...

Finding the intersect of two arrays in Fortran

arrays,fortran,fortran90,fortran95,set-intersection
I'm trying to generate the intersect of two 1-D arrays in Fortran. The intent is to use this intersection as a mask in maxloc so that I can pull the max few elements from one array into another (behavior analogous to repeated root removal in a max heap). Currently I...

Code crashes at runtime with Absoft Fortran but not with gfortran

fortran,gfortran
I'm running a script that starts similar to the code below. In the past when I ran the script f90 -o fakefile fakefile.f and then ./fakefile it worked, but now it does not and immediately returns a segmentation fault (core dumped) error. When I use gfortran fakefile.f and then ./a.out...

expm1 for GNU gfortran [closed]

fortran,gfortran,exp
Is there any way to call a fast implementation of expm1 from GNU Fortran? Ideally, it would be great to have a function to calculate (exp(x)-1)/x directly to avoid extra check for zero argument. Elemental version of expm1 would be especially helpful.

Fortran Subroutine that changes byte order

fortran
I have coded a routine in Fortran to perform reverse byte order. This will be equivalent to src="1234"; dst="4321". I want to change the routine to to arbitrary ordering specified using the variables src and dst to set the ordering positions. Here is the code for reverse byte ordering. Subroutine...

How to open and read a file

fortran,fortran90,fortran77,fortran95
I have this Fortran code that reads two columns of data from an external file: PRINT*, ' Q1 Q2 ' DO 2 J = 1, NPTS READ(20,*) Q1(J),Q2(J) WRITE(*,98) Q1(J),Q2(J) So the file 20 is used, but it doesn't seem to like any names I use in the file, so...

How to call Fortran routine with unit number argument from C

c,io,fortran,shared-libraries,abi
If I have a Fortran subroutine which takes a Fortran IO Unit as one of its parameters (for printing debug information to), and this function is compiled into a shared library, how do I correctly call this function from C? ! An example subroutine that I want to call from...

Disabling fp-model strict when using ifort with f2py

python,numpy,optimization,fortran,f2py
I'm using f2py to offload performance critical sections of my python code to fortran. I have two fortran compilers, gfortran and ifort. Since the code I run will be on intel processors, ifort is usually faster. But for the most critical part of my code, I observe the opposite, with...

Compile Fortran source with Accelerate Framework (LAPACK and BLAS) [duplicate]

osx,makefile,frameworks,fortran
This question already has an answer here: How to use LDFLAGS in makefile 2 answers I wish to compile Fortran source code which uses functions from LAPACK and BLAS. When I compile a single source code file e.g. gfortran -g -framework accelerate test.f it works. However, I have many...

Fortran + MPI: Issue with Gatherv

fortran,mpi
I am trying to distribute a 2D array using Scatterv, which works fine. However, the corresponding Gatherv operation gives an error: message truncated. Can someone explain what I am doing wrong. program scatterv use mpi implicit none integer, allocatable, dimension(:,:) :: array integer, allocatable, dimension(:) :: chunk integer, allocatable, dimension(:)...

Unclassifiable statement at (1) in Fortran

gcc,fortran,fortran90,gfortran
I am pretty new to to fortran and I don't really know why am I getting this error. integrand(i)=inte(x(i),beta,r2,r1) 1 Error: Unclassifiable statement at (1) calka11.f95:97.6: I have made all the variables into a module file and then call them using use and when I am getting those variables into...

How to make a random function in fortran to generate the same random distribution into array?

random,fortran,fortran90
I think my code below it's not exactly give me the same random distribution. subroutine trig_random_value() implicit none integer :: t, z, y, x real(real64) :: theta, r real(real64), parameter :: PI=4.D0*DATAN(1.D0) integer, dimension(12) :: date_time integer, dimension(12) :: seed call date_and_time(values=date_time) call random_seed seed = date_time(6) * date_time(7) +...

Using underscores to define kind/precision

fortran
I've been using using an underscore to define an integer as a specific kind in fortran. Here is a snippet of code to demonstrate what 1_8 means, for example: program main implicit none integer(2) :: tiny integer(4) :: short integer(8) :: long tiny = 1 short = 1 long =...

Compiling Fortran using Ifort for Linux under Windows

linux,windows,visual-studio-2010,fortran,intel-fortran
I develop an run some Fortran Code under Windows (7, 64bit) using Visual Stuido 2010 and ifort. The Code, mostly compiled to DLL, is tested in Windows and is deployd approx. 25% of the time to Windows (2000 up to 7) and 75% to Suse Linux. While the Windows solution...

Are the LAPACK routines thread safe?

multithreading,fortran,lapack,blas
I am a novice using the LAPACK routines, so I don't deeply know them, and I want to use them in parallelized loops (openmp). I use Ubuntu 14.04LTS and have LAPACK installed using my package manager. The version installed is: liblapack3 3.5.0-2ubuntu1 Library of linear algebra routines 3 - shared...

Read all the entries of a matrix using shell script

linux,shell,unix,fortran
I have a matrix, A(i,j), i=1,m and j=1,n I can read it in C and FORTRAN, but I can't read it in shell script. I know this is a very simple question, but I am very new to shell script. I want to read all entries and do some calculation...

Fortran Program Crashes when running

crash,fortran,fortran90,gfortran
I'm a starter in Fortran, using it to solve mathematical models in economics. I wrote a program (below) that is crashing when running. Windows show that message of error and nothing seems to happen. I haven't got a clue of what may be wrong, I already debugged it and it...

Compiling issue with ifort composer_xe_2015.3.187

compiler-errors,fortran
I am compiling my Fortran code with the latest Fortran compiler composer_xe_2015.3.187 on Ubuntu 14.04 64 bit system. I am using this compiler flag: -fp-model precise The error message is: f95: error: precise: No such file or directory f95: error: unrecognized command line option ‘-fp-model’ The same code does not...

C Wrapper Calling Fortran Functions

c,fortran,fortran90,gfortran,fortran-iso-c-binding
I'm trying to write a C wrapper to call a set of functions in a Fortran module. I'm starting with something basic but I'm missing something important. I've tried appending/prepending different numbers of underscores. I've also tried linking with gcc instead of gfortran. What I show below gives the simplest...

Fortran 90 Character array error

arrays,fortran,fortran90,gfortran
I have to calculate commissions for different interval of sales on different days and form a table "Day", "Sales", "Commissions". So far I've done this: real::a(5),b(5) character(10)::c(5)=(/Sunday,Monday,Tuesday,Wednesday,Thursday/) open(1,file='in_1.txt') open(2,file='out_1.txt') read(1,*)(a(i),i=1,5) do i=1,5 if(0.<a(i).and.a(i)<99.)then b(i)=a(i)*.02 elseif(100.<a(i).and.a(i)<299.)then b(i)=a(i)*.05 elseif(300.<a(i).and.a(i)<499.)then b(i)=a(i)*.075 else b(i)=500.*.1+(a(i)-500.)*.125 endif enddo write(2,*)' Day ','...

Fortran function variable length string return

string,function,fortran
I am writing a function to return a string function doc () Result s character (Len=65) :: s ... end function Is it possible to have a variable length string, where I can allocate the length of the string being returned. I know I can do it using a subroutine,...

Ambiguous reference to variable

gcc,fortran,fortran90,gfortran,intel-fortran
So I am doing 2 modules which are linking to the main program. The first one has all the variables defined in it and the second one is with the functions. Module1: module zmienne implicit none integer, parameter :: ngauss = 8 integer, parameter :: out_unit=1000 integer, parameter :: out_unit1=1001...

Fortran error: Program received signal SIGSEGV: Segmentation fault - invalid memory reference

cygwin,fortran
I'm try to run an ocean temperature model for 25 years using the explicit method (parabolic differential equation). If I run for a year a = 3600 or five years a = 18000 it works fine. However, when I run it for 25 years a = 90000 it crashes. a...

How can I avoid a stack overflow when Fortran RESHAPE produces a large, internal, temporary array?

stack,fortran,heap,stack-overflow,reshape
I have some Fortran code that calls RESHAPE to reorder a matrix such that the dimension that I am now about to loop over becomes the first varying dimension (Column-major order in Fortran). This has nothing to do with C/Fortran interoperability. Now the matrix is rather large and when I...

Fortran memory allocation does not give an error, but the program is killed by OS at initialization

memory-management,fortran
Given the minimal working example provided below, do you know why the memory allocation error does not occur at memory allocation step? As I checked, when I use valgrind to run the code, or add parameter source=0.0 to memory allocation statement, then I have, as expected, the memory allocation error....

Overriding a procedure with 'nopass' attribute in Fortran

fortran
Suppose I have type :: type1 contains procedure, nopass :: proc => proc_type1 end type type1 type, extends (type1) :: type2 contains procedure, nopass :: proc => proc_type2 end type type2 What happens if I do call instanceOfType2%proc()? Although this compiles I strongly suspect that proc_type1 will not be overriden...

How to orchestrate members in a cluster to read new input from a single file once the current job is done?

file-io,fortran,mpi,fortran90
I am working on a global optimization using brutal force. I am wondering if it is possible to complete the following task with Fortran MPI file I/O: I have three nodes, A, B, C. I want these nodes to search for the optima over six sets of parameter inputs, which...

How to create a new directory from Force Fortran 2.0

directory,fortran,create-directory
I need to create a new directory from my code to be able to write a data file to it. I am using Force Fortran 2.0 from Windows 8 and I am also wondering if this syntax is going to vary from one operating system to the other due to...

Proper use of the PURE keyword Fortran

fortran,keyword,fortran90,fortran95
I'm currently delving into Fortran and I've come across the pure keyword specifying functions/subroutines that have no side effects. I have a book, Fortran 90/95 by S Chapman which introduces the pure keyword but strangely provides no "good coding practice" uses. I'm wondering how liberally one should use this keyword...

Errors in linking fortran code that imports a MAT-file [duplicate]

matlab,fortran,gfortran,mat-file
This question already has an answer here: Reading data from matlab files into C 1 answer I have to import a MAT-file in a fortran program. I followed the example file but I am facing some problems while linking. The compilation happens fine. Minimal code: #include "fintrf.h" PROGRAM main...

Fortran compiler for mac to read program

compiler-errors,fortran,fortran77,g77
I'm using the g77 compiler (on terminal I just type g77 filename.for ) on a Mac. It can't read my fortran program and I can't modify the program (very old program, not mine, and I really just need the output from it). Any suggestion for another compiler to read the...

MPI Fortran compiler optimization error [duplicate]

fortran,mpi,compiler-optimization
This question already has an answer here: MPI_Recv changes the value of count 1 answer Despite having written long, heavily parallelized codes with complicated send/receives over three dimensional arrays, this simple code with a two dimensional array of integers has got me at my wits end. I combed stackoverflow...

Data exchange - Python and Fortran

python-2.7,fortran
We are developing a scientific application which has the interface in python 2.7 and the computation routines written in Intel Visual Fortran. Reading the source files is done using python, then only the required data for computations has to be passed to standalone Fortran algorithms. Once the computations done, the...

Setting size() of a scalar

fortran
In some legacy code, I found the following line size(k)=N What (if anything) does this do? As far as I know, it does not make sense to set size(thing) to a value in Fortran. Furthermore, k is implicitly defined as a scalar integer (i.e. there it is not declared in...

Fortran Functions with optional arguments

function,fortran,optional
I want to use an operator .ef. however the operator does not accept optional arguments. Is it possible to keep the my function and be able to have the operator working too? Module Core Implicit None Interface Operator (.ef.) Module Procedure fes End Interface Operator (.ef.) Contains Function fes &...

Print and write in one line?

file-io,fortran
Is it possible to print something in the screen and, at the same time, that what is being printed is also written in a file? Right now, I have something like this: print *, root1, root2 open(unit=10,file='result.txt' write(10,*), root1, root2 close(10) I feel like I'm wasting lines and making the...

How to set a mpreal parameter inside a Fortran module [duplicate]

module,fortran
This question already has an answer here: Fortran derived types: Overloaded assignment operator not working with 'PARAMETER' attribute 2 answers I'd really like to be able to define some parameters in a Fortran module, so so that they are accessible for the main program and all its subroutines. The...

Precision not respected

visual-studio-2010,fortran
I use Visual Studio (2010 SP1) with Fortran IMSL (2011) and I can't get the right precision for my reals: program prova use, intrinsic :: iso_fortran_env implicit none integer, parameter :: ikind=selected_real_kind(p=8, r=99) real(kind=ikind) :: a=0.79 real(real64) :: b=0.79 real(kind=16) :: c=0.79 real(8) :: d=0.79 print *, a print *,...

gfortran doesn't compile real variables

fortran,gfortran
I have written a simple program in Fortran90 to calculate the area of a triangle. The user enters the three sides of the triangle, and then the program outputs the area. Simple enough. MODULE Triangle_Operations IMPLICIT NONE CONTAINS FUNCTION Area(x,y,z) REAL :: Area ! function type REAL, INTENT( IN )...

Fortran derived type in common: initialization?

fortran,fortran90,static-initialization
I got troubles with this common: COMMON /REDCOM/ DPREC,NITMA,INDIC,NBERR,NCAR,KMOTLU, & REDVAR,MOCDER(2) COMMON /REDCO1/ CTEXT C type(double_st) :: DPREC INTEGER :: NITMA,INDIC,NBERR,NCAR,KMOTLU,REDVAR,MOCDER CHARACTER(72) :: CTEXT CHARACTER(4) :: CTEXT4 C EQUIVALENCE (CTEXT,CTEXT4) The double_st derived type is: type double_st sequence real(kind(0.d0)) :: x,y,z integer :: acc = -1 end type double_st Trying...

Calling C function with **int parameter from Fortran

c,fortran,fortran-iso-c-binding
Suppose that I have a C function with the following API : int c_function(int **a); How should I go about declaring a Fortran array/pointer to array, and passing it to the function, assuming that the C function is responsible for memory allocation ?...

Access element in function result

arrays,function,fortran
Why this Fortran code is incorrect? function foo(x) real x real, dimension(3) :: foo foo = (/1, 2, 3/) end ... and in main program print*, foo(x)(1) Why we cannot access element in function result directly?...

Passing arguments to interactive fortran program

bash,fortran,interactive
I have a fortran program (which I cannot modify) that requires several inputs from the user (in the command line) when it is run. The program takes quite a while to run, and I would like to retain use of the terminal by running it in the background; however, this...

Ordering of array dimensions

arrays,fortran
Given the following code: integer, parameter :: n = 10000 integer, parameter :: m = 3 real, dimension(:,:), allocatable :: arr ! First way allocate(arr(n,m)) ! Second way allocate(arr(m,n)) What is the "best" way to allocate arr when there is a large difference in the two dimensions, the first way...

Fibonacci Recursive function takes forever

recursion,fortran,fibonacci
I want to get the 48th element of the Fibonacci sequence which I can store in a 64 bit integer. I am using a recursive subroutine, but it is taking forever to finish. If anyone can find a problem with my recursive subroutine, I would be very grateful. Integer (Int8)...

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

fortran,gfortran,fortran2003,fortran2008
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?...

Filling Multidimensional Arrays

fortran,derived-types
I have created a derived type to access multi-dimensional arrays. With each array I associate a name in the array nm. My problem consists how to fill the array values once I have allocated the memory. An initial idea has been to use a multi-dimensional array as input. However I...

Running gnuplot from Fortran program under Windows

windows,fortran,gnuplot
I need to make a Fortran program(.exe) that analyses data and builds a plot. I've decided to do this by calling gnuplot from my Fortran program along with a gnuplot settings file. When I do this from Windows Command Line: wgnuplot -persist input.txt it works fine. But when I call...

Fortran multidimensional array in C++

c++,arrays,multidimensional-array,fortran,fortran90
I am trying to be able to pass a multidimensional Fortran array to a C++ program, in a C++ Fortran interoperating program. I have a basic idea of how passing the arrays from Fortran to C++ works; you pass a location of the array from Fortran to C++. Then C++...

How to pass C++ pointer to Fortran?

c++,pointers,fortran,fortran-iso-c-binding
I have the following C++ code: extern "C" void C_ASSIGN_ARRAY_TO_FORTRAN(double *doublearray) { doublearray=new double [10]; for (int i=0;i<10;i++) doublearray[i]=i; } The array doublearray should be passed to Fortran: USE, INTRINSIC :: ISO_C_BINDING IMPLICIT NONE INTERFACE SUBROUTINE C_ASSIGN_ARRAY_TO_FORTRAN(cdoublearray) BIND(C, NAME='C_ASSIGN_ARRAY_TO_FORTRAN') USE, INTRINSIC :: ISO_C_BINDING IMPLICIT NONE TYPE(C_PTR) :: cdoublearray END SUBROUTINE...

Reading a file of lists of integers in Fortran

string,file-io,fortran,data-conversion,fortran2003
I would like to read a data file with a Fortran program, where each line is a list of integers. Each line has a variable number of integers, separated by a given character (space, comma...). Sample input: 1,7,3,2 2,8 12,44,13,11 I have a solution to split lines, which I find...

unformatted output with wild card in Fortran

fortran,wildcard,fortran90
I've searched for a long time before I ask: I need to output a lot of unformatted files in Fortran to Ensight. I want to name them with geo.000000, geo.000001 ... geo.0001000. Here is how I deal with wild card: character(54) :: filename, temp character(80) :: buffer write(temp,'(i6.6)') step filename...

Fortran serialization using C_LOC and C_F_POINTER

serialization,fortran,fortran2003
I'm looking for a Fortran Library or preferred method of serializing data to a memory buffer in Fortran. After researching the topic, I found examples using the EQUIVALENCE statement and the TRANSFER intrinsic function. I wrote code to test them and they both worked. In my limited testing, the transfer...

Simple read function error

fortran,fortran90
I imagine this is something silly I've missed but I've asked my whole class and noone can seem to work it out. Making a simple program calling in a subroutine and I'm having trouble with the do loop reading in the entries of the matrix. program Householder_Program use QR_Factorisation use...

Fortran: Check namelist presence

fortran
As of now I am checking if iostat is smaller than 0 and re-open the file if a namelist could not be found (which is really ugly), i.e.: read(100, nml=nm_tensor, iostat = ios) if (ios < 0) then close(100) open(100, file="input_nm", status='old', action="read", iostat = ios) end if How do...

How do I extract a floating number in the middle of an alphanumeric chain?

fortran,fortran95
I am coding in Fortran 95. I must extract the two floating values from this line in an ascii file: circle(4097.0438,4111.337) Of course the READ statement is read(unit=11, fmt="(tr7,f9.4,tr1,f8.3)") x, y The problem is that I must do that for hundreds of ascii files, but there are variations in the...

Fortran DO loop, warning to use integer only

fortran,fortran90,gfortran,fortran95
I installed gfortran on my Ubuntu 15.04. While compiling in Fortran, be it .f95 or .f90 type, the DO loop asks to take integer parameters only but not real values or variables. That includes the loop variable and the step expression. Why can't it take real values too? The following...

Matrix from column

fortran,fortran90
The following data is given in a file: 1 7 5 4 11 0 1 -13 -7 I want to form a 3x3 matrix from these columns. I have tried advance=no but receive a runtime error. program form_matrix implicit none integer:: col,A(9) open(unit=12,file='q10.txt') do col=1,9 read(12,*,advance='no')(A(col)) end do 7 format(3i4)...

Using BLAS ?gemm on a subset of an array in fortran

arrays,fortran,slice,blas
The various LDx arguments to BLAS ?gemm functions are there to make it possible to operate on slices of larger arrays. For example, this small C program does a matrix multiplication of the top left and top right (100,100) submatrices of a (200,200) matrix, and stores the result in the...

ieee_arithmetic intrinsic module in gfortran

fortran,gfortran
I need to use gfortran to compile a library that is dependent on ieee_arithmetic. However, it is found that gfortran can not identify this module. For example with the code a.f90 program test use,intrinsic :: ieee_arithmetic real :: x read *, x if (ieee_is_nan(x)) then print *, "Nan" else print...

Batch file to conditionally execute ifortvars.bat

windows,batch-file,cmd,fortran
I am using a make.bat file to compile my Fortran code. To compile using the ifort command, I first need to initialize the compiler by executing ifortvarsbat intel64 command where I had to setup the path variable. This works fine, however, the path keeps increasing in size and says command...

The name of a subroutine can be a variable in fortran? [duplicate]

fortran,fortran90,subroutine
This question already has an answer here: How to alias a function name in Fortran 2 answers I was wondering if there is something similar to this in FORTRAN. Of course this example does not compile but I think you can get the idea, program test character(1):: sub sub='A'...

Different color schemes on vim

vim,fortran
In my lab, I can either work directly on my work station or on some server that is made available to us. On both my accounts, I have the same .bashrc and .vimrc files. Now looking at the picture below, you can see that there is some minor difference about...

How can I implement BCD in Fortran?

binary,fortran,bcd
Not sure if the title of my question makes sense, so bear with me. I'd like to find a system for representing single digit numbers with as few bits as possible. There is a method called "Densely packed decimal" (https://en.wikipedia.org/wiki/Densely_packed_decimal) which would be my ideal solution, but I wouldn't even...

Using Floor and Int in a computation

int,fortran,floor
I am using a calculation to locate a base pixel. Seems to me that the two calculations for i and j are equivalent (i.e. i==j is always true) when I tried a few examples. Is this always true? i = (int ((x - xmin) / a)) + 1 j =...

Checking all elements of array for a logical condition in fortran

gcc,fortran,gfortran
I want to check all rows of an array for a logical condition. I used function ALL as described in GNU GCC guide https://gcc.gnu.org/onlinedocs/gfortran/ALL.html Here is a sample code: program test3 implicit none real, allocatable, dimension (:,:) :: mat1 integer :: i,j,k,r logical :: lg r=3 allocate(mat1(r,r)) mat1=transpose( reshape( (/-1,-2,-3,-4,-5,-6,-7,-8,-9/),...

Fortran runtime error “bad integer for item 11 in list input”

io,fortran
I receive the runtime error "bad integer for item 11 in list input" referencing the following line of code. read(2,*)a,b,c,d,e,f,g,h,theta1,phi1,k,l,m,n,o, $ p,theta2,phi2,s,theta3,phi3, $ r1,x1,y1,r2,x2,y2,r3,x3,y3,z1,z2,z3 The line its reading from is 1 255.11211 0.2876 165.11404 90 4 8 0.19173 90 165.11404 0.09587 90 345.11404 4 4 0.0764 89.99915 -64.51149 0.11131 90.0015...

How do I make cmake output fortran .mod files into a mod dir?

cmake,fortran
Is there a cmake_mod_output_directory variable I can set? Right now cmake trows all *.mod files at the root of the CMAKE_BINARY_DIR.

How to compile fortran code to run without gfortran installed

osx,static,compilation,makefile,fortran
I have downloaded Bellhop, which is an underwater acoustic simulator written in Fortran. It can be found here with the Makefile. Question 1: I would like to know if it is possible to compile Fortran code, including everything needed, so a user without gfortran installed, can run it. I have...

gfortran does not find symbol fabsq_ in libquadmath

fortran,precision,gfortran,quad
I'm trying to get quad precision to work with my FORTRAN code. I have to replace some intrinsic functions by those in libquadmath, i.e. the dabs function by fabsq. Unfortunately, if I compile the following test function program test integer dp parameter (dp=10) real(kind=dp) a a= -5.0_dp a=fabsq(a) write(*,*) "abs(a)",...

OpenMP over Summation

parallel-processing,fortran,openmp,fortran90,gfortran
I have been trying to apply OpenMP on a simple summation operation inside two nested loop, but it produced incorrect result so far. I have been looking around in here and here, also in here. All suggest to use reduction clause, but it does not work for my case by...

How exactly do pointers in Fortran differ from C/C++ pointers?

c++,c,pointers,fortran
It might be useful to have both C/C++ programmers and Fortran programmers compare and contrast pointers in these two languages. In trying to explain to C/C++ programmers how Fortran pointers differ, I usually say pointers to functions or subroutines do not exist. I then try to make the argument that...

Segmentation fault; core dumped Fortran

fortran,gfortran,fortran77
I would like to ask about the error occurred with my Fortran code. Since I'm new to fortran I can't handle this after 2 days, I also searched around but still don't know how to fix it. PROGRAM SUBDEM IMPLICIT REAL*8(A-H,O-Z) REAL*8 NTET,NPTK INTEGER*4 NA,NC,NE,NBAND,NTMAX,IDEF C CALL SETK08(NA,NC, A,C, PTK,NPTK,...

Why is my Fortran code wrapped with f2py using so much memory?

python,memory-management,fortran,out-of-memory,f2py
I am trying to calculate all the distances between approximately a hundred thousand points. I have the following code written in Fortran and compiled using f2py: C 1 2 3 4 5 6 7 C123456789012345678901234567890123456789012345678901234567890123456789012 subroutine distances(coor,dist,n) double precision coor(n,3),dist(n,n) integer n double precision x1,y1,z1,x2,y2,z2,diff2 cf2py intent(in) :: coor,dist cf2py...

Fortran type conversions

arrays,fortran,converter
I have the following command to set my array Use, Intrinsic :: iso_fortran_env Integer (Int8), Allocatable :: iu(:) Allocate (iu(4)) iu = [4,3,2,1] How can I stop the compiler giving me Allocate (iu(4)); iu = [4,3,2,1] 1 Warning: Possible change of value in conversion from INTEGER(4) to INTEGER(1) at (1)...

Proper way of doing the systematic computations / initializations at the beginning of a program

fortran
I am writing a program that I will use in two main cases : 1D and 2D. The dimension ndim is loaded through a read of an external file, this read I want to do in module param. I have various declarations of vectors whose sizes depend on the dimension....

How can i store 2 numbers in a 1 byte char?

c++,c,binary,fortran,bcd
I have the question of the title, but If not, how could I get away with using only 4 bits to represent an integer? EDIT really my question is how. I am aware that there are 1 byte data structures in a language like c, but how could I use...

Can I read the rest of the line after a positive value of IOSTAT?

csv,file-io,fortran
I have a file with 13 columns and 41 lines consisting of the coefficients for the Joback Method for 41 different groups. Some of the values are non-existing, though, and the table lists them as "X". I saved the table as a .csv and in my code read the file...

dispose syntax error when using fortran open statement

file,fortran
I am opening a file which has to be deleted at the end. The following command complains about using dispose. f = "espy.tmp"; h = "formatted"; r = "read" Open (newunit=u, file=f, form=h, action=r, & status="old", dispose="delete") lib/core.f:177:21: status="old", dispose="delete") 1 Error: Syntax error in OPEN statement at (1) ...