% ler formato GSI (Leica)

clear all; close all

ficheiro_gsi='F:\IPA\Escola\3º ano\2º Semestre\Projeto de Engenharia Geoespacial\pontos_23_3\Jobs\PONTOS\G02.GSI';
ficheiro_gsi_out='F:\IPA\Escola\3º ano\2º Semestre\Projeto de Engenharia Geoespacial\pontos_23_3\tabela.txt';

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(22:24));
    ponto{k,2}=cellstr(tline(34:49));
    direcao(k)=str2double(ponto{k,2})/100000;
    
    ponto{k,3}=cellstr(tline(58:73));
    zenital(k)=str2double(ponto{k,3})/100000;
    
    ponto{k,4}=cellstr(tline(82:97));
    distInc(k)=str2double(ponto{k,4})/1000;
    
    ponto{k,5}=cellstr(tline(130:145));
    hAlvo(k)=str2double(ponto{k,5})/1000;
    
% O formato de saida não contempla a altura do instrumento
%     ponto{k,6}=cellstr(tline(104:111));
%     hEstacao(k)=str2double(ponto{k,6})/1000;
          
end
k
fclose(fid1);



fid1=fopen(ficheiro_gsi_out, 'w');
fprintf(fid1,'Nome, Direcao, zenital, distInc, hAlvo\n'); 
for i=1:k
   a = char(ponto{i,1});
   fprintf(fid1,'%2s, %12.4f, %12.4f, %12.4f, %8.3f\n',a,direcao(i), zenital(i), distInc(i), hAlvo(i)); 
 end
fclose(fid1);




