10    !  GETCURF
20    !-------------------------------------------------------------------------
30    ! HPBASIC/IBASIC Programs; Get Curve Fit table
40    ! This program will query the Curve Fit Data in Binary and print out most
50    ! of the information on the CRT screen. The program does not cover all
52    ! cases but uses the default conditions. The program assumes that the
54    ! Curve Fit has already been run, and the user wishes to dump the
56    ! data out of the Instrument and into the controller. The program also
58    ! prints out most of the acquired data. Use the descriptions found in
60    ! the CALC:CFIT:DATA to extract other available information from the
70    ! Curve Fit table.
80    ! This program will also distinguish between IBASIC and HPBASIC run modes.
90    !-------------------------------------------------------------------------
92    !
94    ON ERROR GOTO Not_ibasic     ! auto selection of proper select code
100   Device=800                   ! device select code from IBASIC
110   CLEAR Device
120   GOTO Start_prog
130   !
140 Not_ibasic: !
150   Device=711                   ! device select code from external computer
160 Start_prog: !
170   OFF ERROR
250   !
260   ASSIGN @Analyzer TO Device   ! allows code to be address independent
261   !
262   ! set aside a large space to read data
270   DIM A(5000)
272   !
274   ! assign an i/o path for binary transfers
280   ASSIGN @Analyzer_bin TO Device;FORMAT OFF
282   !
284   ! command the analyzer to output block data in floating point binary
286   ! representation.
290   OUTPUT @Analyzer;"FORM:DATA REAL,64"
300   !
310   !
312   ! command the analyzer to output the curve fit data
314   ! NOTE: By changing CFIT to SYNT You can extract the Synthesis table
320   OUTPUT @Analyzer;"CALC1:CFIT:DATA?"
340   !
342   ! read the header of the data block.  first read the '#n' to
344   ! find out how many digits are in the byte count then read the
346   ! number of bytes.
350   ENTER @Analyzer USING "%,A,D";A$,Digits
390   ENTER @Analyzer USING "%,"&VAL$(Digits)&"D";Num_of_bytes
392   !
400   Num_points=Num_of_bytes DIV 8 ! 8 data bytes per number
402   !
410   ! Use the number of bytes to determine the amount of data.
412   ! Redimension the array so it's the same size as the data block
414   ! being read in so we can read the data in the fastest possible way.
430   REDIM A(Num_points-1)
431   !
432   ! read all the curve fit table in binary
440   ENTER @Analyzer_bin;A(*)
450   ENTER @Analyzer;A$        ! read the line feed character (IEEE 488.2)
460   !
470   ! open up a display window if in IBASIC on the analyzer
480   IF Device=800 THEN OUTPUT @Analyzer;"DISP:PROG FULL"
490   !
500   ! start of the the print section of the program
510   PRINT ""
520   IF A(0)=0 THEN PRINT "TABLE TYPE = POLE ZERO"
530   IF A(0)=1 THEN PRINT "TABLE TYPE = POLE RESIDUE"
540   IF A(0)=2 THEN PRINT "TABLE TYPE = POLYNOMIAL"
550   PRINT ""
560   PRINT "                 POLES"
570   PRINT "       REAL              IMAGINARY"
572   !
574   ! print the left part of the table
580   FOR I=4 TO 4+2*(A(1)-1) STEP 2
590     PRINT USING "10D.4D,3X,5A,7D.3D";A(I),"+/- j",A(I+1)
600   NEXT I
610   PRINT ""
620   PRINT "                 ZEROS"
630   PRINT "       REAL              IMAGINARY"
632   !
634   ! print the right part of the table
640   FOR I=46 TO 46+2*(A(2)-1) STEP 2
650     PRINT USING "10D.4D,3X,4A,7D.3D";A(I),"+/- j",A(I+1)
660   NEXT I
670   PRINT ""
680   PRINT ""
690   PRINT "CURVE FIT TERMS"
700   PRINT "         POLES             ZERO'S"
710   PRINT ""
712   !
714   ! indicate which terms are fixed/moveable
720   FOR I=130 TO 130+(A(1)-1) STEP 1
730     IF A(I)=0 THEN
740       PRINT USING "8X,10A,#";"MOVEABLE"
750     ELSE 
760       PRINT USING "8X,10A,#";"FIXED"
770     END IF 
780     IF A(I+21)=0 THEN
790       PRINT USING "8X,10A";"MOVEABLE"
800     ELSE 
810       PRINT USING "8X,10A";"FIXED"
820     END IF 
830   NEXT I
832   !
834   ! print the final parameters of the data block
840   PRINT ""
850   PRINT " GAIN = ",A(Num_points-3)
860   PRINT " FREQUENCY SCALE  = ",A(Num_points-2),"HZ/HZ"
870   PRINT " TIME DELAY = ",A(Num_points-1),"SECONDS"
880   END
