File: util.cpp

package info (click to toggle)
klustakwik 3.0.2%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 684 kB
  • sloc: cpp: 2,101; makefile: 176; sh: 15
file content (46 lines) | stat: -rw-r--r-- 835 bytes parent folder | download | duplicates (2)
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
/*
 * util.cpp
 *
 * Various utility functions.
 *
 *  Created on: 11 Nov 2011
 *      Author: dan
 */

#include "util.h"
#include<stdlib.h>
#include<stdarg.h>

const scalar HugeScore = (scalar)1e32;

/* integer random number between min and max*/
int irand(int min, int max)
{
	return (rand() % (max - min + 1) + min);
}

FILE *fopen_safe(char *fname, char *mode) {
	FILE *fp;

	fp = fopen(fname, mode);
	if (!fp) {
		fprintf(stderr, "Could not open file %s\n", fname);
		abort();
	}

	return fp;
}

// Print a matrix
void MatPrint(FILE *fp, scalar *Mat, int nRows, int nCols) {
	int i, j;

	for (i=0; i<nRows; i++) {
		for (j=0; j<nCols; j++) {
			fprintf(fp, "%.5g ", Mat[i*nCols + j]);
            Output("%.5g ", Mat[i*nCols + j]);
		}
		fprintf(fp, "\n");
        Output("\n");
	}
}