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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data file editing with tcl/tk 1

Status
Not open for further replies.

anorky

Technical User
Jun 17, 2009
18
NL
Hi all,

I'm currently scripting a icemcfd analysis with tcl/tk.
At a certain point I need to edit a .dat file (with x and z coordinates). Normal this is easy to achieve however I haven't succeeded yet doing this in tcl/tk.
The .dat file looks as follow:

X1 Z1
X2 Z2
. .
. .
. .

I would like to edit this file in 1 or 2 steps to achieve the following result:

First step: Add the Z-coordinates (all Y are 0)

X1 Y1 Z1
X2 Y2 Z2
. . .
. . .
. . .

Final result should look as follow:

X-colon Y-colon Z-colon
expr[X1+$var] expr[Y1+$var] expr[Z1+$var]
expr[X2+$var] expr[Y2+$var] expr[Z2+$var]
. . .
. . .
. . .

It would be realy nice if afterwards I would still be able to put kind of a note on the first line of this file ("#number"). (This would then tell icemcfd how many points are needed to create curve) So finaly the file should have the following layout:

#Number
X-colon Y-colon Z-colon
expr[X1+$var] expr[Y1+$var] expr[Z1+$var]
expr[X2+$var] expr[Y2+$var] expr[Z2+$var]
. . .
. . .
. . .


I have already read the post on:
However as I already mentioned this didn't solve my problem.

Does anyone know how to achive this?

My idea to solve this was as follow:
The first thing to do is make a matrix of the .dat file.
Than I could edit this matrix and print it back to a .txt or .dat file to save the results.
If I'm not mistaken this would give me the desired result however I haven't succeeded so far.

Who can help me?

Thanks!!!
 
X1 Z1
X2 Z2
. .

First step: Add the Z-coordinates (all Y are 0)

X1 Y1 Z1
X2 Y2 Z2
. . .

Z-coordinates are given in your original file. Did you mean Add the Y-coordinates ?

If I understood it good, when you have the data, e.g.

1 10
2 20
...

then in the first step you mean to insert one zero column

1 0 10
2 0 20
...

and at end you want to have this

expr[1 + $var] expr[$var] expr[10 + $var]
expr[2 + $var] expr[$var] expr[20 + $var]
...

for example if $var = 0.5 then this should be your result:

1.5 0.5 10.5
2.5 0.5 20.5
...

Is that right or not ?



 
Hi mikrom,

First of all, thanks for your reply.
You are right, I mean add Y coordinates instead of Z coordinates!

You understood correctly, I only made a mistake in the end, I want to end up with:

expr[1 + $var1] expr[$var2] expr[10 + $var3]
expr[2 + $var1] expr[$var2] expr[20 + $var3]
...

But that is not a big change in code I imagine to include three different variables $var1,$var2,$var3 instead only one and the same $var.

But you understood the "goal" to achieve correctly.
 
Hi anorky,

