'Database Modification Program for
'8B30,31,32,34,35,36,37,38,39,40,41,42,47,50,51
'signal conditioning modules
'
'AUTHOR: John Lehman
'DATE:   01/14/04
'
'       REVISION RECORD

'DATE     APPR    DESCRIPTION
'----     ----    -----------
'01/14/04  JL     Initial release, modified version of DB5BMAIN.BAS
'12/10/04  CG     Revised for converting all SCM5B reference to 8B.
'01/17/05  CG     Changed the recommended frequency attenuation values.
'03/18/05  CG     Added 8B39 items.
'03/24/05  CG     Added 8B50,51 selections.                            .
'04/25/05  CG     Added recommended atten and noise for 40/41 and 50/51
'04/28/05  CG     Added 8B35 model selection.
'07/18/07  JL     Changed path from S: to T:
'08/22/07  JL     Changed sensor type from MAIN to MA in MODDATA for RCONV.
'05/12/08  TSO    Changed GNCALIN Calibration point on 8B32-01 from 20mA to 12mA
'   "       "     Changed GNCALIN Calibration point on 8B32-02 from 20mA to 10mA
'   "       "     Changed LPCNT% (Loop count) inside GIANCAL when testing 8B32s and 8B42s from 15 to 200
'   "       "     Changed the Calibration Tolerance CALTOL from 0.015% to 0.010% for 8B32s
'05/25/11  TSO    Changed PSS database spec for custom modules 8B31-1734, -1735, -1736
'                 from 50ppm/% to 125ppm/% - it is built on PCB1322 and not PCB1306
'11/11/11  TSO    Message was added to the same screen that indicated the 8BMAIN.dat
'                 Database file was updated.  This second message instructs the user
'                 to view and/or print the instructions for making the same changes
'                 to the 8B Gang Tester Database.
'03/30/2023       Updated the file location to reflect the move to the new engineering drive.

DECLARE FUNCTION CHANGE! (SPEC!)
DECLARE FUNCTION KEYBDIN$ ()
DECLARE FUNCTION MEASRES! (OHM!, RESNUM%, TE$)  'Measure loop current sense resistor
DECLARE FUNCTION MENU1% ()
DECLARE FUNCTION MENU3% ()                      'Gets the module family
DECLARE FUNCTION RTDOHMS! (PVIN!, RTDTYPE$)
DECLARE FUNCTION SENSORNUM% ()
DECLARE FUNCTION SENSOROUT! (PVIN!, PTCV!)
DECLARE FUNCTION TCVOLTS! (TEMP!, SENTYPE$)

DECLARE SUB CONTINUE ()
DECLARE SUB MODDATA ()
DECLARE SUB GETSN (SN$)
DECLARE SUB GETSPECS (SEL%)
DECLARE SUB GTMODINS ()
DECLARE SUB ENTDATA ()
DECLARE SUB SAVEDATA (SEL%)
DECLARE SUB SORTALL ()
DECLARE SUB SORTDB (ENDFLAG%)


'Database Record defintion for the specifications
	TYPE DBASE
		MODNAME         AS STRING * 15  '8B47X-XXXX
		SENTYPE         AS STRING * 7   'mV, V, mA, xTC, xxRTDxW, FBRIDGE, 2WTX, HBRIDGE
		ISMAXNEXCL      AS SINGLE
		ISMAXFEXCL      AS SINGLE
		MININ           AS SINGLE
		MAXIN           AS SINGLE
		IEXC            AS SINGLE
		RCONV           AS SINGLE
		OUTSIGTYPE      AS STRING * 7   'Output signal, "VOLTAGE" or "CURRENT"
		MINOUT          AS SINGLE
		MAXOUT          AS SINGLE
		OSCALPT         AS SINGLE
		GNCALPT         AS SINGLE
		CALTOL          AS SINGLE
		VEXC            AS SINGLE
		VEXCACC         AS SINGLE
		EXCLOAD         AS SINGLE
		EXCLOADREG      AS SINGLE
		EXCIMAX         AS SINGLE
		LINEAR          AS SINGLE
		ACCURACY        AS SINGLE
		TESTFREQ        AS SINGLE
		ATTEN           AS SINGLE
		ATTENTOL        AS SINGLE
		STEPRMIN        AS SINGLE
		STEPRMAX        AS SINGLE
		PSS             AS SINGLE
		OUTNOISE        AS SINGLE
		INPUTRES        AS SINGLE
		VOPENINMIN      AS SINGLE
		VOPENINMAX      AS SINGLE
		LEADRERR        AS SINGLE
		LINEARIZED      AS INTEGER  '1 = linearized, 0 = non-linearized
		OSCALIN         AS SINGLE   'input for offset calibration
		GNCALIN         AS SINGLE   'input for gain calibration
		BANDWIDTH       AS SINGLE   'filter -3dB point
		IMATCHTOL       AS SINGLE   'current source matching tolerance
   
'-*/-*/-*/-*/-*/-*/-*/*///-*/-*/5B39 DATABASE VALUES (USE EXISTING NAMES)
		'Database Record defintion
'        TYPE DBASE
'@                MODNAME         AS STRING * 9
'@                SENTYPE         AS STRING * 2
'@                MININ           AS SINGLE
'@                MAXIN           AS SINGLE
'@                MINOUT          AS SINGLE
'@                MAXOUT          AS SINGLE
'@ISMAXFEXCL      MAXSUPPLY       AS SINGLE
'@EXCIMAX         LIMITOUT        AS SINGLE
'@PSS             POWERSEN        AS SINGLE
'@                TESTFREQ        AS INTEGER
'@                ATTEN           AS INTEGER
'@                LINEAR          AS SINGLE
'@                ACCURACY        AS SINGLE
'@                STEPRMIN        AS SINGLE
'@                STEPRMAX        AS SINGLE
'@ OUTNOISE       NOISEOUT        AS SINGLE
'N/A              QINJECT         AS SINGLE
'@                INPUTRES        AS SINGLE
'N/A              ACQLIM          AS SINGLE
'        END TYPE
'
'COMMON SHARED /SAMPLE/ SPECS AS DBASE
'
'
'-*/-/-*/-*/--*/-*/-*/-*/-*/-*/-*/-*/-*/-*/
   
	END TYPE
			  
	TYPE DBASE2
		RECNUM          AS INTEGER
		MODNAME         AS STRING * 15
	END TYPE

'define common variables
COMMON SHARED /SAMPLE/ SPECS AS DBASE, SPECS2 AS DBASE, SORTDATA1 AS DBASE2, SORTDATA2 AS DBASE

DO
	SELECT CASE MENU1%

		CASE 1
		   CALL ENTDATA
		   IF LEFT$(SPECS.MODNAME, 4) <> "    " THEN
				CALL SAVEDATA(0)
		   END IF
		CASE 2
		   CALL GETSPECS(SEL%)
		   IF LEFT$(SPECS.MODNAME, 4) <> "EXIT" THEN
				CALL MODDATA
				CALL SAVEDATA(0)
		   END IF
		CASE 3
		   CALL GETSPECS(SEL%)
		   IF LEFT$(SPECS.MODNAME, 4) <> "EXIT" THEN
				CALL MODDATA
				CALL SAVEDATA(SEL%)
		   END IF
		CASE 4
			CALL SORTALL
		CASE 5  'Modify records in mass
			CLS
			LOCATE 10
			PRINT "Set up modifications in source code main segment."
		   
			OPEN "U:\ENGR\ATE\8B\8BDATA\8BMAIN.DAT" FOR RANDOM AS #1 LEN = LEN(SPECS)
			OPEN "U:\ENGR\ATE\8B\8BDATA\8BMAIN2.DAT" FOR RANDOM AS #2 LEN = LEN(SPECS)
			NUMRECORD% = LOF(1) / LEN(SPECS)

			FOR i% = 1 TO NUMRECORD%
				GET #1, i%, SPECS
				SNM% = SENSORNUM%
			NEXT
			CLOSE #1
			CLOSE #2
		CASE 6
			CALL GTMODINS
		CASE 7
			END
	END SELECT

LOOP WHILE REPEAT$ <> "N"

FUNCTION CHANGE (SPEC!)

	Y% = CSRLIN
	X% = POS(0)
	LOCATE Y%, X% + 1
		
	INPUT A$

	IF A$ <> "" THEN
		CHANGE = VAL(A$)
	ELSE
		CHANGE = SPEC!
	END IF
		
END FUNCTION

