Skip to content
Snippets Groups Projects
Commit e069fba9 authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

mp* and ms* work. still 29 TODO's

parent 48e0edcd
No related branches found
No related tags found
No related merge requests found
......@@ -424,6 +424,9 @@ void NManip::ScaSelect( string del_or_ret )
}
}
//! Bin spectra.
void NManip::ScaAvge()
{
NOlm::SelAssert();
......@@ -507,10 +510,11 @@ void NManip::ScaAvge()
}
}
ScaRemoveConstantZ( fout );
NOlm::OloAdd( fout );
NOlm::OloAdd( fout, fiter.k() );
}
}
//! Merge spectra, concatenating points.
void NManip::ScaJoin()
......@@ -520,37 +524,39 @@ void NManip::ScaJoin()
CList JSel;
static string jSel = "";
NOlm::JSelAsk( "Start groups at spectra", &jSel, &JSel );
vector<double> y;
uint ji, jf, n, nz;
string err;
NOlm::IterateD fiter;
POld fin;
while( fin = fiter() ) {
POld fout;
// fout = *fin;
cerr << "TODO probably broken after V rewrite\n";
POld fout( new COld( *fin ) );
fout->V.clear();
JSel.evaluate( 0, fin->nJ()-1 );
if (JSel.V.size()<1 || JSel.V[0]!=0)
throw string( "spectrum selection must contain 0" );
fout->lDoc.push_back("msj " + JSel.str());
fout->V.clear();
nz = fin->nZ();
for(uint iv=0; iv<JSel.size(); iv++) {
cerr << "WARNING: z just taken from first spectrum of each group\n";
for ( uint iv=0; iv<JSel.size(); iv++ ) {
uint ji, jf;
ji = JSel.V[iv];
jf = ( iv<JSel.size()-1 ? JSel.V[iv+1] : fin->nJ() );
PSpec sout( new CSpec( *(fin->VS(ji)) ) );
n = fin->VS(ji)->size();
bool with_dy = fin->VS(ji)->dy.size();
for ( uint jj=ji+1; jj<jf; jj++){
for( uint i=0; i<fin->VS(jj)->size(); ++i )
sout->push_xy( fin->VS(jj)->x[i], fin->VS(jj)->y[i] );
if ( with_dy )
sout->push_xyd( fin->VS(jj)->x[i], fin->VS(jj)->y[i],
fin->VS(jj)->dy[i]);
else
sout->push_xy( fin->VS(jj)->x[i], fin->VS(jj)->y[i] );
}
fout->V.push_back(sout);
}
ScaRemoveConstantZ( fout );
NOlm::OloAdd( fout );
NOlm::OloAdd( fout, fiter.k() );
}
}
//! After each span, insert given number of copies.
void NManip::ScaSpawn()
......@@ -565,105 +571,106 @@ void NManip::ScaSpawn()
NOlm::IterateO fiter;
POlo fin;
while( fin = fiter() ) {
POlo fout; // TODO
// fout = fin->copy();
// fout->clear();
fout->ZCo.push_back(CCoord("no-in-spawn", ""));
POlo fout( fin->new_olo() );
fout->lDoc.push_back( "ms* " + strg(njj) );
fout->ZCo.push_back(CCoord("no-in-spawn", ""));
for( uint jj=0; jj<njj; ++jj ){
for( uint j=0; j<fin->nJ(); j++ ){
/* TODO PZentry E( new CZentry( fin->V[j] ) );
E->z.push_back( jj );
fout->V.push_back( E );
*/
PZentry eout = fin->new_zentry( j );
eout->z.push_back( jj );
fout->V.push_back( eout );
}
}
NOlm::OloAdd(fout);
NOlm::OloAdd( fout, fiter.k() );
}
}
//! Exchange x and z.
void NManip::ScaExch()
{
NOlm::SelAssert();
vector<double> zcommon, xcommon;
uint ji, jf, j, i, ii, izco;
CCoord xcoin, zcoin;
string doc;
NOlm::IterateD fiter;
POld fin;
while( fin = fiter() ) {
POld fout; // TODO = *fin;
POld fout( new COld (*fin ) );
fout->V.clear();
xcoin = fin->xco;
izco = fin->ZCo.size() - 1;
uint izco = fin->ZCo.size() - 1;
if ( izco==(uint)-1 )
throw string( "no input z coordinate" );
zcoin = fin->ZCo[izco];
doc = "msx # exchanging x=" + xcoin.str() + " against z" + strg(izco)
+ "=" + zcoin.str();
cout << doc+"\n";
fout->lDoc.push_back(doc);
fout->xco = zcoin;
fout->ZCo[izco] = xcoin;
fout->lDoc.push_back(
"msx # exchanging x=" + fin->xco.str() +
" with z" + strg(izco) + "=" + fin->ZCo[izco].str() );
fout->xco = fin->ZCo[izco];
fout->ZCo[izco] = fin->xco;
if ( fin->nJ()<=0 )
throw string( "no spectra in file" );
for (ji=0; ji<fin->nJ(); ) {
vector<double> zcommon, xcommon;
uint ji, jf;
for ( ji=0; ji<fin->nJ(); ) {
zcommon.clear();
for (i=0; i<izco; ++i)
for ( uint i=0; i<izco; ++i)
zcommon.push_back(fin->V[ji]->z[i]);
for (jf=ji+1; jf<fin->nJ(); jf++)
for (i=0; i<izco; ++i)
for ( jf=ji+1; jf<fin->nJ(); jf++ )
for ( uint i=0; i<izco; ++i)
if (fin->V[jf]->z[i] != zcommon[i])
goto end_group;
end_group:
// build common grid:
xcommon.clear();
for (j=ji; j<jf; ++j)
for (i=0; i<fin->VS(j)->size(); ++i)
for ( uint j=ji; j<jf; ++j )
for ( uint i=0; i<fin->VS(j)->size(); ++i )
xcommon.push_back( fin->VS(j)->x[i] );
sort(xcommon.begin(), xcommon.end());
sort( xcommon.begin(), xcommon.end() );
mystd::unique(&xcommon, 1e-180, 1e-20);
printf("group of spectra %u .. %u has %zu different x\n",
ji, jf-1, xcommon.size());
ii = 0; // a guess
for(i=0; i<xcommon.size(); ++i) {
uint ii = 0; // a guess
for ( uint i=0; i<xcommon.size(); ++i ) {
PSpec sout( new CSpec );
sout->z = zcommon;
sout->z.push_back(xcommon[i]);
for (j=ji; j<jf; ++j){
if( fin->VS(j)->x[ii]!=xcommon[i] ){ // guess failed
for (ii=0; ii<fin->VS(j)->size(); ++ii)
if( fin->VS(j)->x[ii]==xcommon[i] )
for ( uint j=ji; j<jf; ++j ) {
PSpec sin = fin->VS( j );
bool with_dy = sin->dy.size();
if( sin->x[ii]!=xcommon[i] ){ // guess failed
for (ii=0; ii<sin->size(); ++ii)
if( sin->x[ii]==xcommon[i] )
break;
}
if( ii<fin->VS(j)->size() )
sout->push_xy( fin->V[j]->z[izco], fin->VS(j)->y[ii] );
if( ii<sin->size() ){
if( with_dy )
sout->push_xyd( sin->z[izco], sin->y[ii],
sin->dy[ii] );
else
sout->push_xy( sin->z[izco], sin->y[ii] );
}
}
fout->V.push_back(sout);
fout->V.push_back( sout );
++ii;
}
ji = jf;
}
NOlm::OloAdd( fout );
NOlm::OloAdd( fout, fiter.k() );
}
}
//! Sort spectra according to expression.
void NManip::ScaSortByExpr()
......@@ -678,28 +685,25 @@ void NManip::ScaSortByExpr()
NOlm::IterateO fiter;
POlo fin;
while( fin = fiter() ) {
uint k = fiter.k();
POld fout; // TODO fout = *fin;
fout->V.clear();
POlo fout( fin->new_olo() );
fout->lDoc.push_back("mso "+expr);
uint nj = fin->nJ();
vector<double> v(nj);
size_t P[nj];
for (uint j=0; j<nj; j++) {
T->tree_point_val( &(v[j]), k, j );
}
for (uint j=0; j<nj; j++)
T->tree_point_val( &(v[j]), fiter.k(), j );
gsl_sort_index (P, &(v[0]), 1, nj);
size_t pos[nj];
gsl_sort_index (pos, &(v[0]), 1, nj);
for (uint j=0; j<nj; j++) {
fout->V.push_back( fin->V[P[j]] );
}
NOlm::OloAdd( fout );
for (uint j=0; j<nj; j++)
fout->V.push_back( fin->new_zentry( pos[j] ) );
NOlm::OloAdd( fout, fiter.k() );
}
}
//! Sort spectra according to full z vector.
void NManip::ScaSortByZ()
......@@ -709,26 +713,26 @@ void NManip::ScaSortByZ()
NOlm::IterateO fiter;
POlo fin;
while( fin = fiter() ) {
/* TODO
fout = *fin;
sort( fout.V.begin(), fout.V.end(), CompareZ );
NOlm::OloAdd( fout );
*/
POlo fout( fin->new_olo() );
for (uint j=0; j<fin->nJ(); j++)
fout->V.push_back( fin->new_zentry( j ) );
sort( fout->V.begin(), fout->V.end(), CompareZ );
NOlm::OloAdd( fout, fiter.k() );
}
}
//! Change order of z coordinates.
void NManip::ZExchange()
{
NOlm::SelAssert();
int nzmax = 0;
int nzmin;
int nzmin, nzmax = 0;
char mod;
string com;
int num1;
int num2;
int num1, num2;
NOlm::IterateO fiter;
POlo fin;
while( fin = fiter() ) {
......@@ -776,11 +780,14 @@ void NManip::ZExchange()
fiter.reset();
while( fin = fiter() ) {
POlo fout; // TODO = *fin;
POlo fout( fin->new_olo() );
fout->lDoc.push_back( com );
for (uint j=0; j<fin->nJ(); j++)
fout->V.push_back( fin->new_zentry( j ) );
int nz = fout->ZCo.size();
if ( nz<nzmin ){
printf( "WARNING nz<nzmin\n" );
cerr << "WARNING nz<nzmin\n";
} else if( mod=='r' ){
for( int irot=0; irot<num1; ++irot ){
for( int iz=1; iz<nz; ++iz ){
......@@ -815,7 +822,7 @@ void NManip::ZExchange()
fout->V[j]->z[num2] = fin->V[j]->z[num1];
}
}
NOlm::OloAdd( fout );
NOlm::OloAdd( fout, fiter.k() );
}
}
......@@ -831,26 +838,28 @@ void NManip::ZDelete()
sel = wask("Delete z coordinates (-=quit)");
if (sel=="-" || sel=="q") return;
IndexSet ISel;
IndexSetIterator II;
uint iz;
NOlm::IterateO fiter;
POlo fin;
while( fin = fiter() ) {
POlo fout;// TODO = *fin;
POlo fout( fin->new_olo() );
fout->lDoc.push_back("mz- "+sel);
for (uint j=0; j<fin->nJ(); j++)
fout->V.push_back( fin->new_zentry( j ) );
IndexSet ISel;
if ( ISel.parse(sel, 0, fin->ZCo.size()) )
throw ( "invalid selection for file " + strg( fiter.k() ) );
IndexSetIterator II;
II.setback(ISel);
uint iz;
while (II(&iz)) {
fout->ZCo.erase(fout->ZCo.begin()+iz);
for (uint j=0; j<fin->nJ(); j++)
fout->V[j]->z.erase(fout->V[j]->z.begin()+iz);
}
NOlm::OloAdd( fout );
NOlm::OloAdd( fout, fiter.k() );
}
}
......@@ -861,38 +870,30 @@ void NManip::ScaBreak()
{
NOlm::SelAssert();
CCoord zco;
double zval;
NOlm::IterateD fiter;
POld fin;
NOlm::IterateO fiter;
POlo fin;
while( fin = fiter() ) {
if (!(fin->ZCo.size()))
throw string( "invalid operation / no z coordinate" );
zco = fin->ZCo[0];
cout << ".. eliminate " << zco << "\n";
/* TODO
COld ftmp, fout;
ftmp = *fin;
ftmp.lDoc.push_back("spectra -> files, eliminating " + zco.str());
ftmp.ZCo.erase(ftmp.ZCo.begin());
for (uint j=0; j<ftmp.nJ(); ) {
fout = ftmp;
fout->V.clear();
zval = ftmp.V[j]->z[0];
if ( !(fin->ZCo.size()) )
throw string( "no z coordinate" );
CCoord zco = fin->ZCo[0];
// intermediate file, on which output files will be based:
POlo ftmp( fin->new_olo() );
ftmp->V.clear();
ftmp->lDoc.push_back("spectra -> files, eliminating " + zco.str());
ftmp->ZCo.erase( ftmp->ZCo.begin() );
for ( uint j=0; j<fin->nJ(); ) {
POlo fout( ftmp->new_olo() );
double zval = ftmp->z(j,0);
fout->RPar.push_back( CParam( zco, zval ) );
ftmp.V[j]->z.erase(ftmp.V[j]->z.begin()); // SIMPLIFY
fout->V.push_back( new CSpec( *(ftmp.V(j)) ) );
while (++j<ftmp.nJ() && ftmp.V[j]->z[0]==zval) {
ftmp.V[j]->z.erase(ftmp.V[j]->z.begin());
fout->V.push_back(ftmp.V[j]);
}
do {
PZentry eout( fin->new_zentry(j) );
eout->z.erase( eout->z.begin() );
fout->V.push_back( eout );
} while ( ++j<fin->nJ() && fin->z(j,0)==zval );
NOlm::OloAdd( fout );
}
*/
}
}
......@@ -901,7 +902,6 @@ void NManip::ScaBreak()
//* manipulations on files *//
//***************************************************************************//
//! Merge files, concatenating spectra.
void NManip::FilMerge( const string& opts )
......
......@@ -32,8 +32,8 @@ COld::COld( class COlc const* c )
}
uint COld::nPts( uint j ) const {
if (!nJ() || j>=nJ())
throw string( "PROGRAM ERROR: nPts called with invalid j="+strg(j) );
if ( !nJ() || j>=nJ() )
throw string( "BUG: nPts called with invalid j="+strg(j) );
return VS(j)->size();
}
......@@ -41,10 +41,10 @@ uint COld::nPts( uint j ) const {
//! Return number of points if it is the same for all spectra. Else return 0.
uint COld::nPts() const {
if (!nJ())
throw string( "PROGRAM ERROR: nPts() called while nSpec=0" );
if ( !nJ() )
throw string( "BUG: nPts() called while nSpec=0" );
uint np = VS(0)->size();
for (uint j=0; j<nJ(); ++j)
for ( uint j=0; j<nJ(); ++j )
if (VS(j)->size()!=np) return 0;
return np;
}
......
......@@ -22,15 +22,15 @@ void CZentry::copy_zentry( PZentry ein )
//! Compare z vectors of two zentries, for use within sort routine.
bool CompareZ( const CZentry& E1, const CZentry& E2 )
bool CompareZ( const PZentry& E1, const PZentry& E2 )
{
if( E1.z.size()!=E2.z.size() )
return false;
uint nz = E1.z.size();
if( E1->z.size()!=E2->z.size() )
throw string( "BUG: inconsistent z.size in CompareZ" );
uint nz = E1->z.size();
for( uint iz=0; iz<nz; ++iz ){
if ( E1.z[iz]>E2.z[iz] )
if ( E1->z[iz] > E2->z[iz] )
return false;
if ( E1.z[iz]<E2.z[iz] )
if ( E1->z[iz] < E2->z[iz] )
return true;
}
return false;
......
......@@ -12,6 +12,6 @@ class CZentry {
typedef boost::shared_ptr<CZentry> PZentry;
bool CompareZ( const CZentry& E1, const CZentry& E2 );
bool CompareZ( const PZentry& E1, const PZentry& E2 );
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment