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

  • Thread starter Thread starter FUNKER
  • Start date Start date
  • Tags Tags
    Fortran Forum
AI Thread Summary
The discussion revolves around programming in Fortran, specifically addressing issues related to Fortran 77 and 90/95. A user seeking help with array declarations and common blocks encounters multiple errors in their code. Key points include the importance of correctly declaring arrays and understanding the limitations of common blocks in Fortran. It is emphasized that array dimensions must be defined using integer values, and the use of floating-point numbers for array sizes is incorrect. The conversation also touches on the need for proper syntax, such as starting code lines in the correct column to avoid compilation errors. Users are advised to break down their programming tasks into manageable steps, utilize pseudocode for clarity, and compile code frequently to identify errors early. Additionally, there are discussions about the inability to dynamically allocate memory in Fortran 77, contrasting it with more modern versions that allow for such flexibility. The thread concludes with inquiries about breaking loops in subroutines and plotting functions, indicating ongoing challenges faced by users in mastering Fortran programming.
  • #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.
 
Technology news on Phys.org
  • #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.
 
  • #106
Thanks Mathmate for your help, can I put the body of subroutine in separate file, and in the main program just write

include 'subroutine_name.f'
the same of including the numerical recipes...
 
  • #107
Yes, but you have to make sure the subroutine parameters allow you to return the arrays that you have just filled.
 
  • #108
Hi MATHmate, I found the angle between two adjacent side in rectangle and then divide by \pi, as I need to know wheather the angles are rational or irrational multiple of \pi, I've got this number 0.397583618, how do I know WEATHER rational or irrational?
 
  • #109
It doesn't look like rational to me.
It is almost impossible to know from a single number because of rounding errors.
Would you have an idea of the three sides?
 
  • #110
let say for polygon, the length of the five sides are 2.82842712, 2.82842712, 2, 2.82842712, 4.47213595, and the angles are after diving by pi 0.5,0.75, 0.75, 0.397583618, 0.852416382

I want to to know if the last two ones are rational or irrational, is there any role to distinguish between the two types, I think it easier if we can force the code to produce the number as numerator and denumertor, but how can we do that...
 
Last edited:
  • #111
The last number (4.47213595) appears to be 2sqrt(5), while the other ones (2.82842712) appear to be 2sqrt(2).
 
  • #112
mathmate said:
The last number (4.47213595) appears to be 2sqrt(5), while the other ones (2.82842712) appear to be 2sqrt(2).

Thanks mathmate, i meant the these two numbers 0.397583618 , 0.602416382 , are they rational or irrational? can one say that ...( if the length of the side of the triangle are irrational number, then the angle will be irrational multiple of \pi?)
 
  • #113
I do not think one implies the other.
Try a 30-60-90 triangle.
The side lengths are 1,2 and sqrt(3), the last side being irrational. Yet the angles are rational fractions (1/6, 1/3, 1/2) of π.
The converse is not valid either. For example, a triangle with rational sides such as 1,2,3 will have most probably all three angles irrational multiples of π.
 
  • #114
small question on fomatting in f77, I typed the line below to write the data in a file, but the data being separated in two lines in the data file, the first 6 numbers in th first line of the data file then the last two numbers in the second line of the data file, how can we write them in one line

999 FORMAT(2x,I2,5x,F9.6,5x,F9.6,5x,F9.6,5x
& ,F9.6,5x, F9.6,5x, F9.6,5x, F9.6)
 
  • #115
Try
999 FORMAT(2x,I2,5x,F9.6,5x,F9.6,5x,F9.6,5x,F9.6,5x, F9.6 / F9.6,5x, F9.6)
or
999 FORMAT(I4,F14.6,F14.6,F14.6,F14.6,F14.6 /F18.6,F14.6)
 
  • #116
Does anyone know of an algorithm to solve coupled first order differential equations?

Thanks,
 
  • #117
