/*************************************************************************\ * 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 sddsminterp.c (model interpolation) * interpolates data using another data set as a model function. * use abscissa from a values files or from the model function file. * version 1.0 Dec 1994 was called scaleref2data * version 2.0 June 1995 reads multiple table from the data file, * uses option syntax that resembles that of sddsinterp, * uses pipes. $Log: sddsminterp.c,v $ Revision 1.10 2006/10/19 17:55:39 soliday Updated to work with linux-x86_64. Revision 1.9 2005/11/04 22:46:15 soliday Updated code to be compiled by a 64 bit processor. Revision 1.8 2002/08/14 17:12:48 soliday Added Open License Revision 1.7 2001/01/10 19:35:41 soliday Standardized usage message. Revision 1.6 1999/05/25 19:11:27 soliday Removed compiler warning on linux. Revision 1.5 1999/01/06 19:54:47 borland Fixed the version number in the usage message. * Revision 1.4 1996/02/14 01:05:28 borland * Changed over from scan_item_list() to scanItemList(). * * Revision 1.3 1995/09/06 14:56:45 saunders * First test release of SDDS1.5 * */ #include "mdb.h" #include "scan.h" #include "match_string.h" #include "SDDS.h" #define CLO_COLUMNS 0 #define CLO_ORDER 1 #define CLO_MODEL 2 #define CLO_VALUES 3 #define CLO_VERBOSE 4 #define CLO_ASCII 5 #define CLO_PIPE 6 #define COMMANDLINE_OPTIONS 7 char *commandline_option[COMMANDLINE_OPTIONS] = { "columns", "order", "model", "fileValues", "verbose", "ascii", "pipe" }; static char *USAGE="sddsminterp [-pipe=[input],[output]] \n\ -columns=, [-interpOrder=]\n\ -model=,abscissa=,ordinate=[,interp=] \n\ -fileValues=[,abscissa=] \n\ -verbose -ascii\n\n\ Multiplicative renormalized model interpolation of a data set using another data set as a model function.\n\ columns specifies the data in the input file to be interpolated.\n\ order interpolation order of the multiplicative factor.\n\ model data representing the model function.\n\ fileValues specifies abscissa at which interpolated values are calculated.\n\ If not present, then the abscissa values of the model file are used.\n\ pipe writes the output to a pipe.\n\n\ Program by Louis Emery, ANL (This is version 3, February 1996.)\n"; #define MOD_ABSCISSA 0x0001U #define MOD_ORDINATE 0x0002U #define MOD_ORDER 0x0004U static char *modUsage="-model=,abscissa=,ordinate=[,interp=]\n"; #define VAL_ABSCISSA 0x0001U static char *valUsage="-valueFile=,abscissa=\n"; #define DEFAULT_ORDER 1 int main(int argc, char **argv) { SCANNED_ARG *s_arg; SDDS_DATASET modDataSet, valDataSet, dataDataSet, outDataSet; unsigned long modFlags, valFlags; char *modAbscissaName, *modOrdinateName; char *valAbscissaName; char *dataAbscissaName, *dataOrdinateName; char *outAbscissaName, *outOrdinateName; char *modFile, *dataFile, *valFile, *outFile; long dataOrder; int32_t modOrder; double *modAbscissa, *modOrdinate; double *valAbscissa; double *dataAbscissa, *dataOrdinate, *dataScale, *dataOrdinateInterp; double *outScale, *outAbscissa, *outOrdinate; long modRows, valRows, dataRows, outRows; long i, i_arg; long verbose; long warning; long ascii; long returnCode; unsigned long pipeFlags; long tmpfile_used, noWarnings; SDDS_RegisterProgramName(argv[0]); argc = scanargs(&s_arg, argc, argv); if (argc==1) bomb(NULL, USAGE); verbose=0; dataFile = dataAbscissaName = dataOrdinateName = modFile = valFile = NULL; modOrdinate = dataOrdinate = NULL; outFile = NULL; warning=0; modOrder=DEFAULT_ORDER; dataOrder=DEFAULT_ORDER; ascii=0; modFlags=0x0UL; valFlags=0x0UL; pipeFlags = 0; tmpfile_used = 0; noWarnings = 0; for (i_arg=1; i_argSDDS_StartPage(&outDataSet, outRows)) SDDS_PrintErrors(stdout, SDDS_EXIT_PrintErrors|SDDS_VERBOSE_PrintErrors); if(!SDDS_CopyParameters(&outDataSet, &dataDataSet) || !SDDS_CopyArrays(&outDataSet, &dataDataSet) || !SDDS_SetColumn(&outDataSet, SDDS_SET_BY_NAME|SDDS_PASS_BY_REFERENCE, modAbscissa, outRows, outAbscissaName)|| !SDDS_SetColumn(&outDataSet, SDDS_SET_BY_NAME|SDDS_PASS_BY_REFERENCE, outOrdinate, outRows, outOrdinateName)|| 0>SDDS_WritePage(&outDataSet)) SDDS_PrintErrors(stdout, SDDS_EXIT_PrintErrors|SDDS_VERBOSE_PrintErrors); free(dataAbscissa); free(dataOrdinate); free(dataOrdinateInterp); free(dataScale); free(outScale); free(outOrdinate); } if(!SDDS_Terminate(&modDataSet) || !SDDS_Terminate(&outDataSet)) SDDS_PrintErrors(stdout, SDDS_EXIT_PrintErrors|SDDS_VERBOSE_PrintErrors); if(!SDDS_Terminate(&dataDataSet)) SDDS_PrintErrors(stdout, SDDS_EXIT_PrintErrors|SDDS_VERBOSE_PrintErrors); if (tmpfile_used && !replaceFileAndBackUp(dataFile, outFile)) exit(1); return(0); }