Writing Data in Ascii Format

Other topics about Sample Programs

Overview

The sample program demonstrates to Write Formatted Data Arrays in Using the ASCII Transfer Format

See Entering Data into a Trace for this programming.

Sample Program in HT Basic (write_a.htb)

10 REAL Freq,Fdata(1:1601,1:2)

20 DIM File$[300]

30 INTEGER Nop

40 !

50 ASSIGN @Agte507x TO 717

60 !

70 CALL Inp_file_name(File$)

80 !

90 OUTPUT @Agte507x;":CALC1:PAR1:SEL"

100 OUTPUT @Agte507x;":INIT1:CONT OFF"

110 OUTPUT @Agte507x;":ABOR"

120 !

130 OUTPUT @Agte507x;":SENS1:SWE:POIN?"

140 ENTER @Agte507x;Nop

150 REDIM Fdata(1:Nop,1:2)

160 !

170 ON ERROR GOTO File_error

180 ASSIGN @File TO File$

190 ENTER @File USING "K";Buff$

200 ENTER @File USING "K";Buff$

210 ENTER @File USING "K";Buff$

220 FOR I=1 TO Nop

230 ENTER @File USING "19D,2X,19D,2X,19D";Freq,Fdata(I,1),Fdata (I,2)

240 NEXT I

250 ASSIGN @File TO *

260 OFF ERROR

270 !

280 OUTPUT @Agte507x;":FORM:DATA ASC"

290 !

300 OUTPUT @Agte507x;":CALC1:DATA:FDAT ";Fdata(*)

310 !

320 GOTO Prog_end

330 !

340 File_error: OFF ERROR

350 PRINT "############ ERROR ############"

360 PRINT File$&" is NOT exist."

370 PRINT " or"

380 PRINT File$&" has UNSUITABLE data."

390 !

400 Prog_end: END

410 !=============================================

420 ! File Name Input Function

430 !=============================================

440 SUB Inp_file_name(Inp_name$)

450 DIM Inp_char$[9]

460 ON ERROR GOTO Inp_start

470 Inp_start: !

480 PRINT "Input File Name!"

490 INPUT "Name?",Inp_name$

500 PRINT "Input Name: "&Inp_name$

510 INPUT "OK? [Y/N]",Inp_char$

520 IF UPC$(Inp_char$)<>"Y" THEN Inp_start

530 OFF ERROR

540 SUBEND

Description

Line 50

Assigns a GPIB address to the I/O pass.

Line 70

Passes control to a subprogram named Inp_file_name, which lets the user input a file name, and then stores the returned file name into the File$ variable. For more information on the Inp_file_name subprogram, refer to the description in Using the Binary Transfer Format to write Formatted Data Arrays.

Lines 90 to 110

These lines set channel 1's active trace to trace 1 and hold the sweep.

Lines 130 to 140

These lines retrieve the number of points in channel 1 and stores that number into the Nop variable.

Line 150

Resizes the Fdata array based on the value of the Nop variable (the number of points).

Line 170

This line points to the statement block to be executed if an error occurs in retrieving data from the file (for example, if no file matches File$).

Lines 180 to 260

These lines retrieve the formatted data from the file identified by File$, and store the data into the Fdata array.

Line 280

Sets the data transfer format to ASCII.

Line 300

Writes Fdata into the formatted data array for the active trace (trace 1) in channel 1.

Lines 340 to 380

This statement block is executed if an error occurs in retrieving data from the file.