how can I integrate a function(f(x)) on polygonal area numerically on each point we can start with double summation and multiply by dx, dy, but how can we end the summation? the double summation seems to be difficult to implemented as a code...
 
  • #118
Are you looking for simply the area, or do you put weights throughout the area?

If it is a matter of simply the area, you do not need to integrate. There are formulae for calculating the area of a non-self intersecting polygon from the known vertices. See for example:
http://en.wikipedia.org/wiki/Polygon
under Area and centroid.

If the polygon is guaranteed convex, and you need to put weights throughout the surface of the polygon as a function of x and y, I suggest you write code for a triangle (which is simpler), and subdivide the polygon into a number of triangles all radiating from a given source vertex. If the polygon has only one concavity, subdivision into triangles will still work if the source vertex is at the concave point.
 
  • #119
mathmate said:
Are you looking for simply the area, or do you put weights throughout the area?

If it is a matter of simply the area, you do not need to integrate. There are formulae for calculating the area of a non-self intersecting polygon from the known vertices. See for example:
http://en.wikipedia.org/wiki/Polygon
under Area and centroid.

If the polygon is guaranteed convex, and you need to put weights throughout the surface of the polygon as a function of x and y, I suggest you write code for a triangle (which is simpler), and subdivide the polygon into a number of triangles all radiating from a given source vertex. If the polygon has only one concavity, subdivision into triangles will still work if the source vertex is at the concave point.
nooooooo not the area, I have some function with given value at points in the polygon with regular grids, what I need is how to code the numerical integral over the polygon, for example if I have a rectangle I will integrate by doing summation over the region by increasing x till the length and increase y till the width of the rectangle, but for ploygon how can I do this with double summation
 
  • #120
If there are no libraries available for this purpose, you will have to write your own.

If the polygon is convex, I would subdivide the polygon into triangles and write a double integration function for a triangle with the given vertices, together the given weight function.

For integration over the area of the triangle, you will need to split the integration into two regions through the line that passes through the middle vertex (along the x-axis). This is where there is a discontinuity in the integration.
 
  • #121
anyone know how to configure a file as VTK file to be able to plot it by paraview??
 
  • #122
Nusc said:
Does anyone know of an algorithm to solve coupled first order differential equations?

Thanks,

There are several NAG routines that can do this - provided that you have access to the nag libraries anyway.
 
  • #123
I'm looking for a way to write to strings in Fortran. Basically I'd like to do something along the lines of
k = 'A'
at the top of the code, and then throughout have lines like
OPEN(file = 'mesh' k, unit = 11),
which would therefore give
OPEN(file = meshA, unit = 11).

I use the same code to print a lot of different output files and manually changing all the OPEN statements, even with a replaceall command, gets tedious.

Thanks
 
  • #124
This snippet should help you. If your suffixes are letters, you only need to create an array of suffixes to append to the base name. If it is numeric, convert it to a character as shown in the snippet.

Code:
      character*12 filename
      character*1 num
      do 20 I=1,9
      write(num,999)I
 999  format(I1)
      filename='A'//num//'.dat'
      print *,filename
      open(unit=5,file=filename, status='unknown')
   20 continue
 
  • #125
Thanks mathmate - that has saved me an extraordinary amount of time.
 
  • #126
anyone know how to measure the running time for a FORTRAN 77 code?is there any function for this purpose??
 
  • #127
Some compilers have profilers built-in for this purpose. Most profilers can decompose the running time spent in different programming units. Profilers are compiler dependent and most probably operating system dependent, and are not part of the Fortran language.

If you run on Unix, you can use to time command which is probably less accurate, and gives only the total running time.
 
  • #128
mathmate said:
Some compilers have profilers built-in for this purpose. Most profilers can decompose the running time spent in different programming units. Profilers are compiler dependent and most probably operating system dependent, and are not part of the Fortran language.
thanks mathmate for your help, how can have such profilers built-in, do I need to download anything, or how can I check cos I might have them on my unix machine...
mathmate said:
If you run on Unix, you can use to time command which is probably less accurate, and gives only the total running time.

