nmmtl_retrieve.cpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. /*
  2. FACILITY: NMMTL
  3. MODULE DESCRIPTION:
  4. Contains the function nmmtl_retrieve
  5. AUTHOR(S):
  6. Kevin J. Buchs
  7. CREATION DATE: Mon Jun 1 15:21:29 1992
  8. COPYRIGHT: Copyright (C) 1992 by Mayo Foundation. All rights reserved.
  9. */
  10. /*
  11. *******************************************************************
  12. ** INCLUDE FILES
  13. *******************************************************************
  14. */
  15. #include "nmmtl.h"
  16. #include <string.h>
  17. /*
  18. *******************************************************************
  19. ** STRUCTURE DECLARATIONS AND TYPE DEFINTIONS
  20. *******************************************************************
  21. */
  22. /*
  23. *******************************************************************
  24. ** MACRO DEFINITIONS
  25. *******************************************************************
  26. */
  27. /*
  28. *******************************************************************
  29. ** PREPROCESSOR CONSTANTS
  30. *******************************************************************
  31. */
  32. /*
  33. *******************************************************************
  34. ** GLOBALS
  35. *******************************************************************
  36. */
  37. /*
  38. *******************************************************************
  39. ** FUNCTION DECLARATIONS
  40. *******************************************************************
  41. */
  42. /*
  43. *******************************************************************
  44. ** FUNCTION DEFINITIONS
  45. *******************************************************************
  46. */
  47. /*
  48. FUNCTION NAME: nmmtl_retrieve
  49. FUNCTIONAL DESCRIPTION:
  50. Retreive data from a dump file of conductor and dielectric elements.
  51. FORMAL PARAMETERS:
  52. FILE *retrieve_file - where to write dumpy things to.
  53. int *cntr_seg, - cseg parameter
  54. int *pln_seg, - dseg parameter
  55. float *coupling - coupling length
  56. float *risetime - risetime
  57. struct contour **psignals - signals data structure
  58. int *pconductor_counter, - how many conductors (gnd not included)
  59. CONDUCTOR_DATA_P *pconductor_data, - array of data on conductors
  60. DELEMENTS_P *pdie_elements - list of dielectric elements
  61. unsigned int *pnode_point_counter - highest node number
  62. unsigned int *phighest_conductor_node - highest node for a conductor
  63. RETURN VALUE:
  64. SUCCESS, or FAIL
  65. CALLING SEQUENCE:
  66. status =
  67. nmmtl_retrieve(retrieve_file,conductor_counter,cd,*die_elements);
  68. */
  69. int nmmtl_retrieve(FILE *retrieve_file,
  70. int *cntr_seg,
  71. int *pln_seg,
  72. float *coupling,
  73. float *risetime,
  74. CONTOURS_P *psignals,
  75. int *sig_cnt,
  76. int *pconductor_counter,
  77. CONDUCTOR_DATA_P *pconductor_data,
  78. DELEMENTS_P *pdie_elements,
  79. unsigned int *pnode_point_counter,
  80. unsigned int *phighest_conductor_node)
  81. {
  82. CELEMENTS_P ce;
  83. int cntr,i,edge0,edge1;
  84. char line[256];
  85. CONTOURS_P sigs;
  86. CONDUCTOR_DATA_P conductor_data;
  87. DELEMENTS_P die_elements;
  88. int temp[2];
  89. float ftemp[2];
  90. if(fscanf(retrieve_file,"%d %d %g %g\n",
  91. &temp[0],&temp[1],&ftemp[0],&ftemp[1]) != 4) return(FAIL);
  92. *cntr_seg = temp[0];
  93. *pln_seg = temp[1];
  94. *coupling = ftemp[0];
  95. *risetime = ftemp[1];
  96. /* skip if null otherwise skip what comes after this section */
  97. if(psignals != NULL)
  98. {
  99. if(fgets(line,255,retrieve_file) == NULL) return(FAIL);
  100. i = 0;
  101. while(line[0] == '=')
  102. {
  103. if(*psignals == NULL)
  104. {
  105. sigs = (struct contour *)malloc(sizeof(struct contour));
  106. *psignals = sigs;
  107. }
  108. else
  109. {
  110. sigs->next = (struct contour *)malloc(sizeof(struct contour));
  111. sigs = sigs->next;
  112. }
  113. /* null out newline */
  114. if(strchr(line+1,'\n') != 0) *(strchr(line+1,'\n')) = '\0';
  115. strcpy(sigs->name,line+1);
  116. sigs->next = NULL;
  117. i++;
  118. if(fgets(line,255,retrieve_file) == NULL) return(FAIL);
  119. }
  120. *sig_cnt = i;
  121. return(SUCCESS);
  122. }
  123. else
  124. {
  125. if(fgets(line,255,retrieve_file) == NULL) return(FAIL);
  126. while(line[0] == '=')
  127. if(fgets(line,255,retrieve_file) == NULL) return(FAIL);
  128. }
  129. if(fscanf(retrieve_file,"%d %d %d\n",pnode_point_counter,
  130. phighest_conductor_node,
  131. pconductor_counter) != 3)
  132. {
  133. return(FAIL);
  134. }
  135. *pconductor_data = (CONDUCTOR_DATA_P)malloc(
  136. sizeof(CONDUCTOR_DATA)*(*pconductor_counter+1));
  137. conductor_data = *pconductor_data;
  138. for(cntr=0;cntr <= *pconductor_counter;cntr++)
  139. {
  140. if(fscanf(retrieve_file,"%d %d \n",
  141. &conductor_data[cntr].node_start,
  142. &conductor_data[cntr].node_end) != 2) return(FAIL);
  143. conductor_data[cntr].elements = NULL;
  144. if(fgets(line,255,retrieve_file) == NULL) return(FAIL);
  145. while(line[0] != '.')
  146. {
  147. if(conductor_data[cntr].elements == NULL)
  148. {
  149. ce = (CELEMENTS_P)malloc(sizeof(CELEMENTS));
  150. conductor_data[cntr].elements = ce;
  151. }
  152. else
  153. {
  154. ce->next = (CELEMENTS_P)malloc(sizeof(CELEMENTS));
  155. ce = ce->next;
  156. }
  157. ce->next = NULL;
  158. ce->edge[0] = NULL;
  159. ce->edge[1] = NULL;
  160. sscanf(line,"%f %d %d",&ce->epsilon,&edge0,&edge1);
  161. /* skip over first three fields */
  162. i = 0;
  163. while(line[i] != ' ') i++;
  164. i++;
  165. while(line[i] != ' ') i++;
  166. i++;
  167. while(line[i] != ' ') i++;
  168. i++;
  169. if(edge0)
  170. {
  171. ce->edge[0] = (EDGEDATA_P)malloc(sizeof(EDGEDATA));
  172. sscanf(&line[i],"%f %f",&ce->edge[0]->nu,
  173. &ce->edge[0]->free_space_nu);
  174. /* skip these two fields */
  175. while(line[i] != ' ') i++;
  176. i++;
  177. while(line[i] != ' ') i++;
  178. i++;
  179. }
  180. if(edge1)
  181. {
  182. ce->edge[1] = (EDGEDATA_P)malloc(sizeof(EDGEDATA));
  183. sscanf(&line[i],"%f %f",&ce->edge[1]->nu,
  184. &ce->edge[1]->free_space_nu);
  185. /* skip these two fields */
  186. while(line[i] != ' ') i++;
  187. i++;
  188. while(line[i] != ' ') i++;
  189. i++;
  190. }
  191. for(i = 0; i < 3; i++)
  192. {
  193. if(fscanf(retrieve_file,"%d %lf %lf\n",&ce->node[i],
  194. &ce->xpts[i],&ce->ypts[i]) != 3) return(FAIL);
  195. }
  196. if(fgets(line,255,retrieve_file) == NULL) return(FAIL);
  197. }
  198. }
  199. if(fgets(line,255,retrieve_file) == NULL) return(FAIL);
  200. while(line[0] != '.')
  201. {
  202. if(*pdie_elements == NULL)
  203. {
  204. die_elements = (DELEMENTS_P)malloc(sizeof(DELEMENTS));
  205. *pdie_elements = die_elements;
  206. }
  207. else
  208. {
  209. die_elements->next = (DELEMENTS_P)malloc(sizeof(DELEMENTS));
  210. die_elements = die_elements->next;
  211. }
  212. die_elements->next = NULL;
  213. if(sscanf(line,"%f %f %f %f\n",
  214. &die_elements->epsilonplus,&die_elements->epsilonminus,
  215. &die_elements->normalx,&die_elements->normaly) != 4)
  216. return(FAIL);
  217. for(i = 0; i < 3; i++)
  218. {
  219. fscanf(retrieve_file,"%d %lf %lf\n",&die_elements->node[i],
  220. &die_elements->xpts[i],&die_elements->ypts[i]);
  221. }
  222. if(fgets(line,255,retrieve_file) == NULL) return(FAIL);
  223. }
  224. return(SUCCESS);
  225. }