SUB ENTDATA
		  
	'for specs which are not input for all models, default value is zero.
	CLS
	INPUT "Model Number (8Bxx-xx, blank to exit) "; SPECS.MODNAME
	IF SPECS.MODNAME = "          " THEN
		EXIT SUB
	ELSE
	SPECS.MODNAME = UCASE$(SPECS.MODNAME)
	END IF
	PRINT "Valid Sensor Types:"
	PRINT TAB(5); "V (millivolt or volt source)"
	PRINT TAB(5); "mA (milliamp source)"
	PRINT TAB(5); "xTC, x options are: J, K, T, E, R, S, B, N, C type thermocouple"
	PRINT TAB(5); "xxRTDyy, xx options are: P1 = Pt100, P2 = Pt600, P3 = Pt500,"
	PRINT TAB(5); "                         P4 = E1 Pt100 Rosemount, P5 = Pt1000,"
	PRINT TAB(5); "                         NI = Ni120"
	PRINT TAB(30); "C1 = Cu10 (10 ohms @ 25C), C2 = Cu10 (10 ohms @ 0C)"
	PRINT TAB(14); "yy options are: 3W = 3-wire, 4W = 4-wire sensor"
	PRINT TAB(5); "POT (potentiometer)"
	PRINT TAB(5); "FBRIDGE (full-bridge strain gage)"
	PRINT TAB(5); "HBRIDGE (half-bridge strain gage)"
	PRINT TAB(5); "2WTX (two-wire transmitter)"
	PRINT TAB(5); "DCLVDT"
	PRINT TAB(5); "OUTMA (milliamp output with voltage input)"
	INPUT "Sensor Type "; SPECS.SENTYPE
   
	IF UCASE$(LEFT$(SPECS.SENTYPE, 5)) <> "OUTMA" AND UCASE$(LEFT$(SPECS.SENTYPE, 4)) <> "IOMA" THEN
		PRINT
		PRINT "RECOMMENDED VALUES: 35mA, 8B30,31,32,34,35,36,37,40,41,47"
	'    PRINT TAB(21); "tbd mA, 8B38,43 'D' models"
	'    PRINT TAB(21); "tbd 8B42-01"
		INPUT "Supply Current with no excitation load (mA)"; SPECS.ISMAXNEXCL
	END IF

	PRINT
	INPUT "Minus F.S. Input (V, mA, deg. C, or ohms) "; SPECS.MININ
	INPUT "Plus F.S. Input (V, mA, deg. C, or ohms) "; SPECS.MAXIN
	IF UCASE$(MID$(SPECS.SENTYPE, 2, 2)) = "TC" OR UCASE$(MID$(SPECS.SENTYPE, 3, 3)) = "RTD" THEN
		INPUT "Linearization Status (1 = linearized, 0 = non-linearized)"; SPECS.LINEARIZED
	ELSE
		SPECS.LINEARIZED = 0
	END IF
  
	'input the following data for RTD or pot. input only
	IF UCASE$(MID$(SPECS.SENTYPE, 3, 3)) = "RTD" OR UCASE$(LEFT$(SPECS.SENTYPE, 3)) = "POT" THEN
		INPUT "RTD or Pot. excitation current (uA) "; SPECS.IEXC
		INPUT "Twin current source matching tolerance (%) "; SPECS.IMATCHTOL
		INPUT "Lead resistance effects (+/- deg C/ohm or +/- ohm/ohm) "; SPECS.LEADRERR
	END IF
   
	'input the following data for current input only
	IF UCASE$(LEFT$(SPECS.SENTYPE, 2)) = "MAIN" OR UCASE$(LEFT$(SPECS.SENTYPE, 4)) = "2WTX" THEN
		INPUT "Current conversion resistor (ohms) "; SPECS.RCONV
	END IF
	DO
		INPUT "Output signal type ('VOLTAGE' or 'CURRENT')"; SPECS.OUTSIGTYPE
	LOOP WHILE UCASE$(SPECS.OUTSIGTYPE) <> "VOLTAGE" AND UCASE$(SPECS.OUTSIGTYPE) <> "CURRENT"
	IF SPECS.OUTSIGTYPE = "CURRENT" THEN
		PRINT "RECOMMENDED VALUE: 110mA, 8B39"
		INPUT "Supply Current @ +f.s. out (mA)"; SPECS.ISMAXFEXCL
	END IF
	INPUT "Minus F.S. Output (V, mA) "; SPECS.MINOUT
	INPUT "Plus F.S. Output (V, mA) "; SPECS.MAXOUT

	PRINT
'    PRINT "FOR VOLTAGE UNIPOLAR IN AND UNIPOLAR OUT, USE 0V"
'    PRINT "FOR VOLTAGE BIPOLAR IN AND UNIPOLAR OUT, USE -2 * +F.S. INPUT"
'    PRINT "FOR VOLTAGE UNIPOLAR IN AND BIPOLAR OUT, USE +F.S. INPUT"
	INPUT "Input for OFFSET calibration (V, mA, deg. C, or ohms) "; SPECS.OSCALIN
   
	PRINT
'    PRINT "FOR VOLTAGE UNIPOLAR IN AND BIPOLAR OUT, USE -F.S. INPUT"
	INPUT "Input for GAIN calibration (V, mA, deg. C, or ohms) "; SPECS.GNCALIN
   
	IF UCASE$(LEFT$(SPECS.SENTYPE, 5)) <> "OUTMA" AND UCASE$(LEFT$(SPECS.SENTYPE, 4)) <> "IOMA" THEN
		PRINT
		PRINT "Offset and gain may be calibrated at a point other than -f.s. out"
		PRINT "or +f.s. out. Reference linearizer design plots.  Use 0 for non-linearized."
		INPUT "Offset Calibration Point (% of span) "; SPECS.OSCALPT
		INPUT "Gain Calibration Point (% of span) "; SPECS.GNCALPT
	END IF
	INPUT "Offset and Gain Calibration Tolerance (+/- % of span) "; SPECS.CALTOL
	IF UCASE$(MID$(SPECS.SENTYPE, 2, 6)) = "BRIDGE" OR UCASE$(LEFT$(SPECS.SENTYPE, 4)) = "2WTX" OR UCASE$(LEFT$(SPECS.SENTYPE, 6)) = "DCLVDT" THEN
		PRINT "RECOMMENDED VALUES: tbd mA, 8B38, 43"
		INPUT "Supply Current with full excitation load (mA)"; SPECS.ISMAXFEXCL
		INPUT "Excitation Voltage (V) "; SPECS.VEXC
		IF SPECS.VEXC <= 5 THEN
			RECEXCACC! = .09
			RECILIMIT% = 47
			RECEXCREG% = 32
		ELSEIF SPECS.VEXC <= 10 THEN
			RECEXCACC! = .045
			IF SNM% = 8 THEN    '8B38
				RECILIMIT% = 63
			ELSE
				RECLIMIT% = 75
			END IF
			RECEXCREG% = 11
		ELSE
			RECEXCACC! = 2.5
			RECILIMIT! = 38
			RECEXCREG% = 3000
		END IF
		PRINT "RECOMMENDED VALUE: "; RECEXCACC!; "%"
		INPUT "Excitation Voltage Accuracy (+/- % of Vexc) "; SPECS.VEXCACC
		INPUT "Maximum Excitation Operating Load (mA) "; SPECS.EXCLOAD
		PRINT
		PRINT "RECOMMENDED VALUE: "; RECEXCREG%; " ppm/mA"
		INPUT "Excitation Load Regulation (+/- ppm/mA) "; SPECS.EXCLOADREG
		PRINT
		PRINT "RECOMMENDED VALUE: "; RECILIMIT%; " mA"
		INPUT "Excitation Current with 80 ohm load (usually the current limit, mA) "; SPECS.EXCIMAX
	END IF
   
	IF UCASE$(LEFT$(SPECS.SENTYPE, 5)) = "OUTMA" OR UCASE$(LEFT$(SPECS.SENTYPE, 4)) = "IOMA" THEN
		RECILIMIT% = 26
		PRINT
		PRINT "RECOMMENDED VALUE: "; RECILIMIT%; " mA"
		INPUT "Output current limit (mA) "; SPECS.EXCIMAX
	END IF
   
	PRINT
	IF SPECS.LINEARIZED = 0 THEN
		PRINT "RECOMMENDED VALUE: 0.030%"
	END IF
	INPUT "Nonlinearity or Conformity (+/- % of span) "; SPECS.LINEAR
	INPUT "Accuracy (+/- % of span) "; SPECS.ACCURACY
   
