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
|
/*
* list3.c - linked list procedures involving quantities and node-values
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include "CNdata.h"
#include "CNproperty.h"
#include "CNdatatypes.h"
#include "CNquant.h"
#include "CNstring.h"
static CNndvalptr make_ndval();
static CNregionptr make_region();
/*
* QUANTITIES
*/
/*
* quantities are used to store field information at nodes
*/
CNquantptr CNmake_quant(label, nfields, ID)
char *label;
int nfields;
int ID;
{
CNquantptr newptr;
unsigned int size = sizeof(CNquant);
if ((newptr = (CNquantptr)malloc(size))!=NULL) {
newptr->label = CNcreate_string(label);
newptr->ID = ID;
newptr->nfields = nfields;
newptr->ndvalhead = NULL;
newptr->ndvaltail = NULL;
newptr->next = NULL;
newptr->prev = NULL;
}
return(newptr);
}
/*
* Insert a quantity at the tail of the current quantity list
*/
CNquantptr CNinsert_quant(quant_listhead,quant_listtail,
label, nfields, ID)
CNquantptr *quant_listhead, *quant_listtail;
char *label;
int nfields;
int ID;
{
CNquantptr next,A,B;
A = *quant_listtail;
if ((B=CNmake_quant(label, nfields, ID))!=NULL) {
if (A==NULL) {
*quant_listhead = B;
*quant_listtail = B;
} else {
next = A->next;
B->next = next;
B->prev = A;
A->next = B;
if (next != NULL) next->prev = B;
if (B->next == NULL) *quant_listtail = B;
}
}
return(B);
}
/*
* Insert a quantity at the tail of the current quantity list
*/
void CNadd_quant(quant_listhead,quant_listtail,quant)
CNquantptr *quant_listhead, *quant_listtail, quant;
{
CNquantptr next,A,B;
A = *quant_listtail;
if ((B=quant)!=NULL) {
if (A==NULL) {
*quant_listhead = B;
*quant_listtail = B;
} else {
next = A->next;
B->next = next;
B->prev = A;
A->next = B;
if (next != NULL) next->prev = B;
if (B->next == NULL) *quant_listtail = B;
}
}
}
/*
* Delete quant
*/
void CNdelete_quant(quant_listhead, quant_listtail, Q)
CNquantptr *quant_listhead, *quant_listtail;
CNquantptr Q;
{
CNquantptr prev,next;
/* Delete the label */
CNdestroy_string(Q->label);
/* Delete all the node-values associated with the quantity */
CNdelete_ndval_list(&(Q->ndvalhead), &(Q->ndvaltail));
prev = Q->prev;
next = Q->next;
if (prev!=NULL) prev->next = next;
if (next!=NULL) next->prev = prev;
if (Q==*quant_listhead) *quant_listhead = next;
if (Q==*quant_listtail) *quant_listtail = prev;
/* Now delete Q */
free ((char*)Q);
}
/*
* Delete all the quantities in the list
*/
void CNdelete_quant_list(quant_listhead, quant_listtail)
CNquantptr *quant_listhead, *quant_listtail;
{
CNquantptr Q;
while ((Q = *quant_listhead) != NULL)
CNdelete_quant(quant_listhead, quant_listtail, Q);
}
/*
* print out the list of quantities
*/
/*ARGSUSED*/
void CNprint_quant_list(quant_listhead, quant_listtail)
CNquantptr quant_listhead, quant_listtail;
{
CNquantptr Q;
for (Q=quant_listhead; Q!=NULL; Q=Q->next)
CNprint_quant(Q);
}
/*
* print a quantity
*/
void CNprint_quant(Q)
CNquantptr Q;
{
(void) fprintf(stdout,
" QuantID# %3d Label=\"%s\" Fields=%d\n",
Q->ID, Q->label, Q->nfields);
CNprint_ndval_list(Q->ndvalhead, Q->ndvaltail);
(void) fflush(stdout);
}
/*
* Count the number of quants in the list
*/
/*ARGSUSED*/
int CNcount_quants(quant_listhead, quant_listtail)
CNquantptr quant_listhead, quant_listtail;
{
CNquantptr P;
int count = 0;
for (P=quant_listhead; P!=NULL; P=P->next) count++;
return(count);
}
/*
* Return the size of all quants in the list
*/
/*ARGSUSED*/
int CNquant_list_size(quant_listhead, quant_listtail)
CNquantptr quant_listhead, quant_listtail;
{
CNquantptr C;
int size = 0;
for (C=quant_listhead; C!=NULL; C=C->next)
size += CNquant_size(C);
return(size);
}
/*
* Return the (approximate) size of the quant
*/
int CNquant_size(Qptr)
CNquantptr Qptr;
{
int size, nndvals;
if (Qptr == NULL) return(0);
/* The basic size */
size = sizeof(CNquant);
/* Count the contents of the curve */
nndvals = CNcount_ndvals(Qptr->ndvalhead,Qptr->ndvaltail);
/* Count the size of the components */
size += nndvals*sizeof(CNndval);
/* return */
return(size);
}
/*
* NODE-VALUES
*/
/*
* node-values are used to store field information at nodes
*/
static
CNndvalptr make_ndval(nfields, nodeID)
int nfields, nodeID;
{
CNndvalptr newptr;
unsigned int size = sizeof(CNndval);
int i;
if ((newptr = (CNndvalptr)malloc(size))!=NULL) {
newptr->nodeID = nodeID;
newptr->nfields = nfields;
for (i=0; i<CN_MAXFIELDS; i++) newptr->field[i] = 0.0;
newptr->next = NULL;
newptr->prev = NULL;
}
return(newptr);
}
/*
* Insert a node-value at the tail of the current node-value list
*/
CNndvalptr CNinsert_ndval(ndval_listhead,ndval_listtail, nfields, ID)
CNndvalptr *ndval_listhead, *ndval_listtail;
int nfields, ID;
{
CNndvalptr next,A,B;
A = *ndval_listtail;
if ((B=make_ndval(nfields, ID))!=NULL) {
if (A==NULL) {
*ndval_listhead = B;
*ndval_listtail = B;
} else {
next = A->next;
B->next = next;
B->prev = A;
A->next = B;
if (next != NULL) next->prev = B;
if (B->next == NULL) *ndval_listtail = B;
}
}
return(B);
}
/*
* Delete ndval
*/
void CNdelete_ndval(ndval_listhead, ndval_listtail, N)
CNndvalptr *ndval_listhead, *ndval_listtail;
CNndvalptr N;
{
CNndvalptr prev,next;
prev = N->prev;
next = N->next;
if (prev!=NULL) prev->next = next;
if (next!=NULL) next->prev = prev;
if (N==*ndval_listhead) *ndval_listhead = next;
if (N==*ndval_listtail) *ndval_listtail = prev;
/* Now delete N */
free ((char*)N);
}
/*
* Delete all the node-values in the list
*/
void CNdelete_ndval_list(ndval_listhead, ndval_listtail)
CNndvalptr *ndval_listhead, *ndval_listtail;
{
CNndvalptr N;
while ((N = *ndval_listhead) != NULL)
CNdelete_ndval(ndval_listhead, ndval_listtail, N);
}
/*
* print out the list of node-values
*/
/*ARGSUSED*/
void CNprint_ndval_list(ndval_listhead, ndval_listtail)
CNndvalptr ndval_listhead, ndval_listtail;
{
void CNprint_ndval();
CNndvalptr N;
for (N=ndval_listhead; N!=NULL; N=N->next)
CNprint_ndval(N);
}
/*
* print a node-value
*/
void CNprint_ndval(N)
CNndvalptr N;
{
int i;
(void) fprintf(stdout," NdvalID# %3d Fields (%3d):", N->nodeID, N->nfields);
for (i=0; i<N->nfields; i++)
(void) fprintf(stdout," [%d] %8.5e ", i, N->field[i]);
(void) fprintf(stdout,"\n");
(void) fflush(stdout);
}
/*
* Count the number of ndvals in the list
*/
/*ARGSUSED*/
int CNcount_ndvals(ndval_listhead, ndval_listtail)
CNndvalptr ndval_listhead, ndval_listtail;
{
CNndvalptr P;
int count = 0;
for (P=ndval_listhead; P!=NULL; P=P->next) count++;
return(count);
}
/*
* REGIONS
*/
/*
* regions are used to store boundary information.
* A region contains a label identifier and a collection of nodes.
*/
static
CNregionptr make_region(matname, matID, ID)
char *matname;
int matID;
int ID;
{
CNregionptr newptr;
unsigned int size = sizeof(CNregion);
if ((newptr = (CNregionptr)malloc(size))!=NULL) {
newptr->matname = CNcreate_string(matname);
newptr->matID = matID;
newptr->ID = ID;
newptr->color = -1;
newptr->isair = CN_FALSE;
newptr->nocont = CN_FALSE;
newptr->polyhead = NULL;
newptr->polytail = NULL;
newptr->matpolyhead = NULL;
newptr->matpolytail = NULL;
newptr->next = NULL;
newptr->prev = NULL;
}
return(newptr);
}
/*
* Insert a region at the tail of the current region list
*/
CNregionptr CNinsert_region(region_listhead,region_listtail, matname, matID, ID)
CNregionptr *region_listhead, *region_listtail;
char *matname;
int matID, ID;
{
CNregionptr next,A,B;
A = *region_listtail;
if ((B=make_region(matname, matID, ID))!=NULL) {
if (A==NULL) {
*region_listhead = B;
*region_listtail = B;
} else {
next = A->next;
B->next = next;
B->prev = A;
A->next = B;
if (next != NULL) next->prev = B;
if (B->next == NULL) *region_listtail = B;
}
}
return(B);
}
/*
* Delete region
*/
void CNdelete_region(region_listhead, region_listtail, R)
CNregionptr *region_listhead, *region_listtail;
CNregionptr R;
{
CNregionptr prev,next;
/* Delete the label */
CNdestroy_string(R->matname);
/* Delete the polygons associated with the quantity */
CNdelete_poly_list(&(R->polyhead), &(R->polytail));
CNdelete_poly_list(&(R->matpolyhead), &(R->matpolytail));
prev = R->prev;
next = R->next;
if (prev!=NULL) prev->next = next;
if (next!=NULL) next->prev = prev;
if (R==*region_listhead) *region_listhead = next;
if (R==*region_listtail) *region_listtail = prev;
/* Now delete R */
free ((char*)R);
}
/*
* Delete all the regions in the list
*/
void CNdelete_region_list(region_listhead, region_listtail)
CNregionptr *region_listhead, *region_listtail;
{
CNregionptr N;
while ((N = *region_listhead) != NULL)
CNdelete_region(region_listhead, region_listtail, N);
}
/*
* print out the list of regions
*/
/*ARGSUSED*/
void CNprint_region_list(region_listhead, region_listtail)
CNregionptr region_listhead, region_listtail;
{
void CNprint_region();
CNregionptr N;
for (N=region_listhead; N!=NULL; N=N->next)
CNprint_region(N);
}
/*
* print a region
*/
void CNprint_region(R)
CNregionptr R;
{
(void) fprintf(stdout," RegionID# %3d Label=\"%s\" \n",
R->ID, R->matname);
CNprint_poly_list(R->polyhead, R->polytail);
(void) fflush(stdout);
}
/*
* Count the number of regions in the list
*/
/*ARGSUSED*/
int CNcount_regions(region_listhead, region_listtail)
CNregionptr region_listhead, region_listtail;
{
CNregionptr P;
int count = 0;
for (P=region_listhead; P!=NULL; P=P->next) count++;
return(count);
}
/*
* Return the size of all regions in the list
*/
/*ARGSUSED*/
int CNregion_list_size(region_listhead, region_listtail)
CNregionptr region_listhead, region_listtail;
{
CNregionptr C;
int size = 0;
for (C=region_listhead; C!=NULL; C=C->next)
size += CNregion_size(C);
return(size);
}
/*
* Return the (approximate) size of the region
*/
int CNregion_size(Rptr)
CNregionptr Rptr;
{
int size;
if (Rptr == NULL) return(0);
/* The basic size */
size = sizeof(CNregion);
/* Count the contents of the region */
size += CNpoly_list_size(Rptr->polyhead,Rptr->polytail);
/* return */
return(size);
}
|