Nick Pine loves to model thermal systems, especially for ultra efficient solar thermal heating (he considers any system with a COP of less than 50 to be unfrugal and thus unethical). Unfortunately, some of us find BASIC to be a detestable language, completely unreadable and locked off from the real world.

So I present bas2py, a program for demisterfrying Nick code. It converts basic to python, and attempts to pretty print the output. I had code in do_identifier to remap names, but Nick likes to reuse letters.

It does not currently handle any control structures, input, graphics, arrays or non-deterministic quantum operators. But this has not posed a problem so far.

PD, use at own risk (may cause your cat to spontaneously transform into a piano).

(Some people might consider this a total waste of time, but I have many other basic programs of similar nature which I am trying to convert)

Example input: 20 'WS=4:LS=12:HS=3'cloudy-day store dimensions (ft) 30 'PRINT"1000'Cloudy store dimensions (ft):"WS;"x";LS;"x";hS 40 'AS=2*(WS+LS)*HS+2*WS*LS'cloudy store surface (ft^2) 50 'CS=WS*LS*HS*62.33'cloudy store capacitance (Btu/F) 60 DS=7:HS=4'cloudy-day store dimensions (ft) 70 PRINT"1000'Cloudy store dimensions (ft):";DS;"diam x";HS;"high" 80 AS=2*PI*(DS/2)^2+PI*HS*DS'cloudy store surface (ft^2) 90 RS=36'cloudy store R-value (ft^2-F-h/Btu) 100 GS=AS/RS'cloudy store thermal conductance (Btu/h-F) 110 CS=PI*(DS/2)^2*HS*62.33'cloudy store capacitance (Btu/F) 120 TS=140'average-day store temp (F) 130 GH=180'total house conductance (Btu/h-F) 140 PRINT"1010'Total house conductance (Btu/h-F):";GH 150 TA=24.4'average outdoor temp (F) 160 TH=32.9'average daily high (F) 170 TD=TA-(TH-TA)'dawn temp (F) 180 HD=(70-TD)*GH'dawn heat required at 70 F (Btu/h) 190 GRAD=1000'radiator conductance (Btu/h-F) 200 TM=70+HD/GRAD'min usable store temp (F) 210 PRINT"1020'Min/max cloudy store temp (F):";TM;TS 220 HS=(TS-TM)*CS'stored cloudy-day heat (Btu) 230 HC=24*(65-TA)*GH'heat required for 1 cloudy day (Btu/day) 240 EUSE=600'indoor electrical use (kWh/mo) 250 HE=3412*EUSE/30'electric heat (Btu/day) 260 ND=HS/(HC-HE)'number of cloudy days stored 270 PRINT"1030'Number of cloudy days stored:";ND 280 PRINT"1040'Approximate solar fraction:";1-2^(-ND) 290 ES=24*(TS-65)*GS'average day store loss (Btu/day) 300 DUSE=50'DHW use (gal/day) 310 ED=8.33*DUSE*(110-50)'DHW energy (Btu/day) 320 ESTORE=ES+ED'average store collection (Btu/day) 330 SSUN=990'sun on south wall (Btu/ft^2-day) 340 SWA=96'south window area (ft^2) 350 SWG=.5*SWA*SSUN'average south window gain (Btu/day) 360 EDAY=HC-SWG-HE-ES'average sunspace air heating (Btu/day) 370 PRINT"1050'Estore, Eday (Btu/day):";ESTORE;EDAY 375 DAYL=6'solar collection day length (hours) 380 NHEAT=(24-DAYL)*EDAY/24'overnight heat (Btu/day) 390 NDIFF=10'day-night temp diff (F) 400 CHOUSE=NHEAT/NDIFF'overnight house capacitance (Btu/F) 410 PRINT"1055'Overnight house capacitance (Btu/F):";CHOUSE 430 TDAY=(TA+TH)/2'approximate daytime temp (F) 440 TSS=TDAY+2*.8*SSUN/DAYL'Thevenin sunspace temp (F) 450 RSS=DAYL/(EDAY/(TSS-65)+ESTORE/(TSS-TS))'Thev SS resistance (F-h/Btu) 460 TSC=RSS*ESTORE/(TSS-TS)'store collection time (hours) 470 TDC=DAYL-TSC'sunspace air heating time (hours) 480 PRINT"1060'Tstore, Tday (hours):";TSC;TDC 490 PP=60'pump power (watts) 500 FP=20'fan power (watts) 510 CE=PP*TSC+FP*DAYL'collection energy (wH) 520 PRINT"1065'Collection energy (Wh):";CE 530 COP=(ESTORE+EDAY)/(3.412*CE)'Coefficient Of Performance 540 PRINT"1068'Coefficient Of Performance (COP):";COP 550 AG=2/(RSS-1/GRAD)'min sunspace glazing area (ft^2) 560 HG=8'sunspace glazing height (ft) 570 LG=AG/HG'sunspace glazing length (ft) 580 LGR=4*INT(LG/4+1)'round up length to 4' 590 PRINT"1070'SS glazing dimensions (ft):";HG;"high x";LGR;"long"

