-
Notifications
You must be signed in to change notification settings - Fork 0
/
gid2tec.m
473 lines (462 loc) · 19.9 KB
/
gid2tec.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
function gid2tec(basename)
%% Name of carat or empire mesh and result files
nameFileMshInfo=strcat(basename,'.msh');
nameFileResInfo=strcat(basename,'.res');
if ~(isfile(nameFileMshInfo))
fprintf('\t>> Error: The file %s does not exist.\n',nameFileMshInfo);
return;
end
if ~(isfile(nameFileResInfo))
fprintf('\t>> Error: The file %s does not exist.\n',nameFileResInfo);
return;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Mesh
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% extract infos from the headers of the mesh
fid = fopen(nameFileMshInfo);
headersMsh=fgetl(fid);
fclose(fid);
headersMsh_info = strsplit(headersMsh);
if strcmp(headersMsh_info{1},'MESH')
fprintf('\t>> The file %s is a MESH file...\n',nameFileMshInfo);
else
fprintf('\t>> Error: The file %s is not a MESH file.\n',nameFileMshInfo);
return;
end
headersMsh_info_tmp = strsplit(headersMsh,'dimension');
headersMsh_name=headersMsh_info_tmp{1};
headersMsh_info = strsplit(headersMsh_info_tmp{2});
headersMsh_info(1)= [];
headersMsh_dimension=str2num(headersMsh_info{1});
headersMsh_elementType=headersMsh_info{3};
headersMsh_Nnode=str2num(headersMsh_info{5});
% read the mesh and result files
fileMshInfo = fileread(nameFileMshInfo);
fileResInfo = fileread(nameFileResInfo);
%% Get the nodes and the elements of the meshes
%
% Get the nodes of the mesh
% the first stringSeparator is the header of the file
stringSeparator = headersMsh;
block = regexp(fileMshInfo,stringSeparator,'split');
% delete first index of 'block'
block(1) = [];
block = regexp(block{1},'Coordinates','split');
% delete first index of 'block'
block(1) = [];
% delete last index of 'block'
block(end) = [];
block = regexp(block{1},'End','split');
block(end) = [];
out = cell(size(block));
%
fprintf('\t>> Reading the coordinates of the nodes...');
for k = 1:numel(block)
out{k} = textscan(block{k},'%f %f %f %f','delimiter',' ','MultipleDelimsAsOne', 1);
out{k} = horzcat(out{k}{:});
end
msh.nodes = cell2mat(out);
msh.nodes = [msh.nodes(:,2:end) msh.nodes(:,1)]; % swap node ID to the last column
[num_nodes,~]=size(msh.nodes);
fprintf('DONE\n');
% NOT NEEDED if nodeID are passed to tecplot file in combination with NV=4:
% tecplot seems to have some problem with the nodeID of FASTEST.
% The following reattributes an nodeID, which corresponds to the line in
% the msh file.
% fprintf('\t>> Reformating the nodeIDs...');
% maxNodeID=max(msh.nodes(:,4));
% msh.nodeID2nodeLine=zeros(maxNodeID,1);
% for i=1:num_nodes
% msh.nodeID2nodeLine(msh.nodes(i,4))=i;
% end
% fprintf('DONE\n');
% Get the elements of the mesh
fprintf('\t>> Reading the elements of the mesh...\n');
stringSeparator = 'Elements';
block = regexp(fileMshInfo,stringSeparator,'split');
block(1) = [];
block = regexp(block{1},'End','split');
block(end) = [];
out = cell(size(block));
% Carat GiD files contain an additional column with the mesh id.
% Empire GiD files do not have it
% To handle that the format used in textscan does not have a %f for the
% mesh id. In consequence lines with NaN are generated with Carat GiD files.
% Therefore, a trick with 'isnan' is added after the reading of the
% elements.
if headersMsh_Nnode == 2
% Linear
fprintf('\t>> The MESH file contains Linear.\n');
for k = 1:numel(block)
out{k} = textscan(block{k},'%f %f %f','delimiter',' ','MultipleDelimsAsOne', 1); % three values
out{k} = horzcat(out{k}{:});
end
elseif headersMsh_Nnode == 3
% Triangle
fprintf('\t>> The MESH file contains triangles.\n');
for k = 1:numel(block)
out{k} = textscan(block{k},'%f %f %f %f','delimiter',' ','MultipleDelimsAsOne', 1); % four values
out{k} = horzcat(out{k}{:});
end
elseif headersMsh_Nnode == 4
% Quad
fprintf('\t>> The MESH file contains quad.\n');
for k = 1:numel(block)
out{k} = textscan(block{k},'%f %f %f %f %f','delimiter',' ','MultipleDelimsAsOne', 1); % five values
out{k} = horzcat(out{k}{:});
end
elseif headersMsh_Nnode == 8
% Hexa/Brick
fprintf('\t>> The MESH file contains hexa.\n');
for k = 1:numel(block)
out{k} = textscan(block{k},'%f %f %f %f %f %f %f %f %f','delimiter',' ','MultipleDelimsAsOne', 1); % five values
out{k} = horzcat(out{k}{:});
end
else
fprintf('\t>> Error: ElementType not supported.\n');
return;
end
elements = cell2mat(out);
% carat msh file introduces NaN in the elements array. This is a trick to
% remove the lines with NaN
elements=elements(sum(isnan(elements),2)==0,:);
msh.elements = elements(:,2:end);
%num_elements = length(msh.elements);
[num_elements,~]=size(msh.elements);
fprintf('\t>> DONE\n');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Results
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% remove header (it contains the word 'Result')
stringSeparator = 'GiD Post Results File 1.0';
block = regexp(fileResInfo,stringSeparator,'split');
% delete first index of 'block'
block(1) = [];
% create a cell array containing one result section per element
stringSeparator = 'Result';
block = regexp(block{1},stringSeparator,'split');
% delete first index of 'block'
block(1) = [];
nressection=size(block,2);
% look for the maximum number of step
resblock = regexp(block{end},'Values','split');
% extract info about the quantity in the current result section
% The delimiter has to be " for the case with variables including spaces
resblock_info=strsplit(resblock{1},'"');
resblock_info(1)=[];
outputQuantity_name=resblock_info{1};
% remove " from the name of quantity
outputQuantity_name=erase(outputQuantity_name,'"');
% replace whitespace with underscore
outputQuantity_name=regexprep(outputQuantity_name, ' ', '_');
resblock_info2=strsplit(resblock_info{4});
resblock_info2(1)=[];
ntotstep=str2num(resblock_info2{1});
% initialize for Tecplot file
nbquantityperstep=0;
outputQuantity_step_old=0;
% loop on all result sections
for ires=1:nressection
fprintf('\t>> Reading results of the Result section number = %d/%d\n',ires,nressection);
resblock = regexp(block{ires},'Values','split');
% extract info about the quantity in the current result section
% The delimiter has to be " for the case with variables including spaces
resblock_info=strsplit(resblock{1},'"');
resblock_info(1)=[];
outputQuantity_name=resblock_info{1};
% remove " from the name of quantity
outputQuantity_name=erase(outputQuantity_name,'"');
% replace whitespace with underscore
outputQuantity_name=regexprep(outputQuantity_name, ' ', '_');
resblock_info2=strsplit(resblock_info{4});
resblock_info2(1)=[];
outputQuantity_step=str2num(resblock_info2{1});
outputQuantity_type=resblock_info2{2};
outputQuantity_location=resblock_info2{3};
if strcmpi(outputQuantity_type,'vector')
%vector
outputQuantity_name_x=strcat('"',outputQuantity_name,'_X','"');
outputQuantity_name_y=strcat('"',outputQuantity_name,'_Y','"');
outputQuantity_name_z=strcat('"',outputQuantity_name,'_Z','"');
outputQuantity_varname=strcat(outputQuantity_name_x," ",outputQuantity_name_y," ",outputQuantity_name_z);
if strcmp(outputQuantity_location,'OnNodes')
outputQuantity_varlocation='NODAL NODAL NODAL';
elseif strcmp(outputQuantity_location,'OnGaussPoints')
outputQuantity_varlocation='CELLCENTERED CELLCENTERED CELLCENTERED';
else
fprintf('\t>> Error: Location not supported.\n');
return;
end
else
% scalar
outputQuantity_varname=strcat('"',outputQuantity_name,'"');
if strcmp(outputQuantity_location,'OnNodes')
outputQuantity_varlocation='NODAL';
elseif strcmp(outputQuantity_location,'OnGaussPoints')
outputQuantity_varlocation='CELLCENTERED';
else
fprintf('\t>> Error: Location not supported.\n');
return;
end
end
%
% write one tecplot file per step; A tecplot file may contain several
% output quantities
if outputQuantity_step > outputQuantity_step_old
fprintf('\t>> A new step starts.\n');
if (nbquantityperstep>0)
%% Write tecplot file
fprintf('\t>> Flush the previous data in a Tecplot file....\n');
writeData2plt(basename,nameFileMshInfo,outputQuantity_step_old, ...
outputQuantity,headersMsh_Nnode,num_nodes, ...
num_elements,msh,nbquantityperstep,ntotstep)
end
nbquantityperstep=1;
else
nbquantityperstep=nbquantityperstep+1;
end
% store the infos for the current step
outputQuantity.name(nbquantityperstep)=string(outputQuantity_name);
outputQuantity.varname(nbquantityperstep)=string(outputQuantity_varname);
outputQuantity.type(nbquantityperstep)=string(outputQuantity_type);
outputQuantity.location(nbquantityperstep)=string(outputQuantity_location);
outputQuantity.varlocation(nbquantityperstep)=string(outputQuantity_varlocation);
%
% remove the first element of the block: Typically the Result line
resblock(1) = [];
% remove the last elements of the block: Typically empty.
resblock(2:end) = [];
%resblock
% Remove all after End
resblock = regexp(resblock{1},'End','split');
% Remove the last element of the block: Typically empty
resblock(end) = [];
out = cell(size(resblock));
if strcmpi(outputQuantity_type,'vector')
fprintf('\t>> The quantity %s is a vector.\n',outputQuantity_name);
for k = 1:numel(resblock)
out{k} = textscan(resblock{k},'%f %f %f %f','delimiter',' ','MultipleDelimsAsOne', 1);
out{k} = horzcat(out{k}{:});
end
elseif strcmpi(outputQuantity_type,'scalar')
fprintf('\t>> The quantity %s is a scalar.\n',outputQuantity_name);
for k = 1:numel(resblock)
out{k} = textscan(resblock{k},'%f %f','delimiter',' ','MultipleDelimsAsOne', 1);
out{k} = horzcat(out{k}{:});
end
else
fprintf('\t>> Error: The type of the quantity %s is not supported yet.\n',outputQuantity_name);
end
%
if strcmp(outputQuantity_location,'OnNodes')
outputQuantity.dataOnNodes(:,:,nbquantityperstep) = cell2mat(out);
elseif strcmp(outputQuantity_location,'OnGaussPoints')
outputQuantity.dataOnGaussPoints(:,:,nbquantityperstep) = cell2mat(out);
else
fprintf('\t>> Error: Location not supported.\n');
return;
end
outputQuantity_step_old=outputQuantity_step;
end
%
%% Write tecplot file for the last step or if there is only 1 step
fprintf('\t>> Flush the last step in a Tecplot file....\n');
writeData2plt(basename,nameFileMshInfo,outputQuantity_step_old, ...
outputQuantity,headersMsh_Nnode,num_nodes, ...
num_elements,msh,nbquantityperstep,ntotstep)
return
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function writeData2plt(basename,nameFileMshInfo,outputQuantity_step_old, ...
outputQuantity,headersMsh_Nnode,num_nodes, ...
num_elements,msh,nbquantityperstep,ntotstep)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% write data into tecplot files
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% initialization and setting of variables
fieldwidth=20;
sigfigures=10;
numformat = strcat('%',num2str(fieldwidth),'.',num2str(sigfigures),'e');
% use a fixed length format for the step in the tecplot file
stepformat=strcat('%0',num2str(numel(num2str(ntotstep))),'d');
breaklineCharNum = 4000;
dotlocation = find(nameFileMshInfo =='.');
%
%% create the name of the tecplot file for the step and open it
nameFileMeshInfo_tecplot = strcat(nameFileMshInfo(1:dotlocation(end)-1),'_step_',num2str(outputQuantity_step_old,stepformat),'.dat');
fileID = fopen(nameFileMeshInfo_tecplot,'w');
%
%% create the headers of the tecplot file
list_tecplot_var = strjoin(outputQuantity.varname,' ');
list_tecplot_varlocation = strjoin(outputQuantity.varlocation,' ');
if headersMsh_Nnode == 2
% header_tecplot=strcat('TITLE = "',basename,'"\n VARIABLES = "X" "Y" "Z" "nodeID"'," ", ...
% list_tecplot_var,"\n ", ...
% 'ZONE T="STEP %d"\n N=%d, E=%d, DATAPACKING=BLOCK, ZONETYPE=FELINESEG, VARLOCATION = (NODAL NODAL NODAL NODAL '," ", ...
% list_tecplot_varlocation,')\n');
header_tecplot=strcat('TITLE = "',basename,'"\n VARIABLES = "X" "Y" "Z" "nodeID"'," ", ...
list_tecplot_var,"\n ", ...
'ZONE T="STEP %d"\n N=%d, NV=4, E=%d, DATAPACKING=BLOCK, ZONETYPE=FELINESEG, VARLOCATION = (NODAL NODAL NODAL NODAL '," ", ...
list_tecplot_varlocation,')\n');
elseif headersMsh_Nnode == 3
% header_tecplot=strcat('TITLE = "',basename,'"\n VARIABLES = "X" "Y" "Z" "nodeID"'," ", ...
% list_tecplot_var,"\n ", ...
% 'ZONE T="STEP %d"\n N=%d, E=%d, DATAPACKING=BLOCK, ZONETYPE=FETRIANGLE, VARLOCATION = (NODAL NODAL NODAL NODAL '," ", ...
% list_tecplot_varlocation,')\n');
header_tecplot=strcat('TITLE = "',basename,'"\n VARIABLES = "X" "Y" "Z" "nodeID"'," ", ...
list_tecplot_var,"\n ", ...
'ZONE T="STEP %d"\n N=%d, NV=4, E=%d, DATAPACKING=BLOCK, ZONETYPE=FETRIANGLE, VARLOCATION = (NODAL NODAL NODAL NODAL '," ", ...
list_tecplot_varlocation,')\n');
elseif headersMsh_Nnode == 4
% header_tecplot=strcat('TITLE = "',basename,'"\n VARIABLES = "X" "Y" "Z" "nodeID"'," ", ...
% list_tecplot_var,"\n ", ...
% 'ZONE T="STEP %d"\n N=%d, E=%d, DATAPACKING=BLOCK, ZONETYPE=FEQUADRILATERAL, VARLOCATION = (NODAL NODAL NODAL NODAL '," ", ...
% list_tecplot_varlocation,')\n');
header_tecplot=strcat('TITLE = "',basename,'"\n VARIABLES = "X" "Y" "Z" "nodeID"'," ", ...
list_tecplot_var,"\n ", ...
'ZONE T="STEP %d"\n N=%d, NV=4, E=%d, DATAPACKING=BLOCK, ZONETYPE=FEQUADRILATERAL, VARLOCATION = (NODAL NODAL NODAL NODAL '," ", ...
list_tecplot_varlocation,')\n');
elseif headersMsh_Nnode == 8
header_tecplot=strcat('TITLE = "',basename,'"\n VARIABLES = "X" "Y" "Z" "nodeID"'," ", ...
list_tecplot_var,"\n ", ...
'ZONE T="STEP %d"\n N=%d, NV=4, E=%d, DATAPACKING=BLOCK, ZONETYPE=FEBRICK, VARLOCATION = (NODAL NODAL NODAL NODAL '," ", ...
list_tecplot_varlocation,')\n');
else
fprintf('\t>> Error: ElementType not supported.\n');
return
end
fprintf(fileID,header_tecplot,outputQuantity_step_old,num_nodes,num_elements);
%
%% coordinate (x,y,z) loop
for i=1:4
% node loop
for j=1:num_nodes
fprintf(fileID, numformat, msh.nodes(j,i));
if mod((j*fieldwidth), breaklineCharNum) == 0
fprintf(fileID, '\n'); % Start a new line every 4000 characters
end
end
fprintf(fileID,'\n');
end
%
%% output quantity loop
for iquantity=1:nbquantityperstep
if strcmpi(outputQuantity.type(iquantity),'vector')
% vector quantity
if strcmp(outputQuantity.location(iquantity),'OnNodes')
% sort the quantity by the nodeID
orderquantityOnNodes = zeros(length(outputQuantity.dataOnNodes(:,1,iquantity)),4);
orderquantityOnNodes = sortrows(outputQuantity.dataOnNodes(:,:,iquantity));
orderquantityOnNodes = [orderquantityOnNodes(:,2:4), orderquantityOnNodes(:,1)]; % swap node ID to the last column
for i=1:3
% node loop
for j=1:num_nodes
fprintf(fileID, numformat, orderquantityOnNodes(j,i));
if mod((j*fieldwidth), breaklineCharNum) == 0
fprintf(fileID, '\n'); % Start a new line every 4000 characters
end
end
fprintf(fileID,'\n');
end
elseif strcmp(outputQuantity.location(iquantity),'OnGaussPoints')
% sort the quantity by the elements
orderquantityOnGaussPoints = zeros(length(outputQuantity.dataOnGaussPoints(:,1,iquantity)),4);
orderquantityOnGaussPoints = sortrows(outputQuantity.dataOnGaussPoints(:,:,iquantity));
orderquantityOnGaussPoints = [orderquantityOnGaussPoints(:,2:4), orderquantityOnGaussPoints(:,1)]; % swap node ID to the last column
for i=1:3
% element loop
for j=1:num_elements
fprintf(fileID, numformat, orderquantityOnGaussPoints(j,i));
if mod((j*fieldwidth), breaklineCharNum) == 0
fprintf(fileID, '\n'); % Start a new line every 4000 characters
end
end
fprintf(fileID,'\n');
end
else
fprintf('\t>> Error: Location not supported.\n');
return
end % end test on variable location
else
% scalar quantity
if strcmp(outputQuantity.location(iquantity),'OnNodes')
% sort the quantity by the nodeID
orderquantityOnNodes = zeros(length(outputQuantity.dataOnNodes(:,1,iquantity)),2);
orderquantityOnNodes = sortrows(outputQuantity.dataOnNodes(:,:,iquantity));
orderquantityOnNodes = [orderquantityOnNodes(:,2), orderquantityOnNodes(:,1)]; % swap node ID to the last column
% node loop
for j=1:num_nodes
fprintf(fileID, numformat, orderquantityOnNodes(j,1));
if mod((j*fieldwidth), breaklineCharNum) == 0
fprintf(fileID, '\n'); % Start a new line every 4000 characters
end
end
fprintf(fileID,'\n');
elseif strcmp(outputQuantity.location(iquantity),'OnGaussPoints')
orderquantityOnGaussPoints = zeros(length(outputQuantity.dataOnGaussPoints(:,1,iquantity)),2);
orderquantityOnGaussPoints = sortrows(outputQuantity.dataOnGaussPoints(:,:,iquantity));
orderquantityOnGaussPoints = [orderquantityOnGaussPoints(:,2), orderquantityOnGaussPoints(:,1)]; % swap node ID to the last column
% element loop
for j=1:num_elements
fprintf(fileID, numformat, orderquantityOnGaussPoints(j,1));
if mod((j*fieldwidth), breaklineCharNum) == 0
fprintf(fileID, '\n'); % Start a new line every 4000 characters
end
end
fprintf(fileID,'\n');
else
fprintf('\t>> Error: Location not supported.\n');
return
end % end test on variable location
end % end of test on outputQuantity.type
end % end of output quantity loop
%
%% connectivity loop
if headersMsh_Nnode == 2
for i=1:num_elements
for j=1:2
fprintf(fileID, '%10d',msh.elements(i,j));
% NOT NEEDED if nodeID are passed to tecplot file in combination with NV=4:
%fprintf(fileID, '%10d',msh.nodeID2nodeLine(msh.elements(i,j)));
end
fprintf(fileID,'\n');
end
elseif headersMsh_Nnode == 3
for i=1:num_elements
for j=1:3
fprintf(fileID, '%10d',msh.elements(i,j));
% NOT NEEDED if nodeID are passed to tecplot file in combination with NV=4:
%fprintf(fileID, '%10d',msh.nodeID2nodeLine(msh.elements(i,j)));
end
fprintf(fileID,'\n');
end
elseif headersMsh_Nnode == 4
for i=1:num_elements
for j=1:4
fprintf(fileID, '%10d',msh.elements(i,j));
% NOT NEEDED if nodeID are passed to tecplot file in combination with NV=4:
%fprintf(fileID, '%10d',msh.nodeID2nodeLine(msh.elements(i,j)));
end
fprintf(fileID,'\n');
end
elseif headersMsh_Nnode == 8
for i=1:num_elements
for j=1:8
fprintf(fileID, '%10d',msh.elements(i,j));
% NOT NEEDED if nodeID are passed to tecplot file in combination with NV=4:
%fprintf(fileID, '%10d',msh.nodeID2nodeLine(msh.elements(i,j)));
end
fprintf(fileID,'\n');
end
else
fprintf('\t>> Error: ElementType not supported.\n');
return
end % end of connectivity loop
%
%% close the file
fclose(fileID);
%
return
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%