Fortran Forum for Programming Help: Resources, Tips, and Support

In summary, this conversation is about a closed thread on Fortran programming and the suggestion to visit a different forum for help. A new user also asks for help with Fortran 77 and is given a definition of a common block and how to use it. An example of a code using a common block is provided, but the user encounters errors when compiling.
  • #71
Please can you help me with this code in FORTRAN 95, attached with the errors
Code:
module A
   implicit none
   ! DEFINE GLOBAL DATA
   integer, parameter :: dp=kind(1.0d0)
   integer ::	i,n,n_max
   !   
   integer, parameter :: no=30
   real(kind=dp), parameter :: zero=0,one=1,two=2
   real(dp), dimension(:) :: o,A,r,t,u
   real(dp), allocatable :: z(:)
    n = size(o)
    n = size(A)
    n = size(r)
    n = size(t)
    n = size(u)
   write(*,*) 'Input the dimension of matrix z'
   read(*,*) no_max
   allocate(z(no_max))
   !
   deallocate(z)
end module A
I've written this code as an example of module in F95, but I've got these error message
PHP:
Error: A.f90, line 12: syntax error
       detected at <end-of-statement>@WRITE
*** Malformed statement
*** Malformed statement
*** Malformed statement
*** Malformed statement
[f95 terminated - errors found by pass 1]
Anyone could help me please:frown::cry::cry:
 
Technology news on Phys.org
  • #72
Hi all!

I'm trying to model a differential equation having to do with free fall, using RK4 and Fortran 90. The equation is:

[tex]\ddot{y}(t)=-g\frac{R^2}{y^2}[/tex]

The code is attached in caidalibre.f90

The big problem is that function f(y,v,t) returns an unexpected value within the main program. Moreover, the program yields results which would indicate the object is ascending, and not descending. Any insight will be greatly appreciated.

Cheers!

PS: I am using

gfortran
Using built-in specs.
Target: powerpc-apple-darwin8.9.0
Configured with: ../gcc-4.3-20070810/configure --enable-threads=posix --enable-languages=fortran
Thread model: posix
gcc version 4.3.0 20070810 (experimental)
 

Attachments

  • caidalibre.f90.zip
    639 bytes · Views: 154
  • #73
It does not seem like you have the latest version of the program.
As it is , the values of g and R have not been tranmitted to function f.
Also the formal parameters v and t have not been used.
Do you have some data to run with?

To solve this DE, wouldn't it be simpler to integrate it w.r.t. y, unless it is an exercise on numerical analysis.
 
  • #74
URGENT anyone give a suggestion how to deal with a segmentation default error when I called a NAG routine in FORTAN 77 code
 
  • #75
It is a problem that can have many causes, mostly because the program is trying to access a part (segment) of the memory where it does not have the permission to read or to write.

If your compiler has a debugging option, activate it to see if it gives more information.
If there is a compiler option to check "arrays out of bounds", activate it even though it may execute slower than without.
Check your linker report to see if there are missing modules or libraries.

If everything else fails, recheck your code to see if the sizes of arrays are large enough, and have the right addresses. Check that the parameters of calls to functions and subroutines correspond in size and type with the formal parameters defined.

Try a reduced sized problem to see if the problem persists, which may give an idea if the problem comes from arrays out of bound or otherwise.

Good luck!
 
  • #76
mathmate said:
It is a problem that can have many causes, mostly because the program is trying to access a part (segment) of the memory where it does not have the permission to read or to write.

If your compiler has a debugging option, activate it to see if it gives more information.
If there is a compiler option to check "arrays out of bounds", activate it even though it may execute slower than without.
Check your linker report to see if there are missing modules or libraries.

If everything else fails, recheck your code to see if the sizes of arrays are large enough, and have the right addresses. Check that the parameters of calls to functions and subroutines correspond in size and type with the formal parameters defined.

Try a reduced sized problem to see if the problem persists, which may give an idea if the problem comes from arrays out of bound or otherwise.

Good luck!
I guess I've done that and ckecked many times, actaully my main program call a NAG routine, and this routine call a function which also call another NAG ROUTINE. Is this possible??I think so cos I have tried with
known funcion like sin(x)
 
  • #77
Yes, this is very possible.
When they build libraries, common routines are included to be called by different functions or modules to avoid repetition of code.
What is important is to see where the program went wrong, namely arrays out of bound, calling functions with invalid parameters, or other reasons such as bad linking. Another possibility is a complication as a result of an array out of bound overwriting code, which in turn causes program execution to jump outside of the program area.
Try a different problem, a smaller problem. If your compiler has a trace function, you can know at least the last function/subroutine called, and hence narrow down the search. If the trace function allows break points, you can examine the values of the variables at different times of the execution, unless you decide to put in various print statements throughout the code.
Did you by any chance activate the array-out-of-bounds check?
 
  • #78
