Fortran Coder

标题: 有偿求助点云曲面拟合函数接口 [打印本页]

作者: 天马行空    时间: 2024-6-16 09:59
标题: 有偿求助点云曲面拟合函数接口
现有曲面点云数据(Xi,Yi,Zi),曲面范围很小(投影面Xi,Yi)是一个局部有限的连续空间曲面,想求助可以根据点云数据,确定曲面拟合的接口函数(如NURBS曲面),多项式最小二乘法拟合效果不太好(已经尝试过了),采用IMSL库自带的Surface_Fitting函数调用提示Compliation Aborted,估计是编译器不兼容,请问有没有朋友做过类似的接口或者有相关的经验,可以提供对应的接口或者函数不?跪谢了,有偿求助,不胜感激! 我的编译器版本是IVF2013,IMSL7.0,后者可以解决imsl调用的问题也可以。 如果愿意提供帮助的,麻烦您联系:

QQ: 50604800

有偿求助,跪谢!

作者: 天马行空    时间: 2024-6-16 10:13
  调用IMSL中的一个使用手册的例子程序如下(顺带编译报错结果,去掉调用函数Surface_Fitting,则编译可以通过)
[Fortran] 纯文本查看 复制代码
  program Test_SurfaceFitting
      INCLUDE 'link_fnl_shared.h'
      use numerical_libraries
  
      USE surface_fitting_int
      USE rand_int
      USE norm_int

      implicit none

! This is Example 1 for SURFACE_FITTING, tensor product
! B-splines approximation.  Use the function
! exp(-x**2-y**2) on the square (0, 2) x (0, 2) for samples.
! The spline order is "nord" and the number of cells is
! "(ngrid-1)**2".  There are "ndata" data values in the square.

      integer :: i
      integer, parameter :: ngrid=9, nord=4, ndegree=nord-1, &
      nbkpt=ngrid+2*ndegree, ndata = 2000, nvalues=100
      real(kind(1d0)), parameter :: zero=0d0, one=1d0, two=2d0
      real(kind(1d0)), parameter :: TOLERANCE=1d-3
      real(kind(1d0)), target :: spline_data (4, ndata), bkpt(nbkpt), &
             & coeff(ngrid+ndegree-1,ngrid+ndegree-1), delta, sizev, &
             & x(nvalues), y(nvalues), values(nvalues, nvalues)
      real(kind(1d0)), pointer :: pointer_bkpt(:)
      type (d_spline_knots) knotsx, knotsy

! Set Random Number generator seed
                                             
      real(kind(1d0)),parameter::zero_par=0.d0
      real(kind(1d0))::dummy_par(0)
      integer iseed_par,lev_par
      type(d_options)::iopti_par(2)

      iseed_par = 53976279
      iopti_par(1)=d_options(d_rand_gen_generator_seed,zero_par)
      iopti_par(2)=d_options(iseed_par,zero_par)

      call rand_gen(dummy_par,iopt=iopti_par)

! Generate random (x,y) pairs and evaluate the
! example exponential function at these values.   
      spline_data(1:2,:)=two*rand(spline_data(1:2,:))
      spline_data(3,:)=exp(-sum(spline_data(1:2,:)**2,dim=1))
      spline_data(4,:)=one

! Define the knots for the tensor product data fitting problem.
      delta = two/(ngrid-1)
      bkpt(1:ndegree) = zero
      bkpt(nbkpt-ndegree+1:nbkpt) =  two
      bkpt(nord:nbkpt-ndegree)=(/(i*delta,i=0,ngrid-1)/)

! Assign the degree of the polynomial and the knots.
      knotsx%spline_degree=ndegree
      knotsx%d_knots=>bkpt
      knotsy%spline_degree=knotsx%spline_degree
      knotsy%d_knots=>knotsx%d_knots

! Fit the data and obtain the coefficients.
      coeff = surface_fitting(spline_data, knotsx, knotsy)

! Evaluate the residual = spline - function
! at a grid of points inside the square.
      delta=two/(nvalues+1)
      x=(/(i*delta,i=1,nvalues)/); y=x

      values=exp(-spread(x**2,1,nvalues)-spread(y**2,2,nvalues))
      values=surface_values((/0,0/), x, y, knotsx, knotsy, coeff)-values
            
! Compute the R.M.S. error:
      sizev=norm(pack(values, (values == values)))/nvalues

      if (sizev <= TOLERANCE) then
         write (*,*) 'SURFACE_FITTING_EX1 Passed on pcdsms.'
      else
         write(*,*) 'SURFACE_FITTING_EX1 ********** Failed on pcdsms **********'
      end if
end program

在IVF2013中调用MSL6.0函数库中的B样条拟合曲面函数,Surface_Fitting函数,编译的时候出现如下报错:
1>------ 已启动生成:  项目: SurfaceFitting, 配置: Debug Win32 ------
1>Compiling with Intel(R) Visual Fortran Compiler XE 14.0.1.139 [IA-32]...
1>SurfaceFitting.f90
1>fortcom: Fatal: There has been an internal compiler error (C0000005).
1>compilation aborted for E:\IVF_File\SurfaceFitting\SurfaceFitting\SurfaceFitting.f90 (code 1)
1>
1>Build log written to  "file://E:\IVF_File\SurfaceFitting\SurfaceFitting\Debug\BuildLog.htm"
1>SurfaceFitting - 1 error(s), 0 warning(s)
========== 生成:  成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========
作者: fcode    时间: 2024-6-19 10:41
这个应该是 IMSL 的问题。surface_fitting_int.mod 文件损坏了,找找官方吧。
作者: 天马行空    时间: 2024-6-19 14:23
谢谢坛主,Surface_Fitting.Mod的文件损坏了,还有其他的调用方式可以实现吗?谢谢。
作者: fcode    时间: 2024-6-19 15:09
你可以试图根据帮助文档,自己写一个同名的 Module Surface_fitting_int。
只需要包含你需要调用的函数即可,只写函数接口,不写函数内部实现过程。
作者: 天马行空    时间: 2024-6-19 22:59
fcode 发表于 2024-6-19 15:09
你可以试图根据帮助文档,自己写一个同名的 Module Surface_fitting_int。
只需要包含你需要调用的函数即可 ...

谢谢堂主,本人愚钝,不明深意,写一个同名的Module,但是接口无法调用,又如何能够实现呢?
作者: fcode    时间: 2024-6-20 11:38
大概就像这样,我只复原了 D_SURFACE_FITTING 和 DV_SURFACE_VALUES 两个函数。没有写其他接口。
某些版本的IMSL可能是 D_SURFACE_VALUES 而不是 DV_SURFACE_VALUES。

[Fortran] 纯文本查看 复制代码
Module surface_fitting_int
  USE norm_int
  implicit none
  interface surface_fitting
    function D_SURFACE_FITTING(DATA,KNOTSX,KNOTSY,CONSTRAINTS,COVARIANCE,IOPT,epack)
      import
      implicit none
      type (d_spline_knots) :: knotsx, knotsy
      real(kind(1d0)) :: DATA(:,:)
      type (d_SURFACE_CONSTRAINTS) , optional :: CONSTRAINTS(:)
      real(kind(1d0)) , optional :: COVARIANCE(:,:)
      type (d_options) , optional :: iopt(:)
      type (d_error) , optional :: epack
      real(kind(1d0)) :: D_SURFACE_FITTING(size(KNOTSX%D_KNOTS)-KNOTSX%SPLINE_DEGREE-1,size(KNOTSY%D_KNOTS)-KNOTSY%SPLINE_DEGREE-1)
    end function D_SURFACE_FITTING   
  end interface surface_fitting

  interface SURFACE_VALUES   
    function DV_SURFACE_VALUES(DERIVATIVE, VARIABLESX, VARIABLESY, KNOTSX, KNOTSY, COEFFS)
      import
      implicit none
      integer :: DERIVATIVE(2)
      real(kind(1d0)) :: VARIABLESX(:), VARIABLESY(:)
      type (d_spline_knots) :: knotsx, knotsy
      real(kind(1d0)) :: COEFFS(:,:)
      real(kind(1d0)) :: DV_SURFACE_VALUES(size(VARIABLESX),size(VARIABLESY))
    end function DV_SURFACE_VALUES
  end interface SURFACE_VALUES

End Module surface_fitting_int




作者: 天马行空    时间: 2024-6-20 16:02
fcode 发表于 2024-6-20 11:38
大概就像这样,我只复原了 D_SURFACE_FITTING 和 DV_SURFACE_VALUES 两个函数。没有写其他接口。
某些版本 ...

堂主太伟大了,谢谢啦,我试试看看能否解决问题。
作者: 天马行空    时间: 2024-6-20 17:34
堂主好,我亲自试验了,真的可以解决这个问题啊,重新编译没有报错了,直接通过!
堂主太伟大了,顺便请教下:为什么封装一下就可以编译通过呢?这是啥原因呢?谢谢!

作者: fcode    时间: 2024-6-20 19:01
天马行空 发表于 2024-6-20 17:34
堂主好,我亲自试验了,真的可以解决这个问题啊,重新编译没有报错了,直接通过!
堂主太伟大了,顺便请教 ...

Module 编译出来的 .mod 文件就像是C语言的头文件。
但是不同编译器编译出来的 .mod 格式有些不同。
可能是 IMSL 用的编译器和 intel 现在的编译器有些区别,就导致直接使用IMSL官方的 .mod 文件出错。

重新封装一个 Module ,然后用现在的 intel 编译器编译出自己的 .mod 文件,就没问题了。
但这样编译出来的 .mod 文件,只能使用这两个函数,并不是完整的。
如果要使用别的函数,也需要再复原其他函数的接口才行。

原则上,IMSL应该像其他一些函数库一样,公布这种接口 module 的源代码,但似乎并没有。
作者: 天马行空    时间: 2024-6-27 09:39
fcode 发表于 2024-6-20 19:01
Module 编译出来的 .mod 文件就像是C语言的头文件。
但是不同编译器编译出来的 .mod 格式有些不同。
可能 ...

感谢版主,您辛苦了!
可以再麻烦您帮我看看另外一个函数
Surface_Constraints的接口函数如何编写呢?自己写了很久,感觉都调用不成功,谢谢您!




欢迎光临 Fortran Coder (http://bbs.fcode.cn/) Powered by Discuz! X3.2