MATLAB script is yielding scaled outputs
Show older comments
I found this script which reads in .rpc/.rsp files (format - binary, data type - short integer, file type - time history) and writes data values to column vectors. Script origin can be found here: https://www.mathworks.com/matlabcentral/fileexchange/9357-load-rpc-files-of-type-binary-short_integer-time_history
function [TIME,DATA,FFORMAT]=load2_rpc(varargin)
if length(varargin)==0; % filename missing
%[fname, pname] = uigetfile('*.rpc','Choose rpc III file');
[fname, pname, filterindex] = uigetfile( ...
{'*.rpc;*.rsp', '(*.rpc *.rsp) files';
'*.rpc', '*.rpc - RPC file'; ...
'*.rsp','*.rsp - RPC response file'; ...
'*.*', 'All Files (*.*)'}, ...
'Choose RPC / III file');
FFORMAT.NAME=fname;
if fname==0;
return
end
fname=[pname fname];
elseif length(varargin)==1;
fname = varargin{1};
else
disp('Warning, wrong number of parameters')
end
% initialize standard rpc fullscale, if not defined in rpc header
FFORMAT.num_fullscale=32752;
% intitialize standard integer fullscale
int_FS=32768;
fid = fopen(fname); % open rpc-file for reading
if fid<=0
disp('file could not be opened')
return
end
fdir = dir(fname);
FFORMAT.fsize = fdir.bytes;
% read Header
FFORMAT.num_para=8; %minimum 8x 128byte header lines
% (NUM_PARAMS must be found within these 1024 bytes)
FFORMAT.num_header_blocks=2;
para_found=0;
lin=0;
while lin<FFORMAT.num_header_blocks*4 | mod(lin,4)~=0;
tline = fread(fid, 128, 'uint8=>char');
lin=lin+1;
%disp(num2str(lin))
%convert to true string
for n=1:128
if double(tline(n))==0
tline(n)=' ';
end
end
oline=tline';
tline=upper(tline)'; %create upper case row-String
%disp(tline)
para='INT_FULL_SCALE';
if strcmp(para,tline(1:length(para)));
FFORMAT.num_fullscale=str2num(strtrim(oline(33:33+80)));
end
para='NUM_HEADER_BLOCKS';
if strcmp(para,tline(1:length(para)));
FFORMAT.num_header_blocks=str2num(strtrim(oline(33:33+80)));
end
para='NUM_PARAMS';
if strcmp(para,tline(1:length(para)));
FFORMAT.num_para=str2num(strtrim(oline(33:33+80)));
para_found=1;
end
para='FORMAT';
if strcmp(para,tline(1:length(para)));
FFORMAT.format=strtrim(oline(33:33+80));
if upper(FFORMAT.format) ~= 'BINARY'
disp('WARNING: rpc file format not binary, may cause errors');
end
end
para='DATA_TYPE';
if strcmp(para,tline(1:length(para)));
FFORMAT.data_type=strtrim(oline(33:33+80));
if upper(FFORMAT.data_type) ~= 'SHORT_INTEGER'
disp('WARNING: rpc data not of type "short_integer", may cause errors');
end
end
para='DELTA_T';
if strcmp(para,tline(1:length(para)))
FFORMAT.dt=str2num(strtrim(oline(33:33+15)));
FFORMAT.fsample=1/str2num(strtrim(oline(33:33+80)));
end
para='CHANNELS';
if strcmp(para,tline(1:length(para)));
FFORMAT.num_chan=str2num(strtrim(oline(33:33+80)));
end
para='PTS_PER_FRAME';
if strcmp(para,tline(1:length(para)));
FFORMAT.num_PPF=str2num(strtrim(oline(33:33+80)));
end
para='PTS_PER_GROUP';
if strcmp(para,tline(1:length(para)));
FFORMAT.num_PPG=str2num(strtrim(oline(33:33+80)));
end
para='FRAMES';
if strcmp(para,tline(1:length(para)));
FFORMAT.num_frames=str2num(strtrim(oline(33:33+80)));
end
para='DATE';
if strcmp(para,tline(1:length(para)));
FFORMAT.dat_date=strtrim(oline(33:33+80));
end
para='FILE_TYPE';
if strcmp(para,tline(1:length(para)));
FFORMAT.file_type=strtrim(oline(33:33+80));
end
para='TIME_TYPE';
if strcmp(para,tline(1:length(para)));
FFORMAT.time_type=strtrim(oline(33:33+80));
end
para='OPERATION';
if strcmp(para,tline(1:length(para)));
FFORMAT.operation=strtrim(oline(33:33+80));
end
para='SCALE.CHAN_';
if strcmp(para,tline(1:length(para)));
tmp_ch=str2num(strtrim(oline(length(para)+1:length(para)+4)));
FFORMAT.chan(tmp_ch).scale = str2num(strtrim(oline(33:33+80)));
end
para='LOWER.LIMIT.CHAN_';
if strcmp(para,tline(1:length(para)));
tmp_ch=str2num(strtrim(oline(length(para)+1:length(para)+4)));
FFORMAT.chan(tmp_ch).lolim = str2num(strtrim(oline(33:33+80)));
end
para='UPPER.LIMIT.CHAN_';
if strcmp(para,tline(1:length(para)));
tmp_ch=str2num(strtrim(oline(length(para)+1:length(para)+4)));
FFORMAT.chan(tmp_ch).uplim = str2num(strtrim(oline(33:33+80)));
end
para='MAP.CHAN_';
if strcmp(para,tline(1:length(para)));
tmp_ch=str2num(strtrim(oline(length(para)+1:length(para)+4)));
FFORMAT.chan(tmp_ch).map = strtrim(oline(33:33+80));
end
para='DESC.CHAN_';
if strcmp(para,tline(1:length(para)));
tmp_ch=str2num(strtrim(oline(length(para)+1:length(para)+4)));
FFORMAT.chan(tmp_ch).desc = strtrim(oline(33:33+80));
end
para='UNITS.CHAN_';
if strcmp(para,tline(1:length(para)));
tmp_ch=str2num(strtrim(oline(length(para)+1:length(para)+4)));
FFORMAT.chan(tmp_ch).units = strtrim(oline(33:33+80));
end
end
%disp(chan(:))
anaName = find(fname=='\');
FFORMAT.NAME = fname; %(anaName(length(anaName)):length(fname));
if length(anaName) > 0
FFORMAT.NAME = fname(1+anaName(end):end);
end
if para_found==0
disp('Parameter NUM_PARAMS missing within the first 1024 bytes');
return
end
data_read=lin*128;
% initialize matrix DATA size
FFORMAT.data_length=round((FFORMAT.fsize-data_read)/(2*FFORMAT.num_chan));
DATA(1:FFORMAT.data_length,1:FFORMAT.num_chan)=0;
% read data
f=0;
fstep=round(FFORMAT.num_PPG / FFORMAT.num_PPF);
ink=0;
data_read=0;
h=waitbar(0,['Reading file ' FFORMAT.NAME]);
next_wb=0.2;
data_step=round(0.2*FFORMAT.data_length);
while ~feof(fid) & f < FFORMAT.num_frames
for fi = 1:FFORMAT.num_chan
tline = fread(fid, FFORMAT.num_PPG, 'int16');
%if length(tline) < FFORMAT.num_PPG
% tline(length(tline):FFORMAT.num_PPG)=0;
%end
DATA(ink*FFORMAT.num_PPG+1:(ink+1)*FFORMAT.num_PPG,fi)=tline;
end
data_read=data_read + FFORMAT.num_PPG;
if data_read > data_step
waitbar(next_wb);
next_wb=next_wb+0.2;
data_step=data_step + round(0.2 * FFORMAT.data_length);
end
f=f + fstep;
ink=ink+1;
end
close(h);
fclose(fid);
%DATA=DATA';
ndata = length(DATA(:,1));
%TIME = linspace(0, ndata / FFORMAT.fsample, 20)';
assignin('base','data',DATA);
FFORMAT
When reading .rsp files through this script, the y-axis outputs are coming out but being multiplied by some seemingly random multiplier, which differs for each channel. I don't see where in the script is the output being multiplied by value, however. Does anyone know why this is happening?
1 Comment
Cris LaPierre
on 22 Jan 2022
Can you give us a hint where you are seeing a yaxis in the output?

Answers (0)
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!