爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 10152|回复: 4

[其他] NCL中调用fortran出错,求指点~~~

[复制链接]
发表于 2014-12-9 00:11:11 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
想在NCL中调用FORTRAN的,但是提示提出 错,貌似错误应该在Fortran代码中,但是我在VCF中是可以编译fortran代码的,,,不知道问题出在哪了,求大侠指点~~~

error1 ,while WRAPTI getlatlon.stub getlatlon.f90,shows:
        A syntax error occurred while parsing:
        LINKING
        END WRAPIT

erro2, while run ncl getlatlon.ncl

      warning:Could not find Init() in external file ./getlatlon.so, file not loaded
      warning:error at line 2 in file getlatlon.ncl

      fatal:syntax error: line 10 in file getlatlon.ncl before or near :
       GETLATLON_SO:
   ----------------^

fatal:error in statement
fatal:Syntax Error in block, block not executed
fatal:error at line 16 in file getlatlon.ncl
***********fortran program**************
subroutine getlatlon (infile,nx,ny,ii,iilat,iilon)
implicit none
character*80 infile
integer:: nx,ny,ii,i,j
real:: iilat, iilon
real,allocatable::latlon(:,:)

open(10,file=infile,status='old')

allocate(latlon(nx,ny))
do j=1,ny
   read(10,*)(latlon(i,j),i=1,nx)
end do

iilat=latlon(1,ii)
iilon=latlon(2,ii)

close(10)
return
end subroutine
*************************stub file************************
C NCLFORTSTART
    SUBROUTINE getlatlon (infile,nx,ny,ii,iilat,iilon)
       CHARACTER*80 infile
        INTEGER  nx,ny,ii
        REAL iilat,iilon
C NCLEND

********************NCL file********************************

load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
external GETLATLON_SO "./getlatlon.so"

begin
infile ="./station.txt"
nx=2
ny=60
do ii=1,ny

    GETLATLON_SO::getlatlon(infile,nx,ny,ii,iilat,iilon)
    print(iilat)
    print(iilon)

end do

end

密码修改失败请联系微信:mofangbao
发表于 2014-12-9 10:15:51 | 显示全部楼层
编译过程正常
$ WRAPIT test.stub test.f90

WRAPIT Version: 120209
COMPILING test.f90
LINKING
END WRAPIT



Copyright (C) 1995-2014 - All Rights Reserved
University Corporation for Atmospheric Research
NCAR Command Language Version 6.2.1
The use of this software is governed by a License Agreement.
See http://www.ncl.ucar.edu/ for more details.
fatal:Number of elements of dimension (0) of argument (0) is (1) in function (getlatlon), expected (80) elements
fatal:["Execute.c":8578]:Execute: Error occurred at or near line 22 in file test.ncl

我试着运行了一下,因为没数据,所以是在 getlatlon 运行的地方报错。
LZ还有什么信息可以提供的?
密码修改失败请联系微信:mofangbao
 楼主| 发表于 2014-12-9 10:46:58 | 显示全部楼层
hzwjy 发表于 2014-12-9 10:15
编译过程正常
$ WRAPIT test.stub test.f90

有人提醒说F77要在第7列开始写,可是我是f90, 我调成开头第7列开始,也还是不行,我的WRAPIT也是120209版本,大侠能把你运行成功的test.stub和test.f90发过来看看格式吗?
密码修改失败请联系微信:mofangbao
发表于 2014-12-9 14:23:52 | 显示全部楼层
以下是我改过的代码,我用两行两列的数据测试了一下,没有问题。红色部分我改过的。

1. test.f90
subroutine getlatlon (infile,nx,ny,ii,iilat,iilon)
implicit none
character*80 infile
integer:: nx,ny,ii,i,j
real:: iilat, iilon
real,allocatable::latlon(:,:)

open(10,file=infile,status='old')

allocate(latlon(nx,ny))
do j=1,ny
   read(10,*)(latlon(i,j),i=1,nx)
end do

iilat=latlon(1,ii)
iilon=latlon(2,ii)

close(10)
return
end subroutine

2. test.stub
C NCLFORTSTART
    SUBROUTINE getlatlon (infile,nx,ny,ii,iilat,iilon)
        CHARACTER*(*) infile
        INTEGER  nx,ny,ii
        REAL iilat,iilon
C NCLEND

3. test.ncl
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
external GETLATLON_SO "./test.so"

begin
infile = "./station.txt"
nx=2
ny=2
iilat = 0.
iilon = 0.

do ii=1,ny

    GETLATLON_SO::getlatlon(infile,nx,ny,ii,iilat,iilon)
    print(iilat)
    print(iilon)

end do

end

test.so (9.74 KB, 下载次数: 6)
密码修改失败请联系微信:mofangbao
 楼主| 发表于 2014-12-9 18:06:27 | 显示全部楼层
longlivehj 发表于 2014-12-9 14:23
以下是我改过的代码,我用两行两列的数据测试了一下,没有问题。红色部分我改过的。

1. test.f90

在stub文件里面的确是要把character长度设为*(*),才行,我改了之后测试成功了,谢谢大侠赐教。这是什么原理呢?fortran里可是设的80,这样不对称吧~~~。还有一个原因就是,我的stub文件可能含有“”dos"字符,用dos2unix转一下,单独编译WRAPIT *.stub是没问题的。当然其实我这个调用是为了输入经纬度,可以直接用asciiread也是可以读入的。好像弄复杂了
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表