1 /*
2 Copyright (c) 1994 - 2010, Lawrence Livermore National Security, LLC.
3 LLNL-CODE-425250.
4 All rights reserved.
5
6 This file is part of Silo. For details, see silo.llnl.gov.
7
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions
10 are met:
11
12 * Redistributions of source code must retain the above copyright
13 notice, this list of conditions and the disclaimer below.
14 * Redistributions in binary form must reproduce the above copyright
15 notice, this list of conditions and the disclaimer (as noted
16 below) in the documentation and/or other materials provided with
17 the distribution.
18 * Neither the name of the LLNS/LLNL nor the names of its
19 contributors may be used to endorse or promote products derived
20 from this software without specific prior written permission.
21
22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE
26 LIVERMORE NATIONAL SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR
27 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
35 This work was produced at Lawrence Livermore National Laboratory under
36 Contract No. DE-AC52-07NA27344 with the DOE.
37
38 Neither the United States Government nor Lawrence Livermore National
39 Security, LLC nor any of their employees, makes any warranty, express
40 or implied, or assumes any liability or responsibility for the
41 accuracy, completeness, or usefulness of any information, apparatus,
42 product, or process disclosed, or represents that its use would not
43 infringe privately-owned rights.
44
45 Any reference herein to any specific commercial products, process, or
46 services by trade name, trademark, manufacturer or otherwise does not
47 necessarily constitute or imply its endorsement, recommendation, or
48 favoring by the United States Government or Lawrence Livermore
49 National Security, LLC. The views and opinions of authors expressed
50 herein do not necessarily state or reflect those of the United States
51 Government or Lawrence Livermore National Security, LLC, and shall not
52 be used for advertising or product endorsement purposes.
53 */
54
55 #include "silo_taurus_private.h"
56 #define MAKE_N DONT_USE_THIS--use ALLOC_N instead
57
58 /*-------------------------------------------------------------------------
59 * Private global variables.
60 *-------------------------------------------------------------------------
61 */
62 static char *mesh_names[] =
63 {"mesh1", "hs_mesh", "hex_mesh",
64 "shell_mesh", "beam_mesh"};
65
66 #define NDIRS 7
67
68 static char *dir_names[] =
69 {"almansi", "green", "inf_strain",
70 "nodal", "shell", "stress", "rates"};
71
72 PRIVATE int db_taur_cd(TAURUSfile *taurus, char const *path);
73 PRIVATE int db_taur_pwd(TAURUSfile *taurus, char *path);
74 INTERNAL void db_taur_extface(int *znodelist, int nnodes,
75 int nzones, int *matlist, int **fnodelist,
76 int *nfaces, int **zoneno);
77
78 /*-------------------------------------------------------------------------
79 * Function: db_taur_InitCallbacks
80 *
81 * Purpose: Initialize the callbacks for the Taurus device driver.
82 *
83 * Return: Success: void
84 *
85 * Failure:
86 *
87 * Programmer: robb@cloud
88 * Fri Dec 9 12:14:52 EST 1994
89 *
90 * Modifications:
91 * Robb Matzke, Tue Mar 7 10:43:02 EST 1995
92 * I added the callback DBNewToc.
93 *
94 * Eric Brugger, Wed Oct 4 08:46:31 PDT 1995
95 * I added the call back db_taur_InqVarExists.
96 *
97 * Brad Whitlock, Thu Apr 28 16:43:47 PST 2005
98 * Added callback for db_taur_InqVartype.
99 *
100 *-------------------------------------------------------------------------
101 */
102 PRIVATE void
db_taur_InitCallbacks(DBfile * dbfile)103 db_taur_InitCallbacks (DBfile *dbfile)
104 {
105 dbfile->pub.close = db_taur_Close;
106 dbfile->pub.g_dir = db_taur_GetDir;
107 dbfile->pub.cd = db_taur_SetDir;
108 dbfile->pub.g_comp = db_taur_GetComponent;
109 dbfile->pub.g_ma = db_taur_GetMaterial;
110 dbfile->pub.g_um = db_taur_GetUcdmesh;
111 dbfile->pub.g_uv = db_taur_GetUcdvar;
112 dbfile->pub.g_var = db_taur_GetVar;
113 dbfile->pub.g_varbl = db_taur_GetVarByteLength;
114 dbfile->pub.g_varlen = db_taur_GetVarLength;
115 dbfile->pub.i_meshname = db_taur_InqMeshname;
116 dbfile->pub.exist = db_taur_InqVarExists;
117 dbfile->pub.i_meshtype = db_taur_InqMeshtype;
118 dbfile->pub.r_var = db_taur_ReadVar;
119 dbfile->pub.newtoc = db_taur_NewToc;
120 dbfile->pub.module = db_taur_Filters;
121 dbfile->pub.inqvartype = db_taur_InqVartype;
122 }
123
124 /*-------------------------------------------------------------------------
125 * Function: reduce_path
126 *
127 * Purpose:
128 *
129 * Return: Success:
130 *
131 * Failure:
132 *
133 * Programmer:
134 *
135 * Modifications:
136 *
137 * Jim Reus, 23 Apr 97
138 * Change to prototype form.
139 *
140 *-------------------------------------------------------------------------
141 */
142 static void
reduce_path(char * path)143 reduce_path (char *path)
144 {
145 int i, j;
146 int lpath;
147 char *npath;
148
149 npath = ALLOC_N(char, strlen(path) + 1);
150
151 npath[0] = '/';
152 npath[1] = '\0';
153 j = 0;
154 lpath = strlen(path);
155 for (i = 0; i < lpath; i++) {
156 while (path[i] == '/' && path[i + 1] == '/')
157 i++;
158 if (path[i] == '/' && path[i + 1] == '.' && path[i + 2] == '.' &&
159 (path[i + 3] == '/' || path[i + 3] == '\0')) {
160 if (j > 0)
161 j--;
162 while (npath[j] != '/' && j > 0)
163 j--;
164 i += 2;
165 }
166 else {
167 npath[j++] = path[i];
168 }
169 }
170 npath[j] = '\0';
171
172 if (j == 0) {
173 npath[0] = '/';
174 npath[1] = '\0';
175 }
176 strcpy(path, npath);
177 }
178
179 /*-------------------------------------------------------------------------
180 * Function: get_next_int
181 *
182 * Purpose: Return a sequential list of integers beginning with 1.
183 *
184 * Return: Success: n
185 *
186 * Failure: never fails
187 *
188 * Programmer: robb@cloud
189 * Fri Dec 9 15:56:58 EST 1994
190 *
191 * Modifications:
192 *
193 * Jim Reus, 23 Apr 97
194 * Change to prototype form.
195 *
196 *-------------------------------------------------------------------------
197 */
198 static int
get_next_int(void)199 get_next_int (void)
200 {
201 static int n = 0;
202
203 return ++n;
204 }
205
206 /*-------------------------------------------------------------------------
207 * Function: db_taur_Open
208 *
209 * Purpose: Open a Taurus database.
210 *
211 * Return: Success: ptr to new file
212 *
213 * Failure: NULL
214 *
215 * Programmer:
216 *
217 * Modifications:
218 * Eric Brugger, Fri Jan 27 08:27:46 PST 1995
219 * I changed the call DBGetToc to db_taur_GetToc.
220 *
221 * Robb Matzke, Tue Mar 7 10:43:02 EST 1995
222 * I changed the call db_taur_GetToc to DBNewToc.
223 *
224 * Sean Ahern, Thu Oct 5 09:16:31 PDT 1995
225 * Fixed a parameter type problem.
226 *
227 * Sean Ahern, Mon Jan 8 17:41:26 PST 1996
228 * Added the mode parameter. The mode information is not yet
229 * Used in the function.
230 *
231 *-------------------------------------------------------------------------*/
232 /* ARGSUSED */
233 PUBLIC DBfile *
db_taur_Open(char const * name,int mode,int subtype)234 db_taur_Open(char const *name, int mode, int subtype)
235 {
236 TAURUSfile *taurus;
237 DBfile_taur *dbfile;
238 char *me = "db_taur_Open";
239
240 if (!SW_file_exists(name)) {
241 db_perror(name, E_NOFILE, me);
242 return NULL;
243 }
244 else if (!SW_file_readable(name)) {
245 db_perror("not readable", E_NOFILE, me);
246 return NULL;
247 }
248
249 if ((taurus = db_taur_open(name)) == NULL) {
250 db_perror("db_taur_open", E_CALLFAIL, me);
251 return NULL;
252 }
253
254 dbfile = ALLOC(DBfile_taur);
255 memset(dbfile, 0, sizeof(DBfile_taur));
256 dbfile->pub.name = STRDUP(name);
257 dbfile->pub.type = DB_TAURUS;
258 dbfile->taurus = taurus;
259 db_taur_InitCallbacks((DBfile*)dbfile);
260 DBNewToc((DBfile *) dbfile);
261 return (DBfile *) dbfile;
262 }
263
264 /*-------------------------------------------------------------------------
265 * Function: db_taur_Close
266 *
267 * Purpose: Close a Taurus database.
268 *
269 * Return: Success: NULL
270 *
271 * Failure:
272 *
273 * Programmer:
274 *
275 * Modifications:
276 *
277 * Eric Brugger, Mon Feb 27 16:01:37 PST 1995
278 * I changed the return value to be an integer instead of a pointer
279 * to a DBfile.
280 *
281 * Jim Reus, 23 Apr 97
282 * Changed to prototype form.
283 *
284 *-------------------------------------------------------------------------
285 */
286 SILO_CALLBACK int
db_taur_Close(DBfile * _dbfile)287 db_taur_Close (DBfile *_dbfile)
288 {
289 DBfile_taur *dbfile = (DBfile_taur *) _dbfile;
290
291 if (dbfile) {
292 /*
293 * Free the private parts of the file.
294 */
295 db_taur_close(dbfile->taurus);
296 dbfile->taurus = NULL;
297
298 /*
299 * Free the public parts of the file.
300 */
301 silo_db_close(_dbfile);
302 }
303 return 0;
304 }
305
306 /*-------------------------------------------------------------------------
307 * Function: db_taur_GetDir
308 *
309 * Purpose: Returns the name of the current directory.
310 *
311 * Return: Success: 0
312 *
313 * Failure: never fails
314 *
315 * Programmer:
316 *
317 * Modifications:
318 *
319 *-------------------------------------------------------------------------
320 */
321 SILO_CALLBACK int
db_taur_GetDir(DBfile * _dbfile,char * path)322 db_taur_GetDir(DBfile *_dbfile, char *path)
323 {
324 DBfile_taur *dbfile = (DBfile_taur *) _dbfile;
325
326 db_taur_pwd(dbfile->taurus, path);
327 return 0;
328 }
329
330 /*-------------------------------------------------------------------------
331 * Function: db_taur_SetDir
332 *
333 * Purpose: Sets the current directory within the Taurus database.
334 *
335 * Return: Success: 0
336 *
337 * Failure: -1
338 *
339 * Programmer:
340 *
341 * Modifications:
342 * Eric Brugger, Fri Jan 27 08:27:46 PST 1995
343 * I changed the call DBGetToc to db_taur_GetToc.
344 *
345 * Robb Matzke, Tue Mar 7 10:43:20 EST 1995
346 * I changed the call db_taur_GetToc to DBNewToc.
347 *
348 *-------------------------------------------------------------------------
349 */
350 SILO_CALLBACK int
db_taur_SetDir(DBfile * _dbfile,char const * path)351 db_taur_SetDir(DBfile *_dbfile, char const *path)
352 {
353 DBfile_taur *dbfile = (DBfile_taur *) _dbfile;
354 char *me = "db_taur_SetDir";
355
356 if (db_taur_cd(dbfile->taurus, path) < 0) {
357 return db_perror("db_taur_cd", E_CALLFAIL, me);
358 }
359
360 /* Must make new table-of-contents since dir has changed */
361 db_FreeToc(_dbfile);
362 DBNewToc(_dbfile);
363 return (0);
364 }
365
366 /*-------------------------------------------------------------------------
367 * Function: db_taur_Filters
368 *
369 * Purpose: Print the name of this filter to the specified stream.
370 *
371 * Return: Success: 0
372 *
373 * Failure: never fails
374 *
375 * Programmer: robb@cloud
376 * Tue Mar 7 11:18:19 EST 1995
377 *
378 * Modifications:
379 *
380 *-------------------------------------------------------------------------
381 */
382 /* ARGSUSED */
383 SILO_CALLBACK int
db_taur_Filters(DBfile * dbfile,FILE * stream)384 db_taur_Filters(DBfile *dbfile, FILE *stream)
385 {
386 fprintf(stream, "Taurus Device Driver\n");
387 return 0;
388 }
389
390 /*-------------------------------------------------------------------------
391 * Function: db_taur_NewToc
392 *
393 * Purpose: Free the old table of contents (toc) and read a new
394 * one.
395 *
396 * Return: Success: 0
397 *
398 * Failure: -1
399 *
400 * Programmer:
401 *
402 * Modifications:
403 * Robb Matzke, Fri Dec 9 13:58:52 EST 1994
404 * Memory management is with macros defined in silo_private.h (which
405 * are normally bound to the C library malloc family). The function
406 * builds a table of contents for the DBfile pointer and returns an
407 * int instead of returning a table of contents. The old table
408 * of contents is freed.
409 *
410 * Eric Brugger, Fri Jan 27 08:27:46 PST 1995
411 * I made it into an internal routine.
412 *
413 * Robb Matzke, Tue Feb 21 16:19:37 EST 1995
414 * Removed references to the `id' fields of the DBtoc.
415 *
416 * Robb Matzke, Tue Mar 7 10:44:02 EST 1995
417 * Changed the name from db_taur_GetToc to db_taur_NewToc.
418 *
419 * Robb Matzke, Tue Mar 7 11:23:19 EST 1995
420 * Changed this to a CALLBACK.
421 *
422 * Eric Brugger, Tue Mar 28 15:54:19 PST 1995
423 * I corrected the spelling of the material variable name when no
424 * state data is present.
425 *
426 * Eric Brugger, Wed Apr 26 14:13:03 PDT 1995
427 * I modified the code to work properly with state directories.
428 *
429 * Eric Brugger, Thu Jul 27 13:18:52 PDT 1995
430 * I modified the routine to handle files generated by hydra.
431 *
432 * Brad Whitlock, Thu Apr 28 15:42:05 PST 2005
433 * I modified the routine so it exposes more of the meshes that are used
434 * by the various variables that we added to the toc. This helps VisIt
435 * read Taurus files.
436 *
437 *-------------------------------------------------------------------------
438 */
439 SILO_CALLBACK int
db_taur_NewToc(DBfile * _dbfile)440 db_taur_NewToc(DBfile *_dbfile)
441 {
442 DBfile_taur *dbfile = (DBfile_taur *) _dbfile;
443 TAURUSfile *taurus = dbfile->taurus;
444 int i, j, k;
445 int idir;
446 DBtoc *toc;
447
448 db_FreeToc(_dbfile);
449 dbfile->pub.toc = toc = db_AllocToc();
450
451 if (taurus->state == -1) {
452 if (taurus->nstates == 0) {
453 /*
454 * We have no solution data, only the mesh and
455 * materials. In this case we have no directories.
456 */
457 toc->ucdmesh_names = ALLOC_N(char *, 1);
458
459 toc->ucdmesh_names[0] = STRDUP("mesh1");
460 toc->ucdmesh_names[1] = STRDUP("hs_mesh");
461 toc->nucdmesh = 2;
462
463 toc->mat_names = ALLOC_N(char *, 1);
464
465 toc->mat_names[0] = STRDUP("mat1");
466 toc->nmat = 1;
467 }
468 else {
469 /*
470 * We are at the top level so we have only directories.
471 */
472 toc->ucdmesh_names = NULL;
473 toc->nucdmesh = 0;
474
475 toc->ucdvar_names = NULL;
476 toc->nucdvar = 0;
477
478 toc->mat_names = NULL;
479 toc->nmat = 0;
480
481 toc->dir_names = ALLOC_N(char *, taurus->nstates);
482
483 for (i = 0; i < taurus->nstates; i++) {
484 toc->dir_names[i] = ALLOC_N(char, 12);
485
486 if (taurus->nstates < 100) {
487 sprintf(toc->dir_names[i], "state%02d", i);
488 }
489 else {
490 sprintf(toc->dir_names[i], "state%03d", i);
491 }
492 }
493 toc->ndir = taurus->nstates;
494 }
495 }
496 else {
497 /*
498 * We are in a state.
499 */
500 if (taurus->idir == -1) {
501 /*
502 * We are at the top of a state, we have the
503 * meshes, materials.
504 */
505 toc->ucdmesh_names = ALLOC_N(char *, 2);
506
507 toc->ucdmesh_names[0] = STRDUP("mesh1");
508 toc->ucdmesh_names[1] = STRDUP("hs_mesh");
509 toc->nucdmesh = 2;
510
511 toc->mat_names = ALLOC_N(char *, 1);
512
513 toc->mat_names[0] = STRDUP("mat1");
514 toc->nmat = 1;
515 }
516
517 if (taurus->icode == 1)
518 idir = 8;
519 else if (taurus->icode == 200)
520 idir = 9;
521 else
522 idir = taurus->idir;
523 if (idir == -1) {
524 /*
525 * We are not in a directory, also have directories.
526 */
527 toc->dir_names = ALLOC_N(char *, NDIRS);
528
529 for (i = 0; i < NDIRS; i++)
530 toc->dir_names[i] = STRDUP(dir_names[i]);
531 toc->ndir = NDIRS;
532 }
533 else {
534 /*
535 * We are in a directory, get the variables from
536 * the directory.
537 */
538 for (i = 0; taur_var_list[i].idir < idir; i++)
539 /* do nothing */ ;
540
541 k = 0;
542 for (j = i; taur_var_list[j].idir == idir; j++) {
543 if (taurus->var_start[taur_var_list[j].ival] != -1)
544 k++;
545 }
546 toc->nucdvar = k;
547 toc->ucdvar_names = ALLOC_N(char *, k);
548
549 k = 0;
550 for (j = i; taur_var_list[j].idir == idir; j++) {
551 if (taurus->var_start[taur_var_list[j].ival] != -1)
552 toc->ucdvar_names[k++] = STRDUP(taur_var_list[j].name);
553 }
554 }
555 }
556
557 return 0;
558 }
559
560 /*-------------------------------------------------------------------------
561 * Function: db_taur_GetComponent
562 *
563 * Purpose: Returns a pointer to a newly allocated space containing
564 * the component value.
565 *
566 * Return: Success: ptr to component
567 *
568 * Failure: NULL
569 *
570 * Programmer:
571 *
572 * Modifications:
573 * Eric Brugger, Wed Apr 26 14:13:03 PDT 1995
574 * I modified the code to work properly with state directories.
575 *
576 * Eric Brugger, Fri Sep 24 09:24:58 PDT 1999
577 * I modified the routine to also return the matnos component of
578 * the mat1 object.
579 *
580 *-------------------------------------------------------------------------
581 */
582 SILO_CALLBACK void *
db_taur_GetComponent(DBfile * _dbfile,char const * obj_name,char const * comp_name)583 db_taur_GetComponent(DBfile *_dbfile, char const *obj_name, char const *comp_name)
584 {
585 DBfile_taur *dbfile = (DBfile_taur *) _dbfile;
586 TAURUSfile *taurus = dbfile->taurus;
587 int *v;
588 char *me = "db_taur_GetComponent";
589
590 if (taurus->state == -1 && taurus->nstates != 0) {
591 db_perror(NULL, E_TAURSTATE, me);
592 return (NULL);
593 }
594 if (taurus->idir != -1) {
595 db_perror(NULL, E_NOTFOUND, me);
596 return (NULL);
597 }
598
599 /*
600 * We only support the components "nmat" and "matnos" from the
601 * object "mat1".
602 */
603 if (strcmp(obj_name, "mat1") == 0) {
604 if (strcmp(comp_name, "nmat") == 0) {
605 v = ALLOC_N(int, 1);
606 *v = taurus->nmat;
607 }
608 else if (strcmp(comp_name, "matnos") == 0) {
609 v = ALLOC_N(int, taurus->nmat);
610 memcpy (v, taurus->matnos, taurus->nmat * sizeof(int));
611 }
612 else {
613 db_perror("comp_name!=\"nmat\" or comp_name!=\"matnos\"",
614 E_NOTIMP, me);
615 return (NULL);
616 }
617 }
618 else {
619 db_perror("obj_name!=\"mat1\"", E_NOTIMP, me);
620 return (NULL);
621 }
622
623 return v;
624 }
625
626 /*-------------------------------------------------------------------------
627 * Function: db_taur_GetMaterial
628 *
629 * Purpose: Allocates a DBmaterial data structure and reads material
630 * data from the Taurus database.
631 *
632 * Return: Success: ptr to DBmaterial.
633 *
634 * Failure: NULL
635 *
636 * Programmer:
637 *
638 * Modifications:
639 * Eric Brugger, Wed Apr 26 14:13:03 PDT 1995
640 * I modified the code to work properly with state directories.
641 *
642 * Eric Brugger, Mon Aug 28 13:40:41 PDT 1995
643 * I modified the routine to return the matnos array added to the
644 * TAURUSfile structure as the matnos, instead of returning an array
645 * of integers from 1 to nmat.
646 *
647 * Eric Brugger, Thu Dec 21 07:51:53 PST 1995
648 * I modified the code to handle the activity data.
649 *
650 *-------------------------------------------------------------------------
651 */
652 SILO_CALLBACK DBmaterial *
db_taur_GetMaterial(DBfile * _dbfile,char const * mat_name)653 db_taur_GetMaterial(DBfile *_dbfile, char const *mat_name)
654 {
655 DBfile_taur *dbfile = (DBfile_taur *) _dbfile;
656 TAURUSfile *taurus = dbfile->taurus;
657 int i, j;
658 int nhex, nshell, nbeam;
659 int nhex2, nshell2, nbeam2;
660 int *buf;
661 DBmaterial *mat;
662 char *me = "db_taur_GetMaterial";
663
664 if (taurus->state == -1 && taurus->nstates != 0) {
665 db_perror(NULL, E_TAURSTATE, me);
666 return (NULL);
667 }
668 if (taurus->idir != -1) {
669 db_perror(NULL, E_NOTFOUND, me);
670 return (NULL);
671 }
672
673 /*
674 * Get the material.
675 */
676 if (taurus->mesh_read == 0)
677 init_mesh_info(taurus);
678
679 if (taurus->coord_state != taurus->state) {
680 init_coord_info (taurus);
681 init_zone_info (taurus);
682 }
683
684 mat = DBAllocMaterial();
685
686 mat->id = get_next_int();
687 mat->name = STRDUP(mat_name);
688 mat->ndims = taurus->ndim;
689 mat->origin = 0;
690 mat->dims[0] = taurus->nhex +
691 taurus->nshell +
692 taurus->nbeam;
693 mat->dims[1] = 1;
694 mat->dims[2] = 1;
695 mat->major_order = 1;
696 mat->stride[0] = 1;
697 mat->stride[1] = 1;
698 mat->stride[2] = 1;
699
700 mat->nmat = taurus->nmat;
701
702 if (SILO_Globals.dataReadMask & DBMatMatnos)
703 {
704 mat->matnos = ALLOC_N(int, mat->nmat);
705
706 for (i = 0; i < mat->nmat; i++)
707 mat->matnos[i] = taurus->matnos[i];
708 }
709
710 if (SILO_Globals.dataReadMask & DBMatMatlist)
711 {
712 nhex = taurus->nhex;
713 nshell = taurus->nshell;
714 nbeam = taurus->nbeam;
715
716 mat->matlist = ALLOC_N(int, nhex + nshell + nbeam);
717
718 if (taurus->activ >= 1000 && taurus->activ <= 1005) {
719 for (i = 0, j = 0; i < nhex; i++) {
720 if (taurus->hex_activ [i] != 0) {
721 mat->matlist[j] = taurus->hex_matlist[i];
722 j++;
723 }
724 }
725 nhex2 = j;
726
727 buf = &(mat->matlist [nhex2]);
728 for (i = 0, j = 0; i < nshell; i++) {
729 if (taurus->shell_activ [i] != 0) {
730 buf[j] = taurus->shell_matlist[i];
731 j++;
732 }
733 }
734 nshell2 = j;
735
736 buf = &(mat->matlist[nhex2+nshell2]);
737 for (i = 0, j = 0; i < nbeam; i++) {
738 if (taurus->beam_activ [i] != 0) {
739 buf[j] = taurus->beam_matlist[i];
740 j++;
741 }
742 }
743 nbeam2 = j;
744
745 mat->dims[0] = nhex2 + nshell2 + nbeam2;
746 }
747 else {
748 for (i = 0; i < nhex; i++)
749 mat->matlist[i] = taurus->hex_matlist[i];
750 for (i = 0, j = nhex; i < nshell; i++, j++)
751 mat->matlist[j] = taurus->shell_matlist[i];
752 for (i = 0, j = nhex + nshell; i < nbeam; i++, j++)
753 mat->matlist[j] = taurus->beam_matlist[i];
754 }
755 }
756
757 mat->mixlen = 0;
758 mat->datatype = DB_FLOAT;
759 mat->mix_vf = NULL;
760 mat->mix_next = NULL;
761 mat->mix_mat = NULL;
762 mat->mix_zone = NULL;
763
764 return (mat);
765 }
766
767 /*-------------------------------------------------------------------------
768 * Function: db_taur_GetUcdmesh
769 *
770 * Purpose: Allocate and read a UCD mesh from the Taurus database.
771 *
772 * Return: Success: ptr to new UCD mesh
773 *
774 * Failure: NULL
775 *
776 * Programmer:
777 *
778 * Modifications:
779 * Eric Brugger, Wed Apr 26 14:13:03 PDT 1995
780 * I modified the code to work properly with state directories.
781 *
782 * Eric Brugger, Wed Dec 20 17:08:26 PST 1995
783 * I modified the code to handle the activity data.
784 *
785 * Eric Brugger, Tue Feb 6 10:24:21 PST 1996
786 * I corrected a bug, where the wrong number of elements would be
787 * returned for the shell and beam meshes.
788 *
789 *-------------------------------------------------------------------------
790 */
791 SILO_CALLBACK DBucdmesh *
db_taur_GetUcdmesh(DBfile * _dbfile,char const * mesh_name)792 db_taur_GetUcdmesh(DBfile *_dbfile, char const *mesh_name)
793 {
794 DBfile_taur *dbfile = (DBfile_taur *) _dbfile;
795 TAURUSfile *taurus = dbfile->taurus;
796 int i, j;
797 int nhex, nshell, nbeam;
798 int nhex2, nshell2, nbeam2;
799 int nhexface, nshellface, nbeamface;
800 int nshellface2, nbeamface2;
801 int imesh;
802 int *buf;
803 DBfacelist *faces;
804 DBzonelist *zones;
805 DBucdmesh *mesh;
806 char *me = "db_taur_GetUcdmesh";
807
808 if (taurus->state == -1 && taurus->nstates != 0) {
809 db_perror(NULL, E_TAURSTATE, me);
810 return (NULL);
811 }
812 if (taurus->idir != -1) {
813 db_perror(NULL, E_NOTFOUND, me);
814 return (NULL);
815 }
816
817 for (imesh = 0;
818 imesh < MAX_MESH && strcmp(mesh_names[imesh], mesh_name) != 0;
819 imesh++)
820 /* do nothing */ ;
821
822 if (imesh >= MAX_MESH) {
823 db_perror("imesh", E_NOTFOUND, me);
824 return (NULL);
825 }
826
827 /*
828 * Get the ucd mesh.
829 */
830 if (taurus->mesh_read == 0)
831 init_mesh_info (taurus);
832
833 if (taurus->coord_state != taurus->state) {
834 init_coord_info (taurus);
835 init_zone_info (taurus);
836 }
837
838 mesh = DBAllocUcdmesh();
839
840 /*
841 * Add the coordinate information and some miscellaneous information.
842 */
843 mesh->id = get_next_int();
844 mesh->block_no = 1;
845 mesh->name = STRDUP(mesh_name);
846 mesh->cycle = taurus->state;
847 mesh->time = taurus->state_time[taurus->state];
848 mesh->coord_sys = DB_CARTESIAN;
849 mesh->units[0] = STRDUP("cm");
850 mesh->units[1] = STRDUP("cm");
851 mesh->units[2] = STRDUP("cm");
852 mesh->labels[0] = STRDUP("x");
853 mesh->labels[1] = STRDUP("y");
854 mesh->labels[2] = STRDUP("z");
855
856 for (i = 0; i < 3; i++) {
857 if (SILO_Globals.dataReadMask & DBUMCoords)
858 {
859 mesh->coords[i] = ALLOC_N(float, taurus->numnp);
860
861 for (j = 0; j < taurus->numnp; j++) {
862 ((float**)(mesh->coords))[i][j] = taurus->coords[i][j];
863 }
864 }
865 mesh->min_extents[i] = taurus->min_extents[i];
866 mesh->max_extents[i] = taurus->max_extents[i];
867 }
868 mesh->datatype = DB_FLOAT;
869 mesh->ndims = 3;
870 mesh->nnodes = taurus->numnp;
871 mesh->origin = 0;
872
873 /*
874 * Determine which types of zones should be included in the
875 * zone list.
876 */
877 nhex = 0;
878 nbeam = 0;
879 nshell = 0;
880 if (imesh == 0 || imesh == 1 || imesh == 2)
881 nhex = taurus->nel8;
882 if (imesh == 0 || imesh == 1 || imesh == 3)
883 nshell = taurus->nel4;
884 if (imesh == 0 || imesh == 4)
885 nbeam = taurus->nel2;
886
887 /*
888 * Add the zone information.
889 */
890
891 if (SILO_Globals.dataReadMask & DBUMZonelist)
892 {
893 zones = ALLOC_N(DBzonelist, 1);
894 zones->ndims = taurus->ndim;
895 zones->nzones = nhex + nbeam + nshell;
896 zones->nshapes = 1;
897 zones->shapecnt = ALLOC_N(int, 1);
898 zones->shapecnt[0] = nhex + nbeam + nshell;
899 zones->shapesize = ALLOC_N(int, 1);
900 zones->shapesize[0] = 8;
901 zones->lnodelist = (nhex + nbeam + nshell) * 8;
902
903 if (SILO_Globals.dataReadMask & DBCalc)
904 {
905 zones->nodelist = ALLOC_N(int, zones->lnodelist);
906
907 if (taurus->activ >= 1000 || taurus->activ <= 1005) {
908 for (i = 0, j = 0; i < nhex; i++) {
909 if (taurus->hex_activ [i] != 0) {
910 zones->nodelist[j * 8] = taurus->hex_nodelist[i * 8];
911 zones->nodelist[j * 8 + 1] = taurus->hex_nodelist[i * 8 + 1];
912 zones->nodelist[j * 8 + 2] = taurus->hex_nodelist[i * 8 + 2];
913 zones->nodelist[j * 8 + 3] = taurus->hex_nodelist[i * 8 + 3];
914 zones->nodelist[j * 8 + 4] = taurus->hex_nodelist[i * 8 + 4];
915 zones->nodelist[j * 8 + 5] = taurus->hex_nodelist[i * 8 + 5];
916 zones->nodelist[j * 8 + 6] = taurus->hex_nodelist[i * 8 + 6];
917 zones->nodelist[j * 8 + 7] = taurus->hex_nodelist[i * 8 + 7];
918 j++;
919 }
920 }
921 nhex2 = j;
922
923 buf = &(zones->nodelist[nhex2 * 8]);
924 for (i = 0, j = 0; i < nshell; i++) {
925 if (taurus->shell_activ [i] != 0) {
926 buf[j * 8] = taurus->shell_nodelist[i * 4];
927 buf[j * 8 + 1] = taurus->shell_nodelist[i * 4 + 1];
928 buf[j * 8 + 2] = taurus->shell_nodelist[i * 4 + 2];
929 buf[j * 8 + 3] = taurus->shell_nodelist[i * 4 + 3];
930 buf[j * 8 + 4] = taurus->shell_nodelist[i * 4];
931 buf[j * 8 + 5] = taurus->shell_nodelist[i * 4 + 1];
932 buf[j * 8 + 6] = taurus->shell_nodelist[i * 4 + 2];
933 buf[j * 8 + 7] = taurus->shell_nodelist[i * 4 + 3];
934 j++;
935 }
936 }
937 nshell2 = j;
938
939 buf = &(zones->nodelist[(nhex2 + nshell2) * 8]);
940 for (i = 0, j = 0; i < nbeam; i++) {
941 if (taurus->beam_activ [i] != 0) {
942 buf[j * 8] = taurus->beam_nodelist[i * 2];
943 buf[j * 8 + 1] = taurus->beam_nodelist[i * 2 + 1];
944 buf[j * 8 + 2] = taurus->beam_nodelist[i * 2];
945 buf[j * 8 + 3] = taurus->beam_nodelist[i * 2 + 1];
946 buf[j * 8 + 4] = taurus->beam_nodelist[i * 2];
947 buf[j * 8 + 5] = taurus->beam_nodelist[i * 2 + 1];
948 buf[j * 8 + 6] = taurus->beam_nodelist[i * 2];
949 buf[j * 8 + 7] = taurus->beam_nodelist[i * 2 + 1];
950 j++;
951 }
952 }
953 nbeam2 = j;
954
955 zones->nzones = nhex2 + nshell2 + nbeam2;
956 zones->shapecnt [0] = nhex2 + nshell2 + nbeam2;
957 zones->lnodelist = (nhex2 + nshell2 + nbeam2) * 8;
958 }
959 else {
960 for (i = 0, j = 0; i < nhex * 8; i++, j++)
961 zones->nodelist[j] = taurus->hex_nodelist[i];
962 for (i = 0; i < nshell * 8; i++, j++)
963 zones->nodelist[j] = taurus->shell_nodelist[i];
964 for (i = 0; i < nbeam * 8; i++, j++)
965 zones->nodelist[j] = taurus->beam_nodelist[i];
966 }
967
968 zones->origin = 0;
969 } else
970 {
971 zones->nodelist = NULL;
972 }
973 mesh->zones = zones;
974 }
975
976 /*
977 * Determine which types of zones should be included in the
978 * face list.
979 */
980 if (SILO_Globals.dataReadMask & DBUMFacelist)
981 {
982 nhexface = 0;
983 nshellface = 0;
984 nbeamface = 0;
985 if (imesh == 0 || imesh == 1 || imesh == 2)
986 nhexface = taurus->nhex_faces;
987 if (imesh == 0 || imesh == 1 || imesh == 3)
988 nshellface = taurus->nel4;
989 if (imesh == 0 || imesh == 4)
990 nbeamface = taurus->nel2;
991
992 /*
993 * Add the face information.
994 */
995 faces = ALLOC_N(DBfacelist, 1);
996 faces->ndims = taurus->ndim;
997 faces->origin = 0;
998 faces->lnodelist = nhexface * 4 + nbeamface * 2 + nshellface * 4;
999
1000 if (SILO_Globals.dataReadMask & DBCalc)
1001 {
1002 faces->nodelist = ALLOC_N(int, faces->lnodelist);
1003
1004 if (taurus->activ >= 1000 || taurus->activ <= 1005) {
1005 for (i = 0; i < nhexface*4; i++)
1006 faces->nodelist[i] = taurus->hex_facelist[i];
1007
1008 buf = &(faces->nodelist [nhexface*4]);
1009 for (i = 0, j = 0; i < nshellface; i++) {
1010 if (taurus->shell_activ [i] != 0) {
1011 buf[j*4] = taurus->shell_nodelist[i*4];
1012 buf[j*4+1] = taurus->shell_nodelist[i*4+1];
1013 buf[j*4+2] = taurus->shell_nodelist[i*4+2];
1014 buf[j*4+3] = taurus->shell_nodelist[i*4+3];
1015 j++;
1016 }
1017 }
1018 nshellface2 = j;
1019
1020 buf = &(faces->nodelist [(nhexface+nshellface2)*4]);
1021 for (i = 0, j = 0; i < nbeamface; i++) {
1022 if (taurus->beam_activ [i] != 0) {
1023 buf[j*2] = taurus->beam_nodelist[i*2];
1024 buf[j*2+1] = taurus->beam_nodelist[i*2+1];
1025 j++;
1026 }
1027 }
1028 nbeamface2 = j;
1029 }
1030 else {
1031 for (i = 0; i < nhexface*4; i++)
1032 faces->nodelist[i] = taurus->hex_facelist[i];
1033 for (i = 0, j = nhexface*4; i < nshellface*4; i++, j++)
1034 faces->nodelist[j] = taurus->shell_nodelist[i];
1035 nshellface2 = nshellface;
1036 for (i = 0; i < nbeamface * 2; i++, j++)
1037 faces->nodelist[j] = taurus->beam_nodelist[i];
1038 nbeamface2 = nbeamface;
1039 }
1040
1041 faces->nfaces = nhexface + nshellface2 + nbeamface2;
1042 faces->lnodelist = nhexface * 4 + nbeamface2 * 2 + nshellface2 * 4;
1043
1044 if (nbeamface2 == 0) {
1045 faces->nshapes = 1;
1046 faces->shapecnt = ALLOC_N(int, 1);
1047
1048 faces->shapecnt[0] = nhexface + nshellface2;
1049 faces->shapesize = ALLOC_N(int, 1);
1050
1051 faces->shapesize[0] = 4;
1052 }
1053 else {
1054 faces->nshapes = 2;
1055 faces->shapecnt = ALLOC_N(int, 2);
1056
1057 faces->shapecnt[0] = nhexface + nshellface2;
1058 faces->shapecnt[1] = nbeamface2;
1059 faces->shapesize = ALLOC_N(int, 2);
1060
1061 faces->shapesize[0] = 4;
1062 faces->shapesize[1] = 2;
1063 }
1064
1065 faces->ntypes = 0;
1066 faces->typelist = NULL;
1067 faces->types = NULL;
1068
1069 faces->zoneno = ALLOC_N(int, nhexface + nshellface2 + nbeamface2);
1070
1071 if (taurus->activ >= 1000 || taurus->activ <= 1005) {
1072 for (i = 0; i < nhexface; i++)
1073 faces->zoneno[i] = taurus->hex_zoneno[i];
1074
1075 buf = &(faces->zoneno[nhexface]);
1076 for (i = 0, j = 0; i < nshellface; i++)
1077 if (taurus->shell_activ [i] != 0) {
1078 buf[j] = nhex2 + j;
1079 j++;
1080 }
1081
1082 buf = &(faces->zoneno[nhexface+nshellface2]);
1083 for (i = 0, j = 0; i < nbeamface; i++)
1084 if (taurus->beam_activ [i] != 0) {
1085 buf [j] = nhex2 + nshell2 + j;
1086 j++;
1087 }
1088 }
1089 else {
1090 for (i = 0; i < nhexface; i++)
1091 faces->zoneno[i] = taurus->hex_zoneno[i];
1092 for (i = 0, j = nhexface; i < nshellface; i++, j++)
1093 faces->zoneno[j] = taurus->nel8 + i;
1094 for (i = 0, j = nhexface + nshellface; i < nbeamface; i++, j++)
1095 faces->zoneno[j] = taurus->nel8 + taurus->nel4 + i;
1096 }
1097 } else
1098 {
1099 faces->nodelist = NULL;
1100 }
1101
1102 mesh->faces = faces;
1103 }
1104
1105 /*
1106 * Add the edge information.
1107 */
1108 mesh->edges = NULL;
1109
1110 return (mesh);
1111 }
1112
1113 /*-------------------------------------------------------------------------
1114 * Function: db_taur_GetUcdvar
1115 *
1116 * Purpose: Reads a ucd variable from the Taurus database.
1117 *
1118 * Return: Success: ptr to UCD variable
1119 *
1120 * Failure: NULL
1121 *
1122 * Programmer: robb@cloud
1123 * Fri Dec 9 15:09:34 EST 1994
1124 *
1125 * Modifications:
1126 * Eric Brugger, Wed Apr 26 14:13:03 PDT 1995
1127 * I modified the code to work properly with state directories.
1128 *
1129 * Eric Brugger, Thu Jul 27 13:18:52 PDT 1995
1130 * I modified the routine to handle files generated by hydra.
1131 *
1132 * Eric Brugger, Thu Dec 21 09:47:28 PST 1995
1133 * I modified the code to handle the activity data.
1134 *
1135 * Brad Whitlock, Thu Apr 28 14:13:26 PST 2005
1136 * I changed the code so certain ucd var information is set even when
1137 * the data read mask is not on.
1138 *
1139 *-------------------------------------------------------------------------
1140 */
1141 SILO_CALLBACK DBucdvar *
db_taur_GetUcdvar(DBfile * _dbfile,char const * var_name)1142 db_taur_GetUcdvar(DBfile *_dbfile, char const *var_name)
1143 {
1144 int i, j;
1145 int nhex, nshell;
1146 float *buf, *buf2;
1147 char meshname [256];
1148 DBucdvar *uv;
1149 DBfile_taur *dbfile = (DBfile_taur *) _dbfile;
1150 TAURUSfile *taurus = dbfile->taurus;
1151 char *me = "db_taur_GetUcdvar";
1152
1153 if (taurus->state == -1) {
1154 db_perror(NULL, E_TAURSTATE, me);
1155 return (NULL);
1156 }
1157 if (taurus->icode != 1 && taurus->icode != 200 && taurus->idir == -1) {
1158 db_perror(NULL, E_NOTFOUND, me);
1159 return (NULL);
1160 }
1161
1162 /*
1163 * Get the ucd var.
1164 */
1165 if (taurus->mesh_read == 0)
1166 init_mesh_info (taurus);
1167
1168 if (taurus->coord_state != taurus->state) {
1169 init_coord_info (taurus);
1170 init_zone_info (taurus);
1171 }
1172
1173 uv = DBAllocUcdvar();
1174
1175 uv->id = get_next_int();
1176 uv->name = STRDUP(var_name);
1177 uv->cycle = taurus->state;
1178 uv->time = taurus->state_time[taurus->state];
1179 uv->units = NULL;
1180 uv->label = NULL;
1181 uv->meshid = get_next_int();
1182
1183 if (SILO_Globals.dataReadMask & DBUVData)
1184 {
1185 uv->vals = (void **)ALLOC_N(void*, 1);
1186 if (taurus_readvar(taurus, var_name, &(((float **)(uv->vals))[0]), &uv->nels,
1187 &uv->centering, meshname) < 0) {
1188 db_perror("taurus_readvar", E_CALLFAIL, me);
1189 FREE(uv->name);
1190 FREE(uv);
1191 return (NULL);
1192 }
1193
1194 /*
1195 * Subselect the active values, if the activ flag is set and
1196 * the variable is zone centered.
1197 */
1198 if (taurus->activ >= 1000 && taurus->activ <= 1005) {
1199 if (uv->centering != 0) {
1200 buf = (float *)uv->vals[0];
1201 if (strcmp (meshname, "hs_mesh") == 0) {
1202 for (i = 0, j = 0; i < taurus->nhex; i++) {
1203 if (taurus->hex_activ [i] != 0) {
1204 buf [j] = buf [i];
1205 j++;
1206 }
1207 }
1208 nhex = j;
1209
1210 buf = &(((float**)(uv->vals))[0][taurus->nhex]);
1211 buf2 = &(((float**)(uv->vals))[0][nhex]);
1212 for (i = 0, j = 0; i < taurus->nshell; i++) {
1213 if (taurus->shell_activ [i] != 0) {
1214 buf2 [j] = buf [i];
1215 j++;
1216 }
1217 }
1218 nshell = j;
1219
1220 uv->nels = nhex + nshell;
1221 }
1222 else if (strcmp (meshname, "shell_mesh") == 0) {
1223 for (i = 0, j = 0; i < taurus->nshell; i++) {
1224 if (taurus->shell_activ [i] != 0) {
1225 buf [j] = buf [i];
1226 j++;
1227 }
1228 }
1229
1230 uv->nels = j;
1231 }
1232 }
1233 }
1234 }
1235 else
1236 {
1237 uv->vals = NULL;
1238 uv->nels = 0;
1239 }
1240
1241 uv->datatype = DB_FLOAT;
1242 uv->nvals = 1;
1243 uv->ndims = 3;
1244 uv->origin = 0;
1245
1246 if (uv->centering == 0)
1247 uv->centering = DB_NODECENT;
1248 else
1249 uv->centering = DB_ZONECENT;
1250
1251 return (uv);
1252 }
1253
1254 /*-------------------------------------------------------------------------
1255 * Function: db_taur_GetVar
1256 *
1257 * Purpose: Allocates space for a new variable and reads the variable
1258 * from the Taurus database.
1259 *
1260 * Bugs: By allocating only 20 bytes for the variable, we may
1261 * run into problems with memory overrun.
1262 *
1263 * Return: Success: ptr to new variable.
1264 *
1265 * Failure: NULL
1266 *
1267 * Programmer:
1268 *
1269 * Modifications:
1270 * Eric Brugger, Thu Aug 31 15:06:58 PDT 1995
1271 * I increased the size of the array the routine allocates for the
1272 * variable to 40 bytes from 20 bytes.
1273 *
1274 *-------------------------------------------------------------------------
1275 */
1276 SILO_CALLBACK void *
db_taur_GetVar(DBfile * _dbfile,char const * varname)1277 db_taur_GetVar(DBfile *_dbfile, char const *varname)
1278 {
1279 void *ptr;
1280 char *me = "db_taur_GetVar";
1281
1282 ptr = ALLOC_N(char, 40);
1283
1284 if (DBReadVar(_dbfile, varname, ptr) < 0) {
1285 db_perror("DBReadVar", E_CALLFAIL, me);
1286 FREE(ptr);
1287 return NULL;
1288 }
1289 return (ptr);
1290 }
1291
1292 /*-------------------------------------------------------------------------
1293 * Function: db_taur_GetVarByteLength
1294 *
1295 * Purpose: Returns the length of the given variable in bytes.
1296 *
1297 * Return: Success: length of variable.
1298 *
1299 * Failure: -1
1300 *
1301 * Programmer: robb@cloud
1302 * Fri Dec 9 15:21:45 EST 1994
1303 *
1304 * Modifications:
1305 * Eric Brugger, Wed Apr 26 13:13:40 PDT 1995
1306 * I modified the routine to return the title in the file
1307 * as _fileinfo.
1308 *
1309 * Eric Brugger, Thu Aug 31 15:06:58 PDT 1995
1310 * I modified the routine to return the defaults plots as _meshtvinfo.
1311 *
1312 * Brad Whitlock, Thu Apr 28 16:24:58 PST 2005
1313 * Added dtime for VisIt.
1314 *
1315 *-------------------------------------------------------------------------
1316 */
1317 SILO_CALLBACK int
db_taur_GetVarByteLength(DBfile * _dbfile,char const * varname)1318 db_taur_GetVarByteLength(DBfile *_dbfile, char const *varname)
1319 {
1320 DBfile_taur *dbfile = (DBfile_taur *) _dbfile;
1321 TAURUSfile *taurus = dbfile->taurus;
1322 char *me = "db_taur_GetVarByteLength";
1323
1324 if (strcmp(varname, "time") == 0) {
1325 return (4);
1326 }
1327 else if (strcmp(varname, "dtime") == 0) {
1328 return (8);
1329 }
1330 else if (strcmp(varname, "cycle") == 0) {
1331 return (4);
1332 }
1333 else if (strcmp(varname, "noreg") == 0) {
1334 return (4);
1335 }
1336 else if (strcmp(varname, "_fileinfo") == 0) {
1337 return (strlen(taurus->title) + 1);
1338 }
1339 else if (strcmp(varname, "_meshtvinfo") == 0) {
1340 return (32);
1341 }
1342 else {
1343 return db_perror(varname, E_NOTIMP, me);
1344 }
1345 }
1346
1347 /*-------------------------------------------------------------------------
1348 * Function: db_taur_GetVarLength
1349 *
1350 * Purpose: Returns the number of elements in the given variable.
1351 *
1352 * Return: Success: number of elements
1353 *
1354 * Failure: -1
1355 *
1356 * Programmer: robb@cloud
1357 * Fri Dec 9 15:24:04 EST 1994
1358 *
1359 * Modifications:
1360 * Eric Brugger, Wed Apr 26 13:13:40 PDT 1995
1361 * I modified the routine to return the title in the file
1362 * as _fileinfo.
1363 *
1364 * Eric Brugger, Thu Aug 31 15:06:58 PDT 1995
1365 * I modified the routine to return the defaults plots as _meshtvinfo.
1366 *
1367 * Brad Whitlock, Thu Apr 28 16:25:38 PST 2005
1368 * Added dtime for VisIt.
1369 *
1370 *-------------------------------------------------------------------------
1371 */
1372 SILO_CALLBACK int
db_taur_GetVarLength(DBfile * _dbfile,char const * varname)1373 db_taur_GetVarLength(DBfile *_dbfile, char const *varname)
1374 {
1375 DBfile_taur *dbfile = (DBfile_taur *) _dbfile;
1376 TAURUSfile *taurus = dbfile->taurus;
1377 char *me = "db_taur_GetVarLength";
1378
1379 if (strcmp(varname, "time") == 0) {
1380 return (1);
1381 }
1382 else if (strcmp(varname, "dtime") == 0) {
1383 return (1);
1384 }
1385 else if (strcmp(varname, "cycle") == 0) {
1386 return (1);
1387 }
1388 else if (strcmp(varname, "noreg") == 0) {
1389 return (1);
1390 }
1391 else if (strcmp(varname, "_fileinfo") == 0) {
1392 return (strlen(taurus->title) + 1);
1393 }
1394 else if (strcmp(varname, "_meshtvinfo") == 0) {
1395 return (32);
1396 }
1397 else {
1398 return db_perror(varname, E_NOTIMP, me);
1399 }
1400 }
1401
1402 /*-------------------------------------------------------------------------
1403 * Function: db_taur_InqMeshname
1404 *
1405 * Purpose: Returns the name of a mesh associated with a mesh variable.
1406 *
1407 * Return: Success: 0
1408 *
1409 * Failure: -1
1410 *
1411 * Programmer: robb@cloud
1412 * Fri Dec 9 15:26:45 EST 1994
1413 *
1414 * Modifications:
1415 * Eric Brugger, Tue Feb 7 08:57:18 PST 1995
1416 * I removed some code that is never executed.
1417 *
1418 * Eric Brugger, Wed Apr 26 14:13:03 PDT 1995
1419 * I modified the code to work properly with state directories.
1420 *
1421 * Eric Brugger, Thu Jul 27 13:18:52 PDT 1995
1422 * I modified the routine to handle files generated by hydra.
1423 *
1424 *-------------------------------------------------------------------------
1425 */
1426 SILO_CALLBACK int
db_taur_InqMeshname(DBfile * _dbfile,char const * var_name,char * mesh_name)1427 db_taur_InqMeshname(DBfile *_dbfile, char const *var_name, char *mesh_name)
1428 {
1429 DBfile_taur *dbfile = (DBfile_taur *) _dbfile;
1430 TAURUSfile *taurus = dbfile->taurus;
1431 int i;
1432 int idir;
1433 char *me = "db_taur_InqMeshname";
1434
1435 if (taurus->state == -1 && taurus->nstates != 0) {
1436 return db_perror(NULL, E_TAURSTATE, me);
1437 }
1438
1439 if (taurus->nstates == 0) {
1440 /*
1441 * Check against the material names.
1442 */
1443 if (strcmp(var_name, "mat1") == 0) {
1444 strcpy(mesh_name, "mesh1");
1445 return (0);
1446 }
1447 }
1448 else {
1449 if (taurus->state == -1)
1450 return db_perror(var_name, E_NOTFOUND, me);
1451
1452 if (taurus->idir == -1) {
1453 /*
1454 * Check against the material names.
1455 */
1456 if (strcmp(var_name, "mat1") == 0) {
1457 if (taurus->nstates < 100)
1458 sprintf(mesh_name, "/state%02d/mesh1", taurus->state);
1459 else
1460 sprintf(mesh_name, "/state%03d/mesh1", taurus->state);
1461 return (0);
1462 }
1463 }
1464
1465 if (taurus->icode == 1)
1466 idir = 8;
1467 else if (taurus->icode == 200)
1468 idir = 9;
1469 else
1470 idir = taurus->idir;
1471 if (idir != -1) {
1472 /*
1473 * Check against the variable names.
1474 */
1475 for (i = 0; taur_var_list[i].idir < idir; i++)
1476 /* do nothing */ ;
1477 for (i = i; taur_var_list[i].idir == idir &&
1478 strcmp(var_name, taur_var_list[i].name) != 0; i++)
1479 /* do nothing */ ;
1480
1481 if (taur_var_list[i].idir == idir) {
1482 if (taurus->nstates < 100)
1483 sprintf(mesh_name, "/state%02d/%s", taurus->state,
1484 taur_var_list[i].mesh);
1485 else
1486 sprintf(mesh_name, "/state%03d/%s", taurus->state,
1487 taur_var_list[i].mesh);
1488 return (0);
1489 }
1490 }
1491 }
1492
1493 return db_perror(var_name, E_NOTFOUND, me);
1494 }
1495
1496 /*-------------------------------------------------------------------------
1497 * Function: db_taur_InqMeshtype
1498 *
1499 * Purpose: Returns the mesh type for the given mesh.
1500 *
1501 * Return: Success: mesh type
1502 *
1503 * Failure: -1
1504 *
1505 * Programmer:
1506 *
1507 * Modifications:
1508 * Eric Brugger, Wed Apr 26 14:13:03 PDT 1995
1509 * I modified the code to work properly with state directories.
1510 *
1511 * Eric Brugger, Thu Jul 27 13:18:52 PDT 1995
1512 * I modified the routine to handle files generated by hydra.
1513 *
1514 *-------------------------------------------------------------------------
1515 */
1516 SILO_CALLBACK int
db_taur_InqMeshtype(DBfile * _dbfile,char const * mesh_name)1517 db_taur_InqMeshtype(DBfile *_dbfile, char const *mesh_name)
1518 {
1519 DBfile_taur *dbfile = (DBfile_taur *) _dbfile;
1520 TAURUSfile *taurus = dbfile->taurus;
1521 int i;
1522 int idir;
1523 char *me = "db_taur_InqMeshtype";
1524
1525 if (taurus->state == -1 && taurus->nstates != 0) {
1526 return db_perror(NULL, E_TAURSTATE, me);
1527 }
1528
1529 if (taurus->nstates == 0) {
1530 /*
1531 * Check against the material and mesh names.
1532 */
1533 if (strcmp(mesh_name, "mat1") == 0)
1534 return (DB_MATERIAL);
1535 else if (strcmp(mesh_name, "mesh1") == 0)
1536 return (DB_UCDMESH);
1537 }
1538 else {
1539 if (taurus->state == -1)
1540 return db_perror(mesh_name, E_NOTFOUND, me);
1541
1542 if (taurus->idir == -1) {
1543 /*
1544 * Check against the material and mesh names.
1545 */
1546 if (strcmp(mesh_name, "mat1") == 0) {
1547 return (DB_MATERIAL);
1548 }
1549 else {
1550 for (i = 0; i < MAX_MESH &&
1551 strcmp(mesh_name, mesh_names[i]) != 0; i++)
1552 /* do nothing */ ;
1553
1554 if (i < MAX_MESH)
1555 return (DB_UCDMESH);
1556 }
1557 }
1558
1559 if (taurus->icode == 1)
1560 idir = 8;
1561 else if (taurus->icode == 200)
1562 idir = 9;
1563 else
1564 idir = taurus->idir;
1565 if (idir != -1) {
1566 /*
1567 * Check against the variable names.
1568 */
1569 for (i = 0; taur_var_list[i].idir < idir; i++)
1570 /* do nothing */ ;
1571 for (i = i; taur_var_list[i].idir == idir &&
1572 strcmp(mesh_name, taur_var_list[i].name) != 0; i++)
1573 /* do nothing */ ;
1574
1575 if (taur_var_list[i].idir == idir)
1576 return (DB_UCDVAR);
1577 }
1578 }
1579
1580 return db_perror(mesh_name, E_NOTFOUND, me);
1581 }
1582
1583 /*-------------------------------------------------------------------------
1584 * Function: db_taur_InqVartype
1585 *
1586 * Purpose: Returns the var type for the given var.
1587 *
1588 * Return: Success: var type
1589 *
1590 * Failure: -1
1591 *
1592 * Programmer: Brad Whitlock
1593 * Thu Apr 28 16:41:21 PST 2005
1594 *
1595 * Modifications:
1596 *
1597 *-------------------------------------------------------------------------
1598 */
1599 SILO_CALLBACK DBObjectType
db_taur_InqVartype(DBfile * _dbfile,char const * varname)1600 db_taur_InqVartype(DBfile *_dbfile, char const *varname)
1601 {
1602 DBfile_taur *dbfile = (DBfile_taur *) _dbfile;
1603 TAURUSfile *taurus = dbfile->taurus;
1604 char *me = "db_taur_InqVartype";
1605 int pos = strlen(varname) - 1;
1606
1607 if(pos >= 0)
1608 {
1609 char pwd[400];
1610 char *path = 0;
1611 int vartype = DB_INVALID_OBJECT;
1612 int changeDir = 0;
1613 char const *var = varname + pos;
1614 while(*var != '/' && var != varname)
1615 --var;
1616 /* If we have a slash in the name then we have a directory and
1617 * we chould cd into that directory.
1618 */
1619 if(*var == '/')
1620 {
1621 ++var;
1622
1623 /* Get the current directory so we can restore it later. */
1624 db_taur_pwd(taurus, pwd);
1625
1626 /* cd into the specified directory. */
1627 pos = var - varname;
1628 path = ALLOC_N(char, pos);
1629 strncpy(path, varname, pos);
1630 path[pos-1] = '\0';
1631
1632 db_taur_cd(taurus, path);
1633 FREE(path);
1634
1635 changeDir = 1;
1636 }
1637
1638 vartype = db_taur_InqMeshtype(_dbfile, var);
1639
1640 /* Return to the old directory. */
1641 if(changeDir)
1642 db_taur_cd(taurus, pwd);
1643
1644 return (DBObjectType)vartype;
1645 }
1646
1647 db_perror(varname, E_NOTFOUND, me);
1648 return DB_INVALID_OBJECT;
1649 }
1650
1651 /*----------------------------------------------------------------------
1652 * Routine db_taur_InqVarExists
1653 *
1654 * Purpose
1655 * Check whether the variable exists and return non-zero if so,
1656 * and 0 if not
1657 *
1658 * Programmer
1659 * Eric Brugger, Wed Oct 4 08:46:31 PDT 1995
1660 *
1661 * Modifications
1662 * Brad Whitlock, Thu Apr 28 13:40:41 PST 2005
1663 * Added support for dtime.
1664 *
1665 *--------------------------------------------------------------------*/
1666 /* ARGSUSED */
1667 SILO_CALLBACK int
db_taur_InqVarExists(DBfile * _dbfile,char const * varname)1668 db_taur_InqVarExists(DBfile *_dbfile, char const *varname)
1669 {
1670 if (strcmp(varname, "time") == 0) {
1671 return (1);
1672 }
1673 else if (strcmp(varname, "dtime") == 0) {
1674 return (1);
1675 }
1676 else if (strcmp(varname, "cycle") == 0) {
1677 return (1);
1678 }
1679 else if (strcmp(varname, "noreg") == 0) {
1680 return (1);
1681 }
1682 else if (strcmp(varname, "_fileinfo") == 0) {
1683 return (1);
1684 }
1685 else if (strcmp(varname, "_meshtvinfo") == 0) {
1686 return (1);
1687 }
1688
1689 return (0);
1690 }
1691
1692 /*-------------------------------------------------------------------------
1693 * Function: db_taur_ReadVar
1694 *
1695 * Purpose: Read a variable into caller-allocated memory.
1696 *
1697 * Return: Success: 0
1698 *
1699 * Failure: -1
1700 *
1701 * Programmer:
1702 *
1703 * Modifications:
1704 * Eric Brugger, Fri Jan 27 15:57:47 PST 1995
1705 * I replaced the call to byte_copy with a call to memcpy.
1706 *
1707 * Eric Brugger, Wed Apr 26 13:13:40 PDT 1995
1708 * I modified the routine to return the title in the file
1709 * as _fileinfo.
1710 *
1711 * Eric Brugger, Thu Aug 31 15:06:58 PDT 1995
1712 * I modified the routine to return the defaults plots as _meshtvinfo.
1713 *
1714 * Brad Whitlock, Thu Apr 28 13:40:17 PST 2005
1715 * Added support for dtime.
1716 *
1717 *-------------------------------------------------------------------------
1718 */
1719 SILO_CALLBACK int
db_taur_ReadVar(DBfile * _dbfile,char const * varname,void * ptr)1720 db_taur_ReadVar(DBfile *_dbfile, char const *varname, void *ptr)
1721 {
1722 DBfile_taur *dbfile = (DBfile_taur *) _dbfile;
1723 TAURUSfile *taurus = dbfile->taurus;
1724 char *me = "db_taur_ReadVar";
1725
1726 if (strcmp(varname, "time") == 0) {
1727 memcpy(ptr, &taurus->state_time[taurus->state], 4);
1728 }
1729 else if (strcmp(varname, "dtime") == 0) {
1730 double dtime = (double)taurus->state_time[taurus->state];
1731 memcpy(ptr, &dtime, sizeof(double));
1732 }
1733 else if (strcmp(varname, "cycle") == 0) {
1734 memcpy(ptr, &taurus->state, 4);
1735 }
1736 else if (strcmp(varname, "noreg") == 0) {
1737 memcpy(ptr, &taurus->nmat, 4);
1738 }
1739 else if (strcmp(varname, "_fileinfo") == 0) {
1740 memcpy(ptr, &(taurus->title), strlen(taurus->title) + 1);
1741 }
1742 else if (strcmp(varname, "_meshtvinfo") == 0) {
1743 memcpy(ptr, "filled-boundary mat1;mesh mesh1", 32);
1744 }
1745 else {
1746 return db_perror(varname, E_NOTIMP, me);
1747 }
1748
1749 return (0);
1750 }
1751
1752 /*-------------------------------------------------------------------------
1753 * Function: db_taur_cd
1754 *
1755 * Purpose: Change to the specified directory.
1756 *
1757 * Return: Success: 0
1758 *
1759 * Failure: -1
1760 *
1761 * Programmer:
1762 *
1763 * Modifications:
1764 * Eric Brugger, Wed Apr 26 12:13:05 PDT 1995
1765 * I modified the routine to handle directories within states.
1766 *
1767 * Eric Brugger, Thu Jul 27 13:18:52 PDT 1995
1768 * I modified the routine to handle files generated by hydra.
1769 *
1770 *-------------------------------------------------------------------------
1771 */
1772 PRIVATE int
db_taur_cd(TAURUSfile * taurus,char const * path)1773 db_taur_cd(TAURUSfile *taurus, char const *path)
1774 {
1775 int i;
1776 int state;
1777 char *dir;
1778 char opath[160];
1779 char npath[160];
1780
1781 /*
1782 * Form the new path.
1783 */
1784 if (path[0] == '/') {
1785 strcpy(npath, path);
1786 }
1787 else {
1788 db_taur_pwd(taurus, opath);
1789 sprintf(npath, "%s/%s", opath, path);
1790 }
1791 reduce_path(npath);
1792
1793 /*
1794 * Convert the new path into a state.
1795 */
1796 /*
1797 * Handle the case where we are specifying the root directory.
1798 */
1799 if (strcmp(npath, "/") == 0) {
1800 taurus->state = -1;
1801 return (0);
1802 }
1803
1804 /*
1805 * Pick off the state directory.
1806 */
1807 if (strncmp(npath, "/state", 6) != 0)
1808 return (-1);
1809 for (i = 6; npath[i] >= '0' && npath[i] <= '9'; i++)
1810 /* do nothing */ ;
1811 if (i == 6)
1812 return (-1);
1813
1814 if (taurus->icode == 1 || taurus->icode == 200) {
1815 if (npath[i] != '\0')
1816 return (-1);
1817 }
1818 else {
1819 if (npath[i] != '\0' && npath[i] != '/')
1820 return (-1);
1821 }
1822 sscanf(&npath[6], "%d", &state);
1823 if (state >= taurus->nstates)
1824 return (-1);
1825
1826 /*
1827 * Pick off the directory within the state, if one is present.
1828 */
1829 if (npath[i] == '\0') {
1830 taurus->state = state;
1831 taurus->idir = -1;
1832 }
1833 else {
1834 dir = &npath[i + 1];
1835 for (i = 0; i < NDIRS && strcmp(dir, dir_names[i]) != 0; i++)
1836 /* do nothing */ ;
1837 if (i < NDIRS) {
1838 taurus->state = state;
1839 taurus->idir = i;
1840 }
1841 else {
1842 return (-1);
1843 }
1844 }
1845
1846 return (0);
1847 }
1848
1849 /*-------------------------------------------------------------------------
1850 * Function: db_taur_pwd
1851 *
1852 * Purpose: Fill in the `path' buffer with the name of the current
1853 * directory.
1854 *
1855 * Return: Success: 0
1856 *
1857 * Failure: -1
1858 *
1859 * Programmer:
1860 *
1861 * Modifications:
1862 * Eric Brugger, Wed Apr 26 12:13:05 PDT 1995
1863 * I modified the routine to handle directories within states.
1864 *
1865 *-------------------------------------------------------------------------
1866 */
1867 PRIVATE int
db_taur_pwd(TAURUSfile * taurus,char * path)1868 db_taur_pwd(TAURUSfile *taurus, char *path)
1869 {
1870 if (taurus->state == -1) {
1871 strcpy(path, "/");
1872 }
1873 else {
1874 if (taurus->idir == -1) {
1875 if (taurus->nstates < 100) {
1876 sprintf(path, "/state%02d", taurus->state);
1877 }
1878 else {
1879 sprintf(path, "/state%03d", taurus->state);
1880 }
1881 }
1882 else {
1883 if (taurus->nstates < 100) {
1884 sprintf(path, "/state%02d/%s", taurus->state,
1885 dir_names[taurus->idir]);
1886 }
1887 else {
1888 sprintf(path, "/state%03d/%s", taurus->state,
1889 dir_names[taurus->idir]);
1890 }
1891 }
1892 }
1893 return 0;
1894 }
1895
1896 /*-------------------------------------------------------------------------
1897 * Function: db_taur_extface
1898 *
1899 * Purpose:
1900 *
1901 * Return: Success: void
1902 *
1903 * Failure:
1904 *
1905 * Programmer:
1906 *
1907 * Modifications:
1908 *
1909 *-------------------------------------------------------------------------
1910 */
1911 INTERNAL void
db_taur_extface(int * znodelist,int nnodes,int nzones,int * matlist,int ** fnodelist,int * nfaces,int ** zoneno)1912 db_taur_extface(int *znodelist, int nnodes, int nzones, int *matlist,
1913 int **fnodelist, int *nfaces, int **zoneno)
1914 {
1915 int nzshapes;
1916 int zshapecnt[1];
1917 int zshapesize[1];
1918 DBfacelist *fl;
1919
1920 nzshapes = 1;
1921 zshapecnt[0] = nzones;
1922 zshapesize[0] = 8;
1923
1924 fl = DBCalcExternalFacelist(znodelist, nnodes, 0, zshapesize,
1925 zshapecnt, nzshapes, matlist, 2);
1926
1927 *fnodelist = fl->nodelist;
1928 *nfaces = fl->nfaces;
1929 *zoneno = fl->zoneno;
1930
1931 FREE(fl->shapecnt);
1932 FREE(fl->shapesize);
1933 FREE(fl);
1934 }
1935