Files
Work/proto/source/SPLINE.CPP
2024-08-07 09:16:27 -04:00

93 lines
2.6 KiB
C++

#include <common/windows.hpp>
#include <common/catmull.hpp>
#include <common/string.hpp>
#include <common/stdio.hpp>
#include <fileio/fileio.hpp>
BOOL readInFile(const String &pathFileName,PureVector<FloatPairs> &srcPairs);
int main(int argc,char **argv)
{
PureVector<FloatPairs> srcPairs;
PureVector<FloatPairs> dstPairs;
CatmullRom splineGen;
FileIO writeFile;
String strOutLine;
String srcFile;
String dstFile;
if(3!=argc)
{
::printf("Fortis Spline Generator Copyright(c) 1998\n");
::printf("USAGE: spline <infile> <outfile>\n");
::printf("where:\n");
::printf("<infile> contains point pair list (ie)\n");
::printf(" 1.00,4.356\n");
::printf(" 2.00,4.467\n");
::printf(" 4.00,4.393\n");
::printf(" 8.00,4.393\n");
::printf(" 20.00,4.393\n");
::printf(" 40.00,4.393\n");
::printf(" 120.00,4.393\n");
::printf("<outfile> is output destination\n");
::printf("* Don't forget to comma delimit the source file.\n");
::printf("* Keep in mind, the first number in the last line\n");
::printf(" is used to determine the size of the output data set.\n");
return 1;
}
if(!readInFile(argv[1],srcPairs))
{
::printf(String("Error reading ")+String(argv[1]));
return 1;
}
dstPairs.size(srcPairs[srcPairs.size()-1].column());
for(int index=1;index<=dstPairs.size();index++)dstPairs[index-1].column(index);
splineGen.performSpline(srcPairs,dstPairs);
writeFile.open(argv[2],FileIO::GenericWrite,FileIO::FileShareRead,FileIO::CreateAlways);
for(index=0;index<dstPairs.size();index++)
{
::sprintf(strOutLine,"%9.3lf",dstPairs[index].row());
writeFile.writeLine(strOutLine);
}
writeFile.close();
return 0;
}
BOOL readInFile(const String &pathFileName,PureVector<FloatPairs> &srcPairs)
{
FileIO inFile;
String strLine;
int numEntries(0);
inFile.open(pathFileName);
if(!inFile.isOkay())return FALSE;
while(inFile.readLine(strLine))
{
if(strLine.isNull())break;
numEntries++;
}
if(!numEntries)return FALSE;
inFile.rewind();
srcPairs.size(numEntries);
for(int index=0;index<numEntries;index++)
{
inFile.readLine(strLine);
srcPairs[index].column(::atof(strLine.betweenString(0,',')));
srcPairs[index].row(::atof(strLine.betweenString(',',0)));
}
inFile.close();
return TRUE;
}
// srcPairs.size(7);
// dstPairs.size(120);
// srcPairs[0]=FloatPairs(1.00,4.356);
// srcPairs[1]=FloatPairs(2.00,4.467);
// srcPairs[2]=FloatPairs(4.00,4.393);
// srcPairs[3]=FloatPairs(8.00,4.269);
// srcPairs[4]=FloatPairs(20.00,4.221);
// srcPairs[5]=FloatPairs(40.00,4.408);
// srcPairs[6]=FloatPairs(120.00,4.965);
// for(int index=1;index<=dstPairs.size();index++)dstPairs[index-1].column(index);