Here is an example:
dataproc.tcl
Code:
[COLOR=#0000ff]# input file[/color]
[COLOR=#804040][b]set[/b][/color] fname [COLOR=#ff00ff]"data.txt"[/color]
[COLOR=#804040][b]set[/b][/color] input_file [[COLOR=#804040][b]open[/b][/color] [COLOR=#008080]$fname[/color] [COLOR=#ff00ff]"r"[/color]]
[COLOR=#0000ff]# output file[/color]
[COLOR=#804040][b]set[/b][/color] new_fname [COLOR=#ff00ff]"data_result.txt"[/color]
[COLOR=#804040][b]set[/b][/color] output_file [[COLOR=#804040][b]open[/b][/color] [COLOR=#008080]$new_fname[/color] [COLOR=#ff00ff]"w"[/color]]

[COLOR=#0000ff]# define variables[/color]
[COLOR=#804040][b]set[/b][/color] var1 [COLOR=#ff00ff]0.1[/color]
[COLOR=#804040][b]set[/b][/color] var2 [COLOR=#ff00ff]0.2[/color]
[COLOR=#804040][b]set[/b][/color] var3 -[COLOR=#ff00ff]0.3[/color]

[COLOR=#804040][b]while[/b][/color] { [[COLOR=#804040][b]gets[/b][/color] [COLOR=#008080]$input_file[/color] line] != -[COLOR=#ff00ff]1[/color] } {
[COLOR=#0000ff]  # write line to the screen[/color]
  [COLOR=#804040][b]puts[/b][/color] [COLOR=#ff00ff]"line found  : '$line'"[/color]
[COLOR=#0000ff]  # extract X- and Z-columns[/color]
  [COLOR=#804040][b]set[/b][/color] result [[COLOR=#804040][b]regexp[/b][/color] {([-+]?[[COLOR=#ff00ff]0[/color]-[COLOR=#ff00ff]9[/color]]*\.?[[COLOR=#ff00ff]0[/color]-[COLOR=#ff00ff]9[/color]]+)\s+([-+]?[[COLOR=#ff00ff]0[/color]-[COLOR=#ff00ff]9[/color]]*\.?[[COLOR=#ff00ff]0[/color]-[COLOR=#ff00ff]9[/color]]+)}[COLOR=#ff0000]\[/color]
              [COLOR=#008080]$line[/color] match x z]
  [COLOR=#804040][b]if[/b][/color] {[COLOR=#008080]$result[/color]} {
    [COLOR=#804040][b]puts[/b][/color] [COLOR=#ff00ff]"Numbers found: x = $x, z = $z"[/color]
[COLOR=#0000ff]    # create new line[/color]
    [COLOR=#804040][b]set[/b][/color] new_x [[COLOR=#804040][b]expr[/b][/color] [COLOR=#008080]$x[/color] + [COLOR=#008080]$var1[/color]]
    [COLOR=#804040][b]set[/b][/color] new_y [[COLOR=#804040][b]expr[/b][/color] [COLOR=#008080]$var2[/color]]
    [COLOR=#804040][b]set[/b][/color] new_z [[COLOR=#804040][b]expr[/b][/color] [COLOR=#008080]$z[/color] + [COLOR=#008080]$var3[/color]]
    [COLOR=#804040][b]set[/b][/color] new_line [COLOR=#ff00ff]"$new_x $new_y $new_z"[/color]
    [COLOR=#804040][b]puts[/b][/color] [COLOR=#ff00ff]"line created: '$new_line'"[/color]
[COLOR=#0000ff]    # write to file[/color]
    [COLOR=#804040][b]puts[/b][/color] [COLOR=#008080]$output_file[/color] [COLOR=#008080]$new_line[/color]
  } [COLOR=#804040][b]else[/b][/color] {
    [COLOR=#804040][b]puts[/b][/color] [COLOR=#ff00ff]"Nothing matched !"[/color]
  } 
}

[COLOR=#0000ff]# close files[/color]
[COLOR=#804040][b]close[/b][/color] [COLOR=#008080]$input_file[/color]
[COLOR=#804040][b]close[/b][/color] [COLOR=#008080]$output_file[/color]

Now if I have this input file
data.txt
Code:
1    10
2.0  20.0
2.71 -3.14
-1.41 7.62
4x4
after running the above script
Code:
D:\Work>tclsh85 dataproc.tcl
line found  : '1    10'
Numbers found: x = 1, z = 10
line created: '1.1 0.2 9.7'
line found  : '2.0  20.0'
Numbers found: x = 2.0, z = 20.0
line created: '2.1 0.2 19.7'
line found  : '2.71 -3.14'
Numbers found: x = 2.71, z = -3.14
line created: '2.81 0.2 -3.44'
line found  : '-1.41 7.62'
Numbers found: x = -1.41, z = 7.62
line created: '-1.3099999999999998 0.2 7.32'
line found  : '4x4'
Nothing matched !
I get this result file
data_result.txt
Code:
1.1 0.2 9.7
2.1 0.2 19.7
2.81 0.2 -3.44
-1.3099999999999998 0.2 7.32
Look which horrible result TCL computed:
-1.41 + 0.1 = -1.3099999999999998 (instead of -1.31)
:)
 
Hi Mikrom,

You are a genius! Thanks a lot for the help! Now it's working perfectly.
I have one small question left, could you tell me how to put some text on the first line of the output file? For example assume there is a $var4, one value, and this needs to be placed on the first line of the output file. (and a $var5 to be placed on the second line). The x,y,z coordinates start from the third line on in that case.
Do you understand what I mean?

And indeed what a strange result from tcl :D. No way you would get the same result if you wanted to ;D

Well thanks again for the help,




 
:D

I just thought of a second question, i'm sorry.
Considering my previous question, the $var4 value on the first line should actualy be the number of entries in a colum. I mean if there 20 values in the X-colum, the $var4 should be 20 and posted on the first line.
I'm not sure wether my question is clear, if not feel free to comment.

Again thanks a lot
 
Hi anorky,

It's not so simple to write the number of lines at the first line of the resulting file. It's because you write the lines in the file sequential and you don't know the number of resulting lines at the beginning of the processing but first at end, when all the lines are written.

The simple solution would be to add to the above example a second loop, use the resulting file as an input and write the final file - something like this:
dataproc2.tcl
Code:
[COLOR=#0000ff]# input file[/color]
[COLOR=#804040][b]set[/b][/color] fname [COLOR=#ff00ff]"data.txt"[/color]
[COLOR=#804040][b]set[/b][/color] input_file [[COLOR=#804040][b]open[/b][/color] [COLOR=#008080]$fname[/color] [COLOR=#ff00ff]"r"[/color]]
[COLOR=#0000ff]# output file[/color]
[COLOR=#804040][b]set[/b][/color] new_fname [COLOR=#ff00ff]"data_result.txt"[/color]
[COLOR=#804040][b]set[/b][/color] output_file [[COLOR=#804040][b]open[/b][/color] [COLOR=#008080]$new_fname[/color] [COLOR=#ff00ff]"w"[/color]]

[COLOR=#0000ff]# define variables[/color]
[COLOR=#804040][b]set[/b][/color] var1 [COLOR=#ff00ff]0.1[/color]
[COLOR=#804040][b]set[/b][/color] var2 [COLOR=#ff00ff]0.2[/color]
[COLOR=#804040][b]set[/b][/color] var3 -[COLOR=#ff00ff]0.3[/color]
[COLOR=#804040][b]set[/b][/color] var4 [COLOR=#ff00ff]"*--- Something like a header ---*"[/color]
[COLOR=#804040][b]set[/b][/color] count [COLOR=#ff00ff]0[/color]
[COLOR=#804040][b]while[/b][/color] { [[COLOR=#804040][b]gets[/b][/color] [COLOR=#008080]$input_file[/color] line] != -[COLOR=#ff00ff]1[/color] } {
[COLOR=#0000ff]  # write line to the screen[/color]
  [COLOR=#804040][b]puts[/b][/color] [COLOR=#ff00ff]"line found  : '$line'"[/color]
[COLOR=#0000ff]  # extract X- and Z-columns[/color]
  [COLOR=#804040][b]set[/b][/color] result [[COLOR=#804040][b]regexp[/b][/color] {([-+]?[[COLOR=#ff00ff]0[/color]-[COLOR=#ff00ff]9[/color]]*\.?[[COLOR=#ff00ff]0[/color]-[COLOR=#ff00ff]9[/color]]+)\s+([-+]?[[COLOR=#ff00ff]0[/color]-[COLOR=#ff00ff]9[/color]]*\.?[[COLOR=#ff00ff]0[/color]-[COLOR=#ff00ff]9[/color]]+)}[COLOR=#ff0000]\[/color]
              [COLOR=#008080]$line[/color] match x z]
  [COLOR=#804040][b]if[/b][/color] {[COLOR=#008080]$result[/color]} {
    [COLOR=#804040][b]puts[/b][/color] [COLOR=#ff00ff]"Numbers found: x = $x, z = $z"[/color]
[COLOR=#0000ff]    # create new line[/color]
    [COLOR=#804040][b]set[/b][/color] new_x [[COLOR=#804040][b]expr[/b][/color] [COLOR=#008080]$x[/color] + [COLOR=#008080]$var1[/color]]
    [COLOR=#804040][b]set[/b][/color] new_y [[COLOR=#804040][b]expr[/b][/color] [COLOR=#008080]$var2[/color]]
    [COLOR=#804040][b]set[/b][/color] new_z [[COLOR=#804040][b]expr[/b][/color] [COLOR=#008080]$z[/color] + [COLOR=#008080]$var3[/color]]
    [COLOR=#804040][b]set[/b][/color] new_line [COLOR=#ff00ff]"$new_x $new_y $new_z"[/color]
    [COLOR=#804040][b]puts[/b][/color] [COLOR=#ff00ff]"line created: '$new_line'"[/color]
[COLOR=#0000ff]    # write to file[/color]
    [COLOR=#804040][b]puts[/b][/color] [COLOR=#008080]$output_file[/color] [COLOR=#008080]$new_line[/color]
[COLOR=#0000ff]    # increment count[/color]
    [COLOR=#804040][b]set[/b][/color] count [[COLOR=#804040][b]expr[/b][/color] [COLOR=#008080]$count[/color] + [COLOR=#ff00ff]1[/color]]
  } [COLOR=#804040][b]else[/b][/color] {
    [COLOR=#804040][b]puts[/b][/color] [COLOR=#ff00ff]"Nothing matched !"[/color]
  } 
}

[COLOR=#0000ff]# close files[/color]
[COLOR=#804040][b]close[/b][/color] [COLOR=#008080]$input_file[/color]
[COLOR=#804040][b]close[/b][/color] [COLOR=#008080]$output_file[/color]

[COLOR=#0000ff]# Now creating the final result in second loop[/color]
[COLOR=#804040][b]puts[/b][/color] [COLOR=#ff00ff]"[/color][COLOR=#6a5acd]\n[/color][COLOR=#ff00ff]Now creating the final result"[/color]
[COLOR=#804040][b]set[/b][/color] input_file [[COLOR=#804040][b]open[/b][/color] [COLOR=#008080]$new_fname[/color] [COLOR=#ff00ff]"r"[/color]]
[COLOR=#804040][b]set[/b][/color] final_fname [COLOR=#ff00ff]"data_result_final.txt"[/color]
[COLOR=#804040][b]set[/b][/color] output_file [[COLOR=#804040][b]open[/b][/color] [COLOR=#008080]$final_fname[/color] [COLOR=#ff00ff]"w"[/color]]
[COLOR=#0000ff]# writing count and var4 in the file[/color]
[COLOR=#804040][b]puts[/b][/color] [COLOR=#008080]$output_file[/color] [COLOR=#008080]$count[/color]
[COLOR=#804040][b]puts[/b][/color] [COLOR=#008080]$output_file[/color] [COLOR=#008080]$var4[/color]
[COLOR=#0000ff]# writing the lines[/color]
[COLOR=#804040][b]while[/b][/color] { [[COLOR=#804040][b]gets[/b][/color] [COLOR=#008080]$input_file[/color] line] != -[COLOR=#ff00ff]1[/color] } {
  [COLOR=#804040][b]puts[/b][/color] [COLOR=#008080]$output_file[/color] [COLOR=#008080]$line[/color]
}
[COLOR=#0000ff]# close files[/color]
[COLOR=#804040][b]close[/b][/color] [COLOR=#008080]$input_file[/color]
[COLOR=#804040][b]close[/b][/color] [COLOR=#008080]$output_file[/color]
[COLOR=#804040][b]puts[/b][/color] [COLOR=#ff00ff]"Done!"[/color]
This program creates additionally the file
data_result_final.txt which contain what you probably want
Code:
4
*--- Something like a header ---*
1.1 0.2 9.7
2.1 0.2 19.7
2.81 0.2 -3.44
-1.3099999999999998 0.2 7.32
The first line contains a number of data lines. The second line is a header - you can define it as you want. The next lines are the data lines copied fromthe previous file.
 
Hi Mikrom,

That whas exactly what I wanted to achieve. Your help has saved me a lot of time...

Thanks a lot!

Regards
 
Hi Mikrom,

A small last question, I promise :D! Due to circumstances my input file has changed format a bit.
Instead of starting direct with the coordinates on the first line of the input file there is a line of text (a combination of numbers and letters) which I want to delete.
Could you tell me how to do this?

Thanks!
 
Hi anorky,

Of course you can skip and ignore the first line in the input file. You only have to write before the first while loop this blue piece of code:
Code:
...
set count 0
[COLOR=blue]if { [gets $input_file line] != -1 } {
  # skip the header line
  puts "skip header : '$line'"
}[/color]
while { [gets $input_file line] != -1 } {
...

But skipping the header line in this case is not necessary.

The program dataproc2.tcl parses the lines of the input file and looks only for lines which contain two numbers. It uses for the recognizing - if the line is valid or not - regular expression. If the line doesn't contain 2 numbers separated by spaces, it will not be processed, i.e written in the output file.

Consider following input file
data.txt
Code:
 X-values  Y-values  
 1         10
 2.0       20.0
#Now trying floating point negative and positive numbers
 2.71      -3.14
-1.41      +7.62
#This is only a bug - this shouldn't be parsed by regular expression:
4x4
You see that the data file contains in the first line a header and some comments between the data lines.
Now look how dataproc2.tcl works
Code:
D:\Work\Tcl_Tk>tclsh85 dataproc2.tcl
[COLOR=red]line found  : ' X-values  Y-values  '[/color]
[COLOR=red]Nothing matched ![/color]
line found  : ' 1         10'
Numbers found: x = 1, z = 10
line created: '1.1 0.2 9.7'
line found  : ' 2.0       20.0'
Numbers found: x = 2.0, z = 20.0
line created: '2.1 0.2 19.7'
[COLOR=red]line found  : '#Now trying floating point negative and positive numbers'[/color]
[COLOR=red]Nothing matched ![/color]
line found  : ' 2.71      -3.14'
Numbers found: x = 2.71, z = -3.14
line created: '2.81 0.2 -3.44'
line found  : '-1.41      +7.62'
Numbers found: x = -1.41, z = +7.62
line created: '-1.3099999999999998 0.2 7.32'
[COLOR=red]line found  : '#This is only a bug - this shouldn't be parsed by regular express
ion:'[/color]
[COLOR=red]Nothing matched ![/color]
line found  : '4x4'
Nothing matched !

Now creating the final result
Done!
You see: the red lines were not matched by regular expression and they were not be processed.
The resulting file data_result_final.txt is the same as in your previous case, when you used the input file without comments:
Code:
4
*--- Something like a header ---*
1.1 0.2 9.7
2.1 0.2 19.7
2.81 0.2 -3.44
-1.3099999999999998 0.2 7.32
 
Hi Mikrom,

As usual you know the answer, thanks.

The piece of blue code you provided does the job. The input line consisted of several numebers and letters so they where processed in dataproc2.tcl. However using the blue code this problem is solved.
Thanks a lot!

Regards
 
anorky said:
The input line consisted of several numebers and letters so they where processed in dataproc2.tcl. However using the blue code this problem is solved.
Yes in some cases the line could be processed: if it contains 2 following numbers separated by space(s).
It could be avoided by adjusting the regular expression, but in this case you need to know exactly what can the header line contain and what cannot.
You are right - if you don't want to touch that line, use the blue code.

 
Well all works almost fine now :D

The last thing to do is to delete the last line of the output file. This is since my input file are a bunch of airfoil coordinates. The first and last entry are exactly the same, creating hereby the same point twice. By deleting the last line this will be avoided. If I solve this problem I'm finished... I hope it won't be to hard.

Thanks again for the help
 
Hi anorky,

Try to replace the original regex from dataproc2.tcl with this one
Code:
  [COLOR=#804040][b]set[/b][/color] result [[COLOR=#804040][b]regexp[/b][/color] {^\s*([-+]?[[COLOR=#ff00ff]0[/color]-[COLOR=#ff00ff]9[/color]]*\.?[[COLOR=#ff00ff]0[/color]-[COLOR=#ff00ff]9[/color]]+)\s+([-+]?[[COLOR=#ff00ff]0[/color]-[COLOR=#ff00ff]9[/color]]*\.?[[COLOR=#ff00ff]0[/color]-[COLOR=#ff00ff]9[/color]]+)\s*$}[COLOR=#ff0000]\[/color]
              [COLOR=#008080]$line[/color] match x z]
Now the regular expresion should exactly match only the line, which contains from the beginning to the end only 2 numbers separated by space(s). If the line contains something more that 2 numbers and some spaces it shouldn't be matched.

So, if your file header and footer contain more then 2 numbers they shouldn't be processed, e.g. if I have this
data.txt
Code:
 X-values  Y-values  
 1         10
 2.0       20.0
#Now trying floating point negative and positive numbers
 2.71      -3.14
-1.41      +7.62
#This is only a bug - this shouldn't be parsed by regular expression:
4x4
# last line shouldn't be processed even if it contains numbers 1 2 !
1 2 3
after running the modified script called dataproc3.tcl
Code:
D:\Work\Tcl_Tk>tclsh85 dataproc3.tcl
line found  : ' X-values  Y-values  '
Nothing matched !
line found  : ' 1         10'
Numbers found: x = 1, z = 10
line created: '1.1 0.2 9.7'
line found  : ' 2.0       20.0'
Numbers found: x = 2.0, z = 20.0
line created: '2.1 0.2 19.7'
line found  : '#Now trying floating point negative and positive numbers'
Nothing matched !
line found  : ' 2.71      -3.14'
Numbers found: x = 2.71, z = -3.14
line created: '2.81 0.2 -3.44'
line found  : '-1.41      +7.62'
Numbers found: x = -1.41, z = +7.62
line created: '-1.3099999999999998 0.2 7.32'
line found  : '#This is only a bug - this shouldn't be parsed by regular express
ion:'
Nothing matched !
line found  : '4x4'
Nothing matched !
line found  : '# last line shouldn't be processed even if it contains numbers 1
2 !'
Nothing matched !
line found  : '1 2 3'
Nothing matched !

Now creating the final result
Done!
I get this result
data_result_final.txt
Code:
4
*--- Something like a header ---*
1.1 0.2 9.7
2.1 0.2 19.7
2.81 0.2 -3.44
-1.3099999999999998 0.2 7.32

You see, that the numbers from the last two lines weren't extracted, because both lines contain more then 2 numbers and spaces, so they don't match the regex.

/Note, that now with the improved regex, you probably don't need the blue code I posted in my previous example, but when you leave it in your code nothing bad happens/

Hope this help you - give a response, if it fulfills your needs.
:)
 
Hey Mikrom,

Again, thanks.
I'll try to check the result over the weekend. Since I don't have internet access this weekend I'll let you know on monday wether it works. But really thanks a lot for your help!!!

Have a nice week end!

 
Hi Mikrom,

Sorry I took a bit longer than expected to test the new code you provided.
I tried the new expression for regexp, but I think it's not working correctly yet.

My input file looks like:
naca 45356 9%
1.0 0.0
0.9 0.1
...
0.9 -0.1
1.0 0.0

The code you provided does the job up till the last line. The first line is ignored, the following lines are processed as required.
What I would like the program to do is to ignore the last line containing also 2 entries (1.0 0), since it is the same as the second line of the input file.
The new expression for regexp, ignores the last line only if it contains more than 2 entries which is not the case for my input files.

I think this can be realised by letting the expression run a second time up to the value of count-1, or am I mistaken?

Thanks for the help!

regards,
 
Hi anorky,

You are right, when the last line contains 2 numbers as the previous lines it will be accepted by regex and processed. (I thought, that your last line should be different from previous lines and would not contain 2 numbers only.)
You think right, in the second loop you should write lines up to (count -1) only.

So for quick fix replace the code from the second loop between these comments
Code:
[COLOR=blue]# writing count and var4 in the file[/color]
...
[COLOR=blue]# close files[/color]
with this code chunk
Code:
[COLOR=#0000ff]# writing (count-1) and var4 in the file[/color]
[COLOR=#804040][b]puts[/b][/color] [COLOR=#008080]$output_file[/color] [[COLOR=#804040][b]expr[/b][/color] [COLOR=#008080]$count[/color]-[COLOR=#ff00ff]1[/color]]
[COLOR=#804040][b]puts[/b][/color] [COLOR=#008080]$output_file[/color] [COLOR=#008080]$var4[/color]
[COLOR=#0000ff]# writing the lines[/color]
[COLOR=#804040][b]set[/b][/color] k [COLOR=#ff00ff]0[/color]
[COLOR=#804040][b]while[/b][/color] { (([[COLOR=#804040][b]gets[/b][/color] [COLOR=#008080]$input_file[/color] line] != -[COLOR=#ff00ff]1[/color]) && ([COLOR=#008080]$k[/color] < [COLOR=#008080]$count[/color]-[COLOR=#ff00ff]1[/color])) } {
  [COLOR=#804040][b]puts[/b][/color] [COLOR=#008080]$output_file[/color] [COLOR=#008080]$line[/color]
  [COLOR=#804040][b]set[/b][/color] k [[COLOR=#804040][b]expr[/b][/color] [COLOR=#008080]$k[/color] + [COLOR=#ff00ff]1[/color]]
}
[COLOR=#0000ff]# close files[/color]
Then for your input
data.txt
Code:
naca 45356 9% 
1.0 0.0
0.9 0.1
...
0.9 -0.1
1.0 0.0
you will get this
data_result_final.txt
Code:
3
*--- Something like a header ---*
1.1 0.2 -0.3
1.0 0.2 -0.19999999999999998
1.0 0.2 -0.4
Is this what you desired?
 
anorky said:
...to ignore the last line containing also 2 entries ..., since it is the same as the second line of the input file
When the last line is everytime the same as the second line, then the other possible approach would be to ignore the second line, or not?
:)
 
Hi Mikrom,

That was exactly what I desired. Thanks for the help. If all is fine I should be able to finish the rest myself.
Thanks again for the great assistance!!!

Regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top