/*************************************************************************\ * Copyright (c) 2002 The University of Chicago, as Operator of Argonne * National Laboratory. * Copyright (c) 2002 The Regents of the University of California, as * Operator of Los Alamos National Laboratory. * This file is distributed subject to a Software License Agreement found * in the file LICENSE that is included with this distribution. \*************************************************************************/ /* program: sddsconvert * purpose: copy a SDDS file and allow ascii/binary switching * * Michael Borland, 1993 $Log: sddsconvert.c,v $ Revision 1.20 2007/06/08 21:51:15 soliday Removed call to free_scanargs because string arguments currently are not copied with SDDS_CopyString which free_scanargs requires. Revision 1.19 2007/03/27 21:30:56 soliday Cleaned up the code. Revision 1.18 2006/12/14 22:21:58 soliday Updated a bunch of programs because SDDS_SaveLayout is now called by SDDS_WriteLayout and it is no longer required to be called directly. Also the AutoCheckMode is turned off by default now so I removed calls to SDDS_SetAutoCheckMode that would attempt to turn it off. It is now up to the programmer to turn it on in new programs until debugging is completed and then remove the call to SDDS_SetAutoCheckMode. Revision 1.17 2005/11/04 22:46:12 soliday Updated code to be compiled by a 64 bit processor. Revision 1.16 2003/09/02 20:36:37 soliday Cleaned up for WIN32 Revision 1.15 2003/04/29 17:23:41 borland Added -rowlimit option. Revision 1.14 2002/08/14 17:12:42 soliday Added Open License Revision 1.13 2002/05/07 20:14:40 shang freed memory allocated for sdds array Revision 1.12 2001/03/26 19:16:29 soliday Added options -removePages and -keepPages. Revision 1.11 2001/01/10 19:35:34 soliday Standardized usage message. Revision 1.10 1999/05/25 19:07:08 soliday Removed compiler warning on linux. Revision 1.9 1999/01/06 19:54:40 borland Fixed the version number in the usage message. * Revision 1.8 1996/06/11 22:12:10 borland * Added debugging statements to help with performance evaluation. * * Revision 1.7 1996/04/09 04:56:10 borland * Now use SDDS_GetInternalColumn for better performance. * * Revision 1.6 1995/10/31 02:38:10 borland * Fixed -toPage implementation to exit just after processing the indicated page, * rather than after reading the next page. * * Revision 1.5 1995/10/05 17:31:14 borland * Added initialization for noWarnings and ascii_output variables. * * Revision 1.4 1995/09/12 03:10:35 borland * Added -acceptAllNames option to give backward compatibility for "illegal" element names. * * Revision 1.3 1995/09/06 14:56:16 saunders * First test release of SDDS1.5 * */ #include "mdb.h" #include "SDDS.h" #include "scan.h" #define COLUMN_MODE 0 #define PARAMETER_MODE 1 #define ARRAY_MODE 2 #define MODES 3 static char *mode_name[MODES] = { "column", "parameter", "array", } ; #define SET_BINARY 0 #define SET_ASCII 1 #define SET_DELETE 2 #define SET_RETAIN 3 #define SET_RENAME 4 #define SET_DESCRIPTION 5 /* -table is retained for backward compatibility: */ #define SET_TABLE 6 #define SET_EDIT_NAMES 7 #define SET_LINES_PER_ROW 8 #define SET_NOWARNINGS 9 #define SET_RECOVER 10 #define SET_PIPE 11 #define SET_FROMPAGE 12 #define SET_TOPAGE 13 #define SET_ACCEPT_ALL_NAMES 14 #define SET_REMOVEPAGES 15 #define SET_KEEPPAGES 16 #define SET_ROWLIMIT 17 #define N_OPTIONS 18 char *option[N_OPTIONS] = { "binary", "ascii", "delete", "retain", "rename", "description", "table", "editnames", "linesperrow", "nowarnings", "recover", "pipe", "frompage", "topage", "acceptallnames", "removePages", "keepPages", "rowlimit", } ; char *USAGE = "sddsconvert [] []\n\ [-pipe=[input][,output]]\n\ [-binary] [-ascii] [-description=,]\n\ [-fromPage=] [-toPage=]\n\ [-removePages=] [-keepPages=]\n\ [-linesperrow=] [-nowarnings] [-recover[=clip]]\n\ [-delete={column|parameter|array},[,...]]\n\ [-retain={column|parameter|array},[,...]]\n\ [-rename={column|parameter|array},=[,...]]\n\ [-editnames={column|parameter|array},,]\n\ [-acceptAllNames] [-rowlimit=]\n\n\ sddsconvert converts SDDS files between ASCII and binary, and allows wildcard-based\ filtering-out of unwanted columns and/or rows.\n\ Any column or parameter matched by a deletion string is deleted unless it is matched by a retention string.\n\ The -acceptAllNames option may be used to force the SDDS library to accept\n\ element names that have spaces and other normally unacceptable characters.\n\n\ Program by Michael Borland. (This is version 6, April 2003.)\n"; typedef char *STRING_PAIR[2]; typedef struct { char *match_string, *edit_string; } EDIT_NAME_REQUEST; char **process_name_options(char **orig_name, long **orig_flag, long orig_names, char **delete, long deletes, char **retain, long retains, STRING_PAIR *rename, long renames, EDIT_NAME_REQUEST *edit_request, long edit_requests); int main(int argc, char **argv) { SDDS_DATASET SDDS_dataset, SDDS_orig; long i, i_arg; SCANNED_ARG *s_arg; char *description_text, *description_contents; long first, tmpfile_used, noWarnings; char *input, *output, *ptr, *buffer; long ascii_output, binary_output, recover, recovered; unsigned long pipeFlags; char **retain_column, **delete_column; long retain_columns, delete_columns, rename_columns, edit_column_requests; EDIT_NAME_REQUEST *edit_column_request; STRING_PAIR *rename_column; char **orig_column_name, **new_column_name; long *orig_column_flag=NULL; int32_t orig_column_names; char **retain_parameter, **delete_parameter; long retain_parameters, delete_parameters, rename_parameters, edit_parameter_requests; EDIT_NAME_REQUEST *edit_parameter_request; STRING_PAIR *rename_parameter; char **orig_parameter_name, **new_parameter_name; long *orig_parameter_flag=NULL; int32_t orig_parameter_names; char **retain_array, **delete_array; long retain_arrays, delete_arrays, rename_arrays, edit_array_requests; EDIT_NAME_REQUEST *edit_array_request; STRING_PAIR *rename_array; char **orig_array_name, **new_array_name; long *orig_array_flag=NULL; int32_t orig_array_names; long lines_per_row, pageNumber=0, fromPage, toPage; long rows, max_size, output_columns; long *removePage, *keepPage; long removePages, keepPages, keep; long rowLimit; new_column_name = new_parameter_name = new_array_name = NULL; SDDS_RegisterProgramName(argv[0]); argc = scanargs(&s_arg, argc, argv); if (argc<3) { fprintf(stderr, "%s\n", USAGE); return(1); } input = output = NULL; ascii_output = binary_output = noWarnings = 0; retain_column = delete_column = NULL; retain_columns = delete_columns = rename_columns = edit_column_requests = 0; rename_column = NULL; edit_column_request = NULL; retain_parameter = delete_parameter = NULL; retain_parameters = delete_parameters = rename_parameters = edit_parameter_requests = 0; rename_parameter = NULL; edit_parameter_request = NULL; retain_array = delete_array = NULL; retain_arrays = delete_arrays = rename_arrays = edit_array_requests = 0; rename_array = NULL; edit_array_request = NULL; tmpfile_used = 0; description_text = description_contents = NULL; fromPage = toPage = recover = 0; removePage = keepPage = NULL; removePages = keepPages = 0; lines_per_row = 1; pipeFlags = 0; for (i_arg=1; i_arg