'Database Modification Program for DSCA33
'DIN rail signal conditioning modules
'
'AUTHOR: John Lehman
'DATE:   08/30/99
'
'       REVISION RECORD

'DATE       APPR    DESCRIPTION
'----       ----    -----------
'08/30/99   JL      Create, start from DBDSC4.BAS
'10/30/06   JL      Added suggested P.S. voltage levels of 19-29V.

DECLARE FUNCTION CHANGE (SPEC!)
DECLARE FUNCTION CHANGE2 (SPEC!, SCALE!)
DECLARE FUNCTION MENU1% ()
DECLARE FUNCTION MENU3% ()                      'Gets the module family
DECLARE FUNCTION REPEAT$ ()
DECLARE FUNCTION STRINGVAL% (A$)

DECLARE SUB MODDATA (SEL%)
DECLARE SUB GETSPECS (SEL%)
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 * 13  'DSCA33-XXXX or SCM5B33-XXXX
        INTYPE          AS STRING * 3   ''V' OR 'A'
        MININ           AS SINGLE       'Minus F.S. input (V or I)
        MAXIN           AS SINGLE       'Plus F.S. input (V or I)
        OUTSIGTYPE      AS STRING * 7   ''VOLTAGE' or 'CURRENT'
        MINOUT          AS SINGLE       'Minus F.S. output (V or I)
        MAXOUT          AS SINGLE       'Plus F.S. output (V or I)
        WAVESHPCAL      AS STRING * 8   ''SINE', 'SQUARE', 'TRIANGLE', 'ARBxxxxx'
        FINCAL          AS SINGLE       'Calibration Frequency input (Hz)
        FINMIN          AS SINGLE       'Minimum Std. Frequency input (Hz)
        FINMAX          AS SINGLE       'Highest Std. Frequency input (Hz)
        FINEXTMIN       AS SINGLE       'Minimum Extd. Frequency input (Hz)
        FINEXTMAX       AS SINGLE       'Highest Extd. Frequency input (Hz)
        INPROTECT       AS SINGLE       'Rated input Protection (V or I)
        IOUTLIM         AS SINGLE       'Current output limit (mA)
        VOUTLIM         AS SINGLE       'Voltage output limit (V)
        OUTRES          AS SINGLE       'Output resistance
        OUTNOISE        AS SINGLE       'Output noise/ripple 100kHz BW (rms)
        OSCALIN         AS SINGLE       'Module input for offset calibration
        GNCALIN         AS SINGLE       'Module input for gain calibration
        OSCALPT         AS SINGLE       'Offset cal point (%span)
        GNCALPT         AS SINGLE       'Gain cal point (%span)
        CALTOL          AS SINGLE       'Calibration tolerance (%span)
        ADJ             AS SINGLE       'User Adjustability Range (%span)
        LINEAR          AS SINGLE       'Linearity (% span) at sine input and FINCAL
        ACCSINCAL       AS SINGLE       'Sine accuracy (%span) at CALFIN
        ACCSINSTD       AS SINGLE       'Sine accuracy (%span) from FINMIN to FIMMAX
        ACCSINEXT       AS SINGLE       'Sine accuracy (%span) from FINEXTMIN to FINEXTMAX
        ACCCF12         AS SINGLE       'C.F. = 1 TO 2 accuracy (%span) at FINCAL
        ACCCF23         AS SINGLE       'C.F. = 2 TO 3 accuracy (%span) at FINCAL
        ACCCF34         AS SINGLE       'C.F. = 3 TO 4 accuracy (%span) at FINCAL
        ACCCF45         AS SINGLE       'C.F. = 4 TO 5 accuracy (%span) at FINCAL
        CMR             AS SINGLE       'Common Mode Rejection (dB)
        STEPTIME        AS SINGLE       'Test time for step response
        STEPPERC        AS SINGLE       '% F.S. @ STEPTIME
        STEPTOL         AS SINGLE       'STEPPERC measurement tolerance
        LOOPVMIN        AS SINGLE       'Output Loop Voltage min (V)
        LOOPVNOM        AS SINGLE       'Output Loop Voltage nom (V)
        LOOPVMAX        AS SINGLE       'Output Loop Voltage max (V)
        MAXLOADR        AS SINGLE       'Maximum load resistance (ohms)
        MINVS           AS SINGLE       'Lowest supply voltage (V)
        NOMVS           AS SINGLE       'Nominal supply voltage (V)
        MAXVS           AS SINGLE       'Highest supply voltage (V)
        ISMIN           AS SINGLE       'Minimum suuply current (mA)
        ISMAX           AS SINGLE       'Supply current, full load (mA)
        PSS             AS SINGLE       'Power supply sensitivity (ppm/% or %/% Delta Vs)
    END TYPE

    TYPE DBASE2
        RECNUM          AS INTEGER
        MODNAME         AS STRING * 13
    END TYPE

