资源简介
用matlab编写的读取comtrade格式的文件并绘制波形的程序
代码片段和文件信息
function read_comtrade
%% Comtrade Reader function
%
% This file is designed to decode the data stored in COMTRADE format
% as defined in IEEE C37.111-1999. This involves the opening of two files
% one containing the configuration (.cfg) information and the other
% the data (.dat).
%
% COMTRADE provides a common format for the data files and exchange medium
% needed for the interchange of various types of fault test or simulation
% data.
%% open the comtrade files & extract the data
% read_comtrade(filename)
% Imports data from the specified file
% filename: files to read .cfg and .dat
% Auto-generated by MATLAB on 12-Jul-2007 13:45:45
% Use the uigetfile function to load the .cfg file which is then used to
% load the associated .dat file
% First get the .cfg file information
[CfgFileNamePath] = uigetfile(‘*.cfg‘);%载入.CFG文件
PathAndCfgName =[Path CfgFileName]; %PathAndCfgName =路径\文件名.cfg eg. PathAndCfgName =E:\研究生\项目\READE_comtrade\262-RCS902A.cfg
% Derive the .dat file string
DatFileName = strcat(sscanf(CfgFileName‘%1s‘length(CfgFileName)-4) ‘.dat‘);%DatFileName=262-RCS902A.dat
PathAndDatName =[Path DatFileName]; %DatFileName=E:\研究生\项目\READE_comtrade\262-RCS902A.dat
% Store the file name (minus extension) and path in the workspace
assignin(‘base‘‘Path‘ Path);
assignin(‘base‘‘FileName‘ sscanf(CfgFileName‘%1s‘length(CfgFileName)-4));
% Now open the .cfg and .dat files
cfg_id = fopen(PathAndCfgName);
dat_id = fopen(PathAndDatName);
% Scan the text into local cells cfg and dat.
cfg = textscan(cfg_id ‘%s‘ ‘delimiter‘ ‘\n‘); %返回的 cfg is a single cell array
dat = textscan(dat_id ‘%s‘ ‘delimiter‘ ‘\n‘); %fopen和textscan配对使用
% close all open files as we‘re done with them now.
fclose(‘all‘);
%% start to decode the data
cfg_len = length(cfg{11});
cfg_string = cell(size(cfg));%made a empty cell array whose size equalls to the cfg
for i = 1:cfg_len
temp_string = char(cfg{11}{i});
cfg_string(i) = textscan(temp_string ‘%s‘ ‘Delimiter‘ ‘‘)‘;
end
% Comtrade File Identifier
title = char(cfg_string{11}(1));
% Comtrade Version
if length(cfg_string{11}) < 3 %#ok
Version = ‘1999‘;
else
Version = char(cfg_string{11}(3));
end
% Channel information: total analogues and digitals
No_Ch = strread(char(cfg_string{12}(1)));%No_Ch is a 1-by-N vector
Ana_Ch = strread(char(cfg_string{12}(2)));
Dig_Ch = strread(char(cfg_string{12}(3)));
% Data length i.e. no of samples
dat_len = strread(char(cfg_string{15+No_Ch}(2)));
% Nominal frequency
frequency = strread(char(cfg_string{13+No_Ch}(1)));
% Sampling rate
samp_rate = strread(char(cfg_string{15+No_Ch}(1)));
% Record started
start_date = char(cfg_string{16+No_Ch}(1));
start_time = char(cfg_string{16+No_Ch}(2));
% Record ended
end_date = char(cfg_string{17+No_Ch}(1));
end_time = c
评论
共有 条评论