74 {
76 long i, j, i_arg;
77 SCANNED_ARG *s_arg;
78 long tmpfile_used, no_warnings, integer_columns, digits;
79 int32_t column_matches;
80 long index, type;
81 int64_t i_row, rows;
82 void *data;
83 int32_t columns;
84 short *integer_type;
85 char *input, *output, **column_name, **column_match, **integer_column;
86 char buff[1024], **binary_string;
87 unsigned long pipe_flags;
88
89
90 tmpfile_used = 0;
91 pipe_flags = 0;
92 input = output = NULL;
93 data = NULL;
94 no_warnings = 0;
95
96 binary_string = NULL;
97 buff[0] = 0;
98
99 columns = column_matches = integer_columns = 0;
100 column_name = column_match = integer_column = NULL;
101 integer_type = NULL;
102
103
105 argc =
scanargs(&s_arg, argc, argv);
106 if (argc < 2)
108
109
110 for (i_arg = 1; i_arg < argc; i_arg++) {
111 if (s_arg[i_arg].arg_type == OPTION) {
114 case SET_COLUMN:
115 if (s_arg[i_arg].n_items < 2)
117 column_match =
118 tmalloc(
sizeof(*column_match) *
119 (column_matches = s_arg[i_arg].n_items - 1));
120 for (i = 0; i < column_matches; i++)
121 column_match[i] = s_arg[i_arg].list[i + 1];
122 break;
123 case SET_PIPE:
125 s_arg[i_arg].n_items - 1, &pipe_flags))
127 break;
128 default:
129 fprintf(stderr, "Error (%s): unknown switch: %s\n",
130 argv[0], s_arg[i_arg].list[0]);
131 exit(1);
132 break;
133 }
134 } else {
135 if (input == NULL)
136 input = s_arg[i_arg].list[0];
137 else if (output == NULL)
138 output = s_arg[i_arg].list[0];
139 else
141 }
142 }
143
144
146 no_warnings, &tmpfile_used);
147
148#ifdef DEBUG
149 fprintf(stderr, "Initializing input and output files.\n");
150#endif
151
154 exit(1);
155 }
156
157
158 if (!column_match)
160 else {
161 column_name =
163 &columns, SDDS_MATCH_COLUMN);
164 free(column_match);
165 }
166
167
168 for (i = 0; i < columns; i++) {
172 integer_column =
174 sizeof(*integer_column) * (integer_columns + 1));
175 integer_type =
177 sizeof(*integer_type) * (integer_columns + 1));
178 integer_column[integer_columns] = NULL;
179
181 integer_type[integer_columns] = type;
182 integer_columns++;
183 }
184 }
186 free(column_name);
187
188
189 if (!integer_columns) {
190 fprintf(stderr, "There are no integer columns in %s for converting.\n",
191 input);
192 exit(1);
193 }
194
195
198 exit(1);
199 }
200
201
202 for (i = 0; i < integer_columns; i++) {
203 sprintf(buff, "%sBinaryString", integer_column[i]);
206 SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
207 }
210 SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
211
212#ifdef DEBUG
213 fprintf(stderr, "Reading integer data from input file.\n");
214#endif
215
218 continue;
219 binary_string = malloc(sizeof(*binary_string) * rows);
222 SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
223
224
225 for (i = 0; i < integer_columns; i++) {
228 SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
229
230
232 digits = 16;
234 digits = 32;
235 else
236 digits = 64;
237
238
239 for (i_row = 0; i_row < rows; i_row++) {
240 binary_string[i_row] = NULL;
241 binary_string[i_row] =
242 (char *)malloc(sizeof(**binary_string) * (digits + 1));
243
244 for (j = 0; j < digits; j++) {
246 binary_string[i_row][digits - 1 - j] = (((short*)data)[i_row] >> j & 0x1) ? '1' : '0';
248 binary_string[i_row][digits - 1 - j] = (((unsigned short*)data)[i_row] >> j & 0x1) ? '1' : '0';
250 binary_string[i_row][digits - 1 - j] = (((int32_t*)data)[i_row] >> j & 0x1) ? '1' : '0';
252 binary_string[i_row][digits - 1 - j] = (((uint32_t*)data)[i_row] >> j & 0x1) ? '1' : '0';
254 binary_string[i_row][digits - 1 - j] = (((int64_t*)data)[i_row] >> j & 0x1) ? '1' : '0';
256 binary_string[i_row][digits - 1 - j] = (((uint64_t*)data)[i_row] >> j & 0x1) ? '1' : '0';
257 }
258 binary_string[i_row][digits] = 0;
259 }
260
261
262 sprintf(buff, "%sBinaryString", integer_column[i]);
264 rows, buff))
266 SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
268 }
269 free(binary_string);
270 binary_string = NULL;
271
272
275 SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
276 }
277
278
281 SDDS_VERBOSE_PrintErrors | SDDS_EXIT_PrintErrors);
283 exit(1);
285 free(integer_column);
287 return 0;
288}
int32_t SDDS_InitializeCopy(SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source, char *filename, char *filemode)
int32_t SDDS_CopyPage(SDDS_DATASET *SDDS_target, SDDS_DATASET *SDDS_source)
int32_t SDDS_SetColumn(SDDS_DATASET *SDDS_dataset, int32_t mode, void *data, int64_t rows,...)
Sets the values for one data column in the current data table of an SDDS dataset.
int32_t SDDS_DefineSimpleColumn(SDDS_DATASET *SDDS_dataset, const char *name, const char *unit, int32_t type)
Defines a simple data column within the SDDS dataset.
int32_t SDDS_WritePage(SDDS_DATASET *SDDS_dataset)
Writes the current data table to the output file.
int32_t SDDS_WriteLayout(SDDS_DATASET *SDDS_dataset)
Writes the SDDS layout header to the output file.
int32_t SDDS_FreeStringArray(char **string, int64_t strings)
Frees an array of strings by deallocating each individual string.
char ** getMatchingSDDSNames(SDDS_DATASET *dataset, char **matchName, int32_t matches, int32_t *names, short type)
Retrieves an array of matching SDDS entity names based on specified criteria.
int32_t SDDS_GetColumnIndex(SDDS_DATASET *SDDS_dataset, char *name)
Retrieves the index of a named column in the SDDS dataset.
char ** SDDS_GetColumnNames(SDDS_DATASET *SDDS_dataset, int32_t *number)
Retrieves the names of all columns in the SDDS dataset.
void SDDS_PrintErrors(FILE *fp, int32_t mode)
Prints recorded error messages to a specified file stream.
void SDDS_RegisterProgramName(const char *name)
Registers the executable program name for use in error messages.
int32_t SDDS_GetColumnType(SDDS_DATASET *SDDS_dataset, int32_t index)
Retrieves the data type of a column in the SDDS dataset by its index.
void SDDS_Bomb(char *message)
Terminates the program after printing an error message and recorded errors.
int32_t SDDS_CopyString(char **target, const char *source)
Copies a source string to a target string with memory allocation.
void * SDDS_Realloc(void *old_ptr, size_t new_size)
Reallocates memory to a new size.
#define SDDS_ULONG
Identifier for the unsigned 32-bit integer data type.
#define SDDS_STRING
Identifier for the string data type.
#define SDDS_ULONG64
Identifier for the unsigned 64-bit integer data type.
#define SDDS_LONG
Identifier for the signed 32-bit integer data type.
#define SDDS_SHORT
Identifier for the signed short integer data type.
#define SDDS_USHORT
Identifier for the unsigned short integer data type.
#define SDDS_LONG64
Identifier for the signed 64-bit integer data type.
void * tmalloc(uint64_t size_of_block)
Allocates a memory block of the specified size with zero initialization.
void bomb(char *error, char *usage)
Reports error messages to the terminal and aborts the program.
char * delete_chars(char *s, char *t)
Removes all occurrences of characters found in string t from string s.
long match_string(char *string, char **option, long n_options, long mode)
Matches a given string against an array of option strings based on specified modes.
long replaceFileAndBackUp(char *file, char *replacement)
Replaces a file with a replacement file and creates a backup of the original.
int scanargs(SCANNED_ARG **scanned, int argc, char **argv)
long processPipeOption(char **item, long items, unsigned long *flags)
void processFilenames(char *programName, char **input, char **output, unsigned long pipeFlags, long noWarnings, long *tmpOutputUsed)
void free_scanargs(SCANNED_ARG **scanned, int argc)
char * option[N_OPTIONS]
String representation of the command-line options.
char * usage
Usage message for the program.