/** Add a DataSet of specified type, set it up and return pointer to it. * \param inType type of DataSet to add. * \param metaIn DataSet MetaData. * \return pointer to successfully set-up DataSet or 0 if error. */ DataSet* DataSetList::AddSet(DataSet::DataType inType, MetaData const& metaIn) { // TODO Always generate default name if empty? // Do not add to a list with copies if (hasCopies_) { mprinterr("Internal Error: Attempting to add DataSet (%s) to DataSetList with copies.\n", metaIn.PrintName().c_str()); return 0; } MetaData meta( metaIn ); meta.SetEnsembleNum( ensembleNum_ ); // Check if DataSet with same attributes already present. DataSet* DS = CheckForSet(meta); if (DS != 0) { mprintf("Warning: DataSet '%s' already present.\n", DS->Meta().PrintName().c_str()); // NOTE: Should return found dataset? return 0; } TokenPtr token = &(DataArray[inType]); if ( token->Alloc == 0) { mprinterr("Internal Error: No allocator for DataSet type [%s]\n", token->Description); return 0; } DS = (DataSet*)token->Alloc(); if (DS==0) { mprinterr("Internal Error: DataSet %s memory allocation failed.\n", meta.PrintName().c_str()); return 0; } // If 1 dim set and time series status not set, set to true. if (meta.TimeSeries() == MetaData::UNKNOWN_TS && DS->Ndim() == 1) { meta.SetTimeSeries( MetaData::IS_TS ); // Also set dimension default DS->SetDim(Dimension::X, Dimension(1.0, 1.0, "Frame") ); } // Set up dataset if ( DS->SetMeta( meta ) ) { mprinterr("Error setting up data set %s.\n", meta.PrintName().c_str()); delete DS; return 0; } Push_Back(DS); //fprintf(stderr,"ADDED dataset %s\n",dsetName); return DS; }
/** Special version of AddSet that does NOT check if set already exists. * Intended for use in Action Setup/DoAction where it is assumed that * the Action is setting up DataSets in such a way that there will not * be name conflicts, i.e. the DataSet name at least is unique. * \param inType type of DataSet to add. * \param metaIn DataSet MetaData. * \return pointer to successfully set-up DataSet or 0 if error. */ DataSet* DataSetList::AddSet_NoCheck(DataSet::DataType inType, MetaData const& metaIn) { // TODO Pass in Nframes? // Assume list does NOT have copies. MetaData meta( metaIn ); meta.SetEnsembleNum( ensembleNum_ ); // Allocate DataSet TokenPtr token = &(DataArray[inType]); if ( token->Alloc == 0) { mprinterr("Internal Error: No allocator for DataSet type [%s]\n", token->Description); return 0; } DataSet* DS = (DataSet*)token->Alloc(); if (DS==0) { mprinterr("Internal Error: DataSet %s memory allocation failed.\n", meta.PrintName().c_str()); return 0; } // If 1 dim set and time series status not set, set to true, allocate for frames. if (meta.TimeSeries() == MetaData::UNKNOWN_TS && DS->Ndim() == 1) { meta.SetTimeSeries( MetaData::IS_TS ); // Also set dimension default DS->SetDim(Dimension::X, Dimension(1.0, 1.0, "Frame") ); //DS->Allocate( DataSet::SizeArray(1, Nframes) ); } // Set up DataSet MetaData if ( DS->SetMeta( meta ) ) { mprinterr("Error setting up data set %s.\n", meta.PrintName().c_str()); delete DS; return 0; } # ifdef MPI if (newSetsNeedSync_) DS->SetNeedsSync( true ); # endif // Add to list Push_Back(DS); return DS; }
Analysis::RetType Analysis_Spline::Setup(ArgList& analyzeArgs, DataSetList* datasetlist, DataFileList* DFLin, int debugIn) { std::string setname = analyzeArgs.GetStringKey("name"); outfile_ = DFLin->AddDataFile(analyzeArgs.GetStringKey("out"), analyzeArgs); meshsize_ = analyzeArgs.getKeyInt("meshsize", 0); meshfactor_ = -1.0; if (meshsize_ < 3) { meshfactor_ = analyzeArgs.getKeyDouble("meshfactor", -1.0); if (meshfactor_ < Constants::SMALL) { mprinterr("Error: Either meshsize must be specified and > 2, or meshfactor must be\n" "Error: specified and > 0.0\n"); return Analysis::ERR; } } if (analyzeArgs.Contains("meshmin")) { meshmin_ = analyzeArgs.getKeyDouble("meshmin", 0.0); useDefaultMin_ = true; } else useDefaultMin_ = false; if (analyzeArgs.Contains("meshmax")) { meshmax_ = analyzeArgs.getKeyDouble("meshmax", -1.0); useDefaultMax_ = true; } else useDefaultMax_ = false; if (useDefaultMin_ && useDefaultMax_ && meshmax_ < meshmin_) { mprinterr("Error: meshmax must be > meshmin\n"); return Analysis::ERR; } // Select datasets from remaining args if (input_dsets_.AddSetsFromArgs( analyzeArgs.RemainingArgs(), *datasetlist )) { mprinterr("Error: Could not add data sets.\n"); return Analysis::ERR; } if (input_dsets_.empty()) { mprinterr("Error: No input data sets.\n"); return Analysis::ERR; } // Set up output datasets Dimension Xdim( meshmin_, (meshmax_ - meshmin_) / (double)meshsize_ ); for (Array1D::const_iterator dsIn = input_dsets_.begin(); dsIn != input_dsets_.end(); ++dsIn) { DataSet* ds = datasetlist->AddSet(DataSet::XYMESH, setname, "Spline"); if (ds == 0) return Analysis::ERR; ds->SetLegend( "Spline(" + (*dsIn)->Meta().Legend() + ")" ); // TODO: Set individually based on input_dsets_ ds->SetDim(Dimension::X, Xdim); if (outfile_ != 0) outfile_->AddDataSet( ds ); output_dsets_.push_back( (DataSet_Mesh*)ds ); } mprintf(" SPLINE: Applying cubic splining to %u data sets\n", input_dsets_.size()); if (meshfactor_ < 0) mprintf("\tMesh size= %i\n", meshsize_); else mprintf("\tMesh size will be input set size multiplied by %f\n", meshfactor_); if (useDefaultMin_) mprintf("\tMesh min= %f,", meshmin_); else mprintf("\tMesh min will be input set min,"); if (useDefaultMax_) mprintf(" Mesh max= %f\n", meshmax_); else mprintf(" Mesh max will be input set max.\n"); if (outfile_ != 0) { if (!setname.empty()) mprintf("\tOutput set name: %s\n", setname.c_str()); mprintf("\tOutfile name: %s\n", outfile_->DataFilename().base()); } //for (Array1D::const_iterator set = input_dsets_.begin(); set != input_dsets_.end(); ++set) // mprintf("\t%s\n", (*set)->legend()); return Analysis::OK; }
// Analysis_CrdFluct::Setup() Analysis::RetType Analysis_CrdFluct::Setup(ArgList& analyzeArgs, DataSetList* datasetlist, DataFileList* DFLin, int debugIn) { bfactor_ = analyzeArgs.hasKey("bfactor"); // Attempt to get coords dataset from datasetlist std::string setname = analyzeArgs.GetStringKey("crdset"); coords_ = (DataSet_Coords*)datasetlist->FindCoordsSet( setname ); if (coords_ == 0) { mprinterr("Error: crdfluct: Could not locate COORDS set corresponding to %s\n", setname.c_str()); return Analysis::ERR; } DataFile* outfile = DFLin->AddDataFile( analyzeArgs.GetStringKey("out"), analyzeArgs ); windowSize_ = analyzeArgs.getKeyInt("window", -1); // Get mask mask_.SetMaskString( analyzeArgs.GetMaskNext() ); mprintf(" CRDFLUCT: Atomic fluctuations will be calcd for set %s, mask [%s]\n", coords_->legend(), mask_.MaskString()); if (windowSize_ != -1) mprintf("\tWindow size = %i\n", windowSize_); if (outfile != 0) mprintf("\tOutput to %s\n", outfile->DataFilename().base()); // Set up data sets setname = analyzeArgs.GetStringNext(); if (windowSize_ < 1) { // Only one data set for total B-factors DataSet* ds = datasetlist->AddSet( DataSet::DOUBLE, setname, "fluct" ); if (ds == 0) return Analysis::ERR; outSets_.push_back( ds ); if (outfile != 0) outfile->AddDataSet( ds ); } else { if (coords_->Size() == 0) { mprinterr("Error: window size > 0 and COORDS data set %s is empty.\n", coords_->legend()); mprinterr("Error: Cannot predict how many window data sets will be needed.\n"); return Analysis::ERR; } if (setname.empty()) setname = datasetlist->GenerateDefaultName("fluct"); // Determine how many windows will be needed int nwindows = coords_->Size() / windowSize_; for (int win = 0; win < nwindows; ++win) { int frame = (win + 1) * windowSize_; DataSet* ds = datasetlist->AddSet( DataSet::DOUBLE, MetaData(setname, frame) ); if (ds == 0) return Analysis::ERR; ds->SetLegend( "F_" + integerToString( frame ) ); ds->SetDim( Dimension::X, Dimension(1.0, 1.0, "Atom") ); outSets_.push_back( ds ); if (outfile != 0) outfile->AddDataSet( ds ); } if ( (coords_->Size() % windowSize_) != 0 ) { DataSet* ds = datasetlist->AddSet( DataSet::DOUBLE, MetaData(setname, coords_->Size()) ); ds->SetLegend("Final"); outSets_.push_back( ds ); if (outfile != 0) outfile->AddDataSet( ds ); } for (SetList::iterator out = outSets_.begin(); out != outSets_.end(); ++out) mprintf("\t%s\n", (*out)->legend()); } // Setup output file /* if (bfactor_) outfile->Dim(Dimension::Y).SetLabel("B-factors"); outfile->Dim(Dimension::X).SetLabel("Atom");*/ return Analysis::OK; }