function [t,v,head] = isfread (filename) % This function loads the binary data from a Tektronix ".ISF" % file. The ISF file format is used by newer Tektronix % TDS-series oscilloscopes. % % USAGE % % [x,y] = isfread(filename); % [x,y,head] = isfread(filename); % % INPUT % % filename - name of Tektronix ISF file % % OUTPUT % % x - evenly spaced column-vector of x-values % y - corresponding column-vector of y-values % head - (optional) header record of file FID = fopen(filename,'r'); hdata = fread(FID,511,'char')'; % read first 511 bytes hdata = min(hdata,126); % eliminate non-ascii hdata = max(hdata,9); % characters from header data hdata = char(hdata); % convert to character string bytenum = getnum(hdata,'BYT_NR'); bitnum = getnum(hdata,'BIT_NR'); encoding = getstr(hdata,'ENCDG'); binformat = getstr(hdata,'BN_FMT'); byteorder = getstr(hdata,'BYT_OR'); wfid = getquotedstr(hdata,'WFID'); pointformat = getstr(hdata,'PT_FMT'); xunit = getquotedstr(hdata,'XUNIT'); yunit = getquotedstr(hdata,'YUNIT'); xzero = getnum(hdata,'XZERO'); xincr = getnum(hdata,'XINCR'); ptoff = getnum(hdata,'PT_OFF'); ymult = getnum(hdata,'YMULT'); yzero = getnum(hdata,'YZERO'); yoff = getnum(hdata,'YOFF'); npts = getnum(hdata,'NR_PT'); if ((bytenum ~= 2) | ... (bitnum ~= 16) | ... not(strcmp(encoding,'BIN')) | ... not(strcmp(binformat,'RI')) | ... not(strcmp(pointformat,'Y'))) fclose(FID); error('Unable to process IFS file.'); end switch byteorder case 'MSB' machineformat = 'b'; case 'LSB' machineformat = 'l'; otherwise, error('Unrecognized byte order.'); end ii = strfind(hdata,'#'); fseek(FID,ii,'bof'); % advance to start of data skip = str2num(char(fread(FID,1,'char'))); fread(FID,skip); data = fread(FID, npts, 'int16', machineformat); v = yzero + ymult*(data - yoff); t = xzero + xincr*(0:npts-1)'; fclose(FID); if (nargout > 2) head.bytenum = bytenum; head.bitnum = bitnum; head.encoding = encoding; head.binformat = binformat; head.byteorder = byteorder; head.wfid = wfid; head.pointformat = pointformat; head.xunit = xunit; head.yunit = yunit; head.xzero = xzero; head.xincr = xincr; head.ptoff = ptoff; head.ymult = ymult; head.yzero = yzero; head.yoff = yoff; head.npts = npts; end function z = getnum(str,pattern) ii = strfind(str,pattern) + length(pattern); tmp = strtok(str(ii:length(str)),';'); z = str2num(tmp); function z = getstr(str,pattern) ii = strfind(str,pattern) + length(pattern) + 1; z = strtok(str(ii:length(str)),';'); function z = getquotedstr(str,pattern) ii = strfind(str,pattern) + length(pattern) + 1; z = strtok(str(ii:length(str)),'"'); z = strtok(str(ii:length(str)),'"');