Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8513017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:26:20+00:00 2026-06-11T04:26:20+00:00

I have this txt file: BLOCK_START_DATASET dlcdata L:\loads\confidential\000_Loads_Analysis_Environment\Tools\releases\01_Preprocessor\Version_3.0\Parameterfiles\Bladed4.2\DLC-Files\DLCDataFile.txt simulationdata L:\loads\confidential\000_Loads_Analysis_Environment\Tools\releases\01_Preprocessor\Version_3.0\Parameterfiles\Bladed4.2\DLC-Files\BladedFile.txt outputfolder Pfadangabe\runs_test windfolder L:\loads2\WEC\1002_50-2\_calc\50-2_D135_HH95_RB-AB66-0O_GL2005_towerdesign_Bladed_v4-2_revA01\_wind

  • 0

I have this txt file:

BLOCK_START_DATASET

dlcdata                 L:\loads\confidential\000_Loads_Analysis_Environment\Tools\releases\01_Preprocessor\Version_3.0\Parameterfiles\Bladed4.2\DLC-Files\DLCDataFile.txt
simulationdata          L:\loads\confidential\000_Loads_Analysis_Environment\Tools\releases\01_Preprocessor\Version_3.0\Parameterfiles\Bladed4.2\DLC-Files\BladedFile.txt

outputfolder    Pfadangabe\runs_test
windfolder      L:\loads2\WEC\1002_50-2\_calc\50-2_D135_HH95_RB-AB66-0O_GL2005_towerdesign_Bladed_v4-2_revA01\_wind

referenzfile_servesea       L:\loads\confidential\000_Loads_Analysis_Environment\Tools\releases\01_Preprocessor\Version_3.0\Dataset_to_start\Referencefiles\Bladed4.2\DLC\dlc1-1_04a1.$PJ
referenzfile_generalsea     L:\loads\confidential\000_Loads_Analysis_Environment\Tools\releases\01_Preprocessor\Version_3.0\Dataset_to_start\Referencefiles\Bladed4.2\DLC\dlc6-1_000_a_50a_022.$PJ

externalcontrollerdll           L:\loads\confidential\000_Loads_Analysis_Environment\Tools\releases\01_Preprocessor\Version_3.0\Dataset_to_start\external_Controller\DisCon_V3_2_22.dll
externalcontrollerparameter     L:\loads\confidential\000_Loads_Analysis_Environment\Tools\releases\01_Preprocessor\Version_3.0\Dataset_to_start\external_Controller\ext_Ctrl_Data_V3_2_22.txt

BLOCK_END_DATASET

% ------------------------------------

BLOCK_START_WAVE
% a6*x^6 + a5*x^5 + a4*x^4 + a3*x^3 + a2*x^2 + a1*x + a0
factor_hs           0.008105;0.029055;0.153752
factor_tz               -0.029956;1.050777;2.731063
factor_tp               -0.118161;1.809956;3.452903
spectrum_gamma  3.3

BLOCK_END_WAVE

% ------------------------------------

BLOCK_START_EXTREMEWAVE

height_hs1  7.9
period_hs1  11.8

height_hs50 10.8
period_hs50 13.8

height_hred1    10.43
period_hred1    9.9

height_hred50   14.26
period_hred50   11.60

height_hmax1    14.8
period_hmax1    9.9

height_hmax50   20.1
period_hmax50   11.60

BLOCK_END_EXTREMEWAVE

% ------------------------------------

BLOCK_START_TIDE

normal  0.85
yr1 1.7
yr50    2.4

BLOCK_END_TIDE

% ------------------------------------

BLOCK_START_CURRENT

velocity_normal 1.09
velocity_yr1    1.09
velocity_yr50   1.38

BLOCK_END_CURRENT

% ------------------------------------

BLOCK_START_EXTREMEWIND

velocity_v1 29.7
velocity_v50    44.8

velocity_vred1  32.67
velocity_vred50 49.28

velocity_ve1    37.9
velocity_ve50   57

velocity_Vref   50

BLOCK_END_EXTREMEWIND

% ------------------------------------

Currently I’m parsing it this way:

clc, clear all, close all

%Find all row headers
fid = fopen('test_struct.txt','r');
row_headers = textscan(fid,'%s %*[^\n]','CommentStyle','%','CollectOutput',1);
row_headers = row_headers{1};
fclose(fid);

%Find all attributes
fid1 = fopen('test_struct.txt','r');
attributes = textscan(fid1,'%*s %s','CommentStyle','%','CollectOutput',1);
attributes = attributes{1};
fclose(fid1);

%Collect row headers and attributes in a single cell
parameters = [row_headers,attributes];


