00001
00006 #include <stdio.h>
00007 #include <stdlib.h>
00008 #include "tetmesh.h"
00009 #include "charm.h"
00010
00012 bool readInts(FILE *f,int *dest,int n,int base) {
00013 for (int i=0;i<n;i++) {
00014 int v;
00015 if (1!=fscanf(f,"%d",&v)) return false;
00016 dest[i]=v-base;
00017 }
00018 return true;
00019 }
00020
00022 bool readPts(FILE *f,CkVector3d *dest,int n) {
00023 for (int i=0;i<n;i++) {
00024 double x,y,z;
00025 if (3!=fscanf(f,"%lf%lf%lf",&x,&y,&z)) return false;
00026 dest[i]=CkVector3d(x,y,z);
00027 }
00028 return true;
00029 }
00030
00031 void bad(const char *why) {
00032 printf("Fatal error> %s\n",why);
00033 abort();
00034 }
00035
00037 void readNoboite(FILE *f,TetMesh &t) {
00038 if (f==NULL)
00039 CkAbort("Error opening TetMesh file");
00040
00041
00042
00043 const int headerLen=17;
00044 int header[headerLen];
00045 if (!readInts(f,header,headerLen,0))
00046 CkAbort("Error reading TetMesh file header");
00047 t.allocate(header[0],header[1]);
00048
00049
00050 if (!readInts(f,t.getTetConn(),4*t.getTets(),1))
00051 CkAbort("Error reading TetMesh file's tets");
00052
00053
00054 if (!readPts(f,t.getPointArray(),t.getPoints()))
00055 CkAbort("Error reading TetMesh file's points");
00056 }
00057
00059 void writeNoboite(FILE *f,TetMesh &t) {
00060 if (f==NULL)
00061 CkAbort("Error opening TetMesh file for write");
00062 int i, e=t.getTets(), n=t.getPoints();
00063 fprintf(f,"%d %d ", e,n);
00064 for (i=0;i<15;i++) fprintf(f,"-1 ");
00065 fprintf(f,"\n");
00066 for (i=0;i<e;i++) {
00067 for (int j=0;j<TetMesh::nodePer;j++)
00068 fprintf(f,"%d ",t.getTet(i)[j]+1);
00069 fprintf(f,"\n");
00070 }
00071 for (i=0;i<n;i++) {
00072 CkVector3d v=t.getPoint(i);
00073 fprintf(f,"%f %f %f \n",v.x,v.y,v.z);
00074 }
00075 }
00076
00077