/*************************************************************************\ * 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. \*************************************************************************/ /* * $Log: wfm2sdds.c,v $ Revision 1.7 2009/01/20 20:41:56 soliday Fixed an issue with the postcharge offset. Revision 1.6 2009/01/19 22:42:05 soliday Added support for FastFrames (multiple waveforms) Revision 1.5 2008/11/13 15:47:54 soliday Fixed an issue on 64bit machines. Revision 1.4 2006/12/14 22:22:01 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.3 2006/02/13 21:36:34 soliday Added support for WIN32. Revision 1.2 2006/02/13 16:04:34 soliday Added options to include an Index column. Also added options to output the data in float format instead of double format. Revision 1.1 2006/02/10 21:26:34 soliday Wrote program to convert binary WFM data from Tektronix TDS scopes into SDDS data. * */ #include "mdb.h" #include "SDDS.h" #include "scan.h" #if defined(_WIN32) #include #include #if defined(__BORLANDC__) #define _setmode(handle, amode) setmode(handle, amode) #endif #endif void swapdouble(double *l); void swapfloat(float *l); void swaplongLong(uint64_t *l); void swaplong(uint32_t *l); void swapshort(short *l); void swaplonglong(uint64_t *l) { unsigned char *cp = (unsigned char *) l; unsigned char temp; temp = cp[0]; cp[0] = cp[7]; cp[7] = temp; temp = cp[1]; cp[1] = cp[6]; cp[6] = temp; temp = cp[2]; cp[2] = cp[5]; cp[5] = temp; temp = cp[3]; cp[3] = cp[4]; cp[4] = temp; } void swapdouble(double *l) { unsigned char *cp = (unsigned char *) l; unsigned char temp; temp = cp[0]; cp[0] = cp[7]; cp[7] = temp; temp = cp[1]; cp[1] = cp[6]; cp[6] = temp; temp = cp[2]; cp[2] = cp[5]; cp[5] = temp; temp = cp[3]; cp[3] = cp[4]; cp[4] = temp; } void swapfloat(float *l) { unsigned char *cp = (unsigned char *) l; unsigned char temp; temp = cp[0]; cp[0] = cp[3]; cp[3] = temp; temp = cp[1]; cp[1] = cp[2]; cp[2] = temp; } void swaplong(uint32_t *l) { unsigned char *cp = (unsigned char *) l; unsigned char temp; temp = cp[0]; cp[0] = cp[3]; cp[3] = temp; temp = cp[1]; cp[1] = cp[2]; cp[2] = temp; } void swapshort(short *l) { unsigned char *cp = (unsigned char *) l; unsigned char temp; temp = cp[0]; cp[0] = cp[1]; cp[1] = temp; } int INTEL=0; #define SET_ASCII 0 #define SET_BINARY 1 #define SET_DUMPHEADER 2 #define SET_PIPE 3 #define SET_WITHINDEX 4 #define SET_FLOAT 5 #define SET_DOUBLE 6 #define N_OPTIONS 7 char *option[N_OPTIONS] = { "ascii", "binary", "dumpheader", "pipe", "withindex", "float", "double" }; char *USAGE = "wfm2sdds [] [] [-pipe[=in][,out]]\n\ [-ascii | -binary]\n\ [-withIndex]\n\ [-float | -double]\n\ [-dumpHeader]\n\n\ pipe SDDS toolkit pipe option.\n\ ascii Requests SDDS ASCII output. Default is binary.\n\ binary Requests SDDS BINARY output.\n\ withIndex Add Index column.\n\ float Output in float format. Default is double.\n\ double Output in double format.\n\ dumpHeader Print all header info to stdout.\n\n\ Converts Tektronix WFM files to SDDS.\n\ Program by Robert Soliday. ("__DATE__")\n"; int main(int argc,char **argv) { FILE *fd; char *input=NULL, *output=NULL; SDDS_DATASET SDDSout; SCANNED_ARG *scanned; long iArg; long ascii=0, dumpheader=0; unsigned long pipeFlags=0; int i=0, j=0, n; int withIndex=0, floatValues=0, version=0; /* 1=char 2=short 3=unsigned short 4=long 5=unsigned long 6=unsigned long long 7=float 8=double 9=char[] */ short fileFormat[122] = {3, 9, 1, 4, 1, 4, 4, 7, 8, 7, 9, 5, 3, 5, 5, 6, 6, 5, 4, 5, 5, 5, 5, 6, 5, 5, 5, 5, 5, 3, 5, 6, 8, 8, 5, 9, 8, 8, 8, 8, 5, 5, 4, 4, 4, 4, 4, 8, 9, 8, 5, 8, 8, 8, 8, 5, 9, 8, 8, 8, 8, 5, 5, 4, 4, 4, 4, 4, 8, 9, 8, 5, 8, 8, 8, 8, 5, 9, 8, 8, 8, 8, 5, 8, 9, 8, 5, 8, 8, 8, 8, 5, 9, 8, 8, 8, 8, 5, 8, 9, 8, 5, 8, 8, 5, 5, 5, 5, 5, 5, 5, 8, 8, 4, 7, 5, 2, 5, 5, 5, 5, 5}; short fileBits[122] = {2, 8, 1, 4, 1, 4, 4, 4, 8, 4, 32, 4, 2, 4, 4, 8, 8, 4, 4, 4, 4, 4, 4, 8, 4, 4, 4, 4, 4, 2, 4, 8, 8, 8, 4, 20, 8, 8, 8, 8, 4, 4, 4, 4, 4, 4, 4, 8, 20, 8, 4, 8, 8, 8, 8, 4, 20, 8, 8, 8, 8, 4, 4, 4, 4, 4, 4, 4, 8, 20, 8, 4, 8, 8, 8, 8, 4, 20, 8, 8, 8, 8, 4, 8, 20, 8, 4, 8, 8, 8, 8, 4, 20, 8, 8, 8, 8, 4, 8, 20, 8, 4, 8, 8, 4, 4, 4, 4, 4, 4, 4, 8, 8, 4, 4, 4, 2, 4, 4, 4, 4, 4}; char Char; short Short; unsigned short uShort; int32_t Long; uint32_t uLong; uint64_t uLLong; float Float; double Double; char buffer[50]; short bytesPerPoint=2; unsigned long prechargeoffset=0; unsigned long *precharge; unsigned long RecLength=0; unsigned long *recordLength; unsigned long postchargestart=0, postchargestop=0, postcharge; double sampleInterval=1; char sampleUnits[50]; double sampleStart=0; double triggerPositionPercent=0; int32_t *triggerPoint; long timeInt; double *time; double timeFrac=0; double expDimInterval=1, expDimStart=0; char expDimUnits[50]; int32_t *index=NULL; double *sample=NULL, *curve=NULL; uint32_t waveform, waveforms=1; SDDS_RegisterProgramName(argv[0]); argc = scanargs(&scanned, argc, argv); if (argc<2) { fprintf(stderr, "%s", USAGE); return(1); } for (iArg=1; iArg