/*************************************************************************\ * 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: sddsarray2column $Log: sddsarray2column.c,v $ Revision 1.12 2006/12/14 22:21:57 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.11 2005/11/04 22:46:11 soliday Updated code to be compiled by a 64 bit processor. Revision 1.10 2003/09/02 19:16:02 soliday Cleaned up code for Linux. Revision 1.9 2002/08/14 17:12:40 soliday Added Open License Revision 1.8 2002/02/11 17:44:53 soliday Fixed bug related to invalid indexes. Revision 1.7 2001/08/29 19:30:53 soliday Fixed a bug. Revision 1.6 2001/08/27 18:40:18 soliday Fixed some memory allocation problems. Revision 1.5 2001/08/27 15:47:03 soliday Added the ability to convert selected dimensions. Revision 1.4 2001/01/10 19:35:31 soliday Standardized usage message. Revision 1.3 2000/10/24 20:38:23 borland Now does multidimensional arrays. Revision 1.2 2000/10/20 15:27:09 soliday Fixed a problem with the pipe and with allocating row space when there are no columns to begin with. Revision 1.1 2000/10/19 21:42:04 soliday First version. * */ #include "mdb.h" #include "SDDS.h" #include "scan.h" #define SET_NOWARNINGS 0 #define SET_CONVERT 1 #define SET_PIPE 2 #define N_OPTIONS 3 char *option[N_OPTIONS] = { "nowarnings", "convert", "pipe", } ; #define DIM_0 0 #define DIM_1 1 #define DIM_2 2 #define DIM_OPTIONS 3 char *dim_option[DIM_OPTIONS] = { "d0", "d1", "d2", }; char *USAGE = "sddsarray2column [] []\n\ [-pipe=[input][,output]]\n\ [-nowarnings]\n\ [-convert=[,][,d=]...]\n\n\ sddsarray2column converts SDDS arrays to SDDS columns.\n\ The number of elements in the converted arrays must equal\n\ the number of rows if there are columns in the file and\n\ the number of elements in other converted arrays.\n\n\ Examples:\n\ sddsarray2column in out -convert=A,A_out\n\ sddsarray2column in out -convert=A,A_out,d0=0\n\ sddsarray2column in out \"-convert=A,A_out,d2=(1,3)\"\n\ Program by Robert Soliday. (Version 2, "__DATE__".)\n"; typedef struct { char *name, *new_name; char *d[3]; long *dim[3]; long dims[3]; void *data; long type; } CONVERTED_ARRAY; int main(int argc, char **argv) { CONVERTED_ARRAY *ca=NULL; SDDS_DATASET SDDS_dataset, SDDS_orig; ARRAY_DEFINITION *ardef=NULL; long i, i_arg, j, found, k, m, n; SCANNED_ARG *s_arg; char *input=NULL, *output=NULL, *ptr=NULL, *buffer=NULL; char *description_text=NULL, *description_contents=NULL; unsigned long pipeFlags=0; long noWarnings=0, tmpfile_used=1; long rows, virtual_rows, max_size, pageNumber, vrows; char **orig_column_name=NULL, **orig_parameter_name=NULL, **orig_array_name=NULL; int32_t orig_column_names=0, orig_parameter_names=0, orig_array_names=0; char **new_array_name=NULL; long new_array_names=0; long converted_array_names=0; SDDS_RegisterProgramName(argv[0]); argc = scanargs(&s_arg, argc, argv); if (argc<3) bomb(NULL, USAGE); for (i_arg=1; i_arg2) && (strchr(s_arg[i_arg].list[2],'=') == NULL)) { ca[converted_array_names].new_name=s_arg[i_arg].list[2]; i=3; } else { ca[converted_array_names].new_name=s_arg[i_arg].list[1]; i=2; } ca[converted_array_names].d[0] = NULL; ca[converted_array_names].d[1] = NULL; ca[converted_array_names].d[2] = NULL; while (i