Functions to read data files.
More...
#include "libirt.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Functions |
int | chomp (char *line) |
| remove the newline (and possibly carriage return).
|
int | count_lines (FILE *file) |
| Count the number of line in file and then rewind.
|
int | count_fields (FILE *file, int skip, char delimiter) |
| Count the number of delimiter in the (skip+1) line of file and then rewind.
|
int | trim (char *str) |
| remove the spaces in a string.
|
int | convert_delimited_bin (char *resp_str, char *true_string, char *false_string, char *blank_string) |
| Convert the response string resp_str to integer.
|
int | read_bin_patterns_delimited (FILE *file, int nbr_item, int nbr_subject, int skip, char delimiter, int offset, int extra, char *true_string, char *false_string, char *blank_string, int trimming, gsl_matrix_int **patterns) |
| Read binary patterns from a file in delimited format.
|
int | convert_delimited_mc (char *resp_str) |
| Convert the multiple choice response string resp_str to integer.
|
int | read_mc_patterns_delimited (FILE *file, int nbr_item, int nbr_subject, int skip, char delimiter, int offset, int extra, int trimming, gsl_matrix_int **patterns, gsl_vector_int **nbr_options) |
| Read multiple choice patterns from a file in delimited format.
|
Detailed Description
Functions to read data files.
- Author
- Stephane Germain germs.nosp@m.te@g.nosp@m.mail..nosp@m.com
Macro Definition Documentation
#define MAX_LINE_LENGTH 2000 |
The maximum allowed length of a line.
Function Documentation
remove the newline (and possibly carriage return).
- Parameters
-
[in,out] | line | The line to chomp. |
- Returns
- The new length of the line.
int count_lines |
( |
FILE * |
file | ) |
|
Count the number of line in file and then rewind.
- Parameters
-
- Returns
- The number of lines.
int count_fields |
( |
FILE * |
file, |
|
|
int |
skip, |
|
|
char |
delimiter |
|
) |
| |
Count the number of delimiter in the (skip+1) line of file and then rewind.
- Parameters
-
[in] | file | The file. |
[in] | skip | The number of line to skip. |
[in] | delimiter | The delimiter. |
- Returns
- The number of delimiter in the line.
remove the spaces in a string.
- Parameters
-
[in,out] | str | The string to trim. |
- Returns
- The new length of the string.
int convert_delimited_bin |
( |
char * |
resp_str, |
|
|
char * |
true_string, |
|
|
char * |
false_string, |
|
|
char * |
blank_string |
|
) |
| |
Convert the response string resp_str to integer.
- Parameters
-
[in] | resp_str | The response string. |
[in] | true_string | The string representing a success. |
[in] | false_string | The string representing a failure or NULL. |
[in] | blank_string | The string representing a non response or NULL. |
- Returns
- If resp_str is true_str return TRUE else if resp_str is blank_str return BLANK else if resp_str is false_str return FALSE else if false_str is not NULL return BLANK else return FALSE.
int read_bin_patterns_delimited |
( |
FILE * |
file, |
|
|
int |
nbr_item, |
|
|
int |
nbr_subject, |
|
|
int |
skip, |
|
|
char |
delimiter, |
|
|
int |
offset, |
|
|
int |
extra, |
|
|
char * |
true_string, |
|
|
char * |
false_string, |
|
|
char * |
blank_string, |
|
|
int |
trimming, |
|
|
gsl_matrix_int ** |
patterns |
|
) |
| |
Read binary patterns from a file in delimited format.
- Parameters
-
[in] | file | A open file descriptor with a rewind capability (not stdin). |
[in] | nbr_item | The number of item to read or 0 for autodetection. |
[in] | nbr_subject | The number of pattern to read or 0 for autodetection. |
[in] | skip | The number of line to skip at the start of the file. |
[in] | delimiter | The delimiter to use. |
[in] | offset | The number of field to skip at the start of each line. |
[in] | extra | The number of field between the items. |
[in] | true_string | The string representing a success. |
[in] | false_string | The string representing a failure. If NULL then anything not a success nor a non response will be assume to be a failure. |
[in] | blank_string | The string representing a non response. If NULL then anything not a success nor a failure will be assume to be a non response. A empty field is always assumed to be a non response. |
[in] | trimming | Enable the trimming of spaces. |
[out] | patterns | A matrix(patterns x items) of binary responses. |
- Returns
- 1 for success and 0 for failure.
- Warning
- This function allocate the memory for patterns.
int convert_delimited_mc |
( |
char * |
resp_str | ) |
|
Convert the multiple choice response string resp_str to integer.
- Parameters
-
[in] | resp_str | The response string. |
- Returns
- If resp_str is a positive integer return this integer else return BLANK.
int read_mc_patterns_delimited |
( |
FILE * |
file, |
|
|
int |
nbr_item, |
|
|
int |
nbr_subject, |
|
|
int |
skip, |
|
|
char |
delimiter, |
|
|
int |
offset, |
|
|
int |
extra, |
|
|
int |
trimming, |
|
|
gsl_matrix_int ** |
patterns, |
|
|
gsl_vector_int ** |
nbr_options |
|
) |
| |
Read multiple choice patterns from a file in delimited format.
The responses are assumed to be positive integer, anything else will be assumed to be a non response.
- Parameters
-
[in] | file | A open file descriptor with a rewind capability (not stdin). |
[in] | nbr_item | The number of item to read or 0 for autodetection. |
[in] | nbr_subject | The number of pattern to read or 0 for autodetection. |
[in] | skip | The number of line to skip at the start of the file. |
[in] | delimiter | The delimiter to use. |
[in] | offset | The number of field to skip at the start of each line. |
[in] | extra | The number of field to ignore after each items. |
[in] | trimming | Enable the trimming of spaces. |
[out] | patterns | A matrix(patterns x items) of mc responses. |
[out] | nbr_options | A vector(items) with the number of option of each item in patterns (and probs). |
- Returns
- 1 for success and 0 for failure.
- Warning
- This function allocate the memory for patterns and nbr_options.