-
Notifications
You must be signed in to change notification settings - Fork 0
/
intecplot.cpp
3546 lines (3014 loc) · 97.5 KB
/
intecplot.cpp
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
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/******************************************************************************
Copyright (c) 2017-2020, Ioannis Nompelis
All rights reserved.
Redistribution and use in source and binary forms, with or without any
modification, are permitted provided that the following conditions are met:
1. Redistribution of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistribution in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. All advertising materials mentioning features or use of this software
must display the following acknowledgement:
"This product includes software developed by Ioannis Nompelis."
4. Neither the name of Ioannis Nompelis and his partners/affiliates nor the
names of other contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
5. Redistribution or use of source code and binary forms for profit must
have written permission of the copyright holder.
THIS SOFTWARE IS PROVIDED BY IOANNIS NOMPELIS ''AS IS'' AND ANY
EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL IOANNIS NOMPELIS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <utils.h>
#include "intecplot.h"
#ifdef __cplusplus
extern "C" {
#endif
enum inTecFile_Component {
Unknown = -1,
Title = 11,
Filetype = 12,
FiletypeFull = 12001,
FiletypeGrid = 12002,
FiletypeSolution = 12003,
Variables = 13,
Zone = 21,
Text = 31,
Geometry = 41,
Custom_Label = 51,
Dataset_Auxilary = 61,
Variable_Auxilary = 71,
Comment = 100
};
enum inTecZone_FEtype {
ORDERED = 0,
FELINESEG = 1,
FETRIANGLE = 2,
FEQUADRILATERAL = 3,
FEPOLYGON = 4,
FETETRAHEDRON = 5,
FEBRICK = 6,
FEPOLYHEDRAL = 7
};
//
// the zone object methods
//
inTec_Zone::inTec_Zone( inTec_File* file_ )
{
#ifdef _DEBUG_
printf(" i Zone object instantiated\n");
#endif
istate = 0;
ipos = 0;
ipos_data = 0;
ipos_conn = 0;
// keyword-based variables
tkey = NULL;
ietype = -1;
idatapack = -1;
im = 0;
jm = 0;
km = 0;
nodes = 0;
elems = 0;
nv = 0;
parent_zone = -1;
// old-style variables
iold_n = 0;
iold_e = 0;
iold_et = -1;
iold_f = -1;
// utility variables
iparse_num = 0;
node_cnt = 0;
elem_cnt = 0;
var_cnt = 0;
icon_cnt = 0;
InitKeywords();
file = file_;
num_var = 0;
icon = NULL;
ncon = 0;
// if the zone has a parent file, get the number of variables, etc
if( file != NULL ) {
num_var = file->GetNumVariables();
// default all variables to nodal
for(int n=1;n<=num_var;++n) ivar_loc[n] = 1;
}
}
inTec_Zone::~inTec_Zone()
{
#ifdef _DEBUG_
printf(" i Zone object deconstructed\n");
#endif
clear();
}
int inTec_Zone::GetState() const
{
return( istate );
}
int inTec_Zone::GetType() const
{
return( (int) ietype );
}
void inTec_Zone::clear()
{
#ifdef _DEBUG_
printf(" i Zone object clearing\n");
#endif
// deallocate data arrays
std::vector< double * > :: iterator dpi;
for( dpi = var_vec.begin() ; dpi != var_vec.end() ; ++dpi ) {
if( (*dpi) != NULL ) {
double *tp = (*dpi);
//HACK free( tp );
#warning "CLEAN THIS IF ERROR"
free( tp );
(*dpi) = NULL;
}
}
var_vec.clear();
// deallocate connectivity array
if( icon != NULL ) free( icon );
icon = NULL;
#ifdef _DEBUG_
printf(" i Keywords in zone (%ld) \n", keywords.size());
printf(" Index Keyword=String \n");
std::map< std::string, std::string > :: iterator imap;
int i=0;
for( imap = keywords.begin(); imap != keywords.end(); ++imap ) {
printf(" %d ", i++ );
printf(" [%s] = %s\n", (*imap).first.c_str(), (*imap).second.c_str() );
}
#endif
keywords.clear();
#ifdef _DEBUG_
printf(" Other data in zone \n");
printf(" - T: %s \n", tkey);
printf(" - Nodes: %ld \n", nodes);
printf(" - Elements: %ld \n", elems);
printf(" - im,jm,kn: %ld, %ld, %ld \n", im,jm,km);
printf(" - Number of variables: %d \n", num_var);
std::map< int, int > :: iterator it;
for( it= ivar_loc.begin(); it != ivar_loc.end(); ++it ) {
printf(" ==> %d location %d \n", (*it).first, (*it).second );
}
#endif
ivar_loc.clear();
// drop T-keyword string
if( tkey != NULL ) free( tkey );
// initialize variables as if it were a fresh object
istate = 0;
ipos = 0;
ipos_data = 0;
ipos_conn = 0;
// keyword-based variables
tkey = NULL;
ietype = -1;
idatapack = -1;
im = 0;
jm = 0;
km = 0;
nodes = 0;
elems = 0;
nv = 0;
parent_zone = -1;
// old-style variables
iold_n = 0;
iold_e = 0;
iold_et = -1;
iold_f = -1;
// utility variables
iparse_num = 0;
node_cnt = 0;
elem_cnt = 0;
var_cnt = 0;
icon_cnt = 0;
InitKeywords();
file = NULL;
num_var = 0;
icon = NULL;
ncon = 0;
num_var = 0;
}
void inTec_Zone::InitKeywords()
{
// add TecPlot keywords with default values
// keywords["T"] = "";
keywords["ZONETYPE"] = "ORDERED";
// keywords["I"] = "";
// keywords["J"] = "";
// keywords["K"] = "";
// keywords["NODES"] = "";
// keywords["ELEMENTS"] = "";
// keywords["FACES"] = "";
// keywords["TOTALNUMFACENODES"] = "";
// keywords["NUMCONNECTEDBOUNDARYFACES"] = "";
// keywords["TOTALNUMBOUNDARYCONNECTIONS"] = "";
// keywords["FACENEIGBORMODE"] = "LOCALONETOONE";
// keywords["FACENEIGHBORCONNECTIONS"] = "";
keywords["DT"] = "SINGLE";
keywords["DATAPACKING"] = "BLOCK";
keywords["VARLOCATION"] = "(NODAL)";
// keywords["VARSHARELIST"] = "";
// keywords["NV"] = "";
// keywords["CONNECTIVITYSHAREZONE"] = "";
// keywords["STRANDID"] = "";
// keywords["SOLUTIONTIME"] = "";
// keywords["PARENTZONE"] = "";
// keywords["PASSIVEVARLIST"] = "";
// keywords["AUXDATA"] = "";
// keywords[""] = "";
// keywords from the old format
// keywords["E"] = "";
// keywords["N"] = "";
// keywords["ET"] = "";
}
long inTec_Zone::GetPositionInFile( void ) const
{
return( ipos );
}
int inTec_Zone::NotifyPositionInFile( long ipos_ )
{
// reject reseting of position if it is already set
if( ipos != 0 ) {
return(1);
} else { // this is for when a zone is created but not read from a file
ipos = ipos_;
return(0);
}
}
long inTec_Zone::GetDataPositionInFile( void ) const
{
return( ipos_data );
}
int inTec_Zone::NotifyDataPositionInFile( long ipos_data_ )
{
// reject reseting of position if it is already set
if( ipos_data != 0 ) {
return(1);
} else { // this is for when a zone is created but not read from a file
ipos_data = ipos_data_;
#ifdef _DEBUG_
printf(" --- Zone's data position at: %ld \n", ipos_data );
#endif
return(0);
}
}
int inTec_Zone::SetState_Reading( void )
{
if( istate != 0 ) {
// this is an error code that implies prior setting of the state
return(1);
}
// use whatever keywords hava been collected to manage the internal state
int iret = ManageInternals();
if( iret == 0 ) {
istate = 1;
return(0);
} else {
// this is an error code that should imply an inconsistency
return(2);
}
}
int inTec_Zone::ParseKeywords( char *buf )
{
#ifdef _DEBUG_
printf(" i Parsing zone keywords \n");
#endif
size_t isize=0;
while( buf[isize] != '\0' && buf[isize] != '\n' ) ++isize;
char *data;
// create a duplicate buffer
data = (char *) malloc(((size_t) (isize+1))*sizeof(char));
if( data == NULL ) return(-1);
// copy line to buffer and add termination character
memcpy( data, buf, isize );
data[isize] = '\0';
#ifdef _DEBUG3_
printf("DATA: %s\n",data);
#endif
// keep parsing for keywords and values
int np=0;
int ipar=0, ibra=0, iquote=0, ikey=0, ierror=0, iparse=0;
char *s=data, *es=NULL;
size_t n=0;
while( n <= isize ) {
#ifdef _DEBUG2_
printf(" (key: %d, quote: %d) ", ikey,iquote);
printf(" %c s: %c ", data[n],s[0]);
// printf(" %c s: %c (key: %d, quote: %d) ", data[n],s[0],ikey,iquote);
#endif
// space or comma as keyword delimeter
if( data[n] == ' ' || data[n] == ',' ) {
if( ikey == 0 ) {
s = &( data[n+1] );
} else if( ikey == 1 ) {
if( data[n] == ',' ) { ierror = 1;printf("This is in error! (1)"); }
} else if( ikey == 2 ) {
if( data[n] == ',' ) { ierror = 1;printf("This is in error! (1b)");}
} else if( ikey == 3 ) {
if( iquote == 1 || ibra == 1 || ipar == 1 ) {
// we continue parsing because the quote/bracket/paren. is open
} else {
// this terminates the keyword
ikey = 0;
// parsing should take place
iparse = 1;
}
}
} else
// equal sign
if( data[n] == '=' ) {
if( ikey == 0 ) {
ierror = 1; printf("This is in error! (2)");
} else if( ikey == 1 ) {
// we are moving to the second stage
es = &( data[n] );
ikey = 2;
#ifdef _DEBUG2_
printf(" (equal sign) ");
#endif
} else if( ikey == 2 ) {
ierror = 1; printf("This is in error! (2b)");
} else if( ikey == 3 ) {
if( iquote == 1 || ibra == 1 || ipar == 1 ) {
// we continue parsing because the quote/bracket/paren. is open
#ifdef _DEBUG2_
printf(" (equal sign in key=3) ");
#endif
} else {
ierror = 1; printf("This is in error! (3)");
}
}
} else
// double quote
if( data[n] == '\"' ) {
if( ikey < 2 ) {
ierror = 1; printf("This is in error! (4) (stray quote) ");
} else if( ikey == 2 ) {
// entering data section of this keyword
ikey = 3;
#ifdef _DEBUG2_
printf(" (start data of keyword) ");
#endif
// open quote
iquote = 1;
} else {
if( data[n-1] == '\\' ) {
// simply pick it up as a character
} else {
// it is a functional quote (marker)
if( iquote == 1 ) {
// close the quote
iquote = 0;
// // indicate that we can parse
// ikey = 0;
// iparse = 1;
// let the next encounter terminate the parsing
} else {
ierror = 1; printf("This is in error! (4b) (stray quote) ");
}
}
}
} else
// newline or null
if( data[n] == '\n' || data[n] == '\0' ) {
if( ikey == 3 ) {
if( iquote == 1 || ibra == 1 || ipar == 1 ) {
ierror = 1;printf("This is in error! (5) (unterminated quote/bracket/paren.) ");
} else {
ikey = 0;
iparse = 1;
#ifdef _DEBUG2_
printf(" (parsing ending) ");
#endif
}
} else if( ikey == 2 ) {
ierror = 1; printf("This is in error! (5b) (empty keyword) ");
} else if( ikey == 1 ) {
ierror = 1; printf("This is in error! (5b) (empty keyword) ");
} else {
// termination of parsing everything
#ifdef _DEBUG2_
printf(" (parsing ending) ");
#endif
}
} else
// open bracket
if( data[n] == '[' ) {
if( ikey < 2 ) {
ierror = 1; printf("This is in error! (6) (stray bracket) ");
} else if( ikey == 2 ) {
// entering data section of this keyword...
ikey = 3;
// ...with an open bracket
ibra = 1;
#ifdef _DEBUG2_
printf(" (start data of keyword with bracket) ");
#endif
} else {
// simply open bracket
ibra = 1;
#ifdef _DEBUG2_
printf(" (open bracket) ");
#endif
}
} else
// close bracket
if( data[n] == ']' ) {
if( ikey < 3 ) {
ierror = 1; printf("This is in error! (7a) (stray bracket) ");
} else {
if( ibra != 1 ) {
ierror = 1; printf("This is in error! (7b) (stray bracket) ");
} else {
// simply close bracket
ibra = 0;
#ifdef _DEBUG2_
printf(" (close bracket) ");
#endif
}
}
} else
// open parenthesis
if( data[n] == '(' ) {
if( ikey < 2 ) {
ierror = 1; printf("This is in error! (8) (stray paren.) ");
} else if( ikey == 2 ) {
// entering data section of this keyword...
ikey = 3;
// ...with an open parenthesis
ipar = 1;
#ifdef _DEBUG2_
printf(" (start data of keyword with paren.) ");
#endif
} else {
// simply open parenthesis
ipar = 1;
#ifdef _DEBUG2_
printf(" (open paren.) ");
#endif
}
} else
// close parenthesis
if( data[n] == ')' ) {
if( ikey < 3 ) {
ierror = 1; printf("This is in error! (9) (stray paren.) ");
} else {
if( ipar != 1 ) {
ierror = 1; printf("This is in error! (9b) (stray paren.) ");
} else {
// simply close parenthesis
ipar = 0;
#ifdef _DEBUG2_
printf(" (close paren.) ");
#endif
}
}
} else
// anything else
{
if( ikey == 0 ) {
// check whether we are in a line of data
if( CheckCharForNum( data[n] ) == 1 ) {
// terminate parsing immediately; the zone header must be done
free( data );
#ifdef _DEBUG2_
printf(" (numerical string) \n");
#endif
return( -100 );
}
// encountered keyword
ikey = 1;
#ifdef _DEBUG2_
printf(" (start keyword) ");
#endif
} else if( ikey == 2 ) {
// entering data section of this keyword
ikey = 3;
#ifdef _DEBUG2_
printf(" (start data of keyword) ");
#endif
}
}
// provide some output
if( iparse == 1 ) {
#ifdef _DEBUG2_
printf(" (parsing now)");
#endif
data[n+0] = '\0';//HACK
int iret = HandleKeyword( s );
// allow for the possibility of dealiing with this differently...
if( iret == 0 ) ++np;
iparse = 0;
}
++n;
#ifdef _DEBUG2_
printf("\n");
#endif
}
// drop duplicate buffer
free( data );
if( ierror == 0 ) {
return( np );
} else {
#ifdef _DEBUG_
printf(" --- Error returned: %d \n", -10*ierror );
#endif
return( -10*ierror );
}
}
int inTec_Zone::HandleKeyword( char *buf )
{
#ifdef _DEBUG_
printf("\n i Handling keyword \n");
#endif
#ifdef _DEBUG2_
printf(" --- keyword -->|%s|<-- \n", buf );
#endif
// shift start of buffer to beginning of the keyword
char *s = buf;
while( s[0] == ' ' || s[0] == ',' ) s++;
#ifdef _DEBUG_
printf(" --- start keyword -->|%s|<-- \n", s );
#endif
// size to equal sign
size_t i=0,key_size=0;
while( s[ i ] != '=' ) {
// nullify spaces as you go
if( s[ i ] != ' ' ) {
++key_size;
} else {
s[key_size] = '\0';
}
++i;
}
#ifdef _DEBUG_
printf(" --- Equal sign at character %ld \n", i );
#endif
s[i] = '\0';
#ifdef _DEBUG_
printf(" --- Cleaned keyword: --->|%s|<--- \n", s );
#endif
// need to "shift" past the equal sign and to the beginning of the payload
char *p = &( s[ i+1] );
while( p[0] == ' ' && p[0] != '\0' ) p++;
#ifdef _DEBUG_
printf(" --- Payload: --->|%s|<--- \n", p );
#endif
// trials to match keyword
// (determine size of keyword and do per-size compar.)
int iret=1;
if( key_size == 1 ) {
if( strncasecmp( s, "T", 1 ) == 0 ) {
keywords["T"] = p;
iret = 0;
}
if( strncasecmp( s, "I", 1 ) == 0 ) {
keywords["I"] = p;
iret = 0;
}
if( strncasecmp( s, "J", 1 ) == 0 ) {
keywords["J"] = p;
iret = 0;
}
if( strncasecmp( s, "K", 1 ) == 0 ) {
keywords["K"] = p;
iret = 0;
}
if( strncasecmp( s, "E", 1 ) == 0 ) { // old keyword
keywords["E"] = p;
iret = 0;
}
if( strncasecmp( s, "N", 1 ) == 0 ) { // old keyword
keywords["N"] = p;
iret = 0;
}
if( strncasecmp( s, "F", 1 ) == 0 ) { // old keyword
keywords["F"] = p;
iret = 0;
}
}
if( key_size == 2 ) {
if( strncasecmp( s, "ET", 2 ) == 0 ) { // old keyword
keywords["ET"] = p;
iret = 0;
}
if( strncasecmp( s, "DT", 2 ) == 0 ) {
keywords["DT"] = p;
iret = 0;
}
if( strncasecmp( s, "NV", 2 ) == 0 ) {
keywords["NV"] = p;
iret = 0;
}
}
if( key_size == 5 ) {
if( strncasecmp( s, "NODES", 5 ) == 0 ) {
keywords["NODES"] = p;
iret = 0;
}
if( strncasecmp( s, "FACES", 5 ) == 0 ) {
keywords["FACES"] = p;
iret = 0;
}
}
if( key_size == 8 ) {
if( strncasecmp( s, "ELEMENTS", 8 ) == 0 ) {
keywords["ELEMENTS"] = p;
iret = 0;
}
if( strncasecmp( s, "ZONETYPE", 8 ) == 0 ) {
keywords["ZONETYPE"] = p;
iret = 0;
}
}
if( key_size == 11 ) {
if( strncasecmp( s, "DATAPACKING", 11 ) == 0 ) {
keywords["DATAPACKING"] = p;
iret = 0;
}
if( strncasecmp( s, "VARLOCATION", 11 ) == 0 ) {
keywords["VARLOCATION"] = p;
iret = 0;
}
}
if( key_size == 12 ) {
if( strncasecmp( s, "VARSHARELIST", 11 ) == 0 ) {
keywords["VARSHARELIST"] = p;
iret = 0;
}
}
return( iret );
}
int inTec_Zone::CheckCharForNum( char c ) const
{
if( c == '0' ) {
return(1);
} else if( c == '1' ) {
return(1);
} else if( c == '2' ) {
return(1);
} else if( c == '3' ) {
return(1);
} else if( c == '4' ) {
return(1);
} else if( c == '5' ) {
return(1);
} else if( c == '6' ) {
return(1);
} else if( c == '7' ) {
return(1);
} else if( c == '8' ) {
return(1);
} else if( c == '9' ) {
return(1);
} else if( c == '-' ) {
return(1);
} else if( c == '+' ) {
return(1);
} else if( c == '.' ) {
return(1);
} else {
return(0);
}
}
int inTec_Zone::ManageInternals( void )
{
#ifdef _DEBUG_
printf(" i Inside ManageInternals() \n");
#endif
int ierror=0,iret=0;
// processing individual keywords
const char *string=NULL,*string2=NULL;
size_t is;
int i=0;
std::map< std::string, std::string > :: iterator imap;
for( imap = keywords.begin(); imap != keywords.end(); ++imap ) {
printf(" %d ", i++ );
string = (*imap).first.c_str();
printf(" %s ", string );
string2 = (*imap).second.c_str();
printf(" \"%s\"\n", string2 );
// keywords by size
is = strlen( string );
if( is == 1 ) {
if( strncasecmp( string, "N", 1 ) == 0 ) {
iold_n = (unsigned long) atol( string2 );
}
if( strncasecmp( string, "E", 1 ) == 0 ) {
iold_e = (unsigned long) atol( string2 );
}
if( strncasecmp( string, "I", 1 ) == 0 ) {
im = (unsigned long) atol( string2 );
}
if( strncasecmp( string, "J", 1 ) == 0 ) {
jm = (unsigned long) atol( string2 );
}
if( strncasecmp( string, "K", 1 ) == 0 ) {
km = (unsigned long) atol( string2 );
}
if( strncasecmp( string, "T", 1 ) == 0 ) {
iret = HandleKeyword_T( string2 );
if( iret != 0 ) ierror += 1;
}
if( strncasecmp( string, "F", 1 ) == 0 ) {
// will deal with this later...
// iret = HandleKeyword_F( string2 );
if( iret != 0 ) ierror += 1;
}
}
if( is == 2 ) {
if( strncasecmp( string, "DT", 2 ) == 0 ) {
// will do this later...
}
if( strncasecmp( string, "ET", 2 ) == 0 ) {
iret = HandleKeyword_ET( string2 );
if( iret != 0 ) ierror += 1;
}
if( strncasecmp( string, "NV", 2 ) == 0 ) {
// will do this later...
}
}
if( is == 5 ) {
if( strncasecmp( string, "NODES", 5 ) == 0 ) {
nodes = (unsigned long) atol( string2 );
}
}
if( is == 8 ) {
if( strncasecmp( string, "ELEMENTS", 8 ) == 0 ) {
elems = (unsigned long) atol( string2 );
}
if( strncasecmp( string, "ZONETYPE", 8 ) == 0 ) {
iret = HandleKeyword_Zonetype( string2 );
if( iret != 0 ) ierror += 1;
}
}
if( is == 10 ) {
if( strncasecmp( string, "PARENTZONE", 10 ) == 0 ) {
parent_zone = atoi( string2 );
}
}
if( is == 11 ) {
if( strncasecmp( string, "VARLOCATION", 11 ) == 0 ) {
iret = HandleKeyword_Varlocation( string2 );
if( iret != 0 ) ierror += 1;
}
if( strncasecmp( string, "DATAPACKING", 11 ) == 0 ) {
iret = HandleKeyword_Datapacking( string2 );
if( iret != 0 ) ierror += 1;
}
}
if( is == 12 ) {
if( strncasecmp( string, "VARSHARELIST", 12 ) == 0 ) {
iret = HandleKeyword_Varsharelist( string2 );
if( iret != 0 ) ierror += 1;
}
}
}
// sanity checks for the zone's collected keywords
ierror += ConsistencyCheck();
// final error check
if( ierror != 0 ) {
iret = 1;
#ifdef _DEBUG_
printf(" e Exiting ManageInternals() in error (return %d) \n",iret);
#endif
return( iret );
}
//
// allocate memory for variables
//
// get a vertex and cell count
size_t iv=0,ie=0;
// first try the ordered zone sizes
if( ietype == ORDERED ) {
unsigned long imt,jmt,kmt;
#ifdef _DEBUG_
printf(" i Internal var. \"ietype\" indicates it is an ORDERED zone \n");
#endif
if( im - 1 == 0 ) { imt = 2; } else { imt = im; }
if( jm - 1 == 0 ) { jmt = 2; } else { jmt = jm; }
if( km - 1 == 0 ) { kmt = 2; } else { kmt = km; }
if( jm > 0 ) {
if( km > 0 ) {
iv = (size_t) (im*jm*km);
ie = (size_t) ((imt-1)*(jmt-1)*(kmt-1));
} else {
iv = (size_t) (im*jm);
ie = (size_t) ((imt-1)*(jmt-1));
}
} else {
iv = (size_t) im;
ie = (size_t) (imt-1);
}
}
// then try the unstruct. zone sizes
if( ietype != ORDERED ) {
#ifdef _DEBUG_
printf(" i Internal var. \"ietype\" indicates it is an unstr. zone \n");
#endif
iv = (size_t) nodes;
ie = (size_t) elems;
}
#ifdef _DEBUG_
printf(" i Number of vertices %ld, elements %ld \n",
(unsigned long) iv, (unsigned long) ie );
#endif
// sanity check
if( iv <= 0 || ie <= 0 ) {
printf(" e Cannot have zero nodes or zero elements \n");
iret = 1;
#ifdef _DEBUG_
printf(" e Exiting ManageInternals() in error (return %d) \n",iret);
#endif
return( iret );
}
// allocate memory for data arrays
for(int n=1;n<=num_var;++n) {
if( ivar_loc[n] == 1 ) {
double *p = (double *) malloc(iv*sizeof(double));
var_vec.push_back( p );
if( p == NULL ) ierror += 1;
#ifdef _DEBUG_
printf(" --- Vertex-data pointer at %p \n", p );
#endif
} else if( ivar_loc[n] == 2 ) {
double *p = (double *) malloc(ie*sizeof(double));
var_vec.push_back( p );
if( p == NULL ) ierror += 1;
#ifdef _DEBUG_
printf(" --- Cell-data pointer at %p \n", p );
#endif
} else {
// allow for the provision to skip allocating memory for a variable
}
}
// allocate memory for connectivity if needed
if( ietype != ORDERED ) {
if( ietype == FETRIANGLE ) ncon = 3;
if( ietype == FEQUADRILATERAL) ncon = 4;
if( ietype == FETETRAHEDRON) ncon = 4;
if( ietype == FEBRICK) ncon = 8;
size_t isize = (size_t) (elems*ncon);
if( icon == NULL ) {
icon = (unsigned long *) malloc(isize*sizeof(unsigned long));
}
if( icon == NULL ) ierror += 1;
}
// drop all memory on any allocation error
if( ierror != 0 ) {
#ifdef _DEBUG_
printf(" e There was an allocation error!\n");