This repository has been archived by the owner on Mar 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrd_exo.c
2702 lines (2240 loc) · 63.9 KB
/
rd_exo.c
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
/************************************************************************ *
* Goma - Multiphysics finite element software *
* Sandia National Laboratories *
* *
* Copyright (c) 2014 Sandia Corporation. *
* *
* Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, *
* the U.S. Government retains certain rights in this software. *
* *
* This software is distributed under the GNU General Public License. *
\************************************************************************/
/* rd_exo -- open & read an EXODUS II finite element database.
*
* rd_exo() -- input arguments
* x -- a pointer to a structure containing the information from
* an EXODUS IIv2 finite element database. A detailed description
* of this structure may be found in "exo_struct.h"
*
* fn -- points to a character string of the filename to be opened and
* subsequently read
*
* tasks -- there's a lot under the hood, dude. Things like read
* initialization information, memory allocation, results
* preliminaries, results data, for instance. These Boolean
* flags can be added together to do multiple tasks on one
* call, which is wanted at least as often as having only
* selective tasks performed.
*
* verbosity -- a integer that determines the level of output
* from rd_exo(). If zero, then no output is produced, larger
* values produce more detailed reporting of rd_exo()'s progress.
*
* Return values:
* integer -- A value of zero is returned upon normal completion of the
* routine. A value of -1 is returned if abnormal conditions
* were encountered.
*
* Notes:
*
* 1. rd_exo() allocates space as needed to accomodate the data from the
* input file.
*
* 2. The structure gets filled in with as much data as it can find.
*
* 3. The emphasis is on reading mesh data and other preliminary
* information. Little provision is made for reading results data
* or history data from the file.
*
* 4. Implemented new variables for "state" of the database and for
* "actions" to be performed.
*
* Modified: 1997/03/19 09:57 MST [email protected]
*
* Modified: 1998/08/04 12:45 MDT [email protected]
*/
#define _RD_EXO_C
#include <config.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
#ifdef STDC_HEADERS
#include <stdlib.h>
#endif
#include <string.h>
#include "map_names.h"
#include "std.h"
#include "exo_struct.h"
#include "eh.h"
#include "aalloc.h"
#include "rd_exo.h"
/*
* Prototypes for functions needed here, defined elsewhere...
*/
extern int in_list /* utils.c */
PROTO((int , /* val - what integer value to seek */
int *, /* start - where to begin looking */
int )); /* length - how far to search from start */
/*
* Variables used in several routines in this file.
*/
static int sc = sizeof(char);
static int si = sizeof(int);
static int sd = sizeof(dbl);
static int spc = sizeof(char *);
static int spi = sizeof(int *);
static int spf = sizeof(flt *);
static int spd = sizeof(dbl *);
static Spfrtn sr=0; /* sprintf() return type */
static char err_msg[MAX_CHAR_ERR_MSG];
int
rd_exo(Exo_DB *x, /* def'd in exo_struct.h */
char *fn,
int verbosity,
int task)
{
int i;
int index; /* translate elem var, block into 1D index */
int j;
int k;
int len;
int status=0;
int nnn;
char rc; /* generic returned character (char)*/
int ri; /* generic returned integer (int)*/
flt rf; /* generic returned flt (float)*/
/* dbl rd; generic returned dbl (double)*/
int nodal_var_index;
int time_index;
/*
* Do not specify the ground state unless the action includes reading
* initialization information...
*/
if ( task & EXODB_ACTION_RD_INIT )
{
x->state = EXODB_STATE_GRND;
}
if ( verbosity > 0 )
{
fprintf(stderr, "rd_exo() begins.\n");
}
/*
* Don't allocate memory for the file path unless this struct is in the
* ground state. Thereafter, it won't be.
*/
if ( x->state == EXODB_STATE_GRND )
{
len = strlen(fn) + 1; /* Space for terminating null character. */
x->path = (char *) smalloc(len*sizeof(char));
}
strcpy(x->path, fn);
x->mode = EX_READ;
x->comp_wordsize = sd;
x->io_wordsize = 0; /* That is, you tell me. */
if ( verbosity > 1 )
{
fprintf(stderr, "ex_open() call...\n");
}
x->exoid = ex_open(x->path, x->mode, &x->comp_wordsize,
&x->io_wordsize, &x->version);
if ( verbosity > 1 )
{
fprintf(stderr, "ex_open() rtn = %d\n", x->exoid);
}
if ( verbosity > 2 )
{
fprintf(stderr, "\tx->path = \"%s\"\n", x->path);
fprintf(stderr, "\tx->mode = %d\n", x->mode);
fprintf(stderr, "\tx->comp_ws = %d\n", x->comp_wordsize);
fprintf(stderr, "\tx->io_ws = %d\n", x->io_wordsize);
fprintf(stderr, "\tx->version = %g\n", x->version);
}
EH(x->exoid, "ex_open");
if ( task & EXODB_ACTION_RD_INIT )
{
/*
* Check to see if we're trying to build on top of an existing
* database? We really need to start from the ground zero state.
*/
/*
if ( x->state != EXODB_STATE_GRND )
{
EH(-1, "Attempt to rd init EXO db into previously used struct.");
}
*/
x->title = (char *) smalloc(MAX_LINE_LENGTH*sc);
if ( verbosity > 1 )
{
fprintf(stderr, "ex_get_init() call...\n");
}
status = ex_get_init(x->exoid,
x->title,
&x->num_dim,
&x->num_nodes,
&x->num_elems,
&x->num_elem_blocks,
&x->num_node_sets,
&x->num_side_sets);
EH(status, "ex_get_init");
if ( verbosity > 0 )
{
fprintf(stderr, "\tx->title = \"%s\"\n", x->title);
fprintf(stderr, "\tx->num_nodes = %d\n", x->num_nodes);
fprintf(stderr, "\tx->num_elems = %d\n", x->num_elems);
fprintf(stderr, "\tx->num_elem_blocks = %d\n", x->num_elem_blocks);
fprintf(stderr, "\tx->num_node_sets = %d\n", x->num_node_sets);
fprintf(stderr, "\tx->num_side_sets = %d\n", x->num_side_sets);
}
/*
* Consider Quality Assurance and Information to be vital initial
* information. Hey, we're politically correct!
*/
status = ex_inquire(x->exoid, EX_INQ_QA, &ri, &rf, &rc);
EH(status, "ex_inquire(EX_INQ_QA)");
x->num_qa_rec = ri;
if ( verbosity > 1 )
{
fprintf(stderr, "\tx->num_qa_rec = %d\n", x->num_qa_rec);
}
if ( x->num_qa_rec > 0 )
{
x->qa_record = (QA_Record *)smalloc(x->num_qa_rec*sizeof(QA_Record));
for ( i=0; i<x->num_qa_rec; i++)
{
for ( j=0; j<4; j++)
{
x->qa_record[i][j] = (char *) smalloc((MAX_STR_LENGTH+1)*sc);
}
}
status = ex_get_qa(x->exoid, x->qa_record);
EH(status, "ex_get_qa");
}
status = ex_inquire(x->exoid, EX_INQ_INFO, &ri, &rf, &rc);
EH(status, "ex_inquire(EX_INQ_INFO)");
x->num_info = ri;
if ( x->num_info > 0 )
{
x->info = (INFO_Record *) smalloc(x->num_info * sizeof(INFO_Record));
for ( i=0; i<x->num_info; i++)
{
x->info[i] = (char *) smalloc((MAX_LINE_LENGTH+1) * sc);
}
status = ex_get_info(x->exoid, &(x->info[0]));
EH(status, "ex_get_info");
}
status = ex_inquire(x->exoid, EX_INQ_API_VERS, &ri, &rf, &rc);
EH(status, "ex_inquire(EX_INQ_API_VERS)");
x->api_version = rf;
status = ex_inquire(x->exoid, EX_INQ_DB_VERS, &ri, &rf, &rc);
EH(status, "ex_inquire(EX_INQ_DB_VERS)");
x->db_version = rf;
status = ex_inquire(x->exoid, EX_INQ_NS_NODE_LEN, &ri, &rf, &rc);
EH(status, "ex_inquire(EX_INQ_NS_NODE_LEN)");
x->ns_node_len = ri;
status = ex_inquire(x->exoid, EX_INQ_NS_DF_LEN, &ri, &rf, &rc);
EH(status, "ex_inquire(EX_INQ_NS_DF_LEN)");
x->ns_distfact_len = ri;
status = ex_inquire(x->exoid, EX_INQ_SS_ELEM_LEN, &ri, &rf, &rc);
EH(status, "ex_inquire(EX_INQ_SS_ELEM_LEN)");
x->ss_elem_len = ri;
status = ex_inquire(x->exoid, EX_INQ_SS_DF_LEN, &ri, &rf, &rc);
EH(status, "ex_inquire(EX_INQ_SS_DF_LEN)");
x->ss_distfact_len = ri;
status = ex_inquire(x->exoid, EX_INQ_SS_NODE_LEN, &ri, &rf, &rc);
EH(status, "ex_inquire(EX_INQ_SS_NODE_LEN)");
x->ss_node_len = ri;
status = ex_inquire(x->exoid, EX_INQ_EB_PROP, &ri, &rf, &rc);
EH(status, "ex_inquire(EX_INQ_EB_PROP)");
x->eb_num_props = ri;
status = ex_inquire(x->exoid, EX_INQ_NS_PROP, &ri, &rf, &rc);
EH(status, "ex_inquire(EX_INQ_NS_PROP)");
x->ns_num_props = ri;
status = ex_inquire(x->exoid, EX_INQ_SS_PROP, &ri, &rf, &rc);
EH(status, "ex_inquire(EX_INQ_SS_PROP)");
x->ss_num_props = ri;
status = ex_inquire(x->exoid, EX_INQ_TIME, &ri, &rf, &rc);
EH(status, "ex_inquire()");
x->num_times = ri;
x->state |= EXODB_STATE_INIT; /* Did it! */
}
if ( task & EXODB_ACTION_RD_MESH )
{
if ( ! ( x->state & EXODB_STATE_INIT ) )
{
EH(-1, "Need to rd init info from EXO db before mesh.");
}
if ( x->state & EXODB_STATE_MESH )
{
EH(-1, "Attempt to rd mesh EXO db into previously used struct.");
}
x->x_coord = NULL;
x->y_coord = NULL;
x->z_coord = NULL;
if ( x->num_dim > 0 )
{
x->x_coord = (dbl *) smalloc(x->num_nodes * sd);
}
if ( x->num_dim > 1 )
{
x->y_coord = (dbl *) smalloc(x->num_nodes * sd);
}
if ( x->num_dim > 2 )
{
x->z_coord = (dbl *) smalloc(x->num_nodes * sd);
}
status = ex_get_coord(x->exoid, x->x_coord, x->y_coord, x->z_coord);
EH(status, "ex_get_coord");
if ( x->num_dim > 0 )
{
x->coord_names = (char **) smalloc(x->num_dim * spc);
for ( i=0; i<x->num_dim; i++ )
{
x->coord_names[i] = (char *) smalloc((MAX_STR_LENGTH+1)*sc);
}
status = ex_get_coord_names(x->exoid, x->coord_names);
EH(status, "ex_get_coord_names");
}
if ( x->num_nodes > 0 )
{
if ( x->node_map_exists )
{
x->node_map = (int *) smalloc(x->num_nodes * si);
status = ex_get_node_num_map(x->exoid, x->node_map);
EH(status, "ex_get_node_num_map");
}
}
if ( x->num_elems > 0 )
{
if ( x->elem_map_exists )
{
x->elem_map = (int *) smalloc(x->num_elems * si);
status = ex_get_elem_num_map(x->exoid, x->elem_map);
EH(status, "ex_get_elem_num_map");
}
if ( x->elem_order_map_exists )
{
x->elem_order_map = (int *) smalloc(x->num_elems * si);
status = ex_get_map(x->exoid, x->elem_order_map);
EH(status, "ex_get_map");
}
}
/*
* ELEMENT BLOCKS...
*/
if ( x->num_elem_blocks > 0 )
{
x->eb_id = (int *) smalloc(x->num_elem_blocks* si);
x->eb_elem_type = (char **) smalloc(x->num_elem_blocks*spc);
x->eb_num_elems = (int *) smalloc(x->num_elem_blocks*si);
x->eb_num_nodes_per_elem = (int *) smalloc(x->num_elem_blocks*si);
x->eb_num_attr = (int *) smalloc(x->num_elem_blocks*si);
x->eb_conn = (int **) smalloc(x->num_elem_blocks*spi);
x->eb_attr = (dbl **) smalloc(x->num_elem_blocks*spf);
x->eb_ptr = (int *)smalloc((x->num_elem_blocks+1)*si);
x->eb_ptr[0] = 0;
for ( i=0; i<x->num_elem_blocks; i++)
{
x->eb_elem_type[i] = (char *) smalloc((MAX_STR_LENGTH+1)*sc);
}
status = ex_get_elem_blk_ids(x->exoid, x->eb_id);
EH(status, "ex_get_elem_blk_ids");
for ( i=0; i<x->num_elem_blocks; i++)
{
status = ex_get_elem_block(x->exoid,
x->eb_id[i],
x->eb_elem_type[i],
&x->eb_num_elems[i],
&x->eb_num_nodes_per_elem[i],
&x->eb_num_attr[i]);
EH(status, "ex_get_elem_blocks");
if ( (x->eb_num_elems[i] * x->eb_num_nodes_per_elem[i]) > 0 )
{
x->eb_conn[i] =
(int *) smalloc((x->eb_num_elems[i] *
x->eb_num_nodes_per_elem[i])*
si);
status = ex_get_elem_conn(x->exoid,
x->eb_id[i],
x->eb_conn[i]);
EH(status, "ex_get_elem_conn");
}
if ( (x->eb_num_elems[i]*x->eb_num_attr[i]) > 0 )
{
x->eb_attr[i] = (dbl *)
smalloc( (x->eb_num_elems[i]*x->eb_num_attr[i])* sd);
status = ex_get_elem_attr(x->exoid, x->eb_id[i],
x->eb_attr[i]);
EH(status, "ex_get_elem_attr");
}
x->eb_ptr[i+1] = x->eb_ptr[i] + x->eb_num_elems[i];
}
}
/*
* NODE SETS...
*/
if ( x->num_node_sets > 0 )
{
x->ns_id = (int *) smalloc( x->num_node_sets* si);
x->ns_num_nodes = (int *) smalloc(x->num_node_sets* si);
x->ns_num_distfacts = (int *) smalloc(x->num_node_sets* si);
x->ns_node_index = (int *) smalloc(x->num_node_sets* si);
x->ns_distfact_index = (int *) smalloc(x->num_node_sets* si);
if ( x->ns_node_len > 0 )
{
x->ns_node_list = (int *) smalloc(x->ns_node_len* si);
}
if ( x->ns_distfact_len > 0 )
{
x->ns_distfact_list = (dbl *) smalloc(x->ns_distfact_len* sd);
status = ex_get_concat_node_sets(x->exoid, x->ns_id,
x->ns_num_nodes,
x->ns_num_distfacts,
x->ns_node_index,
x->ns_distfact_index,
x->ns_node_list,
x->ns_distfact_list);
EH(status, "ex_get_concat_node_sets");
}
}
/*
* SIDE SETS...
*/
if ( x->num_side_sets > 0 )
{
x->ss_id = (int *) smalloc(x->num_side_sets* si);
x->ss_num_sides = (int *) smalloc(x->num_side_sets* si);
x->ss_num_distfacts = (int *) smalloc(x->num_side_sets* si);
x->ss_elem_index = (int *) smalloc(x->num_side_sets* si);
x->ss_distfact_index = (int *) smalloc(x->num_side_sets* si);
x->ss_node_cnt_list = (int **) smalloc(x->num_side_sets* spi);
x->ss_node_list = (int **) smalloc(x->num_side_sets* spi);
x->ss_node_side_index = (int **) smalloc(x->num_side_sets* spi);
if ( x->ss_elem_len > 0 )
{
x->ss_elem_list = (int *) smalloc(x->ss_elem_len* si);
x->ss_side_list = (int *) smalloc(x->ss_elem_len* si);
}
if ( x->ss_distfact_len > 0 )
{
x->ss_distfact_list = (dbl *) smalloc(x->ss_distfact_len* sd);
}
status = ex_get_concat_side_sets(x->exoid, x->ss_id,
x->ss_num_sides,
x->ss_num_distfacts,
x->ss_elem_index,
x->ss_distfact_index,
x->ss_elem_list,
x->ss_side_list,
x->ss_distfact_list);
EH(status, "ex_get_concat_side_sets");
/*
* This information turns out to be useful in constructing more
* rapid indeces into the distribution factor array.
*/
x->ss_node_list_exists = TRUE; /* does now! */
for ( i=0; i<x->num_side_sets; i++)
{
x->ss_node_cnt_list[i] = (int *) smalloc(x->ss_num_sides[i]* si);
x->ss_node_list[i] = (int *) smalloc(x->ss_num_distfacts[i]* si);
status = ex_get_side_set_node_list(x->exoid,
x->ss_id[i],
x->ss_node_cnt_list[i],
x->ss_node_list[i]);
#ifdef DEBUG
fprintf(stderr, "SSID=%d has %d dfs/nds on %d sides.\n",
x->ss_id[i], x->ss_num_distfacts[i], x->ss_num_sides[i]);
for ( j=0; j<x->ss_num_sides[i]; j++)
{
fprintf(stderr, "nodes for elem %d side %d = %d\n",
x->ss_elem_list[x->ss_elem_index[i]+j],
x->ss_side_list[x->ss_elem_index[i]+j],
x->ss_node_cnt_list[i][j]);
}
#endif
/*
* Set up quick pointers for nodes on each given side of
* a sideset that can be used later to find exactly where to go
* in the big distribution factor list...
*/
x->ss_node_side_index[i] = (int *)
smalloc((x->ss_num_sides[i]+1)*si);
x->ss_node_side_index[i][0] = 0;
for ( j=0; j<x->ss_num_sides[i]; j++)
{
x->ss_node_side_index[i][j+1] = (x->ss_node_side_index[i][j]+
x->ss_node_cnt_list[i][j]);
}
#ifdef DEBUG
for ( j=0; j<x->ss_num_sides[i]; j++)
{
fprintf(stderr, "SS[%d]=%d, nodes for elem %d, side %d:", i,
x->ss_id[i], x->ss_elem_list[x->ss_elem_index[i]+j],
x->ss_side_list[x->ss_elem_index[i]+j]);
for ( k=x->ss_node_side_index[i][j];
k<x->ss_node_side_index[i][j+1]; k++)
{
fprintf(stderr, " %d", x->ss_node_list[i][k]);
}
fprintf(stderr, "\n");
}
#endif
}
}
/*
* PROPERTIES...
*
* We try to not really count just "one" property. EXODUS II will
* fake us out with the "ID" property that it will create anyway.
* If we count it here, then we'll get double bookkeeping...
*/
/*
* Node sets...
*/
if ( x->ns_num_props > 1 )
{
x->ns_prop_name = (char **) smalloc(x->ns_num_props* spc);
for ( i=0; i<x->ns_num_props; i++)
{
x->ns_prop_name[i] = (char *) smalloc(MAX_STR_LENGTH* sc);
}
status = ex_get_prop_names(x->exoid, EX_NODE_SET, x->ns_prop_name);
EH(status, "ex_get_prop_names(EX_NODE_SET)");
x->ns_prop = (int **) smalloc(x->ns_num_props* spi);
for ( i=0; i<x->ns_num_props; i++)
{
x->ns_prop[i] = (int *)smalloc(x->num_node_sets* si);
}
for ( i=0; i<x->ns_num_props; i++)
{
status = ex_get_prop_array(x->exoid, EX_NODE_SET,
x->ns_prop_name[i],
x->ns_prop[i]);
EH(status, "ex_get_prop_array(EX_NODE_SET)");
}
}
/*
* Side sets...
*/
if ( x->ss_num_props > 1 )
{
x->ss_prop_name = (char **) smalloc(x->ss_num_props* spc);
for ( i=0; i<x->ss_num_props; i++)
{
x->ss_prop_name[i] = (char *) smalloc((MAX_STR_LENGTH+1)* sc);
}
status = ex_get_prop_names(x->exoid, EX_SIDE_SET, x->ss_prop_name);
EH(status, "ex_get_prop_names(EX_SIDE_SET)");
x->ss_prop = (int **) smalloc(x->ss_num_props* spi);
for ( i=0; i<x->ss_num_props; i++)
{
x->ss_prop[i] = (int *)smalloc(x->num_side_sets* si);
}
for ( i=0; i<x->ss_num_props; i++)
{
status = ex_get_prop_array(x->exoid, EX_SIDE_SET,
x->ss_prop_name[i],
x->ss_prop[i]);
EH(status, "ex_get_prop_array(EX_SIDE_SET)");
}
}
/*
* Element blocks...
*/
if ( x->eb_num_props > 1 )
{
x->eb_prop_name = (char **) smalloc(x->eb_num_props* spc);
for ( i=0; i<x->eb_num_props; i++)
{
x->eb_prop_name[i] = (char *) smalloc((MAX_STR_LENGTH+1)* sc);
}
status = ex_get_prop_names(x->exoid, EX_ELEM_BLOCK, x->eb_prop_name);
EH(status, "ex_get_prop_names(EX_ELEM_BLOCK)");
x->eb_prop = (int **) smalloc(x->eb_num_props* spi);
for ( i=0; i<x->eb_num_props; i++)
{
x->eb_prop[i] = (int *)smalloc(x->num_elem_blocks* si);
}
for ( i=0; i<x->eb_num_props; i++)
{
status = ex_get_prop_array(x->exoid, EX_ELEM_BLOCK,
x->eb_prop_name[i],
x->eb_prop[i]);
EH(status, "ex_get_prop_array(EX_ELEM_BLOCK)");
}
}
x->state |= EXODB_STATE_MESH; /* Did it! */
}
/*
* Read in result preliminaries.
*
* In particular, read number of nodal, element, global variables
* as well as their names.
*
* Also, read the number of timeplanes and the element variable
* polygraph test results, Monica - Bill?
*
* Here might be a good place to allocate space for the little arrays
* describing how much data to read?
*/
if ( task & EXODB_ACTION_RD_RES0 )
{
/*
* Check for sanity - better not be doing this unless a fair
* amount of information is already known about this database.
*/
if ( ! ( x->state & EXODB_STATE_INIT ) )
{
EH(-1, "Need to rd init info from EXO db before result metadata.");
}
/*
* Hmmm... is it really just the element block IDs for element
* variables that are required? Perhaps for nodal variables it suffices
* to know merely the number of nodes...
*/
if ( ! ( x->state & EXODB_STATE_MESH ) )
{
EH(-1, "Need to rd mesh info from EXO db before result metadata.");
}
if ( x->state & EXODB_STATE_RES0 )
{
EH(-1, "Attempt to rd mesh EXO db into previously used struct.");
}
/*
* Initialize, then read what they really are.
*/
x->num_glob_vars = 0;
x->num_elem_vars = 0;
x->num_node_vars = 0;
/*
* Sometimes EXODUS II v2.** interacts badly with netCDF 3.*
* in the sense that "zero" answers are often equivalent to
* "undefined" answers. I think EXODUS II v3.00 fixes some
* of these problems...
*/
status = ex_get_var_param(x->exoid, "g", &x->num_glob_vars);
EH(status, "ex_get_var_param(g)");
status = ex_get_var_param(x->exoid, "e", &x->num_elem_vars);
EH(status, "ex_get_var_param(e)");
status = ex_get_var_param(x->exoid, "n", &x->num_node_vars);
EH(status, "ex_get_var_param(n)");
//printf("NUMBER OF NODAL VARIABLES = %d\n", x->num_node_vars);
/*
* Get the names of the results variables: global, element and nodal.
*/
if ( x->num_glob_vars > 0 )
{
nnn = MAX(x->num_glob_vars, 1);
x->glob_var_names = (char **) smalloc(nnn* spc);
for ( i=0; i<x->num_glob_vars; i++)
{
x->glob_var_names[i] = (char *) smalloc((MAX_STR_LENGTH+1)* sc);
}
status = ex_get_var_names(x->exoid, "g", x->num_glob_vars,
x->glob_var_names);
EH(status, "ex_get_var_names(g)");
}
if ( x->num_elem_vars > 0 )
{
x->elem_var_names = (char **) smalloc(x->num_elem_vars* spc);
for ( i=0; i<x->num_elem_vars; i++)
{
x->elem_var_names[i] = (char *) smalloc((MAX_STR_LENGTH+1)* sc);
}
status = ex_get_var_names(x->exoid, "e", x->num_elem_vars,
x->elem_var_names);
EH(status, "ex_get_var_names(e)");
}
if ( x->num_node_vars > 0 )
{
x->node_var_names = (char **) smalloc(x->num_node_vars* spc);
for ( i=0; i<x->num_node_vars; i++)
{
x->node_var_names[i] = (char *) smalloc((MAX_STR_LENGTH+1)* sc);
}
status = ex_get_var_names(x->exoid, "n", x->num_node_vars,
x->node_var_names);
//for ( i=0; i<x->num_node_vars; i++) {
// printf(" name %d = %s\n", i, x->node_var_names[i]);
// }
EH(status, "ex_get_var_names(n)");
}
/*
* Get time values...
*/
if ( x->num_times > 0 )
{
x->time_vals = (dbl *) smalloc(x->num_times* sizeof(dbl));
status = ex_get_all_times(x->exoid, x->time_vals);
EH(status, "ex_get_all_times");
}
/*
* Get element variable truth table...
*/
if ( x->num_elem_vars > 0 )
{
x->elem_var_tab = (int *) smalloc(x->num_elem_vars *
x->num_elem_blocks*
si);
status = ex_get_elem_var_tab(x->exoid, x->num_elem_blocks,
x->num_elem_vars, x->elem_var_tab);
EH(status, "ex_get_elem_var_tab");
}
/*
* There are auxiliary arrays that can be set up to direct the
* slurping of multiple timeplanes of results in one shot.
*
* Generally, though, it will be expedient to set up and allocate
* for ONE timeplane and ALL nodal, elemental, and global variables.
*/
/*
* Some inactive alternatives for you...
*
* x->num_nv_time_indeces = x->num_times;
* x->num_nv_indeces = 1;
*/
#ifdef DEBUG
fprintf(stderr,
"exo-> for %s has num_node_vars=%d, nv_time_indeces=%d, nv_indeces=%d\n",
x->path, x->num_node_vars, x->num_nv_time_indeces,
x->num_nv_indeces);
#endif
if ( x->state & EXODB_STATE_NDIA )
{
EH(-1, "Attempt to make nd indeces twice.");
}
x->num_nv_time_indeces = 1;
x->num_nv_indeces = x->num_node_vars;
if ( x->num_nv_indeces > 0 )
{
x->nv_indeces = (int *) smalloc(x->num_nv_indeces*
sizeof(int));
}
if ( x->num_nv_time_indeces > 0 )
{
x->nv_time_indeces = (int *) smalloc(x->num_nv_time_indeces*
sizeof(int));
}
x->state |= EXODB_STATE_NDIA;
/*
* Fill these indeces with reasonable defaults.
*
* WARNING!!! On 2nd and subsequent calls, you will probably want
* to increment x->nv_time_indeces[0] to look at the subsequent
* timeplanes of results!
*/
for ( i=0; i<x->num_nv_indeces; i++)
{
x->nv_indeces[i] = i+1; /* Names are 1,2,...,n -- FORTRAN rulz,
* dude! */
}
for ( j=0; j<x->num_nv_time_indeces; j++)
{
x->nv_time_indeces[j] = j+1;
}
x->state |= EXODB_STATE_RES0;
}
/*
* Get nodal results.
*/
if ( task & EXODB_ACTION_RD_RESN )
{
if ( !(x->state & EXODB_STATE_RES0) )
{
EH(-1, "Need to rd result metadata from EXO db before result data.");
}
/*
* Should be OK to read in another clump of data and to re-use
* the allocated space if we want to save space by reading clumps
* of data incrementally...
*
* The only hitch would be if the user changed x->num_nv_indeces
* in the interim. Good opportunity for public and private data, eh?
*/
/*
* The idea is this. The variable x->num_node_vars will indicated what
* is in the database file, while x->num_nv_indeces will be used to
* indicate memory that has been allocated for the memory model.
* Thus, if x->num_nv_indeces > 0, then we expect the arrays have
* been allocated and places made so the request for data can be
* satisfied.
*
* It is up to the user to say what, if any, nodal results data they
* want.
*/
#if 0
/*
* It must be "OK" for use to retrieve one nodal variable at a time
* from the database, so don't make this an error. It's more like
* a weakly informative message...
*/
if ( x->num_node_vars > x->num_nv_indeces )
{
sr = sprintf(err_msg, "Database has %d node vars, you want %d.",
x->num_node_vars, x->num_nv_indeces);
EH(-1, err_msg);
}
#endif
/*
* Don't do anything unless there's really something to do...
*/
if ( x->num_nv_time_indeces > 0 &&
x->num_nv_indeces > 0 &&
x->num_nodes > 0 &&
x->num_node_vars > 0 )
{
/*
* Nodal variable results -- allocate space if needed.
*/
if ( ! ( x->state & EXODB_STATE_NDVA ) )
{
/*
* Read only one timeplane's worth of nodal variables at
* a time, but read all of the nodal variables that are
* available. To do so, allocate enough space. Note that
* allocation of x->nv[][][] will use info in
* x->num_nv_time_indeces, etc.
*/
alloc_exo_nv(x);
}
/*
* Nodal results -- get values.
*/
for ( i=0; i<x->num_nv_time_indeces; i++)
{
time_index = x->nv_time_indeces[i];
for ( j=0; j<x->num_nv_indeces; j++)
{
nodal_var_index = x->nv_indeces[j];
status = ex_get_nodal_var(x->exoid, time_index,
nodal_var_index, x->num_nodes,
x->nv[i][j]);
EH(status, "ex_get_nodal_var");
}
}
}
/*
* Indicate that this memory representation of the database
* has some meaty nodal results variables in it.
*/
x->state |= EXODB_STATE_NDVR;
}
/*
* Global variable results.
*/
if ( task & EXODB_ACTION_RD_RESG )
{
/*
* Should do some error checking here to make sure things are
* setup and reasonable.
*/