From f16df2e984942acfedcd211a168be42ecb4a9098 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Fri, 18 Sep 2015 15:00:58 +0200 Subject: ambigator: Write correlation matrix in lines, not all at once --- src/ambigator.c | 142 ++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 86 insertions(+), 56 deletions(-) diff --git a/src/ambigator.c b/src/ambigator.c index 48609ab4..906d5ad3 100644 --- a/src/ambigator.c +++ b/src/ambigator.c @@ -812,25 +812,58 @@ static void write_reindexed_stream(const char *infile, const char *outfile, static void save_corr(const char *filename, struct cc_list *ccs, int n_crystals, int *assignments) { - hid_t fh, sh, dh; - hid_t ph; /* Property list */ + hid_t fh, fsh, msh, cdh, rdh; herr_t r; hsize_t size[2]; - float *matrix; - float *rmatrix; int i; - matrix = calloc(n_crystals*n_crystals, sizeof(float)); - rmatrix = calloc(n_crystals*n_crystals, sizeof(float)); - if ( (matrix == NULL) || (rmatrix == NULL) ) { - ERROR("Failed to allocate space for correlation matrices.\n"); + /* Create file */ + fh = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + if ( fh < 0 ) { + ERROR("Couldn't create file: %s\n", filename); + return; + } + + /* Size of overall dataset */ + size[0] = n_crystals; + size[1] = n_crystals; + fsh = H5Screate_simple(2, size, NULL); + msh = H5Screate_simple(2, size, NULL); + + /* Create overall correlation matrix dataset */ + cdh = H5Dcreate2(fh, "correlation_matrix", H5T_NATIVE_FLOAT, fsh, + H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + if ( cdh < 0 ) { + ERROR("Couldn't create dataset\n"); + ERROR("Correlation matrices will not be written.\n"); + H5Fclose(fh); + return; + } + /* Create overall reindexed correlation matrix dataset */ + rdh = H5Dcreate2(fh, "correlation_matrix_reindexed", H5T_NATIVE_FLOAT, + fsh, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); + if ( rdh < 0 ) { + ERROR("Couldn't create dataset\n"); ERROR("Correlation matrices will not be written.\n"); + H5Fclose(fh); return; } for ( i=0; i