// Action_Energy::Init() Action::RetType Action_Energy::Init(ArgList& actionArgs, ActionInit& init, int debugIn) { ENE_.SetDebug( debugIn ); // Get keywords DataFile* outfile = init.DFL().AddDataFile( actionArgs.GetStringKey("out"), actionArgs ); // Which terms will be calculated? Ecalcs_.clear(); if (actionArgs.hasKey("bond")) Ecalcs_.push_back(BND); if (actionArgs.hasKey("angle")) Ecalcs_.push_back(ANG); if (actionArgs.hasKey("dihedral")) Ecalcs_.push_back(DIH); if (actionArgs.hasKey("nb14")) Ecalcs_.push_back(N14); if (actionArgs.hasKey("nonbond")) Ecalcs_.push_back(NBD); // If nothing is selected, select all. if (Ecalcs_.empty()) { for (int c = 0; c <= (int)NBD; c++) Ecalcs_.push_back( (CalcType)c ); } // Get Masks Mask1_.SetMaskString( actionArgs.GetMaskNext() ); // DataSet std::string setname = actionArgs.GetStringNext(); if (setname.empty()) setname = init.DSL().GenerateDefaultName("ENE"); Energy_.clear(); Energy_.resize( (int)TOTAL + 1, 0 ); for (calc_it calc = Ecalcs_.begin(); calc != Ecalcs_.end(); ++calc) { switch (*calc) { case BND: if (AddSet(BOND, init.DSL(), outfile, setname)) return Action::ERR; break; case ANG: if (AddSet(ANGLE, init.DSL(), outfile, setname)) return Action::ERR; break; case DIH: if (AddSet(DIHEDRAL, init.DSL(), outfile, setname)) return Action::ERR; break; case N14: if (AddSet(V14, init.DSL(), outfile, setname)) return Action::ERR; if (AddSet(Q14, init.DSL(), outfile, setname)) return Action::ERR; break; case NBD: if (AddSet(VDW, init.DSL(), outfile, setname)) return Action::ERR; if (AddSet(ELEC, init.DSL(), outfile, setname)) return Action::ERR; break; } } // if (Ecalcs_.size() > 1) { if (AddSet(TOTAL, init.DSL(), outfile, setname)) return Action::ERR; // } mprintf(" ENERGY: Calculating energy for atoms in mask '%s'\n", Mask1_.MaskString()); mprintf("\tCalculating terms:"); for (calc_it calc = Ecalcs_.begin(); calc != Ecalcs_.end(); ++calc) mprintf(" %s", Cstring[*calc]); mprintf("\n"); return Action::OK; }
/** Add a DataSet with given MetaData; if no name given create a name based on * defaultName and DataSet position. */ DataSet* DataSetList::AddSet( DataSet::DataType inType, MetaData const& metaIn, const char* defaultName ) { MetaData meta = metaIn; if (meta.Name().empty()) { if (defaultName != 0) meta.SetName( GenerateDefaultName(defaultName) ); } return AddSet( inType, meta ); }
void IPCSetEvent(int argc, char** argv, PLSOBJECT Object) { char* Name = argv[0]; char* Method = argv[1]; LSOBJECT setobject; if((setobject.Ptr = FindSet(Name)) == 0) { setobject.Ptr = new LSSet(); AddSet(Name, (LSSet*)setobject.Ptr); } pSetType->GetMethodEx(setobject.GetObjectData(), Method, argc - 2, &argv[2]); }
/** Search for a COORDS DataSet. If no name specified, create a default * COORDS DataSet named _DEFAULTCRD_. */ DataSet* DataSetList::FindCoordsSet(std::string const& setname) { DataSet* outset = 0; if (setname.empty()) { // crdset not given, search for the default set outset = FindSetOfType("_DEFAULTCRD_", DataSet::COORDS); if (outset == 0) { // No default set; create one. outset = AddSet(DataSet::COORDS, "_DEFAULTCRD_", "CRD"); } } else { DataSetList dslist = SelectGroupSets(setname, DataSet::COORDINATES); if (!dslist.empty()) outset = dslist[0]; } return outset; }
/** Initialize sander energy for current top/reference, set up data sets. */ int Action_Esander::InitForRef() { # ifdef MPI if ( SANDER_.Initialize( *currentParm_, refFrame_, trajComm_ ) ) return 1; # else if ( SANDER_.Initialize( *currentParm_, refFrame_ ) ) return 1; # endif // Set up DataSets int Nsets = (int)Energy_Sander::N_ENERGYTYPES; for (int ie = 0; ie != Nsets; ie++) { Energy_Sander::Etype etype = (Energy_Sander::Etype)ie; if (SANDER_.IsActive( etype )) { if (AddSet( etype, Init_.DSL(), outfile_, setname_ )) return 1; } } mprintf("\tSaving the following energy terms:\n"); for (int ie = 0; ie != Nsets; ie++) if (Esets_[ie] != 0) mprintf("\t %s in '%s'\n", Energy_Sander::Elabel((Energy_Sander::Etype)ie), Esets_[ie]->legend()); return 0; }
/** Given an array of already set up data sets (from e.g. input data files) * and optional X values, add the sets to this list if they do not exist * or append any existing sets. */ int DataSetList::AddOrAppendSets(std::string const& XlabelIn, Darray const& Xvals, DataListType const& Sets) { if (debug_ > 0) mprintf("DEBUG: Calling AddOrAppendSets for %zu sets, %zu X values, Xlabel= %s.\n", Sets.size(), Xvals.size(), XlabelIn.c_str()); if (Sets.empty()) return 0; // No error for now. // If no X label assume 'Frame' for backwards compat. std::string Xlabel; if (XlabelIn.empty()) Xlabel.assign("Frame"); else Xlabel = XlabelIn; Dimension Xdim; // First determine if X values increase monotonically with a regular step bool isMonotonic = true; double xstep = 1.0; if (Xvals.size() > 1) { xstep = (Xvals.back() - Xvals.front()) / (double)(Xvals.size() - 1); for (Darray::const_iterator X = Xvals.begin()+2; X != Xvals.end(); ++X) if ((*X - *(X-1)) - xstep > Constants::SMALL) { isMonotonic = false; break; } // Set dim even for non-monotonic sets so Label is correct. FIXME is this ok? Xdim = Dimension( Xvals.front(), xstep, Xlabel ); } else // No X values. set generic X dim. Xdim = Dimension(1.0, 1.0, Xlabel); if (debug_ > 0) { mprintf("DEBUG: xstep %g xmin %g\n", Xdim.Step(), Xdim.Min()); if (isMonotonic) mprintf("DEBUG: Xdim is monotonic.\n"); } for (const_iterator ds = Sets.begin(); ds != Sets.end(); ++ds) { if (*ds == 0) continue; // TODO: Warn about blanks? if (debug_ > 0) mprintf("DEBUG: AddOrAppend set '%s'", (*ds)->legend()); if (isMonotonic) (*ds)->SetDim(Dimension::X, Xdim); DataSet* existingSet = CheckForSet( (*ds)->Meta() ); if (existingSet == 0) { // New set. If set is scalar 1D but X values are not monotonic, // convert to XY mesh if necessary. if ( !isMonotonic && (*ds)->Group() == DataSet::SCALAR_1D && (*ds)->Type() != DataSet::XYMESH ) { DataSet* xyptr = AddSet( DataSet::XYMESH, (*ds)->Meta() ); if (xyptr == 0) { mprinterr("Error: Could not convert set %s to XY mesh.\n", (*ds)->legend()); continue; // TODO exit instead? } if ( (*ds)->Size() != Xvals.size() ) { // Sanity check mprinterr("Error: # of X values does not match set %s size.\n", (*ds)->legend()); continue; } DataSet_1D const& set = static_cast<DataSet_1D const&>( *(*ds) ); DataSet_Mesh& xy = static_cast<DataSet_Mesh&>( *xyptr ); for (unsigned int i = 0; i != set.Size(); i++) xy.AddXY( Xvals[i], set.Dval(i) ); xy.SetDim(Dimension::X, Xdim); if (debug_ > 0) mprintf(", New set, converted to XY-MESH\n"); // Free memory since set has now been converted. delete *ds; } else { // No conversion. Just add. (*ds)->SetDim(Dimension::X, Xdim); AddSet( *ds ); if (debug_ > 0) mprintf(", New set\n"); } } else { if (debug_ > 0) mprintf(", appending to existing set\n"); // Set exists. Try to append this set to existing set. bool canAppend = true; if ( (*ds)->Group() == DataSet::GENERIC ) { // For GENERIC sets, base Type must match. // TODO: Should this logic be in DataSets? if ( (*ds)->Type() != existingSet->Type() ) canAppend = false; } else { // For non-GENERIC sets, Group must match if ( (*ds)->Group() != existingSet->Group() ) canAppend = false; } if (!canAppend) mprinterr("Error: Cannot append set of type %s to set of type %s\n", DataArray[(*ds)->Type()].Description, DataArray[existingSet->Type()].Description); // If cannot append or attempt to append fails, rename and add as new set. if (!canAppend || existingSet->Append( *ds )) { // TODO Dimension check? if (canAppend) mprintf("Warning: Append currently not supported for type %s\n", DataArray[existingSet->Type()].Description); MetaData md = (*ds)->Meta(); md.SetName( GenerateDefaultName("X") ); mprintf("Warning: Renaming %s to %s\n", (*ds)->Meta().PrintName().c_str(), md.PrintName().c_str()); (*ds)->SetMeta( md ); AddSet( *ds ); } else // Set was appended to existing set; memory can be freed. delete *ds; } } // END loop over input sets return 0; }
void EditPatchMod::NewSetFromCurSel(TSTR &setName) { MaybeFixupNamedSels(); ModContextList mcList; INodeTab nodes; if (!ip) return; ip->GetModContexts(mcList, nodes); for (int i = 0; i < mcList.Count(); i++) { EditPatchData *patchData =(EditPatchData*)mcList[i]->localData; if (!patchData) continue; RPatchMesh *rpatch; PatchMesh *patch = patchData->TempData(this)->GetPatch(ip->GetTime(), rpatch); if (!patch) continue; GenericNamedSelSetList &sel = patchData->GetSelSet(this); BitArray *exist = sel.GetSet(setName); switch (selLevel) { case EP_VERTEX: if (exist) { *exist = patch->vertSel; } else { patchData->vselSet.AppendSet(patch->vertSel, 0, setName); } break; case EP_PATCH: if (exist) { *exist = patch->patchSel; } else { patchData->pselSet.AppendSet(patch->patchSel, 0, setName); } break; case EP_EDGE: if (exist) { *exist = patch->edgeSel; } else { patchData->eselSet.AppendSet(patch->edgeSel, 0, setName); } break; } } int index = FindSet(setName, selLevel); if (index < 0) AddSet(setName, selLevel); nodes.DisposeTemporary(); }
bool IPCSetType::GetMethod(LSOBJECTDATA &ObjectData, PLSTYPEMETHOD pMethod, int argc, char *argv[]) { /******************************************* * Parameters * * [in] LSOBJECTDATA ObjectData: ObjectData is a 32-bit value that can be accessed in any number of different ways * by way of union. Most commonly, ObjectData.Ptr, ObjectData.DWord, or ObjectData.CharPtr are useful. This * value is the representation of some object of this object type. "ipcfoo" works on IPCFoo* * so ObjectData is a IPCFoo* * * [in] PLSTYPEMETHOD pMethod: pMethod is a pointer to the information on the method to be retrieved, including its * Name and ID. We use the ID in a switch statement in order to quickly process the method, since the Name * has already been resolved by the LavishScript engine. * * [in] int argc, char *argv[]: argc and argv are *nearly* standard C console program parameters. The difference here * is that the name of the method is NOT given as the first argument (in contrast to LavishScript commands). * Therefore, argc is 0 unless arguments are specifically given to the method retrieval. */ /******************************************* * Return Value * * The return value for this function is very simple. If the method execution fails for any reason, OR the object * is destroyed during execution, return false. Otherwise, return true (indicating the object still exists AND * the method execution succeeded). * */ /* Validate the pointer */ if (!pSet) return false; /* Perform the given member retrieval */ switch(pMethod->ID) { case Add: if(argc) { pSet->Set->AddItem(argv[0]); SetRelay(pSet->IPCName, "Add", argc, argv); return true; } return false; case Remove: if(argc) { pSet->Set->RemoveItem(argv[0]); SetRelay(pSet->IPCName, "Remove", argc, argv); return true; } return false; case Set: case SetIPCName: if(argc) { LSSet *newSet; strncpy(pSet->IPCName, argv[0], sizeof(pSet->IPCName)); if((newSet=FindSet(pSet->IPCName))==0) { newSet = new LSSet(); AddSet(pSet->IPCName, newSet); } pSet->Set = newSet; return true; } return false; case GetIterator: LSOBJECT iteratorobject; if(argc) { //printf("%s %s %d", argv[0], pSet->IPCName, pSet->Set->GetContainerUsed()); if(pLSInterface->DataParse(argv[0], iteratorobject)) { return InitializeIterator(pSet->Set, 0, iteratorobject); } } return false; } return false; }
bool FilesSets::Load(const wxString& filename) { DeleteAllSets(); wxXmlDocument *xmldoc = WXDEBUG_NEW wxXmlDocument(filename); wxXmlNode *root; if ( !xmldoc->IsOk() ) { m_error = 100; delete(xmldoc); return false; } // checking data root = xmldoc->GetRoot(); if (( root->GetType() != wxXML_ELEMENT_NODE ) || ( root->GetName().Cmp(wxT("sets")) != 0 )) { m_error = 1; delete(xmldoc); wxLogError(filename + wxT(": Invalid document type. The root node must be 'sets'.")); return false; } wxXmlNode *set = root->GetChildren(); wxString value; long lid; FilesSet *fset; while (set != NULL) { if (( set->GetType() == wxXML_ELEMENT_NODE ) && ( set->GetName().Cmp(wxT("set")) == 0 ) && (( !set->GetPropVal(wxT("id"), &value) ) || ( !value.ToLong(&lid) ) || ( lid <= 0 ))) { m_error = 2; delete(xmldoc); wxLogError(filename + wxT(": Attribute 'id' having positive numeric value must be specified for each element 'set'.")); return false; } if (( set->GetType() != wxXML_ELEMENT_NODE ) || ( set->GetName().Cmp(wxT("set")) != 0 )) { set = set->GetNext(); continue; } fset = WXDEBUG_NEW FilesSet(); fset->SetId( (int) lid ); m_error = CheckFilesSet(set, fset, filename); if (m_error) { delete(fset); delete(xmldoc); return false; } if ( !AddSet(fset) ) { m_error = -3; delete(fset); delete(xmldoc); wxLogError(filename + wxT(": Duplicate set for id = %d."), lid); return false; } set = set->GetNext(); } delete(xmldoc); return true; }
int PPF_Print( MPI_Comm comm, const char * string, ... ) { va_list args; static int inited; static MPI_Op PTC_Print_reduce; static size_t linesize, blocksize; static MPI_Datatype type; static char * src_block; static char * dest_block; static int rank, size; int i; int localrank; int status; LineData * src_lines; LineData * dest_lines; LineData * pline; char * ptoken, * plast; char temp[PPF_MAXLINE]; if( !inited ) { status = MPI_Op_create( PrintReduceOp, 1, &PTC_Print_reduce ); #ifdef _MSC_VER _set_printf_count_output(1); #endif if( status != MPI_SUCCESS ) { fprintf( stderr, "Couldn't create Print Reduce op %d\n", status ); return status; } /* Use comm world so that output is identified in terms of * global rank. (Should this be optional?) */ MPI_Comm_rank( MPI_COMM_WORLD, &rank ); MPI_Comm_size( MPI_COMM_WORLD, &size ); /* Get enough memory to hold size line entries + * count field + and linesize field */ linesize = CLOSED_SET_BYTES( size ) + PPF_MAXLINE; blocksize = linesize * size + 2 * sizeof(int); src_block = malloc( blocksize ); dest_block = malloc( blocksize ); /* Store the number of entries and linesize (since set size * varies from run to run) */ ((int*)src_block)[0] = size; ((int*)src_block)[1] = linesize; MPI_Type_contiguous( blocksize, MPI_BYTE, &type ); MPI_Type_commit( &type ); inited = 1; } /* Initialize the line entries */ src_lines = (LineData *)(src_block + 2 * sizeof(int)); dest_lines = (LineData *)(dest_block + 2 * sizeof(int)); #if 0 /* Truncate the string if necessary */ if( strlen( string ) >= PPF_MAXLINE ) { string[PPF_MAXLINE - 1] = '\0'; } #endif /* Search for the pattern that means "put the node numbers here". * Since it will begin with at %, we have to convert it to * something else so sprintf doesn't try to interpret it. When * we finally do the printout, we'll replace the placeholder * with the node list. Likewise, since we're processing * this string twice through printf-like functions, any %% * patterns the user put in will get eaten up. To prevent * that, we change %% to something else before the first * pass through sprintf and change it back before the second. */ if( string != NULL ) { /* Don't try formatting an empty string */ /* First copy into a buffer that we can modify */ strncpy( temp, string, PPF_MAXLINE ); temp[PPF_MAXLINE-1] = '\0'; for( ptoken = strchr( temp, '%' ); ptoken != NULL; ptoken = strchr( ptoken + 2, '%' ) ) { if( ptoken[1] == NODECHAR ) { *ptoken = PERCENTSUB; ptoken[1] = NODESUB; } else if( ptoken[1] == '%' ) { *ptoken = ptoken[1] = PERCENTSUB; } } } /* Initialize all the strings and sets in our list to be * empty, except the one for this node. That gets * initialized with the formatted string that the user * requested and the nodeset consisting of this node. */ va_start( args, string ); for( pline = src_lines, i = 0; i < size; pline += linesize, i++ ) { InitSet( size, pline+SET ); if( i == rank ) { if( string != NULL ) { vsprintf( pline+TEXT, temp, args ); AddSet( pline+SET, rank ); } /* If string is NULL, this node won't appear in * the set for any string entry, so it won't * produce any output. */ } } va_end( args ); MPI_Reduce( src_block, dest_block, 1, type, PTC_Print_reduce, 0, comm ); /* For this test, we use to input comm rank so that we're sure * "node 0" is in this group. */ MPI_Comm_rank( comm, &localrank ); if( localrank == 0 ) { PrintResult( dest_lines, size, linesize ); } return MPI_SUCCESS; }
bool OnGossipSelect(Player *player, Creature *creature, uint32 sender, uint32 action ) { if (!player->getAttackers().empty()) { creature->MonsterWhisper(MSG_ERR_INCOMBAT, player->GetGUID()); player->CLOSE_GOSSIP_MENU(); return false; } switch (action) { case 2: player->AddItem(bag, 4); player->CLOSE_GOSSIP_MENU(); break; case 3: player->SetHealth(player->GetMaxHealth()); player->CLOSE_GOSSIP_MENU(); break; case 4: player->UpdateSkillsToMaxSkillsForLevel(); player->CLOSE_GOSSIP_MENU(); break; case 5: if (player->HasAura(15007)) { creature->MonsterWhisper(MSG_ERR_AURA, player->GetGUID()); player->CLOSE_GOSSIP_MENU(); }else { player->RemoveAllAuras(); player->CLOSE_GOSSIP_MENU(); player->RemoveAllSpellCooldown(); } break; case 6: player->SetSkill(762, 6, 450, 450); player->learnSpell(54197, true); player->CLOSE_GOSSIP_MENU(); break; case 7: AddSet(player, warlockItem); player->CLOSE_GOSSIP_MENU(); break; case 8: AddSet(player, warriorItem); break; case 9: AddSet(player, druidRestorItem); break; case 10: AddSet(player, druidBalanceItem); break; case 11: AddSet(player, druidFeralItem); break; case 12: AddSet(player, priestDiscItem); break; case 13: AddSet(player, priestShadowItem); break; case 14: AddSet(player, mageItem); break; case 15: AddSet(player, paladinHolyItem); break; case 16: AddSet(player, paladinMeleeItem); break; case 17: AddSet(player, rogueItem); break; case 18: AddSet(player, deathknightItem); break; case 19: AddSet(player, shamanMeleeItem); break; case 20: AddSet(player, shamanRestorItem); break; case 21: AddSet(player, shamanElementalItem); break; case 22: AddSet(player, hunterItem); case 23: if (player->GetArenaPoints() < CONST_ARENA_POINT_1) { creature->MonsterWhisper(MSG_ERR_ARENA_POINT, player->GetGUID()); player->CLOSE_GOSSIP_MENU(); }else{ // Делаем Ренейм player->SetAtLoginFlag(AT_LOGIN_RENAME); player->ModifyArenaPoints(-CONST_ARENA_POINT_1); creature->MonsterWhisper(MSG_COMPLETE_RENAME, player->GetGUID()); player->CLOSE_GOSSIP_MENU(); } break; case 24: if (player->GetArenaPoints() < CONST_ARENA_POINT_1) { creature->MonsterWhisper(MSG_ERR_ARENA_POINT, player->GetGUID()); player->CLOSE_GOSSIP_MENU(); }else{ // Делаем Смену внешности player->SetAtLoginFlag(AT_LOGIN_CUSTOMIZE); player->ModifyArenaPoints(-CONST_ARENA_POINT_1); creature->MonsterWhisper(MSG_CUSTOMIZE_COMPLETE, player->GetGUID()); player->CLOSE_GOSSIP_MENU(); } break; case 25: if (player->GetArenaPoints() < CONST_ARENA_POINT_2) { creature->MonsterWhisper(MSG_ERR_ARENA_POINT, player->GetGUID()); player->CLOSE_GOSSIP_MENU(); }else{ // Делаем Смену фракции player->SetAtLoginFlag(AT_LOGIN_CHANGE_FACTION); player->ModifyArenaPoints(-CONST_ARENA_POINT_2); creature->MonsterWhisper(MSG_CHANGE_FACTION_COMPLETE, player->GetGUID()); player->CLOSE_GOSSIP_MENU(); } break; } return true; }