code to read BUFKIT formatted model data

5 views (last 30 days)
I need to write code to read in BUFKIT formatted text files for GFS weather model output. I'm kind of surprised there's not a tool out there already, but days of searching has found nothing. I've found some python tools.....but I figured I could write some code quicker than getting that set up. But that's proving to be time consuming also. Anyway, an example of the format is here:
SNPARM = PRES;TMPC;TMWC;DWPC;THTE;DRCT;SKNT;OMEG;HGHT
STNPRM = SHOW;LIFT;SWET;KINX;LCLP;PWAT;TOTL;CAPE;LCLT;CINS;EQLV;LFCT;BRCH
STID = XMR STNM = 747940 TIME = 220101/0000
SLAT = 28.47 SLON = -80.55 SELV = 3.0
STIM = 0
SHOW = 7.09 LIFT = 1.45 SWET = 115.26 KINX = 12.49
LCLP = 976.23 PWAT = 28.84 TOTL = 36.49 CAPE = 133.62
LCLT = 292.62 CINS = -214.76 EQLV = 251.06 LFCT = 455.21
BRCH = 11.15
PRES TMPC TMWC DWPC THTE DRCT SKNT OMEG
HGHT
1018.50 23.04 21.08 20.16 337.22 129.81 6.06 -0.02
3.00
1013.30 23.04 20.81 19.76 336.89 133.99 7.83 -0.07
47.77
1007.50 22.94 20.43 19.24 336.23 140.91 8.00 -0.09
97.96
1001.00 22.94 20.04 18.65 335.64 145.12 7.81 -0.10
154.52
993.60 22.84 19.63 18.06 335.09 155.56 7.03 -0.13
219.34
985.50 22.84 19.25 17.48 334.82 176.19 5.85 -0.12
290.82
976.30 22.54 18.82 16.95 334.49 196.50 5.48 -0.10
372.66
966.10 21.94 18.36 16.53 334.23 214.82 5.44 -0.08
464.15
954.80 21.04 17.85 16.20 333.99 225.00 5.50 -0.02
566.37
942.30 19.94 17.27 15.86 333.69 232.31 5.40 0.04
680.47
928.40 18.74 16.53 15.34 333.08 239.74 5.40 0.11
808.63
...
The "STID =" part repeats 140 times, for each model valid time. And yes...the data "table" wraps with the "HGHT" variable......don't ask me why.
I've tried attacking this with fileread.m and readlines.m.....but then kind of stuck there on the best way to parse the data out. I'm not super familar with regexp, so wondering if that would be the quickest/easiest way to go, or use something like strsplit.
Really hoping someone else has tackled this, and can point me in a good direction.
Thanks in advance.

Accepted Answer

Mathieu NOE
Mathieu NOE on 22 May 2023
hello
this can be a simple wrapper to get your data
D=readlines('data.txt'); % read as string array
ixP1=find(contains(D,'HGHT')); % find the HGHT line sections
eof = numel(D);
% get first the long lines data corresponding to PRES TMPC TMWC DWPC THTE DRCT SKNT OMEG
n = 0;
for k=ixP1(end)+1:2:eof
n = n +1;
out1(n,:)=str2double(split(D(k)))';
end
% then get the short lines data corresponding to HGHT
n = 0;
for k=ixP1(end)+2:2:eof
n = n +1;
out2(n,:)=str2double(split(D(k)))';
end
% horizontal concatenation
Out = [out1 out2];
  3 Comments
Mathieu NOE
Mathieu NOE on 23 May 2023
My pleasure !
do you mind accepting my answer ?
tx !
Frank
Frank on 23 May 2023
Edited: Frank on 23 May 2023
ok...can do.
I will say the code didn't completely work...it didn't account for the repeating of the table. Putting "ixP1(end)" in the for loop takes it to the last stacked table. But I was able to manipulate a bit, and got it to work.
Thanks again!

Sign in to comment.

More Answers (0)

Categories

Find more on Data Import and Export in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!