status_t ConvertToAMessage(const Message & from, os::Message & to) { to.MakeEmpty(); to.SetCode(from.what); uint32 type; uint32 count; bool fixedSize; for (MessageFieldNameIterator it = from.GetFieldNameIterator(B_ANY_TYPE, HTIT_FLAG_NOREGISTER); it.HasData(); it++) { const String & n = it.GetFieldName(); if (from.GetInfo(n, &type, &count, &fixedSize) != B_NO_ERROR) return B_ERROR; for (uint32 j=0; j<count; j++) { const void * nextItem; uint32 itemSize; if (from.FindData(n, type, j, &nextItem, &itemSize) != B_NO_ERROR) return B_ERROR; // do any necessary translation from the Muscle data types to Be data types switch(type) { case B_POINT_TYPE: { const Point * p = static_cast<const Point *>(nextItem); os::Point bpoint(p->x(), p->y()); if (to.AddPoint(n, bpoint) != B_NO_ERROR) return B_ERROR; } break; case B_RECT_TYPE: { const Rect * r = static_cast<const Rect *>(nextItem); os::Rect brect(r->left(), r->top(), r->right(), r->bottom()); if (to.AddRect(n, brect) != B_NO_ERROR) return B_ERROR; } break; case B_MESSAGE_TYPE: { const MessageRef * msgRef = static_cast<const MessageRef *>(nextItem); os::Message amsg; if (msgRef->GetItemPointer() == NULL) return B_ERROR; if (ConvertToAMessage(*msgRef->GetItemPointer(), amsg) != B_NO_ERROR) return B_ERROR; if (to.AddMessage(n, &amsg) != B_NO_ERROR) return B_ERROR; } break; default: if (to.AddData(n, type, nextItem, itemSize, fixedSize, count) != B_NO_ERROR) return B_ERROR; break; } } } return B_NO_ERROR; }
void WriteFile (int typ, const Mesh & mesh, const CSGeometry & geom, const char * filename, const char * geomfile, double h) { int inverttets = mparam.inverttets; int invertsurf = mparam.inverttrigs; if (typ == WRITE_EDGEELEMENT) { // write edge element file // Peter Harscher, ETHZ cout << "Write Edge-Element Format" << endl; ofstream outfile (filename); int i, j; int ned; // hash table representing edges; INDEX_2_HASHTABLE<int> edgeht(mesh.GetNP()); // list of edges Array<INDEX_2> edgelist; // edge (point) on boundary ? BitArray bedge, bpoint(mesh.GetNP()); static int eledges[6][2] = { { 1, 2 } , { 1, 3 } , { 1, 4 }, { 2, 3 } , { 2, 4 } , { 3, 4 } }; // fill hashtable (point1, point2) ----> edgenr for (i = 1; i <= mesh.GetNE(); i++) { const Element & el = mesh.VolumeElement (i); INDEX_2 edge; for (j = 1; j <= 6; j++) { edge.I1() = el.PNum (eledges[j-1][0]); edge.I2() = el.PNum (eledges[j-1][1]); edge.Sort(); if (!edgeht.Used (edge)) { edgelist.Append (edge); edgeht.Set (edge, edgelist.Size()); } } } // set bedges, bpoints bedge.SetSize (edgelist.Size()); bedge.Clear(); bpoint.Clear(); for (i = 1; i <= mesh.GetNSE(); i++) { const Element2d & sel = mesh.SurfaceElement(i); for (j = 1; j <= 3; j++) { bpoint.Set (sel.PNum(j)); INDEX_2 edge; edge.I1() = sel.PNum(j); edge.I2() = sel.PNum(j%3+1); edge.Sort(); bedge.Set (edgeht.Get (edge)); } } outfile << mesh.GetNE() << endl; // write element ---> point for (i = 1; i <= mesh.GetNE(); i++) { const Element & el = mesh.VolumeElement(i); outfile.width(8); outfile << i; for (j = 1; j <= 4; j++) { outfile.width(8); outfile << el.PNum(j); } outfile << endl; } // write element ---> edge for (i = 1; i <= mesh.GetNE(); i++) { const Element & el = mesh.VolumeElement (i); INDEX_2 edge; for (j = 1; j <= 6; j++) { edge.I1() = el.PNum (eledges[j-1][0]); edge.I2() = el.PNum (eledges[j-1][1]); edge.Sort(); outfile.width(8); outfile << edgeht.Get (edge); } outfile << endl; } // write points outfile << mesh.GetNP() << endl; outfile.precision (6); for (i = 1; i <= mesh.GetNP(); i++) { const Point3d & p = mesh.Point(i); for (j = 1; j <= 3; j++) { outfile.width(8); outfile << p.X(j); } outfile << " " << (bpoint.Test(i) ? "1" : 0) << endl; } // write edges outfile << edgelist.Size() << endl; for (i = 1; i <= edgelist.Size(); i++) { outfile.width(8); outfile << edgelist.Get(i).I1(); outfile.width(8); outfile << edgelist.Get(i).I2(); outfile << " " << (bedge.Test(i) ? "1" : "0") << endl; } } }
int main(int argc, char *argv[]) { FILE *fp; int i, pc_init; Program pm[50000]; float x = 0.0; fpin = stdin; fpout = stdout; for(i = 0; i < 32; i++) { reg[i].i = 0; freg[i].i = 0; } reg[29].i = 1048575; reg[30].i = 65536; for(i = 0; i < 1048576; i++) memory[i].i = 0; if((fp = fopen(argv[argc-1],"r")) == NULL) { perror("open error"); return 0; } load(fp, pm); fclose(fp); getoption(argc, argv); pc_init = pc; while(x < 2*M_PI) { freg[12].f = x; do{ if(printflag == 1) print_instr(pm[pc]); while((breakflag == 1 && pc == breakpoint) || (stepflag == 1 && stepcount == 0)) bpoint(pm[pc]); if(stepcount > 0) stepcount--; } while(exec(pm[pc]) == 0); fprintf(fpout, "%f %f\n", x, freg[0].f); x += 0.01; pc = pc_init; for(i = 0; i < 32; i++) freg[i].i = 0; } fprintf(stderr, "complete instructions\n"); print_status(); fclose(fpin); fclose(fpout); return 0; }