0001 function [specstruct] = read_specfile(specfile,plotall)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030 fid = fopen(specfile,'r');
0031 if(fid < 0)
0032 error(['file: ' specfile ' does not exist']);
0033 end;
0034 fclose(fid);
0035
0036
0037 cmd = ['grep LOCATION ' specfile ' | grep -v LOCATIONS | wc -l > out'];
0038 system(cmd);
0039 fid = fopen('out','r');
0040 C=textscan(fid,'%d',1);
0041 nProfiles = C{1};
0042 fclose(fid);
0043
0044
0045 fid = fopen(specfile,'r');
0046 lin = fgetl(fid);
0047 lin = fgetl(fid);
0048 lin = fgetl(fid);
0049 lin = fgetl(fid);
0050 lin = fgetl(fid);
0051 lin = fgetl(fid);
0052 lin = fgetl(fid);
0053
0054
0055
0056 C = textscan(fid, '%f %f\n',1);
0057 x = C{1};
0058 y = C{2};
0059 fprintf('probe location: %f %f\n',x,y);
0060
0061
0062 C = textscan(fid, '%s %s %s %s %s',1);
0063 C = textscan(fid, '%d %s %s %s',1);
0064 nFreq = C{1}
0065
0066
0067 fprintf('number of profiles %d\n',nProfiles);
0068 fprintf('number of freqs %d\n',nFreq);
0069
0070
0071 freq = zeros(nFreq,1);
0072 time = zeros(nProfiles,1);
0073 dens = zeros(nProfiles,nFreq);
0074 wdir = zeros(nProfiles,nFreq);
0075 sprd = zeros(nProfiles,nFreq);
0076
0077
0078 for i=1:nFreq
0079 C = textscan(fid, '%f', 1);
0080 freq(i) = C{1};
0081 end;
0082
0083
0084 C = textscan(fid, '%s', 1);
0085 lin = fgets(fid);
0086 lin = fgets(fid);
0087 lin = fgets(fid);
0088 lin = fgets(fid);
0089 lin = fgets(fid);
0090 lin = fgets(fid);
0091 lin = fgets(fid);
0092 lin = fgets(fid);
0093 lin = fgets(fid);
0094 lin = fgets(fid);
0095 lin = fgets(fid);
0096
0097
0098 for i=1:nProfiles
0099 fprintf('reading profile %d\n',i)
0100 C = textscan(fid, '%s %s %s %s', 1);
0101 C = textscan(fid, '%s %d', 1);
0102 for j=1:nFreq
0103 C = textscan(fid, '%f %f %f', 1);
0104 pwr = C{1}; if(pwr < 0) pwr = NaN; end;
0105 dir = C{2}; if(pwr < -900) dir = NaN; end;
0106 spr = C{3}; if(pwr < 0) spr = NaN; end;
0107 dens(i,j) = pwr;
0108 wdir(i,j) = dir;
0109 sprd(i,j) = spr;
0110 end;
0111 end;
0112
0113
0114 if(plotall)
0115 for i=1:2:nProfiles
0116 plot(1./freq,dens(i,:)); hold on;
0117 end;
0118 end;