'    MININ! = SPECS.MININ
'    MAXIN! = SPECS.MAXIN
'    MINOUT! = SPECS.MINOUT
'    MAXOUT! = SPECS.MAXOUT
'    SNM% = SENSORNUM%
'    IF SNM% = 5 OR SNM% = 6 THEN
'        GAIN! = (MAXOUT! - MINOUT!) / (MAXIN! - MININ!)
'        PSS.SPEC! = .005 / .5 / GAIN!  'Max. test spec. = +/-5mV or +/-0.1% per 0.5V change.
'        UNIT$ = "deg C/V"
'        CALCPSS! = PSS.SPEC!
'    ELSE
'        GAIN! = (MAXOUT! - MINOUT!) / (SENSOROUT!(MAXIN!, 0) - SENSOROUT!(MININ!, 0))
'        IF SNM% = 7 THEN GAIN! = GAIN! / (SPECS.IEXC / 1000000!)
'        PSS.SPEC! = .0006  'Let max. test spec be +/-600uV/% RTO or 0.12% for 10% Vs change and 5V span.
'        CALCPSS! = PSS.SPEC! / GAIN! * 1000000!
'        UNIT$ = "ppm/%"
'    END IF
	PRINT
'    PRINT USING "SUGGESTED VALUE OF PSS IS +/- #####.# &"; CALCPSS!; UNIT$
'    INPUT "Power Supply Sensitivity (+/- uV/% RTI OR +/- deg C/V) "; SPECS.PSS; UNIT$;
	IF UCASE$(LEFT$(SPECS.SENTYPE, 5)) = "OUTMA" OR UCASE$(LEFT$(SPECS.SENTYPE, 4)) = "IOMA" THEN
		PRINT
		PRINT "SUGGESTED VALUE OF PSS IS +/- 150 ppm/%"
	ELSE
		PRINT
		PRINT "SUGGESTED VALUE OF PSS IS +/- 50 ppm/%"
	END IF
	INPUT "Power Supply Sensitivity (+/- ppm/%) "; SPECS.PSS
	PRINT
	INPUT "Low Pass Filter -3dB Frequency (Hz) "; SPECS.BANDWIDTH
	IF SPECS.BANDWIDTH = 3 THEN
		RECTF& = 20
		IF SNM% = 1 OR SNM% = 3 THEN
			IF LEFT$(SPECS.MODNAME, 4) = "8B31" THEN
				RECATTEN% = 40 '8B31-XX
			ELSE
				RECATTEN% = 30 '8B30-XX, 37-XX, 47-XX
			END IF
		ELSE
			RECATTEN% = 40 '8B32-XX
		END IF
	ELSEIF SPECS.BANDWIDTH = 100 THEN
		RECTF& = 500
		RECATTEN% = 35
	ELSEIF SPECS.BANDWIDTH = 1000 THEN      '8B40/41
		RECTF& = 3000
		RECATTEN% = 31
	ELSEIF SPECS.BANDWIDTH = 20000 THEN     '8B50/51
		RECTF& = 41000
		RECATTEN% = 30
	END IF
   
	PRINT
	PRINT "RECOMMENDED TEST FREQUENCY: "; RECTF&; " Hz"
	INPUT "Low Pass Filter Test Frequency (Hz) "; SPECS.TESTFREQ
	PRINT
	PRINT "RECOMMENDED ATTENUATION AT "; RECTF&; "Hz:"; RECATTEN%; " dB"
	INPUT "Attenuation @ Test Frequency (dB) "; SPECS.ATTEN
	INPUT "Filter Attenuation Tolerance (+/- dB) "; SPECS.ATTENTOL
	IF SPECS.BANDWIDTH <= 50 AND UCASE$(LEFT$(SPECS.SENTYPE, 5)) <> "OUTMA" AND UCASE$(LEFT$(SPECS.SENTYPE, 4)) <> "IOMA" THEN
		PRINT
		IF SNM% = 5 OR SNM% = 6 THEN
			RECSMIN% = 80
		ELSE
			RECSMIN% = 85
		END IF
		PRINT "RECOMMENDED VALUE: "; RECSMIN%
		INPUT "Step Response Min (% of span @ 200 ms) (98 for no test)"; SPECS.STEPRMIN

		PRINT
		IF SNM% = 5 OR SNM% = 6 THEN
			RECSMAX% = 105
		ELSE
			RECSMAX% = 110
		END IF
		PRINT "RECOMMENDED VALUE: "; RECSMAX%
		INPUT "Step Response Max (% of span @ 200 ms) "; SPECS.STEPRMAX
	ELSEIF UCASE$(LEFT$(SPECS.SENTYPE, 5)) = "OUTMA" OR UCASE$(LEFT$(SPECS.SENTYPE, 4)) = "IOMA" THEN
		PRINT
		RECSMIN% = 65
		PRINT "RECOMMENDED VALUE: "; RECSMIN%
		INPUT "Step Response Min (% of span @ 4ms) (98 for no test)"; SPECS.STEPRMIN

		PRINT
		RECSMAX% = 85
		PRINT "RECOMMENDED VALUE: "; RECSMAX%
		INPUT "Step Response Max (% of span @ 4ms) "; SPECS.STEPRMAX

	ELSE
		SPECS.STEPRMIN = 98
	END IF
   
	PRINT
	IF SPECS.OUTSIGTYPE = "CURRENT" THEN
		RECNOISE% = 3
		PRINT USING "RECOMMENDED VALUE: ## uArms"; RECNOISE%
	ELSE
		IF SPECS.BANDWIDTH = 1000 THEN       '8B40/41
			RECNOISE% = 600
		ELSEIF SPECS.BANDWIDTH = 20000 THEN      '8B50/51
			RECNOISE% = 5000
		ELSE
			RECNOISE% = 300
		END IF
		PRINT USING "RECOMMENDED VALUE: #### uVrms"; RECNOISE%
	END IF
	INPUT "Output Noise (uVrms, uArms) "; SPECS.OUTNOISE
  
	PRINT
	'input the following data for millivolt or volt input only
	IF UCASE$(LEFT$(SPECS.SENTYPE, 1)) = "V" OR UCASE$(MID$(SPECS.SENTYPE, 2, 6)) = "BRIDGE" OR UCASE$(LEFT$(SPECS.SENTYPE, 5)) = "OUTMA" OR UCASE$(LEFT$(SPECS.SENTYPE, 4)) = "IOMA" THEN
		INPUT "Input Resistance (Meg ohm) "; SPECS.INPUTRES
	END IF
   
	PRINT
	PRINT "For open input response less than zero, the MINIMUM response is"
	PRINT "the lower negative value.  i.e. for -5.9V to -5.2V, -5.9V is MIN."
	INPUT "MINIMUM Open input response (V, for 8Bxx, 0 = none, 5.5 = upscale)"; SPECS.VOPENINMIN
	IF SPECS.VOPENINMIN <> 0 THEN
		PRINT "MAXIMUM Open input response (V, for 8Bxx, 0 = none, 8.5 = upscale)"
		INPUT "                            (   for 8BxxD, 16 = upscale)"; SPECS.VOPENINMAX
	END IF

END SUB

SUB GETSN (SN$)

END SUB

SUB GETSPECS (SEL%)
	   
	DIM POINTER%(1000)

	CALL SORTDB(ENDFLAG%)
	IF ENDFLAG% = 1 THEN
		SPECS.MODNAME = "EXIT"
		EXIT SUB
	END IF
	 
	CLS
	LOCATE , 30
	PRINT "Model Selection Menu"
	PRINT TAB(30); "--------------------"
 
	YINIT% = CSRLIN                 'Initialize starting rows
 
	OPEN "U:\ENGR\ATE\8B\8BDATA\DBSORT2.DAT" FOR RANDOM AS #2 LEN = LEN(SORTDATA1)
				  
	DO
		i% = i% + 1
		GET #2, i%, SORTDATA1
		IF SORTDATA1.RECNUM <> -1 THEN NUMRECORD! = NUMRECORD! + 1
	LOOP WHILE SORTDATA1.RECNUM <> -1

	SCRNCTR% = 40                   'display center
	NUMCHAR% = 26                   '20 char + 4 char for # + 2 spaces
	NUMLINES! = 23                  '# of lines for model display below header
	NUMCOLUMNS! = 1 + INT(NUMRECORD! / NUMLINES!)
									'Model # length = 20 characters max
									'-> 3 columns max per screen
									'3 columns x 26 char = 78 spaces

	i% = 1
 
	FOR C% = 0 TO NUMCOLUMNS! - 1
		Y% = YINIT%
		TB% = SCRNCTR% - NUMCHAR% / 2 * NUMCOLUMNS! + NUMCHAR% * C%
		DO
			GET #2, i%, SORTDATA1
			IF SORTDATA1.RECNUM <> -1 THEN
				POINTER%(i%) = SORTDATA1.RECNUM
				LOCATE Y%, TB%
				PRINT USING "##.) &"; i%; SORTDATA1.MODNAME;
				i% = i% + 1
				Y% = Y% + 1
			END IF
		LOOP WHILE SORTDATA1.RECNUM <> -1 AND Y% - YINIT% < NUMLINES!

	NEXT C%
 
	LOCATE Y%, TB%
	PRINT USING "##.) Exit"; i%;

	CLOSE #2

	DO
		LOCATE 25, SCRNCTR% - 18 / 2
		'LOCATE 1, SCRNCTR% - NUMCHAR% / 2 * NUMCOLUMNS! + NUMCHAR% * (C% - 1)
		PRINT "Enter Selection ";
		INPUT SEL%
	LOOP WHILE SEL% < 1 OR SEL% > i%

	IF SEL% = i% THEN
		SPECS.MODNAME = "EXIT"
	ELSE
		OPEN "U:\ENGR\ATE\8B\8BDATA\8BMAIN.DAT" FOR RANDOM AS #1 LEN = LEN(SPECS)
		GET #1, POINTER%(SEL%), SPECS
		CLOSE #1
	END IF

	SEL% = POINTER%(SEL%)       'pass back to main code for use in SAVEDATA

