function [outmat, ch, np, S_RATE]=loadwdq(in_file) %LOADWDQ is a function that % loads in data from a 'codas' file and returns the data % must give a filename ("in_file")% % % data returns in matrix 'outmat' % number of channels returns in 'ch' % number of points retruns in 'np' % sample rate of data returns in 'S_RATE' % %%%%%%% % % % Updated by Eric Hunter; September 2000. www.ncvs.org % % Fixed by Fari Alipour, January 2001 % dname=['outmat']; MAX_CHANNEL=29; fid_cod = fopen(in_file, 'rb'); % Read in the first two numbers from the CODAS data file % Number of Channels is the Remainder of (first number/32). [val, cnt] = fread(fid_cod, 2, 'ushort'); ch = rem(val(1),32); [tmp, cnt]=fread(fid_cod, 2, 'uchar'); % skip two bytes clear val cnt [val, cnt] = fread(fid_cod, 1, 'ushort'); nbhead=val(1); % number of bytes in the header (1156) clear val cnt % Read in total number of the BYTES from CODAS data file. [np_total_u, n_tmp] = fread( fid_cod, 1, 'uint32'); np_total = (np_total_u / 2); np = np_total / ch; clear np_total_u n_tmp [tmp, n_tmp] = fread(fid_cod, 4, 'ulong'); clear tmp n_tmp % Read in the inverse of the Sampling Frequency from CODAS data file [fs_inv, n_tmp] = fread(fid_cod, 1, 'double'); S_RATE = 1/fs_inv; clear fs_inv n_tmp [tmp, n_tmp] = fread(fid_cod, 74, 'char'); clear tmp n_tmp %%%%%%%%%%%%%%% Read in the Slope and Intercept. hdr = zeros(ch,2); for n = 1:ch [tmp, n_tmp] = fread(fid_cod, 8, 'char'); [hdr(n,:), n_tmp] = fread(fid_cod, [1,2], 'double'); [tmp, n_tmp] = fread(fid_cod, 12, 'char'); clear tmp n_tmp end res_channel = MAX_CHANNEL - ch; res_header = res_channel * 36 + 2; [tmp, n_tmp] = fread(fid_cod, res_header, 'char'); clear tmp n_tmp res_channel res_header %%%%%%%%%%%%%% Read in the 2 bytes integer data and shift twice to the %%%%%%%%%%%%%% RIGHT for each data. [data_tmp, n_tmp] = fread(fid_cod, [ch,np], 'short'); data_tmp = data_tmp' / 4; eval([dname ' = data_tmp;']); clear data_tmp n_tmp for n = 1:ch eval([dname '(:,n) = ' dname '(:,n) * hdr(n,1) + hdr(n,2) ;']); end clear hdr fclose(fid_cod); clear n MAX_CHANNEL fid_cod ans np_total fname hdr clear in_file