%Find all the blocks
startIdx = find(~cellfun(@isempty, regexp(parameters, 'BLOCK_START_', 'match')));
endIdx = find(~cellfun(@isempty, regexp(parameters, 'BLOCK_END_', 'match')));
assert(all(size(startIdx) == size(endIdx)))


%Extract fields between BLOCK_START_ and BLOCK_END_
extract_fields = @(n)(parameters(startIdx(n)+1:endIdx(n)-1,1));
struct_fields = arrayfun(extract_fields, 1:numel(startIdx), 'UniformOutput', false);

%Extract attributes between BLOCK_START_ and BLOCK_END_
extract_attributes = @(n)(parameters(startIdx(n)+1:endIdx(n)-1,2));
struct_attributes = arrayfun(extract_attributes, 1:numel(startIdx), 'UniformOutput', false);

%Get structure names stored after each BLOCK_START_
structures_name = @(n) strrep(parameters{startIdx(n)},'BLOCK_START_','');
structure_names = genvarname(arrayfun(structures_name,1:numel(startIdx),'UniformOutput',false));

%Generate structures
for i=1:numel(structure_names)
    eval([structure_names{i} '=cell2struct(struct_attributes{i},struct_fields{i},1);'])
end

It works, but not as I want. The overall idea is to read the file into one structure (one field per block BLOCK_START / BLOCK_END). Furthermore, I would like the numbers to be read as double and not as char, and delimiters like “whitespace” “,” or “;” have to be read as array separator (e.g. 3;4;5 = [3;4;5] and similar).

To clarify better, I will take the block

BLOCK_START_WAVE
% a6*x^6 + a5*x^5 + a4*x^4 + a3*x^3 + a2*x^2 + a1*x + a0
factor_hs           0.008105;0.029055;0.153752
factor_tz               -0.029956;1.050777;2.731063
factor_tp               -0.118161;1.809956;3.452903
spectrum_gamma  3.3

BLOCK_END_WAVE

The structure will be called WAVE with

WAVE.factor_hs = [0.008105;0.029055;0.153752]
WAVE.factor_tz = [-0.029956;1.050777;2.731063]
WAVE.factor_tp = [-0.118161;1.809956;3.452903]
WAVE.spectrum.gamma = 3.3

Any suggestion will be strongly appreciated.

Best regards.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T04:26:22+00:00Added an answer on June 11, 2026 at 4:26 am

    You have answers to this question (which is also yours) as a good starting point! To extract everything into a cell array, you do:

    %# Read data from input file
    fd = fopen('test_struct.txt', 'rt');
    C = textscan(fd, '%s', 'Delimiter', '\r\n', 'CommentStyle', '%');
    fclose(fd);
    
    %# Extract indices of start and end lines of each block
    start_idx = find(~cellfun(@isempty, regexp(C{1}, 'BLOCK_START', 'match')));
    end_idx = find(~cellfun(@isempty, regexp(C{1}, 'BLOCK_END', 'match')));
    assert(all(size(start_idx) == size(end_idx)))
    
    %# Extract blocks into a cell array
    extract_block = @(n)({C{1}{start_idx(n):end_idx(n) - 1}});
    cell_blocks = arrayfun(extract_block, 1:numel(start_idx), 'Uniform', false);
    

    Now, to translate that into corresponding structs, do this:

    %# Iterate over each block and convert it into a struct
    for i = 1:length(cell_blocks)
    
        %# Extract the block
        C = strtrim(cell_blocks{i});
        C(cellfun(@(x)isempty(x), C)) = [];         %# Ignore empty lines
    
        %# Parse the names and values
        params = cellfun(@(s)textscan(s, '%s%s'), {C{2:end}}, 'Uniform', false);
        name = strrep(C{1}, 'BLOCK_START_', '');    %# Struct name
        fields = cellfun(@(x)x{1}{:}, params, 'Uniform', false);
        values = cellfun(@(x)x{2}{:}, params, 'Uniform', false);
    
        %# Create a struct
        eval([name, ' = cell2struct({values{idx}}, {fields}, 2)'])
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this file file.txt which I want to split into many smaller ones.
OK. For example I have this line in my txt file: 1|1,12;7,19;6,4;8,19;2,2 As you
I have a CMakeLists.txt file that looks like this: add_executable(exec1 exec1.c source1.c source2.c source3.c)
I have a .txt file having some text. I want to read this file
I have a ID.txt file that looks like this: http://something.net/something-ak/41389_718783565_1214898307_q.jpg http://something.net/something-ak/372142_106502518141813_1189943482_q.jpg and so on
I have an array of file path components like this: [ ['some', 'dir', 'file.txt'],
I have a file (dictionary.txt) with data field entries as follows - ABC This
I'm creating a Shell Script, and I have a file like this called expressions.txt
I have a file like this. rm a.txt mkdir foo cp a.doc docs I
I have one file (for example: test.txt), this file contains some lines and for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.