10    !  GETBIN
20    !-------------------------------------------------------------------------
30    ! HPBASIC/IBASIC Programs; Power spectrum  Query in binary
40    ! This program will query the channel 1 Power Spectrum  Data  in Binary.
50    ! This program will also distinguish between IBASIC and HPBASIC run modes.
60    !-------------------------------------------------------------------------
70    !
80    ON ERROR GOTO Not_ibasic     ! auto selection of proper select code
90    Device=800                   ! device select code from IBASIC
100   CLEAR Device
110   GOTO Start_prog
120   !
130 Not_ibasic: !
140   Device=711                   ! device select code from external computer
150 Start_prog: !
160   OFF ERROR
170   !
180   !
190   ASSIGN @Analyzer TO Device
200   OUTPUT @Analyzer;"*RST"             ! Reset the analyzer
210   OUTPUT @Analyzer;"ABOR;:INIT; *WAI" ! start a new measurement
220   OUTPUT @Analyzer;":INIT:CONT OFF"   ! pause after first measurement
230   !
240   ! set aside a large space for the data
250   DIM A(5000)
260   !
270   ! assign an i/o path for binary transfers
280   ASSIGN @Analyzer_bin TO Device;FORMAT OFF
290   !
300   ! command the analyzer to output block data in floating point binary 
302   ! representation.
310   OUTPUT @Analyzer;"form:data real,64"
320   !
330   ! command the analyzer to output the data from trace A
340   OUTPUT @Analyzer;"CALC1:DATA?"
350   !
360   ! read the header of the data block.  first read the '#n' to
370   ! find out how many digits are in the byte count then read the
380   ! number of bytes.
390   ENTER @Analyzer USING "%,A,D";A$,Digits
400   ENTER @Analyzer USING "%,"&VAL$(Digits)&"D";Num_of_bytes
410   !
420   Num_points=Num_of_bytes DIV 8 ! 8 data bytes per number
430   !
440   ! Use the number of bytes to determine the amount of data.
450   ! Redimension the array so it's the same size as the data block
460   ! being read in so we can read the data in the fastest possible way.
470   REDIM A(Num_points-1)
480   !
490   ! read all the numbers in the block into the array in binary
500   ENTER @Analyzer_bin;A(*)
510   ENTER @Analyzer;A$        ! read the line feed character (IEEE 488.2)
520   !
530   ! open up a display window if in IBASIC running in the analyzer
540   IF Device=800 THEN OUTPUT @Analyzer;"DISP:PROG LOW"
550   !
560   FOR I=0 TO 9              ! print the first ten values
570     PRINT "Data point ";I,A(I)
580   NEXT I
590   END
