function [bathStruct] = readELCOMbathy(filename) % function [bathStruct] = writeELCOMbathy(filename) % % Inputs: % filename : filename of bathymetry file % Outputs % bathStruct : a matlab structure that contains all the data in the file % to rewrite this file use writeELCOMbathy % % Uses: % line2strs.m % isF90comment.m % % Written by C. Dallimore 31 August 04 % % Open file fid = fopen(filename,'r'); x_count = 0; y_count = 0; z_count = 0; % Read file until end eof = 0; bathStruct.dx = []; bathStruct.dy = []; while (~eof) oneline = fgetl(fid); if (isempty(oneline)) elseif (oneline == -1) eof = 1; % Skip all comments lines elseif (~isF90comment(oneline)) % Break each line up into strings words=line2strs(oneline); % each line should have at least two words if (length(words) > 1) word1 = char(words(1)); word2 = char(words(2)); % process according to type % Fist word keyword if (~isempty(findstr(word1,'FILE'))) bathStruct.file = word2; elseif (~isempty(findstr(word1,'VERSION'))) bathStruct.version = word2; % Second word keyword first word elseif (~isempty(findstr(word2,'TITLE'))) bathStruct.title = word1; elseif (~isempty(findstr(word2,'ANALYST'))) bathStruct.analyst = word1; elseif (~isempty(findstr(word2,'ORGANIZATION'))) bathStruct.organization = word1; elseif (~isempty(findstr(word2,'COMMENT'))) bathStruct.comment = word1; elseif (~isempty(findstr(word2,'overwrite'))) bathStruct.overwrite = word1; % Second word keyword first word number elseif (~isempty(findstr(word2,'x_rows'))) bathStruct.x_rows = str2num(word1); elseif (~isempty(findstr(word2,'y_columns'))) bathStruct.y_columns = str2num(word1); elseif (~isempty(findstr(word2,'z_layers'))) bathStruct.z_layers = str2num(word1); elseif (~isempty(findstr(word2,'n_max'))) bathStruct.n_max = str2num(word1); elseif (~isempty(findstr(word2,'land_value'))) bathStruct.land_value = str2num(word1); elseif (~isempty(findstr(word2,'open_value'))) bathStruct.open_value = str2num(word1); elseif (~isempty(findstr(word2,'north_x'))) bathStruct.north_x = str2num(word1); elseif (~isempty(findstr(word2,'north_y'))) bathStruct.north_y = str2num(word1); elseif (~isempty(findstr(word2,'true_north_x'))) bathStruct.true_north_x = str2num(word1); elseif (~isempty(findstr(word2,'true_north_y'))) bathStruct.true_north_y = str2num(word1); elseif (~isempty(findstr(word2,'x_grid'))) bathStruct.x_grid = str2num(word1); elseif (~isempty(findstr(word2,'y_grid'))) bathStruct.y_grid = str2num(word1); elseif (~isempty(findstr(word2,'dz'))) z_count = z_count + 1; bathStruct.dz(z_count) = str2num(word1); elseif (~isempty(findstr(word2,'dx'))) x_count = x_count + 1; bathStruct.dx(x_count) = str2num(word1); elseif (~isempty(findstr(word2,'dy'))) y_count = y_count + 1; bathStruct.dy(y_count) = str2num(word1); elseif (~isempty(findstr(word2,'latitude'))) bathStruct.latitude = str2num(word1); elseif (~isempty(findstr(word2,'longitude'))) bathStruct.longitude = str2num(word1); elseif (~isempty(findstr(word2,'altitude'))) bathStruct.altitude = str2num(word1); % Data elseif (~isempty(findstr(word2,'DATA'))) % BATHYMETRY if (~isempty(findstr(word1,'BATHYMETRY'))) for i=1:bathStruct.x_rows for j=1:bathStruct.y_columns bathStruct.bathData(i,j) = fscanf(fid,'%f',1); end end else disp ('Aux data not processed') return; end else disp ('Error unknown lineformat') oneline end end end end