projects
/
pspp
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Categoricals: Use moments instead of keeping cc count ourselves
[pspp]
/
src
/
language
/
stats
/
flip.c
diff --git
a/src/language/stats/flip.c
b/src/language/stats/flip.c
index 3ca2413fcf35f2d56bba7b2200cde2934bb92985..de7f52c043bcb4d85fa263d3fc91debd8e916488 100644
(file)
--- a/
src/language/stats/flip.c
+++ b/
src/language/stats/flip.c
@@
-1,5
+1,5
@@
/* PSPP - a program for statistical analysis.
/* PSPP - a program for statistical analysis.
- Copyright (C) 1997-9, 2000, 2009 Free Software Foundation, Inc.
+ Copyright (C) 1997-9, 2000, 2009
, 2010
Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@
-40,7
+40,8
@@
#include <libpspp/misc.h>
#include <libpspp/pool.h>
#include <libpspp/str.h>
#include <libpspp/misc.h>
#include <libpspp/pool.h>
#include <libpspp/str.h>
-
+#include <data/data-in.h>
+#include <data/data-out.h>
#include "intprops.h"
#include "minmax.h"
#include "xalloc.h"
#include "intprops.h"
#include "minmax.h"
#include "xalloc.h"
@@
-66,6
+67,7
@@
struct flip_pgm
int n_cases; /* Pre-flip number of cases. */
struct variable *new_names_var; /* Variable with new variable names. */
int n_cases; /* Pre-flip number of cases. */
struct variable *new_names_var; /* Variable with new variable names. */
+ struct dictionary *dict; /* Dictionary of the names */
struct var_names old_names; /* Variable names before FLIP. */
struct var_names new_names; /* Variable names after FLIP. */
struct var_names old_names; /* Variable names before FLIP. */
struct var_names new_names; /* Variable names after FLIP. */
@@
-105,6
+107,7
@@
cmd_flip (struct lexer *lexer, struct dataset *ds)
flip->file = NULL;
flip->cases_read = 0;
flip->error = false;
flip->file = NULL;
flip->cases_read = 0;
flip->error = false;
+ flip->dict = dict;
lex_match (lexer, '/');
if (lex_match_id (lexer, "VARIABLES"))
lex_match (lexer, '/');
if (lex_match_id (lexer, "VARIABLES"))
@@
-141,7
+144,7
@@
cmd_flip (struct lexer *lexer, struct dataset *ds)
}
}
}
}
- flip->file = pool_
tmp
file (flip->pool);
+ flip->file = pool_
create_temp_
file (flip->pool);
if (flip->file == NULL)
{
msg (SE, _("Could not create temporary file for FLIP."));
if (flip->file == NULL)
{
msg (SE, _("Could not create temporary file for FLIP."));
@@
-181,9
+184,9
@@
cmd_flip (struct lexer *lexer, struct dataset *ds)
}
else
{
}
else
{
- int width = var_get_width (flip->new_names_var);
- name = pool_strdup0 (flip->pool,
- value_str (value, width), width);
+ name = data_out_pool (value, dict_get_encoding (flip->dict), var_get_write_format (flip->new_names_var),
+ flip->pool);
+
}
var_names_add (flip->pool, &flip->new_names, name);
}
}
var_names_add (flip->pool, &flip->new_names, name);
}
@@
-208,7
+211,7
@@
cmd_flip (struct lexer *lexer, struct dataset *ds)
else
{
char s[VAR_NAME_LEN + 1];
else
{
char s[VAR_NAME_LEN + 1];
- sprintf (s, "VAR%03
d
", i);
+ sprintf (s, "VAR%03
zu
", i);
dict_create_var_assert (dict, s, 0);
}
dict_create_var_assert (dict, s, 0);
}
@@
-270,7
+273,7
@@
make_new_var (struct dictionary *dict, const char *name_)
{
char n[VAR_NAME_LEN + 1];
int ofs = MIN (VAR_NAME_LEN - 1 - intlog10 (i), len);
{
char n[VAR_NAME_LEN + 1];
int ofs = MIN (VAR_NAME_LEN - 1 - intlog10 (i), len);
-
mem
cpy (n, name, ofs);
+
strn
cpy (n, name, ofs);
sprintf (&n[ofs], "%d", i);
if (dict_create_var (dict, n, 0))
sprintf (&n[ofs], "%d", i);
if (dict_create_var (dict, n, 0))
@@
-319,13
+322,13
@@
flip_file (struct flip_pgm *flip)
output_buf = input_buf + flip->n_vars * case_capacity;
input_file = flip->file;
output_buf = input_buf + flip->n_vars * case_capacity;
input_file = flip->file;
- if (fseek (input_file, 0, SEEK_SET) != 0)
+ if (fseek
o
(input_file, 0, SEEK_SET) != 0)
{
msg (SE, _("Error rewinding FLIP file: %s."), strerror (errno));
return false;
}
{
msg (SE, _("Error rewinding FLIP file: %s."), strerror (errno));
return false;
}
- output_file = pool_
tmp
file (flip->pool);
+ output_file = pool_
create_temp_
file (flip->pool);
if (output_file == NULL)
{
msg (SE, _("Error creating FLIP source file."));
if (output_file == NULL)
{
msg (SE, _("Error creating FLIP source file."));
@@
-376,15
+379,11
@@
flip_file (struct flip_pgm *flip)
case_idx += read_cases;
}
case_idx += read_cases;
}
- if (pool_fclose (flip->pool, input_file) == EOF)
- {
- msg (SE, _("Error closing FLIP source file: %s."), strerror (errno));
- return false;
- }
+ pool_fclose_temp_file (flip->pool, input_file);
pool_unregister (flip->pool, input_buf);
free (input_buf);
pool_unregister (flip->pool, input_buf);
free (input_buf);
- if (fseek (output_file, 0, SEEK_SET) != 0)
+ if (fseek
o
(output_file, 0, SEEK_SET) != 0)
{
msg (SE, _("Error rewinding FLIP source file: %s."), strerror (errno));
return false;
{
msg (SE, _("Error rewinding FLIP source file: %s."), strerror (errno));
return false;
@@
-407,8
+406,12
@@
flip_casereader_read (struct casereader *reader, void *flip_)
return false;
c = case_create (casereader_get_proto (reader));
return false;
c = case_create (casereader_get_proto (reader));
- value_copy_str_rpad (case_data_rw_idx (c, 0), 8,
- flip->old_names.names[flip->cases_read], ' ');
+ data_in (ss_cstr (flip->old_names.names[flip->cases_read]), dict_get_encoding (flip->dict),
+ FMT_A, 0,
+ 0, 0,
+ flip->dict,
+ case_data_rw_idx (c, 0), 8);
+
for (i = 0; i < flip->n_cases; i++)
{
double in;
for (i = 0; i < flip->n_cases; i++)
{
double in;