mersenneforum.org Could you help me change this into a bash script?
 Register FAQ Search Today's Posts Mark Forums Read

 2007-11-01, 00:07 #1 jasong     "Jason Goatcher" Mar 2005 3·7·167 Posts Could you help me change this into a bash script? The following is a script used for a project called '3x+1' which is studying the Collatz Conjecture. It is a .vbs script. What I'd like to be able to do is turn it into a script that can be run under a bash prompt that calls on Wine to run the Windows executable. What the program basically does is take the range given it, which is from the 'Const blockstart' number to that number plus the 'Const blockinterval' number. Basically, these numbers multiplied by 10^12 are considered to be the range. These numbers are changed to whatever is needed by the user. When the script is run, it looks for a log file to see if the program's been run previously. If it has, then it just starts the next "chunk" in that range. A chunk is basically a range of numbers from one multiple of 2^34 to the next multiple of 2^34. Technically, though the ranges are reserved in multiples of 10^12, they are completed in ranges of 2^34. Not sure if the rounding at the very beginning is always to the nearest multiple of 2^34, rounded up, or rounded down. It's in the script somewhere. The main goal of this script is to (1)determine what needs to be completed, (2) add the normal arguments to the script: idle process, a special command to make sure it's started properly, tell it what it needs to start at and where it needs to end(which is described as how many chunks need to be completed), and I'm not sure what else. (3) Lastly, it needs to send out the command, which in this case involves Wine. Any help is appreciated. (Even pseudocode that classifies the stuff in the .vbs script in such a way that Googling for the solution gets tremendously easier. I do want to become a computer programmer, but in this case the learning curve is a bit steep. Code: option explicit ' ---- Change this constant for a new block! ---- Const blockstart = 58860 Const blockinterval = 20 ' -------------------------------------- Const exefilename = "w422f.exe" dim NTSystem, shell, fso, cmdfilename, logfilename On Error Resume Next set shell = wscript.createobject("wscript.shell") set fso = wscript.createobject("scripting.filesystemobject") logfilename = "w" & cstr(blockstart) & ".log" NTSystem = RunningOnNT If NTSystem Then cmdfilename = "wondrous.cmd" Else cmdfilename = "wondrous.bat" End If makecmdfile NTSystem If err.Number <> 0 then msgbox err.description, vbexclamation, wscript.scriptname else shell.run cmdfilename end if wscript.quit '------------------------------ Sub makecmdfile(Byval NTSystem) dim ts dim i, ch, lastline, s1, s2, s3 dim start, finish dim startcount, finishcount, loopcount dim Message, procspeed, calcdays On error resume next set ts = fso.opentextfile(logfilename) if err <> 0 then ' -- New block, start from scratch start = blockstart & "000000000000" If not NTSystem Then Message = "Warning: you are starting the program on a non-NT system." & VBNewLine Message = Message & "Since the program can not be started in idle priority" & VbNewLine Message = Message & "performance of normal applications on your system could be affected" Message = Message & " (this message wil disappear automatically in 60 seconds)" Shell.Popup Message, 60, "Class Record Search", VBExclamation End If ShowDuration else ' -- Read last number from file do s1 = ts.readline If Len(Trim(s1)) > 0 Then lastline = s1 End If loop until ts.atendofstream s2 = "" for i = 1 to len(lastline) ch = mid(lastline,i,1) if isnumeric (ch) then s2 = s2 & ch end if if not isnumeric(ch) and ch <> "," and len(s2) > 0 then exit for end if next ts.close start = s2 end if on error goto 0 ' ---- Calculate new loopcount finish = (clng(blockstart) + clng(blockinterval) ) * 1.0e+12 startcount = int( cdbl(start ) / (2.0^32) ) finishcount = int( cdbl(finish) / (2.0^32) ) loopcount = finishcount - startcount + 2 ' ---- Create batchfile set ts = fso.createtextfile(cmdfilename, True) if loopcount > 0 then s3 = "start /min " If NTSystem Then s3 = s3 & " /low " End If s3 = s3 & exefilename & " /o /c" & cstr(loopcount) & " /f" & logfilename & " " & start ts.writeline s3 end if ts.close end sub Function RunningOnNT Dim NTVersionKey, v NTVersionKey = "HKLM\Software\Microsoft\Windows NT\CurrentVersion\CurrentVersion" On Error Resume Next Err.Clear v = shell.RegRead(NTVersionKey) RunningOnNT = (Err.Number = 0) End Function Sub ShowDuration ' -- Show info about length of calculation Dim Message, procspeed, calcdays On Error Resume Next procspeed = shell.regread("HKLM\hardware\description\system\centralprocessor\0\~Mhz") If Err.Number = 0 then calcdays = cint (920.0 * blockinterval / procspeed) Message = "Calculation time on this machine will probably take around " Message = Message & calcdays & " days" & vbNewLine Message = Message & " (this message wil disappear automatically in 30 seconds)" Shell.PopUp Message, 30, "Class Record Search", VBInformation Else Err.Clear End if End Sub ' ---- end of script ----
 2007-11-29, 05:59 #2 Ken_g6     Jan 2005 Caught in a sieve 5×79 Posts Well, this chunk: Code: ' -- Read last number from file do s1 = ts.readline If Len(Trim(s1)) > 0 Then lastline = s1 End If loop until ts.atendofstream s2 = "" for i = 1 to len(lastline) ch = mid(lastline,i,1) if isnumeric (ch) then s2 = s2 & ch end if if not isnumeric(ch) and ch <> "," and len(s2) > 0 then exit for end if next ts.close start = s2 looks to be equivalent to: Code: start = tail -1 $logfilename | sed -e "s/^[^0-9,]*//;s/[^0-9,].*$//;s/,//g" Ain't regular expressions grand? Of course, with the amount of math done in other places, you might want to use a different scripting language instead. Might I suggest Perl, where I believe that line would work almost identically? In Perl: Code: $start = tail -1$logfilename; $start =~ s/^[^0-9,]*//;$start =~ s/[^0-9,].*$//;$start =~ s/,//g"; is even better, since sed (Perl's older brother) isn't used.

 Similar Threads Thread Thread Starter Forum Replies Last Post henryzz Software 11 2017-07-28 21:24 EdH Linux 11 2016-05-13 15:36 Dubslow Information & Answers 11 2011-12-14 21:07 gLauss Linux 0 2010-07-31 11:19 CRGreathouse Software 16 2009-03-26 08:42

All times are UTC. The time now is 01:44.

Mon Jan 17 01:44:58 UTC 2022 up 177 days, 20:13, 0 users, load averages: 0.97, 1.07, 1.09