% ----------------------------------------------------------------------- %
% Author: Mireia Leon Dasi
% European Space Agency - ESAC
% Last modified: 13/08/2020
% Description: matlab script to read ellipses from SBMT files and write the
% latitude and longitude coordinates to excel file
% ----------------------------------------------------------------------- %

clc; clear all; close all;

% Add savepaths
%save_path='';

% MODIFY input/output files IDs
Input_file = 'Bright_Patches';
Output_file = 'Bright_Patches.xlsx';
table_path_format = [save_path, Output_file];

% Open and read Input file
fid = fopen(Input_file);
data = textscan(fid,'%d%s%f%f%f%f%f%f%f%f%f%f%f%f%f%s%s%s');
fclose(fid);

% Extract latitude, longitude, diameter, eccentricity
ID = data{2};
lat = round(data{6},4);
long = round(data{7},4);
slope = round(data{9},4);
grav = round(data{12},8);
D = round(data{13}*1000);
Ecc = data{14};

for i = 1:length(lat)
latlong{i,1} =  sprintf('( %.2f , %.2f )', lat(i),long(i));
end

% Create table with variables
T = table(ID,lat,long,latlong,D,Ecc,slope,grav);

% Write data to Excel file
writetable(T,table_path_format,'Sheet',1,'Range','B2')