Looking for text editor that can do math

jtr1962

Storage? I am Storage!
Joined
Jan 25, 2002
Messages
4,184
Location
Flushing, New York
I'm currently in the process of editing a couple of hundred unicode text files. The editing process involves changing a few dozen to a few hundred numbers in each file that appear in the following format:

point ( -115.214 0.2 648.984 )
point ( -115.214 0.325 648.984 )
point ( -115.356 0.325 648.935 )
point ( -115.356 0.2 648.935 )
point ( -116.713 0.2 648.468 )
point ( -116.713 0.325 648.468 )
point ( -116.854 0.325 648.419 )
point ( -116.854 0.2 648.419 )

Notice that we have sets of three numbers(x,y,z coordinates). I'm interesting in changing some of the first numbers(x coordinates). In this example, we have -115.214 twice followed by -115.356 twice. The difference is ~0.15 and I need to change the second two numbers to -115.289 so that the difference is 0.075. Same deal with the next set of four coordinates below it, etc.

Right now I need to find the numbers I want to change, manually or mentally subtract 0.075, and then put in the result. This is tedious to say the least, and I want to get done with this sometime before I'm a senior citizen. Is there a text editor that will search for numbers, and then perform simple operations on each number only if you want it to, and then search for the next one? Ideally, I want to be able to hit a key or two, jump to the next number, change it(or not), jump to the one after that, etc. Right now I don't have an exact algorithm for finding the number I want to change, but just know which one it is based on it's location relative to the other numbers. This is why I want an optional subtract and replace rather than an automatic one. If I can eventually figure out an algorithm I could write a simple C program to do this, but as of now I just don't see much of a pattern, or at least not one that I could easily program for with my limited programming skills.

Are there any text editors that can also manipulate numbers like I want to? Nothing fancy, just a simple addition or subtraction of a constant is all I'm really looking for.
 

Cliptin

Wannabe Storage Freak
Joined
Jan 22, 2002
Messages
1,206
Location
St. Elmo, TN
Website
www.whstrain.us
jtr1962 said:
I'm currently in the process of editing a couple of hundred unicode text files. The editing process involves changing a few dozen to a few hundred numbers in each file that appear in the following format:

point ( -115.214 0.2 648.984 )
point ( -115.214 0.325 648.984 )
point ( -115.356 0.325 648.935 )
point ( -115.356 0.2 648.935 )
point ( -116.713 0.2 648.468 )
point ( -116.713 0.325 648.468 )
point ( -116.854 0.325 648.419 )
point ( -116.854 0.2 648.419 )

Notice that we have sets of three numbers(x,y,z coordinates). I'm interesting in changing some of the first numbers(x coordinates). In this example, we have -115.214 twice followed by -115.356 twice. The difference is ~0.15 and I need to change the second two numbers to -115.289 so that the difference is 0.075. Same deal with the next set of four coordinates below it, etc.

Right now I need to find the numbers I want to change, manually or mentally subtract 0.075, and then put in the result. This is tedious to say the least, and I want to get done with this sometime before I'm a senior citizen. Is there a text editor that will search for numbers, and then perform simple operations on each number only if you want it to, and then search for the next one? Ideally, I want to be able to hit a key or two, jump to the next number, change it(or not), jump to the one after that, etc. Right now I don't have an exact algorithm for finding the number I want to change, but just know which one it is based on it's location relative to the other numbers. This is why I want an optional subtract and replace rather than an automatic one. If I can eventually figure out an algorithm I could write a simple C program to do this, but as of now I just don't see much of a pattern, or at least not one that I could easily program for with my limited programming skills.

Are there any text editors that can also manipulate numbers like I want to? Nothing fancy, just a simple addition or subtraction of a constant is all I'm really looking for.

I know you specificly ask for text editors; but I think this could be pretty easily accomplished in excel or one of the less expensive equivalents. I know of no text editors that will do any math.
 

jtr1962

Storage? I am Storage!
Joined
Jan 25, 2002
Messages
4,184
Location
Flushing, New York
There's the problem of transferring the numbers from the text file to the spreadsheet and back again after changing them. Using cut and paste I get the whole line of text in one cell of the spreadsheet, not one number in each cell. By the time I go through all the manipulations to get the spreadsheet to change the numbers, it's faster just doing it manually. Ideally, I would write a C program to automate most of the process, but I still haven't figured out a reliable pattern to determine what needs to be changed.

After I finish the first batch I may have a couple of thousand more to do(perhaps as many as 10,000) so I really need to be able to automate this.
 

Mercutio

Fatwah on Western Digital
Joined
Jan 17, 2002
Messages
21,607
Location
I am omnipresent
Emacs.

Emacs is a bootloader away from being an operating system, but pointy-he4aded emacs flunkies have made modules to do EVERYTHING, including math.

A solution that does not involve a change of religion is to spend a few quality hours with a regexp tutorial and any of the fine tools out there that can operate with them. Perl is obviously ideal but you could get away with awk (smaller download) if you wanted.
 

Cliptin

Wannabe Storage Freak
Joined
Jan 22, 2002
Messages
1,206
Location
St. Elmo, TN
Website
www.whstrain.us
jtr1962 said:
Using cut and paste ...

