×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Little help with a code

Little help with a code

Little help with a code

(OP)
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


RE: Little help with a code

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.

RE: Little help with a code

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.

RE: Little help with a code

(OP)
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

RE: Little help with a code

@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
https://www.tek-tips.com/viewthread.cfm?qid=172313...
you will find a little example how to process program arguments and how to read a file

RE: Little help with a code

Lots of IDEs for Fortran
  • Photran
  • Eclipse
  • Codeblocks
  • Emacs
Those will work on both Linux and Windows on most compilers.

RE: Little help with a code

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close