Using Textscan to read Sinex file rows with variable delimiters
2 ビュー (過去 30 日間)
古いコメントを表示
Hi Everyone,
I'm having trouble with reading a block of text from a sinex file, where the general delimiter seems to be a space but then there are two columns where this is changeable.
+SITE/ID
*CODE PT __DOMES__ T _STATION DESCRIPTION__ APPROX_LON_ APPROX_LAT_ _APP_H_
7835 A 10002S001 L Grasse, France 6 55 16.0 43 45 16.8 1322.8
7845 A 10002S002 L Grasse CDP7845 6 55 17.6 43 45 16.6 1323.3
7848 A 10077M002 L Ajaccio 8 45 45.7 41 55 38.6 97.3
7805 A 10503S001 L Metsahovi, Finland 24 23 40.3 60 13 02.3 78.2
7806 A 10503S014 L Metsahovi, Finland 24 23 40.3 60 13 01.7 74.0
7839 A 11001S002 L Graz, fixed 15 29 36.0 47 04 01.6 539.4
.
.
.
98 lines total
-SITE/ID
*
For example the station_description column has a comma in between the strings 'Grasse' and 'France', then a space between the second row 'Grasse' and 'CDP7845' and the third ends on a delimiter. I have tried using %q, collectoutput and multipledelimsasone,delims: ' ' and {' ',','} to read the lines but it seems to either stop at the first delimiter on line 1 before France, or just skip the word Ajaccio completely. The next issue is then reading the long/lat as one float effectively and I'd like to end up with two columns, one for the lat and one for long so I can use for plotting later.
The code I am currently using below: positions(2) - positions(1) is the end-start positions from my searcher that finds and points to the block within the sinex file. That works fine.
Code:
location_import = textscan(fileID(1),'%d %c %q %c %s %s',...
positions(2)-positions(1),'Delimiter',' ','MultipleDelimsAsOne',true);
Current Output:
79x1 int32 79x1 char 79x1 cell 79x1 char 79x1 cell 79x1 cell
7835 'A' 1002S001 'L' Grasse, France
6 '5' 5 '1' 6.0 43
45 '1' 6.8 '1' 322.8
7845 'A' 10002S002 'L' Grasse CDP7845
6 '5' 5 '1' 7.6 43
45 '1' 6.6 '1' 323.3
7848 'A' 10077M002 'L' Ajaccio 8
I just cant figure out the textscan command I need to get it to work, especially for the station_description formatting changes. Any help would be massively appreciated so I can learn from this.
Thanks very much!
0 件のコメント
採用された回答
Stephen23
2021 年 12 月 31 日
編集済み: Stephen23
2021 年 12 月 31 日
This is a fixed-width file, especially e.g. the presence of space characters in the location names indicates this. The header underscores also seem to be used to indicate the fieldwidths. You could probably use READTABLE's fixed-width options to import it.
"The next issue is then reading the long/lat as one float effectively and I'd like to end up with two columns, one for the lat and one for long"
The long/lat each consist of three values, not one, so you will have a total of six columns, not two. If you keep the values as text then you could have two columns, but this would make processing/plotting them harder.
opt = {'MultipleDelimsAsOne',true, 'CollectOutput',true, 'HeaderLines',2};
fmt = '%d%s%d%s%22c%f%f%f%f%f%f%f';
fid = fopen('test.txt','rt');
tmp = textscan(fid,fmt,opt{:})
fclose(fid);
format short G
tmp{:}
Convert Longitude and Latitude into degrees (e.g. for plotting):
format long G
lon = tmp{6}(:,1:3) * [1;1/60;1/60/60] % longitude
lat = tmp{6}(:,4:6) * [1;1/60;1/60/60] % latitude
or into seconds:
lon = tmp{6}(:,1:3) * [60*60;60;1]
0 件のコメント
その他の回答 (1 件)
参考
カテゴリ
Help Center および File Exchange で Data Import and Export についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!