fortran - Fortran90 wrong output -


i'm working on small program course in university , i'm finished somehow doesn't work want work.

now, output file gravity1.dat should give me values unequal 0. doesnt... somewhere in last formula calculate g(surf), 1 of variables 0. if tried in power correct can't seem fix it.

program gravity  implicit none real(8) lx,ly,sx,sy,xsphere,ysphere,r,a,rho1,rho2,dx,g integer np,nel,nelx,nely,i,nnx,nny,j,counter,nsurf real(8),dimension(:),allocatable :: xcgrid real(8),dimension(:),allocatable :: ycgrid real(8),dimension(:),allocatable :: xgrid real(8),dimension(:),allocatable :: ygrid real(8),dimension(:),allocatable :: rho real(8),dimension(:),allocatable :: xsurf, gsurf real(8),dimension(:),allocatable :: ysurf  nnx=11. nny=11. lx=10. ly=10. nelx=nnx-1. nely=nny-1. nel=nelx*nely np=nnx*nny sx=lx/nelx sy=ly/nely xsphere=5. ysphere=5. r=3. nsurf=7  !number of gravimeters  dx=lx/(nsurf-1.)  !==========================================================  allocate(xgrid(np)) allocate(ygrid(np))  counter=0 i=1,nnx     j=1,nny     counter=counter+1        xgrid(counter)=dble(i-1)*sx     ygrid(counter)=dble(j-1)*sy     end end  call write_two_columns(np,xgrid,ygrid,'grid_init1.dat') !==========================================================  allocate(xcgrid(np)) allocate(ycgrid(np))   counter=0 i=1,nnx-1     j=1,nny-1     counter=counter+1        xcgrid(counter)=dble(i-1)*sx+0.5*sx     ycgrid(counter)=dble(j-1)*sy+0.5*sy     end end  call write_two_columns(np,xcgrid,ycgrid,'gridc_init1.dat') !==========================================================  allocate(rho(nel))  rho1=3000. !kg/m^3 rho2=3200. !kg/m^3  i=1,nel       if (sqrt((xsphere-xcgrid(i))**2)+((ysphere-ycgrid(i))**2)<r)     rho(i)=3200.     else      rho(i)=3000.     end if end  call write_three_columns(nel,xcgrid,ycgrid,rho,'inclusion1.dat') !==========================================================  allocate(xsurf(nsurf)) allocate(ysurf(nsurf))  i=1,nsurf xsurf(i)=(i-1)*dx ysurf(i)=ly end  call write_two_columns(nsurf,xsurf,ysurf,'surf_init1.dat') !==========================================================  allocate(gsurf(nsurf))  g=0.000000000066738480 !m^3 kg^-1 s^-2  i=1,nsurf     j=1,nel     gsurf(i)=gsurf(i)+(-2.*g*(((rho(i)-rho1)*(ycgrid(counter)-ysurf(i)))/((xcgrid(counter)-xsurf(i))**2.+(ycgrid(counter)-ysurf(i))**2.))*sx*sy)      end end  call write_two_columns(nsurf,xsurf,gsurf,'gravity1.dat')  deallocate(xgrid) deallocate(ygrid) deallocate(xcgrid) deallocate(ycgrid) deallocate(xsurf) deallocate(ysurf) deallocate(gsurf) end program 

the subroutines used:

!===========================================  subroutine write_two_columns (nnn,xxx,yyy,filename) implicit none integer i,nnn real(8) xxx(nnn),yyy(nnn) character(len=*) filename  open(unit=123,file=filename,action='write') i=1,nnn write(123,*) xxx(i),yyy(i) end close(123) end subroutine 

and other subroutine:

!===========================================  subroutine write_three_columns (nnn,xxx,yyy,zzz,filename) implicit none integer i,nnn real(8) xxx(nnn),yyy(nnn),zzz(nnn) character(len=*) filename open(unit=123,file=filename,action='write') i=1,nnn write(123,*) xxx(i),yyy(i),zzz(i) end close(123) end subroutine  !=========================================== 

shouldn't (rho(j)-rho1)? fill rho(1:nel), use rho(1:7)!

by way, careful variable initialization... assign reals integers, , mixed type arithmetics. careful might lead unexpected results. use compiler detect issues.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -