Manuals >Reference >User C Functions
Print version of this Book (PDF file)
prevnext

Example 1

This example shows how to read a data set from a file using the following three functions:

    • USERC_open
    • USERC_readnum
    • USERC_close

Example 1, to be coded as a Transform Program from a Setup

 ! This Program reads a data set from a disk file 'datafile'.
! It is assumed that the file has scientific notation 
! numbers, e.g., 15 or 15.0E3, separated by white space.  The 
! white-space can be any amount of blanks, tabs,
! carriage-returns, or newlines (linefeeds).
fnum = USERC_open("datafile","r")
! open a file for reading
COMPLEX tmp_array[SIZE(vb)]
! array as big as data set 'vb'
i=0
WHILE i < SIZE(tmp_array)
  data_pt=USERC_readnum(fnum,0," %lf") 
! fnum came from USERC_open.
! 0 indicates NOT an instrument.
! " %lf" (leading space intentional)
! is to scan for any amount of 
! white-space (including none),
! followed by a long-float number,
! i.e. a double precision
! real number.
  PRINT data_pt
! To show each value as it is read.
  tmp_array[i] = data_pt
  i=i+1
END WHILE
status=USERC_close(fnum) 
! close the open file.
RETURN tmp_array 
! store data, for plotting, etc.

prevnext