calling multiple files in FORTRAN90
Kindly I request a help on my FORTRAN90 code. I have written FORTRAN code to calculate density profile. This code will open two files ( topology and x,y,z trajectory). The trajectory file contains XYZ data coordinates for multiple frames (about 20 or 100 frames for instance). One frame contains 20736 data.
Previously this code was written to open ONLY one input XYZ data file and do the calculation and would dump the results in separate file and it was running without problem. Recently my data file get bigger in size, so I decided to break the single XYZ data file into few small parts. Now I have modified the code so that it calls the parts of the XYZ data files ( eg: maltoTHERMO_10Frames.traj, maltoTHERMO_20Frames.traj,... and so on) and do the calculation and dump the results in the same result output file. I have tested this code just with openning the XYZ coordinates and printing into another file to see wheather it collecting the data sequently and it was working fine. This code supposedly read the x coordinate data and calculate distance and put a count accoding the criteria in the approperiate bins. But when I let the code to do the calculation it stop and shows error. (I have indicated as !** in the code). If I enable this line, it shows error but if I disable this line, than the code do collect only the XYZ coordinates. Could anyone help to correct this code? Many thanks in advance. The code is as below: Code:
|
Hi. It would be useful if you can post the exact error message. Furthermore, please use CODE tags to embed your code, so that it will result far more readable. To use code tags, either go in advanced mode, select the text and press the button marked with #, OR explicitly write the two tags [CODE] and [/CODE] before and after the text, respectively.
|
Quote:
I have have taged in code mode. Regards |
Thank you. Nevertheless you did not show us the exact error message. What is the complete output of the program whenever it stops working?
|
I use script to run this code. In side the code there I typed
gfortran ldp_malto_lowLyo1000_test2.f90 -o ldp_malto_lowLyo1000_test2.out ./ldp_malto_lowLyo1000_test2.out And the error output is as below: ./ldp_run.sh: line 6: 11054 Segmentation fault ./ldp_malto_lowLyo1000_test2.out regards |
It's difficult to debug a segmentation fault error without having the possibility of running the code (we miss the input files). In general a segmentation fault happens when the program tries to access a memory location which is beyond that one allocated/requested by the program itself.
Regarding the multiple files reading, personally I would do something different: I would not open multiple I/O units, but I would stick with opening/closing only one unit by changing the name of the file in a loop (or by reading the file names passed as arguments to the program). I don't think this is the problem here, anyway. I can't see any macroscopic error in the code, except the following (I'm not sure it is correct): Code:
read(jjj,'(10F8.3)') (x(i),y(i),z(i),i = 1,total_atoms) ! reading TRAJ file |
Yea,
That was the error. When I correct it as 3, it runs fine. Thank you so much for your kind help. It helps me to understand the meaning of segmentation fault. Regards Quote:
|
So that was the problem! Most likely it stored some weird value in x, y and z and the subsequent calculation of xDistance and BIN brought to an invalid index for the ldp_HEAD_hist62 array. Glad to see it works now! Kind regards.
|
All times are GMT -5. The time now is 01:01 AM. |