'This program is built from RLseries.BAS. 10-23-10 'This program is modified in order to get the colors to be more convenient when inverting colors, the output graphing area is reduced to allow for more text. DECLARE SUB Intro () DECLARE SUB SetTscale () DECLARE SUB SetVscale () DECLARE SUB DrawScreen () DECLARE SUB DrawGrid () DECLARE SUB PrintVar () DECLARE SUB Charge () 'Plots charging function DECLARE SUB Discharge () 'Plots discharging function DECLARE FUNCTION CheckRange# (y#) DECLARE FUNCTION subtract# (aaa#, bbb#) DECLARE SUB FourBIT (x1%, y1%, x2%, y2%, FileNAME$) DIM SHARED Fault AS INTEGER 'This holds a fault code DIM SHARED StyleHex 'This holds the alternating style pattern to create the dotted plot. DIM SHARED tScale AS DOUBLE 'tScale is the range of the x axis in seconds. DIM SHARED vMax AS DOUBLE 'vMax is the max of the y axis in volts and amps. DIM SHARED vMin AS DOUBLE 'vMin is the min of the y axis in volts and amps. DIM SHARED GrphColor AS INTEGER 'Holds the color to be used for each plot. The color value increments for each successive plot. DIM SHARED CharOrDis AS STRING 'this holds whether the circuit is charging or discharging DIM SHARED R AS DOUBLE 'resistance in ohms DIM SHARED L AS DOUBLE 'inductance in Henrys DIM SHARED V AS DOUBLE 'initial voltage on the capacitor DIM SHARED Rs AS SINGLE 'resistance in ohms used for display DIM SHARED Ls AS SINGLE 'inductance in Henrys used for display DIM SHARED Vs AS SINGLE 'initial voltage on the capacitor used for display DIM SHARED Isat AS SINGLE 'This is the saturation current based on V and R SCREEN 12 CLS 0 'Clears everything Intro CLS 0 'Clears everything '----------This initializes the variables.------------ tScale = .01 REM vMax = 15.5 not used REM vMin = -7.5 not used R = 2.6 L = .0063 V = 13 REM CharOrDis = "Charging" not used GrphColor = 1 'This initializes the color for the plot. Each successive plot changes color. Color choice is based what they will be after converting to 24bit, then gif, then inverted. '---------------------------------------------------- DrawScreen 'Setup the graphics port and print the graph scales. DrawGrid COLOR 15 VIEW PRINT 25 TO 30 CLS 2 PrintVar REM command section------------------------------------------------------------------------------- DO COLOR 15 VIEW PRINT 28 TO 30 CLS 2 PRINT "Enter 1 to clear. 2 exit. 475 to generate a bitmap (BMP)." REM PRINT "3 time scale. 4 vertical scale. 5 charge. 6 discharge. Or hit enter to plot." not used. PRINT "3 change time scale. Or hit enter to plot." INPUT "Or the variable name (r, l, v) to be changed."; Comand$ 'Mispelled Comand$ intentionally beause COMMAND$ is recognized by Qbasic as a "special feature" CLS 2 IF Comand$ = "2" THEN SYSTEM ELSEIF Comand$ = "1" THEN CLS 0 DrawScreen DrawGrid COLOR 7 VIEW PRINT 25 TO 30 CLS 2 PrintVar ELSEIF Comand$ = "475" THEN 'this increments a new bitmap name-number every time a bitmap is generated (up to 9999) BMPnumber% = BMPnumber% + 1 'this makes the new bitmap name based on the new number BMPname$ = "IGcoil" + LTRIM$(STR$(BMPnumber%)) PRINT "A bitmap of this screen called "; BMPname$; ".BMP is being generated. Please wait. " 'the previously set VIEW and WINDOW commands have to be cleared for the sub to work. VIEW WINDOW FourBIT 0, 0, 639, 479, BMPname$ 'must now reinstate the VIEW and WINDOW DrawScreen VIEW PRINT 28 TO 30 CLS 2 LOCATE 29, 1 PRINT "Image file "; BMPname$; " is saved in the folder in which this program resides." INPUT "Enter to continue"; Continue ELSEIF Comand$ = "3" THEN VIEW PRINT 1 TO 30 'needed to expand the text port CLS 2 SetTscale CLS 0 DrawScreen DrawGrid COLOR 7 VIEW PRINT 25 TO 30 CLS 2 PrintVar 'ELSEIF Comand$ = "4" THEN ' VIEW PRINT 1 TO 30 'needed to expand the text port ' CLS 2 ' SetVscale ' CLS 0 ' DrawScreen ' DrawGrid ' COLOR 7 ' VIEW PRINT 25 TO 30 ' CLS 2 ' PrintVar 'ELSEIF Comand$ = "5" THEN 'set to charging ' CharOrDis = "Charging" ' COLOR 7 ' VIEW PRINT 25 TO 30 ' CLS 2 ' PrintVar 'ELSEIF Comand$ = "6" THEN 'set to discharging ' CharOrDis = "Discharging" ' COLOR 7 ' VIEW PRINT 25 TO 30 ' CLS 2 ' PrintVar ELSEIF Comand$ = "r" THEN DO INPUT "Enter resistance of the coil primary in Ohms "; R IF R < .001# OR R > 1000000000# THEN PRINT "Enter .001 to 1,000,000,000" LOOP WHILE R < .001# OR R > 1000000000# COLOR 7 VIEW PRINT 25 TO 30 CLS 2 PrintVar ELSEIF Comand$ = "l" THEN DO INPUT "Enter the inductance of the coil primary in Henrys "; L IF L < .0000000000001# OR L > 1000# THEN PRINT "Enter .0000000000001 to 1000" LOOP WHILE L < .0000000000001# OR L > 1000# COLOR 7 VIEW PRINT 25 TO 30 CLS 2 PrintVar ELSEIF Comand$ = "v" THEN DO INPUT "Enter the applied voltage in Volts "; V IF V < -100000000# OR V > 100000000# THEN PRINT "Enter -100,000,000 to 100,000,000" LOOP WHILE V < -100000000# OR V > 100000000# COLOR 7 VIEW PRINT 25 TO 30 CLS 2 PrintVar ELSEIF Comand$ = "" THEN 'plot 'CLS 2 LINE (0, 0)-(tScale, 0) 'Redraw X axis GrphColor = GrphColor + 1 'change plot color for new plot IF GrphColor = 4 THEN GrphColor = 5 'This is to skip color 4 IF GrphColor = 7 THEN GrphColor = 9 'This is to skip color 8 IF GrphColor = 10 THEN GrphColor = 13 'This is to skip color 10, 11, 12 IF GrphColor = 15 THEN GrphColor = 2 'This is to reset to color 2 COLOR GrphColor VIEW PRINT 13 TO 24 LOCATE 23 PrintVar PRINT " " REM IF CharOrDis = "Charging" THEN Charge not used REM IF CharOrDis = "Discharging" THEN Discharge not used Charge END IF LOOP REM command section--------------------------------------------------------------------- SUB Charge '--------------------- Charge--------------------------- DIM t AS DOUBLE DIM i AS DOUBLE DIM vl AS DOUBLE DIM tau AS DOUBLE tau = L / R REM plot i(t) (solid line) REM t is in seconds FOR t = 0 TO tScale STEP tScale / 600# IF -1# * t / tau > 709 THEN Fault = 1 'EXP function can't take an input higher than about 709 IF Fault = 1 THEN PRINT "Combination of inputs out of Range. Cannot continue plot." Fault = 0 EXIT SUB END IF i = (V / R) - (V / R) * EXP(-1# * t / tau) i = CheckRange(i) 'Checks to see if i is far off scale. Alters it if necessary. IF t = 0 THEN PSET (t, i) 'This sets the graphic cursor to the first point. LINE STEP(0, 0)-(t, i) NEXT t 'REM plot inductor v(t) dotted line 'StyleHex = &HAAAA 'This initializes the style option. Each style has every other pixel blank. This style starts with a color pixel, 'then will alternate for each plot, between starting with blank pixel to starting with color pixel. 'FOR t = 0 TO tScale STEP tScale / 600# 'IF -1# * t / tau > 709 THEN Fault = 1 'EXP function can't take an input higher than about 709 'IF Fault = 1 THEN ' PRINT "Combination of inputs out of Range. Cannot continue plot." ' Fault = 0 ' EXIT SUB 'END IF 'vl = V * EXP(-1# * t / tau) 'vl = CheckRange(vl) 'Checks to see if v is far off scale. Alters it if necessary. 'IF t = 0 THEN PSET (t, vl) 'This sets the graphic cursor to the first point. 'LINE STEP(0, 0)-(t, vl), , , StyleHex 'The commas separate the non-used optons to designate the "style" option. The 16bit hex 'number is a pixel pattern. The style alternates from starting with a color pixel to starting with a blank pixel so consecutive 1-pixel 'lines will still be dotted. 'IF StyleHex = &HAAAA THEN 'This if statement flip flops the stylehex from AAAA to 5555 and vice versa. ' StyleHex = &H5555 'ELSE ' StyleHex = &HAAAA 'END IF 'NEXT t END SUB '---------------------------Charge---------------------------------------- FUNCTION CheckRange# (y#) '----------------------------------CheckRange------------- 'This function is to avoid the glitch in Qbasic which plots errantly ("wrapping around") if the plotting points are very far off scale. 'This function checks the y value to be plotted and alters it if it's very far off the scale. 'If it's over 3 times the scale, it will be set to three times the scale range. If it's less than 3 times the scale it will not be altered. '(The negative side only has half the range of the positive side, so 6 is the multiplier for the negative side.) 'This is so the slope of the line will be straight up if the point is far off scale, and the slope will have proper slope if it's not far off scale. 'This will then make the slope appear correct. vMax = 8 'Adding these limits for the ignition coil version. vMin = -4 IF y# > (3# * vMax) THEN y# = 3# * vMax ELSEIF y# < (6# * vMin) THEN y# = 6# * vMin END IF CheckRange# = y# END FUNCTION '----------------------------------------CheckRange--------------- SUB Discharge '--------------------- Discharge---------------------------NOT USED DIM t AS DOUBLE DIM i AS DOUBLE DIM vl AS DOUBLE DIM tau AS DOUBLE tau = L / R REM plot i(t) (solid line) REM t is in seconds FOR t = 0 TO tScale STEP tScale / 600# IF -1# * t / tau > 709 THEN Fault = 1 'EXP function can't take an input higher than about 709 IF Fault = 1 THEN PRINT "Combination of inputs out of Range. Cannot continue plot." Fault = 0 EXIT SUB END IF i = (-1# * V / R) * EXP(-1# * t / tau) i = -1# * i 'Due to the passive sign convention, the current will come out negative, but for convenience will be plotted as positive. i = CheckRange(i) 'Checks to see if i is far off scale. Alters it if necessary. IF t = 0 THEN PSET (t, i) 'This sets the graphic cursor to the first point. LINE STEP(0, 0)-(t, i) NEXT t REM plot inductor v(t) dotted line StyleHex = &HAAAA 'This initializes the style option. Each style has every other pixel blank. This style starts with a color pixel, then will alternate for each plot, between starting with blank pixel to starting with color pixel. FOR t = 0 TO tScale STEP tScale / 600# IF -1# * t / tau > 709 THEN Fault = 1 'EXP function can't take an input higher than about 709 IF Fault = 1 THEN PRINT "Combination of inputs out of Range. Cannot continue plot." Fault = 0 EXIT SUB END IF vl = V * EXP(-1# * t / tau) vl = CheckRange(vl) 'Checks to see if i is far off scale. Alters it if necessary. IF t = 0 THEN PSET (t, vl) 'This sets the graphic cursor to the first point. LINE STEP(0, 0)-(t, vl), , , StyleHex 'The commas separate the non-used optons to designate the "style" option. The 16bit hex number is a pixel pattern. The style alternates from starting with a color pixel to starting with a blank pixel so consecutive 1-pixel lines will still be dotted. IF StyleHex = &HAAAA THEN 'This if statement flip flops the stylehex from AAAA to 5555 and vice versa. StyleHex = &H5555 ELSE StyleHex = &HAAAA END IF NEXT t END SUB '---------------------------discharge---------------------------------------- SUB DrawGrid '-------------DrawGrid------------------------------------------------------ COLOR 7 'FOR y = vMax - vMax / 31 TO vMin + vMax / 31 STEP -(vMax / 15.5) 'LINE (0, y)-(tScale, y) 'draws horizontal gray lines 'NEXT y 'LINE (0, (vMax - vMin) / 368)-(tScale, (vMax - vMin) / 368) 'adds a gray line above the zero line 'LINE (0, (vMin - vMax) / 368)-(tScale, (vMin - vMax) / 368)'adds a gray line below the zero line FOR y = 10 TO 0 STEP -1 LINE (0, y)-(tScale, y) 'draws horizontal gray lines NEXT y COLOR 7 FOR x = 0 TO tScale + tScale / 100 STEP tScale / 100 'The x loop goes to "tScale + tScale/100" to put one extra step in the loop. 'Due to rounding errors, the last step in the loop was not being performed. 'This is because the STEP calculation was not exactly tScale /100 'LINE (x, vMin + vMax / 31)-(x, vMax - vMax / 31) 'draws vertical gray lines LINE (x, 0)-(x, 10) NEXT x COLOR 15 'LINE (0, vMax - vMax / 31)-(0, vMin + vMax / 31) 'adds vertical zero line in white LINE (0, 0)-(tScale, 0) 'adds horizontal zero line in white COLOR 8 FOR x = 0 TO tScale + tScale / 10 STEP tScale / 10 'One extra step is put into the loop. See notes above. 'LINE (x, vMin + vMax / 31)-(x, vMax - vMax / 31) 'draws vertical dark gray lines LINE (x, 0)-(x, 10) 'LINE (x + tScale / 600, vMin + vMax / 31)-(x + tScale / 600,vMax - vMax / 31 ) 'draws extra vertical white lines to thicken the vertical white lines. Not used for now. NEXT x COLOR 15 LINE (0, 0)-(0, 10) 'Adds vertical zero line in white. END SUB'-------------------DrawGrid-------------------------------------------------------- SUB DrawScreen '---------------------------DrawScreen----------------------------------- 'The graphics port is set to leave room to the left and bottom for scale indicators. 'Vertically, 0-368 gives 23 spaces, but 1/2 is wasted on top and 1/2 is wasted on bottom to leave room for the scale numbers so the center of the number lines up with the graph lines. 'The graph is broken into 22 useable spaces vertically with a 1/2 unused on top, and 1/2 unused on bottom for a total of 23, and the scale gets 22 numbers. 'It has to be that way in order for the vertical scale numbers to line up. 'Vertically, one line of text takes 16 vertical pixels. 368/23 = 16 . 'If more vertical space is needed at the bottom for text, the graph loses 16 pixels per line. REM not used VIEW (39, 0)-(639, 368) 'must be 601 by 369 (The View and Window commands are also reinstated after bitmap generator call.) VIEW (39, 0)-(639, 176) 'For ignition coils, must be 601 by 177. 'Graphics port scale will be 0 to "tScale" seconds by -7 to +15 amps/volts (multiplied ordivided by some factor of 10 and called vmax and vmin). '(15.5 and -7.5 in order to center the scale with the scale numbers) 'tScale is either .0001, .001, .01, .1, 1, 10, 100, 1000, or 10000. REM not using WINDOW (0, vMax)-(tScale, vMin) 'vMax/248 is one pixel, vMin/120 is one pixel. WINDOW (0, 10.5)-(tScale, -.5) 'For ignition coils, only using 0 to 10 amps 'Show the scale numbers of the y axis as 15 to -7 'note: using "PRINT USING" command to force the formatting. Without it, extra spaces get printed. VIEW PRINT 1 TO 30 LOCATE 1, 1 'FOR y = vMax - vMax / 31 TO vMin + vMax / 31 STEP -(vMax / 15.5) FOR y = 10 TO 0 STEP -1 PRINT USING "####"; y NEXT y 'IF vMax = .0155 THEN ' PRINT USING ".###"; ABS(y) 'ELSEIF vMax = .155 THEN ' PRINT USING "#.##"; y 'ELSEIF vMax = 1.55 THEN ' PRINT USING "#.##"; y 'ELSE ' PRINT USING "####"; y 'END IF 'NEXT y 'Print the x axis time-scale values LOCATE 12, 1 IF tScale = .0001 THEN PRINT " 0msec .01ms .02ms .03ms .04ms .05ms .06ms .07ms .08ms .09ms .1ms" IF tScale = .001 THEN PRINT " 0sec .0001 .0002 .0003 .0004 .0005 .0006 .0007 .0008 .0009 .001" IF tScale = .01 THEN PRINT " 0sec .001 .002 .003 .004 .005 .006 .007 .008 .009 .01" IF tScale = .1 THEN PRINT " 0sec .01 .02 .03 .04 .05 .06 .07 .08 .09 .1" IF tScale = 1 THEN PRINT " 0sec .1 .2 .3 .4 .5 .6 .7 .8 .9 1" IF tScale = 10 THEN PRINT " 0sec 1 2 3 4 5 6 7 8 9 10" IF tScale = 100 THEN PRINT " 0sec 10 20 30 40 50 60 70 80 90 100" IF tScale = 1000 THEN PRINT " 0sec 100 200 300 400 500 600 700 800 900 1000" IF tScale = 10000 THEN PRINT " 0sec 1k 2k 3k 4k 5k 6k 7k 8k 9k 10k" END SUB'--------------------------------------DrawScreen---------------------------------------- '------------------------this is the screen 12 bitmap generator--------------- SUB FourBIT (x1%, y1%, x2%, y2%, FileNAME$) DIM FileCOLORS%(1 TO 48) DIM Colors4%(15) IF INSTR(FileNAME$, ".BMP") = 0 THEN FileNAME$ = RTRIM$(LEFT$(FileNAME$, 8)) + ".BMP" END IF FOR x = x1% TO x2% FOR y = y1% TO y2% Colors4%(POINT(x, y)) = 1 NEXT y NEXT x FOR n = 0 TO 15 IF Colors4%(n) = 1 THEN SigCOLORS& = SigCOLORS& + 1 NEXT n FileTYPE$ = "BM" Reserved1% = 0 Reserved2% = 0 OffsetBITS& = 118 InfoHEADER& = 40 PictureWIDTH& = x2% - x1% + 1 PictureDEPTH& = y2% - y1% + 1 NumPLANES% = 1 BPP% = 4 Compression& = 0 WidthPELS& = 3780 DepthPELS& = 3780 NumCOLORS& = 16 IF PictureWIDTH& MOD 8 <> 0 THEN ZeroPAD$ = SPACE$((8 - PictureWIDTH& MOD 8) \ 2) END IF ImageSIZE& = (((ImageWIDTH& + LEN(ZeroPAD$)) * ImageDEPTH&) + .1) / 2 FileSIZE& = ImageSIZE& + OffsetBITS& Colr = 0 FOR n = 1 TO 48 STEP 3 OUT &H3C7, Colr FileCOLORS%(n) = INP(&H3C9) FileCOLORS%(n + 1) = INP(&H3C9) FileCOLORS%(n + 2) = INP(&H3C9) Colr = Colr + 1 NEXT n OPEN FileNAME$ FOR BINARY AS #1 PUT #1, , FileTYPE$ PUT #1, , FileSIZE& PUT #1, , Reserved1% 'should be zero PUT #1, , Reserved2% 'should be zero PUT #1, , OffsetBITS& PUT #1, , InfoHEADER& PUT #1, , PictureWIDTH& PUT #1, , PictureDEPTH& PUT #1, , NumPLANES% PUT #1, , BPP% PUT #1, , Compression& PUT #1, , ImageSIZE& PUT #1, , WidthPELS& PUT #1, , DepthPELS& PUT #1, , NumCOLORS& PUT #1, , SigCOLORS& u$ = " " FOR n% = 1 TO 46 STEP 3 Colr$ = CHR$(FileCOLORS%(n% + 2) * 4) PUT #1, , Colr$ Colr$ = CHR$(FileCOLORS%(n% + 1) * 4) PUT #1, , Colr$ Colr$ = CHR$(FileCOLORS%(n%) * 4) PUT #1, , Colr$ PUT #1, , u$ 'Unused byte NEXT n% FOR y = y2% TO y1% STEP -1 FOR x = x1% TO x2% STEP 2 HiX = POINT(x, y) LoX = POINT(x + 1, y) HiNIBBLE$ = HEX$(HiX) LoNIBBLE$ = HEX$(LoX) HexVAL$ = "&H" + HiNIBBLE$ + LoNIBBLE$ a$ = CHR$(VAL(HexVAL$)) PUT #1, , a$ NEXT x PUT #1, , ZeroPAD$ NEXT y CLOSE #1 END SUB SUB Intro '----------------------Intro-------------------------------- 'PRINT "This program analyzes a resistor-inductor series circuit." 'PRINT "It can analyze the charging of the RL circuit in series with a voltage" 'PRINT "source, or analyze the discharging of the RL circuit without any sources" 'PRINT "connected." 'PRINT "Given R, L, and V, the program plots the current as a function of time," 'PRINT "and the inductor's voltage as a function of time." PRINT "This program plots the primary current of an idealized ignition coil." PRINT "The resistance, inductance, and applied voltage are the input values." PRINT "Resistance is in ohms, inductance is in Henrys, voltage in volts." PRINT "The current is plotted as a thin, solid line." 'PRINT "The inductor voltage is plotted as a dotted line." PRINT "The X axis is time in seconds." 'PRINT "The Y axis is both current in amps and voltage in Volts." PRINT "The Y axis is current in amps." PRINT " Note: there is only some checking of out-of-range variables, so overflow" PRINT "errors may result if input values are not selected carefully." PRINT "Printing: This progam can generate a bitmap file of the screen. The files" PRINT "will be saved in the folder in which this program resides. If it will be " PRINT "printed out, it is recommended the file be opened in MSPaint and edited." PRINT "First save as 24bit BMP then convert to gif. Then invert colors if desired," PRINT "or convert to black and white. It's all done in MSPaint." INPUT "Enter to continue"; Continue END SUB'----------------------Intro---------------------------------- SUB PrintVar '---------------------------PrintVar--------------- 'CLS 2 'PRINT "The line plot is current. The dotted plot is inductor voltage." '-------reprint input values in same color----------- 'to print neatly, they should be converted to single length. Rs = R Ls = L Vs = V Isat = Vs / Rs PRINT "R"; Rs; "ohms, L"; Ls; "henrys, V"; Vs; "volts, Isat"; Isat; "amps." 'PRINT "R"; Rs; "ohms L"; Ls; "henrys V"; Vs; "volts " ; 'IF CharOrDis = "Charging" THEN PRINT " Charging." 'IF CharOrDis = "Discharging" THEN PRINT " Discharging." END SUB '--------------------------------PrintVar---------------- SUB SetTscale '----------------------------SetTscale------------------------------- PRINT " Nine different time scales can be chosen from." PRINT "0 to .0001 sec." PRINT "0 to .001 sec." PRINT "0 to .01 sec." PRINT "0 to .1 sec." PRINT "0 to 1 sec." PRINT "0 to 10 sec." PRINT "0 to 100 sec." PRINT "0 to 1000 sec." PRINT "0 to 10,000 sec." DO INPUT "Enter the number of seconds for the x axis (default is .1)"; tScale LOOP WHILE tScale < 0 IF tScale = 0 THEN tScale = .1 'default case ELSEIF tScale < .00011 THEN tScale = .0001 ELSEIF tScale < .0011 THEN tScale = .001 ELSEIF tScale < .011 THEN tScale = .01 ELSEIF tScale < .11 THEN tScale = .1 ELSEIF tScale < 1.1 THEN tScale = 1 ELSEIF tScale < 11 THEN tScale = 10 ELSEIF tScale < 110 THEN tScale = 100 ELSEIF tScale < 1100 THEN tScale = 1000 ELSE tScale = 10000 END IF END SUB'----------------------------SetTscale------------------------------- SUB SetVscale '----------------------------SetVscale-----------NOT USED-------------------- PRINT " Five different vertical scales can be chosen from." PRINT "-.007 to +.015 volts and amps." PRINT "-.07 to +.15 volts and amps." PRINT "-.7 to +1.5 volts and amps." PRINT "-7 to +15 volts and amps." PRINT "-70 to +150 volts and amps." DO INPUT "Enter the max number for the y axis (default is 15)"; vMax LOOP WHILE vMax < 0 IF vMax = 0 THEN vMax = 15.5 'default casefx vMin = -7.5 'default case ELSEIF vMax < .016 THEN vMax = .0155 vMin = -.00750001# 'Scale has to be fudged a little to get the full scale to show since it is not an integer in this case. ELSEIF vMax < .16 THEN vMax = .155 vMin = -.0750001 'Scale has to be fudged a little to get the full scale to show since it is not an integer in this case. ELSEIF vMax < 1.6 THEN vMax = 1.55 vMin = -.750001 'Scale has to be fudged a little to get the full scale to show since it is not an integer in this case. ELSEIF vMax < 16 THEN vMax = 15.5 vMin = -7.5 ELSE vMax = 155 vMin = -75 END IF END SUB'--------------------------------SetVscale-------------------------------- FUNCTION subtract# (aaa#, bbb#) '---------------Subtraction function-------------- ' The purpose of this function is to avoid loss-of-significance errors. ' subtract# = aaa# - bbb# ' But, if both aaa and bbb are positive or both negative, then loss-of-sig is possible. ' In that case, check the ratio of aaa to bbb, and bbb to aaa. (Use different ratio for Double and Single precision math.) ' If too close, then loss of sig is going to happen. ' In that case, subtract# = 0. subtract# = aaa# - bbb# IF (aaa# > 0# AND bbb# > 0#) OR (aaa# < 0# AND bbb# < 0#) THEN IF ((aaa# / bbb#) < 1.0000000000001# AND (aaa# / bbb#) > 1#) OR ((bbb# / aaa#) < 1.0000000000001# AND (bbb# / aaa#) > 1#) THEN subtract# = 0 END IF END IF END FUNCTION'----------------------------------Subtraction function--------------