'define common variables
COMMON SHARED /SAMPLE/ SPECS 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(SEL%)
                CALL SAVEDATA(0)
           END IF
        CASE 3
           CALL GETSPECS(SEL%)
           IF LEFT$(SPECS.MODNAME, 4) <> "EXIT" THEN
                CALL MODDATA(SEL%)
                CALL SAVEDATA(SEL%)
           END IF
        CASE 4
            CALL SORTALL
        CASE 5
            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

FUNCTION CHANGE2 (SPEC!, SCALE!)

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

    IF A$ <> "" THEN
        CHANGE2 = VAL(A$) / SCALE!
    ELSE
        CHANGE2 = SPEC!
    END IF

END FUNCTION

SUB ENTDATA
          
    'for specs which are not input for all models, default value is zero.
   
    CLS
    INPUT "SCM5B, SCM8B or DSCA Model Number (SCM5Bxx-xx, SCM8Bxx-xx or DSCAxx-xx, blank to exit) "; MN$
                                            
    IF LEFT$(MN$, 1) = " " THEN
        EXIT SUB
    ELSE                                 'Check if model already exists
        OPEN "T:\ENGR\ATE\ATE\HVU\HVDATA\HVIN.DAT" FOR RANDOM AS #1 LEN = LEN(SPECS)
       
       
       
        NR% = LOF(1) / LEN(SPECS)
  
        FOR N = 1 TO NR%
            GET #1, N, SPECS
            IF SPECS.MODNAME = MN$ THEN
                BEEP
                PRINT "This model already exists in the database."
                PRINT "Press any key to continue."
                DO
                LOOP WHILE INKEY$ = ""
                CLOSE #1
                EXIT SUB
            END IF
        NEXT N
        CLOSE #1
        SPECS.MODNAME = UCASE$(MN$)
    END IF
   
    PRINT "Valid Sensor Types:"
    PRINT TAB(5); "V (millivolt or volt source)"
   ' PRINT TAB(5); "A (milliamp or amp source)"
    DO
        INPUT "Sensor Type "; SPECS.INTYPE
    LOOP WHILE LEFT$(UCASE$(SPECS.INTYPE), 1) <> "V" AND LEFT$(UCASE$(SPECS.INTYPE), 1) <> "A"
          
    INPUT "Minus F.S. Input (V, A) "; SPECS.MININ
    INPUT "Plus F.S. Input (V, A) "; SPECS.MAXIN
   
    DO
        INPUT "Output signal type ('VOLTAGE' or 'CURRENT')"; SPECS.OUTSIGTYPE
        SPECS.OUTSIGTYPE$ = UCASE$(SPECS.OUTSIGTYPE)
    LOOP WHILE SPECS.OUTSIGTYPE <> "VOLTAGE" AND SPECS.OUTSIGTYPE <> "CURRENT"

    IF SPECS.OUTSIGTYPE = "CURRENT" THEN
        UNIT$ = "mA"
        SCALE! = 1000!
    ELSE
        UNIT$ = "V"
        SCALE! = 1!
    END IF
  
    PRINT "Minus F.S. Output ("; UNIT$; ") ";
    INPUT SPECS.MINOUT
    SPECS.MINOUT = SPECS.MINOUT / SCALE! 'Convert to V or A
    PRINT "Plus F.S. Output ("; UNIT$; ") ";
    INPUT SPECS.MAXOUT
    SPECS.MAXOUT = SPECS.MAXOUT / SCALE! 'Convert to V or A
   
  '  DO
   '     INPUT "Calibration Signal Waveshape (SINE, SQUARE, TRIANGLE, RAMP) = "; SPECS.WAVESHPCAL
    '    SPECS.WAVESHPCAL = UCASE$(SPECS.WAVESHPCAL)
    'LOOP WHILE SPECS.WAVESHPCAL <> "SINE    " AND SPECS.WAVESHPCAL <> "SQUARE  " AND SPECS.WAVESHPCAL <> "TRIANGLE" AND SPECS.WAVESHPCAL <> "RAMP    "
   
   ' INPUT "Calibration Signal Frequency (Hz, 60Hz standard) "; SPECS.FINCAL
   ' INPUT "Mininum Standard Input Frequency (Hz) "; SPECS.FINMIN
   ' INPUT "Maximum Standard Input Frequency (Hz) "; SPECS.FINMAX
   ' INPUT "Mininum Extended Input Frequency (Hz) "; SPECS.FINEXTMIN
   ' INPUT "Maximum Extended Input Frequency (Hz) "; SPECS.FINEXTMAX

    'INPUT "Input Protection Rating, Max (V, A) "; SPECS.INPROTECT
    'IF SPECS.OUTSIGTYPE = "CURRENT" THEN
     '   INPUT "Current Output Limit (mA) "; SPECS.IOUTLIM
    'ELSE
     '   INPUT "Voltage Output Limit (V) "; SPECS.VOUTLIM
    'END IF
   
    'IF LEFT$(SPECS.MODNAME, 5) = "SCM5B" THEN
     '   INPUT "Output Resistance (Ohms) "; SPECS.OUTRES
    'END IF
    INPUT "Output noise/ripple (% span rms) "; SPECS.OUTNOISE
    INPUT "Input for OFFSET calibration (V, A) "; SPECS.OSCALIN
    INPUT "Input for GAIN calibration (V, A) "; SPECS.GNCALIN
    INPUT "Offset Calibration Point (+/- % of span) "; SPECS.OSCALPT
    INPUT "Gain Calibration Point (+/- % of span) "; SPECS.GNCALPT
    INPUT "Offset and Gain Calibration Tolerance (+/- % of Span) "; SPECS.CALTOL
    INPUT "Offset/Gain User Adjustability (+/- % of Span) "; SPECS.ADJ
   
    INPUT "Nonlinearity (+/- % of span) "; SPECS.LINEAR
    'PRINT USING "Accuracy z (+/- % of span) "; SPECS.FINCAL
    INPUT "Accuracy  (+/- % of span) "; SPECS.ACCSINCAL
   ' PRINT USING "Accuracy w/ Sine Input @ #####Hz to #####Hz (+/- % of span) "; SPECS.FINMIN; SPECS.FINMAX
   ' INPUT SPECS.ACCSINSTD
   ' PRINT USING "Accuracy w/ Sine Input @ #####Hz to #####Hz (+/- % of span) "; SPECS.FINEXTMIN; SPECS.FINEXTMAX
   ' INPUT SPECS.ACCSINEXT
   
   ' PRINT USING "Accuracy w/ Crest Factor 1 to 2 @ #####Hz (+/- % of span) "; SPECS.FINCAL
    'INPUT SPECS.ACCCF12
    'PRINT USING "Accuracy w/ Crest Factor 2 to 3 @ #####Hz (+/- % of span) "; SPECS.FINCAL
   ' INPUT SPECS.ACCCF23
   ' PRINT USING "Accuracy w/ Crest Factor 3 to 4 @ #####Hz (+/- % of span) "; SPECS.FINCAL
   ' INPUT SPECS.ACCCF34
   ' PRINT USING "Accuracy w/ Crest Factor 4 to 5 @ #####Hz (+/- % of span) "; SPECS.FINCAL
   ' INPUT SPECS.ACCCF45
   
   ' INPUT "Common Mode Rejection (dB) "; SPECS.CMR
    INPUT "Step Response Test Delay (s, 0.1 typ.)"; SPECS.STEPTIME
    PRINT "Nominal Response at #.### s (% span)"; SPECS.STEPTIME;
   ' INPUT SPECS.STEPPERC
   ' INPUT "Step Response Tolerance (%) "; SPECS.STEPTOL
          
    IF SPECS.OUTSIGTYPE = "CURRENT" THEN
        INPUT "Maximum Load Resistance (Ohms) "; SPECS.MAXLOADR
        IF LEFT$(SPECS.MODNAME, 5) = "SCM5B" THEN
            INPUT "Minimum Output Loop Voltage (V) "; SPECS.LOOPVMIN
            INPUT "Nominal Output Loop Voltage (V) "; SPECS.LOOPVNOM
            INPUT "Maximum Output Loop Voltage (V) "; SPECS.LOOPVMAX
        END IF
    END IF
 
    INPUT "Minimum Supply Voltage (V) [5B/8B- 4.75V, DSCA- 19V]"; SPECS.MINVS
    INPUT "Nominal Supply Voltage (V) [5B/8B- 5V,    DSCA- 24V]"; SPECS.NOMVS
    INPUT "Maximum Supply Voltage (V) [5B/8B- 5.25V, DSCA- 29V]"; SPECS.MAXVS
    INPUT "Minimum Supply Current (mA) "; SPECS.ISMIN
    INPUT "Maximum Supply Current (mA) "; SPECS.ISMAX
   
    
    IF LEFT$(SPECS.MODNAME, 5) = "SCM5B" THEN
        UNIT$ = "ppm / %"
    ELSEIF LEFT$(SPECS.MODNAME, 2) = "8B" THEN
        UNIT$ = "ppm / %"
    ELSE
        UNIT$ = "% / %"
    END IF
    PRINT "Power Supply Sensitivity ("; UNIT$; ") ";
    INPUT SPECS.PSS

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); "--------------------"
    PRINT
     
    YINIT% = CSRLIN                 'Initialize starting rows

    OPEN "T:\ENGR\ATE\HVU\HVDATA\HVSORT.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% = 19                   '13 char + 4 char for # + 2 spaces
    NUMLINES! = 19                  '# 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 23, SCRNCTR% - NUMCHAR% / 2 * NUMCOLUMNS!
        PRINT "Enter Selection ";
        INPUT SEL%
    LOOP WHILE SEL% < 1 OR SEL% > I%
  
    IF SEL% = I% THEN
        SPECS.MODNAME = "EXIT"
    ELSE
        OPEN "T:\ENGR\ATE\HVU\HVDATA\HVIN.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

