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
/
fix.c
1055 lines (831 loc) · 25.6 KB
/
fix.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. *
\************************************************************************/
/* fix -- GOMA monolith problem recomposition from polylithic EXODUS II data
*
* Copyright (c) 1999-2000 Sandia National Laboratories. All rights reserved.
*
* fix - using n augmented EXODUS II files with results, reconstruct a
* monolithic EXODUS II file for the global problem that includes
* both mesh and results.
*
* Created: 1997/11/12 12:55 MST pasacki@sandia.gov
*
* Revised: 1998/08/29 07:22 MDT pasacki@sandia.gov
*/
#define _FIX_C
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#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 <unistd.h>
#include <string.h>
#include "std.h" /* useful general stuff */
#include "eh.h" /* error handling */
#include "aalloc.h" /* multi-dim array allocation */
#include "exo_struct.h" /* some definitions for EXODUS II */
#include "dpi.h" /* distributed processing information */
#include "nodesc.h" /* node descriptions */
#include "rd_dpi.h"
static int show_help = FALSE;
static int be_quiet = FALSE;
static int be_verbose = FALSE;
static int num_procs_specified = FALSE;
char *program_name; /* name this program was run with */
static char program_version[] = BRK_VERSION;
const char program_description[] = "GOMA distributed problem recomposition tool";
const char copyright[] =
"Copyright (c) 1999-2000 Sandia National Laboratories. All rights reserved.";
int *ep; /* element pointers into node list */
int *np; /* node pointers into element list */
int *nl; /* node list */
int *el; /* element list */
int *ebl; /* element block list */
extern int rd_exo /* def in "rd_exo.c" */
PROTO((Exo_DB *, /* structure defined in exo_struct.h */
char *, /* filename of exo2 file */
int, /* verbosity flag */
int)); /* task */
extern void init_exo_struct /* "rd_exo.c" */
PROTO((Exo_DB *)); /* ptr to whole database in memory */
extern int free_exo /* "rd_exo.c" */
PROTO((Exo_DB *)); /* pointer to EXODUS II FE db structure */
extern void alloc_exo_nv
PROTO((Exo_DB *));
extern void alloc_exo_gv
PROTO((Exo_DB *, int ));
extern void alloc_exo_ev
PROTO((Exo_DB *, int ));
extern int wr_mesh_exo /* wr_exo.c */
PROTO((Exo_DB *, /* exo - ptr to full ripe EXODUS II fe db */
char *, /* filename - where to write */
int)); /* verbosity - talk while writing */
extern void wr_resetup_exo /* wr_exo.c */
PROTO((Exo_DB *, /* exo - ptr to full ripe EXODUS II fe db */
char *, /* filename - where to write */
int )); /* verbosity - 0 for quiet, more to talk */
void
wr_result_exo(Exo_DB *exo,
char *filename,
int verbosity,
int write_node_vars,
int write_elem_vars);
extern void zero_base /* utils.c */
PROTO((Exo_DB *)); /* E - pointer to an EXODUS II database */
extern void one_base /* utils.c */
PROTO((Exo_DB *)); /* x = pointer to an EXODUS II FE database */
extern int get_filename_num_procs /* utils.c */
PROTO((const char *)); /* basename - of polylithic files */
extern int rd_dpi /* rd_dpi.c */
PROTO((Dpi *, /* fantastic structure defd in "dpi.h" */
char *, /* fn - filename */
int )); /* verbosity - how much to talk */
extern int wr_dpi /* wr_dpi.c */
PROTO((Dpi *, /* fantastic structure defd in "dpi.h" */
char *, /* filename */
int )); /* verbosity - how much to talk */
extern void free_dpi /* rd_dpi.c */
PROTO((Dpi *)); /* fantastic structure defd in "dpi.h" */
extern void free_dpi_uni /* rd_dpi.c */
PROTO((Dpi *)); /* fantastic structure defd in "dpi.h" */
extern void multiname /* rd_mesh.c */
PROTO((char *, /* in_name - generic global name "pref.suf" */
int, /* integer processor_name */
int)); /* number_processors - total */
extern void strip_suffix /* rd_mesh.c */
PROTO((char *, /* result - "a" */
char *)); /* in -- input string "a.b" */
extern void get_suffix /* rd_mesh.c */
PROTO((char *, /* result -- "b" */
char *)); /* in -- extract the tail of "a.b" -> "b" */
extern void build_big_bones
PROTO((Exo_DB *, /* EXODUS info from representative polylith */
Dpi *, /* distributed processing info from polylith */
Exo_DB *)); /* ptr to monolithic EXODUS II database */
extern void build_global_conn /* bbb.c */
PROTO((Exo_DB *, /* EXODUS info from representative polylith */
Dpi *, /* distributed processing info from polylith */
Exo_DB *)); /* ptr to monolithic EXODUS II database */
extern void build_global_attr /* bbb.c */
PROTO((Exo_DB *, /* EXODUS info from representative polylith */
Dpi *, /* distributed processing info from polylith */
Exo_DB *)); /* ptr to monolithic EXODUS II database */
extern void build_global_coords /* bbb.c */
PROTO((Exo_DB *, /* EXODUS info from representative polylith */
Dpi *, /* distributed processing info from polylith */
Exo_DB *)); /* ptr to monolithic EXODUS II database */
extern void build_global_ns /* bbb.c */
PROTO((Exo_DB *, /* EXODUS info from representative polylith */
Dpi *, /* distributed processing info from polylith */
Exo_DB *)); /* ptr to monolithic EXODUS II database */
extern void build_global_ss /* bbb.c */
PROTO((Exo_DB *, /* EXODUS info from representative polylith */
Dpi *, /* distributed processing info from polylith */
Exo_DB *)); /* ptr to monolithic EXODUS II database */
extern void build_global_res /* bbb.c */
PROTO((Exo_DB *, /* EXODUS info from representative polylith */
Dpi *, /* distributed processing info from polylith */
Exo_DB *)); /* ptr to monolithic EXODUS II database */
/*
* Prototypes of functions defined in this file.
*/
static void usage
PROTO((const int)); /* status */
static void setup_exo_res_desc /* fix.c */
PROTO((Exo_DB *)); /* exo - ptr to database */
static void
usage(const int status)
{
if (status != 0)
{
fprintf(stderr, ("Try `%s -h' for help.\n"),
program_name);
}
else
{
fprintf(stdout,
"Usage: %s [OPTIONS] basename\n",
program_name);
fprintf(stdout, "\n");
fprintf(stdout, "Reconstruct a monolithic EXODUS II file from\n");
fprintf(stdout, "multiple polylithic EXODUS II files of the form\n");
fprintf(stdout, "basename_1ofn.exoII, ..., basename_nofn.exoII.\n");
fprintf(stdout, "\n");
fprintf(stdout, "OPTIONS:\n");
fprintf(stdout, "\t-h show options summary (this message)\n");
fprintf(stdout, "\t-n P explicitly assemble from P pieces\n");
fprintf(stdout, "\t (default deduces P from basename and files in cwd)\n");
fprintf(stdout, "\n");
fprintf(stdout, "\t-o file name for reconstructed monolith\n");
fprintf(stdout, "\t (default is basename.exoII)\n");
fprintf(stdout, "\t-v print code version\n");
fprintf(stdout, "\n");
}
exit(status);
}
int
main (int argc, char *argv[], char *envp[])
{
int c; /* hold each option flag */
int err;
int i;
int num_procs=1; /* from which to build the monolith */
int p, pmax = 0, num_node_var_max=0;
int status = 0; /* in case anything goes wrong */
int t;
Exo_DB *mono; /* monolith mesh */
Exo_DB *poly; /* polylith mesh+dpi+results in */
Dpi *dpin; /* polylith dpi in */
char monolith_file_name [FILENAME_MAX_ACK]; /* original mesh */
char polylith_basename [FILENAME_MAX_ACK]; /* broken results */
char polylith_name [FILENAME_MAX_ACK]; /* "basename_1of2.exoII" */
char err_msg[MAX_CHAR_ERR_MSG];
char *tmp; /* char pointer junkyard of no interest */
extern char *optarg;
extern int optind;
Spfrtn sr=0;
program_name = argv[0];
/*
* Defaults
*/
for ( i=0; i<FILENAME_MAX_ACK; i++)
{
monolith_file_name[i] = '\0';
polylith_basename[i] = '\0';
polylith_name[i] = '\0';
}
tmp = strcpy(monolith_file_name, "in.exoII");
tmp = strcpy(polylith_basename, "out");
if ( argc < 2 )
{
usage(0);
}
/*
* Process any command line options.
*/
while ( ( c = getopt(argc, argv, "b:hn:o:v")) != EOF )
{
#ifdef DEBUG
fprintf(stderr, "Processing with argc=%d\n", argc);
#endif
switch(c)
{
case 'h':
/*
* Show synopsis of help.
*/
show_help |= TRUE;
usage(status);
break;
case 'n':
err = sscanf(optarg, "%d", &num_procs);
#ifdef DEBUG
fprintf(stderr, "Processing with optind=%d, optarg=%s, argc=%d\n",
optind, optarg, argc);
#endif
if ( err != 1 || num_procs < 1 )
{
EH(-1,
"For number of pieces, specify one positive nonzero integer.");
}
num_procs_specified = TRUE;
break;
case 'o':
tmp = strcpy(monolith_file_name, optarg);
#ifdef DEBUG
fprintf(stderr, "Processing with optind=%d, optarg=%s, argc=%d\n",
optind, optarg, argc);
#endif
break;
case 'q':
/*
* Quiet operation mode.
*/
be_quiet |= TRUE;
if ( be_verbose )
{
show_help |= TRUE;
status = -1;
}
break;
case 'v':
/*
* Print code version and exit.
*/
fprintf(stdout, "%s\n", BRK_VERSION);
exit(0);
#if 0
be_verbose |= TRUE;
if ( be_quiet )
{
show_help |= TRUE;
status = -1;
}
#endif
break;
default:
show_help = TRUE;
status = -1;
break;
}
}
if ( optind > argc )
{
fprintf(stderr, "optind = %d, argc = %d\n", optind, argc);
usage(-1);
}
#ifdef DEBUG
fprintf(stderr, "Opts done: optind=%d, argc=%d\n",
optind, argc); /* , optind, argv[optind]);*/
#endif
tmp = strcpy(polylith_basename, argv[optind]);
optind++;
/*
* If the number of processors was not specified, then try to figure
* it out...
*/
if ( ! num_procs_specified )
{
num_procs = get_filename_num_procs(polylith_basename);
fprintf(stderr, "Found %d pieces\n", num_procs);
}
if ( num_procs < 1 )
{
sr = sprintf(err_msg, "Bad number of processors specified: %d.",
num_procs);
EH(-1, err_msg);
}
if ( show_help )
{
usage(status);
}
if ( ! be_quiet )
{
fprintf(stdout, "%s %s - %s\n%s\n", program_name, program_version,
program_description, copyright);
}
/*
* Turn off annoying error reporting from within the EXODUS II API...
*/
ex_opts(EX_VERBOSE);
/* Here we will loop through the pieces and find that which represents the most
* nodal variables to help with sizing of the monolith. PRS-6/1/2010
*/
for ( p=0; p<num_procs; p++)
{
strcpy(polylith_name, polylith_basename);
strcat(polylith_name, ".exoII");
strcpy(monolith_file_name, polylith_name);
multiname(polylith_name, p, num_procs);
#ifdef DEBUG
/* err = sscanf(line, "%s", in_exodus_file_name); */
fprintf(stderr, "monolith EXODUSII file = \"%s\"\n", monolith_file_name);
#endif
/*
* Make preliminary space for the monolithic database and the
* polylithic pieces.
*
* The strategy will be to look closely at the first polylithic piece
* in order to ascribe basic sizing information to the monolith.
*
* Then, the polyliths are traversed to slowly build the mesh and the
* results of the monolith. Several passes may be necessary...
*/
poly = (Exo_DB *) smalloc(sizeof(Exo_DB));
dpin = (Dpi *) smalloc(sizeof(Dpi));
/*
* Open the first polylith to determine if there are many timeplanes
* of data.
*
* Assume that the first polylith is representative, that the number
* of nodal variables, the number of timeplanes, etc will be the same
* for each and every polylith encountered hereafter.
*
* The first polylith is important, too, in that much of the sizing
* information for the global problem will be derived from it.
*/
init_exo_struct(poly);
init_dpi_struct(dpin);
/*
* Some defaults are different for polylithic pieces - they have use these
* maps to relate themselves to the monolith...
*
* Now, these maps are part of the Dpi information and no longer piggybacked
* inside EXODUS II. Thus, don't attempt to read them if they aren't there.
*/
#ifdef DEBUG
fprintf(stderr, "Fix: attempting to build a %d piece %s from %s pieces\n",
num_procs, monolith_file_name, polylith_basename);
#endif
/*
* Read everything in the 1st polylith's EXODUS information except for
* the results data per se...
*
* Set to zero the variables that get used for allocating and writing...
*/
rd_exo(poly, polylith_name, 0, ( EXODB_ACTION_RD_INIT +
EXODB_ACTION_RD_MESH +
EXODB_ACTION_RD_RES0 ));
if (poly->num_node_vars > num_node_var_max)
{
num_node_var_max = poly->num_node_vars;
pmax = p;
}
zero_base(poly);
rd_dpi(dpin, polylith_name, 0);
free_dpi(dpin);
free(dpin);
free_exo(poly);
free(poly);
}
/*
* Now that we know which piece to use, Build the monolithic skeleton...
*/
strcpy(polylith_name, polylith_basename);
strcat(polylith_name, ".exoII");
strcpy(monolith_file_name, polylith_name);
multiname(polylith_name, pmax, num_procs);
poly = (Exo_DB *) smalloc(sizeof(Exo_DB));
dpin = (Dpi *) smalloc(sizeof(Dpi));
init_exo_struct(poly);
init_dpi_struct(dpin);
rd_exo(poly, polylith_name, 0, ( EXODB_ACTION_RD_INIT +
EXODB_ACTION_RD_MESH +
EXODB_ACTION_RD_RES0 ));
zero_base(poly);
rd_dpi(dpin, polylith_name, 0);
mono = (Exo_DB *) smalloc(sizeof(Exo_DB));
init_exo_struct(mono);
/*
* This fills in sketchy material like ex_get_init(), as well as
* various array allocations and initializations in preparation for
* the polylith sweep...
*/
build_big_bones(poly, dpin, mono);
free_dpi(dpin);
free(dpin);
free_exo(poly);
free(poly);
for ( p=0; p<num_procs; p++)
{
poly = (Exo_DB *) smalloc(sizeof(Exo_DB));
dpin = (Dpi *) smalloc(sizeof(Dpi));
init_dpi_struct(dpin);
init_exo_struct(poly);
for ( i=0; i<FILENAME_MAX_ACK; i++)
{
polylith_name[i] = '\0';
}
strcpy(polylith_name, polylith_basename);
strcat(polylith_name, ".exoII");
multiname(polylith_name, p, num_procs);
/*
* Set actions...
*/
rd_exo(poly, polylith_name, 0, ( EXODB_ACTION_RD_INIT +
EXODB_ACTION_RD_MESH ) );
zero_base(poly);
rd_dpi(dpin, polylith_name, 0);
build_global_coords(poly, dpin, mono);
/*
* Contribute to the element block data...
*/
build_global_conn(poly, dpin, mono);
build_global_attr(poly, dpin, mono);
/*
* Contribute to the node set node list and distribution factor list...
*/
build_global_ns(poly, dpin, mono);
/*
* Contribute to the side set side, elem, and dist fact lists...
*/
build_global_ss(poly, dpin, mono);
free_exo(poly);
free(poly);
free_dpi(dpin);
free(dpin);
}
one_base(mono);
wr_mesh_exo(mono, monolith_file_name, 0);
wr_resetup_exo(mono, monolith_file_name, 0);
zero_base(mono);
/*
* Now sweep through polyliths while there are timeplanes of results
* and map those results into the monolith, then write them out one
* at a time.
*/
/* PRS Note (5/31/2010): this is where the memory for p->nv gets allocated
* and it is based on the num_nod_vars set above */
setup_exo_res_desc(mono);
#ifdef DEBUG
fprintf(stderr, "mono->num_times = %d\n", mono->num_times);
#endif
for ( t=0; t<mono->num_times; t++)
{
for ( p=0; p<num_procs; p++)
{
poly = (Exo_DB *) smalloc(sizeof(Exo_DB));
dpin = (Dpi *) smalloc(sizeof(Dpi));
/*
* Initialize to semisanity...
*/
init_dpi_struct(dpin);
init_exo_struct(poly);
for ( i=0; i<FILENAME_MAX_ACK; i++)
{
polylith_name[i] = '\0';
}
strcpy(polylith_name, polylith_basename);
strcat(polylith_name, ".exoII");
multiname(polylith_name, p, num_procs);
/*
* Set actions - what to fetch from the polylith databases.
*/
rd_exo(poly, polylith_name, 0, ( EXODB_ACTION_RD_INIT +
EXODB_ACTION_RD_MESH +
EXODB_ACTION_RD_RES0 ));
zero_base(poly);
rd_dpi(dpin, polylith_name, 0);
/*
* Now indicate what variables and time planes to read from the
* individual polyliths...
*/
#ifdef DEBUG
fprintf(stderr, "\nBuilding results for proc=%d, time=%d\n", p, t);
#endif
setup_exo_res_desc(poly);
#ifdef DEBUG
fprintf(stderr, "A mono->nv_time_indeces[0] = %d\n",
mono->nv_time_indeces[0]);
fprintf(stderr, "A poly->nv_time_indeces[0] = %d\n",
poly->nv_time_indeces[0]);
#endif
/*
* Pick one timeplane to pick - this one!
*/
if ( mono->num_glob_vars > 0 )
{
mono->gv_time_indeces[0] = t+1;
}
if ( mono->num_elem_vars > 0 )
{
mono->ev_time_indeces[0] = t+1;
}
if ( mono->num_node_vars > 0 )
{
mono->nv_time_indeces[0] = t+1;
}
if ( poly->num_glob_vars > 0 )
{
poly->gv_time_indeces[0] = t+1;
}
if ( poly->num_node_vars > 0 )
{
poly->nv_time_indeces[0] = t+1;
}
if ( poly->num_elem_vars > 0 )
{
poly->ev_time_indeces[0] = t+1;
}
#ifdef DEBUG
fprintf(stderr, "B mono->nv_time_indeces[0] = %d\n",
mono->nv_time_indeces[0]);
fprintf(stderr, "B poly->nv_time_indeces[0] = %d\n",
poly->nv_time_indeces[0]);
#endif
/*
* This assignment will help rd_exo() figure out to allocate
* enough space to read in one timeplane with ALL the nodal
* variables that are in the database.
*/
poly->num_nv_indeces = poly->num_node_vars;
rd_exo(poly, polylith_name, 0, ( EXODB_ACTION_RD_RESN +
EXODB_ACTION_RD_RESE +
EXODB_ACTION_RD_RESG ) );
#ifdef DEBUG
fprintf(stderr, "C mono->nv_time_indeces[0] = %d\n",
mono->nv_time_indeces[0]);
fprintf(stderr, "C poly->nv_time_indeces[0] = %d\n",
poly->nv_time_indeces[0]);
#endif
/*
* Map the polylith's results into the monolith...
*/
build_global_res(poly, dpin, mono);
#ifdef DEBUG
fprintf(stderr, "D mono->nv_time_indeces[0] = %d\n",
mono->nv_time_indeces[0]);
fprintf(stderr, "D poly->nv_time_indeces[0] = %d\n",
poly->nv_time_indeces[0]);
#endif
free_dpi(dpin);
free(dpin);
free_exo(poly);
free(poly);
}
/*
* Now, write out the global results at this particular timeplane.
*/
one_base(mono);
#ifdef DEBUG
fprintf(stderr,
"About to wr_results at t=%d, mono->nv_time_indeces[0]=%d\n",
t, mono->nv_time_indeces[0]);
#endif
wr_result_exo(mono, monolith_file_name, 0, 1, 1);
if ( mono->num_glob_vars > 0 ) {
mono->cmode = EX_WRITE;
mono->io_wordsize = 0; /* i.e., query */
mono->comp_wordsize = sizeof(dbl);
mono->exoid = ex_open(mono->path,
mono->cmode,
&mono->comp_wordsize,
&mono->io_wordsize,
&mono->version);
/*status = ex_put_var_param(mono->exoid, "g", mono->num_glob_vars);
EH(status, "ex_put_var_param(g)");
*/
status = ex_put_var_names(mono->exoid, "g", mono->num_glob_vars,
mono->glob_var_names);
EH(status, "ex_put_var_names(g)");
for (i = 0; i < mono->num_gv_time_indeces; i++) {
status = ex_put_glob_vars(mono->exoid, mono->gv_time_indeces[i],
mono->num_glob_vars,
mono->gv[i]);
EH(status, "ex_put_glob_vars");
}
status = ex_close(mono->exoid);
EH(status, "ex_close()");
}
zero_base(mono);
}
free_exo(mono);
free(mono);
if ( tmp == NULL ) exit(2);
if ( sr < 0 ) exit(2);
return(0);
}
/* multiname() -- translate filename string to distributed processing version
*
*
* Description:
*
* Many data file names will be unique to a given processor. Construct that
* name for this processor. The names will be translate like this
*
* Old name: "basename.suffix"
*
* New name: "basename_13of437.suffix"
*
* Note: The input string is assumed to have sufficient space allocated to
* contain the revised name.
*
* Processors, while named beginning at zero, are incremented so that
* the string reads 1ofn, 2ofn, ...., nofn and NOT
* 0ofn, 1ofn, ..., n-1ofn.
*
*
* Created: 1997/07/09 13:18 MDT pasacki@sandia.gov
*
* Revised:
*/
void
multiname(char *in_name,
int processor_name,
int number_processors)
{
char err_msg[1024];
Spfrtn sr=0;
if ( number_processors == 1 ) return;
if ( processor_name < 0 )
{
sr = sprintf(err_msg, "processor_name = %d ( less than zero).",
processor_name);
EH(-1, err_msg);
EH(sr, err_msg);
}
else if ( processor_name > number_processors - 1 )
{
sr = sprintf(err_msg, "processor_name = %d ( too high ).",
processor_name);
EH(-1, err_msg);
}
if ( number_processors < 1 )
{
sr = sprintf(err_msg, "number_processors = %d ( less than one ).",
number_processors);
EH(-1, err_msg);
}
sprintf(in_name, "%s.%d.%d", in_name, number_processors, processor_name);
return;
}
/*
* strip_suffix() -- chop off trailing characters and the period in a string
*
* Description:
* The input string is examined from back to front until a period is
* found or the beginning of the string is reached. A new string is allocated
* and filled with everything but the suffix. Thus "a.b" -> "a"
*
* Created: 1997/07/09 16:10 MDT pasacki@sandia.gov
*/
void
strip_suffix(char *result,
char *in)
{
int i,j;
int e;
e = strlen(in);
if ( e < 1 ) exit(-1);
/*
* Starting from the end of the string, look back until we find a
* period "." character.
*/
i = e;
while ( i>0 && *(in+i) != '.' ) i--;
for ( j=0; j<i; j++)
{
result[j] = *(in+j);
}
result[i] = '\0';
/*
* No suffix found? Then the whole string is the basename.
*/
if ( i == 0 )
{
strcpy(result, in);
}
return;
}
/*
* get_suffix() -- extract the tail substring of a string past the last period
*
* Created: 1997/07/09 16:14 MDT pasacki@sandia.gov
*/
void
get_suffix(char *result,
char *in)
{
int i;
int b;
int e;
e = strlen(in);
b = e;
while ( b>0 && *(in+b) != '.' ) b--;
if ( b == 0 )
{
*result = '\0';
}
else
{
for ( i=b; i<e; i++)
{
result[i-b] = in[i+1];
}
}
return;
}
/* setup_exo_res_desc() -- allocate, set arrays to rd/wr all results, 1 time
*
* Allocate and setup arrays for reading and writing EXODUS II results
* variables (nodal, global, element).
*
* Default values for some quantities are inserted after allocation. It is
* the user's responsibility to fill them in later. I.e, things like
* ev_time_indeces[], etc.
*
* These auxiliary arrays in the Exo_DB structure give instructions to
* rd_exo and wr_exo as to what to read and write, without the need to
* explicitly interact with the EXODUS II API.
*
*
* Created: 1998/08/14 06:04 MDT pasacki@sandia.gov
*
* Revised: 1998/08/15 12:43 MDT pasacki@sandia.gov
*/
static void
setup_exo_res_desc(Exo_DB *exo)
{
int i;
if ( ! ( exo->state & EXODB_STATE_RES0 ) )
{
EH(-1, "Setup to read bulk results requires preliminary info.");
}
/*
* Global variables...
*/
if ( ! ( exo->state & EXODB_STATE_GBIA ) )
{
alloc_exo_gv(exo, 1);
}
/*
* Nodal variables...
*/
if ( ! ( exo->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.