% ler formato GSI (Leica)

clear all; close all

ficheiro_gsi='lev-2016-04-04.gsi';

fid1=fopen(ficheiro_gsi, 'r');
ponto=cell(1000,6);
k=0;
while ~feof(fid1)
    tline = fgets(fid1);
    k=k+1;
    ponto{k,1}=cellstr(tline(11:15));
    ponto{k,2}=cellstr(tline(24:31));
    direcao(k)=str2double(ponto{k,2})/100000;
    
    ponto{k,3}=cellstr(tline(40:47));
    zenital(k)=str2double(ponto{k,3})/100000;
    
    ponto{k,4}=cellstr(tline(56:63));
    distInc(k)=str2double(ponto{k,4})/1000;
    
    ponto{k,5}=cellstr(tline(88:95));
    hAlvo(k)=str2double(ponto{k,5})/1000;
    
    ponto{k,6}=cellstr(tline(104:111));
    hEstacao(k)=str2double(ponto{k,6})/1000;
          
end
k
fclose(fid1);


ficheiro_gsi='lev-2016-04-04.txt';

fid1=fopen(ficheiro_gsi, 'w');

for i=1:k
   a = char(ponto{i,1});
   fprintf(fid1,'%2s %12.4f %12.4f %12.4f %8.3f %8.3f\n',a,direcao(i), zenital(i), distInc(i), hAlvo(i), hEstacao(i)); 
 end
fclose(fid1);




