Help with batch file creation maths involved.

May 8, 2011 at 15:46:42
Specs: Windows XP
Hi everyone I'm just registered here to ask for help since I did some search to see if there was a case similar to mine but I didnt find it or I was negligent enough to dont recognise that it could be used for my propourses.

Anyway, what I want to do is kinda complex, I need to retrieve some numbers from a text file, then multiplicate them for x2 or x3(a variable to be determined) and then put them back in the file or create other one with all the current data but with the new multiplied numbers.

Here is a example of how the data looks:
...
time 0
0 -0.824249 19.319506 153.386719 1.537240 0.340327 1.574440
1 0.014341 5.357971 0.000001 -1.570796 -0.000000 0.000000
2 18.044678 19.938002 -19.993452 0.000000 -0.000000 -2.788575
3 -0.000001 0.000001 -18.512442 0.000000 0.118264 0.000000
4 -43.442562 0.000001 -20.980772 0.000000 0.085347 0.000000
5 -41.714733 -0.000002 50.600700 0.000000 0.221655 0.000000
6 -24.930103 0.000005 -108.112709 0.000000 -0.058880 0.000000
7 -36.962315 0.000004 -67.252213 0.000000 0.130900 0.000000
8 0.033607 0.000002 -49.838158 0.000000 -0.000000 0.000000
9 -8.532483 -0.000003 44.268562 0.000000 -0.567232 0.000000
10 0.550831 -0.000001 34.266941 0.000000 0.008727 0.000000
11 -6.044763 0.000000 -13.417998 0.000000 0.881391 0.000000
12 0.059830 0.000001 -40.417564 0.000000 -0.000000 0.000000
13 18.044678 -19.937988 -19.993448 0.000000 -0.000000 2.688174
...

Those last 3 numbers are the ones that i need to multiplicate from each line.
but the final file needs to have the rest of the data too(not the old numbers, I mean the untouched data).

Here is the full file:
http://www.mediafire.com/file/4lxpj...

Hope you can help me.
Thanks in advance!


See More: Help with batch file creation maths involved.

Report •