Output from math import * # 'WS=4:LS=12:HS=3'cloudy-day store dimensions (ft) # 'PRINT"1000'Cloudy store dimensions (ft):"WS;"x";LS;"x";hS # 'AS=2*(WS+LS)*HS+2*WS*LS'cloudy store surface (ft^2) # 'CS=WS*LS*HS*62.33'cloudy store capacitance (Btu/F) Ds = 7.0 Hs = 4.0 # 'cloudy-day store dimensions (ft) print "Cloudy store dimensions (ft):", Ds, "diam x", Hs, "high" As = 2.0*pi*(Ds/2.0)**2.0+pi*Hs*Ds # 'cloudy store surface (ft^2) Rs = 36.0 # 'cloudy store R-value (ft^2-F-h/Btu) Gs = As/Rs # 'cloudy store thermal conductance (Btu/h-F) Cs = pi*(Ds/2.0)**2.0*Hs*62.33 # 'cloudy store capacitance (Btu/F) Ts = 140.0 # 'average-day store temp (F) Gh = 180.0 # 'total house conductance (Btu/h-F) print "Total house conductance (Btu/h-F):", Gh Ta = 24.4 # 'average outdoor temp (F) Th = 32.9 # 'average daily high (F) Td = Ta-(Th-Ta) # 'dawn temp (F) Hd = (70.0-Td)*Gh # 'dawn heat required at 70 F (Btu/h) Grad = 1000.0 # 'radiator conductance (Btu/h-F) Tm = 70.0+Hd/Grad # 'min usable store temp (F) print "Min/max cloudy store temp (F):", Tm, Ts Hs = (Ts-Tm)*Cs # 'stored cloudy-day heat (Btu) Hc = 24.0*(65.0-Ta)*Gh # 'heat required for 1 cloudy day (Btu/day) Euse = 600.0 # 'indoor electrical use (kWh/mo) He = 3412.0*Euse/30.0 # 'electric heat (Btu/day) Nd = Hs/(Hc-He) # 'number of cloudy days stored print "Number of cloudy days stored:", Nd print "Approximate solar fraction:", 1.0-2.0**(-Nd) Es = 24.0*(Ts-65.0)*Gs # 'average day store loss (Btu/day) Duse = 50.0 # 'DHW use (gal/day) Ed = 8.33*Duse*(110.0-50.0) # 'DHW energy (Btu/day) Estore = Es+Ed # 'average store collection (Btu/day) Ssun = 990.0 # 'sun on south wall (Btu/ft^2-day) Swa = 96.0 # 'south window area (ft^2) Swg = 0.5*Swa*Ssun # 'average south window gain (Btu/day) Eday = Hc-Swg-He-Es # 'average sunspace air heating (Btu/day) print "Estore, Eday (Btu/day):", Estore, Eday Dayl = 6.0 # 'solar collection day length (hours) Nheat = (24.0-Dayl)*Eday/24.0 # 'overnight heat (Btu/day) Ndiff = 10.0 # 'day-night temp diff (F) Chouse = Nheat/Ndiff # 'overnight house capacitance (Btu/F) print "Overnight house capacitance (Btu/F):", Chouse Tday = (Ta+Th)/2.0 # 'approximate daytime temp (F) Tss = Tday+2.0*0.8*Ssun/Dayl # 'Thevenin sunspace temp (F) Rss = Dayl/(Eday/(Tss-65.0)+Estore/(Tss-Ts)) # 'Thev SS resistance (F-h/Btu) Tsc = Rss*Estore/(Tss-Ts) # 'store collection time (hours) Tdc = Dayl-Tsc # 'sunspace air heating time (hours) print "Tstore, Tday (hours):", Tsc, Tdc Pp = 60.0 # 'pump power (watts) Fp = 20.0 # 'fan power (watts) Ce = Pp*Tsc+Fp*Dayl # 'collection energy (wH) print "Collection energy (Wh):", Ce Cop = (Estore+Eday)/(3.412*Ce) # 'Coefficient Of Performance print "Coefficient Of Performance (COP):", Cop Ag = 2.0/(Rss-1.0/Grad) # 'min sunspace glazing area (ft^2) Hg = 8.0 # 'sunspace glazing height (ft) Lg = Ag/Hg # 'sunspace glazing length (ft) Lgr = 4.0*int(Lg/4.0+1.0) # 'round up length to 4' print "SS glazing dimensions (ft):", Hg, "high x", Lgr, "long"