/*************************************************************************\ * 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: sddsexpand * purpose: take a SDDS file and create a new file with the * columns turned into parameters. Each page of the * new file corresponds to a row of the old file. * This is basically an inverse of sddscollapse. * * Michael Borland, 1999 * $Log: sddsexpand.c,v $ Revision 1.10 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.9 2005/11/04 22:46:13 soliday Updated code to be compiled by a 64 bit processor. Revision 1.8 2002/08/14 17:12:45 soliday Added Open License Revision 1.7 2002/01/16 18:02:18 soliday Added missing SDDS_Terminate and free functions. Revision 1.6 2001/01/23 19:47:28 soliday Fixed Solaris compiler warnings. Revision 1.5 1999/05/25 19:09:37 soliday Removed compiler warning on linux. Revision 1.4 1999/03/11 14:42:04 soliday Fixed warning message. Revision 1.3 1999/01/06 20:28:41 borland Fixed the program name in the processFilenames call. Revision 1.2 1999/01/06 19:31:41 borland Now copies parameter data as well as column data from input to output. Revision 1.1 1999/01/06 19:04:56 borland First version. */ #include "mdb.h" #include "scan.h" #include "SDDS.h" #define SET_PIPE 0 #define SET_NOWARNINGS 1 #define N_OPTIONS 2 char *option[N_OPTIONS] = { "pipe", "nowarnings", } ; char *USAGE="sddsexpand [-pipe=[input][,output]] [] []\n\ [-noWarnings]\n\n\ sddsexpand is the partial inverse of sddscollapse. All columns of the input file \ are turned into parameters in the output file. For each row of each page in \ the input file, sddsexpand emits a new page with parameter values equal to the \ column values for that page and row.\n\n\ Program by Michael Borland. (This is version 1, January 1999.)\n"; #define ROW_INCREMENT 100 typedef struct { char *name; long size; long index; /* index in the target data set */ short doCopy; } SOURCE_DATA; int main(int argc, char **argv) { SDDS_DATASET SDDS_input, SDDS_output; char *inputfile, *outputfile; long rows, irow, i, i_arg, noWarnings; SCANNED_ARG *s_arg; unsigned long pipeFlags; void **data; SOURCE_DATA *columnSource, *parameterSource; int32_t columnSources, parameterSources; char **name; char buffer[32]; SDDS_RegisterProgramName(argv[0]); argc = scanargs(&s_arg, argc, argv); if (argc<2) bomb(NULL, USAGE); inputfile = outputfile = NULL; pipeFlags = noWarnings = 0; data = NULL; columnSource = parameterSource = NULL; for (i_arg=1; i_arg=0) { if (!noWarnings) fprintf(stderr, "Warning (sddsexpand): name %s used for parameter and column in input file. Column data used.\n", parameterSource[i].name); parameterSource[i].doCopy = 0; continue; } parameterSource[i].doCopy = 1; if (!SDDS_TransferParameterDefinition(&SDDS_output, &SDDS_input, parameterSource[i].name, NULL) || (parameterSource[i].index = SDDS_GetParameterIndex(&SDDS_output, parameterSource[i].name))<0) SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors|SDDS_EXIT_PrintErrors); parameterSource[i].size = SDDS_GetTypeSize(SDDS_GetParameterType(&SDDS_output, parameterSource[i].index)); } if (!SDDS_WriteLayout(&SDDS_output) || !(data=SDDS_Malloc(sizeof(*data)*columnSources))) SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors|SDDS_EXIT_PrintErrors); while (SDDS_ReadPage(&SDDS_input)>0) { if ((rows=SDDS_RowCount(&SDDS_input))<0) continue; for (i=0; i