#1
May 8, 2011 at 23:12:21
Well after reading a bit(thing that I had to done first, i found a way to do it, quite simple:
---------------------------------------
@echo off > tempfile.tmp & setLocal enableDELAYedexpansion

for /f "tokens=1-7 delims= " %%a in (run_fr_up.txt) do (
set str1=%%a
set str2=%%b
set str3=%%c
set str4=%%d
set str5=%%e
set str6=%%f
set str7=%%g

>> myfile1.txt echo !str1! !str2! !str3! !str4! !str5! !str6! !str7!
)
pause
del tempfile.tmp
------------------------------------------

well its not done, but there I can multiplicate str5,str6,str7 with ease to print then in the new file. the only matter is that there is a point in each number, and set /a cannot handle floating point numbers, so I remembered a way to delete the "dot" wich is set yadayada=%yadayadawithdot:.=%
that creates a new variable without the dot, the thing is.. How I put it back after the calc was made?? there is a way similar that does the opposite?


Report •

#2
May 8, 2011 at 23:41:32
Does it need to be pure batch or is using a vbs helper script an option?

Here is an example of passing the math to vbs: http://www.celticproductions.net/ar...

Here is a pure batch helper script: http://judago.webs.com/byteconversi...

The vbs will probably be faster/easier.


Report •

#3
May 9, 2011 at 02:22:19
Well first of all, many thanks, you have been helpfull, I wish I could understand the vbs link, seems complicated but i will reread it later, I found your script to be usefull at least in the teory, since in test it worked just fine, but then when I tried to implement it in the main script it didnt worked :/ here is how I used it:

-----------------------------------------------
@del myfile1.txt
@echo off > tempfile.tmp & setLocal enableDELAYedexpansion

for /f "tokens=1,2,3,4,5,6,7 delims= " %%a in (run_fr_up.txt) do (
set str1=%%a
set str2=%%b
set str3=%%c
set str4=%%d
call multiply.bat %%e * 2 str5
call multiply.bat %%f * 2 str6
call multiply.bat %%g * 2 str7

>> myfile1.txt echo !str1! !str2! !str3! !str4! !str5! !str6! !str7!
)
pause
del tempfile.tmp
-----------------------------------------------
Thanks for the help, Its not that I need to do this with a batch file but it seemed to me the best way to do it quick.
I will apresiate any help. thanks.


Report •

Related Solutions

#4
May 9, 2011 at 13:01:14
That's my fault, I forgot that script is positive numbers only...

@echo off & setLocal enableDELAYedexpansion
@echo Set objArgs = WScript.Arguments>"eval.vbs"
@echo wscript.echo eval(objArgs(0))>>"eval.vbs"

for /f "tokens=1,2,3,4,5,6,7 delims= " %%a in (run_fr_up.txt) do (
    set str1=%%a
    set str2=%%b
    set str3=%%c
    set str4=%%d
    for /f %%X in ('cscript //nologo eval.vbs "%%e * 2"') do set str5=%%X
    for /f %%Y in ('cscript //nologo eval.vbs "%%f * 2"') do set str6=%%Y
    for /f %%Z in ('cscript //nologo eval.vbs "%%g * 2"') do set str7=%%Z
    for %%W in (str5 str6 str7) do (
        if "!%%W:.=!"=="!%%W!" set %%W=!%%W!.
        for /l %%V in (2,1,7) do if "!%%W:~%%V!"=="" set %%W=!%%W!0
        if "!%%W:~0,1!"=="-" if "!%%W:~8!"=="" set %%W=!%%W!0
    )
    
    >> myfile1.txt echo !str1! !str2! !str3! !str4! !str5! !str6! !str7!

) 
pause


Report •

#5
May 9, 2011 at 13:14:56
Many thanks Judago for you help,
But I dont know what im doing wrong now..
I copyed the code you made just as it is in for post and when I try to run it
I got the command screen filled with this:

c:\eval.vbs(2,1) Microsoft VBScript compilation error: Syntax error

Im using XP, could it be something related to that fact? or Im missing some .exe?


Report •

#6
May 9, 2011 at 15:14:24
Judago - pls excuse interruption. Did you d/l the full input file? It seems that the first 100 or so lines and every 100th line after that do not contain 7 space delimited values. Eval will be trying to eval blanks?

Regards

Wahine.


Please come back & tell us if your problem is resolved.


Report •

#7
May 10, 2011 at 00:35:25
Wahine - No I didn't, I missed it completely, I put that script together
10 minutes before leaving for work, I guess I should have just left it....

It was my fault, I should have been paying attention.

I "fixed it", however it is painfully slow, perhaps the
whole thing should be written in vbs, I'm not good with
vbs so I will just leave it as a thought.

@echo off > tempfile.tmp & setLocal enableDELAYedexpansion
@echo Set objArgs = WScript.Arguments>"eval.vbs"
@echo wscript.echo eval(objArgs(0))>>"eval.vbs"

for /f "tokens=1,2,3,4,5,6,7 delims= " %%a in (run_fr_up.txt) do (
    set str1=%%a
    set str2=%%b
    set str3=%%c
    set str4=%%d
    set str5=%%e
    set str6=%%f
    set str7=%%g
    set string=
    for /f "delims=-0123456789. " %%U in ("%%a%%b%%c%%d%%e%%f%%g") do if not "%%U"=="" set string=1
    if "%%g"=="" set string=1
    if not defined string (
        for /f %%X in ('cscript //nologo eval.vbs "%%e * 2"') do set str5=%%X
        for /f %%Y in ('cscript //nologo eval.vbs "%%f * 2"') do set str6=%%Y
        for /f %%Z in ('cscript //nologo eval.vbs "%%g * 2"') do set str7=%%Z
        for %%W in (str5 str6 str7) do (
            if "!%%W:.=!"=="!%%W!" set %%W=!%%W!.
            for /l %%V in (2,1,7) do if "!%%W:~%%V!"=="" set %%W=!%%W!0
            if "!%%W:~0,1!"=="-" if "!%%W:~8!"=="" set %%W=!%%W!0
            if "!%%W:~-1!"=="." set %%W=!%%W~0,-1!
        )

        >> myfile1.txt echo !str1! !str2! !str3! !str4! !str5! !str6! !str7!
    ) else (
        set line=!str1! !str2! !str3! !str4! !str5! !str6! !str7!
        for /l %%V in (1,1,6) do if "!line:~-1!"==" " set line=!line:~0,-1!
        >> myfile1.txt echo !line!
    )
) 
pause


Report •


Ask Question