Commit 5b38088b authored by Arnaud Blanchard's avatar Arnaud Blanchard
Browse files

Merge branch 'master' of https://framagit.org/blibs/blc_core

parents e9fd48b6 c4f23b37
......@@ -120,6 +120,8 @@ typedef struct blc_array
void init_with_blc_file(char const *filename);
/**Update the content of the memory with the content of the blc file. The blc_array has to be properly defined and allocated before. .blc format is a specific format, whre de first line is the properties of the blc_array and them it is raw binary memory. It may be a problem with endianness */
void update_with_blc_file(char const *filename);
void def_with_tsv_file(char const *filename);
/**Same as update_with_blc_file but this reas .tsv, tab separated values (i.e. 0.75 0.33 0.55 ). Typically used with excel and similar. You have to care yourself to define and allocate an appropriate blc_array.*/
void update_with_tsv_file(char const *filename);
......
/* Basic Library for C/C++ (blclib)
Copyright ETIS — ENSEA, Université de Cergy-Pontoise, CNRS (2011 - 2014)
Author: A. Blanchard
This software is a computer program whose purpose is to simulate neural networks and control robots or simulations.
This software is governed by the CeCILL v2.1 license under French law and abiding by the rules of distribution of free software.
You can use, modify and/ or redistribute the software under the terms of the CeCILL v2.1 license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info".
......@@ -463,6 +461,31 @@ void blc_array::fprint_tsv(FILE *file){
FREE(tmp_dims);
}
void blc_array::def_with_tsv_file(char const *filename){
FILE *file;
const char *ext;
float value;
int tmp_length, ret, pos;
ext=blc_get_filename_extension(filename);
if (strcmp(ext, "tsv")!=0) EXIT_ON_ERROR("'%s' does not .tsv extension but '%s'", filename, ext);
SYSTEM_ERROR_CHECK(file=fopen(filename, "r"), NULL, "Opening filename '%s'.", filename);
dims_nb=0;
do{
tmp_length=0;
do{
SYSTEM_ERROR_CHECK(ret=fscanf(file, "%f", &value), -1, "Scanning file '%s'", filename);
tmp_length++;
}
while(ret==1);
this->add_dim(tmp_length);
SYSTEM_ERROR_CHECK(ret=fscanf(file, "\n%n", &pos), -1, "Scanning file '%s'", filename);
}while(pos==1);
fclose(file);
}
void blc_array::update_with_tsv_file(char const *filename){
FILE *file;
char const *ext;
......
......@@ -56,11 +56,11 @@ int main(int argc, char **argv){
matrix.fprint_tsv(stderr);
//We save the value as a blc file that we will be able to reread
matrix.save_blc_file("bl/blc_core/t_array/array.blc");
matrix.save_tsv_file("bl/blc_core/t_array/array.tsv"); //Bigger but readable in text mode or within spreadsheet, excel, matlab
matrix.save_blc_file("blibs/blc_core/t_array/array.blc");
matrix.save_tsv_file("blibs/blc_core/t_array/array.tsv"); //Bigger but readable in text mode or within spreadsheet, excel, matlab
//We reload the matrix which should be identical
matrix_copy.init_with_blc_file("bl/blc_core/t_array/array.blc");
matrix_copy.init_with_blc_file("blibs/blc_core/t_array/array.blc");
//we compare the content of the two matrixes
if (memcmp(matrix.data, matrix_copy.data, matrix.size)!=0) EXIT_ON_ARRAY_ERROR(&matrix,"The content of the saved and reloaded matrix are not the same");
......@@ -68,7 +68,7 @@ int main(int argc, char **argv){
fprintf(stderr, "\nWe load an array of intensities and display the values\n\n");
//Load the array
pixel_array.init_with_blc_file("bl/blc_core/lena32.blc");
pixel_array.init_with_blc_file("blibs/blc_core/lena32.blc");
//Display the array as a array of decimals)
pixel_array.fprint_surface_uchars(stderr);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment