⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gmvread.c

📁 一个用来实现偏微分方程中网格的计算库
💻 C
📖 第 1 页 / 共 5 页
字号:
         return;        }      /*  Read all face numbers.  */      lfaces = (long *)malloc(nfaces*sizeof(long));      if (lfaces == NULL)        {         gmvrdmemerr();         return;        }      if (ftype != ASCII)        {         if (ftype == IEEEI4R4 || ftype == IEEEI4R8)           {            cellnodenos = (int *)malloc(nfaces*sizeof(int));            if (cellnodenos == NULL)              {               gmvrdmemerr();               return;              }            binread(cellnodenos,intsize,INT,(long)nfaces,gmvin);            for (i = 0; i < nfaces; i++)              lfaces[i] = cellnodenos[i];            FREE(cellnodenos);           }         else            binread(lfaces,longlongsize,LONGLONG,                     (long)nfaces,gmvin);         ioerrtst(gmvin);        }      if (ftype == ASCII) rdlongs(lfaces,(long)nfaces,gmvin);/*      for (i = 0; i < nfaces; i++)         lfaces[i]--;*/            gmv_data.keyword = CELLS;      if (strncmp(keyword,"vface2d",7) == 0)         gmv_data.datatype = VFACE2D;      else gmv_data.datatype = VFACE3D;      strcpy(gmv_data.name1,keyword);      gmv_data.num = lncells;      gmv_data.num2 = nfaces;      gmv_data.nlongdata1 = nfaces;      gmv_data.longdata1 = lfaces;     }   /*  Else read regular cells.  */   else      {      lcellnodenos = (long *)malloc(ndat*sizeof(long));      if (lcellnodenos == NULL)        {         gmvrdmemerr();         return;        }      if (ftype != ASCII)        {         if (ftype == IEEEI4R4 || ftype == IEEEI4R8)           {            verts = (int *)malloc(ndat*sizeof(int));            if (verts == NULL)              {               gmvrdmemerr();               return;              }            binread(verts,intsize,INT,(long)ndat,gmvin);            for (i = 0; i < ndat; i++)              lcellnodenos[i] = verts[i];            free(verts);           }         else            binread(lcellnodenos,longlongsize,LONGLONG,(long)ndat,gmvin);         ioerrtst(gmvin);        }      if (ftype == ASCII) rdlongs(lcellnodenos,(long)ndat,gmvin);      if ((feof(gmvin) != 0) | (ferror(gmvin) != 0))        {         fprintf(stderr,"I/O error while reading cells.\n");         gmv_data.keyword = GMVERROR;         return;        }      gmv_data.keyword = CELLS;      gmv_data.datatype = REGULAR;      strcpy(gmv_data.name1,keyword);      gmv_data.num = lncells;      gmv_data.num2 = ndat;      gmv_data.nlongdata1 = ndat;      gmv_data.longdata1 = lcellnodenos;     }}void readfaces(FILE* gmvin, int ftype){  int i, nverts, *tmpvertsin;  long *vertsin;   if (readkeyword == 1)     {      /*  Read no. of faces to read and cells to generate.  */      if (ftype == ASCII)        {         fscanf(gmvin,"%ld",&lnfaces);         fscanf(gmvin,"%ld",&lncells);        }      else        {         if (ftype == IEEEI8R4 || ftype == IEEEI8R8)           {            binread(&lnfaces,longlongsize,LONGLONG,(long)1,gmvin);            binread(&lncells,longlongsize,LONGLONG,(long)1,gmvin);           }         else           {            binread(&i,intsize,INT,(long)1,gmvin);            lnfaces = i;            binread(&i,intsize,INT,(long)1,gmvin);            lncells = i;           }        }      ioerrtst(gmvin);      numfacesin = 0;      if (printon)         printf("Reading %ld faces.\n",lnfaces);      if (!skipflag)        {         numfaces = lnfaces;         numcells = lncells;         faces_read = 1;        }     }   /*  Check no. of faces read.  */   numfacesin++;   if (numfacesin > lnfaces)     {      readkeyword = 2;      gmv_data.keyword = FACES;      gmv_data.num = lnfaces;      gmv_data.num2 = lncells;      gmv_data.datatype = ENDKEYWORD;      return;     }   /*  Read face vertices and cell info for each face.  */   if (ftype != ASCII) binread(&nverts,intsize,INT,(long)1,gmvin);   if (ftype == ASCII) fscanf(gmvin,"%d",&nverts);   ioerrtst(gmvin);   /*  Read a face vertices and cells.  */   vertsin = (long *)malloc((nverts+2)*sizeof(long));   if (vertsin == NULL)     {      gmvrdmemerr();      return;     }   if (ftype == ASCII) rdlongs(vertsin,(long)nverts+2,gmvin);   else     {      if (ftype == IEEEI8R4 || ftype == IEEEI8R8)        {         binread(vertsin,longlongsize,LONGLONG,(long)nverts+2,gmvin);        }      else         {         tmpvertsin = (int *)malloc((nverts+2)*sizeof(int));         if (tmpvertsin == NULL)           {            gmvrdmemerr();            return;           }         binread(tmpvertsin,intsize,INT,(long)nverts+2,gmvin);         for (i = 0; i < nverts+2; i++)            vertsin[i] = tmpvertsin[i];         free(tmpvertsin);        }      ioerrtst(gmvin);     }   if ((feof(gmvin) != 0) | (ferror(gmvin) != 0))     {      fprintf(stderr,"I/O error while reading faces.\n");      gmv_data.keyword = GMVERROR;      return;     }   gmv_data.keyword = FACES;   gmv_data.datatype = REGULAR;   gmv_data.num = lnfaces;   gmv_data.num2 = lncells;   gmv_data.nlongdata1 = nverts + 2;   gmv_data.longdata1 = vertsin;}void readvfaces(FILE* gmvin, int ftype){  int i, nverts, *tmpvertsin, facepe, oppfacepe;  long *vertsin, oppface, cellid;   if (readkeyword == 1)     {      /*  Read no. of vfaces to read.  */      if (ftype == ASCII) fscanf(gmvin,"%ld",&lnfaces);      else        {         if (ftype == IEEEI8R4 || ftype == IEEEI8R8)           {            binread(&lnfaces,longlongsize,LONGLONG,(long)1,gmvin);           }         else           {            binread(&i,intsize,INT,(long)1,gmvin);            lnfaces = i;           }        }      ioerrtst(gmvin);      numfacesin = 0;      if (printon)         printf("Reading %ld vfaces.\n",lnfaces);      if (!skipflag)        {         numfaces = lnfaces;        }     }   /*  Check no. of vfaces read.  */   numfacesin++;   if (numfacesin > lnfaces)     {      readkeyword = 2;      gmv_data.keyword = VFACES;      gmv_data.datatype = ENDKEYWORD;      return;     }   /*  Read vface vertices, PE number, opposite  */   /*  face info and cell info for each face.    */   if (ftype != ASCII)     {      binread(&nverts,intsize,INT,(long)1,gmvin);      binread(&facepe,intsize,INT,(long)1,gmvin);      if (ftype == IEEEI8R4 || ftype == IEEEI8R8)        {         binread(&oppface,longlongsize,LONGLONG,(long)1,gmvin);         binread(&oppfacepe,intsize,INT,(long)1,gmvin);         binread(&cellid,longlongsize,LONGLONG,(long)1,gmvin);        }      else         {         binread(&i,intsize,INT,(long)1,gmvin);         oppface = i;         binread(&oppfacepe,intsize,INT,(long)1,gmvin);         binread(&i,intsize,INT,(long)1,gmvin);         cellid = i;        }     }   if (ftype == ASCII)      {       fscanf(gmvin,"%d%d",&nverts,&facepe);       fscanf(gmvin,"%ld",&oppface);       fscanf(gmvin,"%d",&oppfacepe);       fscanf(gmvin,"%ld",&cellid);      }   ioerrtst(gmvin);   /*  Read vface vertices.  */   vertsin = (long *)malloc((nverts)*sizeof(long));   if (vertsin == NULL)     {      gmvrdmemerr();      return;     }   if (ftype == ASCII) rdlongs(vertsin,(long)nverts,gmvin);   else     {      if (ftype == IEEEI8R4 || ftype == IEEEI8R8)        {         binread(vertsin,longlongsize,LONGLONG,(long)nverts,gmvin);        }      else         {         tmpvertsin = (int *)malloc((nverts)*sizeof(int));         if (tmpvertsin == NULL)           {            gmvrdmemerr();            return;           }         binread(tmpvertsin,intsize,INT,(long)nverts,gmvin);         for (i = 0; i < nverts; i++)            vertsin[i] = tmpvertsin[i];         free(tmpvertsin);        }      ioerrtst(gmvin);     }   if ((feof(gmvin) != 0) | (ferror(gmvin) != 0))     {      fprintf(stderr,"I/O error while reading faces.\n");      gmv_data.keyword = GMVERROR;      return;     }   gmv_data.keyword = VFACES;   gmv_data.datatype = REGULAR;   gmv_data.num = lnfaces;   gmv_data.nlongdata1 = nverts;   gmv_data.longdata1 = vertsin;   gmv_data.nlongdata2 = 4;   gmv_data.longdata2 = (long *)malloc(4*sizeof(long));   gmv_data.longdata2[0] = facepe;   gmv_data.longdata2[1] = oppface;   /* gmv_data.longdata2[1] = oppface - 1; */   gmv_data.longdata2[2] = oppfacepe;   gmv_data.longdata2[3] = cellid;}void readxfaces(FILE* gmvin, int ftype){  int i, j, *tmpftvin;  long *nxvertsin, *vertsin, totverts;  static int xfaceloc;   if (readkeyword == 1)     {      /*  Read no. of xfaces to read.  */      if (ftype == ASCII) fscanf(gmvin,"%ld",&lnfaces);      else        {         if (ftype == IEEEI8R4 || ftype == IEEEI8R8)           {            binread(&lnfaces,longlongsize,LONGLONG,(long)1,gmvin);           }         else           {            binread(&i,intsize,INT,(long)1,gmvin);            lnfaces = i;           }        }      ioerrtst(gmvin);      xfaceloc = 0;      if (printon)         printf("Reading %ld xfaces.\n",lnfaces);      if (!skipflag)        {         numfaces = lnfaces;         faces_read = 1;        }     }   /*  Check location of xfaces to determine what to read.  */   if (xfaceloc == 0)     {      /*  Allocate and read the face to nodes array.  */      nxvertsin = (long *)malloc(lnfaces*sizeof(long));      if (nxvertsin == NULL)        {         gmvrdmemerr();         return;        }      if (ftype == ASCII) rdlongs(nxvertsin,(long)lnfaces,gmvin);      else        {         if (ftype == IEEEI8R4 || ftype == IEEEI8R8)           {            binread(nxvertsin,longlongsize,LONGLONG,(long)lnfaces,gmvin);           }         else            {            tmpftvin = (int *)malloc(lnfaces*sizeof(int));            if (tmpftvin == NULL)              {               gmvrdmemerr();               return;              }            binread(tmpftvin,intsize,INT,(long)lnfaces,gmvin);            for (i = 0; i < lnfaces; i++)              {               nxvertsin[i] = tmpftvin[i];              }            free(tmpftvin);           }        }      ioerrtst(gmvin);      /*  Count the total number of vertices to read.  */      totverts = 0;      for (i = 0; i < lnfaces; i++)        {         totverts += nxvertsin[i];        }      /*  Allocate and read the vertices.  */      vertsin = (long *)malloc(totverts*sizeof(long));      if (vertsin == NULL)        {         gmvrdmemerr();         return;        }      if (ftype == ASCII) rdlongs(vertsin,(long)totverts,gmvin);      else        {         if (ftype == IEEEI8R4 || ftype == IEEEI8R8)           {            binread(vertsin,longlongsize,LONGLONG,(long)totverts,gmvin);           }         else            {            tmpftvin = (int *)malloc(totverts*sizeof(int));            if (tmpftvin == NULL)              {               gmvrdmemerr();               return;              }            binread(tmpftvin,intsize,INT,(long)totverts,gmvin);            for (i = 0; i < totverts; i++)              {               vertsin[i] = tmpftvin[i];              }            free(tmpftvin);           }        }      ioerrtst(gmvin);      gmv_data.nlongdata1 = lnfaces;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -