10    !  TIMEBIN
20    !-------------------------------------------------------------------------
30    ! HPBASIC/IBASIC Programs; Time Query
40    ! This program will query the channel 1 Time Data  in Binary. This program
50    ! 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   ! allows code to be address independent
200   OUTPUT @Analyzer;"*RST"              ! Reset the analyzer
210   OUTPUT @Analyzer;"ABOR;:INIT; *WAI"  ! start measurements
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
310   ! representation.
320   OUTPUT @Analyzer;"form:data real,64" ! 64 bit binary transfer
330   !
340   ! display channel 1 time data in trace A
350   OUTPUT @Analyzer;"CALC1:FEED 'XTIM:VOLT 1';MATH:STAT OFF; *WAI"
360   ! command the analyzer to output the data from trace A
370   !
380   OUTPUT @Analyzer;"CALC1:DATA?"
390   !
400   ! read the header of the data block.  first read the '#n' to
410   ! find out how many digits are in the byte count then read the
420   ! number of bytes.
430   ENTER @Analyzer USING "%,A,D";A$,Digits
440   ENTER @Analyzer USING "%,"&VAL$(Digits)&"D";Num_of_bytes
450   !
460   Num_points=Num_of_bytes DIV 8 ! 8 data bytes per number
470   !
480   ! Use the number of bytes to determine the amount of data.
490   ! Redimension the array so it's the same size as the data block
500   ! being read in so we can read the data in the fastest possible way.
510   REDIM A(Num_points-1)
520   !
530   ! read all the numbers in the block into the array in binary
540   ENTER @Analyzer_bin;A(*)
550   ENTER @Analyzer;A$        ! read the line feed character (IEEE 488.2)
560   !
570   ! open up a display window if in IBASIC running in the analyzer
580   IF Device=800 THEN OUTPUT @Analyzer;"DISP:PROG LOW"
590   !
600   FOR I=0 TO 9              ! print the first ten values
610     PRINT "Data point ";I,A(I)
620   NEXT I
630   END
