/nemo_cvs/src/nbody/evolve/newton0/scatterreduc.c

https://github.com/Milkyway-at-home/nemo · C · 355 lines · 241 code · 31 blank · 83 comment · 92 complexity · 3a6d02dd0c2613e6a3155dc0895f2a92 MD5 · raw file

  1. /* scatterreduc.c - */
  2. /*
  3. * scatterreduc.c: data reduction of the screen output of multiscatter
  4. *
  5. * Feb 1989 - Piet Hut @ Inst. f. Adv. Study, Princeton, NJ 08540, USA
  6. */
  7. #include <stdinc.h>
  8. #define MAX_LINE_LENGTH 1000
  9. #define MAX_BLOCK_LENGTH 10000
  10. /*-----------------------------------------------------------------------------
  11. * main -- the following new blocks are deemed interesting enough to print:
  12. * the ones containing:
  13. * # previous blocks: # following blocks:
  14. * normal form 1 1
  15. * starting analytic 2 0
  16. * starting a hierarchical 0 0
  17. * halt_criterion 0 0
  18. * =::= 0 0
  19. * too much energy drift 0 1
  20. * report of 0 1
  21. *
  22. * after each type of block is indicated how many blocks before
  23. * and after should be printed; however, no block should be
  24. * printed twice, even if they have more than one independent
  25. * reason for being printed.
  26. *
  27. * if one or more blocks are not printed, ..... is printed instead.
  28. *
  29. * NOTE: this is written specifically for the following default
  30. * parameters of multiscatter:
  31. * dt_minor=10.0
  32. * dt_major=100.0
  33. * de_rel_max=0.001
  34. * nstep_de=100
  35. *-----------------------------------------------------------------------------
  36. */
  37. main()
  38. {
  39. int how_many_before;
  40. int how_many_after;
  41. bool print_next;
  42. bool print_new;
  43. bool print_old;
  44. bool print_anc;
  45. bool skipping;
  46. char new[ MAX_BLOCK_LENGTH ];
  47. char old[ MAX_BLOCK_LENGTH ];
  48. char anc[ MAX_BLOCK_LENGTH ]; /* ancient */
  49. int getblock();
  50. bool isstartblock();
  51. bool unexpected();
  52. bool interesting();
  53. printf("\n");
  54. getblock(new, MAX_LINE_LENGTH, MAX_BLOCK_LENGTH);
  55. if (isstartblock(new) == FALSE)
  56. error_msg("\nmain: false start: first line not starting line\n");
  57. else
  58. printblock(new);
  59. getblock(new, MAX_LINE_LENGTH, MAX_BLOCK_LENGTH);
  60. printblock(new);
  61. getblock(new, MAX_LINE_LENGTH, MAX_BLOCK_LENGTH);
  62. printblock(new);
  63. getblock(new, MAX_LINE_LENGTH, MAX_BLOCK_LENGTH);
  64. printblock(new);
  65. getblock(anc, MAX_LINE_LENGTH, MAX_BLOCK_LENGTH);
  66. getblock(old, MAX_LINE_LENGTH, MAX_BLOCK_LENGTH);
  67. print_new = TRUE;
  68. print_old = TRUE;
  69. print_anc = TRUE;
  70. skipping = FALSE;
  71. while (getblock(new, MAX_LINE_LENGTH, MAX_BLOCK_LENGTH) > 0)
  72. {
  73. if (unexpected(new) == TRUE)
  74. {
  75. printblock(new);
  76. error_msg("\nmain: last block printed was unexpected\n\n");
  77. }
  78. if (interesting(new, &how_many_before, &how_many_after) == TRUE)
  79. {
  80. print_new = TRUE;
  81. if (how_many_before > 1)
  82. print_anc = TRUE;
  83. if (how_many_before > 0)
  84. print_old = TRUE;
  85. if (how_many_after > 0)
  86. print_next = TRUE;
  87. else
  88. print_next = FALSE;
  89. }
  90. else
  91. print_next = FALSE;
  92. if (print_anc == TRUE)
  93. {
  94. printblock(anc);
  95. skipping = FALSE;
  96. }
  97. else if (skipping == FALSE)
  98. {
  99. print_skip_message();
  100. skipping = TRUE;
  101. }
  102. copyblock(anc, old);
  103. copyblock(old, new);
  104. print_anc = print_old;
  105. print_old = print_new;
  106. print_new = print_next;
  107. }
  108. if (print_anc == TRUE)
  109. printblock(anc);
  110. if (print_old == TRUE)
  111. printblock(old);
  112. }
  113. /*-----------------------------------------------------------------------------
  114. * isstartblock --
  115. *-----------------------------------------------------------------------------
  116. */
  117. local bool isstartblock(b)
  118. char *b;
  119. {
  120. bool infirstline();
  121. return(infirstline(b, "Starting a series"));
  122. }
  123. /*-----------------------------------------------------------------------------
  124. * unexpected --
  125. * NOTE: very inefficient as it stands; potentially costly.
  126. *-----------------------------------------------------------------------------
  127. */
  128. local bool unexpected(b)
  129. char *b;
  130. {
  131. bool infirstline();
  132. if (infirstline(b, "t = ") == TRUE)
  133. return(FALSE);
  134. else if (infirstline(b, "t_now") == TRUE)
  135. return(FALSE);
  136. else if (infirstline(b, "tarting") == TRUE)
  137. return(FALSE);
  138. else if (infirstline(b, "normal form") == TRUE)
  139. return(FALSE);
  140. else if (infirstline(b, "halt_criterion") == TRUE)
  141. return(FALSE);
  142. else if (infirstline(b, "=::=") == TRUE)
  143. return(FALSE);
  144. else if (infirstline(b, "the ROOT") == TRUE)
  145. return(FALSE);
  146. else if (infirstline(b, "Multiscatter") == TRUE)
  147. return(FALSE);
  148. else if (infirstline(b, "warning: no binary output") == TRUE)
  149. return(FALSE);
  150. else if (infirstline(b, "nbody = ") == TRUE)
  151. return(FALSE);
  152. else if (infirstline(b, "Setting up") == TRUE)
  153. return(FALSE);
  154. else if (infirstline(b, "too much energy drift") == TRUE)
  155. return(FALSE);
  156. else if (infirstline(b, "report of qualitative") == TRUE)
  157. return(FALSE);
  158. else
  159. return(TRUE);
  160. }
  161. /*-----------------------------------------------------------------------------
  162. * interesting --
  163. *-----------------------------------------------------------------------------
  164. */
  165. local bool interesting(b, beforeptr, afterptr)
  166. char *b;
  167. int *beforeptr;
  168. int *afterptr;
  169. {
  170. if (infirstline(b, "normal form") == TRUE)
  171. {
  172. *beforeptr = 1;
  173. *afterptr = 1;
  174. return(TRUE);
  175. }
  176. /**********************************************************************
  177. else if (infirstline(b, "starting analytic") == TRUE)
  178. {
  179. *beforeptr = 2;
  180. *afterptr = 0;
  181. return(TRUE);
  182. }
  183. **********************************************************************/
  184. else if (infirstline(b, "starting a hierarchical") == TRUE)
  185. {
  186. *beforeptr = 0;
  187. *afterptr = 0;
  188. return(TRUE);
  189. }
  190. else if (infirstline(b, "=::=") == TRUE)
  191. {
  192. *beforeptr = 0;
  193. *afterptr = 0;
  194. return(TRUE);
  195. }
  196. else if (infirstline(b, "too much energy drift") == TRUE)
  197. {
  198. *beforeptr = 0;
  199. *afterptr = 1;
  200. return(TRUE);
  201. }
  202. else if (infirstline(b, "report of qualitative") == TRUE)
  203. {
  204. *beforeptr = 0;
  205. *afterptr = 1;
  206. return(TRUE);
  207. }
  208. else if (infirstline(b, "halt_criterion") == TRUE)
  209. {
  210. *beforeptr = 0;
  211. *afterptr = 0;
  212. return(TRUE);
  213. }
  214. else
  215. return(FALSE);
  216. }
  217. /*-----------------------------------------------------------------------------
  218. * print_skip_message --
  219. *-----------------------------------------------------------------------------
  220. */
  221. local void print_skip_message()
  222. {
  223. printf(" .....\n\n");
  224. }
  225. /*-----------------------------------------------------------------------------
  226. * printblock --
  227. *-----------------------------------------------------------------------------
  228. */
  229. local void printblock(b)
  230. {
  231. printf("%s\n", b);
  232. }
  233. /*-----------------------------------------------------------------------------
  234. * copyblock --
  235. *-----------------------------------------------------------------------------
  236. */
  237. local void copyblock(b1, b2)
  238. char *b1;
  239. char *b2;
  240. {
  241. strcpy(b1, b2);
  242. }
  243. /*-----------------------------------------------------------------------------
  244. * getblock --
  245. *-----------------------------------------------------------------------------
  246. */
  247. local int getblock(s, line_room, block_room)
  248. char *s;
  249. int line_room;
  250. int block_room;
  251. {
  252. int i, j;
  253. int getline();
  254. i = 0;
  255. if ((j = getline(s, line_room)) <= 1)
  256. ; /* silly trick to stomach leading '\n' */
  257. else
  258. {
  259. s += j;
  260. *s++ = '\n';
  261. block_room -= j + 1;
  262. i++;
  263. }
  264. while ((j = getline(s, line_room)) > 1 && block_room > line_room)
  265. {
  266. s += j;
  267. *s++ = '\n';
  268. block_room -= j + 1;
  269. i++;
  270. }
  271. return(i);
  272. }
  273. /*-----------------------------------------------------------------------------
  274. * getline --
  275. *-----------------------------------------------------------------------------
  276. */
  277. local int getline(s, room)
  278. char *s;
  279. int room;
  280. {
  281. int i, c;
  282. i = 0;
  283. while (--room > 0 && (c = getchar()) != EOF && c != '\n')
  284. s[i++] = c;
  285. if (c == 'n')
  286. s[i++] = c;
  287. s[i] = NULL;
  288. return(i);
  289. }
  290. /*-----------------------------------------------------------------------------
  291. * infirstline --
  292. *-----------------------------------------------------------------------------
  293. */
  294. local bool infirstline(s, sub)
  295. char *s;
  296. char *sub;
  297. {
  298. int sub_length;
  299. sub_length = strlen(sub);
  300. while(*s != NULL && *s != '\n')
  301. {
  302. if (*s == *sub)
  303. if (strncmp(s, sub, sub_length) == 0)
  304. return(TRUE);
  305. s++;
  306. }
  307. return(FALSE);
  308. }
  309. /*-----------------------------------------------------------------------------
  310. * error_msg --
  311. *-----------------------------------------------------------------------------
  312. */
  313. local void error_msg(s)
  314. char *s;
  315. {
  316. printf("%s", s);
  317. exit();
  318. }
  319. /* endof: scatterreduc.c */