0001 function [log_text,zPathName,zFileName] = ASCII2KML(inpath,infile)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 current_file = fullfile(inpath,infile);
0018 [zFileName,zPathName] = uigetfile({'*_ASC.TXT','ASCII (*_ASC.TXT)'}, ...
0019 'Convert WRII ASCII output file(s) to KML: Select the ASCII Output Files', ...
0020 current_file, ...
0021 'MultiSelect','on');
0022 if ~ischar(zFileName) && ~iscell(zFileName)
0023 log_text = {};
0024 zPathName = inpath;
0025 zFileName = infile;
0026 return
0027 end
0028
0029
0030 if isa(zFileName,'cell')
0031 z=size(zFileName,2);
0032 zFileName=sort(zFileName);
0033 else
0034 z=1;
0035 zFileName={zFileName}
0036 end
0037
0038
0039
0040
0041
0042
0043 log_text = {...
0044 'Writing KML Files to directory:';
0045 zPathName};
0046 wbh = waitbar(0,'Writing KML Files...Please Be Patient');
0047 for zi=1:z
0048
0049 if isa(zFileName,'cell')
0050 fileName=strcat(zPathName,filesep,zFileName(zi));
0051 fileName=char(fileName);
0052 else
0053 fileName=strcat(zPathName,zFileName);
0054 end
0055
0056
0057 screenData=1;
0058
0059
0060
0061
0062
0063
0064
0065
0066 ignoreBS = 0;
0067 [A(zi)]=tfile(fileName,screenData,ignoreBS);
0068
0069 latlon(:,1)=A(zi).Nav.lat_deg(:,:);
0070 latlon(:,2)=A(zi).Nav.long_deg(:,:);
0071
0072
0073 indx1 = find(abs(latlon(:,1)) > 90);
0074 indx2 = find(abs(latlon(:,2)) > 180);
0075 latlon(indx1,1)=NaN;
0076 latlon(indx2,2)=NaN;
0077
0078 indx3 = find(~isnan(latlon(:,1)) & ~isnan(latlon(:,2)));
0079 latlon = latlon(indx3,:);
0080
0081 clear A
0082
0083
0084 idx=strfind(fileName,'.');
0085 namecut = fileName(1:idx(end)-5);
0086
0087
0088
0089 pwr_kml(namecut,latlon);
0090
0091 clear latlon idx namecut
0092 waitbar(zi/z);
0093 end
0094 delete(wbh)
0095 msgbox('Conversion Complete','Conversion Status','help','replace');
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105 function pwr_kml(name,latlon)
0106
0107
0108
0109
0110 header=['<kml xmlns="http://earth.google.com/kml/2.0"><Placemark><description>"' name '"</description><LineString><tessellate>1</tessellate><coordinates>'];
0111 footer='</coordinates></LineString></Placemark></kml>';
0112
0113 fid = fopen([name 'ShipTrack.kml'], 'wt');
0114 d=flipud(rot90(fliplr(latlon)));
0115 fprintf(fid, '%s \n',header);
0116 fprintf(fid, '%.6f,%.6f,0.0 \n', d);
0117 fprintf(fid, '%s', footer);
0118 fclose(fid);
0119