END SUB

SUB GTMODINS

	CLS

	LOCATE 3, 3
	PRINT "8B Gang Tester TE1220 Database Modification Instructions"
	LOCATE 6, 3
	PRINT "1) Click the Go to Engineering Mode button in the Startup Screen."
	LOCATE 7, 3
	PRINT "2) The 'Enter Engineering Mode Password' is: data4th"
	LOCATE 8, 3
	PRINT "3) Enter this password and click DONE."
	LOCATE 9, 3
	PRINT "4) The Engineering mode confirmed! message will appear - click OK."
	LOCATE 10, 3
	PRINT "5) In the Startup Screen click the Initial Test and Adjust button"
	LOCATE 11, 3
	PRINT "6) To modify the database value, select the model from the Model "
	LOCATE 12, 6
	PRINT "Selection Menu"
	LOCATE 13, 3
	PRINT "7) Click 'Allow Editing' in the Database Modification section"
	LOCATE 14, 6
	PRINT "(next to the Proceed button)."
	LOCATE 15, 3
	PRINT "8) Next, click in the Module Specification box to be modified, enter"
	LOCATE 16, 6
	PRINT "the new value, then click 'Update Database' button"
   
	LOCATE 19, 6
	PRINT "Would you like to print these instructions (Y/N)? ";
   
	DO
		A$ = INKEY$
	LOOP WHILE A$ = ""
   
	IF UCASE$(A$) = "Y" OR UCASE$(A$) = "y" THEN
   
		LOCATE 3, 3
		LPRINT "8B Gang Tester TE1220 Database Modification Instructions"
		LOCATE 6, 3
		LPRINT "1) Click the Go to Engineering Mode button in the Startup Screen."
		LOCATE 7, 3
		LPRINT "2) The 'Enter Engineering Mode Password' is: data4th"
		LOCATE 8, 3
		LPRINT "3) Enter this password and click DONE."
		LOCATE 9, 3
		LPRINT "4) The Engineering mode confirmed! message will appear - click OK."
		LOCATE 10, 3
		LPRINT "5) In the Startup Screen click the Intial Test and Adjust button"
		LOCATE 11, 3
		LPRINT "6) To modify the database value, select the model from the Model "
		LOCATE 12, 6
		LPRINT "Selection Menu"
		LOCATE 13, 3
		LPRINT "7) Click 'Allow Editing' in the Database Modification section"
		LOCATE 14, 6
		LPRINT "(next to the Proceed button)."
		LOCATE 15, 3
		LPRINT "8) Next, click in the Module Specification box to be modified, enter"
		LOCATE 16, 6
		LPRINT "the new value, then click 'Update Database' button"
	LPRINT
	LPRINT
	
	LPRINT CHR$(12)     'Form Feed
   
	ELSE
		CALL CONTINUE
	END IF

END SUB

FUNCTION MEASRES! (OHM!, RESNUM%, TE$)

END FUNCTION

FUNCTION MENU1%

	CLS
	LOCATE 5
	PRINT TAB(23); "8B DATABASE MODIFICATION PROGRAM"
	PRINT
	PRINT TAB(17); "1.) Add New Module, Clean Start"
	PRINT TAB(17); "2.) Add New Module, Start With Existing Module"
	PRINT TAB(17); "3.) Modify Existing Module"
	PRINT TAB(17); "4.) Sort Database"
	PRINT TAB(17); "5.) Mass Database Changes"
	PRINT TAB(17); "6.) Instructions for changing Gang Tester Database"
	PRINT TAB(17); "7.) Exit Program"
	PRINT
	PRINT TAB(17); "Enter your selection";

	DO
		A$ = INKEY$
	LOOP WHILE VAL(A$) < 1 OR VAL(A$) > 7

	MENU1% = VAL(A$)

END FUNCTION

FUNCTION MENU3%

	CLS
	LOCATE 3, 26
	COLOR 14, 0, 0
	PRINT "Module Family Selection Menu"
	PRINT TAB(26); "----------------------------"
	PRINT
	COLOR 11, 0, 0
	PRINT TAB(34); "1.) 8B30-xx"
	PRINT TAB(34); "2.) 8B31-xx"
	PRINT TAB(34); "3.) 8B32-xx"
	PRINT TAB(34); "4.) 8B34-xx"
	PRINT TAB(34); "5.) 8B35-xx"
	PRINT TAB(34); "6.) 8B36-xx"
	PRINT TAB(34); "7.) 8B37-xx"
	PRINT TAB(34); "8.) 8B38-xx"
	PRINT TAB(34); "9.) 8B39-xx"
	PRINT TAB(34); "A.) 8B40-xx"
	PRINT TAB(34); "B.) 8B41-xx"
	PRINT TAB(34); "C.) 8B42-xx"
	PRINT TAB(34); "D.) 8B43-xx"
	PRINT TAB(34); "E.) 8B47x-xx"
	PRINT TAB(34); "F.) 8B50-xx"
	PRINT TAB(34); "G.) 8B51-xx"
	PRINT TAB(34); "H.) 8BPT-xxxx"
	PRINT TAB(34); "I.) Exit"


	DO
		DO
			i$ = UCASE$(INKEY$)
		LOOP WHILE i$ = ""
		C% = ASC(i$)
	LOOP WHILE (C% < 49 OR C% > 57) AND (C% < 65 OR C% > 73)
	

	IF C% > 57 THEN
		MENU3% = C% - 55
	ELSE
		MENU3% = C% - 48
	END IF

END FUNCTION

SUB MODDATA
		 
	CLS
	PRINT "Model Number: "; SPECS.MODNAME;
	INPUT A$
	IF A$ <> "" THEN
		SPECS.MODNAME = UCASE$(A$)
	END IF
	PRINT "Sensor Type: "; SPECS.SENTYPE;
	INPUT A$
	IF A$ <> "" THEN
		SPECS.SENTYPE = A$
	END IF

	IF UCASE$(LEFT$(SPECS.SENTYPE, 5)) <> "OUTMA" AND UCASE$(LEFT$(SPECS.SENTYPE, 4)) <> "IOMA" THEN
		PRINT
		PRINT "RECOMMENDED VALUES: 35mA, 8B30,31,32,34,36,37,40,41,47"
		'   PRINT TAB(21); "tbd mA, 8B38,43 'D' models"
		'   PRINT TAB(21); "tbd mA, 8B42-01"
		PRINT USING "Supply Current with no excitation load = ###.# mA"; SPECS.ISMAXNEXCL;
		SPECS.ISMAXNEXCL = CHANGE(SPECS.ISMAXNEXCL)
	END IF
   
	PRINT USING "Minus F.S. Input = +#####.##### (V, mA, deg. C or ohms)"; SPECS.MININ;
	SPECS.MININ = CHANGE(SPECS.MININ)
	PRINT USING "Plus F.S. Input = +#####.##### (V, mA, deg. C or ohms)"; SPECS.MAXIN;
	SPECS.MAXIN = CHANGE(SPECS.MAXIN)
	PRINT USING "Linearization Status  = # (1 = linearized, 0 = non-linearized)"; SPECS.LINEARIZED;
	SPECS.LINEARIZED = CINT(CHANGE(CSNG(SPECS.LINEARIZED)))
   
	'the following data exits for RTD or pot. input only
	IF UCASE$(MID$(SPECS.SENTYPE, 3, 3)) = "RTD" OR UCASE$(LEFT$(SPECS.SENTYPE, 3)) = "POT" THEN
		PRINT USING "RTD or Pot. excitation current = +#### uA"; SPECS.IEXC;
		SPECS.IEXC = CHANGE(SPECS.IEXC)
		PRINT USING "Twin current source matching tolerance = #.### %"; SPECS.IMATCHTOL;
		SPECS.IMATCHTOL = CHANGE(SPECS.IMATCHTOL)
		PRINT USING "Lead resistance effects = +/- #.### (deg C/ohm or ohm/ohm)"; SPECS.LEADRERR;
		SPECS.LEADRERR = CHANGE(SPECS.LEADRERR)
	END IF
   
	'the following data exits for current input only
	IF UCASE$(LEFT$(SPECS.SENTYPE, 2)) = "MA" OR UCASE$(LEFT$(SPECS.SENTYPE, 4)) = "2WTX" THEN
		PRINT USING "Current conversion resistor = ####.## ohms"; SPECS.RCONV;
		SPECS.RCONV = CHANGE(SPECS.RCONV)
	END IF
   
	DO
		PRINT "Output signal type = "; SPECS.OUTSIGTYPE;
		INPUT A$
		IF A$ <> "" THEN SPECS.OUTSIGTYPE = A$
	LOOP WHILE UCASE$(SPECS.OUTSIGTYPE) <> "VOLTAGE" AND UCASE$(SPECS.OUTSIGTYPE) <> "CURRENT"
	IF SPECS.OUTSIGTYPE = "CURRENT" THEN
		PRINT
		PRINT "RECOMMENDED VALUE: 110mA, 8B39"
		PRINT USING "Supply Current @ +f.s out = ###.# mA"; SPECS.ISMAXFEXCL;
		SPECS.ISMAXFEXCL = CHANGE(SPECS.ISMAXFEXCL)
	END IF
	PRINT USING "Minus F.S. Output = +##.### (V, mA)"; SPECS.MINOUT;
	SPECS.MINOUT = CHANGE(SPECS.MINOUT)
	PRINT USING "Plus F.S. Output = +##.### (V, mA)"; SPECS.MAXOUT;
	SPECS.MAXOUT = CHANGE(SPECS.MAXOUT)

	PRINT