FUNCTION MENU1%

        CLS
        LOCATE 5
        PRINT TAB(18); "SCM5Bxx, SCM8Bxx & DSCAxx 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.) Exit Program"
        PRINT
        PRINT TAB(17); "Enter your selection";

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

        MENU1% = VAL(A$)

END FUNCTION

FUNCTION MENU3%

    CLS
    LOCATE 3, 26
    PRINT "Module Family Selection Menu"
    PRINT TAB(26); "---------------------------"
    PRINT
    PRINT TAB(34); "1.) SCM5Bxx-xx"
    PRINT TAB(34); "2.) DSCAxx-xx"
    PRINT TAB(34); "3.) 8Bxx-xx"
    PRINT TAB(34); "4.) Exit"

    DO
        I$ = INKEY$
    LOOP WHILE VAL(I$) < 1 OR VAL(I$) > 4

    MENU3% = VAL(I$)

END FUNCTION

SUB MODDATA (SEL%)
          
    CLS
    PRINT "Model Number: "; SPECS.MODNAME;
    INPUT MN$
    IF MN$ <> "" THEN
                                         'Check if model already exists
        OPEN "T:\ENGR\ATE\HVU\HVDATA\HVIN.DAT" FOR RANDOM AS #1 LEN = LEN(SPECS)
        
        NR% = LOF(1) / LEN(SPECS)
 
        FOR N% = 1 TO NR%
            GET #1, N%, SPECS
            IF SPECS.MODNAME = MN$ THEN
                BEEP
                PRINT "This model already exists in the database."
                PRINT "Press any key to continue."
                DO
                LOOP WHILE INKEY$ = ""
                CLOSE #1
                EXIT SUB
            END IF
        NEXT
        GET #1, SEL%, SPECS
        SPECS.MODNAME = MN$
        CLOSE #1
    END IF
   
    PRINT "Sensor Type: "; SPECS.INTYPE;
    INPUT A$
    IF A$ <> "" THEN
        SPECS.INTYPE = A$
    END IF
   
    PRINT USING "Minus F.S. Input = +###.### (V, A)"; SPECS.MININ;
    SPECS.MININ = CHANGE(SPECS.MININ)
    PRINT USING "Plus F.S. Input = +###.### (V, A)"; SPECS.MAXIN;
    SPECS.MAXIN = CHANGE(SPECS.MAXIN)
   
    DO
        PRINT "Output signal type = "; SPECS.OUTSIGTYPE;
        INPUT A$
        IF A$ <> "" THEN SPECS.OUTSIGTYPE = UCASE$(A$)
    LOOP WHILE SPECS.OUTSIGTYPE <> "VOLTAGE" AND SPECS.OUTSIGTYPE <> "CURRENT"
   
    IF SPECS.OUTSIGTYPE = "CURRENT" THEN
        UNIT$ = "mA"
        SCALE! = 1000!
    ELSE
        UNIT$ = "V"
        SCALE! = 1!
    END IF
   
    PRINT USING "Minus F.S. Output = +#####.## &"; SPECS.MINOUT * SCALE!; UNIT$;
    SPECS.MINOUT = CHANGE2(SPECS.MINOUT, SCALE!)
    PRINT USING "Plus F.S. Output = +#####.## &"; SPECS.MAXOUT * SCALE!; UNIT$;
    SPECS.MAXOUT = CHANGE2(SPECS.MAXOUT, SCALE!)

   ' DO
    '    PRINT "Calibration Signal Waveshape (SINE, SQUARE, TRIANGLE, RAMP) = "; SPECS.WAVESHPCAL
     '   INPUT A$
      '  IF A$ <> "" THEN SPECS.WAVESHPCAL = UCASE$(A$)
    'LOOP WHILE SPECS.WAVESHPCAL <> "SINE    " AND SPECS.WAVESHPCAL <> "SQUARE  " AND SPECS.WAVESHPCAL <> "TRIANGLE" AND SPECS.WAVESHPCAL <> "RAMP    "
   
   ' PRINT USING "Calibration Signal Frequency = ###### Hz"; SPECS.FINCAL;
   ' SPECS.FINCAL = CHANGE(SPECS.FINCAL)
   ' PRINT USING "Mininum Standard Input Frequency = ##### Hz"; SPECS.FINMIN;
   ' SPECS.FINMIN = CHANGE(SPECS.FINMIN)
   ' PRINT USING "Maximum Standard Input Frequency = ##### Hz"; SPECS.FINMAX;
   ' SPECS.FINMAX = CHANGE(SPECS.FINMAX)
   ' PRINT USING "Mininum Extended Input Frequency = ##### Hz"; SPECS.FINEXTMIN;
   ' SPECS.FINEXTMIN = CHANGE(SPECS.FINEXTMIN)
   ' PRINT USING "Maximum Extended Input Frequency = ###### Hz"; SPECS.FINEXTMAX;
   ' SPECS.FINEXTMAX = CHANGE(SPECS.FINEXTMAX)

   ' PRINT USING "Input Protection Rating, Max = #### (V or A)"; SPECS.INPROTECT;
   ' SPECS.INPROTECT = CHANGE(SPECS.INPROTECT)
   ' IF SPECS.OUTSIGTYPE = "CURRENT" THEN
    '    PRINT USING "Current Output Limit = ##.# mA"; SPECS.IOUTLIM;
     '   SPECS.IOUTLIM = CHANGE(SPECS.IOUTLIM)
    'ELSE
     '   PRINT USING "Voltage Output Limit = ##.# V"; SPECS.VOUTLIM;
      '  SPECS.VOUTLIM = CHANGE(SPECS.VOUTLIM)
    'END IF
  
    'IF LEFT$(SPECS.MODNAME, 5) = "SCM5B" THEN
    '    PRINT USING "Output Resistance = ### Ohms"; SPECS.OUTRES;
     '   SPECS.OUTRES = CHANGE(SPECS.OUTRES)
    'END IF
   
    PRINT USING "Output Noise = #.### % span rms"; SPECS.OUTNOISE;
    SPECS.OUTNOISE = CHANGE(SPECS.OUTNOISE)
   
    PRINT USING "Input for OFFSET calibration = +###.### (V, A)"; SPECS.OSCALIN;
    SPECS.OSCALIN = CHANGE(SPECS.OSCALIN)
    PRINT USING "Input for GAIN calibration = +###.### (V, A)"; SPECS.GNCALIN;
    SPECS.GNCALIN = CHANGE(SPECS.GNCALIN)
   
    PRINT
    PRINT "Offset and gain may be calibrated at a point other than -f.s. out"
    PRINT "or +f.s. out."
    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)
    PRINT USING "Offset and Gain Calibration Tolerance = +/- #.### % of span"; SPECS.CALTOL;
    SPECS.CALTOL = CHANGE(SPECS.CALTOL)
    PRINT USING "Offset/Gain User Adjustability = +/- ##.# % of span"; SPECS.ADJ;
    SPECS.ADJ = CHANGE(SPECS.ADJ)

    PRINT USING "Nonlinearity = +/- #.### % of span"; SPECS.LINEAR;
    SPECS.LINEAR = CHANGE(SPECS.LINEAR)
    PRINT USING "Accuracy  = +/- #.### % of span"; SPECS.ACCSINCAL;
    SPECS.ACCSINCAL = CHANGE(SPECS.ACCSINCAL)
   ' PRINT USING "Addt'l Error w/ Sine Input @ ##### Hz to ##### Hz = +/- #.### % of span"; SPECS.FINMIN; SPECS.FINMAX; SPECS.ACCSINSTD;
   ' SPECS.ACCSINSTD = CHANGE(SPECS.ACCSINSTD)
   ' PRINT USING "Addt'l Error w/ Sine Input @ ##### Hz to ##### Hz = +/- #.### % of span"; SPECS.FINEXTMIN; SPECS.FINEXTMAX; SPECS.ACCSINEXT;
   ' SPECS.ACCSINEXT = CHANGE(SPECS.ACCSINEXT)

   ' PRINT USING "Addt'l Error w/ Crest Factor 1 to 2 @ ##### Hz = +/- #.### % of span"; SPECS.FINCAL; SPECS.ACCCF12;
   ' SPECS.ACCCF12 = CHANGE(SPECS.ACCCF12)
   ' PRINT USING "Addt'l Error w/ Crest Factor 2 to 3 @ ##### Hz = +/- #.### % of span"; SPECS.FINCAL; SPECS.ACCCF23;
   ' SPECS.ACCCF23 = CHANGE(SPECS.ACCCF23)
   ' PRINT USING "Addt'l Error w/ Crest Factor 3 to 4 @ ##### Hz = +/- #.### % of span"; SPECS.FINCAL; SPECS.ACCCF34;
   ' SPECS.ACCCF34 = CHANGE(SPECS.ACCCF34)
   ' PRINT USING "Addt'l Error w/ Crest Factor 4 to 5 @ ##### Hz = +/- #.### % of span"; SPECS.FINCAL; SPECS.ACCCF45;
   ' SPECS.ACCCF45 = CHANGE(SPECS.ACCCF45)
   
   ' PRINT USING "Common Mode Rejection = ### dB"; SPECS.CMR;
   ' SPECS.CMR = CHANGE(SPECS.CMR)
    PRINT USING "Step Response Test Delay = #.###### s"; SPECS.STEPTIME;
    SPECS.STEPTIME = CHANGE(SPECS.STEPTIME)
   ' PRINT USING "Nominal Response at #.### s = ###.# % span"; SPECS.STEPTIME; SPECS.STEPPERC;
    'SPECS.STEPPERC = CHANGE(SPECS.STEPPERC)
    'PRINT USING "Step Response Tolerance = +/- ##.# % "; SPECS.STEPTOL;
    'SPECS.STEPTOL = CHANGE(SPECS.STEPTOL)
         
    IF SPECS.OUTSIGTYPE = "CURRENT" THEN
        PRINT USING "Maximum Load Resistance = ##### Ohms"; SPECS.MAXLOADR;
        SPECS.MAXLOADR = CHANGE(SPECS.MAXLOADR)
        IF LEFT$(SPECS.MODNAME, 5) = "SCM5B" THEN
            PRINT USING "Minimum Output Loop Voltage = ##.# V"; SPECS.LOOPVMIN;
            SPECS.LOOPVMIN = CHANGE(SPECS.LOOPVMIN)
            PRINT USING "Nominal Output Loop Voltage = ##.# V"; SPECS.LOOPVNOM;
            SPECS.LOOPVNOM = CHANGE(SPECS.LOOPVNOM)
            PRINT USING "Maximum Output Loop Voltage = ##.# V"; SPECS.LOOPVMAX;
            SPECS.LOOPVMAX = CHANGE(SPECS.LOOPVMAX)
        END IF
    END IF
   
    PRINT USING "Minimum Supply Voltage = ##.## V"; SPECS.MINVS;
    SPECS.MINVS = CHANGE(SPECS.MINVS)
    PRINT USING "Nominal Supply Voltage = ##.## V"; SPECS.NOMVS;
    SPECS.MINVS = CHANGE(SPECS.MINVS)
    PRINT USING "Maximum Supply Voltage = ##.## V"; SPECS.MAXVS;
    SPECS.MAXVS = CHANGE(SPECS.MAXVS)
   
    PRINT USING "Minimum Supply Current = ### mA"; SPECS.ISMIN;
    SPECS.ISMIN = CHANGE(SPECS.ISMIN)
    PRINT USING "Maximum Supply Current = ### mA"; SPECS.ISMAX;
    SPECS.ISMAX = CHANGE(SPECS.ISMAX)
  
    IF LEFT$(SPECS.MODNAME, 5) = "SCM5B" THEN
        PRINT USING "Power Supply Sensitivity = #### ppm / %"; SPECS.PSS;
    ELSEIF LEFT$(SPECS.MODNAME, 2) = "8B" THEN
        PRINT USING "Power Supply Sensitivity = #### ppm / %"; SPECS.PSS;
   
    ELSE
        PRINT USING "Power Supply Sensitivity = #.#### % / %"; SPECS.PSS;
    END IF
    SPECS.PSS = CHANGE(SPECS.PSS)

END SUB

FUNCTION REPEAT$
       
    CLS
    LOCATE 10, 10
    PRINT "Do you want to enter or modify another module ?";

    DO
        A$ = INKEY$
    LOOP WHILE A$ = ""

    REPEAT$ = A$

END FUNCTION

SUB SAVEDATA (SEL%)

    CLS
    LOCATE 10, 15
    PRINT "Saving record in file HVIN.DAT"
       
    T = TIMER
    DO
    LOOP WHILE (TIMER - T) < 1
       
    OPEN "T:\ENGR\ATE\HVU\HVDATA\HVIN.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

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 "T:\ENGR\ATE\HVU\HVDATA\HVIN.DAT" FOR RANDOM AS #1 LEN = LEN(SPECS)
    
    NUMRECORD% = LOF(1) / LEN(SPECS)

    PRINT
    PRINT TAB(10); "Sorting database, please wait."
  
    'Sort according to string value
    DO
        Swaps% = FALSE
        FOR I% = 1 TO NUMRECORD%
            GET #1, I%, SPECS
            A% = STRINGVAL%(SPECS.MODNAME)
            GET #1, I% + 1, SORTDATA2
            B% = STRINGVAL%(SORTDATA2.MODNAME)
            'Do sort...
            IF A% > B% THEN
                PUT #1, I%, SORTDATA2
                PUT #1, (I% + 1), SPECS
                Swaps% = I%
            END IF
        NEXT I%
    LOOP WHILE Swaps%

    CLOSE #1

