×
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

Helping on making 2 main programs merging into 1!

Helping on making 2 main programs merging into 1!

Helping on making 2 main programs merging into 1!

(OP)
Hi all, I am new to fortran and I just faced the challenging task.

I have two similar programs that I run them separately. The output generated by program#1 has to be used as the input for program#2. I have already figured out the Open/write/read commands so I could make a smooth transition of input/output. However now I am trying to merge both programs into one, so I can run both at once. What I did I pretty much paste program#2 at the end of program#1 (removing end). While they share several same variables, I made sure that the distinct ones should have a different name, same was for the subroutines.

The problems I am facing now is that all the matrices I have allocated a dimension, I can not reallocate new dimension for the new program. I tried to use the function "reallocate" and did not have any success. Well, If y'all have any tips to help me out with it, that would be very much appreciated.

I don't know if I was too clear, otherwise, let me know what questions you might have and I'll try to answer them to the best of my knowledge.

Paulo.

program program#1
...
***
///
end program


program program#2
---
000
...
end program

Merging:

program program12

...
***
///
---
000
...
end program

RE: Helping on making 2 main programs merging into 1!

Hi peterpan2014,
The simple solution would be to write shell-script or bat-file which first runs the program1 and then program2. IMO it's better than to merge the programs.

Quote:


...
While they share several same variables, I made sure that the distinct ones should have a different name, same was for the subroutines.

The problems I am facing now is that all the matrices I have allocated a dimension, I can not reallocate new dimension for the new program.
...

I don't understand what a new problem you could have with matrices, when you properly renamed the original variables. For example if you have matrix A in program1 and other matrix A in program2, you would have in program12 two maatrices A1 and A2 and treat them the same way as in the original programs.

RE: Helping on making 2 main programs merging into 1!

Paulo:

Yes, you are new to Fortran, but no, it is not a challenging task winky smile

As mikrom mentions, the trivial solution to this problem is a script that would do for you what you do by hand. For example, you can simply write the names of the 2 executables in a script file; then, you just run one command (the name of the script file) and all the commands in the script file will be executed for you.

If the name of the files your Fortran programs read data from are hard coded in the programs themselves (very bad idea), then, your script file would look like this:

CODE

#!/bin/bash
program#1
program#2 

This assumes, for example, that program#1 reads from "prog1.in" and writes to "prog1.out" and that program#2 reads from "prog1.out" and writes to "prog2.out".

In most cases, when only one input file and one output file are needed, it is best to leave the names of the files out of the picture and instead of opening and closing files, you use standard input and standard output. In this case, your script would look like this, for example:

CODE

#!/bin/bash
program#1 < prog1.in  > prog1.out
program#2 < prog1.out > prog2.out 

Which would also work with:

CODE

#!/bin/bash
program#1 < anyname.in  > temp.out
program#2 < temp.out > results.out 

Finally, when you have separate programs and you want to put together into a single Fortran source file, you do not merge them the way you illustrate; instead, you make them subroutines of a common main program:

program program#1 --> subroutine program#1
program program#2 --> subroutine program#2

CODE

program program12
    call program#1
    call program#2
end program12

subroutine program#1
.
.
.
end subroutine program#1

subroutine program#1
.
.
.
end subroutine program#1 

The above Fortran would be similar to the first bash script shown in that it will work if your subroutines have the input/output file names hard coded into them, i.e., the data transfer is done the same way as before via files (instead of share variables).

From there, you may stop using files to transfer data and start using subroutine arguments.

gsal

RE: Helping on making 2 main programs merging into 1!

oops...typo...forgot to edit copy/paste: program#1 --> program#2 in second instance, of course.

As for the scripts, read up on bash scripting if you are on Unix/Linux or batch files if you are working on Windows.

RE: Helping on making 2 main programs merging into 1!

(OP)
Mikrom and Salgerman, thanks for the suggestions. This weekend I couldn't work on it, but I'll try to do the script this week. Now I feel more confident and it makes sense. I did not know we could do that!
Cheers!

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!

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