I am using a numerical recipe which called(brent) and when I execute the code for the results it does not give me any error message, but giving me a warning message saying
PHP:
(PAUSE  brent exceed maximum iterations statement executed
To resume execution, type go.  Other input will terminate the job.
go
Execution resumes after PAUSE.)
and I type go the execution resume and give me right results, what I am thinking is that might affect the calculation, even I tried to make the IMAX in (brent) large enough 300, but still giving me warning
 
  • #79
I am curious to know what convinced you that 300 is a big enough number. Was this problem solved using some other programs? If this is the case, would you be able to compare the results?
Did the segment violation fault problem recur?
It seems that you are getting in the arena of Numerical Recipes. I believe the author of the code is quite active in the forum. You may get some ideas from him, especially if the number of iterations are involved. Try:
http://www.nr.com/forum/
There are also bug reports for which you can search (if you are registered).
 
  • #80
I have registered in this forum, and activate my account, but when I've tried to post , they said
PHP:
you do not have permission to access this page
it seem be a problem with this forum cos there are another registered members who couldn't post their question as well
 
  • #81
anyone could show me how to
PHP:
plot with colors in GNUPLOT,
as I need to plot two functions in the same graph
 
  • #82
please can you help me how to access for example the second column of a date file, also can I read a data file {which has been created in a function} in my main programme, when I tried to do tat it gives me the following error message
Code:
list in: end of file
apparent state: unit 6 named fort.6
last format: list io
lately reading direct formatted external IO
Aborted
 
  • #83
please can anyone help me out, I want to calculate the inverse of a complex matrix by calling some NAG routine, when I compile th file it does not give me any warning OR ERROR MESSAGES, but it give any results as well. her the code
Code:
INTEGER NMAX, LDA, LWORK
       PARAMETER (NMAX=8,LDA=NMAX,LWORK=64*NMAX)
* .. Local Scalars ..
       INTEGER I,INFO, J, N
* .. Local Arrays ..
       complex A(LDA,NMAX), WORK(LWORK)
       INTEGER IPIV(NMAX)
* .. External Subroutines ..
       EXTERNAL ZGETRI, ZGETRF
* .. Executable Statements ..
       WRITE (*,*) 'F07AWF Example Program Results'
* Skip heading in data file
       open(unit=4,file='NIN', status='unknown')
       READ (*,*) N
       IF (N.LE.NMAX) THEN
* Read A from data file
       READ (4,*) ((A(I,J),J=1,N),I=1,N)
       rewind 4
       close (4)
* Factorize A
       CALL ZGETRI(N,N,A,LDA,IPIV,INFO)
       print*, 'INFO=', INFO
       IF (INFO.EQ.0) THEN
* Compute inverse of A
*
        CALL ZGETRF(N,A,LDA,IPIV,WORK,LWORK,INFO)
* Print inverse
        open(unit=5,file='Inverse-Matrix.dat', status='unknown')
        do i = 1, N
             write(5,*)  (a(i,j), j = 1, N)
        end do
        close (5)
       ELSE
           WRITE (*,*) 'The factor U is singular'
       END IF
c       rewind 5
       END IF
       END
and I give the program the same matrix which has been giuven in the example with the NAG routine.
 
  • #84
can anyone help me out I need to fit some data file to some function by using the GNUPLOT, actually I have the command, the problem my function contains
PHP:
pi
, so can I define it in GNUPLOT as i do not want to deal with as a parameter
 
  • #85
Anybody has an idea why Fortran is performing so poorly in the Computer Langauge
Benchmarks Game
?

I just started to learn Fortran, mainly because I prefer it to C/C++ and needed speed. I've always heard Fortran was faster than C/C++, and C++ could only get close to Fortan using template techniques (beside, the compiler used for Fortran is made by Intel, while the GCC are used for C/C++).
 
  • #86
please mathmate can you help me in this
Hi guys
I have a code written by fortran 77, it has been working fine, but after I add some changes. I had compiled and does not give me any error messages, but when had the command ./a.out to display the results, it says killed, and I do not have no idea what this means.
please help me out
 
  • #87
Usually killed means that the code is terminated due to some uncorrectable error, such as array out of bounds, or calling a module that is outside the user's work area (hardware violation), or code has been overwritten with data.

