Find the desirable string and read data below them

1 回表示 (過去 30 日間)
Miguel Cardoso
Miguel Cardoso 2019 年 3 月 23 日
コメント済み: Miguel Cardoso 2019 年 3 月 23 日
I just started working in my master thesis with SPR-KKR and I need to get the XC-coupling constants J_ij [eV]. I would like to create a script where I could get out each value of DR, J_ij [Ry] and J_ij [eV]. My main problem is that those strings repeat, they appear always above a new value. Below, I leave a small example how the output file is, although the full output file example is attached.
*******************************************************************************
<XCPLJIJ>
XC-coupling constants J_ij
*******************************************************************************
IQ = 1 IT = 1 JQ = 2 JT = 2
->Q = ( 0.289, 0.500, 0.403) ->Q = ( 0.577, 1.000, -0.403)
ITAUIJ ITAUJI N1 N2 N3 DRX DRY DRZ DR J_ij [Ry] J_ij [eV]
117 194 0 -1 0 0.289 -0.500 -0.806 0.992 0.001122 0.015261
IQ = 1 IT = 1 JQ = 2 JT = 2
->Q = ( 0.289, 0.500, 0.403) ->Q = ( 0.577, 1.000, -0.403)
ITAUIJ ITAUJI N1 N2 N3 DRX DRY DRZ DR J_ij [Ry] J_ij [eV]
101 210 -1 -1 0 -0.577 0.000 -0.806 0.992 0.001122 0.015261
IQ = 1 IT = 1 JQ = 2 JT = 2
->Q = ( 0.289, 0.500, 0.403) ->Q = ( 0.577, 1.000, -0.403)
ITAUIJ ITAUJI N1 N2 N3 DRX DRY DRZ DR J_ij [Ry] J_ij [eV]
121 190 0 0 0 0.289 0.500 -0.806 0.992 0.001122 0.015261

採用された回答

dpb
dpb 2019 年 3 月 23 日
編集済み: dpb 2019 年 3 月 23 日
function data=readTAUIJ(file)
MAGIC_LINE_1='<INIT_MOD_TAUIJ_STAR>';
MAGIC_LINE_2='<XCPLJIJ>';
fid=fopen(file,'r');
% find number elements to read
while ~contains(fgetl(fid),MAGIC_LINE_1), end
N=cell2mat(textscan(fid,'number of TAU(I,J)''s to be calculated: %f','headerlines',2));
while ~contains(fgetl(fid),MAGIC_LINE_2), end
for i=1:4,fgetl(fid);end
data=cell(N,1);
for i=1:N
data(i)=textscan(fid,repmat('%f',1,11),'headerlines',3,'collectoutput',1);
end
fid=fclose(fid);
data=cell2mat(data);
end
  4 件のコメント
dpb
dpb 2019 年 3 月 23 日
編集済み: dpb 2019 年 3 月 23 日
No problem...it's entertainment and teaching...just remember the acknowledgement in the thesis... <VBG>
BTW: As "exercise for Student", look at reading the variable name header line before one of the data sections and then creating a table using those names instead of just the data array. Going forward with the thesis code work, that could be a much more maintainable approach.
Miguel Cardoso
Miguel Cardoso 2019 年 3 月 23 日
I won't forget! Now it's clear for me to interpret the data. Looks easy. Thank you once again.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by