% test.m % % reads in a .xtsr file clear disp(' Script to read in a variable number of constituents from a "xtsr" file') disp(' These files are available') dir *.xtsr dir xtsr.opt infile = input(' Enter the input filename: ','s'); xtsr = fopen(infile); A = fscanf(xtsr,'%f',4); % % read # active const., # of segments, # layers, bottom layer bottom elevation % nac = A(1); nseg = A(2); kmp = A(3); elbot = A(4); % read the constituent numbers that are active numac = fscanf(xtsr,'%f',nac); % read the segment numbers segnum = fscanf(xtsr,'%f',nseg); % read the distance to each segment xdist = fscanf(xtsr,'%f',nseg); % read the bottom layer for each segment kb = fscanf(xtsr,'%f',nseg); % read the layer thicknesses h = fscanf(xtsr,'%f',kmp); % calculate the elevation of the layer bottoms, elb elb(kmp) = elbot; for i=kmp-1:-1:1 elb(i)=elb(i+1) + h(i+1); end % read in which constituents have been printed kpr = fscanf(xtsr,'%f',1); kprn = fscanf(xtsr,'%f',kpr); kpr=kpr+1; kprn(kpr)=22; % read the data for this time step % % i=segment % j= timestep % kc= constituent for j=1:100000 num_times=j-1 jday(j) = fscanf(xtsr,'%f',1); elkt(j)=fscanf(xtsr,'%f',1); kt(j)=fscanf(xtsr,'%f',1); % read constituents and temperature for kc=1:kpr for i=1:nseg dum=fscanf(xtsr,'%f',1); nl=fscanf(xtsr,'%f',1); for k= 1:nl c(kt+k-1,i,j,kc)=fscanf(xtsr,'%f',1); end end end % read elevations % read elevations dum=fscanf(xtsr,'%s',1); numel=fscanf(xtsr,'%f',1); el(:,j)=fscanf(xtsr,'%f',numel); end % finished reading file fclose(xtsr); disp('Use profile4 or t_series4 to look at the constituent data')