I did the command time, so it gave me
real 0m0.000s
user 0m0.000s
sys 0m0.000s
-------
so did the command time filename.f, so it gave me
real 0m0.020s
user 0m0.000s
sys 0m0.000s
...so the running time is ?
 
  • #129
can anyone show me how to search for a specific program such as Graphics tool or whatever on my computer, as I forget where is I installed, I mean which directory it is stored in??what is the shell command for this job?
 
  • #130
Hi,

I want to learn Fortran language,if it is possible Fortran 77.

The question is if this compiler is available to run in Windows XP Operative System.

If it is, I would like to know how I can get it, because I have been searching some pages about Fortran, but unfortunately, I haven`t found clear information where I can download it

Also, I would like to know where I can obtain, documentation like manuals or tutorials.

Thanks with anticipation

Regards
 
  • #131
For Lanz, try the following link:
http://www.cse.yorku.ca/~roumani/fortran/ftn.htm
and see if you could find anything here:
http://www.thefreecountry.com/compilers/fortran.shtml

For Anglea,
Since you are looking for the detailed usage of a Unix command "find -name...", you may want to make a new post called "help on Unix command". Most unix users (outside of NASA) are not interested in Fortran, so they don't get to read your post. Also, you need more hint so Unix can search fo0r your files, such as the name of the executable, or source file, or the name of the software, etc.
 
  • #133
Hi guys,

It is my first time to visit here so I am not sure if I am supposed to post my question here.
If I am supposed to post my question somewhere else, let me know!
I want to compute a huge, ugly equation with different values of a parameter, let's say c.
My program remains same except c varying from 1 to 7000.
So I want to get data file s1.dat for c=1,
s2.dat for c=2,
...
s700.dat for c=7000.
Can I somehow use unix command to change the values of c and the name of the data files corresponding to different values of c?
Or should I change c and the name of the data file in the program and compile one by one?
Because I should submit the batch job to the school server, it will be really tedious job if I have to do it one by one.
I am not sure that this is fortran question or unix question.
But could you please let me know if you know the way to deal with this?
Thank you so much!
 
  • #134
It depends how your data are arranged.

If the data files are named in a systematic way, it is easy to process them one by one. See post#124 of this thread (on page 8) for an example.

If your data file is generated on the fly in Unix, and you have a script to run the fortran program immediately after generation of the data file, then it is easier to run the script through the various values of the parameter c using the unix script, while the data file could retain the same name if you don't need to keep it.
 
  • #135
HI, I'm a new user and from google it seems you are the last forum who talks about fortran in the last month...so here I am.
I'm a new fortran user and I'm going to compile my program but I find a message:" This application has requested the runtime to terminate in an unusual way " etc...
I use:
- macbook intel core 2Duo
- running windows xp with service pack 2 (the teacher suggested us force that works on win)
- force 2.0.8

I attach the program (extension .txt and .zip with .f inside)

thank you
 

Attachments

  • #137
Hi Mathmate

I am looking for your help in this...
I would like to use this NAG routine ( D06AAF) as attached with the post , to generate a mesh on Rectangle,but it is not a clear for me where do I need to give the coordinates of my rectangle

please help me out
 

Attachments

  • #138
I have a mesh on the interior of a square as a triangles grids, 950 points in the interior which construct 1890 triangles, with the connectivity

how can I link these data to generate VTK format, as I need this format to be able to plot the data.
 
  • #139
can anyone please, help me how to construct a matrix with matrices elements, my main matrix A is constructed of 6 matrices, and I have all the element of these matrices, but the problem I do not know how to write the main matrix A, how the indices look like??
 
  • #140
Hello guys,

I'm a beginner in Fortran. i was trying to compile a program but errors below appeared:

/tmp/ifortMMF3EI.o: In function `MAIN__':
file5.f:(.text+0x404): undefined reference to `ddriv2_'
file5.f:(.text+0x702): undefined reference to `rffti_'
file5.f:(.text+0x712): undefined reference to `rfftf_'

what does this mean? I am using Fortran 95. the program comes with subprograms.

it would be great if anyone can give me some hints to solve this. Thanks in advance :-)
 
  • #141
please try to make your own thread, and upload your question there, anyway I think you need to compile by the following commaand
f95nag file_name
 
  • #142
Hi, can I call a subroutine inside another subroutine in Fortran 77?, also can I call a function in a subroutine?

advance thank for help
 
  • #143
Hi everyone
I've got a problem when I build a function, I need my function to produce a matrix, then I called the function in the main program by its name to give the matrix to the main program, but it does not work at all, I mean the matrix is computed correctly in the function but I failed to call it to the main program, here what I have in my code

Code:
main_program
c
complex*16 A(m1,m2), Mat
EXTERNAL Mat
c
A = MainMat(n,m)
.
..
end
complex*16 function Mat(n,m)
c calculate the elemnts of Mat
Mat = A
.
end
I need to return the matrix Mat, which I computed by the function to the main program
I took off the external statement, and declare the function (Mat) in my main program as

Code:
complex*16 A, Mat
C then I call it as
A = MainMat(S1,S2)
But when I've done the following loop, it does not work

Code:
do i = 1,N
do j = 1,M
write(7,*) A(i,j)
end do
end do

so I changed in the declaration as A(N,M), BUT IT DOES NOT WORK AS WELL
 
  • #144
What does the code for your function MainMat look like? When you say that your nested loop in your last code example "doesn't work" what does that mean? Does it produce any results or no results? Did you set N and M? You don't show these variables being initialized.
 
  • #145
Opr

Please do not give me the answer but if you can direct me to site that will tell me what OPR represent in the statement dp_reduce(array, "opr"). I think opr represent operation but I need to find out what it does in this statement. Please don't give me the answer-just direct me to the right site to learn more about this.

thanks in advance.
 
  • #146
Mark44 said:
What does the code for your function MainMat look like? When you say that your nested loop in your last code example "doesn't work" what does that mean? Does it produce any results or no results? Did you set N and M? You don't show these variables being initialized.

thanks, the code in the main function call some subroutines to produce a complex matrix and let the function return this matrix to the main program, actually I've everything correct and the function produce the right matrix,...just I have a problem of return this matrix t the main program.

please don't worry about the initialization and so on as I delete them for not making my post too long...shall I declare the function name in the main program as
complex MainMat

or complex MainMat(N,N)
BECAUSE IN THE MAIN PROGRAM I have the nested loop to print the resulted matrix from the function

thanks
 
  • #147
i'm heading a problem in mathematical equation about the initial condition, what methode should we used if there is an addition force, such as damping force. This equation will be applied to performed oscillatory system in fortran language programme .
 
  • #148
I have been learning Fortran but I have a question
Is It possible to find a job as fortran programmer or Where is Fortran used I mean where in which divisions
 
  • #149
How Call C routines present in archive from Fortran on UNIX

Hello All,

I have created a library, an archive of C routines on UNIX, which we need to use with Fortran programs (call from Fortran program). I am linking the library at the time of compiling.
The command which I am using is as follows,
$ xlf add.o alenia.a - L /home/oracle/oracle/product/db_1/lib -lclnuts -q64

Here the alenia.a is C routines archive and add.o is fortran programm calling C function preasnt in alenia.a.

So plse tell me that any prototype I should add in Fortran program? if yes how to do that or now then how to link the C library to the Fortran program & call the C routines in Fortran program.

Thanx.
Harshal
 
  • #150
I have a problem, here's what the,
should be from ascii file to extract data that is the n-th row and n-th column
I do not know how. Could someone help me.
 

Similar threads

Replies
16
Views
5K
Replies
13
Views
4K
Replies
14
Views
3K
Replies
5
Views
3K
Replies
4
Views
38K
Replies
11
Views
6K
Back
Top