1 /* matutilo.c
2
3 Written by Don Robert Maszle
4 18 September 1992
5
6 Copyright (c) 1992-2017 Free Software Foundation, Inc.
7
8 This file is part of GNU MCSim.
9
10 GNU MCSim is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License
12 as published by the Free Software Foundation; either version 3
13 of the License, or (at your option) any later version.
14
15 GNU MCSim is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with GNU MCSim; if not, see <http://www.gnu.org/licenses/>
22
23 Matrix utilitites. Output routines.
24 */
25
26 #include <stdio.h>
27 #include <math.h>
28
29 #include "matutilo.h"
30
31 /* -----------------------------------------------------------------------------
32 WriteArray
33
34 writes the elements of an array, tab separated, to a specified file.
35
36 The trailing tab is not printed, nor is carriage return.
37 */
38
WriteArray(FILE * pfile,long cElems,double * rg)39 void WriteArray (FILE *pfile, long cElems, double *rg)
40 {
41 register long i;
42 register long cElems_minus_1 = cElems - 1;
43
44 for (i = 0; i < cElems; i++) {
45 fprintf(pfile, "%g", rg[i]);
46 if (i < cElems_minus_1) fputc ('\t', pfile);
47 } /* for */
48 } /* WriteArray */
49
50
WriteArrayExp(FILE * pfile,long cElems,double * rg)51 void WriteArrayExp (FILE *pfile, long cElems, double *rg)
52 {
53 register long i;
54 register long cElems_minus_1 = cElems - 1;
55
56 for (i = 0; i < cElems; i++) {
57 fprintf(pfile, "%g", exp(rg[i]));
58 if (i < cElems_minus_1) fputc ('\t', pfile);
59 } /* for */
60 } /* WriteArrayExp */
61
62
_walog(long cElems,double * rg)63 void _walog (long cElems, double *rg)
64 {
65 int i;
66 double dSum = 0.0;
67 printf ("{");
68 for (i = 0; i < cElems; i++) {
69 dSum += exp(rg[i]);
70 printf("%s%g", (i ? ", " : ""), exp(rg[i]));
71 } /* for */
72 printf ("} => %g [%g]\n", dSum, 1.0-dSum);
73 } /* _walog */
74
75