void Test() { SeqList mypseq; InitSeq(&mypseq); Push_Back(&mypseq,1); Push_Back(&mypseq,2); Push_Back(&mypseq,3); Push_Back(&mypseq,4); Push_Front(&mypseq,0); PrintSeqList(&mypseq); }
// DataSetList::operator+=() DataSetList& DataSetList::operator+=(DataSetList const& rhs) { // It is OK if rhs does not have copies, but this should have copies. // For now just set hasCopies to true. hasCopies_ = true; // Append rhs entries to here for (DataListType::const_iterator DS = rhs.begin(); DS != rhs.end(); ++DS) Push_Back( *DS ); return *this; }
// DataSetList::AddCopyOfSet() void DataSetList::AddCopyOfSet(DataSet* dsetIn) { if (!hasCopies_ && !DataList_.empty()) { mprinterr("Internal Error: Adding DataSet (%s) copy to invalid list\n", dsetIn->legend()); return; } hasCopies_ = true; Push_Back( dsetIn ); }
// DataSetList::AddCopyOfSet() void DataSetList::AddCopyOfSet(DataSet* dsetIn) { if (!hasCopies_ && !DataList_.empty()) { mprinterr("Internal Error: Attempting to add copy of DataSet (%s) to DataSetList" " not set up to hold copies.\n", dsetIn->Meta().PrintName().c_str()); return; } hasCopies_ = true; Push_Back( dsetIn ); }
// DataSetList::AddSet() int DataSetList::AddSet( DataSet* dsIn ) { if (dsIn == 0 ) return 1; DataSet* ds = CheckForSet( dsIn->Meta() ); if (ds != 0) { mprintf("Warning: DataSet '%s' already present.\n", ds->Meta().PrintName().c_str()); return 1; } Push_Back( dsIn ); return 0; }
/** 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; }