/*----------------------------------------------------------*/
/* */
-/* LIBMESH V 5.45 */
+/* LIBMESH V 5.46 */
/* */
/*----------------------------------------------------------*/
/* */
/* Description: handle .meshb file format I/O */
/* Author: Loic MARECHAL */
/* Creation date: feb 16 2007 */
-/* Last modification: feb 08 2011 */
+/* Last modification: apr 03 2012 */
/* */
/*----------------------------------------------------------*/
typedef struct
{
int dim, ver, mod, typ, cod, pos;
- long NexKwdPos;
+ long NexKwdPos, siz;
KwdSct KwdTab[ GmfMaxKwd + 1 ];
FILE *hdl;
int *IntBuf;
/* Global variables */
/*----------------------------------------------------------*/
-int GmfIniFlg=0;
-GmfMshSct *GmfMshTab[ MaxMsh + 1 ];
-char *GmfKwdFmt[ GmfMaxKwd + 1 ][4] =
+static int GmfIniFlg=0;
+static GmfMshSct *GmfMshTab[ MaxMsh + 1 ];
+static const char *GmfKwdFmt[ GmfMaxKwd + 1 ][4] =
{ {"Reserved", "", "", ""},
{"MeshVersionFormatted", "", "", "i"},
{"Reserved", "", "", ""},
{"SolAtPyramids", "SolAtPyramid", "i", "sr"},
{"QuadrilateralsQ2", "QuadrilateralQ2", "i", "iiiiiiiiii"},
{"ISolAtPyramids", "ISolAtPyramid", "i", "iiiii"},
- {"Reserved", "", "", ""},
+ {"SubDomainFromGeom", "SubDomainFromGeom", "i", "iiii"},
{"TetrahedraP2", "TetrahedronP2", "i", "iiiiiiiiiii"},
- {"Reserved", "", "", ""},
- {"Reserved", "", "", ""},
+ {"Fault_NearTri", "Fault_NearTri", "i", "i"},
+ {"Fault_Inter", "Fault_Inter", "i", "i"},
{"HexahedraQ2", "HexahedronQ2", "i", "iiiiiiiiiiiiiiiiiiiiiiiiiiii"},
- {"Reserved", "", "", ""},
- {"Reserved", "", "", ""},
- {"Reserved", "", "", ""},
- {"Reserved", "", "", ""},
- {"Reserved", "", "", ""},
- {"Reserved", "", "", ""},
- {"Reserved", "", "", ""},
- {"Reserved", "", "", ""},
- {"Reserved", "", "", ""},
- {"Reserved", "", "", ""},
- {"Reserved", "", "", ""},
- {"Reserved", "", "", ""},
+ {"ExtraVerticesAtEdges", "ExtraVerticesAtEdge", "i", "in"},
+ {"ExtraVerticesAtTriangles", "ExtraVerticesAtTriangle", "i", "in"},
+ {"ExtraVerticesAtQuadrilaterals", "ExtraVerticesAtQuadrilateral", "i", "in"},
+ {"ExtraVerticesAtTetrahedra", "ExtraVerticesAtTetrahedron", "i", "in"},
+ {"ExtraVerticesAtPrisms", "ExtraVerticesAtPrism", "i", "in"},
+ {"ExtraVerticesAtHexahedra", "ExtraVerticesAtHexahedron", "i", "in"},
+ {"VerticesOnGeometricVertices", "VertexOnGeometricVertex", "i", "iir"},
+ {"VerticesOnGeometricEdges", "VertexOnGeometricEdge", "i", "iirr"},
+ {"VerticesOnGeometricTriangles", "VertexOnGeometricTriangle", "i", "iirrr"},
+ {"VerticesOnGeometricQuadrilaterals", "VertexOnGeometricQuadrilateral", "i", "iirrr"},
+ {"EdgesOnGeometricEdges", "EdgeOnGeometricEdge", "i", "iir"},
+ {"Fault_FreeEdge", "Fault_FreeEdge", "i", "i"},
{"Polyhedra", "Polyhedron", "i", "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii"},
{"Polygons", "Polygon", "", "iiiiiiiii"},
- {"Reserved", "", "", ""},
+ {"Fault_Overlap", "Fault_Overlap", "i", "i"},
{"Pyramids", "Pyramid", "i", "iiiiii"},
{"BoundingBox", "", "", "drdr"},
{"Body","i", "drdrdrdr"},
{"PrivateTable", "PrivateTable", "i", "i"},
- {"Reserved", "", "", ""},
+ {"Fault_BadShape", "Fault_BadShape", "i", "i"},
{"End", "", "", ""},
- {"Reserved", "", "", ""},
- {"Reserved", "", "", ""},
- {"Reserved", "", "", ""},
- {"Reserved", "", "", ""},
+ {"TrianglesOnGeometricTriangles", "TriangleOnGeometricTriangle", "i", "iir"},
+ {"TrianglesOnGeometricQuadrilaterals", "TriangleOnGeometricQuadrilateral", "i", "iir"},
+ {"QuadrilateralsOnGeometricTriangles", "QuadrilateralOnGeometricTriangle", "i", "iir"},
+ {"QuadrilateralsOnGeometricQuadrilaterals", "QuadrilateralOnGeometricQuadrilateral", "i", "iir"},
{"Tangents", "Tangent", "i", "dr"},
{"Normals", "Normal", "i", "dr"},
{"TangentAtVertices", "TangentAtVertex", "i", "ii"},
{"ISolAtHexahedra", "ISolAtHexahedron", "i", "iiiiiiii"},
{"Iterations", "","","i"},
{"Time", "","","r"},
- {"Reserved", "","",""}
+ {"Fault_SmallTri", "Fault_SmallTri","i","i"},
+ {"CoarseHexahedra", "CoarseHexahedron", "i", "i"}
};
char str[ GmfStrSiz ];
va_list VarArg;
GmfMshSct *msh;
+ char *ptr;
+ int k;
if(!GmfIniFlg)
{
/* Copy the FilNam into the structure */
if(strlen(FilNam) + 7 >= GmfStrSiz)
+ {
+ free (msh);
return(0);
+ }
strcpy(msh->FilNam, FilNam);
/* Store the opening mod (read or write) and guess the filetype (binary or ascii) depending on the extension */
msh->mod = mod;
- msh->buf = (void *)msh->DblBuf;
- msh->FltBuf = (void *)msh->DblBuf;
- msh->IntBuf = (void *)msh->DblBuf;
-
- if(strstr(msh->FilNam, ".meshb"))
+ msh->buf = (unsigned char *)msh->DblBuf;
+ msh->FltBuf = (float *)msh->DblBuf;
+ msh->IntBuf = (int *)msh->DblBuf;
+
+ k = strlen(msh->FilNam) - 6;
+ if(k < 0)
+ k = 0;
+ ptr = msh->FilNam+k;
+ if(strstr(ptr, ".meshb"))
msh->typ |= (Bin | MshFil);
- else if(strstr(msh->FilNam, ".mesh"))
+ else if(strstr(ptr, ".mesh"))
msh->typ |= (Asc | MshFil);
- else if(strstr(msh->FilNam, ".solb"))
+ else if(strstr(ptr, ".solb"))
msh->typ |= (Bin | SolFil);
- else if(strstr(msh->FilNam, ".sol"))
+ else if(strstr(ptr, ".sol"))
msh->typ |= (Asc | SolFil);
- else
+ else {
+ free (msh);
return(0);
+ }
/* Open the file in the required mod and initialyse the mesh structure */
/* Create the name string and open the file */
if(!(msh->hdl = fopen(msh->FilNam, "rb")))
+ {
+ free (msh);
return(0);
+ }
/* Read the endian coding tag, the mesh version and the mesh dimension (mandatory kwd) */
fread((unsigned char *)&msh->cod, WrdSiz, 1, msh->hdl);
if( (msh->cod != 1) && (msh->cod != 16777216) )
+ {
+ free (msh);
return(0);
+ }
ScaWrd(msh, (unsigned char *)&msh->ver);
if( (msh->ver < 1) || (msh->ver > 3) )
+ {
+ free (msh);
return(0);
+ }
if( (msh->ver == 3) && (sizeof(long) == 4) )
+ {
+ free (msh);
return(0);
+ }
ScaWrd(msh, (unsigned char *)&KwdCod);
if(KwdCod != GmfDimension)
+ {
+ free (msh);
return(0);
+ }
GetPos(msh);
ScaWrd(msh, (unsigned char *)&msh->dim);
}while( (res != EOF) && strcmp(str, "MeshVersionFormatted") );
if(res == EOF)
+ {
+ free (msh);
return(0);
+ }
fscanf(msh->hdl, "%d", &msh->ver);
if( (msh->ver < 1) || (msh->ver > 3) )
+ {
+ free (msh);
return(0);
+ }
do
{
}while( (res != EOF) && strcmp(str, "Dimension") );
if(res == EOF)
+ {
+ free (msh);
return(0);
+ }
fscanf(msh->hdl, "%d", &msh->dim);
}
if( (msh->dim != 2) && (msh->dim != 3) )
+ {
+ free (msh);
return(0);
+ }
(*PtrVer) = msh->ver;
(*PtrDim) = msh->dim;
/* Read the list of kw present in the file */
if(!ScaKwdTab(msh))
+ {
+ free (msh);
return(0);
+ }
GmfMshTab[ MshIdx ] = msh;
va_end(VarArg);
if( (msh->ver < 1) || (msh->ver > 3) )
+ {
+ free (msh);
return(0);
+ }
if( (msh->ver == 3) && (sizeof(long) == 4) )
+ {
+ free (msh);
return(0);
+ }
if( (msh->dim != 2) && (msh->dim != 3) )
+ {
+ free (msh);
return(0);
+ }
/* Create the mesh file */
if(!(msh->hdl = fopen(msh->FilNam, "wb")))
+ {
+ free (msh);
return(0);
+ }
GmfMshTab[ MshIdx ] = msh;
return(MshIdx);
}
else
+ {
+ free (msh);
return(0);
+ }
}
/* In write down the "End" kw in write mode */
- if(msh->mod == GmfWrite) {
+ if(msh->mod == GmfWrite){
if(msh->typ & Asc)
fprintf(msh->hdl, "\n%s\n", GmfKwdFmt[ GmfEnd ][0]);
else
GmfSetKwd(MshIdx, GmfEnd, 0);
- }
-
+ }
/* Close the file and free the mesh structure */
if(fclose(msh->hdl))
RecWrd(msh, (unsigned char *)&kwd->TypTab[i]);
}
}
+
+ /* Reset write buffer position */
msh->pos = 0;
- return(kwd->NmbLin);
+
+ /* Estimate the total file size and check whether it crosses the 2GB threshold */
+
+ msh->siz += kwd->NmbLin * kwd->NmbWrd * WrdSiz;
+
+ if(msh->siz > 2E9)
+ return(0);
+ else
+ return(kwd->NmbLin);
}
if(kwd->typ != SolKwd)
{
+ int k, nb_repeat = 0;
+
if(msh->ver == 1)
{
if(msh->typ & Asc)
for(i=0;i<kwd->SolSiz;i++)
if(kwd->fmt[i] == 'r')
fscanf(msh->hdl, "%f", va_arg(VarArg, float *));
+ else if(kwd->fmt[i] == 'n') {
+ fscanf(msh->hdl, "%d", &nb_repeat);
+ *(va_arg(VarArg, int *)) = nb_repeat;
+ for(k=0;k<nb_repeat;k++)
+ fscanf(msh->hdl, "%d", va_arg(VarArg, int *));
+ }
else
fscanf(msh->hdl, "%d", va_arg(VarArg, int *));
}
else
{
- ScaBlk(msh, msh->buf, kwd->SolSiz);
-
for(i=0;i<kwd->SolSiz;i++)
if(kwd->fmt[i] == 'r')
- *(va_arg(VarArg, float *)) = msh->FltBuf[i];
+ ScaWrd(msh, (unsigned char *)va_arg(VarArg, float *));
+ else if(kwd->fmt[i] == 'n') {
+ ScaWrd(msh, (unsigned char *)&nb_repeat);
+ *(va_arg(VarArg, int *)) = nb_repeat;
+ for(k=0;k<nb_repeat;k++)
+ ScaWrd(msh, (unsigned char *)va_arg(VarArg, int *));
+ }
else
- *(va_arg(VarArg, int *)) = msh->IntBuf[i];
+ ScaWrd(msh, (unsigned char *)va_arg(VarArg, int *));
}
}
else
for(i=0;i<kwd->SolSiz;i++)
if(kwd->fmt[i] == 'r')
fscanf(msh->hdl, "%lf", va_arg(VarArg, double *));
+ else if(kwd->fmt[i] == 'n') {
+ fscanf(msh->hdl, "%d", &nb_repeat);
+ *(va_arg(VarArg, int *)) = nb_repeat;
+ for(k=0;k<nb_repeat;k++)
+ fscanf(msh->hdl, "%d", va_arg(VarArg, int *));
+ }
else
fscanf(msh->hdl, "%d", va_arg(VarArg, int *));
}
for(i=0;i<kwd->SolSiz;i++)
if(kwd->fmt[i] == 'r')
ScaDblWrd(msh, (unsigned char *)va_arg(VarArg, double *));
+ else if(kwd->fmt[i] == 'n') {
+ ScaWrd(msh, (unsigned char *)&nb_repeat);
+ *(va_arg(VarArg, int *)) = nb_repeat;
+ for(k=0;k<nb_repeat;k++)
+ ScaWrd(msh, (unsigned char *)va_arg(VarArg, int *));
+ }
else
ScaWrd(msh, (unsigned char *)va_arg(VarArg, int *));
}
if(kwd->typ != SolKwd)
{
+ int k, nb_repeat = 0;
+
if(msh->ver == 1)
{
if(msh->typ & Asc)
for(i=0;i<kwd->SolSiz;i++)
if(kwd->fmt[i] == 'r')
fprintf(msh->hdl, "%g ", (float)va_arg(VarArg, double));
+ else if(kwd->fmt[i] == 'n') {
+ nb_repeat = va_arg(VarArg, int);
+ fprintf(msh->hdl, "%d ", nb_repeat);
+ for(k=0;k<nb_repeat;k++)
+ fprintf(msh->hdl, "%d ", va_arg(VarArg, int));
+ }
else
fprintf(msh->hdl, "%d ", va_arg(VarArg, int));
}
else
{
+ int size_of_block = kwd->SolSiz;
for(i=0;i<kwd->SolSiz;i++)
if(kwd->fmt[i] == 'r')
msh->FltBuf[i] = va_arg(VarArg, double);
+ else if(kwd->fmt[i] == 'n') {
+ nb_repeat = va_arg(VarArg, int);
+ msh->FltBuf[i] = nb_repeat;
+ for(k=0;k<nb_repeat;k++) {
+ msh->IntBuf[i+1+k] = va_arg(VarArg, int);
+ size_of_block ++;
+ }
+ }
else
msh->IntBuf[i] = va_arg(VarArg, int);
- RecBlk(msh, msh->buf, kwd->SolSiz);
+ RecBlk(msh, msh->buf, size_of_block);
}
}
else
for(i=0;i<kwd->SolSiz;i++)
if(kwd->fmt[i] == 'r')
fprintf(msh->hdl, "%.15lg ", va_arg(VarArg, double));
+ else if(kwd->fmt[i] == 'n') {
+ nb_repeat = va_arg(VarArg, int);
+ fprintf(msh->hdl, "%d ", nb_repeat);
+ for(k=0;k<nb_repeat;k++)
+ fprintf(msh->hdl, "%d ", va_arg(VarArg, int));
+ }
else
fprintf(msh->hdl, "%d ", va_arg(VarArg, int));
}
for(i=0;i<kwd->SolSiz;i++)
if(kwd->fmt[i] == 'r')
{
- DblBuf = (void *)&msh->buf[ pos ];
+ DblBuf = (double *)&msh->buf[ pos ];
*DblBuf = va_arg(VarArg, double);
pos += 8;
}
+ else if(kwd->fmt[i] == 'n')
+ {
+ IntBuf = (int *)&msh->buf[ pos ];
+ nb_repeat = va_arg(VarArg, int);
+ *IntBuf = nb_repeat;
+ pos += 4;
+ for(k=0;k<nb_repeat;k++) {
+ IntBuf = (int *)&msh->buf[ pos ];
+ *IntBuf = va_arg(VarArg, int);
+ pos += 4;
+ }
+ }
else
{
- IntBuf = (void *)&msh->buf[ pos ];
+ IntBuf = (int *)&msh->buf[ pos ];
*IntBuf = va_arg(VarArg, int);
pos += 4;
}
- RecBlk(msh, msh->buf, kwd->NmbWrd);
+ RecBlk(msh, msh->buf, pos/4);
}
}
}
else
RecDblWrd(OutMsh, (unsigned char *)&d);
}
+ else if(kwd->fmt[i] == 'n')
+ {
+ int k, nb_repeat = 0;
+
+ if(InpMsh->typ & Asc)
+ fscanf(InpMsh->hdl, "%d", &a);
+ else
+ ScaWrd(InpMsh, (unsigned char *)&a);
+
+ nb_repeat = a;
+
+ if(OutMsh->typ & Asc)
+ fprintf(OutMsh->hdl, "%d ", a);
+ else
+ RecWrd(OutMsh, (unsigned char *)&a);
+
+ for(k=0;k<nb_repeat;k++) {
+ if(InpMsh->typ & Asc)
+ fscanf(InpMsh->hdl, "%d", &a);
+ else
+ ScaWrd(InpMsh, (unsigned char *)&a);
+
+ if(OutMsh->typ & Asc)
+ fprintf(OutMsh->hdl, "%d ", a);
+ else
+ RecWrd(OutMsh, (unsigned char *)&a);
+ }
+ }
else
{
if(InpMsh->typ & Asc)
static void ExpFmt(GmfMshSct *msh, int KwdCod)
{
int i, j, TmpSiz=0;
- char chr, *InpFmt = GmfKwdFmt[ KwdCod ][3];
+ char chr;
+ const char *InpFmt = GmfKwdFmt[ KwdCod ][3];
KwdSct *kwd = &msh->KwdTab[ KwdCod ];
/* Set the kwd's type */
/*----------------------------------------------------------*/
-/* Read a 4 or 8 bytes position in mesh file */
+/* Write a 4 or 8 bytes position in a mesh file */
/*----------------------------------------------------------*/
static void SetPos(GmfMshSct *msh, long pos)