Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Little help with a code

Status
Not open for further replies.

jkepler

Programmer
Nov 21, 2007
3
PT
Hi

Fortran is not my speciality to be honest. However, I must adapt a program I have and run it in Fortran.
I have a function of this type:

Code:
SUBROUTINE calcp(PV,NPTS,S,NC,CH)
C       PV = D.P. ARRAY OF INPUT X and Y VALUES, STORED
C            AS A 2 X NPTS ARRAY.

So was hoping someone could help on this: I would like to make a program (lets call it test.f) which would accept a filename and a number (n) as arguments.
Then, it would open the file, and read line by line the X and Y values, separated let's say by a ; These values would be placed in an array of the type PV (DOUBLE PRECISION) until it reached n read lines. At this time, calcp would be called with NPTS=n, and its result outputed to a file. The program would then read another n lines, and do the same. And so on until the end of the file.

Can someone help me out?

Thanks in advance.

JKepler


 
Are you C/C++/C# programmer? Do you want to call this routine from another language or just from Fortran?

Getting command line arguments was not standardized in Fortran until recently (2003/2008). By the looks of it, you are using Fortran IV (66) or F77. Which compiler/OS are you using? Up to 2003, almost every vendor had a different way of getting the command line arguments.
 
It's always a bit difficult to help without knowing the details; when writing a little processor program like this one, often times one also designs the format of the expected data to make things simpler.

For example, I think that having x,y pair sets, one after the other, in one single file is a bad idea from various points of views.

As a human, it would be difficult to tell where one set end and the next starts; it would be difficult to, say, import such file into a spreadsheet program, plot, visualize it to see what every x,y set looks like, etc.

I would rather keep every x,y set in a separate file, and run the program for each, separately; or,

If these x,y sets are truly related and that is why they will all always be the same length, then, if they are to be in the same file, I would at least place them side-by-side:

x1 y1 x2 y2 x3 y3
x1 y1 x2 y2 x3 y3
x1 y1 x2 y2 x3 y3
x1 y1 x2 y2 x3 y3
x1 y1 x2 y2 x3 y3
x1 y1 x2 y2 x3 y3

This way, they can also be imported into a spreadsheet program and easily visualize via some scatter plot or something.

 
Hi

Thanks for the replies.

I do prefer C/C++ to Fortran, yes. But in this particular case since almost all routines are made in F77, I rather not try the conversion of the code....

I will compile with g77 - I have good results with it. I still havent found a Visual IDE and compiler in one software.

The values, pairs, make sense being like:

x1 y1
x2 y2
x3 y3
...

Kind regards

JKepler
 
@jkepler,
g77 has been replaced by gfortran, you can use it. For processing of command line arguments you can use
IARGC() and GETARG(), or COMMAND_ARGUMENT_COUNT() and GET_COMMAND_ARGUMENT()

There are lot of examples here in the forum, which could help you to start.
For example here
you will find a little example how to process program arguments and how to read a file
 
Lots of IDEs for Fortran
[ul]
[li]Photran[/li]
[li]Eclipse[/li]
[li]Codeblocks[/li]
[li]Emacs[/li]
[/ul]
Those will work on both Linux and Windows on most compilers.
 
Hi JKepler,
If you are proficient in C, then Fortran would be for you simple language. I would encourage you to try it to do yourself. Then post here what have you tried so far and where you have some questions or found problems and we will be happy to assist you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top