diff --git a/src/obicolumn.h b/src/obicolumn.h deleted file mode 100644 index dedc731..0000000 --- a/src/obicolumn.h +++ /dev/null @@ -1,47 +0,0 @@ -/**************************************************************************** - * OBIColumn header file * - ****************************************************************************/ - -/** - * @file obicolumn.h - * @author Celine Mercier - * @date 12 May 2015 - * @brief Header file for the shared elements of all the OBIColumn structures. - */ - -#ifndef OBICOLUMN_H_ -#define OBICOLUMN_H_ - -#include - - -/** - * @brief enum OBIDataType for the data type of the OBIColumns. - */ - -typedef enum OBIDataType { - OBI_VOID = 0, /**< data type not specified */ - OBI_INT32, /**< type int32_t */ - OBI_INT64, /**< type int64_t */ - OBI_UINT32, /**< type uint32_t */ - OBI_UNIT64, /**< type uint64_t */ - OBI_STRING /**< type char* */ -} OBIDataType_t, *OBIDataType_p; - - -/** - * @brief OBIColumnHeader structure. - */ - -typedef struct OBIColumnHeader { - bool endyan_byte_order; /**< endyan byte order */ - int header_size_value; /**< size of the header: a multiple of PAGESIZE */ - int line_count; /**< number of lines of data */ - OBIDataType_t data_type; /**< type of the data */ - char* creation_date; /**< date of creation of the file */ - int version; /**< version of the OBIColumn */ - char* comments; /**< comments */> -} OBIIntColumn_t, *OBIIntColumn_p; - - -#endif /* OBICOLUMN_H_ */ diff --git a/src/obicount/Makefile b/src/obicount/Makefile new file mode 100644 index 0000000..6cc4c91 --- /dev/null +++ b/src/obicount/Makefile @@ -0,0 +1,18 @@ +CC = gcc +CFLAGS = -c -Wall +LDFLAGS = +SOURCES = obicount.c ../obidmscolumn.c +OBJECTS = $(SOURCES:.c=.o) +EXECUTABLE = obicount + +all: $(SOURCES) $(EXECUTABLE) + +$(EXECUTABLE): $(OBJECTS) + $(CC) $(LDFLAGS) $(OBJECTS) -o $@ + +.c.o: + $(CC) $(CFLAGS) $< -o $@ + +clean: + rm *o + rm $(EXECUTABLE) \ No newline at end of file diff --git a/src/obicount/obicount.c b/src/obicount/obicount.c new file mode 100644 index 0000000..3e2bc70 --- /dev/null +++ b/src/obicount/obicount.c @@ -0,0 +1,87 @@ + +#include +#include +#include /* mmap() is defined in this header */ +#include +#include +#include + +#include "../obitypes.h" +#include "../obidmscolumn.h" + + +/** + * @brief Computes the size to map. + * + * * @param OBIDMSColumn_file The file to map. + * @return The size to map. + */ +int get_size_to_map(int OBIDMSColumn_file) +// compute size to map : file size minus size of the header +{ + int size; + struct stat s; + + fstat(OBIDMSColumn_file, &s); + size = (s.st_size) - HEADER_SIZE; + return(size); +} + +/** + * @brief Computes and prints the total number of sequences by summing their counts. + * + * * @param The count file. + */ +int main(int argc, char const *argv[]) +{ + char* map; + int size; + int OBIDMSColumn_file; + int count; + char c; + char num_str[10] = ""; + int num_int; + int i,j; + + // initialize variables + OBIDMSColumn_file = open(argv[1], O_RDONLY); //read only + count = 0; + j = 0; + + // compute size to map + size = get_size_to_map(OBIDMSColumn_file); + + // map the data + map = obi_map_read_only(OBIDMSColumn_file, HEADER_SIZE, size); + + // sum the counts + for (i=0; i +#include +#include /* mmap() is defined in this header */ + + +/** + * @brief Reads a memory block from a file. + * + * * @param file The file that should be mapped. + * * @param size The number of bytes that should be mapped. + * * @param start The position at which the mapping should start. + * @return A pointer on the first element of the block. + */ +char* obi_map_read_only(int file, int start, int size) +{ + char* map; + map = (char*) mmap(0, size, PROT_READ, MAP_PRIVATE, file, start); + if (map == MAP_FAILED) + { + fprintf(stderr, "\nmmap read-only error\n"); + exit(1); + } + return(map); +} + +/** + * @brief Unmaps a memory block. + * + * * @param size The size of the block that should be unmapped. + */ +void obi_unmap(int size) +{ + munmap(0, size); +} diff --git a/src/obidmscolumn.h b/src/obidmscolumn.h new file mode 100644 index 0000000..af97765 --- /dev/null +++ b/src/obidmscolumn.h @@ -0,0 +1,63 @@ +/**************************************************************************** + * OBIDMSColumn header file * + ****************************************************************************/ + +/** + * @file obidmscolumn.h + * @author Celine Mercier + * @date 12 May 2015 + * @brief Header file for the shared elements of all the OBIColumn structures. + */ + +#ifndef OBIDMSCOLUMN_H_ +#define OBIDMSCOLUMN_H_ + +#include +#include +#include +#include + +#include "obitypes.h" + +/** + * @brief Value separator in OBIDMSColumn files. + */ +static const char SEPARATOR = '\n'; + + +/** + * @brief Header size in OBIDMSColumn files. + */ +static const int HEADER_SIZE = 4096; + + +/** + * @brief Number of bytes to map + */ +static const int BUFFER_SIZE = 4; + + +/** + * @brief OBIColumnHeader structure. + */ + +typedef struct OBIDMSColumnHeader { + bool endyan_byte_order; /**< endyan byte order */ + int header_size_value; /**< size of the header: a multiple of PAGESIZE */ + bool file_status; /**< file status : 0 is Open and 1 is Closed */ + pid_t PID; /**< PID of the process that created the file and is + the only one allowed to modify it if it is open */ + int line_count; /**< number of lines of data */ + OBIType_t data_type; /**< type of the data */ + char* creation_date; /**< date of creation of the file */ + int version; /**< version of the OBIColumn */ + char* comments; /**< comments */ +} OBIDMSColumnHeader_t, *OBIDMSColumnHeader_p; + + +char* obi_map_read_only(int file, int start, int size); + +void obi_unmap(int size); + + +#endif /* OBIDMSCOLUMN_H_ */ diff --git a/src/obiintcolumn.h b/src/obiintcolumn.h deleted file mode 100644 index 9a380e6..0000000 --- a/src/obiintcolumn.h +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** - * OBIIntColumn header file * - ****************************************************************************/ - -/** - * @file obiintcolumn.h - * @author Celine Mercier - * @date 11 May 2015 - * @brief Header file for the OBIIntColumn structure. - */ - -#ifndef OBIINTCOLUMN_H_ -#define OBIINTCOLUMN_H_ - -#include -#include - -#include "obicolumn.h" - - -/** - * @brief OBIIntColumn stucture. - */ - -typedef struct OBIIntcolumn { - -} OBIIntColumn_t, *OBIIntColumn_p; - -/** - * @brief Reads a memory block from an OBIIntColumn file. - * - * @param OBIIntColumn The OBIColumn that should be read. - * @return A pointer on the first element of the block. - */ - -int* readMemoryBlock(int* OBIIntcolumn, int startingPosition, int memoryBlockSize); - - -/** - * @brief Writes a memory block line by line at the end of a file. - */ - -void writeMemoryBlock(int* OBIIntcolumn, int memoryBlockSize, char* fileName); - - -/** - * @brief Returns one line of an OBIColumn. - */ - -int readLine(int line); - - -/** - * @brief Creates a new file for a new version of the OBIColumn. - */ - -void newColumn(OBIIntcolumn* column); - - -/** - * @brief malloc for OBIIntColumn. - */ - -int* OBIIntMalloc(); - - -/** - * @brief realloc for OBIIntColumn. - */ - -int* OBIIntRealloc(); - - -/** - * @brief free for OBIIntColumn. - */ - -void OBIIntFree(); - - -#endif /* OBIINTCOLUMN_H_ */ diff --git a/src/obitypes.h b/src/obitypes.h new file mode 100644 index 0000000..96ce6c9 --- /dev/null +++ b/src/obitypes.h @@ -0,0 +1,50 @@ +/**************************************************************************** + * OBITypes header file * + ****************************************************************************/ + +/** + * @file obitypes.h + * @author Celine Mercier + * @date 18 May 2015 + * @brief Header file for the OBITypes. + */ + +#ifndef OBITYPES_H_ +#define OBITYPES_H_ + +#include + +#define OBIInt_NA (INT32_MIN) +#define OBIFloat_NA (NAN) +#define OBIIdx_NA (SIZE_MAX) + +/** + * @brief enum for the boolean OBIType. + */ + +typedef enum { + FALSE = 0, + TRUE = 1, + OBIBool_NA = 2 +} OBIBool_t, *OBIBool_p; /**< a boolean true/false value */ + + +/** + * @brief enum OBITypes for the data type of the OBIColumns. + */ + +typedef enum OBIType { + OBI_VOID = 0, /**< data type not specified */ + OBIInt_t, /**< a signed integer value (C type : int32_t) */ + OBIFloat_t, /**< a floating value (C type : double) */ + OBIChar_t, /**< a character (C type : char) */ + OBIIdx_t /**< an index in a data structure (C type : size_t) */ +} OBIType_t, *OBIType_p; + +typedef int32_t obiint_t; +typedef double obifloat_t; +typedef char obichar_t; +typedef size_t obiidx_t; + + +#endif /* OBITYPES_H_ */