2013-10-15 4 views
3

fortran f95를 사용하고 있습니다. 내 OS는 Windows 7, 64 비트입니다.fortran에서 excel 파일 가져 오기 fortran (ftn95)

데이터를 플로팅 할 수 있도록 Excel 파일로 출력하고 싶습니다. 아무도 이것을하는 방법을 아는가? 귀하의 답변은 높이 평가됩니다. 추신 : 출력 파일에 x, f (i), fprime1, fprime2, fprime3, diff1, diff2 및 diff3을 포함하고 싶습니다. 이 코드는 다음과 같이 언급된다 : 공간 또는 쉼표로 구분 된 파일

**

! This program calculates the first derivative of 
! a function, where f(x)= sin x. It makes use of the 
! centred-difference formula using 3 values of the step size: h1, h2, h3. 
! It also calculates the 
! analytical first derivative of the function. 
Program centred_difference_first_derivative 
implicit none 
real :: x, h1, h2, h3, fprime1, fprime2, fprime3, diff1, diff2, diff3, pi, stepa 
real,dimension(:), allocatable :: f 
integer :: i 
! Assignment of variables 
x=0.0 
pi=4*atan2(1.0,1.0) 
allocate(f(41)) 
stepa=pi/20.0 
h1=0.1 
h2=0.01 
h3=0.001 
! Calculate analytical derivative of sin x 
! for the domain x:[0,2pi] 
do i=1,41 
    f(i)=cos(x) 
    x=x+stepa 
    end do 

! Approximates first derivative of sin x 
! step size h1, for the domain x:[0,2pi] 
    x=0.0 
do i=1,41 
    fprime1=(sin(x+h1)-sin(x-h1))/(2*h1) 
    diff1=f(i)-fprime1 
    print 37, x,f(i),fprime1,diff1 
    x=x+stepa 
    end do 
37 format(e15.8,3x,e15.8,3x,e15.8,3x,'ERROR1= ',e15.8) 

! Approximates first derivative of sin x 
! step size h2, for the domain x:[0,2pi] 
    x=0.0 
do i=1,41 
    fprime2=(sin(x+h2)-sin(x-h2))/(2*h2) 
    diff2=f(i)-fprime2 
    print 49,x,f(i),fprime2,diff2  
    x=x+stepa 
    end do 
49 format(e15.8,3x,e15.8,3x,e15.8,3x,'ERROR2= ',e15.8) 
! Approximates first derivative of sin x 
! step size h3, for the domain x:[0,2pi] 
    x=0.0 
do i=1,41 
    fprime3=(sin(x+h3)-sin(x-h3))/(2*h3) 
    diff3=f(i)-fprime3 
print 61,x,f(i),fprime3,diff3  
    x=x+stepa 
    end do 
61 format(e15.8,3x,e15.8,3x,e15.8,3x,'ERROR3= ',e15.8) 
end program 

**

+7

Fortran'write' 문을 사용하는 방법을 알고 있습니까? 그렇게한다면, 그것을 사용하여'csv' 파일을 작성하십시오; Excel에서 이러한 파일을 쉽게 읽을 수 있습니다. 'write' 문을 모른다면 학습을하고 코드가있을 때 돌아와 도움을 청합니다. –

+1

HPM이 말한 것 이외에도 여러 가지 방법으로이 문제를 해결할 수 있습니다. 하나는 앞서 언급 한 CSV 접근 방식입니다. 오히려 잘 작동합니다. 최소한의 소란. 끊임없이 다시로드되고 계속 음모를 꾸미는 것에 대해 생각하고 있다면 출력물을 읽을 수있는 매크로를 조사하고 엑셀 워크 시트로 읽어 보는 것이 좋습니다. 또한 "직접"파일을 작성하는 라이브러리도 있지만 가장 복잡한 접근 방법입니다. – Rook

답변

1

출력하여 데이터. Excel에는 이러한 파일을 올바르게 처리하고 표시하는 텍스트 가져 오기 기능이 있습니다.

예를 들어 소스 코드와 예제가 here - TECPLOT_WRITE 인 Fortran을 사용하여 간단하게 작성할 수있는 ASCII tecplot 파일을 예로들 수 있습니다. 짧은 미리보기가 이어집니다.

! 
! Write the zone header. 
! 
    write (iunit, '(a)') ' ' 
    write (iunit, '(a,i6,a,i6,a,i6,a)') 'Zone I=', nr, ', J=', nz, 'K=', & 
    nt, ', F=POINT' 
! 
! Write the zone data, one node at a time. 
! 
    do k = 1, nt 
    do j = 1, nz 
     do i = 1, nr 

     x = r(i) * cos (t(k)) 
     y = r(i) * sin (t(k)) 

     vx = vr(i,j) * cos (t(k)) - vt(i,j) * sin (t(k)) 
     vy = vr(i,j) * sin (t(k)) + vt(i,j) * cos (t(k)) 

     write (iunit, '(3f10.3,3g15.6)') x, y, z(j), vx, vy, vz(i,j) 

     end do 
    end do 
    end do