/*************************************************************************\ * 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: mpl2sdds * purpose: add mpl data sets to a SDDS data set * * Michael Borland, 1993 $Log: mpl2sdds.c,v $ Revision 1.7 2009/06/01 15:37:51 soliday Moved the WriteLayout before the StartPage. Revision 1.6 2002/08/14 17:12:38 soliday Added Open License Revision 1.5 2001/01/23 19:14:56 soliday Standardized usage message. Revision 1.4 1999/05/25 19:04:02 soliday Removed compiler warning on linux. Revision 1.3 1995/09/06 14:55:55 saunders First test release of SDDS1.5 */ #include "mdb.h" #include "table.h" #include "SDDS.h" #include "scan.h" #include "match_string.h" #define SET_ERASE 0 #define SET_OUTPUT 1 #define SET_BINARY 2 #define N_OPTIONS 3 char *option[N_OPTIONS] = { "erase", "output", "binary" } ; char *USAGE = "mpl2sdds [...] \n\ -output= [-erase] [-binary]\n\n\ Program by Michael Borland. (This is version 1, November 1993.)."; void extract_name_and_unit(char **name, char **unit, char *label); long add_definition(SDDS_DATASET *SDDS_dataset, char *label, char *filename); void fix_mpl_name(char *name); int main(int argc, char **argv) { SDDS_DATASET SDDS_dataset; TABLE *mpl_data; SCANNED_ARG *scanned; char **input; long i, j, i_arg, inputs; char *output; long erase, rows, new_columns, SDDS_rows; double **data; long *index; long binary; SDDS_RegisterProgramName(argv[0]); argc = scanargs(&scanned, argc, argv); if (argc<3) bomb(NULL, USAGE); input = NULL; output = NULL; inputs = erase = binary = 0; for (i_arg=1; i_arg=0) { fprintf(stderr, "warning: column name %s from file %s already exists--ignored\n", name, filename); return(-1); } if ((index=SDDS_DefineColumn(SDDS_dataset, name, symbol, unit, NULL, NULL, SDDS_DOUBLE, 0))<0) { SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors); exit(1); } return(index); } void extract_name_and_unit(char **name, char **unit, char *label) { char *ptr, *uptr; if ((uptr=strchr(label, '('))) { *uptr++ = 0; if ((ptr=strchr(uptr, ')'))) *ptr = 0; SDDS_CopyString(unit, uptr); } else *unit = NULL; ptr = label + strlen(label)-1; while (ptr!=label && *ptr==' ') *ptr-- = 0; SDDS_CopyString(name, label); } void fix_mpl_name(char *name) { char *ptr, *ptr1; ptr = name; while ((ptr=strchr(ptr, '$'))) { switch (*(ptr+1)) { case 'a': case 'b': case 'n': case 'g': case 'r': case 's': case 'e': strcpy(ptr, ptr+2); break; default: ptr += 1; break; } } ptr = name; while ((ptr=strchr(ptr, ' '))) { ptr1 = ptr; while (*ptr1==' ') ptr1++; strcpy(ptr, ptr1); } }