MATLAB scares me - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

MATLAB scares me

JMCOL123JMCOL123 Posts: 1Member
Hi Guys,

I've got a bit of a problem in MATLAB.
I'll try to explain this as best I can but if you have any queries then please ask.

So... I've downloaded some information from the Hi-Flows/FEH website (all about rivers and flooding) and I've used MATLAB in conjunction with this information to put it into a more readable format in Excel.
I want to find values for Q (flow) but I cannot find an equation for it. I have been told that the values for Q are a part of the information downloaded from the FEH website but are not coming out in the excel file because it hasn't been put into MATLAB. I tried to do it but I'm assuming I need to use the correct 'name' for Q for it to come out but I don't know it.
Below is the MATLAB file I'm using:
% readFEH converts FEH .CD2 files into a spreadsheet
% and calculates the QMED from the .AM files

clear;

fprintf('Running FEH data file convertor...
');

% Select FEH file types to read (1 to select, 0 to omit):
% CD2
CD=1;
% AM
AM=1;
% PT - not implemented in this script
PT=0;

% Name of output file
FEH_output_name = 'FEH data';

% Starting station number (lower)
gauge_start_num = 43001;

% End station number (upper)
gauge_end_num = 53028;

num_gauges = gauge_end_num - gauge_start_num + 1;

% Open output spreadsheet
FEH_output_file = strcat(FEH_output_name,'.xls');
fid_out = fopen(FEH_output_file,'w');
fprintf(fid_out,'Station Catchment Gauge Nominal Area Nominal NGR DTM NGR DTM Area ALTBAR ');
fprintf(fid_out,'ASPBAR ASPVAR BFIHOST DPLBAR DPSBAR FARL LDP PROPWET RMED-1H RMED-1D RMED-2D ');
fprintf(fid_out,'SAAR SAAR4170 SPRHOST URBCONC1990 URBEXT1990 URBLOC1990 URBCONC2000 URBEXT2000 ');
fprintf(fid_out,'URBLOC2000n Suitable for QMED Suitable for Pooling ');
fprintf(fid_out,'Station Description Catchment Description QMED Record Length');
for i = 1:num_gauges
station = gauge_start_num + i - 1;
if CD == 1
file_name = int2str(station);
CD_filename = strcat(file_name, '.CD2');
% Read FEH .CD2 text file
if exist(CD_filename)==2
fprintf('%s
',CD_filename);
fid_in = fopen(CD_filename);
% read 5 header lines
for j = 1:5
dump_text = fgets(fid_in);
end
% read station number
stn = str2num(fgets(fid_in));
fprintf(fid_out,'
%d ',stn);
dump_text = fgets(fid_in);
dump_text = fgets(fid_in);
% read catchment name
status = fseek(fid_in,5,'cof');
catchment = fgetl(fid_in);
fprintf(fid_out,'%s ',catchment);
% read gauge location
status = fseek(fid_in,9,'cof');
location = fgetl(fid_in);
fprintf(fid_out,'%s ',location);
% read nominal area
status = fseek(fid_in,13,'cof');
nom_area = str2double(fgets(fid_in));
fprintf(fid_out,'%12.5f ',nom_area);
% read nominal NGR
status = fseek(fid_in,12,'cof');
nom_ngr = fgetl(fid_in);
fprintf(fid_out,'%s ',nom_ngr);
dump_text = fgets(fid_in);
dump_text = fgets(fid_in);
% read IHDTM NGR
status = fseek(fid_in,13,'cof');
ihdtm_ngr = fgetl(fid_in);
fprintf(fid_out,'%s ',ihdtm_ngr);
% read DTM area
status = fseek(fid_in,9,'cof');
dtm_area = str2double(fgets(fid_in));
fprintf(fid_out,'%12.5f ',dtm_area);
% read ALTBAR
status = fseek(fid_in,7,'cof');
alt_bar = str2double(fgets(fid_in));
fprintf(fid_out,'%12.5f ',alt_bar);
% read ASPBAR
status = fseek(fid_in,7,'cof');
asp_bar = str2double(fgets(fid_in));
fprintf(fid_out,'%12.5f ',asp_bar);
% read ASPVAR
status = fseek(fid_in,7,'cof');
asp_var = str2double(fgets(fid_in));
fprintf(fid_out,'%12.5f ',asp_var);
% read BFIHOST
status = fseek(fid_in,8,'cof');
bfi_host = str2double(fgets(fid_in));
fprintf(fid_out,'%12.5f ',bfi_host);
% read DPLBAR
status = fseek(fid_in,7,'cof');
dpl_bar = str2double(fgets(fid_in));
fprintf(fid_out,'%12.5f ',dpl_bar);
% read DPSBAR
status = fseek(fid_in,7,'cof');
dps_bar = str2double(fgets(fid_in));
fprintf(fid_out,'%12.5f ',dps_bar);
% read FARL
status = fseek(fid_in,5,'cof');
farl = str2double(fgets(fid_in));
fprintf(fid_out,'%12.5f ',farl);
% read LDP
status = fseek(fid_in,4,'cof');
ldp = str2double(fgets(fid_in));
fprintf(fid_out,'%12.5f ',ldp);
% read PROPWET
status = fseek(fid_in,8,'cof');
prop_wet = str2double(fgets(fid_in));
fprintf(fid_out,'%12.5f ',prop_wet);
% read RMED-1H
status = fseek(fid_in,8,'cof');
rmed_1h = str2double(fgets(fid_in));
fprintf(fid_out,'%12.5f ',rmed_1h);
% read RMED-1D
status = fseek(fid_in,8,'cof');
rmed_1d = str2double(fgets(fid_in));
fprintf(fid_out,'%12.5f ',rmed_1d);
% read RMED-2D
status = fseek(fid_in,8,'cof');
rmed_2d = str2double(fgets(fid_in));
fprintf(fid_out,'%12.5f ',rmed_2d);
% read SAAR
status = fseek(fid_in,5,'cof');
saar = str2double(fgets(fid_in));
fprintf(fid_out,'%12.5f ',saar);
% read SAAR4170
status = fseek(fid_in,9,'cof');
saar_4170 = str2double(fgets(fid_in));
fprintf(fid_out,'%12.5f ',saar_4170);
% read SPRHOST
status = fseek(fid_in,8,'cof');
spr_host = str2double(fgets(fid_in));
fprintf(fid_out,'%12.5f ',spr_host);
% read URBCONC1990
status = fseek(fid_in,12,'cof');
urb_conc_1990 = str2double(fgets(fid_in));
fprintf(fid_out,'%12.5f ',urb_conc_1990);
% read URBEXT1990
status = fseek(fid_in,11,'cof');
urb_ext_1990 = str2double(fgets(fid_in));
fprintf(fid_out,'%12.5f ',urb_ext_1990);
% read URBLOC1990
status = fseek(fid_in,11,'cof');
urb_loc_1990 = str2double(fgets(fid_in));
fprintf(fid_out,'%12.5f ',urb_loc_1990);
% read URBCONC2000
status = fseek(fid_in,12,'cof');
urb_conc_2000 = str2double(fgets(fid_in));
fprintf(fid_out,'%12.5f ',urb_conc_2000);
% read URBEXT2000
status = fseek(fid_in,11,'cof');
urb_ext_2000 = str2double(fgets(fid_in));
fprintf(fid_out,'%12.5f ',urb_ext_2000);
% read URBLOC2000
status = fseek(fid_in,11,'cof');
urb_loc_2000 = str2double(fgets(fid_in));
fprintf(fid_out,'%12.5f ',urb_loc_2000);
dump_text = fgets(fid_in);
dump_text = fgets(fid_in);
% read QMED suitability
status = fseek(fid_in,5,'cof');
QMED_yes = fgetl(fid_in);
fprintf(fid_out,'%s ',QMED_yes);
% read POOLING suitability
status = fseek(fid_in,8,'cof');
POOLING_yes = fgetl(fid_in);
fprintf(fid_out,'%s ',POOLING_yes);
dump_text = fgets(fid_in);
dump_text = fgets(fid_in);
% read station description
status = fseek(fid_in,8,'cof');
stn_desc = fgetl(fid_in);
fprintf(fid_out,'%s ',stn_desc);
% read catchment description
status = fseek(fid_in,10,'cof');
catch_desc = fgetl(fid_in);
fprintf(fid_out,'%s',catch_desc);
status = fclose(fid_in);
end
end
if AM == 1
AM_filename = strcat(file_name, '.AM');
% Read FEH .AM text file
if exist(AM_filename)==2
fprintf('%s
',AM_filename);
fid_in1 = fopen(AM_filename);
m = 0;
% Check for start and end records of AMS in AM file
while feof(fid_in1) == 0
m = m + 1;
AM_read = fgetl(fid_in1);
if (strcmp('[AM Values]', AM_read))
upperlim = m;
end
lowerlim = m;
end
status = fclose(fid_in1);
fid_in2 = fopen(AM_filename);
% read upperlim header lines
for j = 1:upperlim
dump_text = fgets(fid_in2);
end
% read AMS
num_ams = 1;
for n = (upperlim+1):(lowerlim-1)
ams_data(num_ams) = textscan(fid_in2, '%*s %*s %*s %9.3f %*s %*s', 1);
num_ams = num_ams + 1;
end
rec_length = num_ams - 1;
% Convert cell array to numeric array
for p = 1:rec_length
ams_values(p) = ams_data{p};
end
% Read no. of AMS values to match record length
% and avoid re-using AMS values from previous
% station when calculating median
ams = ams_values(1:rec_length);
status = fclose(fid_in2);
% Calculate QMED
qmed = median(ams);
fprintf(fid_out,' %12.5f ',qmed);
fprintf(fid_out,'%d',rec_length);
end
end
if PT == 1
% Read FEH .PT text file - not implemented yet
PT_filename = strcat(file_name, '.PT');
end
end

status = fclose(fid_out);

fprintf('run completed
');

Any help would be greatly appreciated.
Thanks

Sign In or Register to comment.