1 /* 2 pspw_bond.c 3 author - Eric Bylaska 4 */ 5 6 #include <stdlib.h> 7 #include <stdio.h> 8 #include "pspw_bond.h" 9 10 11 #define NIL ((void *) 0) 12 13 14 15 /******************************** 16 * * 17 * pspw_bond_init * 18 * * 19 ********************************/ pspw_bond_init(Bond_List_Type * bond)20void pspw_bond_init(Bond_List_Type *bond) 21 { 22 *bond = NIL; 23 24 } /* pspw_bond_init */ 25 26 /******************************** 27 * * 28 * pspw_bond_add * 29 * * 30 ********************************/ pspw_bond_add(Bond_List_Type * bond,double a)31void pspw_bond_add(Bond_List_Type *bond, double a) 32 { 33 Bond_List_Type prev,cur,node; 34 35 node = (Bond_List_Type) malloc(sizeof(struct bond_struct)); 36 node->a = a; 37 node->next = NIL; 38 39 /* first bond on list */ 40 if (*bond == NIL) 41 { 42 *bond = node; 43 } 44 /* add to end of list */ 45 else 46 { 47 cur = *bond; 48 while (cur != NIL) 49 { 50 prev = cur; 51 cur = cur->next; 52 } 53 prev->next = node; 54 } 55 56 } 57 58 /******************************** 59 * * 60 * pspw_bond_size * 61 * * 62 ********************************/ pspw_bond_size(Bond_List_Type bond)63int pspw_bond_size(Bond_List_Type bond) 64 { 65 Bond_List_Type cur; 66 int count; 67 68 cur = bond; 69 count = 0; 70 while (cur != NIL) 71 { 72 cur = cur->next; 73 ++count; 74 } 75 return count; 76 } 77 78 /******************************** 79 * * 80 * pspw_bond * 81 * * 82 ********************************/ pspw_bond(Bond_List_Type bond,int indx)83double pspw_bond(Bond_List_Type bond, int indx) 84 { 85 Bond_List_Type cur; 86 int i; 87 88 if (pspw_bond_size(bond) < indx) 89 { 90 printf("pspw_bond ERROR\n"); 91 exit(99); 92 } 93 94 cur = bond; 95 for (i=1; i<(indx); ++i) 96 cur = cur->next; 97 98 return cur->a; 99 } 100 101 /******************************** 102 * * 103 * pspw_bond_end * 104 * * 105 ********************************/ pspw_bond_end(Bond_List_Type bond)106void pspw_bond_end(Bond_List_Type bond) 107 { 108 Bond_List_Type cur; 109 110 while (bond != NIL) 111 { 112 cur = bond; 113 bond = bond->next; 114 free(cur); 115 } 116 } 117 118 /* $Id$ */ 119