'    PRINT "FOR VOLTAGE UNIPOLAR IN AND UNIPOLAR OUT, USE 0V"
'    PRINT "FOR VOLTAGE BIPOLAR IN AND UNIPOLAR OUT, USE -2 * +F.S. INPUT"
'    PRINT "FOR VOLTAGE UNIPOLAR IN AND BIPOLAR OUT, USE +F.S. INPUT"
	PRINT USING "Input for OFFSET calibration = +#####.##### (V, mA, deg. C, or ohms) "; SPECS.OSCALIN;
	SPECS.OSCALIN = CHANGE(SPECS.OSCALIN)

	PRINT
'    PRINT "FOR VOLTAGE UNIPOLAR IN AND BIPOLAR OUT, USE -F.S. INPUT"
	PRINT USING "Input for GAIN calibration = +#####.##### (V, mA, deg. C, or ohms) "; SPECS.GNCALIN;
	SPECS.GNCALIN = CHANGE(SPECS.GNCALIN)
   
	IF UCASE$(LEFT$(SPECS.SENTYPE, 5)) <> "OUTMA" AND UCASE$(LEFT$(SPECS.SENTYPE, 4)) <> "IOMA" THEN
		PRINT
		PRINT "Offset and gain may be calibrated at a point other than -f.s. out"
		PRINT "or +f.s. out. Reference linearizer design plots.  Use 0 for non-linearized."
		PRINT USING "Offset Calibration Point = +/- #.### % of span"; SPECS.OSCALPT;
		SPECS.OSCALPT = CHANGE(SPECS.OSCALPT)
		PRINT USING "Gain Calibration Point = +/- #.### % of span"; SPECS.GNCALPT;
		SPECS.GNCALPT = CHANGE(SPECS.GNCALPT)
	END IF
   
	PRINT USING "Offset and Gain Calibration Tolerance = +/- #.### % of span"; SPECS.CALTOL;
	SPECS.CALTOL = CHANGE(SPECS.CALTOL)
   
	IF UCASE$(MID$(SPECS.SENTYPE, 2, 6)) = "BRIDGE" OR UCASE$(LEFT$(SPECS.SENTYPE, 4)) = "2WTX" OR UCASE$(LEFT$(SPECS.SENTYPE, 6)) = "DCLVDT" THEN
		PRINT "RECOMMENDED VALUES: tbd mA, 8B38, 43"
		PRINT USING "Supply Current with full excitation load = ###.# mA"; SPECS.ISMAXFEXCL;
		SPECS.ISMAXFEXCL = CHANGE(SPECS.ISMAXFEXCL)
		PRINT USING "Excitation Voltage = +##.## V"; SPECS.VEXC;
		SPECS.VEXC = CHANGE(SPECS.VEXC)
		IF SPECS.VEXC <= 5 THEN
			RECEXCACC! = .06
			RECILIMIT% = 47
			RECEXCREG% = 32
		ELSEIF SPECS.VEXC <= 10 THEN
			RECEXCACC! = .03
			IF SNM% = 8 THEN    '8B38
				RECILIMIT% = 63
			ELSE
				RECLIMIT% = 75
			END IF
			RECEXCREG% = 11
		ELSE
			RECEXCACC! = 2.5
			RECILIMIT! = 38
			RECEXCREG% = 3000
		END IF
		PRINT "RECOMMENDED VALUE: "; RECEXCACC!; "%"
		PRINT USING "Excitation Voltage Accuracy = +/- #.## %"; SPECS.VEXCACC;
		SPECS.VEXCACC = CHANGE(SPECS.VEXCACC)
		PRINT USING "Maximum Excitation Operating Load = ##.# mA"; SPECS.EXCLOAD;
		SPECS.EXCLOAD = CHANGE(SPECS.EXCLOAD)

		PRINT
		PRINT "RECOMMENDED VALUE: "; RECEXCREG%; " ppm/mA"
		PRINT USING "Excitation Load Regulation = +/- #### ppm/mA"; SPECS.EXCLOADREG;
		SPECS.EXCLOADREG = CHANGE(SPECS.EXCLOADREG)
		PRINT
		PRINT "RECOMMENDED VALUE: "; RECILIMIT%; " mA"
		PRINT USING "Excitation Current with 80 ohm load = ###.# mA "; SPECS.EXCIMAX;
		SPECS.EXCIMAX = CHANGE(SPECS.EXCIMAX)
	END IF

	IF UCASE$(LEFT$(SPECS.SENTYPE, 5)) = "OUTMA" OR UCASE$(LEFT$(SPECS.SENTYPE, 4)) = "IOMA" THEN
		RECILIMIT% = 26
		PRINT
		PRINT "RECOMMENDED VALUE: "; RECILIMIT%; " mA"
		PRINT USING "Output current limit = ###.# mA "; SPECS.EXCIMAX;
		SPECS.EXCIMAX = CHANGE(SPECS.EXCIMAX)
	END IF
   
	PRINT
	IF SPECS.LINEARIZED = 0 THEN
		PRINT "RECOMMENDED VALUE: 0.030%"
	END IF
	PRINT USING "Nonlinearity or Conformity = +/- #.### % of span"; SPECS.LINEAR;
	SPECS.LINEAR = CHANGE(SPECS.LINEAR)
	PRINT USING "Accuracy = +/- #.## % of span"; SPECS.ACCURACY;
	SPECS.ACCURACY = CHANGE(SPECS.ACCURACY)
   
'    MININ! = SPECS.MININ
'    MAXIN! = SPECS.MAXIN
'    MINOUT! = SPECS.MINOUT
'    MAXOUT! = SPECS.MAXOUT
'    SNM% = SENSORNUM%
'    IF SNM% = 5 OR SNM% = 6 THEN
'        GAIN! = (MAXOUT! - MINOUT!) / (MAXIN! - MININ!)
'        PSS.SPEC! = .005 / .5 / GAIN!  'Max. test spec. = +/-5mV or +/-0.1% per 0.5V change.
'        UNIT$ = "deg C/V"
'        CALCPSS! = PSS.SPEC!
'    ELSE
'        GAIN! = (MAXOUT! - MINOUT!) / (SENSOROUT!(MAXIN!, 0) - SENSOROUT!(MININ!, 0))
'        IF SNM% = 7 THEN GAIN! = GAIN! / (SPECS.IEXC / 1000000!)
'        PSS.SPEC! = .0006   'Let max. test spec be +/-600uV/% RTO or 0.12% for 10% Vs change and 5V span.
'        CALCPSS! = PSS.SPEC! / GAIN! * 1000000!
'        UNIT$ = "uV/%"
'    END IF
'    PRINT
'    PRINT USING "SUGGESTED VALUE OF PSS IS +/- #####.# &"; CALCPSS!; UNIT$
'    PRINT USING "Power Supply Sensitivity = +/- #####.# & RTI"; SPECS.PSS; UNIT$;
	IF UCASE$(LEFT$(SPECS.SENTYPE, 5)) = "OUTMA" OR UCASE$(LEFT$(SPECS.SENTYPE, 4)) = "IOMA" THEN
		PRINT
		PRINT "SUGGESTED VALUE OF PSS IS +/- 150 ppm/%"
	ELSE
		PRINT
		PRINT "SUGGESTED VALUE OF PSS IS +/- 50 ppm/%"
	END IF
	PRINT USING "Power Supply Sensitivity = +/- #####.# ppm/%"; SPECS.PSS;
	SPECS.PSS = CHANGE(SPECS.PSS)
   
	PRINT
	PRINT USING "Low Pass Filter -3dB Frequency = #####.# Hz"; SPECS.BANDWIDTH;
	SPECS.BANDWIDTH = CHANGE(SPECS.BANDWIDTH)
	IF SPECS.BANDWIDTH = 3 THEN
		RECTF& = 20
		IF SNM% = 1 OR SNM% = 3 THEN
			IF LEFT$(SPECS.MODNAME, 4) = "8B31" THEN
				RECATTEN% = 40 '8B31-XX
			ELSE
				RECATTEN% = 30 '8B30-XX, 37-XX, 47-XX
			END IF
		ELSE
			RECATTEN% = 40 '8B32-XX
		END IF
	ELSEIF SPECS.BANDWIDTH = 100 THEN
		RECTF& = 500
		RECATTEN% = 35
	ELSEIF SPECS.BANDWIDTH = 1000 THEN      '8B40/41
		RECTF& = 3000
		RECATTEN% = 31
	ELSEIF SPECS.BANDWIDTH = 20000 THEN     '8B50/51
		RECTF& = 41000
		RECATTEN% = 30
	END IF
   
	PRINT
	PRINT "RECOMMENDED TEST FREQUENCY: "; RECTF&; " Hz"
	PRINT USING "Low Pass Filter Test Frequency = #####.# Hz"; SPECS.TESTFREQ;
	SPECS.TESTFREQ = CHANGE(SPECS.TESTFREQ)

	PRINT
	PRINT "RECOMMENDED ATTENUATION AT "; RECTF&; "Hz:"; RECATTEN%; " dB"
	PRINT USING "Attenuation @ Test Frequency = ##.# dB"; SPECS.ATTEN;
	SPECS.ATTEN = CHANGE(SPECS.ATTEN)
   
	PRINT USING "Filter Attenuation Tolerance +/- ##.# dB "; SPECS.ATTENTOL;
	SPECS.ATTENTOL = CHANGE(SPECS.ATTENTOL)
	IF SPECS.BANDWIDTH <= 50 AND UCASE$(LEFT$(SPECS.SENTYPE, 5)) <> "OUTMA" AND UCASE$(LEFT$(SPECS.SENTYPE, 4)) <> "IOMA" THEN
		PRINT
		IF SNM% = 5 OR SNM% = 6 THEN
			RECSMIN% = 80
		ELSE
			RECSMIN% = 85
		END IF
		PRINT "RECOMMENDED VALUE: "; RECSMIN%
		PRINT USING "Step Response, Min. = ###.# % of span @ 200ms (98 for no test)"; SPECS.STEPRMIN;
		SPECS.STEPRMIN = CHANGE(SPECS.STEPRMIN)

		PRINT
		IF SNM% = 5 OR SNM% = 6 THEN
			RECSMAX% = 105
		ELSE
			RECSMAX% = 110
		END IF
		PRINT "RECOMMENDED VALUE: "; RECSMAX%
		PRINT USING "Step Response, Max. = ###.# % of span @ 200ms"; SPECS.STEPRMAX;
		SPECS.STEPRMAX = CHANGE(SPECS.STEPRMAX)
	ELSEIF UCASE$(LEFT$(SPECS.SENTYPE, 5)) = "OUTMA" OR UCASE$(LEFT$(SPECS.SENTYPE, 4)) = "IOMA" THEN
		PRINT
		RECSMIN% = 65
		PRINT "RECOMMENDED VALUE: "; RECSMIN%
		PRINT USING "Step Response, Min. = ###.# % of span @ 4ms (98 for no test)"; SPECS.STEPRMIN;
		SPECS.STEPRMIN = CHANGE(SPECS.STEPRMIN)

		PRINT
		RECSMAX% = 85
		PRINT "RECOMMENDED VALUE: "; RECSMAX%
		PRINT USING "Step Response, Max. = ###.# % of span @ 4ms"; SPECS.STEPRMAX;
		SPECS.STEPRMAX = CHANGE(SPECS.STEPRMAX)
   
	ELSE
		SPECS.STEPRMIN = 98
	END IF

   
	PRINT
	IF SPECS.OUTSIGTYPE = "CURRENT" THEN
		RECNOISE% = 3
		PRINT USING "RECOMMENDED VALUE: #### uArms"; RECNOISE%
		PRINT USING "Output Noise = ##### uArms"; SPECS.OUTNOISE;
		SPECS.OUTNOISE = CHANGE(SPECS.OUTNOISE)
	ELSE
		IF SPECS.BANDWIDTH = 1000 THEN       '8B40/41
			RECNOISE% = 600
		ELSEIF SPECS.BANDWIDTH = 20000 THEN      '8B50/51
			RECNOISE% = 5000
		ELSE
			RECNOISE% = 300
		END IF
		PRINT USING "RECOMMENDED VALUE: #### uVrms"; RECNOISE%
		PRINT USING "Output Noise = ##### uV rms"; SPECS.OUTNOISE;
		SPECS.OUTNOISE = CHANGE(SPECS.OUTNOISE)
	END IF
   
	'the following data exists for millivolt or volt input only
	IF UCASE$(LEFT$(SPECS.SENTYPE, 1)) = "V" OR UCASE$(MID$(SPECS.SENTYPE, 2, 6)) = "BRIDGE" OR UCASE$(LEFT$(SPECS.SENTYPE, 5)) = "OUTMA" OR UCASE$(LEFT$(SPECS.SENTYPE, 4)) = "IOMA" THEN
		PRINT USING "Input Resistance = ###.###### M ohm"; SPECS.INPUTRES;
		SPECS.INPUTRES = CHANGE(SPECS.INPUTRES)
	END IF
   
	PRINT
	PRINT "For open input response less than zero, the MINIMUM response is"
	PRINT "the lower negative value.  i.e. for -5.9V to -5.2V, -5.9V is MIN."
	PRINT USING "MINIMUM Open input response = +##.## V"; SPECS.VOPENINMIN;
	SPECS.VOPENINMIN = CHANGE(SPECS.VOPENINMIN)
	PRINT USING "MAXIMUM Open input response = +##.## V"; SPECS.VOPENINMAX;
	SPECS.VOPENINMAX = CHANGE(SPECS.VOPENINMAX)

END SUB

SUB SAVEDATA (SEL%)

	CLS
	LOCATE 10, 10
	PRINT "Saving record in file 8BMAIN.DAT"
	LOCATE 13, 10
	PRINT "Database changes must also be made to the 8B Gang Tester Database"
	LOCATE 15, 10
	PRINT "Select 6.) from the Main Menu to veiw and/or print the instructions"
   
	PRINT ""
	PRINT ""
	   
	CALL CONTINUE

	T = TIMER
	DO
	LOOP WHILE (TIMER - T) < 1
	   
	OPEN "U:\ENGR\ATE\8B\8BDATA\8BMAIN.DAT" FOR RANDOM AS #1 LEN = LEN(SPECS)
	IF SEL% = 0 THEN
		NR% = LOF(1) / LEN(SPECS)
		SEL% = NR% + 1
	END IF
	PUT #1, SEL%, SPECS
	CLOSE #1

END SUB

