Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.46 KB | None | 0 0
  1. BLOCK_START_DATASET
  2.  
  3. dlcdata L:loadsconfidential00_Loads_Analysis_EnvironmentToolsreleases1_PreprocessorVersion_3.0ParameterfilesBladed4.2DLC-FilesDLCDataFile.txt
  4. simulationdata L:loadsconfidential00_Loads_Analysis_EnvironmentToolsreleases1_PreprocessorVersion_3.0ParameterfilesBladed4.2DLC-FilesBladedFile.txt
  5.  
  6. outputfolder Pfadangaberuns_test
  7. windfolder L:loads2WEC1002_50-2_calc50-2_D135_HH95_RB-AB66-0O_GL2005_towerdesign_Bladed_v4-2_revA01_wind
  8.  
  9. referenzfile_servesea L:loadsconfidential00_Loads_Analysis_EnvironmentToolsreleases1_PreprocessorVersion_3.0Dataset_to_startReferencefilesBladed4.2DLCdlc1-1_04a1.$PJ
  10. referenzfile_generalsea L:loadsconfidential00_Loads_Analysis_EnvironmentToolsreleases1_PreprocessorVersion_3.0Dataset_to_startReferencefilesBladed4.2DLCdlc6-1_000_a_50a_022.$PJ
  11.  
  12. externalcontrollerdll L:loadsconfidential00_Loads_Analysis_EnvironmentToolsreleases1_PreprocessorVersion_3.0Dataset_to_startexternal_ControllerDisCon_V3_2_22.dll
  13. externalcontrollerparameter L:loadsconfidential00_Loads_Analysis_EnvironmentToolsreleases1_PreprocessorVersion_3.0Dataset_to_startexternal_Controllerext_Ctrl_Data_V3_2_22.txt
  14.  
  15. BLOCK_END_DATASET
  16.  
  17. % ------------------------------------
  18.  
  19. BLOCK_START_WAVE
  20. % a6*x^6 + a5*x^5 + a4*x^4 + a3*x^3 + a2*x^2 + a1*x + a0
  21. factor_hs 0.008105;0.029055;0.153752
  22. factor_tz -0.029956;1.050777;2.731063
  23. factor_tp -0.118161;1.809956;3.452903
  24. spectrum_gamma 3.3
  25.  
  26. BLOCK_END_WAVE
  27.  
  28. % ------------------------------------
  29.  
  30. BLOCK_START_EXTREMEWAVE
  31.  
  32. height_hs1 7.9
  33. period_hs1 11.8
  34.  
  35. height_hs50 10.8
  36. period_hs50 13.8
  37.  
  38. height_hred1 10.43
  39. period_hred1 9.9
  40.  
  41. height_hred50 14.26
  42. period_hred50 11.60
  43.  
  44. height_hmax1 14.8
  45. period_hmax1 9.9
  46.  
  47. height_hmax50 20.1
  48. period_hmax50 11.60
  49.  
  50. BLOCK_END_EXTREMEWAVE
  51.  
  52. % ------------------------------------
  53.  
  54. BLOCK_START_TIDE
  55.  
  56. normal 0.85
  57. yr1 1.7
  58. yr50 2.4
  59.  
  60. BLOCK_END_TIDE
  61.  
  62. % ------------------------------------
  63.  
  64. BLOCK_START_CURRENT
  65.  
  66. velocity_normal 1.09
  67. velocity_yr1 1.09
  68. velocity_yr50 1.38
  69.  
  70. BLOCK_END_CURRENT
  71.  
  72. % ------------------------------------
  73.  
  74. BLOCK_START_EXTREMEWIND
  75.  
  76. velocity_v1 29.7
  77. velocity_v50 44.8
  78.  
  79. velocity_vred1 32.67
  80. velocity_vred50 49.28
  81.  
  82. velocity_ve1 37.9
  83. velocity_ve50 57
  84.  
  85. velocity_Vref 50
  86.  
  87. BLOCK_END_EXTREMEWIND
  88.  
  89. % ------------------------------------
  90.  
  91. clc, clear all, close all
  92.  
  93. %Find all row headers
  94. fid = fopen('test_struct.txt','r');
  95. row_headers = textscan(fid,'%s %*[^n]','CommentStyle','%','CollectOutput',1);
  96. row_headers = row_headers{1};
  97. fclose(fid);
  98.  
  99. %Find all attributes
  100. fid1 = fopen('test_struct.txt','r');
  101. attributes = textscan(fid1,'%*s %s','CommentStyle','%','CollectOutput',1);
  102. attributes = attributes{1};
  103. fclose(fid1);
  104.  
  105. %Collect row headers and attributes in a single cell
  106. parameters = [row_headers,attributes];
  107.  
  108.  
  109. %Find all the blocks
  110. startIdx = find(~cellfun(@isempty, regexp(parameters, 'BLOCK_START_', 'match')));
  111. endIdx = find(~cellfun(@isempty, regexp(parameters, 'BLOCK_END_', 'match')));
  112. assert(all(size(startIdx) == size(endIdx)))
  113.  
  114.  
  115. %Extract fields between BLOCK_START_ and BLOCK_END_
  116. extract_fields = @(n)(parameters(startIdx(n)+1:endIdx(n)-1,1));
  117. struct_fields = arrayfun(extract_fields, 1:numel(startIdx), 'UniformOutput', false);
  118.  
  119. %Extract attributes between BLOCK_START_ and BLOCK_END_
  120. extract_attributes = @(n)(parameters(startIdx(n)+1:endIdx(n)-1,2));
  121. struct_attributes = arrayfun(extract_attributes, 1:numel(startIdx), 'UniformOutput', false);
  122.  
  123. %Get structure names stored after each BLOCK_START_
  124. structures_name = @(n) strrep(parameters{startIdx(n)},'BLOCK_START_','');
  125. structure_names = genvarname(arrayfun(structures_name,1:numel(startIdx),'UniformOutput',false));
  126.  
  127. %Generate structures
  128. for i=1:numel(structure_names)
  129. eval([structure_names{i} '=cell2struct(struct_attributes{i},struct_fields{i},1);'])
  130. end
  131.  
  132. BLOCK_START_WAVE
  133. % a6*x^6 + a5*x^5 + a4*x^4 + a3*x^3 + a2*x^2 + a1*x + a0
  134. factor_hs 0.008105;0.029055;0.153752
  135. factor_tz -0.029956;1.050777;2.731063
  136. factor_tp -0.118161;1.809956;3.452903
  137. spectrum_gamma 3.3
  138.  
  139. BLOCK_END_WAVE
  140.  
  141. WAVE.factor_hs = [0.008105;0.029055;0.153752]
  142. WAVE.factor_tz = [-0.029956;1.050777;2.731063]
  143. WAVE.factor_tp = [-0.118161;1.809956;3.452903]
  144. WAVE.spectrum.gamma = 3.3
  145.  
  146. %# Read data from input file
  147. fd = fopen('test_struct.txt', 'rt');
  148. C = textscan(fd, '%s', 'Delimiter', 'rn', 'CommentStyle', '%');
  149. fclose(fd);
  150.  
  151. %# Extract indices of start and end lines of each block
  152. start_idx = find(~cellfun(@isempty, regexp(C{1}, 'BLOCK_START', 'match')));
  153. end_idx = find(~cellfun(@isempty, regexp(C{1}, 'BLOCK_END', 'match')));
  154. assert(all(size(start_idx) == size(end_idx)))
  155.  
  156. %# Extract blocks into a cell array
  157. extract_block = @(n)({C{1}{start_idx(n):end_idx(n) - 1}});
  158. cell_blocks = arrayfun(extract_block, 1:numel(start_idx), 'Uniform', false);
  159.  
  160. %# Iterate over each block and convert it into a struct
  161. for i = 1:length(cell_blocks)
  162.  
  163. %# Extract the block
  164. C = strtrim(cell_blocks{i});
  165. C(cellfun(@(x)isempty(x), C)) = []; %# Ignore empty lines
  166.  
  167. %# Parse the names and values
  168. params = cellfun(@(s)textscan(s, '%s%s'), {C{2:end}}, 'Uniform', false);
  169. name = strrep(C{1}, 'BLOCK_START_', ''); %# Struct name
  170. fields = cellfun(@(x)x{1}{:}, params, 'Uniform', false);
  171. values = cellfun(@(x)x{2}{:}, params, 'Uniform', false);
  172.  
  173. %# Create a struct
  174. eval([name, ' = cell2struct({values{idx}}, {fields}, 2)'])
  175. end
  176.  
  177. /BLOCK_START_(w+).*?BLOCK_END_1/s
  178.  
  179. /^(?!BLOCK_END_)(w+)s+((?:-?d+.?d*)(?:;(?:-?d+.?d*))*)/m
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement