fortran90

passing pointer arguments in fortran

。_饼干妹妹 提交于 2019-12-02 04:23:26
问题 I am wondering what is the proper way to write the following code? PROGRAM foo INTEGER :: x REAL(KIND=8), TARGET, DIMENSION(0: 10) :: array REAL(KIND=8), POINTER, DIMENSION(:) :: ptr ptr => array CALL bar(ptr) END PROGRAM foo SUBROUTINE bar (ptr) REAL(KIND=8), POINTER, DIMENSION(:) :: ptr INTEGER x DO x =0, 10 ptr(x) = 2 // seg faults ENDDO END SUBROUTINE bar It works if I declare ptr in bar as REAL(KIND=8), DIMENSION(0:10) . But in general I might not know the size of the passed-in array, so

Passing two options as arguments in OpenCL with Fortran (CLFORTRAN)

主宰稳场 提交于 2019-12-02 03:47:39
When my host program is in C language I can pass two options as an argument of an OpenCL function. For example, I can pass two flags to the clCreateBuffer function like this: clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(main_data), main_data, &err) However, when I try to do the same in a host program written in Fortran: main_data=clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, & sizeof(main_data), C_NULL_PTR, err) I get an error: & |CL_MEM_COPY_HOST_PTR, size_in_bytes,C_NULL_PTR,ierr) 1 Error: Syntax error in argument list at (1) I have successfully

Error: Invalid character in name at (1)

只谈情不闲聊 提交于 2019-12-02 03:40:34
I am trying to compile a fortran file along with some .h files in FORTRAN. The .h files contain definition for common blocks of variable. When I compile them in Fortran, I get the following error: integer knue,ke,knumu,kmu,knutau,ktau,ku,kd,kc,ks,kt,kb,kgamma, 1 Error: Invalid character in name at (1) The code where this error occurs is, Now my question is, does this "1" point where the error is? The lines of code which this errors points is, integer knue,ke,knumu,kmu,knutau,ktau,ku,kd,kc,ks,kt,kb,kgamma, & kw,kz,kgluon,kh1,kh2,kh3,khc,ksnue,kse1,kse2,ksnumu,ksmu1, & ksmu2,ksnutau,kstau1

Error in Derived type declaration: Variable at (1) in this context must be constant

戏子无情 提交于 2019-12-02 03:31:13
I have a derived type declared in a module like this: MODULE dmotifs TYPE :: PRM INTEGER, PRIVATE :: nsp=4,nrx=8,maxprx=4 REAL, PRIVATE :: cref=1e-6,tref=1 REAL, DIMENSION(nrx,maxprx) :: k REAL :: input END TYPE PRM CONTAINS SUBROUTINE unreg(y,param,r,s) TYPE(PRM), INTENT(IN) :: param REAL, DIMENSION(param%nsp), INTENT(IN) :: y INTEGER, DIMENSION(param%nsp,param%nrx), INTENT(OUT) :: s=0 REAL, DIMENSION(param%nrx,1), INTENT(OUT) :: r=0 REAL :: mOut, mCtrl, pOut, pCtrl mOut=y(ind_mOut) mCtrl=y(ind_mCtrl) pOut=y(ind_pOut) pCtrl=y(ind_pCtrl) ! <some operations on "r" and "s"> RETURN END SUBROUTINE

Error: Unexpected end of format string in format string in Fortran

梦想的初衷 提交于 2019-12-02 03:12:01
Getting this error while trying to compile a copied code from a Fortran 77 program. code: 900 FORMAT(1H0,2X,'ABSOLUTE GRID LIMITS FOR DATA RETENTION FOR RADAR',I3,' XMIN-XMAX ',2F8.3,' YMIN-YMAX ',2F8.3,' ZMAX ',F8.3, /3X,'WITH AZIMUTH LIMITS OF',2F8.2, 3X,'AND RANGE LIMITS OF',2F10.3,/) compiler error: messy21.f90:529.132: N FOR RADAR',I3,' XMIN-XMAX ',2F8.3,' YMIN-YMAX ',2F8.3,' ZMAX ',F8.3, /3X,(1) Error: Unexpected end of format string in format string at (1) I am not sure what the error means. My guess (on the basis of error position in the line, 132) would be: starting from Fortran 90 we

Array-valued function

亡梦爱人 提交于 2019-12-02 02:36:20
问题 I'm new in the area of Fortran programming and after testing a few programs I already got a feeling of how to write programs. Now I was trying me on a bit harder program and I run into a problem I couldn't solve by myself. I already googled about the problem but I couldn't find an adequate answer ... So I thought maybe there are one or two Fortran programmers which can give me a hand in solving this problem. The program is very simple it just multiplies two matrices with each other. I was

Write array to file by columns

我们两清 提交于 2019-12-02 01:52:49
Is there a way to write columns to a file one by one? For example, I would like to write: write(1,*) 1 write(1,*) 2 And then write (possibly in another subroutine) write(1,*) 3 write(1,*) 4 in such a way that will produce an output file in the format: 1 3 2 4 without combining the arrays (e.g.) write(1,*) 1,3 write(1,*) 2,4 I'm thinking that there may be a way to move the "pointer" (of file location) back to the beginning and add spaces or something, but I really have no idea if this is possible. Any help is greatly appreciated! So far, this is my attempt to make a subroutine to make this work

Error: Invalid character in name at (1)

醉酒当歌 提交于 2019-12-02 01:41:14
问题 I am trying to compile a fortran file along with some .h files in FORTRAN. The .h files contain definition for common blocks of variable. When I compile them in Fortran, I get the following error: integer knue,ke,knumu,kmu,knutau,ktau,ku,kd,kc,ks,kt,kb,kgamma, 1 Error: Invalid character in name at (1) The code where this error occurs is, Now my question is, does this "1" point where the error is? The lines of code which this errors points is, integer knue,ke,knumu,kmu,knutau,ktau,ku,kd,kc,ks

Subroutine with array element as argument

风格不统一 提交于 2019-12-02 01:36:45
In my program subroutine stlstp passing work(2,1) as parameter to stlfts(...) subroutine. work(2,1) will be double value at that index, but how subroutine converting it as single dimension array x(n) ? When I print x value in stlfts(...) subroutine, it is printing elements of n size, example: STLFTS....X,,, 0.0000000000000000 1.4964418382246345E-317 1.48978578 58438612E-317 1.4964339331743010E-317 1.4964418382246345E-317 4.3367611401 .... My understanding is, except 1st value, all other values in this x are garbage, but not sure how this assignment will will effect original reference? can

pointer as a dummy argument

穿精又带淫゛_ 提交于 2019-12-02 01:36:31
问题 I am somewhat puzzled by the following program module test implicit none type TestType integer :: i end type contains subroutine foo(test) type (TestType), intent(out) :: test test%i = 5 end subroutine subroutine bar(test) type (TestType), intent(out) :: test test%i = 6 end subroutine end module program hello use test type(TestType) :: t call foo(t) print *, t%i call bar(t) print *, t%i end program hello and its derivatives. More on those later. As we know, Fortran transfers routine arguments