FUNCTION SENSORNUM%

	'Assign a number to each sensor type for ease of handling
	'Sensor types;
	'1 = millvolt, volt
	'2 = milliamp input
	'3 = thermocouple, except type B
	'4 = type B thermocouple (no cjc)
	'5 = 3-wire RTD
	'6 = 4-wire RTD
	'7 = potentiometer
	'8 = fbridge (full bridge strain gage, load cell)
	'9 = two-wire transmitter
	'10 = DC LVDT
	'11 = hbridge (half strain gage, load cell)
	'12 = milliamp output with voltage input
	'13 = milliamp output with current input

	SENSOR$ = SPECS.SENTYPE
	TCTYPE$ = LEFT$(SENSOR$, 1)

	IF UCASE$(LEFT$(SENSOR$, 1)) = "V" THEN
		SENSORNUM% = 1
	ELSEIF UCASE$(LEFT$(SENSOR$, 4)) = "MA" THEN
		SENSORNUM% = 2
	ELSEIF UCASE$(MID$(SENSOR$, 2, 2)) = "TC" THEN
		IF UCASE$(TCTYPE$) = "B" THEN
			SENSORNUM% = 4
		ELSE
			SENSORNUM% = 3
		END IF
	ELSEIF UCASE$(MID$(SENSOR$, 3, 5)) = "RTD3W" THEN
		SENSORNUM% = 5
	ELSEIF UCASE$(MID$(SENSOR$, 3, 5)) = "RTD4W" THEN
		SENSORNUM% = 6
	ELSEIF UCASE$(LEFT$(SENSOR$, 3)) = "POT" THEN
		SENSORNUM% = 7
	ELSEIF UCASE$(LEFT$(SENSOR$, 7)) = "FBRIDGE" THEN
		SENSORNUM% = 8
	ELSEIF UCASE$(LEFT$(SENSOR$, 4)) = "2WTX" THEN
		SENSORNUM% = 9
	ELSEIF UCASE$(LEFT$(SENSOR$, 6)) = "DCLVDT" THEN
		SENSORNUM% = 10
	ELSEIF UCASE$(LEFT$(SENSOR$, 7)) = "HBRIDGE" THEN
		SENSORNUM% = 11
	ELSEIF UCASE$(LEFT$(SENSOR$, 5)) = "OUTMA" THEN
		SENSORNUM% = 12
	ELSEIF UCASE$(LEFT$(SENSOR$, 4)) = "IOMA" THEN
		SENSORNUM% = 13
	END IF

END FUNCTION

FUNCTION SENSOROUT! (PVIN!, PTCV!)
	   
	'Calculates sensor output based on the sensor type and input
	'Inputs;    PVIN! = process variable input to sensor, i.e. temperature, voltage, current
	'           PTCV! = measured value of parasitic TC voltage

	SENSOR$ = SPECS.SENTYPE
	SNM% = SENSORNUM%
							 
								'Voltage, Potentiometer, Full Bridge, DC LVDT, or Half Bridge in
	IF SNM% = 1 OR SNM% = 7 OR SNM% = 8 OR SNM% = 10 OR SNM% = 11 OR SNM% = 12 THEN
		SENSOROUT! = PVIN!
	ELSEIF SNM% = 2 OR SNM% = 9 THEN                'mA in
		RCONV! = SPECS.RCONV
		SENSOROUT! = PVIN! / 1000! * RCONV!
	ELSEIF SNM% = 3 OR SNM% = 4 THEN                'TC in
		TCTYPE$ = LEFT$(SENSOR$, 1)
		TCV! = TCVOLTS!(PVIN!, TCTYPE$)
		SENSOROUT! = TCV! - PTCV!
	ELSEIF SNM% = 5 OR SNM% = 6 THEN                'RTD in
		RTDTYPE$ = LEFT$(SENSOR$, 2)
		RTDO! = RTDOHMS!(PVIN!, RTDTYPE$)
		SENSOROUT! = RTDO!
	ELSE
		UNKNOWN% = 1
	END IF

	IF TCV! = 99! OR RTDO! = 99! OR UNKNOWN% = 1 THEN
		SOUND 1000, .5
		PRINT
		PRINT TAB(10); "Sensor type unknown.  Check database."
		SENSOROUT! = 99!
		CALL CONTINUE
	ELSEIF TCV! = 98! OR RTDO! = 98! THEN
		SOUND 1000, .5
		PRINT
		PRINT TAB(10); "Sensor polynomial limits have been exceeded."
		SENSOROUT! = 99!                          'Value indicates error
		CALL CONTINUE
	END IF

END FUNCTION

SUB SORTALL

	'This sub does a bubble sort of the model numbers in the database
	'records FOR ALL MODELS

	CONST FALSE = 0, TRUE = NOT FALSE
   
	OPEN "U:\ENGR\ATE\8B\8BDATA\8BMAIN.DAT" FOR RANDOM AS #1 LEN = LEN(SPECS)
	NUMRECORD% = LOF(1) / LEN(SPECS)

	CLS
	LOCATE 10
	PRINT TAB(32); "SORTING PROGRESS"
	PRINT TAB(32); "----------------"
	PRINT
	'PRINT TAB(30); "START"; TAB(43); "FINISH"
	'PRINT TAB(32); "*"; TAB(46); "*"
	PRINT TAB(1); "|";
   
		DO                                  'First sort on family #
			PRINT "|";
			Swaps% = FALSE
			FOR i% = 1 TO NUMRECORD% - 1
				GET #1, i%, SPECS
				GET #1, i% + 1, SPECS2
			   
				IF VAL(MID$(SPECS2.MODNAME, 3, 2)) < VAL(MID$(SPECS.MODNAME, 3, 2)) THEN
					PUT #1, i%, SPECS2   'Swap
					PUT #1, (i% + 1), SPECS
					Swaps% = TRUE
				END IF
			NEXT i%
		LOOP WHILE Swaps%
	   
		LOCATE 13
		DO                                  'Second sort on alpha char. in family
			PRINT "+";
			Swaps% = FALSE
			FOR i% = 1 TO NUMRECORD% - 1
				GET #1, i%, SPECS
				GET #1, i% + 1, SPECS2
			  
				IF VAL(MID$(SPECS2.MODNAME, 3, 2)) = VAL(MID$(SPECS.MODNAME, 3, 2)) THEN
					IF ASC(MID$(SPECS2.MODNAME, 5, 1)) < ASC(MID$(SPECS.MODNAME, 5, 1)) THEN
						PUT #1, i%, SPECS2   'Swap
						PUT #1, (i% + 1), SPECS
						Swaps% = TRUE
					END IF
				END IF
			NEXT i%
		LOOP WHILE Swaps%

		LOCATE 13
		DO                                          'Third sort on 1st two dig. after hyphen
			PRINT "-";
			Swaps% = FALSE
			FOR i% = 1 TO NUMRECORD% - 1
				GET #1, i%, SPECS
				SL1% = LEN(RTRIM$(SPECS.MODNAME))
				L1% = 0
				DO
					L1% = L1% + 1
					'IF L1% = 15 THEN PRINT "."; SPECS.MODNAME; ".": CALL CONTINUE
				LOOP UNTIL MID$(SPECS.MODNAME, L1%, 1) = "-" OR L1% = SL1%
			   
				GET #1, i% + 1, SPECS2
				SL2% = LEN(RTRIM$(SPECS2.MODNAME))
				L2% = 0
				DO
					L2% = L2% + 1
					'IF L2% = 15 THEN PRINT "."; SPECS2.MODNAME; ".": CALL CONTINUE
				LOOP UNTIL MID$(SPECS2.MODNAME, L2%, 1) = "-" OR L2% = SL2%
			 
				IF VAL(MID$(SPECS2.MODNAME, 3, 2)) = VAL(MID$(SPECS.MODNAME, 3, 2)) THEN
				  IF ASC(MID$(SPECS2.MODNAME, 5, 1)) = ASC(MID$(SPECS.MODNAME, 5, 1)) THEN
					IF VAL(MID$(SPECS2.MODNAME, L2% + 1, 2)) < VAL(MID$(SPECS.MODNAME, L1% + 1, 2)) THEN
						PRINT SPECS2.MODNAME, SPECS.MODNAME
						PUT #1, i%, SPECS2   'Swap
						PUT #1, (i% + 1), SPECS
						Swaps% = TRUE
					END IF
				  END IF
				END IF
			NEXT i%
		LOOP WHILE Swaps%
	   
		LOCATE 13
		DO                                          'Fourth sort on 3rd char. after hyphen
			PRINT "^";
			Swaps% = FALSE
			FOR i% = 1 TO NUMRECORD% - 1
				GET #1, i%, SPECS
				SL1% = LEN(RTRIM$(SPECS.MODNAME))
				L1% = 0
				DO
					L1% = L1% + 1
					'IF L1% = 15 THEN PRINT "."; SPECS.MODNAME; ".": CALL CONTINUE
				LOOP UNTIL MID$(SPECS.MODNAME, L1%, 1) = "-" OR L1% = SL1%
			  
				GET #1, i% + 1, SPECS2
				SL2% = LEN(RTRIM$(SPECS2.MODNAME))
				L2% = 0
				DO
					L2% = L2% + 1
					'IF L2% = 15 THEN PRINT "."; SPECS2.MODNAME; ".": CALL CONTINUE
				LOOP UNTIL MID$(SPECS2.MODNAME, L2%, 1) = "-" OR L2% = SL2%
			
				IF VAL(MID$(SPECS2.MODNAME, 3, 2)) = VAL(MID$(SPECS.MODNAME, 3, 2)) THEN
				  IF ASC(MID$(SPECS2.MODNAME, 5, 1)) = ASC(MID$(SPECS.MODNAME, 5, 1)) THEN
					IF VAL(MID$(SPECS2.MODNAME, L2% + 1, 2)) = VAL(MID$(SPECS.MODNAME, L1% + 1, 2)) THEN
						IF ASC(MID$(SPECS2.MODNAME, L2% + 3, 1)) < ASC(MID$(SPECS.MODNAME, L1% + 3, 1)) THEN
							PUT #1, i%, SPECS2   'Swap
							PUT #1, (i% + 1), SPECS
							Swaps% = TRUE
						END IF
					END IF
				  END IF
				END IF
			NEXT i%
		LOOP WHILE Swaps%
	   
		LOCATE 13
		DO                                          'Fifth sort on 4th char. after hyphen
			PRINT "*";
			Swaps% = FALSE
			FOR i% = 1 TO NUMRECORD% - 1
				GET #1, i%, SPECS
				SL1% = LEN(RTRIM$(SPECS.MODNAME))
				L1% = 0
				DO
					L1% = L1% + 1
					'IF L1% = 15 THEN PRINT "."; SPECS.MODNAME; ".": CALL CONTINUE
				LOOP UNTIL MID$(SPECS.MODNAME, L1%, 1) = "-" OR L1% = SL1%
			 
				GET #1, i% + 1, SPECS2
				SL2% = LEN(RTRIM$(SPECS2.MODNAME))
				L2% = 0
				DO
					L2% = L2% + 1
					'IF L2% = 15 THEN PRINT "."; SPECS2.MODNAME; ".": CALL CONTINUE
				LOOP UNTIL MID$(SPECS2.MODNAME, L2%, 1) = "-" OR L2% = SL2%
		   
				IF VAL(MID$(SPECS2.MODNAME, 3, 2)) = VAL(MID$(SPECS.MODNAME, 3, 2)) THEN
				  IF ASC(MID$(SPECS2.MODNAME, 5, 1)) = ASC(MID$(SPECS.MODNAME, 5, 1)) THEN
					IF VAL(MID$(SPECS2.MODNAME, L2% + 1, 2)) = VAL(MID$(SPECS.MODNAME, L1% + 1, 2)) THEN
						IF ASC(MID$(SPECS2.MODNAME, L2% + 3, 1)) = ASC(MID$(SPECS.MODNAME, L1% + 3, 1)) THEN
							IF ASC(MID$(SPECS2.MODNAME, L2% + 4, 1)) < ASC(MID$(SPECS.MODNAME, L1% + 4, 1)) THEN
								PUT #1, i%, SPECS2   'Swap
								PUT #1, (i% + 1), SPECS
								Swaps% = TRUE
							END IF
						END IF
					END IF
				  END IF
				END IF
			NEXT i%
		LOOP WHILE Swaps%

	CLOSE #1

