Creating a Program to Copy & Generate Coordinates in .inp File

In summary: So you could use those to write the string one character at a time.In summary, Charles wants to create a program which reads a .txt file and copies it exactly to a .inp file, followed by some coordinates which he is generating. The .txt file is being used as a header file which can be changed outside the program, but once the program is read in, the new variables are automatically updated.
  • #1
charlie87
8
0
The issue I am having is that I want to create a program which reads a .txt file and copies it exactly to a .inp file followed by some coordinates which I am generating. the . txt file is being used as a header file which can be changed outside the program but once the program is read in the new variables are automatically updated.

Below is the text which I want to read. is there a command for read all?

$title
simple wing
$datacheck
0.
$symmetry - xz plane of symmetry
=misymm mjsymm
1. 0.
$mach number
=amach
.6
$cases - no. of solutions
=nacase
1.
$angles-of-attack
=alpc
4.
=alpha(1) alpha(2) alpha(3)
0. 10. 0.
$printout options
=isings igeomp isingp icontp ibconp iedgep
4. 0. 0. 1. 1. 0.
=ipraic nexdgn ioutpr ifmcpr
.0 .0 1. 0. 3.
$references for accumulated forces and moments
=xref yref zref nref
46. 0. 0.
=sref bref cref dref
2400. 60. 40. 90.
$points - wing-body with composite panels
=kn cpnorm
1. 2.
=kt
1.
=nm nn netname



I than want this text to be written to a new file "pan.inp" in the same format.

Regards,
Charles Pearce
 

Attachments

  • header.txt
    901 bytes · Views: 298
Technology news on Phys.org
  • #2


It's messy to make a completely general solution to this in Fortran. The way I would probably do that would be to write a 5-line C function that did the copying and call it from the Fortran program.

But judging from your sample data, you don't need a completely general solution, because you only have printable text and the lines of the file are reasonably short. So...

* Declare a character string longer than the longest line of text (e.g. 1000 characters should be plenty)
* Start an "infinite" loop.
* Read a line from the file using A format. This will pad out the line with blank characters.
Use the "END=" option to break out of the loop at the end of the file.
* Find where the last non-blank character is.
* Write the correct length substring to the output file, again using A format.
* End of loop.
 
  • #3


thanks AlephZero,

however this route will not work for me as I need the exact number of spaces between each word or number. the formatting for this would be too time consuming so i will create a batch file in C which copies instead.

regards,
Charles
 
  • #4


charlie87 said:
this route will not work for me as I need the exact number of spaces between each word or number.

AlephZero's method does preserve all the spaces between numbers or words on each line. It's just that the read operation adds spaces to the end of each line in order to fill out the fixed-size character array that you're reading into. His method ignores those extra spaces at the end of the array when writing it to the other file, by writing only up to the last non-blank character.

If your data does have spaces at the ends of lines, and those spaces are significant, then AlephZero's method will not work for you.
 
  • #5


jtbell said:
If your data does have spaces at the ends of lines, and those spaces are significant, then AlephZero's method will not work for you.

Some compilers for older versions of fortran used to have a non-standard Q format, which returned the exact number of characters on a line including trailing spaces, but that isn't available in gcc fortran, for example.

On the other hand gcc fortran does have intrinsic functions FGetC and FPutC which will do I/O one character at a time, not one record (line) at a time.
 

1. What is the purpose of creating a program to copy and generate coordinates in .inp files?

The purpose of creating such a program is to automate the process of copying and generating coordinates in .inp files, which can be a time-consuming and tedious task when done manually. This program can save scientists and researchers a significant amount of time and effort, making their work more efficient.

2. What programming language is best suited for creating this type of program?

The choice of programming language largely depends on the individual's preference and familiarity. However, languages such as Python, Java, and C++ are commonly used for creating programs that involve data processing and manipulation, which would be necessary for this task.

3. Is it possible to customize the program to fit specific needs?

Yes, the program can be customized to fit specific needs, such as specifying the format of the coordinates or adding additional features. This can be done by modifying the code or using user input to adjust the program's parameters.

4. Can the program handle large and complex .inp files?

The program's ability to handle large and complex .inp files depends on the programming language and the efficiency of the code. However, with proper optimization and testing, it is possible to create a program that can handle such files without any issues.

5. Are there any potential challenges or limitations when creating a program to copy and generate coordinates in .inp files?

One potential challenge is identifying and handling errors in the input file. This could be addressed by implementing error handling and validation techniques in the program. Other limitations could arise from the programming language's limitations or the complexity of the input file's format.

Similar threads

  • Programming and Computer Science
Replies
32
Views
2K
  • Programming and Computer Science
Replies
8
Views
758
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
6
Views
2K
  • Programming and Computer Science
Replies
16
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
14
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • Programming and Computer Science
Replies
2
Views
2K
Replies
2
Views
2K
  • Programming and Computer Science
Replies
2
Views
2K
Back
Top