/*************************************************************************\ * 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: sddsshiftcor.c,v $ * Revision 1.7 2005/11/04 22:46:18 soliday * Updated code to be compiled by a 64 bit processor. * * Revision 1.6 2003/09/02 19:16:07 soliday * Cleaned up code for Linux. * * Revision 1.5 2002/08/14 17:12:54 soliday * Added Open License * * Revision 1.4 2000/04/13 18:04:25 soliday * Removed invalid prototypes. * * Revision 1.3 2000/04/13 17:12:07 soliday * Added missing include statment. * * Revision 1.2 1999/07/29 21:28:07 borland * Now constructs output columns by transferring defs of input columns. * * Revision 1.1 1999/07/08 16:54:35 borland * Added sddsshiftcor * */ #include "mdb.h" #include "SDDS.h" #include "scan.h" #include "SDDSutils.h" #include #define SET_COLUMNS 0 #define SET_EXCLUDE 1 #define SET_WITH 2 #define SET_PIPE 3 #define SET_RANKORDER 4 #define SET_STDEVOUTLIER 5 #define SET_SCAN 6 #define SET_VERBOSE 7 #define N_OPTIONS 8 char *option[N_OPTIONS] = { "columns", "excludecolumns", "with", "pipe", "rankorder", "stdevoutlier", "scan", "verbose" }; #define USAGE "sddsshiftcor [-pipe=[input][,output]] [] [] -with=\n\ [-scan=start=,end=,delta=]\n\ [-columns=] [-excludeColumns=]\n\ [-rankOrder] [-stDevOutlier[=limit=][,passes=]] [-verbose]\n\n\ Program by Michael Borland. (This is version 1, July 1999.)\n" void replaceWithRank(double *data, long n); double *findRank(double *data, long n); void markStDevOutliers(double *data, double limit, long passes, short *keep, long n); void setupOutputFile(SDDS_DATASET *SDDSout, char *output, char **column, long columns); int main(int argc, char **argv) { int iArg; char **column, **excludeColumn, *withOnly; long columns, excludeColumns; char *input, *output, buffer[16384]; SCANNED_ARG *scanned; SDDS_DATASET SDDSin, SDDSout; long i, rows, count, readCode, rankOrder; int32_t outlierStDevPasses; double **data, correlation, outlierStDevLimit; double **rank; short **accept; unsigned long pipeFlags, dummyFlags; int32_t startShift, endShift, deltaShift; long outputRows, maxShift, iWith, outputRow, shiftAmount, verbose; SDDS_RegisterProgramName(argv[0]); argc = scanargs(&scanned, argc, argv); if (argc<2) bomb(NULL, USAGE); output = input = withOnly = NULL; columns = excludeColumns = 0; column = excludeColumn = NULL; pipeFlags = 0; rankOrder = 0; outlierStDevPasses = 0; outlierStDevLimit = 1.; rank = NULL; accept = NULL; startShift = -(endShift = 10); deltaShift = 1; verbose = 0; for (iArg=1; iArg=endShift || deltaShift<=0 || (endShift-startShift)-startShift?endShift:-startShift; iWith = -1; while ((readCode=SDDS_ReadPage(&SDDSin))>0) { if ((rows = SDDS_CountRowsOfInterest(&SDDSin))<(endShift-startShift)) continue; if (!SDDS_StartPage(&SDDSout, outputRows+1)) SDDS_PrintErrors(stderr, SDDS_VERBOSE_PrintErrors|SDDS_EXIT_PrintErrors); for (i=0; i0) { absLimit = limit*sqrt(variance); for (i=0; iabsLimit) { keep[i] = 0; kept--; } } } } typedef struct { double data; long originalIndex; } DATAnINDEX; int compareData(const void *d1, const void *d2) { double diff; diff = ((DATAnINDEX*)d1)->data - ((DATAnINDEX*)d2)->data; return diff==0? 0 : (diff<0 ? -1 : 1 ); } double *findRank(double *data, long n) { long i; double *rank; if (!(rank = (double*)malloc(sizeof(*rank)*n))) return NULL; for (i=0; i