At least as early as Office 97 you could open the file and tell it how to break the file into cells. It looks as though your file is tab seperated so I don't forsee a problem.

If you need to you can send it to me and I'll get it to where you can work on it.
 

timwhit

Hairy Aussie
Joined
Jan 23, 2002
Messages
5,278
Location
Chicago, IL
I would use excel and write a macro do to it. If you have any experience coding it wouldn't be a very hard excersise.

Here is some sample code that you can try out. It probably won't work perfectly but it will give you some ideas.

Code:
Private Sub SampleMacro()
   Dim i as integer, flag as Boolean
   i=1
   flag=False
   Do While flag = False
      IF Cells(i,1)="" then flag=True

      If Cells(i,1)<>Cells(i+1,1) Then
         Cells(i+1,1)=Cells(i,1)+.075
      End If

      i=i+1
   Loop
End Sub
 

timwhit

Hairy Aussie
Joined
Jan 23, 2002
Messages
5,278
Location
Chicago, IL
If you need a better way to automate and if there are indeed 10,000 of these files I wouldn't even bother working on them by hand. I would just sit down and write a program that would read them into an array of strings and manipulate the strings from there.
 

Fushigi

Storage Is My Life
Joined
Jan 23, 2002
Messages
2,890
Location
Illinois, USA
I strongly agree that using a spreadsheet is the better tool in this instance. Excel's file import routine is actually very flexible nowadays and can usually pick the field separators accurately on its own. Then write a function or use the VBA script that timwhit provided to parse the data & make any changes.

- Fushigi
 

jtr1962

Storage? I am Storage!
Joined
Jan 25, 2002
Messages
4,184
Location
Flushing, New York
Thanks for the replies everyone. I'm going to try out a few of the suggestions here and see how it goes. Yes, I do have Office97 installed so I should be able to paste the numbers in the cells properly, and then hopefully import them back to the text file in the same format as they were originally in. Or if I can find a reliable pattern as to what needs to be changed I'll just write a routine to do it for me. As best as I can tell so far I first need to isolate each group of four coordinates. Once this is done I can take the lower value of x, which usually appears in the third and fourth coordinates, and then add 0.075 to it. The main problem is that the order isn't always consistent in the file, but I suppose if I automate the process by blindly selecting the third and fourth x-values to change there will only be a few mistakes that I can manually find and fix. Much better than manually editing as many as 800 values in a file. :eek:

Just to satisfy everyone's curiosity, even though nobody speculated what I might be doing, the points are coordinates for MS Train Simulator tracks. In their hurry to get the program out the door, Kuju(the firm which made MSTS for Microsoft) made the rails 0.15 meters(6 inches) wide, as well as about 10000 other stupid bugs. The heaviest rail in existence is only 3 inches wide, and I plan to correct all the default track shapes(170 in all) to a more correct rail width of 2 15/16", or 0.075 meters. To date, there have also been about one thousand add-on tracks that I'll correct at a later date if I can make the process reasonably fast. Since I'm doing this in my spare time, there's obviously a limit as to how much time I'm willing to spend on it, and a hour or so per track shape just doesn't cut it. It might be easier to correct the problem with 3D software, but as of now nobody has managed to reverse translate Kuju's shape file format into 3ds so that gmax or 3DStudio Max could manipulate it. In fact, many of the freeware add-on designers say they will stop making add-ons if such a translator existed since it would make it easy to reverse engineer and slightly alter their 3D train shapes. In any case, I was able to figure out enough about the shape file format to be able to alter the rail shape without the need of 3D software, although it is a tedious, repetitive process. The straight tracks are fairly easy and quick, involving a simple search and replace of from one to four values, depending upon how many tracks the shape has. It's the curves that are a nightmare since the x-coordinate is not the same throughout the shape(if they were it would be a straight track). The switches and crossovers promise to be an even bigger nightmare.
 

jtr1962

Storage? I am Storage!
Joined
Jan 25, 2002
Messages
4,184
Location
Flushing, New York
Just to update everyone it's going fairly smoothly. I did 30 files so far, and it's not bad now that I have a method. I paste the lines of interest(which incidentally are only a small part of the entire file) in a text file. I can then open this file with Excel and configure it to put each number in a separate cell, and also to put the text around the numbers in separate cells. I wasn't able to do this with a simple copy and paste directly from unicode shape file. I then paste these cells into a spreadsheet that I made which mirrors the pasted cells elsewhere except that the required constants are subtracted or added as necessary. So far I've found 3 different patterns and made a spreadsheet for each. The modified cells can then be selected, text delimiters and all, and pasted directly in place of the original lines in the unicode shape file. Every file has some lines that don't follow the format. These I modify manually, but since there are at most 16 values that need to be changed it isn't too bad. In some cases the files are very similar and I can just select and paste the modifed lines from one file over the same lines in another. The only thing so far that is difficult are switches(points for those of you outside the U.S.). There doesn't seem to be any pattern at all here, but fortunately only about 20 or so values need to be changed in each file. After modifying each file I test it in the route editor to make sure it looks the way it's supposed to, and then if it does I convert it to binary so it loads faster in the simulator.
 
Top