First check if you have any way to activate array out-of-bounds check. This is the most common problem of this kind, if the original code was well established and checked.
If it is an iterative solution of some kind, print some indicative parameters at every iteration and see if the iterations are going haywire.

If all of the above don't get you anywhere, I could look at your code if you post the working and modified codes. If the code is too long to be posted, you can PM me with your e-mail address, I will contact you. On the other hand, if it is sensitive code, I would decline to avoid getting you entangled in doubts or problems.
 
  • #88
mathmate said:
Usually killed means that the code is terminated due to some uncorrectable error, such as array out of bounds, or calling a module that is outside the user's work area (hardware violation), or code has been overwritten with data.
As I had this guess because I made change in bounds of array, then it gives me this warning, but then I changed to the previous ones, but still giving me the killed warning message, and I have so many data files in my program...
mathmate said:
If all of the above don't get you anywhere, I could look at your code if you post the working and modified codes. If the code is too long to be posted, you can PM me with your e-mail address, I will contact you. On the other hand, if it is sensitive code, I would decline to avoid getting you entangled in doubts or problems.
The matter is not a senstive code or not, but it is that the code is very long and it is difficult to follow not because I am genouse but it deals with many equations...
 
  • #89
As I had this guess because I made change in bounds of array, then it gives me this warning, but then I changed to the previous ones, but still giving me the killed warning message, and I have so many data files in my program...
This is precisely why I would like to see your two versions of code. I was planning to use the unix utility diff to find the differences between them to check out inadvertent changes. I have no interest in understanding the code, but if I do find a difference between the two (old and reconstituted), I would need access to the logic to find out the consequences of the changes.

On the other hand, if you have access to the diff utility in Unix or the equivalent, you could do the same by yourself, as you probably understand the code much better than anyone else.

By the way, I would concentrate a little on out-of-bounds errors if you have modified or had intentions to modify the dimension limits. It could be caused by overflowing data, in which case a smaller model should run perfectly.
 
  • #90
mathmate said:
On the other hand, if you have access to the diff utility in Unix or the equivalent, you could do the same by yourself, as you probably understand the code much better than anyone else.
.

Hi mathmate, how can I access such utility, what is the command shell for it...cos I AM NOT SURE IF i HAVE it or no...:smile:
 
  • #91
Please Mathmate can you help me out in this, I need to solve a system of linear equations with complex coefficients, so I have used the NAG routine F04CAF.F, pleas see the attached which are the F04CAF.F and my file which is just the NAG file updated abit and does work fine for the given test example in pdf file, but is not giving me the right answer for this simple system
(2+2i)x+4y=1+i
-ix+2y=3
with solutions x=2.5+1.5i and y=0.75+1.25i
 

Attachments

  • 1.txt
    2.6 KB · Views: 459
  • f04caf.pdf
    149.1 KB · Views: 175
  • #92
segmentation fault

hii guys,
can anybody help me with a problem in my fortran programming..
basically i use fortran77...in which i have recently wrtten a large code...
It was running properly earlier for all combinations of cycles and steps...but nw it works only for smaller no. of cycles and steps...for larger ones..it takes the run command,runs for about an hr. or two giving sme output properly but then it suddenly stops with the message-----SEGMENTATION FAULT...and the outfile remains incomplete...
if anybody knws the solution...kindly help me with the same..
 
  • #93
Hello Mohs,
Segmentation fault usually means that you are trying to access an area of memory that does not belong to your program. This usually happens in one of the many cases, most of which relate to arrays out of bounds, directly or indirectly.
An array out-of-bounds can cause the problem directly, or it can overwrite some data or even program in your work area, thus causing the program to go haywire, and eventually it tries to branch outside of its execution area, and then segmentation error results.

Try to execute some data (large number of cycles and steps) that used to run before. If it still runs, there is a good chance you have to recheck your code. If the program does not run old (good) data, the environment has probably changed. So check what has changed since, code, memory, compiler, etc.

Good luck, and let us know how it goes.
 
  • #94
Anglea,

