Search Results

Search found 231 results on 10 pages for 'fortran'.

Page 2/10 | < Previous Page | 1 2 3 4 5 6 7 8 9 10  | Next Page >

  • Precision problems of real numbers in Fortran

    - by saladoil
    I've been trying to use Fortran for my research project, with the GNU Fortran compiler (gfortran), latest version, but I've been encountering some problems in the way it processes real numbers. If you have for example the code: program test implicit none real :: y = 23.234, z z = y * 100000 write(*,*) y, z end program You'll get as output: 23.23999 2323400.0. I find this really strange. Can someone tell me what's exactly happening here? Looking at z I can see that y does retain its precision, so for calculations that shouldn't be a problem I suppose. But why is the output of y not exactly the same as the value that I've specified, and what can I do to make it exactly the same?

    Read the article

  • C++ class functions calling fortran subroutine

    - by user2863626
    Okay so I am trying to make my code work. It is a simple C++ program with a class "CArray". This class has 2 properties, the array size, and the value. I want the main C++ program to create two instances of the class CArray. In the class CArray, I have a function called "AddArray( CArray )" where it adds another array to the current array. The problem I am stuck with, is that I want the function "AddArray" to add the two arrays in fortran. I know, much more complicated, but that is what I need. I am having issues with linking the two inside the class code. #include <iostream> using namespace std; class CArray { public: CArray(); ~CArray(); int Size; int* Val; void SetSize( int ); void SetValues(); void GetArray(); extern "C" { void Add( int*, int*, int*, int*); void Subtract( int*, int*, int*, int*); void Muliply( int*, int*, int *, int* ); } void AddArray( CArray ); void SubtractArray( CArray ); void MultiplyArray( CArray ); }; Also here is the CArray function file. #include "Array.h" #include <iostream> using namespace std; CArray::CArray() { } CArray::~CArray() { } void CArray::SetSize( int s ) { Size = s; for ( int i=0; i<s; i++ ) { Val = new int[Size]; } } void CArray::SetValues() { for ( int i=0; i<Size; i++ ) { cout << "Element " << i+1 << ": "; cin >> Val[i]; } } void CArray::GetArray() { for ( int i=0; i<Size; i++ ) { cout << Val[i] << " "; } } void CArray::AddArray( CArray a ) { if ( Size == a.Size ) { Add(&Val, &a.Val); } else { cout << "Array dimensions do not agree!" << endl; } } void CArray::SubtractArray( CArray a ) { Subtract( &Val, &a, &Size, &a.Size); GetArray(); } Here is my Fortran code. module SubtractArrays use ico_c_binding implicit none contains subroutine Subtract(a,b,s1,s2) bind(c,name='Subtract') integer s1,s2 integer a(s1),b(s2) if ( s1.eq.s2 ) do i=1,s1 a(i) = a(i) - b(i) end return end end If someone could just help me with setting me up to send arrays of integers from C++ classes to fortran I would greatly appreciate it! Thank you, Josh Derrick

    Read the article

  • fortran 90 user defined type, passing by value ?

    - by user279137
    I have an issue in fortran 90. I have a user defined type and when I call one of the MPI subroutines the data looks to be passed by values (not address, as I thought it should). The output arguments aren't modified. It seems to be specific to the MPI calls I tried the same thing in a simple test, and I can change the passed in values in the calling scope. I'm not sure why this is because I thought fortran always pass by address. Any idea what could be going on? Just to be clear the commented snippet shows how the calls are made. The in the first call, c%NSubDomains, is an output argument and should be modified in the calling scope, but its not. WHen I call with an array rather than a member of user defined type it works, in the uncommented snippet. ! ! This doesn't work output values aren't modified ?? ! call MPI_Dims_create(c%NProcs,c%NDims,c%NSubDomains,iErr) nsubs(:)=0 call MPI_Dims_create(c%NProcs,c%NDims,nsubs,iErr) c%NSubDomains=nsubs Thanks

    Read the article

  • Reading input files in FORTRAN

    - by lollygagger
    Purpose: Create a program that takes two separate files, opens and reads them, assigns their contents to arrays, do some math with those arrays, create a new array with product numbers, print to a new file. Simple enough right? My input files have comment characters at the beginning. One trouble is, they are '#' which are comment characters for most plotting programs, but not FORTRAN. What is a simple way to tell the computer not to look at these characters? Since I have no previous FORTRAN experience, I am plowing through this with two test files. Here is what I have so far: PROGRAM gain IMPLICIT NONE REAL, DIMENSION (1:4, 1:8) :: X, Y, Z OPEN(1, FILE='test.out', & STATUS='OLD', ACTION='READ') ! opens the first file READ(1,*), X OPEN(2, FILE='test2.out', & STATUS='OLD', ACTION='READ') ! opens the second file READ(2,*), Y PRINT*, X, Y Z = X*Y ! PRINT*, Z OPEN(3, FILE='test3.out', STATUS='NEW', ACTION='WRITE') !creates a new file WRITE(3,*), Z CLOSE(1) CLOSE(2) CLOSE(3) END PROGRAM PS. Please do not overwhelm me with a bunch of code monkey gobblety gook. I am a total programming novice. I do not understand all the lingo, that is why I came here instead of searching for help in existing websites. Thanks.

    Read the article

  • Common block usage in Fortran

    - by Crystal
    I'm new to Fortran and just doing some simple things for work. And as a new programmer in general, not sure exactly how this works, so excuse me if my explanation or notation is not the best. At the top of the .F file there are common declarations. The person explaining it to me said think of it like a struct in C, and that they are global. Also in that same .F file, they have it declared with what type. So it's something like: COMMON SOMEVAR INTEGER*2 SOMEVAR And then when I actually see it being used in some other file, they declare local variables, (e.g. SOMEVAR_LOCAL) and depending on the condition, they set SOMEVAR_LOCAL = 1 or 0. Then there is another conditional later down the line that will say something like IF (SOMEVAR_LOCAL. eq. 1) SOMEVAR(PARAM) = 1; (Again I apologize if this is not proper Fortran, but I don't have access to the code right now). So it seems to me that there is a "struct" like variable called SOMEVAR that is of some length (2 bytes of data?), then there is a local variable that is used as a flag so that later down the line, the global struct SOMEVAR can be set to that value. But because there is (PARAM), it's like an array for that particular instance? Thanks. Sorry for my bad explanation, but hopefully you will understand what I am asking.

    Read the article

  • Fortran bus error on mac

    - by SteveJ
    The following Fortran code is giving me a bus error on my Mac but no errors when I run it on my Linux machine: PROGRAM TINY WRITE(UNIT=*, FMT=*) 'Hello, world!' END My understanding is that a bus error occurs when the program attempts to access impossible memory but I do not understand where such an attempt has been made in this program. My MacBook has GCC 4.4.0 and my Linux machine has GCC 4.3.2. Any ideas as to why this error occurs?

    Read the article

  • FORTRAN: determine variable type

    - by tibbs
    hello, GOOGLE has yet to find an answer for me, so here goes: In FORTRAN, is there a way to determine the TYPE of a variable? E.G., pass the variable type as an argument in a function, to then be able to call type-specific code with that fuction; eliminating the need to have seperate similar functions for each data type. thanks.

    Read the article

  • How to compile Python scripts for use in FORTRAN?

    - by Vincent Poirier
    Hello, Although I found many answers and discussions about this question, I am unable to find a solution particular to my situation. Here it is: I have a main program written in FORTRAN. I have been given a set of python scripts that are very useful. My goal is to access these python scripts from my main FORTRAN program. Currently, I simply call the scripts from FORTRAN as such: CALL SYSTEM ('python pyexample.py') Data is read from .dat files and written to .dat files. This is how the python scripts and the main FORTRAN program communicate to each other. I am currently running my code on my local machine. I have python installed with numpy, scipy, etc. My problem: The code needs to run on a remote server. For strictly FORTRAN code, I compile the code locally and send the executable to the server where it waits in a queue. However, the server does not have python installed. The server is being used as a number crunching station between universities and industry. Installing python along with the necessary modules on the server is not an option. This means that my “CALL SYSTEM ('python pyexample.py')” strategy no longer works. Solution?: I found some information on a couple of things in thread http://stackoverflow.com/questions/138521/is-it-feasible-to-compile-python-to-machine-code Shedskin, Psyco, Cython, Pypy, Cpython API These “modules”(? Not sure if that's what to call them) seem to compile python script to C code or C++. Apparently not all python features can be translated to C. As well, some of these appear to be experimental. Is it possible to compile my python scripts with my FORTRAN code? There exists f2py which converts FORTRAN code to python, but it doesn't work the other way around. Any help would be greatly appreciated. Thank you for your time. Vincent PS: I'm using python 2.6 on Ubuntu

    Read the article

  • Fortran arrays and subroutines (sub arrays)

    - by ccook
    I'm going through a Fortran code, and one bit has me a little puzzled. There is a subroutine, say SUBROUTINE SSUB(X,...) REAL*8 X(0:N1,1:N2,0:N3-1),... ... RETURN END Which is called in another subroutine by: CALL SSUB(W(0,1,0,1),...) where W is a 'working array'. It appears that a specific value from W is passed to the X, however, X is dimensioned as an array. What's going on?

    Read the article

  • Fortran arrays and subroutines

    - by ccook
    I'm going through a Fortran code, and one bit has me a little puzzled. There is a subroutine, say SUBROUTINE SSUB(X,...) REAL*8 X(0:N1,1:N2,0:N3-1),... ... RETURN END Which is called in another subroutine by: CALL SSUB(W(0,1,0,1),...) where W is a 'working array'. It appears that a specific value from W is passed to the X, however, X is dimensioned as an array. What's going on?

    Read the article

  • Should External Routine Be Declared Always in Fortran?

    - by Ngu Soon Hui
    In my fortran code I made the following call to dnrm2 routine d = dnrm2(n, ax, 1) Just a simple call that would return me a double precision result. The problem is whether I should declare the function at the start of my script. I found that if I don't declare it, and when I compile the code in 32 bit Windows, then the result is correct. But if I compile the code in 64 bit Windows, then the result won't be correct. Why this is so? Is external routine must always be declared?

    Read the article

  • Fortran recursion segmentation faults

    - by ConnorG
    Hey all - I have to design and implement a Fortran routine to determine the size of clusters on a square lattice, and it seemed extremely convenient to code the subroutine recursively. However, whenever my lattice size grows beyond a certain value (around 200/side), the subroutine consistently segfaults. Here's my cluster-detection routine: RECURSIVE SUBROUTINE growCluster(lattice, adj, idx, area) INTEGER, INTENT(INOUT) :: lattice(:), area INTEGER, INTENT(IN) :: adj(:,:), idx lattice(idx) = -1 area = area + 1 IF (lattice(adj(1,idx)).GT.0) & CALL growCluster(lattice,adj,adj(1,idx),area) IF (lattice(adj(2,idx)).GT.0) & CALL growCluster(lattice,adj,adj(2,idx),area) IF (lattice(adj(3,idx)).GT.0) & CALL growCluster(lattice,adj,adj(3,idx),area) IF (lattice(adj(4,idx)).GT.0) & CALL growCluster(lattice,adj,adj(4,idx),area) END SUBROUTINE growCluster where adj(1,n) represents the north neighbor of site n, adj(2,n) represents the west and so on. What would cause the erratic segfault behavior? Is the cluster just "too huge" for large lattice sizes?

    Read the article

  • Function pointer arrays in Fortran

    - by Eduardo Dobay
    I can create function pointers in Fortran 90, with code like real, external :: f and then use f as an argument to another function/subroutine. But what if I want an array of function pointers? In C I would just do double (*f[])(int); to create an array of functions returning double and taking an integer argument. I tried the most obvious, real, external, dimension(3) :: f but gfortran doesn't let me mix EXTERNAL and DIMENSION. Is there any way to do what I want? (The context for this is a program for solving a system of differential equations, so I could input the equations without having a million parameters in my subroutines.)

    Read the article

  • Fortran - String with unknown characters into substrings

    - by Masoud
    I am trying to put an input string into sub-string arrays. The number of data in the input file are less than 10 but unknown. The number of spaces between each data is also unclear. Example: Asd B Cwqe21 Ddsw Eww I am quite novice to Fortran, so I do not know which format I should use. My problem is that I do not know the number of data (here I assumed that there are 5), so how can I make the code work? I tried the following which did not work: CHARACTER (LEN=100), DIMENSION(10) :: string READ (1,*) (string,I=1,10) It seems that the error I got was because there was no 6th string to read and put into string(6). I tried using the "Index" to find the space, but since I do not know how many spaces are in the string, it did not help me.

    Read the article

  • Problem: Vectorizing Code with Intel Visual FORTRAN for X64

    - by user313209
    I'm compiling my fortran90 code using Intel Visual FORTRAN on Windows Server 2003 Enterprise X64 Edition. When I compile the code for 32 bit structure and using automatic and manual vectorizing options. The code will be compiled, vectorized. And when I run it on 8 core system the compiled code uses 70% of CPU that shows me that vectorizing is working. But when I compile the code with 64 Bit compiler, it says that the code is vectorized but when I run it it only shows CPU usage of about 12% that is full usage for one core out of 8, so it means that while the compiler says that code is vectorized, vectorization is not working. And it's strange for me because it's on a X64 Edition Windows and I was expecting to see the reverse result. I thought that it should be better to run a code that is compiled for 64 Bit architecture on a 64 bit windows. Anyone have any idea why the compiled code is not able to use the full power of multiple cores for 64 Bit Compiled version? Thanks in advance for your responses.

    Read the article

  • OpenMP in Fortran

    - by user345293
    I very rarely use fortran, however I have been tasked with taking legacy code rewriting it to run in parallel. I'm using gfortran for my compiler choice. I found some excellent resources at https://computing.llnl.gov/tutorials/openMP/ as well as a few others. My problem is this, before I add any OpenMP directives, if I simply compile the legacy program: gfortran Example1.F90 -o Example1 everything works, but turning on the openmp compiler option even without adding directives: gfortran -openmp Example1.F90 -o Example1 ends up with a Segmentation fault when I run the legacy program. Using smaller test programs that I wrote, I've successfully compiled other programs with -openmp that run on multiple threads, but I'm rather at a loss why enabling the option alone and no directives is resulting in a seg fault. I apologize if my question is rather simple. I could post code but it is rather long. It faults as I assign initial values: REAL, DIMENSION(da,da) :: uconsold REAL, DIMENSION(da,da,dr,dk) :: uconsolde ... uconsold=0.0 uconsolde=0.0 The first assignment to "uconsold" works fine, the second seems to be the source of the fault as when I comment the line out the next several lines execute merrily until "uconsolde" is used again. Thank you for any help in this matter.

    Read the article

  • Fortran pointer as an argument to interface procedure

    - by icarusthecow
    Im trying to use interfaces to call different subroutines with different types, however, it doesnt seem to work when i use the pointer attribute. for example, take this sample code MODULE ptr_types TYPE, abstract :: parent INTEGER :: q END TYPE TYPE, extends(parent) :: child INTEGER :: m END TYPE INTERFACE ptr_interface MODULE PROCEDURE do_something END INTERFACE CONTAINS SUBROUTINE do_something(atype) CLASS(parent), POINTER :: atype ! code determines that this allocation is correct from input ALLOCATE(child::atype) WRITE (*,*) atype%q END SUBROUTINE END MODULE PROGRAM testpass USE ptr_types CLASS(child), POINTER :: ctype CALL ptr_interface(ctype) END PROGRAM This gives error Error: There is no specific subroutine for the generic 'ptr_interface' at (1) however if i remove the pointer attribute in the subroutine it compiles fine. Now, normally this wouldnt be a problem, but for my use case i need to be able to treat that argument as a pointer, mainly so i can allocate it if necessary. Any suggestions? Mind you I'm new to fortran so I may have missed something edit: forgot to put the allocation in the parents subroutine, the initial input is unallocated EDIT 2 this is my second attempt, with caller side casting MODULE ptr_types TYPE, abstract :: parent INTEGER :: q END TYPE TYPE, extends(parent) :: child INTEGER :: m END TYPE TYPE, extends(parent) :: second INTEGER :: meow END TYPE CONTAINS SUBROUTINE do_something(this, type_num) CLASS(parent), POINTER :: this INTEGER type_num IF (type_num == 0) THEN ALLOCATE (child::this) ELSE IF (type_num == 1) THEN ALLOCATE (second::this) ENDIF END SUBROUTINE END MODULE PROGRAM testpass USE ptr_types CLASS(child), POINTER :: ctype SELECT TYPE(ctype) CLASS is (parent) CALL do_something(ctype, 0) END SELECT WRITE (*,*) ctype%q END PROGRAM however this still fails. in the select statement it complains that parent must extend child. Im sure this is due to restrictions when dealing with the pointer attribute, for type safety, however, im looking for a way to convert a pointer into its parent type for generic allocation. Rather than have to write separate allocation functions for every type and hope they dont collide in an interface or something. hopefully this example will illustrate a little more clearly what im trying to achieve, if you know a better way let me know

    Read the article

  • gfortran in ubuntu 12.10

    - by user115334
    I hope my message will get read soon and somebody will give me a solution. I use fortran to do simulation and gfortran is the compiler I use. Recently I migrated from Ubuntu 10.10 to 12.10. After installing gfortran then I tried to compile and run my fortran programs then the problem started. I successfully compiled the program but I am unable to execute it. (I work in a directory in shared partition, not in HOME directory). When I compiled the program and run it within HOME directory, everything worked fine. On my Ubuntu 10.10, I was able to compile and execute fortran program from everywhere not only within HOME directory. This is what I do for compiling and executing fortran program: gfortran hello.f90 -o hello # to compile it ./hello # to execute it I'm blind about PATH or anything like it (this has to do with it, I suspect) so please give me direction.

    Read the article

  • Compiling a c++ project using blas (Fortran) in Matlab mex

    - by Yin Zhu
    I am trying to use a package here. I have no problem compiling it under 64-bit Linux as all the Makefiles are already provides. Only minor changes are needed, which I can handle. However, I have a problem compiling it under 64-bit Windows. I have installed gfortran and also compiled BLAS and CBLAS to their static libraries. The problem is that Matlab mex does not support GCC in windows, so I need to use VC 2008 instead. I found in the Makefile this line is to get the final klr_train.mexw64: klr_train.$(MEX_EXT): klr_train.cpp $(MEX) $(MEX_OPTION) klr_train.cpp ../libklr/libklr.cpp $(CBLASDIR)/lib/LINUX/cblas_LINUX.a $(BLASDIR)/blas_LINUX.a -lgfortran I don't know how to execute this line using VC 2008's command line tool cl. As cl obviously does not support -lgfortran, which I think is used to link some library in gfortran to support BLAS.

    Read the article

  • How to Install two library CGNS for Fortran under WIndows XP

    - by user317368
    Hello, I have to install two libraries CGNS to use it in Fortan, but I don't understand how, the basic instructions are: To compile under MS Windows: configure.bat [options] then gmake if using GNU make, or nmake if using nmake. NOTE: This assumes that the cl compiler is in your path, and that the INCLUDE and LIB environment variables are set to include the directories containing the MSC include files and libraries. If not, you will need to use full path names to cl and link, and define INCLUDE and LIB in make.win32. You may also execute VCVARS32.BAT in the BIN directory of your VC installation to set these up prior to running nmake. so what i did was to: tape configure.bat it creates the rights files I set the news paths and lib, include for the cl.exe and link.exe but now the warning and error messages are about the clui.dll. cl -nologo -I. -Iadf -FoWIN32\cgns_error.obj -c cgns_error.c Cannot load language resource clui.dll what can i do now? I'm a beginner user in this field. Thankx Manal

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10  | Next Page >