Error Return Type Mismatch Of Function Fortran
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about function has no implicit type Stack Overflow the company Business Learn more about hiring developers or posting ads type mismatch in argument fortran with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow
Type Mismatch In Argument Passed Real(4) To Real(8)
is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up gfortran 4.8.0 bug? Return type mismatch of function up vote 1 down vote
Implicit None Fortran
favorite 1 I just use gfortran 4.1.2 and gfortran 4.8.0 to compile the following simple code: function foo(a, b) result(res) integer, intent(in) :: a, b integer res res = a+b end function foo program test integer a, b, c c = foo(a, b) end program test gfortran 4.1.2 succeeds, but gfortran 4.8.0 gives the weird error: test.F90:14.11: c = foo(a, b) 1 Error: Return type mismatch of function 'foo' at fortran type casting (1) (REAL(4)/INTEGER(4)) Any idea? gfortran share|improve this question asked May 9 '13 at 5:39 Li Dong 4921823 See stackoverflow.com/questions/16446397/… –High Performance Mark May 9 '13 at 5:48 Thanks @Mark! I am writing a tool for scanning Fortran codes and building them, this is just a test. And I am more familiar with module. Personally, I add implicit none in every code of my Fortran project, but forget to add it in the test! And I also need to declare function foo in the program. –Li Dong May 9 '13 at 6:05 add a comment| 1 Answer 1 active oldest votes up vote 0 down vote accepted There is a bug in your code, namely that you don't specify the return type of the function foo in the main program. Per the Fortran implicit typing rules it thus gets a type of default real. You should (1) always use 'implicit none', furthermore if at all possible, (2) use modules or contained procedures thus giving you explicit interfaces. The reason why GFortran 4.1 doesn't report this error is that older versions of GFortran always functioned in a 'procedure at a time' mode; thus the compiler is happily oblivious to any other functions in the sa
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site
Fortran Module
About Us Learn more about Stack Overflow the company Business Learn more about fortran function hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss fortran interface Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Return type mismatch of http://stackoverflow.com/questions/16455130/gfortran-4-8-0-bug-return-type-mismatch-of-function function up vote 0 down vote favorite I want to diagonalize a complex matrix in fortran90 with a function. This is the function I use !========================================================================== function inv(A,n) Implicit none integer :: n complex*16, dimension(n,n):: A complex*16, dimension(n,n):: inv complex*16,allocatable,dimension(:)::WORK integer,allocatable,dimension(:)::IPIV integer i,j,info,error allocate(WORK(n),IPIV(n),stat=error) if (error.ne.0)then print *,"error:not enough memory" stop end if call ZGETRF(n,n,A,n,IPIV,info) if(info .eq. 0) then write(*,*)"succeded" else write(*,*)"failed" end if call http://stackoverflow.com/questions/26932934/return-type-mismatch-of-function ZGETRI(n,A,n,IPIV,WORK,n,info) if(info .eq. 0) then write(*,*)"succeded" inv=A else write(*,*)"failed" end if !deallocate(A,IPIV,WORK,stat=error) !if (error.ne.0)then ! print *,"error:fail to release" ! stop !end if end function inv and I simply call it with Wmattemp=inv(Wmattemp,nsit) where its type is complex*16, allocatable :: Wmattemp(:,:) But I obtain this error when I compile with gfortran -fdefault-real-8 code.f90 -llapack code.f90:217.19: Wmattemp=inv(Wmattemp,nsit) 1 Error: Return type mismatch of function 'inv' at (1) (INTEGER(4)/COMPLEX(8)) code.f90:217.16: Wmattemp=inv(Wmattemp,nsit) 1 Error: The reference to function 'inv' at (1) either needs an explicit INTERFACE or the rank is incorrect II'm not a fortran expert so I cannot find what is the problem. Now I added to the main program complex*16, allocatable :: inv(:,:) but I obtain this error code.f90:217.13: A=inv(Wmattemp,nsit) 1 Error: Array index at (1) must be of INTEGER type, found COMPLEX fortran share|improve this question edited Nov 14 '14 at 15:23 asked Nov 14 '14 at 15:06 user3368447 428 2 Almost certainly you haven't declared inv at the CALLING site, i.e. not in this piece of code but where inv is invoked. Can you also show that piece of code, with all the declarations? –Ian Bush Nov 14 '14 at 15:1
[ date ] [ thread ] [ subject ] [ author ] On 10-04-2011, at 10:42, Christophe Dutang wrote: > Dear all, > > I use R 2.12.2 to build, install and check my packages, in particular randtoolbox. On my https://stat.ethz.ch/pipermail/r-sig-mac/2011-April/008160.html macbook with OS X 10.6.7, the gcc installed is > i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build https://forums.opensuse.org/showthread.php/479431-gmake-error-when-compiling-didn-t-have-this-problem-before-upgrading-from-11-4-to-12-2 5666) (dot 3) . From http://r.research.att.com/tools/, I have also downloaded gfortran (GNU Fortran (GCC) 4.2.3). > > With this framework, I do not get any error and warnings on the randtoolbox package. > Looking at your Fortran code, I think you have just been lucky. > But using gcc 4.6 on linux, Kurt Hornik get the following errors in the only one type mismatch Fortran file of the package: > > LowDiscrepancy.f:180.26: > > QN(I, J) = HQNORM(QUASI(J)) > 1 > Error: Return type mismatch of function 'hqnorm' at (1) (REAL(4)/REAL(8)) HQNORM is not declared with a type in the routine you are using it. Implicit declaration most likely implies it is real (real*4). But later on it is typed as double precision. Asking for trouble. > LowDiscrepancy.f:1393.29: > > TEMP1 = TEMP1 + TEMP01 > 1 > Warning: Possible change of type mismatch in value in conversion from REAL(4) to INTEGER(4) at (1) Temp01 is not declared and thus implicitly real*4 (most likely). > LowDiscrepancy.f:405.29: > > QN(I, J) = SQNORM(QUASI(J)) > 1 > Error: Return type mismatch of function 'sqnorm' at (1) (REAL(4)/REAL(8)) > make: *** [LowDiscrepancy.o] Error 1 > see remark above about hqnorm. Same problem. > > My first question is which is the standard version of gcc to use? from http://cran.r-project.org/web/checks/check_flavors.html#r-release-macosx-ix86, it should gcc 4.2.1 ? If I have to update gcc, where can I find the binaries? > gcc-4.2.1 comes with Xcode. And gfortran must be obtained from http://r.research.att.com/tools/ and should match the Xcode version. That's all. But looking at that page I don't see a gfortran available for Apple gcc 5666 (from Xcode 3.2.6?). I am using gfortran 5664 with Xcode 3.2.5. Simon knows more about this. > My second question, in the case I can reproduce this error on my macbook or a linux, the fortran errors are a wrong type between the QN variable and the return value of HQNORM. Looking at the LowDiscrepancy.f file, both QN and the return type of QNORM are DOUBLE PRECISION. Does anyone have a guess where is the problem? > Yes. Declare ALL variables. With implicit fortran typing you can run into all sorts of trouble. Test compile your Fortran with gfortran -c -fsyntax-only -fimplicit-none LowDiscrepancy.f You'll get a shock. Always at least
Help Here 64-bit (CLOSED) gmake error when compiling - didn't have this problem before upgrading from 11.4 to 12.2 Welcome! If this is your first visit, be sure to check out the FAQ. You will have to register before you can post in the forums. (Be aware the forums do not accept user names with a dash "-") Also, logging in lets you avoid the CAPTCHA verification when searching . Select Articles, Forum, or Blog. Posting in the Forums implies acceptance of the Terms and Conditions. Results 1 to 6 of 6 Thread: gmake error when compiling - didn't have this problem before upgrading from 11.4 to 12.2 Thread Tools Show Printable Version Subscribe to this Thread… Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode 10-Oct-2012,07:16 #1 gmagnotti View Profile View Forum Posts View Blog Entries View Articles Newcomer Join Date Oct 2012 Posts 22 gmake error when compiling - didn't have this problem before upgrading from 11.4 to 12.2 Hi everyone, So I was able to successfully clean install openSUSE 12.2 after upgrading from 11.4. I went into yast and added many of the libraries that I would need to run in Fortran and compile using 'gmake'. However, I am running into compiler errors now that I didn't run into previously, which leads me to believe that this is due to not having the correct library? Posted below is my error: 1 X(KRANKE+1), RNORML, MODE, WS(N2), IP(2)) 1 Warning: Rank mismatch in argument 'rnorm' at (1) (rank-1 and scalar) gmake: *** [dmath.o] Error 1 I know it's not something in the code (because it was working previously) so if you have any advice about libraries to add or how to diagnose this problem, it would be most appreciated. Thanks! 10-Oct-2012,07:57 #2 lwfinger View Profile View Forum Posts View Blog Entries View Articles Flux Capacitor Penguin Join Date Jun 2008 Location Kansas City Area, Missouri, USA Posts 7,383 Re: gmake error when compiling - didn't have this problem beforeupgrading from 11.4 to 12.2 On 10/10/2012 09:26 AM, gmagnotti wrote: > > Hi everyone, So I was able to successfully clean install openSUSE > 12.2 after upgrading from 11.4. I went into yast and added many of the > libraries that I would need to run in Fortran and compile using 'gmake'. > However, I am running into compiler errors now that I didn't run into > previously, which leads me to believe that this is due to not having the > correct library? Posted below is my error: 1 X(KRANKE+1), > RNORML, MODE, WS(N2), IP(2)) > 1 Warning: Rank mismatch in argument 'rnorm' at (1) (rank-1 and > scalar) gmake: *** [dmath.o] Error 1 I know it's not something in > the code (because it was working previously) so if you have any