script GRAPPLE_GETUNUSEDTID (int mode, int fromItem) { int newTID = TIDSTART; switch (mode) { case 0: while (ThingCount(0, newTID) > 0) { newTID++; } if (fromItem) { GiveInventory("ItemGrappleTID", newTID); } else { GiveInventory("GrappleTIDIndicator", newTID); } Thing_ChangeTID(0, newTID); break; case 1: if (fromItem) { SetResultValue(CheckInventory("ItemGrappleTID")); } else { SetResultValue(CheckInventory("GrappleTIDIndicator")); } break; case 2: while (ThingCount(0, newTID) > 0) { newTID++; } if (fromItem) { GiveInventory("ItemGrappleTID", newTID); } else { GiveInventory("GrappleTIDIndicator", newTID); } Thing_ChangeTID(0, newTID); SetResultValue(newTID); break; } }
script GETFIRERPLN (void) { int switchWorked = SetActivatorToTarget(0); if (switchWorked) { SetResultValue( PlayerNumber() ); } else { SetResultValue(-1); } }
void avtAggregateChordLengthDistributionQuery::PostExecute(void) { int i; int times = 0; char name[1024]; sprintf(name, "cld_a%d.ult", times++); if (PAR_Rank() == 0) { bool lookingForUnused = true; while (lookingForUnused) { ifstream ifile(name); if (ifile.fail()) lookingForUnused = false; else sprintf(name, "cld_a%d.ult", times++); } } char msg[1024]; sprintf(msg, "The aggregate chord length distribution has been outputted " "as an Ultra file (%s), which can then be imported into VisIt.", name); SetResultMessage(msg); SetResultValue(0.); int *nc2 = new int[numBins]; SumIntArrayAcrossAllProcessors(numChords, nc2, numBins); delete [] numChords; numChords = nc2; if (PAR_Rank() == 0) { double binWidth = (maxLength-minLength) / numBins; double totalArea = 0.; for (i = 0 ; i < numBins ; i++) totalArea += binWidth*numChords[i]; if (totalArea == 0.) { sprintf(msg, "The chord length distribution could not be " "calculated because none of the lines intersected the data" " set. If you have used a fairly large number of lines, " "then this may be indicative of an error state."); SetResultMessage(msg); return; } ofstream ofile(name); if (ofile.fail()) { sprintf(msg, "Unable to write out file containing distribution."); SetResultMessage(msg); return; } ofile << "# Chord length distribution - aggregate" << endl; for (int i = 0 ; i < numBins ; i++) { //double x = minLength + (i+0.5)*binWidth; double x1 = minLength + (i)*binWidth; double x2 = minLength + (i+1)*binWidth; double y = numChords[i] / totalArea; // Make it be // a distribution ... the area under the curve: 1 ofile << x1 << " " << y << endl; ofile << x2 << " " << y << endl; } } }
void avtIndividualChordLengthDistributionQuery::PostExecute(void) { int i; int times = 0; char name[1024]; sprintf(name, "cld_i%d.ult", times++); if (PAR_Rank() == 0) { bool lookingForUnused = true; while (lookingForUnused) { ifstream ifile(name); if (ifile.fail()) lookingForUnused = false; else sprintf(name, "cld_i%d.ult", times++); } } char msg[1024]; sprintf(msg, "The chord length distribution has been outputted as an " "Ultra file (%s), which can then be imported into VisIt.", name); SetResultMessage(msg); SetResultValue(0.); int *nc2 = new int[numBins]; SumIntArrayAcrossAllProcessors(numChords, nc2, numBins); delete [] numChords; numChords = nc2; if (PAR_Rank() == 0) { double binWidth = (maxLength-minLength) / numBins; double totalArea = 0.; for (i = 0 ; i < numBins ; i++) totalArea += binWidth*numChords[i]; if (totalArea == 0.) { sprintf(msg, "The chord length distribution could not be " "calculated because none of the lines intersected " "the data set. If you have used a fairly large number " "of lines, then this may be indicative of an error state."); SetResultMessage(msg); return; } ofstream ofile(name); if (ofile.fail()) { sprintf(msg, "Unable to write out file containing distribution."); SetResultMessage(msg); } if (!ofile.fail()) ofile << "# Chord length distribution - individual" << endl; MapNode result_node; doubleVector curve; for (int i = 0 ; i < numBins ; i++) { double x1 = minLength + (i)*binWidth; double x2 = minLength + (i+1)*binWidth; double y = numChords[i] / totalArea; // Make it be a distribution ... // the area under the curve: 1 curve.push_back(x1); curve.push_back(y); curve.push_back(x2); curve.push_back(y); if (!ofile.fail()) { ofile << x1 << " " << y << endl; ofile << x2 << " " << y << endl; } } result_node["chord_length_distribution_individual"] = curve; SetXmlResult(result_node.ToXML()); SetResultValues(curve); } }
void avtMassDistributionQuery::PostExecute(void) { int i; avtWeightedVariableSummationQuery summer; avtDataObject_p dob = GetInput(); summer.SetInput(dob); QueryAttributes qa; summer.PerformQuery(&qa); double totalMass = qa.GetResultsValue()[0]; bool didVolume = false; bool didRVolume = false; bool didSA = false; if (totalMass == 0.) { if (dob->GetInfo().GetAttributes().GetTopologicalDimension() == 3) { avtTotalVolumeQuery tvq; avtDataObject_p dob = GetInput(); tvq.SetInput(dob); QueryAttributes qa; tvq.PerformQuery(&qa); totalMass = qa.GetResultsValue()[0]; didVolume = true; } else if (dob->GetInfo().GetAttributes().GetMeshCoordType() == AVT_RZ || dob->GetInfo().GetAttributes().GetMeshCoordType() == AVT_ZR) { avtTotalRevolvedVolumeQuery rvq; avtDataObject_p dob = GetInput(); rvq.SetInput(dob); QueryAttributes qa; rvq.PerformQuery(&qa); totalMass = qa.GetResultsValue()[0]; didRVolume = true; } else { avtTotalSurfaceAreaQuery saq; avtDataObject_p dob = GetInput(); saq.SetInput(dob); QueryAttributes qa; saq.PerformQuery(&qa); totalMass = qa.GetResultsValue()[0]; didSA = true; } } int times = 0; char name[1024]; sprintf(name, "md%d.ult", times++); if (PAR_Rank() == 0) { bool lookingForUnused = true; while (lookingForUnused) { ifstream ifile(name); if (ifile.fail()) lookingForUnused = false; else sprintf(name, "md%d.ult", times++); } } char msg[1024]; const char *mass_string = (didVolume ? "volume" : (didRVolume ? "revolved volume" : (didSA ? "area" : "mass"))); std::string format = "The %s distribution has been outputted as an " "Ultra file (%s), which can then be imported into VisIt. The" " total %s considered was " + queryAtts.GetFloatFormat() +"\n"; SNPRINTF(msg,1024,format.c_str(), mass_string, name, mass_string, totalMass); SetResultMessage(msg); SetResultValue(0.); double *m2 = new double[numBins]; SumDoubleArrayAcrossAllProcessors(mass, m2, numBins); delete [] mass; mass = m2; double totalMassFromLines = 0.; for (i = 0 ; i < numBins ; i++) totalMassFromLines += mass[i]; if (PAR_Rank() == 0) { if (totalMassFromLines == 0.) { sprintf(msg, "The mass distribution could not be calculated " "becuase none of the lines intersected the data set." " If you have used a fairly large number of lines, then " "this may be indicative of an error state."); SetResultMessage(msg); return; } ofstream ofile(name); if (ofile.fail()) { sprintf(msg, "Unable to write out file containing distribution."); SetResultMessage(msg); } if (!ofile.fail()) ofile << "# Mass distribution" << endl; MapNode result_node; doubleVector curve; double binWidth = (maxLength-minLength) / numBins; for (int i = 0 ; i < numBins ; i++) { double x1 = minLength + (i)*binWidth; double x2 = minLength + (i+1)*binWidth; double y = (totalMass*mass[i]) / (totalMassFromLines*binWidth); curve.push_back(x1); curve.push_back(y); curve.push_back(x2); curve.push_back(y); if (!ofile.fail()) { ofile << x1 << " " << y << endl; ofile << x2 << " " << y << endl; } } result_node["mass_distribution"] = curve; SetXmlResult(result_node.ToXML()); SetResultValues(curve); } }