END SUB

SUB SORTDB (ENDFLAG%)

	'This sub sorts the model numbers in the database
	'records FOR A SELECTED MODEL FAMILY

	CONST FALSE = 0, TRUE = NOT FALSE
	
	'Create a file containing just the model numbers of all of the
	'records in the database for the model family selected

	OPEN "U:\ENGR\ATE\8B\8BDATA\DBSORT2.DAT" FOR RANDOM AS #2 LEN = LEN(SORTDATA1)
	OPEN "U:\ENGR\ATE\8B\8BDATA\8BMAIN.DAT" FOR RANDOM AS #1 LEN = LEN(SPECS)
	NUMRECORD% = LOF(1) / LEN(SPECS)
 
	SELFAM% = MENU3%
	IF SELFAM% = 18 THEN
		ENDFLAG% = 1
		CLOSE #1
		CLOSE #2
		EXIT SUB        'exit selected from MENU3%
	END IF

	N% = 0

	FOR i% = 1 TO NUMRECORD%
		GET #1, i%, SPECS
		SORTDATA1.MODNAME = SPECS.MODNAME
		SORTDATA1.RECNUM = i%
		 
		SELECT CASE SELFAM%    'Pick models in selected family
 
			CASE 1
				'SPECS.MODNAME = "8B30-xxxx  "
				IF MID$(SPECS.MODNAME, 3, 2) = "30" THEN
					PUT #2, , SORTDATA1        'write record # and model number
					N% = N% + 1                'found a record
				END IF
			CASE 2
				'SPECS.MODNAME = "8B31-xxxx  "
				IF MID$(SPECS.MODNAME, 3, 2) = "31" THEN
					PUT #2, , SORTDATA1        'write record # and model number
					N% = N% + 1                'found a record
				END IF
			CASE 3
				'SPECS.MODNAME = "8B32-xxxx  "
				IF MID$(SPECS.MODNAME, 3, 2) = "32" THEN
					PUT #2, , SORTDATA1        'write record # and model number
					N% = N% + 1                'found a record
				END IF
			CASE 4
				'SPECS.MODNAME = "8B34-xxxx  "
				IF MID$(SPECS.MODNAME, 3, 2) = "34" THEN
					PUT #2, , SORTDATA1        'write record # and model number
					N% = N% + 1                'found a record
				END IF
			CASE 5
				'SPECS.MODNAME = "8B35-xxxx  "
				IF MID$(SPECS.MODNAME, 3, 2) = "35" THEN
					PUT #2, , SORTDATA1        'write record # and model number
					N% = N% + 1                'found a record
				END IF
			CASE 6
				'SPECS.MODNAME = "8B36X-xxxx "
				IF MID$(SPECS.MODNAME, 3, 2) = "36" THEN
					PUT #2, , SORTDATA1        'write record # and model number
					N% = N% + 1                'found a record
				END IF
			CASE 7
				'SPECS.MODNAME = "8B37-xxxx  "
				IF MID$(SPECS.MODNAME, 3, 2) = "37" THEN
					PUT #2, , SORTDATA1        'write record # and model number
					N% = N% + 1                'found a record
				END IF
			CASE 8
				'SPECS.MODNAME = "8B38-xxxx  "
				IF MID$(SPECS.MODNAME, 3, 2) = "38" THEN
					PUT #2, , SORTDATA1        'write record # and model number
					N% = N% + 1                'found a record
				END IF
			CASE 9
				'SPECS.MODNAME = "8B39-xxxx  "
				IF MID$(SPECS.MODNAME, 3, 2) = "39" THEN
					PUT #2, , SORTDATA1        'write record # and model number
					N% = N% + 1                'found a record
				END IF
			CASE 10
				'SPECS.MODNAME = "8B40-xxxx  "
				IF MID$(SPECS.MODNAME, 3, 2) = "40" THEN
					PUT #2, , SORTDATA1        'write record # and model number
					N% = N% + 1                'found a record
				END IF
			CASE 11
				'SPECS.MODNAME = "8B41-xxxx  "
				IF MID$(SPECS.MODNAME, 3, 2) = "41" THEN
					PUT #2, , SORTDATA1        'write record # and model number
					N% = N% + 1                'found a record
				END IF
			CASE 12
				'SPECS.MODNAME = "8B42-xxxx  "
				IF MID$(SPECS.MODNAME, 3, 2) = "42" THEN
					PUT #2, , SORTDATA1        'write record # and model number
					N% = N% + 1                'found a record
				END IF
			CASE 13
				'SPECS.MODNAME = "8B43-xxxx "
				IF MID$(SPECS.MODNAME, 3, 2) = "43" THEN
					PUT #2, , SORTDATA1        'write record # and model number
					N% = N% + 1                'found a record
				END IF
			CASE 14
				'SPECS.MODNAME = "8B47x-xxxx "
				IF MID$(SPECS.MODNAME, 3, 2) = "47" THEN
					PUT #2, , SORTDATA1        'write record # and model number
					N% = N% + 1                'found a record
				END IF
			 CASE 15
				'SPECS.MODNAME = "8B50-xxxx  "
				IF MID$(SPECS.MODNAME, 3, 2) = "50" THEN
					PUT #2, , SORTDATA1        'write record # and model number
					N% = N% + 1                'found a record
				END IF
			CASE 16
				'SPECS.MODNAME = "8B51-xxxx  "
				IF MID$(SPECS.MODNAME, 3, 2) = "51" THEN
					PUT #2, , SORTDATA1        'write record # and model number
					N% = N% + 1                'found a record
				END IF
			CASE 17
				'SPECS.MODNAME = "8BPT-XXXX  "
				IF MID$(SPECS.MODNAME, 3, 2) = "PT" THEN
					PUT #2, , SORTDATA1        'write record # and model number
					N% = N% + 1                'found a record
				END IF

		END SELECT
	NEXT

	SORTDATA1.MODNAME = "9999999999-9999"       'always sorted to last value.
	SORTDATA1.RECNUM = -1        'flag indicating end of new data (over writes old)
	PUT #2, , SORTDATA1

	CLOSE #1
	CLOSE #2

END SUB

