-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdump.c
More file actions
44 lines (41 loc) · 1.11 KB
/
dump.c
File metadata and controls
44 lines (41 loc) · 1.11 KB
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
#include <stdio.h>
#include <stdlib.h>
/**
* Write the output into a file
* @parameter char *filename: Name of the file
* @parameter double *XIJ(1:N+1,1:N+1)
* @parameter double *XMOD(1:N+1,1:N+1,1:KK)
* @parameter int nrow
* @parameter int ncol
* @parameter double THRESHOLD
*/
void dumpOutput(char *filename, double *XIJ, double *XMOD,
int nrow, int ncol, double THRESHOLD)
{
int i,j,k;
FILE *fp;
printf(" Writing data to '%s'\n",filename);
fp=fopen(filename,"w");
if(fp==NULL)
{
printf("ERROR: File '%s' can not be opened\n",filename);
exit(-1);
}
// Output Indices starting at 1:w
for(i=0; i<nrow ; i++)
{
for(j=0; j<nrow ; j++)
{
if(XIJ[i*nrow + j] > THRESHOLD)
{
fprintf(fp,"%d %d %12.4lf ",i+1,j+1,XIJ[i*nrow + j]);
for(k=0; k<ncol; k++)
fprintf(fp," %16.10lf", XMOD[i*nrow*ncol + j*ncol + k]);
fprintf(fp,"\n");
}
}
}
fclose(fp);
printf(" Finished writing data to '%s'\n",filename);
return;
}