Skip to content
Snippets Groups Projects
Commit 6de8af37 authored by Carl Philipp Klemm's avatar Carl Philipp Klemm
Browse files

dont forget to initalize the input paramter of length in rlx_get_metadata if no metadata is present

parent 3fc5971e
No related branches found
No related tags found
No related merge requests found
...@@ -43,49 +43,53 @@ int main(int argc, char** argv) ...@@ -43,49 +43,53 @@ int main(int argc, char** argv)
return 4; return 4;
} }
for(size_t i = 0; i < projectCount; ++i)
{
printf("PROJECT %p %d\n", projects[i], projects[i]->id);
// Get the ids of specra associated with the first project in the file // Get the ids of specra associated with the first project in the file
size_t idCount; size_t idCount;
int *ids = rlx_get_spectra_ids(file, projects[0], &idCount); int *ids = rlx_get_spectra_ids(file, projects[i], &idCount);
for(int i = 0; i < idCount; ++i) for(int j = 0; j < idCount; ++j)
printf("PROJECT: %d ID: %d\n", projects[0]->id, ids[i]); printf("PROJECT: %d ID: %d\n", projects[i]->id, ids[j]);
if(idCount < 1) { if(idCount < 1) {
printf("No spectra in project %d: %s\n", projects[0]->id, rlx_get_errnum_str(rlx_get_errnum(file))); printf("No spectra in project %d: %s\n", projects[i]->id, rlx_get_errnum_str(rlx_get_errnum(file)));
return 3; continue;
} }
printf("%p %d\n", projects[0], projects[0]->id);
// Grab the first spectrum // Grab the first spectrum
struct rlx_spectra* spectra = rlx_get_spectra(file, projects[0], ids[0]); struct rlx_spectra* spectra = rlx_get_spectra(file, projects[i], ids[0]);
if(!spectra) { if(!spectra) {
printf("Could not load spectra for %d %d: %s\n", projects[0]->id, ids[0], rlx_get_errnum_str(rlx_get_errnum(file))); printf("Could not load spectra for project %d id %d: %s\n", projects[i]->id, ids[0], rlx_get_errnum_str(rlx_get_errnum(file)));
return 3; return 3;
} }
printf("Spectra for PROJECT: %d ID: %d\nomega, re, im\n", projects[0]->id, ids[0]); printf("Spectra for PROJECT: %d ID: %d\nomega, re, im\n", projects[i]->id, ids[0]);
for(size_t i = 0; i < spectra->length; ++i) { for(size_t j = 0; j < spectra->length; ++j) {
printf("%f,%f,%f\n", spectra->datapoints[i].omega, spectra->datapoints[i].re, spectra->datapoints[i].im); printf("%f,%f,%f\n", spectra->datapoints[j].omega, spectra->datapoints[j].re, spectra->datapoints[j].im);
} }
puts("Metadata:"); puts("Metadata:");
for(size_t i = 0; i < spectra->metadata_count; ++i) { for(size_t j = 0; j < spectra->metadata_count; ++j) {
printf("%s:\t%s\n", spectra->metadata[i].key, spectra->metadata[i].str); printf("%s:\t%s\n", spectra->metadata[j].key, spectra->metadata[j].str);
} }
size_t paramCount; size_t paramCount;
// Grab the parameters for the first spectrum // Grab the parameters for the first spectrum
struct rlx_fitparam** params = rlx_get_fit_parameters(file, projects[0], ids[0], &paramCount); struct rlx_fitparam** params = rlx_get_fit_parameters(file, projects[i], ids[0], &paramCount);
if(!params) { if(!params) {
printf("Could not get parameters for project %d spectra %d: %s\n", projects[0]->id, ids[0], rlx_get_errnum_str(rlx_get_errnum(file))); printf("Could not get parameters for project %d spectra %d: %s\n", projects[i]->id, ids[0], rlx_get_errnum_str(rlx_get_errnum(file)));
return 4; return 4;
} }
for(size_t i = 0; i < paramCount; ++i) { for(size_t j = 0; j < paramCount; ++j) {
printf("Parameter %d: Name: %s Value: %f Error: %f\n", params[i]->p_index, params[i]->name, params[i]->value, params[i]->error); printf("Parameter %d: Name: %s Value: %f Error: %f\n", params[j]->p_index, params[j]->name, params[j]->value, params[j]->error);
} }
// Free aquired structs
rlx_project_free_array(projects);
rlx_spectra_free(spectra); rlx_spectra_free(spectra);
rlx_fitparam_free_array(params); rlx_fitparam_free_array(params);
free(ids); free(ids);
}
// Free aquired structs
rlx_project_free_array(projects);
// Close RelaxIS3 file // Close RelaxIS3 file
rlx_close_file(file); rlx_close_file(file);
......
...@@ -66,6 +66,12 @@ void rlx_spectra_free(struct rlx_spectra* specta) ...@@ -66,6 +66,12 @@ void rlx_spectra_free(struct rlx_spectra* specta)
if(specta->circuit) if(specta->circuit)
free(specta->circuit); free(specta->circuit);
free(specta->datapoints); free(specta->datapoints);
if(specta->metadata)
{
for(size_t i = 0; i < specta->metadata_count; ++i)
rlx_metadata_free(specta->metadata+i);
free(specta->metadata);
}
free(specta); free(specta);
} }
...@@ -98,6 +104,12 @@ void rlx_fitparam_free_array(struct rlx_fitparam** param) ...@@ -98,6 +104,12 @@ void rlx_fitparam_free_array(struct rlx_fitparam** param)
free(firstparam); free(firstparam);
} }
void rlx_metadata_free(struct rlx_metadata* metadata)
{
free(metadata->key);
free(metadata->str);
}
struct rlxfile* rlx_open_file(const char* path, const char** error) struct rlxfile* rlx_open_file(const char* path, const char** error)
{ {
struct rlxfile *file = calloc(1, sizeof(*file)); struct rlxfile *file = calloc(1, sizeof(*file));
...@@ -246,6 +258,8 @@ static struct rlx_metadata* rlx_get_metadata(struct rlxfile* file, int id, size_ ...@@ -246,6 +258,8 @@ static struct rlx_metadata* rlx_get_metadata(struct rlxfile* file, int id, size_
char *error; char *error;
char *req = rlx_alloc_printf("SELECT name,value FROM FileInformation WHERE file_id=%d", id); char *req = rlx_alloc_printf("SELECT name,value FROM FileInformation WHERE file_id=%d", id);
int ret = sqlite3_get_table(file->db, req, &table, &rows, &cols, &error); int ret = sqlite3_get_table(file->db, req, &table, &rows, &cols, &error);
if(length)
*length = 0;
free(req); free(req);
++rows; ++rows;
if(ret != SQLITE_OK) { if(ret != SQLITE_OK) {
...@@ -345,12 +359,14 @@ int* rlx_get_spectra_ids(struct rlxfile* file, const struct rlx_project* project ...@@ -345,12 +359,14 @@ int* rlx_get_spectra_ids(struct rlxfile* file, const struct rlx_project* project
int rows; int rows;
int cols; int cols;
char *error; char *error;
int ret = sqlite3_get_table(file->db, "SELECT ID FROM Files;", &table, &rows, &cols, &error); if(length)
*length = 0;
char *req = rlx_alloc_printf("SELECT ID FROM Files where project_id=%d", project->id);
int ret = sqlite3_get_table(file->db, req, &table, &rows, &cols, &error);
free(req);
if(ret != SQLITE_OK) { if(ret != SQLITE_OK) {
file->error = ret; file->error = ret;
free(error); free(error);
if(length)
*length = 0;
return NULL; return NULL;
} }
++rows; ++rows;
......
...@@ -109,17 +109,7 @@ struct rlx_metadata { ...@@ -109,17 +109,7 @@ struct rlx_metadata {
}; };
/** /**
* @brief Allocates a metadata struct * @brief Frees the content of rlx_metadata struct but not the struct itself
*.
* @param key the key of the metadata value.
* @param str the value of the metadata value as a string.
* @param type the metadata type.
* @return a newly allocated rlx_metadata struct or NULL on oom.
*/
struct rlx_metadata* rlx_metadata_create(const char* key, const char* str, enum rlx_field_type type);
/**
* @brief Frees a rlx_metadata struct
* *
* @param metadata the struct to free * @param metadata the struct to free
*/ */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment