ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have two files which contains 30 real numbers in each file.The file names are DATA1real.dat and DATA1real.dat. I want to count the occurences of these numbers in pair in a two dimensional bins.
The code that I have written functions well for integer type of data but it fails for real type of data. So to convert the data type from real to integer I used NINT function. But it still fails.
I can compile the code without any error but when I run it it appears a message as "Segmentation fault". There is no other messages which could help. I couldn't figure out what is the wrong with this code.
I have given the two data and the code as well. Please help me to fix this problem. Thank you in advance.
The code is :
program surveyDATA
implicit none
!
! Define variables
integer :: i, j, n, k
integer :: total, dataX, dataY
integer :: experience, level
integer,parameter :: bilData=30
integer,dimension(5,4) :: survey
real,dimension(bilData) :: arrData1, arrData2
integer,dimension(bilData) :: arrData11, arrData22
!
! Initialize the array
do i = 1,5
do j= 1,4
survey(i,j) = 0
end do
end do
!
! Oepn files
open(unit=51,file="DATA1real.dat")
read(51,*) (arrData1(i), i=1, bilData)
!write(*,*) (arrData1(i), i=1, bilData)
!
open(unit=52,file="DATA2real.dat")
read(52,*) (arrData2(j), j=1, bilData)
!write(*,*) (arrData2(j), j=1, bilData)
!
!do k = 1, bilData
! arrData11(k) = NINT(arrData1(k))
! arrData22(k) = NINT(arrData2(k))
!end do
! As responses is read increase the count in table position
do i = 1, bilData
do j = 1, bilData
dataX = NINT(arrData1(i))
dataY = NINT(arrData2(j))
! print*, dataX, dataY
survey(dataX, dataY) = survey(dataX, dataY) + 1
end do
end do
!
! Print out the survey resluts
print*,"************* Results *****************"
do i = 1,5
print*, survey(i,1), survey(i,2), survey(i,3), survey(i,4)
end do
!
! Calculate the total data
total=0.0
do i = 1,5
do j = 1,4
total = total + survey(i,j)
end do
end do
print*, "Total numbers of datas are, ", total
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1
end program surveyDATA
I don't know Fortran. If my answer isn't what you need, try editing the title of your post to mention Fortran, so you attract the attention of someone who does know it.
Edit your first post in the thread, then click the "Advanced" button, then you can edit the thread title. I think the title should be segmentation fault in Fortran program
You definitely need to step through your program to determine exactly WHERE the segmentation violation is occurring.
If you're using a Gnu FORTRAN compiler (for example, "g77"), then you can use "gdb".
Even if you don't set breakpoints, step through your code, or display variables (all very useful things to do with any debugger), running inside of gdb will at least give you a LINE NUMBER (to help you locate the source of the problem).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.