Fortran 读入向量列并进行拟合 我的数据文件(expansioncefs.dat)像一个向量列,有33个x值,后面是15789个f(x)块,由五个整数分隔,我想读取x和任何f(x)块,并使用三次样条方法进行拟合 当我编译代码时,我的输出文件是空的

Fortran 读入向量列并进行拟合 我的数据文件(expansioncefs.dat)像一个向量列,有33个x值,后面是15789个f(x)块,由五个整数分隔,我想读取x和任何f(x)块,并使用三次样条方法进行拟合 当我编译代码时,我的输出文件是空的,fortran,Fortran,代码 样本数据 示例输出文件 我已经读了好几遍了,不明白你在问什么。请你把课文修改一下,澄清一下好吗? implicit none real(kind=8),dimension(:), allocatable::x, y real(kind=8) ,allocatable::a(:), b(:), c(:), d(:) Real,Allocatable::inputdat(:,:),param(:,:) real(8) :: mat( 1:3, 1:33,

代码

样本数据

示例输出文件


我已经读了好几遍了,不明白你在问什么。请你把课文修改一下,澄清一下好吗?
    implicit none
    real(kind=8),dimension(:), allocatable::x, y
    real(kind=8) ,allocatable::a(:), b(:), c(:), d(:)
    Real,Allocatable::inputdat(:,:),param(:,:)
    real(8) :: mat( 1:3, 1:33, 1:15789)!,tab(1:33,1:15790)
    integer::n
    
end module interpolation ! end of interpolation module.

program main ! start of main program.
    use interpolation
    implicit none
    character (len=14) :: nameformat, nom
    real(kind = 8)::sj, xin, f
    integer:: j, i
         
    open(100, file='expansioncoefs.dat',status='unknown') 

    Allocate (x(33))                
    Allocate (inputdat(33,15789))
    Allocate (param(15789,5))

    do i=1,33 
    read(100,*) x(i) 
!   write(*,*)x(i)
    enddo 
    do j=1,15789 
    read(100,*) param(j,1),param(j,2),param(j,3),param(j,4),param(j,5)
    do i=1, 33 
    read(100,*) inputdat(i, j)

!   print*, x(i), inputdat(i, j)
    enddo
    enddo
!   Do i=1,33                   

!   

    close(100)

    allocate(y(0:32))
    

    x(1:33) = x
    

        !print*, y
    allocate(a(0:32), b(0:32), c(0:32), d(0:32))
    
    b = 0.0; c = 0.0; d = 0.0
    do i = 1, 15789
    a(0:32) = inputdat(1:33, i+1)
!   a(0:32) = tab(1:33, i+1)

    enddo  
     
   
!   allocate a, b, c, and d arrays.
    
!
    a = y
!
!   call natural cubic spline subroutine.
    call natural_cubic_spline(n,x,a,b,c,d)
    mat(1,1:33,i) = b(0:32)
    mat(2,1:33,i) = c(0:32)
    mat(3,1:33,i) = d(0:32)
      

!   Interpolate data and write to file.
    
    
    do j = 1, 15789
    b(0:32) = mat(1,1:33,j)
    c(0:32) = mat(2,1:33,j)
    d(0:32) = mat(3,1:33,j)
    enddo
  
    do i=1,15789
    nameformat="(A5,I0.5,A4)"
    write(nom,nameformat) "srf_V",i,".asc" !extension
    print*,i,nom

    open (i, file=nom, status='unknown')
    enddo
       
    do i=1,128 
    xin=4.0+dble(i-1)*(12.0-4.0)/(128-1)! grid of 128 points

    write(i,"(e25.14)") f(xin) 
 
    enddo
      
      
     
!
    deallocate(x,y)
    deallocate(a, b, c, d)
!
    stop
end program main ! end of main program.

    real(kind = 8) function f(xin) ! start of interpolant function f.
    use interpolation
    implicit none
    real(kind = 8),intent(in)::xin
    integer:: j, i
!
    do i = 0,n-1
        if((x(i) .le. xin).and.(xin .le. x(i+1)))then
            j = i
            exit
        endif
    enddo
!
    f = a(j) + b(j)*(xin - x(j)) + c(j)*(xin - x(j))**2 + d(j)*(xin - x(j))**3 
!
    return
end function f ! end of interpolant function f.



subroutine natural_cubic_spline(n,x,a,b,c,d) ! start of natural_cubic_spline subroutine.
    implicit none
    integer,intent(in)::n
    real(kind = 8),intent(in)::x(0:n)
    real(kind = 8),intent(inout):: a(0:n)
    real(kind = 8),intent(out):: b(0:n), c(0:n), d(0:n)
    integer:: i, j
    real(kind = 8):: h(0:n), alpha(0:n), l(0:n), mu(0:n), z(0:n)
!
    h = 0.0; alpha = 0.0
!
!   step 1:
    do i = 0,n-1
        h(i) = x(i+1) - x(i)
    enddo
!
!   step 2:
    do i = 1,n-1
        alpha(i) = (3.0/h(i))*(a(i+1) - a(i)) - (3.0/h(i-1))*(a(i) - a(i-1))
    enddo
!
!   step 3:
    l(0) = 1.0; mu(0) = 0.0; z(0) = 0.0;
!
!   step 4:
    do i = 1,n-1
        l(i) = 2.0*(x(i+1) - x(i-1)) - h(i-1)*mu(i-1)
        mu(i) = h(i)/l(i)
        z(i) = (alpha(i) - h(i-1)*z(i-1))/l(i)
    enddo
!
!   step 5:
    l(n) = 1.0; z(n) = 0.0; c(n) = 0.0
!
!   step 6:
    do j = n-1,0,-1
        c(j) = z(j) - mu(j)*c(j+1)
        b(j) = (a(j+1) - a(j))/h(j) - h(j)*(c(j+1) + 2.0*c(j))/3.0
        d(j) = (c(j+1) - c(j))/(3.0*h(j))
    enddo
!
    return
end subroutine natural_cubic_spline ! end of natural_cubic_spline subroutine.
    4.000
    4.250
    4.500
    4.750
    5.000
    5.250
    5.500
    5.750
    6.000
    6.250
    6.500
    6.750
    7.000
    7.250
    7.500
    7.750
    8.000
    8.250
    8.500
    8.750
    9.000
    9.250
    9.500
    9.750
   10.000
   10.250
   10.500
   10.750
   11.000
   11.250
   11.500
   11.750
   12.000
 0 0 0 0 0
     0.55977887068214E-01
     0.33301830925674E-01
     0.19357033058574E-01
     0.10851672673603E-01
     0.57601109719013E-02
     0.27793714306045E-02
     0.10812628240276E-02
     0.15097129824141E-03
    -0.32616649818477E-03
    -0.54065650568596E-03
    -0.60723892717492E-03
    -0.59463219747272E-03
    -0.54352144592126E-03
    -0.47743610751912E-03
    -0.40939905472145E-03
    -0.34605270924249E-03
    -0.29025099403574E-03
    -0.24269312486307E-03
    -0.20294374360102E-03
    -0.17005393420182E-03
    -0.14292238222802E-03
    -0.12048981961726E-03
    -0.10182978503448E-03
    -0.86178058019242E-04
    -0.72928575326720E-04
    -0.61613399268902E-04
    -0.51877242408502E-04
    -0.43452338487951E-04
    -0.36136444117556E-04
    -0.29774951350710E-04
    -0.24247094860570E-04
    -0.19455757052863E-04
    -0.15320203216670E-04
 0 0 1 0 1
    -0.36741232178207E-01
    -0.22980380651746E-01
    -0.14289660523504E-01
    -0.87248119186359E-02
    -0.52165015737020E-02
    -0.30442559592531E-02
    -0.17187672278215E-02
    -0.92034864768368E-03
    -0.44665388594640E-03
    -0.17180624691644E-03
    -0.18029835246793E-04
     0.62656319960734E-04
     0.99836676728874E-04
     0.11171390876218E-03
     0.10943210935956E-03
     0.99757700760475E-04
     0.86750134905736E-04
     0.72803446694530E-04
     0.59292387637833E-04
     0.46969693677009E-04
     0.36207932127320E-04
     0.27145815868709E-04
     0.19777037041139E-04
     0.14005279090632E-04
     0.96796384761379E-05
     0.66186600707396E-05
     0.46274884107037E-05
     0.35104872762797E-05
     0.30805231563062E-05
     0.31655489297527E-05
     0.36128958849786E-05
     0.42916155098686E-05
     0.50932078733324E-05
 0 0 2 0 2
  ```
       1 srf_V00001.asc
       2 srf_V00002.asc
       3 srf_V00003.asc
       4 srf_V00004.asc
       5 srf_V00005.asc
       6 srf_V00006.asc