Hi I'm trying to write a code for Curve Fitting, before I go further I should declare that I'm not an experienced programer I'm still learning Fortran and programing. Here is what happens I need to transpose F matrix and store it in Fbar I do it by calling my transposer subroutine here is my code: (it is fragmented cause it is not complete yet).
there are two problems with it currently I decided to make pi a Parameter first it said you can't use atan intrinsic function in initializing and what you see now is my second try which was in vain again. the second and primary problem with the code is when I run my program (without pi being a parameter) I get Access Violation error which points to this line: Fbar(j,i) = F(i,j) from my subroutine. I tried to understand what was the problem but I couldn't since the error doesn't give me enough information 😦
EDIT: I found my error for access violation I did not allocate Fbar but the first question is still there how can I have pi as constant?
Program Curve_Fitting1
implicit none
integer :: i, j, n, m
real, dimension(:,:), allocatable :: F
real, dimension(:,:), allocatable :: Fbar
real, dimension(2,5) :: P !Data points
real :: c
c = 4.0*atan(1.0)
real, parameter :: e = 0.00001, pi = c
OPEN (10, file='data.txt', status='old', action='read')
READ (10,*) P
allocate (F(5,3))
do i = 1, 5
F(i,1) = 1.0/2
F(i,2) = cos(pi*P(1,i)/2000.)
F(i,3) = cos(2.*pi*P(1,i)/2000.)
end do
n = 5
m = 3
call transposer (n, m, F, Fbar)
write (*,*) Fbar(1,:)
read (*,*) m
end program Curve_Fitting1
!##############################################################
!funcstions and subroutines####################################
!##############################################################
subroutine transposer (n, m, F, Fbar)
implicit none
integer, intent(in) :: n
integer, intent(in) :: m
real, dimension(n,m), intent(in) :: F
real, dimension(m,n), intent(out) :: Fbar
integer :: i, j
do i = 1, n
do j = 1, m
Fbar(j,i) = F(i,j)
end do
end do
end subroutine transposer