0001 function SontekMAT2KML(varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 nVar = numel(varargin);
0014 if nVar == 2
0015 inpath = varargin{1};
0016 infile = varargin{2};
0017 elseif nVar == 1
0018 if strcmpi('-help',varargin{1})
0019
0020 HelpTxt = {...
0021 'Creates KML of ADCP shiptracks for Sontek RSL v3.60 MAT-files';...
0022 '';...
0023 'INPUTS';...
0024 ' inputfilepath: full path to the directory containing RSL';...
0025 ' MAT-files';...
0026 ' inputfiles: name(s) of the RiverSurveyorLive MAT-file';...
0027 '';...
0028 'OUTPUTS';...
0029 ' KML file with the same name as the inputfile(s)';...
0030 '';...
0031 'SUMMARY';...
0032 ' This program reads in a Sontek RiverSurveyLive ENU MAT-file';...
0033 ' or files and outputs the GPS position into a KML file which';...
0034 ' can be displayed in Google Earth.';...
0035 '';...
0036 'EXAMPLES';...
0037 ' Load a MAT-file of ENU Bottom Track ADCP data produced in';...
0038 ' RiverSurveryorLive v3.60 to produce a KML file of the';...
0039 ' shiptrack.';...
0040 ' SontekMAT2KML <path> <filename.mat>';...
0041 '';...
0042 ' To make the program prompt for files, specify NO arguments:';...
0043 ' SontekMAT2KML';...
0044 '';...
0045 ' Display this help.';...
0046 ' SontekMAT2KML -help';
0047 '';...
0048 'Original code concept by Jon Czuba, modified by P.R. Jackson';...
0049 'for use in VMT (TDRI ASCII support).';...
0050 'Created by: Frank L. Engel, USGS';...
0051 'Last modified: 2014/05/30';
0052 };
0053 disp(HelpTxt)
0054 return
0055 else
0056 error('Incorrect number of input arguments or invalid switch')
0057 end
0058 elseif nVar == 0
0059 inpath = [];
0060 infile = [];
0061 else
0062 error('Incorrect number of input arguments or invalid switch')
0063 end
0064
0065
0066
0067
0068
0069 if ~isempty(inpath) && ~isempty(infile)
0070 current_file = fullfile(inpath,infile);
0071 else
0072 current_file = pwd;
0073 end
0074 [zFileName,zPathName] = uigetfile({'*.mat','RSL-MAT (*.mat)'}, ...
0075 'Convert RSL MAT-file(s) to KML: Select the RSL MAT Output Files', ...
0076 current_file, ...
0077 'MultiSelect','on');
0078 if ~ischar(zFileName) && ~iscell(zFileName)
0079 log_text = {};
0080 zPathName = inpath;
0081 zFileName = infile;
0082 return
0083 end
0084
0085
0086 if isa(zFileName,'cell')
0087 z=size(zFileName,2);
0088 zFileName=sort(zFileName);
0089 else
0090 z=1;
0091 zFileName={zFileName}
0092 end
0093
0094
0095
0096
0097
0098
0099 log_text = {...
0100 'Writing KML Files to directory:';
0101 zPathName};
0102 wbh = waitbar(0,'Writing KML Files...Please Be Patient');
0103 for zi=1:z
0104
0105 if isa(zFileName,'cell')
0106 fileName=strcat(zPathName,filesep,zFileName(zi));
0107 fileName=char(fileName);
0108 else
0109 fileName=strcat(zPathName,zFileName);
0110 end
0111 load(fileName)
0112
0113
0114 latlon(:,1)=GPS.Latitude(:);
0115 latlon(:,2)=GPS.Longitude(:);
0116
0117
0118 indx1 = find(abs(latlon(:,1)) > 90);
0119 indx2 = find(abs(latlon(:,2)) > 180);
0120 latlon(indx1,1)=NaN;
0121 latlon(indx2,2)=NaN;
0122
0123 indx3 = find(~isnan(latlon(:,1)) & ~isnan(latlon(:,2)));
0124 latlon = latlon(indx3,:);
0125
0126 clear BottomTrack GPS Processing RawGPSData Setup Summary System Transformation_Matrices WaterTrack
0127
0128
0129 [~,namecut,~] = fileparts(fileName);
0130 namecut = [zPathName namecut];
0131
0132
0133
0134 pwr_kml(namecut,latlon);
0135
0136 clear latlon idx namecut
0137 waitbar(zi/z);
0138 end
0139 delete(wbh)
0140 msgbox('Conversion Complete','Conversion Status','help','replace');
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153 function pwr_kml(name,latlon)
0154
0155
0156
0157
0158 header=['<kml xmlns="http://earth.google.com/kml/2.0"><Placemark><description>"' name '"</description><LineString><tessellate>1</tessellate><coordinates>'];
0159 footer='</coordinates></LineString></Placemark></kml>';
0160
0161 fid = fopen([name 'ShipTrack.kml'], 'wt');
0162 d=flipud(rot90(fliplr(latlon)));
0163 fprintf(fid, '%s \n',header);
0164 fprintf(fid, '%.6f,%.6f,0.0 \n', d);
0165 fprintf(fid, '%s', footer);
0166 fclose(fid);
0167