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

📄 gmvread.c

📁 一个用来实现偏微分方程中网格的计算库
💻 C
📖 第 1 页 / 共 5 页
字号:
/**************************************************************************//* Copyright Notice                                                       *//*                                                                        *//* For Scientific and Technical Information Only                          *//* Copyright 2006 Los Alamos National Security, LLC All rights reserved   *//*                                                                        *//* For All Information Unless otherwise indicated, this information has   *//* been authored by an employee or employees of the Los Alamos National   *//* Security, LLC (LANS), operator of the Los Alamos National Laboratory   *//* under Contract No. DE-AC52-06NA25396 with the U.S. Department of       *//* Energy. The U.S. Government has rights to use, reproduce, and          *//* distribute this information. The public may copy and use this          *//* information without charge, provided that this Notice and any          *//* statement of authorship are reproduced on all copies. Neither the      *//* Government nor LANS makes any warranty, express or implied, or assumes *//* any liability or responsibility for the use of this information.       *//*                                                                        *//* Author: Frank A. Ortega fao[at]lanl.gov                                *//**************************************************************************/#include <stdlib.h>#include <stdio.h>#include <string.h>#define RDATA_INIT#include "gmvread.h"/* #include "gmvrayread.h" */#include <sys/types.h>/* #include <malloc.h> */#include <math.h>#define FREE(a) { if (a) free(a); a = NULL; }#define CHAR 0#define SHORT 1#define INT 2#define FLOAT 3#define WORD 4#define DOUBLE 5#define LONGLONG 6#define CHARSIZE 1#define SHORTSIZE 2#define INTSIZE 4#define WORDSIZE 4#define FLOATSIZE 4#define LONGSIZE 4#define DOUBLESIZE 8#define LONGLONGSIZE 8#define IEEE 0#define ASCII 1#define IEEEI4R4 0#define IEEEI4R8 2#define IEEEI8R4 3#define IEEEI8R8 4#define IECXI4R4 5#define IECXI4R8 6#define IECXI8R4 7#define IECXI8R8 8static int charsize = CHARSIZE, shortsize = SHORTSIZE, intsize = INTSIZE,            wordsize = WORDSIZE, floatsize = FLOATSIZE,           longsize = LONGSIZE, doublesize = DOUBLESIZE,           longlongsize = LONGLONGSIZE, charsize_in;static long numnodes, numcells, lncells, numcellsin, numfaces, lnfaces,            numfacesin, ncells_struct;static int numsurf, lnsurf, numsurfin, numtracers, numunits;static short amrflag_in, structflag_in, fromfileflag, fromfileskip = 0;static short nodes_read = 0, cells_read = 0, faces_read = 0,              surface_read = 0, iend = 0, swapbytes_on = 0, skipflag = 0,              reading_fromfile = 0, vfaceflag = 0, node_inp_type,              printon = 0;static int curr_keyword, ftype, ftype_sav, readkeyword, ff_keyword = -1;static unsigned wordbuf;static char sav_keyword[9], input_dir[300];void swapbytes(void *from, int size, int nitems),     readnodes(FILE *gmvin, int ftype),     readcells(FILE *gmvin, int ftype),     readfaces(FILE *gmvin, int ftype),     readvfaces(FILE *gmvin, int ftype),     readxfaces(FILE *gmvin, int ftype),     readmats(FILE *gmvin, int ftype),     readvels(FILE *gmvin, int ftype),     readvars(FILE *gmvin, int ftype),     readflags(FILE *gmvin, int ftype),     readpolygons(FILE *gmvin, int ftype),     readtracers(FILE *gmvin, int ftype),     readnodeids(FILE *gmvin, int ftype),     readcellids(FILE *gmvin, int ftype),     readfaceids(FILE *gmvin, int ftype),     readtracerids(FILE *gmvin, int ftype),     readunits(FILE *gmvin, int ftype),     readsurface(FILE *gmvin, int ftype),     readsurfvel(FILE *gmvin, int ftype),     readsurfmats(FILE *gmvin, int ftype),     readsurfvars(FILE *gmvin, int ftype),     readsurfflag(FILE *gmvin, int ftype),     readsurfids(FILE *gmvin, int ftype),     readvinfo(FILE *gmvin, int ftype),     readcomments(FILE *gmvin, int ftype),     readgroups(FILE *gmvin, int ftype),     readcellpes(FILE *gmvin, int ftype),     readsubvars(FILE *gmvin, int ftype),     readghosts(FILE *gmvin, int ftype),     readvects(FILE *gmvin, int ftype),     gmvrdmemerr(), ioerrtst(FILE *gmvin), endfromfile();static FILE *gmvin, *gmvin_sav;int binread(void* ptr, int size, int type, long nitems, FILE* stream);int word2int(unsigned wordin);int gmvread_checkfile(char *filnam){  /*                           */  /*  Check a GMV input file.  */  /*                           */  int chkend;  char magic[9], filetype[9];  FILE *gmvchk;  int chk_gmvend(FILE *gmvin);   gmvchk = fopen(filnam,"r");   if (gmvchk == NULL)     {      fprintf(stderr,"GMV cannot open file %s\n",filnam);      return 1;     }       /*  Read header. */   binread(magic,charsize, CHAR, (long)8, gmvchk);   if (strncmp(magic,"gmvinput",8) != 0)     {      fprintf(stderr,"This is not a GMV input file.\n");      fclose(gmvchk);      return 2;     }   /*  Check that gmv input file has "endgmv".  */   if (strncmp(magic,"gmvinput",8) == 0)     {      chkend = chk_gmvend(gmvchk);      if (!chkend)        {         fprintf(stderr,"Error - endgmv not found.\n");         fclose(gmvchk);         return 3;        }     }   /*  Read file type and set ftype: 0-ieee binary, 1-ascii text,  */   /*  0-ieeei4r4 binary, 2-ieeei4r8 binary, 3-ieeei8r4 binary,    */   /*  4-ieeei8r8 binary, 5-iecxi4r4 binary, 6-iecxi4r8 binary,    */   /*  7-iecxi8r4 binary or 8-iecxi8r8 binary.                     */   binread(filetype,charsize, CHAR, (long)8, gmvchk);   /*  Rewind the file and re-read header for file type.  */   ftype = -1;   if (strncmp(filetype,"ascii",5) == 0) ftype = ASCII;   if (strncmp(filetype," ascii",6) == 0) ftype = ASCII;   if (strncmp(filetype,"  ascii",7) == 0) ftype = ASCII;   if (strncmp(filetype,"   ascii",8) == 0) ftype = ASCII;   if (strncmp(filetype,"ieee",4) == 0) ftype = IEEEI4R4;   if (strncmp(filetype," ieee",5) == 0) ftype = IEEEI4R4;   if (strncmp(filetype,"ieeei4r4",8) == 0) ftype = IEEEI4R4;   if (strncmp(filetype," ieeei4r4",9) == 0) ftype = IEEEI4R4;   if (strncmp(filetype,"ieeei4r8",8) == 0) ftype = IEEEI4R8;   if (strncmp(filetype," ieeei4r8",9) == 0) ftype = IEEEI4R8;   if (strncmp(filetype,"ieeei8r4",8) == 0) ftype = IEEEI8R4;   if (strncmp(filetype," ieeei8r4",9) == 0) ftype = IEEEI8R4;   if (strncmp(filetype,"ieeei8r8",8) == 0) ftype = IEEEI8R8;   if (strncmp(filetype," ieeei8r8",9) == 0) ftype = IEEEI8R8;   if (strncmp(filetype,"iecxi4r4",8) == 0) ftype = IECXI4R4;   if (strncmp(filetype," iecxi4r4",9) == 0) ftype = IECXI4R4;   if (strncmp(filetype,"iecxi4r8",8) == 0) ftype = IECXI4R8;   if (strncmp(filetype," iecxi4r8",9) == 0) ftype = IECXI4R8;   if (strncmp(filetype,"iecxi8r4",8) == 0) ftype = IECXI8R4;   if (strncmp(filetype," iecxi8r4",9) == 0) ftype = IECXI8R4;   if (strncmp(filetype,"iecxi8r8",8) == 0) ftype = IECXI8R8;   if (strncmp(filetype," iecxi8r8",9) == 0) ftype = IECXI8R8;   /*  Check for valid file type.  */   if (ftype == -1)     {      fprintf(stderr,"Invalid GMV input file type.  Type must be:\n");      fprintf(stderr,       "  ascii, ieee, ieeei4r4, ieeei4r8, ieeei8r4, ieeei8r8,\n");      fprintf(stderr,       "  iecxi4r4, iecxi4r8, iecxi8r4, iecxi8r8,\n");      fclose(gmvchk);      return 4;     }   /*  Check that machine can read I8 types.  */   if (ftype == IEEEI8R4 || ftype == IEEEI8R8 || ftype == IECXI8R4 ||       ftype == IECXI8R8)     {      if (sizeof(long) < 8)        {         fprintf(stderr,"Cannot read 64bit I* types on this machine.\n");         fclose(gmvchk);         return 5;        }     }   fclose(gmvchk);   return 0;}int gmvread_open(char *filnam){  /*                                    */  /*  Open and check a GMV input file.  */  /*                                    */  int chkend, ilast, i, isize;  char magic[9], filetype[9];  int chk_gmvend(FILE *gmvin);   gmvin = fopen(filnam,"r");   if (gmvin == NULL)      {       fprintf(stderr,"GMV cannot open file %s\n",filnam);       return 1;      }       /*  Read header. */   binread(magic,charsize, CHAR, (long)8, gmvin);   if (strncmp(magic,"gmvinput",8) != 0)      {       fprintf(stderr,"This is not a GMV input file.\n");       return 2;      }   /*  Check that gmv input file has "endgmv".  */   if (strncmp(magic,"gmvinput",8) == 0)      {       chkend = chk_gmvend(gmvin);       if (!chkend)         {          fprintf(stderr,"Error - endgmv not found.\n");          return 3;         }      }   /*  Read file type and set ftype: 0-ieee binary, 1-ascii text,  */   /*  0-ieeei4r4 binary, 2-ieeei4r8 binary, 3-ieeei8r4 binary,    */   /*  or 4-ieeei8r8 binary.                                       */   binread(filetype,charsize, CHAR, (long)8, gmvin);   /*  Rewind the file and re-read header for file type.  */   ftype = -1;   if (strncmp(filetype,"ascii",5) == 0) ftype = ASCII;   if (strncmp(filetype," ascii",6) == 0) ftype = ASCII;   if (strncmp(filetype,"  ascii",7) == 0) ftype = ASCII;   if (strncmp(filetype,"   ascii",8) == 0) ftype = ASCII;   if (strncmp(filetype,"ieee",4) == 0) ftype = IEEEI4R4;   if (strncmp(filetype," ieee",5) == 0) ftype = IEEEI4R4;   if (strncmp(filetype,"ieeei4r4",8) == 0) ftype = IEEEI4R4;   if (strncmp(filetype," ieeei4r4",9) == 0) ftype = IEEEI4R4;   if (strncmp(filetype,"ieeei4r8",8) == 0) ftype = IEEEI4R8;   if (strncmp(filetype," ieeei4r8",9) == 0) ftype = IEEEI4R8;   if (strncmp(filetype,"ieeei8r4",8) == 0) ftype = IEEEI8R4;   if (strncmp(filetype," ieeei8r4",9) == 0) ftype = IEEEI8R4;   if (strncmp(filetype,"ieeei8r8",8) == 0) ftype = IEEEI8R8;   if (strncmp(filetype," ieeei8r8",9) == 0) ftype = IEEEI8R8;   if (strncmp(filetype,"iecxi4r4",8) == 0) ftype = IECXI4R4;   if (strncmp(filetype," iecxi4r4",9) == 0) ftype = IECXI4R4;   if (strncmp(filetype,"iecxi4r8",8) == 0) ftype = IECXI4R8;   if (strncmp(filetype," iecxi4r8",9) == 0) ftype = IECXI4R8;   if (strncmp(filetype,"iecxi8r4",8) == 0) ftype = IECXI8R4;   if (strncmp(filetype," iecxi8r4",9) == 0) ftype = IECXI8R4;   if (strncmp(filetype,"iecxi8r8",8) == 0) ftype = IECXI8R8;   if (strncmp(filetype," iecxi8r8",9) == 0) ftype = IECXI8R8;   /*  Determine character input size.  */   charsize_in = 8;   if (ftype == ASCII || ftype > IEEEI8R8) charsize_in = 32;   /*  Reset IECX types back to regular types.  */   if (ftype == IECXI4R4) ftype = IEEEI4R4;   if (ftype == IECXI4R8) ftype = IEEEI4R8;   if (ftype == IECXI8R4) ftype = IEEEI8R4;   if (ftype == IECXI8R8) ftype = IEEEI8R8;   /*  Check for valid file type.  */   if (ftype == -1)     {      fprintf(stderr,"Invalid GMV input file type.  Type must be:\n");      fprintf(stderr,       "  ascii, ieee, ieeei4r4, ieeei4r8, ieeei8r4, ieeei8r8.\n");      fprintf(stderr,       "  iecxi4r4, iecxi4r8, iecxi8r4, iecxi8r8.\n");      return 4;     }   /*  Check that machine can read I8 types.  */   if (ftype == IEEEI8R4 || ftype == IEEEI8R8)     {      if (sizeof(long) < 8)        {         fprintf(stderr,"Cannot read 64bit I* types on this machine.\n");         return 4;        }     }   rewind(gmvin);   if (ftype != ASCII)     {      binread(magic,charsize,CHAR,(long)8,gmvin);      binread(filetype,charsize,CHAR,(long)8,gmvin);     }   if (ftype == ASCII) fscanf(gmvin,"%s%s",magic,filetype);   readkeyword = 1;   /*  Get directory of GMV input file from the file name  */   /*  for use in case any fromfiles found in the file.    */   /*  First find the last /.                              */   if (fromfileskip == 0)     {      isize = strlen(filnam);      ilast = -1;      for (i = 0; i < isize - 1; i++)        {         if (strncmp((filnam+i),"/",1) == 0) ilast = i;        }      if (ilast > -1)        {         strncpy(input_dir,filnam,ilast+1);        }     }      return 0;}int gmvread_open_fromfileskip(char *filnam){  /*                                    */  /*  Open and check a GMV input file.  */  /*  Skip read of fromfiles.           */  /*                                    */  int ierr;   fromfileskip = 1;      ierr = gmvread_open(filnam);   return ierr;}void gmvread_close(){   fclose(gmvin);   fromfileskip = 0;   nodes_read = 0;  cells_read = 0;  faces_read = 0;    surface_read = 0;  iend = 0;  swapbytes_on = 0;  skipflag = 0;    reading_fromfile = 0;  vfaceflag = 0;}void gmvread_printon(){   printon = 1;}void gmvread_printoff(){   printon = 0;}void gmvread_data(){  char keyword[9], tmpchar[20];  double ptime;  float tmptime;  int cycleno, before_nodes_ok;  void fromfilecheck(int keyword);   /*  Zero gmv_data and free structure arrays.  */   gmv_data.keyword = 0;   gmv_data.datatype = 0;   strcpy(gmv_data.name1,"                   ");   gmv_data.num = 0;   gmv_data.num2 = 0;   gmv_data.ndoubledata1 = 0;   gmv_data.ndoubledata2 = 0;   gmv_data.ndoubledata3 = 0;   FREE(gmv_data.doubledata1);     FREE(gmv_data.doubledata2);   FREE(gmv_data.doubledata3);   gmv_data.nlongdata1 = 0;   gmv_data.nlongdata2 = 0;   FREE(gmv_data.longdata1);   FREE(gmv_data.longdata2);   gmv_data.nchardata1 = 0;   gmv_data.nchardata2 = 0;   FREE(gmv_data.chardata1);   FREE(gmv_data.chardata2);   /*  Check current keyword type for continued reading.  */   if (readkeyword == 0)     {      switch (curr_keyword)        {         case(CELLS):            readcells(gmvin,ftype);            break;            case(FACES):            readfaces(gmvin,ftype);            break;         case(VFACES):            readvfaces(gmvin,ftype);            break;         case(XFACES):            readxfaces(gmvin,ftype);            break;         case(VARIABLE):            readvars(gmvin,ftype);            break;         case(FLAGS):            readflags(gmvin,ftype);

⌨️ 快捷键说明

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