You will find many different versions of diff on XP (if that's your operating system) by googling "diff xp". I do not use any of those because I have a unix simulator from years back.

Also, I will look at the files and get back to you shortly.
 
  • #95
Anglea,
I tried to compile the code you send me, but am missing a module X04DBF.
Irrespective of that, could you confirm if your code gives you the following answers:
x=(11i-3)/10,y=-(3i-19)/20
This is what I got solving the equations manually, and have checked by back-substitution.
Could you double check on the problem or the answers?
 
  • #96
mathmate said:
Anglea,

You will find many different versions of diff on XP (if that's your operating system) by googling "diff xp". I do not use any of those because I have a unix simulator from years back.

thanks aloooooot...I am using unix, so what is the command to check weather I have it on not? regarding to the linear system ...yes I've got the same as you've got manually...did you solve them by eliminating the variables, cos that is what I used to get my solutions...
 
  • #97
Diff is directly available on any unix system. If you have the command-line screen where you can type in commands, typing in "man diff" will give you the command syntax.
Basically, use the cd command to go to the directory where the two source files reside, then type
diff file1.for file2.for
it will display the diffrerences, if any. Man diff will show you how to interprete the results.

with solutions x=2.5+1.5i and y=0.75+1.25i
Are these solutions from the program or are these your hand-calculated values?
I did mine by elimination, as you thought.

Perhaps you may want to check the input data to see if something was amiss. Also, you could try another set of equations just to double check.
 
  • #98
hii mathmate,
thanks for ur reply..i have checked all the runs..and the runs of the earlier types are also not working properly nw..actually i use the services of my institute so there is little way for me to check the changes of memory,compiler etc...the dimensions for the arrays are the same as i was using earlier...though i shud tell u here that i use 3D and 4D arrays...when i remove the one of the 3d arrays the it works smetimes but then it is compulsory for me to include all the 3D and 4D arrays...what shud i do in such a case...
pleasez help...
 
  • #99
In general, 3D and 4D arrays do not cause problems if you use them always as such. Sometimes programmers define a 3D array but access it as a simple array (for efficiency). That's when the size and access method is important. If you don't do that, it would not be a problem. On the other hand, this is the kind of problem that will fail a small sized problem, which seems to be your case.
Then, you can check the function/subroutine parameters. If the parameters in the calling program do not correspond in size, type and function as the subprogram definition, Fortran will likely let it go and give you useless results.
So has the program ever worked before? If so, get that working version and make a comparison (using diff or otherwise) to see what changes you have made, and take it from there.
If the program has never worked (properly) before, then you need to do tracing of the values of the variables at all stages of the calculations, either by a utility supplied with your compiler, or simply making print statements all over the place. For a simple problem, it should not be too troublesome to do so.

So there, give it a try and tell me what you get.
 
  • #100
hii mathmate..
actually my program has worked before properly for all combinations of cycles and steps...and i have nt made any changes since..but nw it has stopped workng properly...yesterday i tried making the initial values of one of the 3D arrays '1' instead of zero...then it worked for 2 cycles ,100steps for which it wasnt working...but when i made it 3 cycles 100 steps...it again strated giving the same problem..i just can't figure out why it is so...
 
  • #101
You may want to check program logic.
Trace back from where problem occurs by printing out values.
Again, find the exact set of data that used to work before, and see if it stops working now.
Print out all values for a simple problem and see where the logic starts to deviate.
Short of seeing the code or running the code, the above are the few options available.
 
  • #102
hii mathmate,
thanks for ur help..my problem has got solved..actually the logic of the program was gettng stuck after reaching a point where the program didnt knw how to proceed..so it was giving seg.fault and crashing..for smaller steps & cycles it was not gettng stuck due to certian conditions...i finally found itr and corrected it..thanks for ur replies..
 
  • #103
Glad that everything works out. Iterative problems are quite tricky and you seem to have managed to provide code for all the foreseeable cases.
 
  • #104
can anyone help me out in ...how to read a specific column id data file in FORTRAN 77, let say I have a data file of 5 columns , I need to read the third column...
 
  • #105
Are the columns in fixed format or free format, for example,
fixed format:
123 2345 2456
482 2421 5820
Free format
1 2024 2520
24556 24821 23

If it is in fixed format, and the third column of data falls betwen the 11th to 15th characters, then

Code:
      READ(9,999)ID
  999 FORMAT(10X,I5)
would do the job.

If it is in free format, try
Code:
      READ(5,*)I,J,K
      PRINT *,K
where I,J are just dummy variables to skip the unnecessary data.
 

Similar threads

  • Programming and Computer Science
Replies
17
Views
4K
  • Programming and Computer Science
Replies
7
Views
6K
  • Programming and Computer Science
Replies
13
Views
4K
  • Programming and Computer Science
Replies
16
Views
4K
  • Programming and Computer Science
Replies
4
Views
3K
  • Programming and Computer Science
Replies
6
Views
3K
  • Programming and Computer Science
Replies
14
Views
3K
  • Sticky
  • DIY Projects
Replies
1
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
11
Views
5K
Back
Top