function data = aprs2csv(filename)

% read the file
str = fileread(filename);

% determine the callsign
callsign = filename(1:min([findstr(filename,'.') findstr(filename,'-')])-1)

% regex pattern to extract info
regex_pattern = ['(?<date>[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}).*?' ...
    'latitude: (?<lat>[+-]*\d*\.\d*).*?longitude: (?<lng>[+-]*\d*\.\d*).*?altitude: (?<alt>[+-]*\d*\.*\d*)'];

% extract the data
pkts = regexp(str,regex_pattern,'Names');

% initalize data
data.callsign = callsign;
data.lat = [];
data.lng = [];
data.alt = [];
data.time = [];

% convert to arrays
for i=1:size(pkts,2)
    data.lat = [data.lat; str2double(pkts(i).lat)];
    data.lng = [data.lng; str2double(pkts(i).lng)];
    data.alt = [data.alt; str2double(pkts(i).alt)];
    data.time = [data.time; datenum(pkts(i).date)];
end

% [callsign '.csv']

% open file
fileID = fopen([callsign '.csv'],'w');
    
% write header
fprintf(fileID,'time, lat [deg], lng [deg], alt [m]\n');

% write data
for i=1:size(pkts,2)
    fprintf(fileID,'%s,%f,%f,%f\n',datestr(data.time(i),'yyyy-mm-dd HH:MM:SS'),data.lat(i),data.lng(i),data.alt(i));
end

fclose(fileID);
% plot(data.lng,data.lat)
% figure()
% plot(data.time,data.alt)
% dynamicDateTicks()