END SUB

SUB SORTDB (ENDFLAG%)

    'This sub does a bubble sort of 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 "T:\ENGR\ATE\HVU\HVDATA\HVSORT.DAT" FOR RANDOM AS #2 LEN = LEN(SORTDATA1)
    OPEN "T:\ENGR\ATE\HVU\HVDATA\HVIN.DAT" FOR RANDOM AS #1 LEN = LEN(SPECS)
    
    NUMRECORD% = LOF(1) / LEN(SPECS)

    SELFAM% = MENU3%
    IF SELFAM% = 4 THEN
        ENDFLAG% = 1
        CLOSE #1
        CLOSE #2
        CLOSE #3
        EXIT SUB        'exit selected from MENU3%
    END IF

    N% = 0

    FOR I% = 1 TO NUMRECORD%
        GET #1, I%, SPECS
        MN$ = SPECS.MODNAME
        SORTDATA1.MODNAME = MN$
        SORTDATA1.RECNUM = I%

        SELECT CASE SELFAM%    'Pick models in selected family

            CASE 1
                'SPECS.MODNAME = "SCM5Bxx-xxxx "
                IF LEFT$(MN$, 3) = "SCM" THEN
                    PUT #2, , SORTDATA1        'write record # and model number
                    N% = N% + 1                'found a record
                END IF
            CASE 2
                'SPECS.MODNAME = "DSCAxx-xxxx  "
                IF LEFT$(MN$, 3) = "DSC" THEN
                    PUT #2, , SORTDATA1        'write record # and model number
                    N% = N% + 1                'found a record
                END IF
       
            CASE 3
                'SPECS.MODNAME = "8Bxx-xxxx  "
                IF LEFT$(MN$, 2) = "8B" THEN
                    PUT #2, , SORTDATA1        'write record # and model number
                    N% = N% + 1                'found a record
                END IF
       
       
       
        END SELECT
    NEXT

    SORTDATA1.MODNAME = "99999999-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
    CLOSE #3
END SUB

FUNCTION STRINGVAL% (A$)

    'Calculate and return the value of the characters in A$
    'which follow the hyphen
  
    T% = LEN(A$)

    DO
        L% = L% + 1
    LOOP UNTIL MID$(A$, L%, 1) = "-" OR L% = T%
 
    STRINGVAL% = VAL(RIGHT$(A$, T% - L%))

END FUNCTION

