Esempio n. 1
0
static INT_ ug_realloc_tmp_file_struct
 (UG_TMP_File_Struct * UG_TMP_File_Struct_Ptr)

{

/*
 * Realloc binary TMP file structure arrays.
 */

  INT_ Error_Flag = 0;
  INT_ Number_of_TMP_Files;

  Number_of_TMP_Files = UG_TMP_File_Struct_Ptr->Number_of_TMP_Files;

  ++Number_of_TMP_Files;

  UG_TMP_File_Struct_Ptr->Number_of_TMP_Files = Number_of_TMP_Files;

  UG_TMP_File_Struct_Ptr->TMP_File_Name =
    (CHAR_UG_MAX *) ug_realloc (&Error_Flag,
                              UG_TMP_File_Struct_Ptr->TMP_File_Name,
                              Number_of_TMP_Files * sizeof (CHAR_UG_MAX));
  UG_TMP_File_Struct_Ptr->TMP_File_Stream =
    (FILE **) ug_realloc (&Error_Flag,
                          UG_TMP_File_Struct_Ptr->TMP_File_Stream,
                          Number_of_TMP_Files * sizeof (FILE));
  UG_TMP_File_Struct_Ptr->TMP_File_Status =
    (INT_1D *) ug_realloc (&Error_Flag,
                           UG_TMP_File_Struct_Ptr->TMP_File_Status,
                           Number_of_TMP_Files * sizeof (INT_1D));

  if (Error_Flag > 0)
    return (-1);

  return (0);

}
Esempio n. 2
0
void  ug_json_push (UgJson* json, UgJsonParseFunc func, void* dest, void* data)
{
	void** stack;

	if (json->stack.allocated <  json->stack.length + PARSER_STACK_UNIT) {
		json->stack.allocated *= 2;
		json->stack.at = ug_realloc (json->stack.at,
				json->stack.allocated * sizeof (void*));
	}

	 stack   = json->stack.at + json->stack.length;
	*stack++ = func;
	*stack++ = dest;
	*stack++ = data;
	*stack++ = (void*)(uintptr_t)json->scope;
	json->stack.length += PARSER_STACK_UNIT;
}
Esempio n. 3
0
UgJsonError  ug_json_end_parse (UgJson* json)
{
	int  stack_length;

	// clear stack
	stack_length = json->stack.length;
	json->stack.length = 0;

	if (stack_length > PARSER_STACK_UNIT)
		return UG_JSON_ERROR_UNCOMPLETED;
	if (json->index[0])
		return UG_JSON_ERROR_UNCOMPLETED;
	if (json->index[1]) {
		if (json->type >= UG_JSON_N_TYPE)
			return UG_JSON_ERROR_UNCOMPLETED;
		// check uncompleted string.
		if (json->type == UG_JSON_STRING) {
			if (json->buf.at[json->buf.length-1] != 0)
				return UG_JSON_ERROR_UNCOMPLETED;
		}
		// null-terminated for UG_JSON_NUMBER.
		else if (json->type == UG_JSON_NUMBER) {
			if (json->stack.allocated == stack_length) {
				json->stack.allocated *= 2;
				json->stack.at = ug_realloc (json->stack.at,
						json->stack.allocated * sizeof (void*));
			}
			json->buf.at[json->buf.length++] = 0;
		}
		// parse remain value
		ug_json_call_parser (json);
		return (UgJsonError) json->error;
	}

	return UG_JSON_ERROR_NONE;
}
Esempio n. 4
0
UgJsonError  ug_json_parse (UgJson* json, const char* string, int len)
{
	const char* cur;
	const char* end;
	char        vchar;

	if (len == -1)
		len = strlen (string);

	for (cur = string, end = string + len;  cur < end;  cur++) {
		if (json->buf.allocated == json->buf.length) {
			json->buf.allocated *= 2;
			json->buf.at = ug_realloc (json->buf.at,
					json->buf.allocated * sizeof (char));
		}
		vchar = cur[0];
		// begin of top level switch - select JSON part by state
TopLevelSwitch:
		switch (json->state) {
		case UG_JSON_VALUE:
			if (json->index[1])
				return UG_JSON_ERROR_EXCESS_VALUE;

			switch (vchar) {
			case ' ':
			case '\t':
			case '\n':
			case '\r':
				continue;
//				break;

			case '[':
				json->type = UG_JSON_ARRAY;
				ug_json_call_parser (json);
				json->type = UG_JSON_VALUE;  // for ',' in array
				json->scope = UG_JSON_ARRAY;
				json->state = UG_JSON_VALUE;
				continue;
//				break;

			case '{':
				json->type = UG_JSON_OBJECT;
				ug_json_call_parser (json);
				json->type = UG_JSON_VALUE;  // for ',' in object
				json->scope = UG_JSON_OBJECT;
				json->state = UG_JSON_OBJECT;
				continue;
//				break;

			case '\"':
				json->type = UG_JSON_STRING;
				json->state = UG_JSON_STRING;
				json->index[1] = json->buf.length;
				continue;
//				break;

			default:
				switch (vchar) {
				case 't':	// true
					json->state = UG_JSON_TRUE;
					break;
				case 'f':	// false
					json->state = UG_JSON_FALSE;
					break;
				case 'n':	// null
					json->state = UG_JSON_NULL;
					break;
				default:	// number or not
					if (vchar == '-' || (vchar >= '0' && vchar <= '9')) {
						json->type = UG_JSON_NUMBER;
						json->state = UG_JSON_NUMBER;
					}
					else {
						json->state = json->scope;
						goto TopLevelSwitch;
					}
					break;
				}
				json->count = 1;
				json->index[1] = json->buf.length;
				json->buf.at[json->buf.length++] = vchar;
				continue;
//				break;
			}
			break;

		case UG_JSON_OBJECT:
			switch (vchar) {
			case '\"':
				if (json->index[0])
					return UG_JSON_ERROR_EXCESS_NAME;
				json->index[0] = json->buf.length;
				json->state = UG_JSON_STRING;
				continue;
//				break;

			case ':':
				if (json->colon)
					return UG_JSON_ERROR_EXCESS_COLON;
				if (json->index[0] == 0)
					return UG_JSON_ERROR_BEFORE_COLON;
				json->type = UG_JSON_VALUE;
				json->colon = 1;
				json->state = UG_JSON_VALUE;
				continue;
//				break;

			case ' ':
			case '\t':
			case '\n':
			case '\r':
				continue;
//				break;

			case ',':
#ifdef IGNORE_ERROR_IN_SEPARATOR
				// if type is UG_JSON_VALUE or UG_JSON_SEPARATOR
				if (json->type >= UG_JSON_VALUE) {
					json->error = UG_JSON_ERROR_IN_SEPARATOR;
					json->type  = UG_JSON_SEPARATOR;
					continue;
//					break;
				}
#else
				// if type is UG_JSON_VALUE or UG_JSON_SEPARATOR
				if (json->type >= UG_JSON_VALUE)
					return UG_JSON_ERROR_IN_SEPARATOR;
#endif // IGNORE_ERROR_IN_SEPARATOR
				ug_json_call_parser (json);
				json->type = UG_JSON_SEPARATOR;
				continue;
//				break;

			case '}':
#ifdef IGNORE_ERROR_IN_OBJECT
				if (json->type == UG_JSON_SEPARATOR) {
					json->error = UG_JSON_ERROR_IN_OBJECT;
					ug_json_pop (json);
					continue;
//					break;
				}
#else
				if (json->type == UG_JSON_SEPARATOR)
					return UG_JSON_ERROR_IN_OBJECT;
#endif // IGNORE_ERROR_IN_OBJECT
				ug_json_call_parser (json);
				ug_json_pop (json);
				continue;
//				break;

			default:
#ifdef IGNORE_ERROR_IN_OBJECT
				json->error = UG_JSON_ERROR_IN_OBJECT;
				continue;
//				break;
#else
				return UG_JSON_ERROR_IN_OBJECT;
#endif // IGNORE_ERROR_IN_OBJECT
			}
			break;

		case UG_JSON_ARRAY:
			switch (vchar) {
			case ' ':
			case '\t':
			case '\n':
			case '\r':
				continue;
//				break;

			case ',':
#ifdef IGNORE_ERROR_IN_SEPARATOR
				// if type is UG_JSON_VALUE or UG_JSON_SEPARATOR
				if (json->type >= UG_JSON_VALUE) {
					json->error = UG_JSON_ERROR_IN_SEPARATOR;
					json->type  = UG_JSON_SEPARATOR;
					json->state = UG_JSON_VALUE;
					continue;
//					break;
				}
#else
				// if type is UG_JSON_VALUE or UG_JSON_SEPARATOR
				if (json->type >= UG_JSON_VALUE)
					return UG_JSON_ERROR_IN_SEPARATOR;
#endif // IGNORE_ERROR_IN_SEPARATOR
				ug_json_call_parser (json);
				json->type  = UG_JSON_SEPARATOR;
				json->state = UG_JSON_VALUE;
				continue;
//				break;

			case ']':
#ifdef IGNORE_ERROR_IN_ARRAY
				if (json->type == UG_JSON_SEPARATOR) {
					json->error = UG_JSON_ERROR_IN_ARRAY;
					ug_json_pop (json);
					continue;
//					break;
				}
#else
				if (json->type == UG_JSON_SEPARATOR)
					return UG_JSON_ERROR_IN_ARRAY;
#endif // IGNORE_ERROR_IN_ARRAY
				ug_json_call_parser (json);
				ug_json_pop (json);
				continue;
//				break;

			default:
#ifdef IGNORE_ERROR_IN_ARRAY
				json->error = UG_JSON_ERROR_IN_ARRAY;
				continue;
//				break;
#else
				return UG_JSON_ERROR_IN_ARRAY;
#endif // IGNORE_ERROR_IN_ARRAY
			}
			break;

		case UG_JSON_STRING:
			switch (vchar) {
			case '\"':
				// null-terminated
				json->buf.at[json->buf.length++] = 0;
				json->state = json->scope;
				continue;
//				break;

			case '\\':
				json->state = UG_JSON_CONTROL;
				continue;
//				break;

			default:
				json->buf.at[json->buf.length++] = vchar;
				continue;
//				break;
			}
			break;

		case UG_JSON_CONTROL:
			json->state = UG_JSON_STRING;
			switch (vchar) {
			case '\"':
				json->buf.at[json->buf.length++] = '\"';
				continue;
//				break;
			case '\\':
				json->buf.at[json->buf.length++] = '\\';
				continue;
//				break;
			case '/':
				json->buf.at[json->buf.length++] = '/';
				continue;
//				break;
			case 'b':
				json->buf.at[json->buf.length++] = '\b';
				continue;
//				break;
			case 'f':
				json->buf.at[json->buf.length++] = '\f';
				continue;
//				break;
			case 'n':
				json->buf.at[json->buf.length++] = '\n';
				continue;
//				break;
			case 'r':
				json->buf.at[json->buf.length++] = '\r';
				continue;
//				break;
			case 't':
				json->buf.at[json->buf.length++] = '\t';
				continue;
//				break;
			case 'u':
				json->state = UG_JSON_UNICODE;
				json->count = 0;
				continue;
//				break;
			default:
				return UG_JSON_ERROR_INVALID_CONTROL;
			}
			break;

		case UG_JSON_UNICODE:
			// convert unicode UTF-16 to UTF-8
			json->buf.at[json->buf.length++] = vchar;
			if (++json->count == 4) {
				const char* putf;
				uint32_t    value;

				json->state = UG_JSON_STRING;
				json->buf.length -= 4;
//				json->count = 0;		// json->count must reset to 0
				// get UTF-16 value from hex string
				putf = json->buf.at + json->buf.length;
				for (value = 0;  json->count > 0;  json->count--, putf++) {
					value <<= 4;
					vchar = putf[0];
					if (vchar >= '0' && vchar <= '9')
						value += vchar - '0';
					else if (vchar >= 'a' && vchar <= 'f')
						value += vchar - 'a' + 10;
					else if (vchar >= 'A' && vchar <= 'F')
						value += vchar - 'A' + 10;
					else
						return UG_JSON_ERROR_INVALID_UNICODE;
				}

				if (value >= 1 && value <= 0x7F)
					json->buf.at[json->buf.length++] = value;
				else if (value > 0x7FF) {
					json->buf.at[json->buf.length++] = 0xE0 | ((value >> 12) & 0x0F);
					json->buf.at[json->buf.length++] = 0x80 | ((value >>  6) & 0x3F);
					json->buf.at[json->buf.length++] = 0x80 | ((value >>  0) & 0x3F);
				}
				else {
					json->buf.at[json->buf.length++] = 0xC0 | ((value >> 12) & 0x1F);
					json->buf.at[json->buf.length++] = 0x80 | ((value >>  6) & 0x3F);
				}
			}
			break;

		case UG_JSON_TRUE:
			json->buf.at[json->buf.length++] = vchar;
			if (++json->count == 4) {
				if (strncmp ("true", json->buf.at + json->buf.length - 4, 4))
					return UG_JSON_ERROR_INVALID_VALUE;
				json->type = UG_JSON_TRUE;
				json->state = json->scope;
				json->buf.at[json->buf.length++] = 0;	// null-terminated
			}
			break;

		case UG_JSON_FALSE:
			json->buf.at[json->buf.length++] = vchar;
			if (++json->count == 5) {
				if (strncmp ("false", json->buf.at + json->buf.length - 5, 5))
					return UG_JSON_ERROR_INVALID_VALUE;
				json->type = UG_JSON_FALSE;
				json->state = json->scope;
				json->buf.at[json->buf.length++] = 0;	// null-terminated
			}
			break;

		case UG_JSON_NULL:
			json->buf.at[json->buf.length++] = vchar;
			if (++json->count == 4) {
				if (strncmp ("null", json->buf.at + json->buf.length - 4, 4))
					return UG_JSON_ERROR_INVALID_VALUE;
				json->type = UG_JSON_NULL;
				json->state = json->scope;
				json->buf.at[json->buf.length++] = 0;	// null-terminated
			}
			break;

		case UG_JSON_NUMBER:
			switch (vchar) {
			case '.':
				if (json->numberPoint || json->numberEe || json->numberPm)
					return UG_JSON_ERROR_INVALID_NUMBER;
				json->numberPoint = 1;
				break;

			case 'E':
			case 'e':
				if (json->numberEe || json->numberPm)
					return UG_JSON_ERROR_INVALID_NUMBER;
				json->numberEe = 1;
				break;

			case '+':
			case '-':
				if (json->numberPm || json->numberEe == 0)
					return UG_JSON_ERROR_INVALID_NUMBER;
				json->numberPm = 1;
				break;

			default:
				if (vchar < '0' || vchar > '9') {
					json->state = json->scope;
					json->buf.at[json->buf.length++] = 0;
					goto TopLevelSwitch;
				}
				break;
			}
			json->buf.at[json->buf.length++] = vchar;
			break;

		default:
			return UG_JSON_ERROR_UNKNOWN;
		}
Esempio n. 5
0
INT_ ug3_qtria_pyramid_reset
 (INT_ mmsg,
  INT_ *nbface,
  INT_ nbfaced,
  INT_ nquad,
  INT_1D ** ibcibf_ptr,
  INT_1D ** idibf_ptr,
  INT_3D * inibf,
  INT_1D * iqibf,
  INT_1D ** irfibf_ptr)

{

/*
 * Reset quad-faces after mesh generation if the quad-faces were replaced with
 * pyramid elements and tria-faces.
 * 
 * UG3 LIB : Unstructured Grid - General Purpose Routine Library
 * 3D Version : $Id: ug3_qtria_pyramid_reset.c,v 1.5 2013/03/16 18:26:24 marcum Exp $
 * Copyright 1994-2012, David L. Marcum
 */

  CHAR_133 Text;

  INT_1D *ibcibf;
  INT_1D *idibf;
  INT_1D *irfibf;

  INT_ ierr, ibface, iquad, jbface, nbfacei, nbfacem;

  ibcibf = *ibcibf_ptr;
  idibf = *idibf_ptr;
  irfibf = *irfibf_ptr;

  if (mmsg == 2)
  {
    sprintf (Text, "Reset Pyramid-Quads: Quad-, Tria-BFaces=%10i%10i", nquad, *nbface);
    ug_message (Text);
  }

  nbfacei = *nbface;
  nbfacem = *nbface + nquad;

  // allocate space for new faces, nodes and pyramids

  if (nbfacem > nbfaced)
  {
    ierr = 0;

    *ibcibf_ptr = (INT_1D *) ug_realloc (&ierr, *ibcibf_ptr, (nbfacem+1) * sizeof (INT_1D));
    *idibf_ptr = (INT_1D *) ug_realloc (&ierr, *idibf_ptr, (nbfacem+1) * sizeof (INT_1D));
    *irfibf_ptr = (INT_1D *) ug_realloc (&ierr, *irfibf_ptr, (nbfacem+1) * sizeof (INT_1D));

    if (ierr > 0)
      return (100318);

    ibcibf = *ibcibf_ptr;
    idibf = *idibf_ptr;
    irfibf = *irfibf_ptr;
  }

  // save BC and ID flags for quad-faces

  for (ibface = 1; ibface <= *nbface; ++ibface)
  {
    iquad = -iqibf[ibface];

    if (iquad > 0)
    {
      ibcibf[*nbface+iquad] = ibcibf[ibface];
      idibf[*nbface+iquad] = idibf[ibface];
      irfibf[*nbface+iquad] = irfibf[ibface];
    }
  }

  // remove tria-faces created for pyramids

  jbface = 0;

  for (ibface = 1; ibface <= *nbface; ++ibface)
  {
    if (iqibf[ibface] >= 0)
    {
      ++jbface;

      inibf[jbface][0] = inibf[ibface][0];
      inibf[jbface][1] = inibf[ibface][1];
      inibf[jbface][2] = inibf[ibface][2];

      ibcibf[jbface] = ibcibf[ibface];
      idibf[jbface] = idibf[ibface];
      iqibf[jbface] = 0;
      irfibf[jbface] = irfibf[ibface];
    }
  }

  *nbface = jbface;

  // reorder BC and ID flags for quad-faces

  for (iquad = 1; iquad <= nquad; ++iquad)
  {
    ibcibf[*nbface+iquad] = ibcibf[nbfacei+iquad];
    idibf[*nbface+iquad] = idibf[nbfacei+iquad];
    irfibf[*nbface+iquad] = 0;
  }

  if (mmsg == 2)
  {
    sprintf (Text, "Reset Pyramid-Quads: Quad-, Tria-BFaces=%10i%10i", nquad, *nbface);
    ug_message (Text);
  }

  return (0);

}
Esempio n. 6
0
INT_ ug_io_read_stl
 (FILE * Grid_File,
  char Error_Message[],
  INT_ File_Format,
  INT_ Message_Flag,
  INT_ Read_Task_Flag,
  INT_ *Number_of_Nodes,
  INT_ *Number_of_Surf_Trias,
  INT_1D * Surf_ID_Flag,
  INT_3D * Surf_Tria_Connectivity,
  DOUBLE_3D * Coordinates)

{

/*
 * Read grid data from a Stereolithography (Standard Tessellation Language)
 * surface grid file.
 * 
 * UG_IO LIB : Unstructured Grid - Input/Output Routine Library
 * $Id: ug_io_read_stl.c,v 1.9 2012/08/23 04:01:49 marcum Exp $
 * Copyright 1994-2012, David L. Marcum
 */


  CHAR_UG_MAX Text;
  CHAR_UG_MAX Text_Line;
  char *Read_Label;
  char *tok;

  INT_ array_size, byte_count, delta_size, i, id, j, inode1, inode2, inode3,
       maxlevel, Error_Flag, Node_Index, Read_Flag, Surf_ID_Index, Surf_Tria_Index;
  
  double dc0, len1, len2, len3, tol;

  static double xmax, xmin, ymax, ymin, zmax, zmin;
  
  UG3_OCTREE_POINTLIST *pointlist_array = NULL;

  //DOUBLE_3D nv;

  DOUBLE_3X3 vertex;

  float TMP_float[3];

  UG3_OCTREE *octree = NULL;

  dc0 = 0.0;

  maxlevel = 2;

  Node_Index = 0;
  Surf_ID_Index = 0;
  Surf_Tria_Index = 0;

  if (Read_Task_Flag == 1)
  {
    xmin = dc0;
    xmax = dc0;
    ymin = dc0;
    ymax = dc0;
    zmin = dc0;
    zmax = dc0;
  }
  else
  {
    array_size = 0;
    delta_size = *Number_of_Nodes / 3 + ((*Number_of_Nodes % 3) > 0 ? 1 : 0);

    maxlevel = (INT_)(*Number_of_Nodes / 100000.0) + 1;
    maxlevel = MAX(2, MIN (5, maxlevel));
    octree = ug3_octree_allocatetree (xmin, xmax, ymin, ymax, zmin, zmax,
                                      0, maxlevel);
    if (octree == NULL)
    {
      strcpy (Error_Message, "Unable to create octree");
      return (1);
    }
  }

  if (File_Format == UG_IO_FORMATTED)
  {
    do
    {
      strcpy (Text_Line, "");
      Read_Label = fgets (Text_Line, UG_MAX_CHAR_STRING_LENGTH, Grid_File);

      if (Read_Label != NULL)
      {
        if (strstr (Text_Line, "solid") != NULL)
        {
          Surf_ID_Index++;
        }
        else if (strstr (Text_Line, "endsolid") != NULL)
        {
          continue;
        }
        else if (strstr (Text_Line, "facet normal") != NULL)
        {
          Surf_Tria_Index++;
/*
          if (Read_Task_Flag == 2)
          {
            tok = strtok (Text_Line, " ");

            tok = strtok (NULL, " ");
            tok = strtok (NULL, " ");
            nv[0] = strtod (tok, (char **) NULL);

            tok = strtok (NULL, " ");
            nv[1] = strtod (tok, (char **) NULL);

            tok = strtok (NULL, " ");
            nv[2] = strtod (tok, (char **) NULL);
          }
*/
        }
        else if (strstr (Text_Line, "outer loop") != NULL)
        {
          i = 0;
        }
        else if (strstr (Text_Line, "vertex") != NULL)
        {
          if (i > 2)
          {
            sprintf (Error_Message, "More than 3 vertices listed for triangle %d", Surf_Tria_Index);
            return (1);
          }

          tok = strtok (Text_Line," ");        

          tok = strtok (NULL," ");
          vertex[i][0] = strtod (tok, (char **) NULL);

          tok = strtok(NULL," ");
          vertex[i][1] = strtod (tok, (char **) NULL);

          tok = strtok(NULL," ");
          vertex[i][2] = strtod (tok, (char **) NULL);

          if (Read_Task_Flag == 1)
          {
            if (vertex[i][0] < xmin) xmin = vertex[i][0];
            if (vertex[i][0] > xmax) xmax = vertex[i][0];
            if (vertex[i][1] < ymin) ymin = vertex[i][1];
            if (vertex[i][1] > ymax) ymax = vertex[i][1];
            if (vertex[i][2] < zmin) zmin = vertex[i][2];
            if (vertex[i][2] > zmax) zmax = vertex[i][2];
          }
          else
          {
            if (i == 2)
            {
	      if (Node_Index >= array_size)
	      {
		Error_Flag = 0;
		array_size += delta_size;
                pointlist_array = (UG3_OCTREE_POINTLIST *) ug_realloc (&Error_Flag,
								       pointlist_array,
								       array_size * 
								       sizeof (UG3_OCTREE_POINTLIST));
		if (Error_Flag > 0)
		{
		  strcpy(Error_Message,"Unable to allocate octree pointlist.");
		  return(1);
		}
	      }

              len1 = STL_DISTANCE(vertex[0], vertex[1]);
              len2 = STL_DISTANCE(vertex[1], vertex[2]);
              len3 = STL_DISTANCE(vertex[2], vertex[0]);

              tol = STL_Rel_Tol * MIN(len1, MIN(len2, len3));

              for (j = 0; j < 3; j++)
              {
                id = ug3_octree_findclosestpoint (octree, tol, vertex[j], Coordinates);
                if (id < 1)
                {
                  id = ug3_octree_addpoint (octree, Node_Index+1, vertex[j],
					    &(pointlist_array[Node_Index]));

                  if (id < 1)
                  {
                    strcpy (Error_Message, "Unable to add point to octree");
                    ug3_octree_destroytree (octree);
                    ug_free (pointlist_array);
                    return (1);
                  }

                  Coordinates[id][0] = vertex[j][0];
                  Coordinates[id][1] = vertex[j][1];
                  Coordinates[id][2] = vertex[j][2];
		  Node_Index++;
                }

                Surf_Tria_Connectivity[Surf_Tria_Index][j] = id;
                Surf_ID_Flag[Surf_Tria_Index] = Surf_ID_Index;
              }
            }
          }
          i++;
        }
        else if (strstr (Text_Line, "endfacet") != NULL)
        {
          continue;
        }
        else if (strstr (Text_Line, "endloop") != NULL)
        {
          if (Read_Task_Flag == 2)
          {
            inode1 = Surf_Tria_Connectivity[Surf_Tria_Index][0];
            inode2 = Surf_Tria_Connectivity[Surf_Tria_Index][1];
            inode3 = Surf_Tria_Connectivity[Surf_Tria_Index][2];

            if (inode1 == inode2 || inode1 == inode3 || inode2 == inode3)
            {
              if (Message_Flag >= 1)
              {
                sprintf (Text, "UG_IO    : Skipped tria-face =%10i Duplicate Connectivity", Surf_Tria_Index);
                ug_message (Text);
              }
              Surf_Tria_Index--;
              continue;
            }
          }
        }
      }
    }
    while (Read_Label != NULL);
  }
  else if (File_Format == UG_IO_BINARY_SINGLE)
  {
    Read_Flag = ug_fread (Text_Line, sizeof (char), 80, Grid_File);
    if (Read_Flag != 80)
    {
      strcpy (Error_Message, "error reading STL grid file");
      return (1);
    }

    Read_Flag = ug_fread (&Surf_Tria_Index, sizeof (unsigned int), 1, Grid_File);
    if (Read_Flag != 1)
    {
      strcpy (Error_Message, "error reading STL grid file");
      return (1);
    }

    for (i = 0; i < Surf_Tria_Index; i++)
    {
      Read_Flag = 0;

      Read_Flag = Read_Flag 
                + ug_fread (&TMP_float, sizeof (float), 3, Grid_File);
/*
      nv[0] = (double) TMP_float[0];
      nv[1] = (double) TMP_float[1];
      nv[2] = (double) TMP_float[2];
*/

      for (j = 0; j < 3; j++)
      {
        Read_Flag = Read_Flag 
                  + ug_fread (&TMP_float, sizeof (float), 3, Grid_File);

        vertex[j][0] = (double) TMP_float[0];
        vertex[j][1] = (double) TMP_float[1];
        vertex[j][2] = (double) TMP_float[2];
      }

      if (Read_Task_Flag == 1)
      {
        for (j = 0; j < 3; j++)
        {
          if (vertex[j][0] < xmin) xmin = vertex[j][0];
          if (vertex[j][0] > xmax) xmax = vertex[j][0];
          if (vertex[j][1] < ymin) ymin = vertex[j][1];
          if (vertex[j][1] > ymax) ymax = vertex[j][1];
          if (vertex[j][2] < zmin) zmin = vertex[j][2];
          if (vertex[j][2] > zmax) zmax = vertex[j][2];
        }
      }
      else
      {
        for (j = 0; j < 3; j++)
        {
          if (j == 0)
          {
            len1 = STL_DISTANCE(vertex[1], vertex[0]);
            len2 = STL_DISTANCE(vertex[2], vertex[0]);
          }
          else if (j == 1)
          {
            len1 = STL_DISTANCE(vertex[0], vertex[1]);
            len2 = STL_DISTANCE(vertex[2], vertex[1]);
          }
          else
          {
            len1 = STL_DISTANCE(vertex[0], vertex[2]);
            len2 = STL_DISTANCE(vertex[1], vertex[2]);
          }

          tol = STL_Rel_Tol * MIN(len1, len2);

          id = ug3_octree_findclosestpoint (octree, tol, vertex[j], Coordinates);
          if (id < 1)
          {
	    if (Node_Index >= array_size)
	    {
	      Error_Flag = 0;
	      array_size += delta_size;
	      pointlist_array = (UG3_OCTREE_POINTLIST *) ug_realloc (&Error_Flag,
								     pointlist_array,
								     array_size * 
								     sizeof (UG3_OCTREE_POINTLIST));
	      if (Error_Flag > 0)
	      {
		strcpy(Error_Message,"Unable to allocate octree pointlist.");
		return(1);
	      }
	    }

            id = ug3_octree_addpoint (octree, Node_Index+1, vertex[j],
                                      &(pointlist_array[Node_Index]));
            if (id < 1)
            {
              strcpy (Error_Message, "Unable to insert point into BSP tree");
              ug3_octree_destroytree (octree);
              ug_free (pointlist_array);
              return (1);
            }

            Coordinates[id][0] = vertex[j][0];
            Coordinates[id][1] = vertex[j][1];
            Coordinates[id][2] = vertex[j][2];
            Node_Index++;
          }

          Surf_Tria_Connectivity[i + 1][j] = id;
          Surf_ID_Flag[i + 1] = 1;
        }

        Read_Flag = Read_Flag 
                  + ug_fread (&byte_count, sizeof (unsigned short int), 1, Grid_File);

        if (Read_Flag != 13)
        {
          strcpy (Error_Message, "error reading STL grid file");
          ug3_octree_destroytree (octree);
          ug_free (pointlist_array);
          return (1);
        }

        inode1 = Surf_Tria_Connectivity[i + 1][0];
        inode2 = Surf_Tria_Connectivity[i + 1][1];
        inode3 = Surf_Tria_Connectivity[i + 1][2];

        if (inode1 == inode2 || inode1 == inode3 || inode2 == inode3)
        {
          sprintf (Error_Message, "Duplicate connectivity for Triangle %d", i + 1);
          ug3_octree_destroytree (octree);
          ug_free (pointlist_array);
          return (1);
        }
      }
    }
  }
  else
  {
    strcpy (Error_Message, "Only formatted ASCII or binary float formats are supported for STL files");
    *Number_of_Surf_Trias = 0;
    *Number_of_Nodes = 3 * 0;
    return (1);
  }

  if (Read_Task_Flag == 1)
  {
    *Number_of_Surf_Trias = Surf_Tria_Index;
    *Number_of_Nodes = 3 * Surf_Tria_Index;
  }
  else if (Read_Task_Flag == 2)
  {
    *Number_of_Surf_Trias = Surf_Tria_Index;
    *Number_of_Nodes = Node_Index;
    ug3_octree_destroytree (octree);
    ug_free (pointlist_array);
  }

  return (0);
}
Esempio n. 7
0
INT_ ug3_read_ugrid_grid_file
 (char File_Name[],
  INT_ File_Format_Flag,
  INT_ Read_Task_Flag,
  INT_ *Number_of_BL_Vol_Tets,
  INT_ *Number_of_Nodes,
  INT_ *Number_of_Surf_Quads,
  INT_ *Number_of_Surf_Trias,
  INT_ *Number_of_Vol_Hexs,
  INT_ *Number_of_Vol_Pents_5,
  INT_ *Number_of_Vol_Pents_6,
  INT_ *Number_of_Vol_Tets,
  INT_ Number_of_Read_Nodes,
  INT_ Number_of_Read_Vol_Hexs,
  INT_ Number_of_Read_Vol_Pents_5,
  INT_ Number_of_Read_Vol_Pents_6,
  INT_ Number_of_Read_Vol_Tets,
  INT_1D * Surf_ID_Flag,
  INT_4D * Surf_Quad_Connectivity,
  INT_3D * Surf_Tria_Connectivity,
  INT_8D ** Vol_Hex_Connectivity_Ptr,
  INT_5D ** Vol_Pent_5_Connectivity_Ptr,
  INT_6D ** Vol_Pent_6_Connectivity_Ptr,
  INT_4D ** Vol_Tet_Connectivity_Ptr,
  DOUBLE_3D ** Coordinates_Ptr)

{

/*
 * Incrementally read grid data from a UGRID volume grid file.
 *
 * If Read_Task_Flag = 1 then open the grid file and read number of nodes,
 * boundary faces, and elements.
 *
 * If Read_Task_Flag = 2 then read everything after number of nodes, boundary
 * faces, and elements (see Read_Task_Flag = -2,-3,...,-8) and then close or
 * rewind the grid file.
 *
 * If Read_Task_Flag = 3 then open the grid file, reallocate arrays, read
 * everything (see Read_Task_Flag = -1,-2,-3,...,-8) and then close or rewind
 * the grid file.
 *
 * If Read_Task_Flag = -1 then open the grid file and read number of nodes,
 * boundary faces, and elements.
 *
 * If Read_Task_Flag = -2 then incrementally read node coordinates
 * (Number_of_Read_Nodes at a time).
 *
 * If Read_Task_Flag = -3 then read boundary face connectivity and flags
 *
 * If Read_Task_Flag = -4 then incrementally read tet element connectivity
 * (Number_of_Read_Read_Vol_Tets at a time).
 *
 * If Read_Task_Flag = -5 then incrementally read pyramid (pent-5) element
 * connectivity (Number_of_Read_Vol_Pents_5 at a time).
 *
 * If Read_Task_Flag = -6 then incrementally read prism (pent-6) element
 * connectivity (Number_of_Read_Vol_Pents_6 at a time).
 *
 * If Read_Task_Flag = -7 then incrementally read hex element connectivity
 * (Number_of_Read_Vol_Hexs at a time).
 *
 * If Read_Task_Flag = -8 then read number of BL tet elements
 *
 * If Read_Task_Flag = -9 then close or rewind the grid file
 * 
 * UG_IO LIB : Unstructured Grid - Input/Output Routine Library
 * $Id: ug3_read_ugrid_grid_file.c,v 1.33 2013/03/19 04:35:44 marcum Exp $
 * Copyright 1994-2012, David L. Marcum
 */

  static FILE *Grid_File = NULL;

  CHAR_UG_MAX drive, dname, fname, ext;

  CHAR_133 Text;
  CHAR_31 Name_Text;

  INT_8D *Vol_Hex_Connectivity = NULL;
  INT_5D *Vol_Pent_5_Connectivity = NULL;
  INT_6D *Vol_Pent_6_Connectivity = NULL;
  INT_4D *Vol_Tet_Connectivity = NULL;
  DOUBLE_3D *Coordinates = NULL;

  INT_ Byte_Order, Error_Flag, Index, Mode_Flag, Number_of_Surf_Faces,
       Read_Flag, TMP_int, TMP_int1, TMP_int2, TMP_int3, TMP_int4, TMP_int5,
       TMP_int6, TMP_int7, TMP_int8;

  if (ug_file_status_monitor_flag())
  {
    ug_splitpath (File_Name, drive, dname, fname, ext);

    strcat (fname, ext);
    strcpy (Name_Text, "");
    strncat (Name_Text, fname, 29);

    sprintf (Text, "ug3_read_ugrid_grid_file : reading UGRID file with File_Name=%s File_Format_Flag=%i Read_Task_Flag=%i", Name_Text, File_Format_Flag, Read_Task_Flag);
    ug_message (Text);
  }

  Byte_Order = ug_get_byte_order ();
  
  Byte_Order = (File_Format_Flag == 2) ? 1:
               (File_Format_Flag == 3) ? -1: ug_get_byte_order ();

  ug_set_byte_order (Byte_Order);

  if (Read_Task_Flag == 1 || Read_Task_Flag == -1 || Read_Task_Flag == 3)
  {
    if (File_Format_Flag == 0 && Byte_Order > 0)
      strcat (File_Name, ".tmp.b8.ugrid");
    else if (File_Format_Flag == 0 && Byte_Order < 0)
      strcat (File_Name, ".tmp.lb8.ugrid");
    else if (File_Format_Flag == 1)
      strcat (File_Name, ".ugrid");
    else if (File_Format_Flag == 2)
      strcat (File_Name, ".b8.ugrid");
    else
      strcat (File_Name, ".lb8.ugrid");

    ug_splitpath (File_Name, drive, dname, fname, ext);

    strcat (fname, ext);

    if (File_Format_Flag == 0)
    {
      strcat (fname, "+");
      strcpy (File_Name, fname);
    }

    strcpy (Name_Text, "");
    strncat (Name_Text, fname, 29);

    if (File_Format_Flag == 0)
    {
      if (ug_file_status_monitor_flag())
      {
        sprintf (Text, "ug3_read_ugrid_grid_file : opening TMP file with name %s", Name_Text);
        ug_message (Text);
      }

      Grid_File = ug_fopen (File_Name, "r_tmp");
    }

    else
    {
      if (ug_file_status_monitor_flag())
      {
        sprintf (Text, "ug3_read_ugrid_grid_file : opening regular file with name %s", Name_Text);
        ug_message (Text);
      }

      Grid_File = ug_fopen (File_Name, "r");
    }

    if (Grid_File == NULL)
      return (338);

    if (File_Format_Flag == 1)
    {
      Read_Flag = fscanf (Grid_File, "%i %i %i %i %i %i %i",
                          Number_of_Nodes,
                          Number_of_Surf_Trias,
                          Number_of_Surf_Quads,
                          Number_of_Vol_Tets,
                          Number_of_Vol_Pents_5,
                          Number_of_Vol_Pents_6,
                          Number_of_Vol_Hexs);
    }
    else
    {
      Read_Flag = 0;
      Read_Flag = Read_Flag + ug_fread (Number_of_Nodes,
                                        sizeof (INT_), 1, Grid_File);
      Read_Flag = Read_Flag + ug_fread (Number_of_Surf_Trias,
                                        sizeof (INT_), 1, Grid_File);
      Read_Flag = Read_Flag + ug_fread (Number_of_Surf_Quads,
                                        sizeof (INT_), 1, Grid_File);
      Read_Flag = Read_Flag + ug_fread (Number_of_Vol_Tets,
                                        sizeof (INT_), 1, Grid_File);
      Read_Flag = Read_Flag + ug_fread (Number_of_Vol_Pents_5,
                                        sizeof (INT_), 1, Grid_File);
      Read_Flag = Read_Flag + ug_fread (Number_of_Vol_Pents_6,
                                        sizeof (INT_), 1, Grid_File);
      Read_Flag = Read_Flag + ug_fread (Number_of_Vol_Hexs,
                                        sizeof (INT_), 1, Grid_File);
      Read_Flag = Read_Flag - 7;
    }

    if (Read_Flag < 0)
    {
      ug_fclose (Grid_File);
      return (338);
    }
  }

  if (Read_Task_Flag == 3)
  {
    Error_Flag = 0;

    if (*Number_of_Vol_Hexs > 0)
      *Vol_Hex_Connectivity_Ptr = (INT_8D *) ug_realloc (&Error_Flag,
                                 *Vol_Hex_Connectivity_Ptr,
                                 (*Number_of_Vol_Hexs+1) * sizeof (INT_8D));

    if (*Number_of_Vol_Pents_5 > 0)
      *Vol_Pent_5_Connectivity_Ptr = (INT_5D *) ug_realloc (&Error_Flag,
                                 *Vol_Pent_5_Connectivity_Ptr,
                                 (*Number_of_Vol_Pents_5+1) * sizeof (INT_5D));

    if (*Number_of_Vol_Pents_6 > 0)
      *Vol_Pent_6_Connectivity_Ptr = (INT_6D *) ug_realloc (&Error_Flag,
                                 *Vol_Pent_6_Connectivity_Ptr,
                                 (*Number_of_Vol_Pents_6+1) * sizeof (INT_6D));

    if (*Number_of_Vol_Tets > 0)
      *Vol_Tet_Connectivity_Ptr = (INT_4D *) ug_realloc (&Error_Flag,
                                 *Vol_Tet_Connectivity_Ptr,
                                 (*Number_of_Vol_Tets+1) * sizeof (INT_4D));

    if (*Number_of_Nodes > 0)
      *Coordinates_Ptr = (DOUBLE_3D *) ug_realloc (&Error_Flag,
                                 *Coordinates_Ptr,
                                 (*Number_of_Nodes+1) * sizeof (DOUBLE_3D));

    if (Error_Flag > 0)
    {
      ug_fclose (Grid_File);
      return (100305);
    }
  }

  if (Read_Task_Flag == 2 || Read_Task_Flag == -2 || Read_Task_Flag == 3)
  {
    if (Grid_File == NULL)
      return (338);

    Coordinates = *Coordinates_Ptr;

    if (Read_Task_Flag >= 2)
      Number_of_Read_Nodes = *Number_of_Nodes;

    if (File_Format_Flag == 1)
    {
      for (Index = 1; Index <= Number_of_Read_Nodes; ++Index)
      {
        Read_Flag = fscanf (Grid_File, "%lg", &Coordinates[Index][0]);
        Read_Flag = fscanf (Grid_File, "%lg", &Coordinates[Index][1]);
        Read_Flag = fscanf (Grid_File, "%lg", &Coordinates[Index][2]);
                           
      }
    }
    else
    {
      Read_Flag = ug_fread (&Coordinates[1][0],
                            sizeof (double), Number_of_Read_Nodes*3,
                            Grid_File);
      Read_Flag = Read_Flag - Number_of_Read_Nodes*3;
    }

    if (Read_Flag < 0)
    {
      ug_fclose (Grid_File);
      return (338);
    }
  }

  if (Read_Task_Flag == 2 || Read_Task_Flag == -3 || Read_Task_Flag == 3)
  {
    if (Grid_File == NULL)
      return (338);

    if (File_Format_Flag == 1)
    {
      for (Index = 1; Index <= *Number_of_Surf_Trias; ++Index)
      {
        Read_Flag = fscanf (Grid_File, "%i", &TMP_int1);
        Read_Flag = fscanf (Grid_File, "%i", &TMP_int2);
        Read_Flag = fscanf (Grid_File, "%i", &TMP_int3);

        if (Surf_Tria_Connectivity != NULL)
        {
          Surf_Tria_Connectivity[Index][0] = TMP_int1;
          Surf_Tria_Connectivity[Index][1] = TMP_int2;
          Surf_Tria_Connectivity[Index][2] = TMP_int3;
        }
      }
    }
    else
    {
      if (*Number_of_Surf_Trias > 0 && Surf_Tria_Connectivity != NULL)
        Read_Flag = ug_fread (&Surf_Tria_Connectivity[1][0],
                              sizeof (INT_), *Number_of_Surf_Trias*3,
                              Grid_File);
      else
      {
        Read_Flag = 0;

        for (Index = 1; Index <= *Number_of_Surf_Trias*3; ++Index)
        {
          Read_Flag = Read_Flag + ug_fread (&TMP_int,
                                            sizeof (INT_), 1, Grid_File);
        }
      }

      Read_Flag = Read_Flag - *Number_of_Surf_Trias*3;
    }

    if (Read_Flag < 0)
    {
      ug_fclose (Grid_File);
      return (338);
    }

    if (File_Format_Flag == 1)
    {
      for (Index = 1; Index <= *Number_of_Surf_Quads; ++Index)
      {
        Read_Flag = fscanf (Grid_File, "%i", &TMP_int1);
        Read_Flag = fscanf (Grid_File, "%i", &TMP_int2);
        Read_Flag = fscanf (Grid_File, "%i", &TMP_int3);
        Read_Flag = fscanf (Grid_File, "%i", &TMP_int4);

        if (Surf_Quad_Connectivity != NULL)
        {
          Surf_Quad_Connectivity[Index][0] = TMP_int1;
          Surf_Quad_Connectivity[Index][1] = TMP_int2;
          Surf_Quad_Connectivity[Index][2] = TMP_int3;
          Surf_Quad_Connectivity[Index][3] = TMP_int4;
        }
      }
    }
    else
    {
      if (*Number_of_Surf_Quads > 0 && Surf_Quad_Connectivity != NULL)
        Read_Flag = ug_fread (&Surf_Quad_Connectivity[1][0],
                              sizeof (INT_), *Number_of_Surf_Quads*4,
                              Grid_File);
      else
      {
        Read_Flag = 0;

        for (Index = 1; Index <= *Number_of_Surf_Quads*4; ++Index)
        {
          Read_Flag = Read_Flag + ug_fread (&TMP_int,
                                            sizeof (INT_), 1, Grid_File);
        }
      }

      Read_Flag = Read_Flag - *Number_of_Surf_Quads*4;
    }

    if (Read_Flag < 0)
    {
      ug_fclose (Grid_File);
      return (338);
    }

    Number_of_Surf_Faces = *Number_of_Surf_Trias + *Number_of_Surf_Quads;

    if (File_Format_Flag == 1)
    {
      for (Index = 1; Index <= Number_of_Surf_Faces; ++Index)
      {
        Read_Flag = fscanf (Grid_File, "%i", &TMP_int);

        if (Surf_ID_Flag != NULL)
        {
          Surf_ID_Flag[Index] = TMP_int;
        }
      }
    }
    else
    {
      if (Number_of_Surf_Faces > 0 && Surf_ID_Flag != NULL)
        Read_Flag = ug_fread (&Surf_ID_Flag[1],
                              sizeof (INT_1D), Number_of_Surf_Faces,
                              Grid_File);
      else
      {
        Read_Flag = 0;

        for (Index = 1; Index <= Number_of_Surf_Faces; ++Index)
        {
          Read_Flag = Read_Flag + ug_fread (&TMP_int,
                                            sizeof (INT_), 1, Grid_File);
        }
      }

      Read_Flag = Read_Flag - Number_of_Surf_Faces;
    }

    if (Read_Flag < 0)
    {
      ug_fclose (Grid_File);
      return (338);
    }
  }

  if (Read_Task_Flag == 2 || Read_Task_Flag == -4 || Read_Task_Flag == 3)
  {
    if (Grid_File == NULL)
      return (338);

    Vol_Tet_Connectivity = *Vol_Tet_Connectivity_Ptr;

    if (Read_Task_Flag >= 2)
      Number_of_Read_Vol_Tets = *Number_of_Vol_Tets;

    if (File_Format_Flag == 1)
    {
      for (Index = 1; Index <= Number_of_Read_Vol_Tets; ++Index)
      {
        Read_Flag = fscanf (Grid_File, "%i", &TMP_int1);
        Read_Flag = fscanf (Grid_File, "%i", &TMP_int2);
        Read_Flag = fscanf (Grid_File, "%i", &TMP_int3);
        Read_Flag = fscanf (Grid_File, "%i", &TMP_int4);

        if (Vol_Tet_Connectivity != NULL)
        {
          Vol_Tet_Connectivity[Index][0] = TMP_int1;
          Vol_Tet_Connectivity[Index][1] = TMP_int2;
          Vol_Tet_Connectivity[Index][2] = TMP_int3;
          Vol_Tet_Connectivity[Index][3] = TMP_int4;
        }
      }
    }
    else
    {
      if (Number_of_Read_Vol_Tets > 0 && Vol_Tet_Connectivity != NULL)
        Read_Flag = ug_fread (&Vol_Tet_Connectivity[1][0],
                              sizeof (INT_), Number_of_Read_Vol_Tets*4,
                              Grid_File);
      else
      {
        Read_Flag = 0;

        for (Index = 1; Index <= Number_of_Read_Vol_Tets*4; ++Index)
        {
          Read_Flag = Read_Flag + ug_fread (&TMP_int,
                                            sizeof (INT_), 1, Grid_File);
        }
      }

      Read_Flag = Read_Flag - Number_of_Read_Vol_Tets*4;
    }

    if (Read_Flag < 0)
    {
      ug_fclose (Grid_File);
      return (338);
    }
  }

  if (Read_Task_Flag == 2 || Read_Task_Flag == -5 || Read_Task_Flag == 3)
  {
    if (Grid_File == NULL)
      return (338);

    Vol_Pent_5_Connectivity = *Vol_Pent_5_Connectivity_Ptr;

    if (Read_Task_Flag >= 2)
      Number_of_Read_Vol_Pents_5 = *Number_of_Vol_Pents_5;

    if (File_Format_Flag == 1)
    {
      for (Index = 1; Index <= Number_of_Read_Vol_Pents_5; ++Index)
      {
        Read_Flag = fscanf (Grid_File, "%i", &TMP_int1);
        Read_Flag = fscanf (Grid_File, "%i", &TMP_int2);
        Read_Flag = fscanf (Grid_File, "%i", &TMP_int3);
        Read_Flag = fscanf (Grid_File, "%i", &TMP_int4);
        Read_Flag = fscanf (Grid_File, "%i", &TMP_int5);

        if (Vol_Pent_5_Connectivity != NULL)
        {
          Vol_Pent_5_Connectivity[Index][0] = TMP_int1;
          Vol_Pent_5_Connectivity[Index][1] = TMP_int2;
          Vol_Pent_5_Connectivity[Index][2] = TMP_int3;
          Vol_Pent_5_Connectivity[Index][3] = TMP_int4;
          Vol_Pent_5_Connectivity[Index][4] = TMP_int5;
        }
      }
    }
    else
    {
      if (Number_of_Read_Vol_Pents_5 > 0 && Vol_Pent_5_Connectivity != NULL)
        Read_Flag = ug_fread (&Vol_Pent_5_Connectivity[1][0],
                              sizeof (INT_), Number_of_Read_Vol_Pents_5*5,
                              Grid_File);
      else
      {
        Read_Flag = 0;

        for (Index = 1; Index <= Number_of_Read_Vol_Pents_5*5; ++Index)
        {
          Read_Flag = Read_Flag + ug_fread (&TMP_int,
                                            sizeof (INT_), 1, Grid_File);
        }
      }

      Read_Flag = Read_Flag - Number_of_Read_Vol_Pents_5*5;
    }

    if (Read_Flag < 0)
    {
      ug_fclose (Grid_File);
      return (338);
    }
  }

  if (Read_Task_Flag == 2 || Read_Task_Flag == -6 || Read_Task_Flag == 3)
  {
    if (Grid_File == NULL)
      return (338);

    Vol_Pent_6_Connectivity = *Vol_Pent_6_Connectivity_Ptr;

    if (Read_Task_Flag >= 2)
      Number_of_Read_Vol_Pents_6 = *Number_of_Vol_Pents_6;

    if (File_Format_Flag == 1)
    {
      for (Index = 1; Index <= Number_of_Read_Vol_Pents_6; ++Index)
      {
        Read_Flag = fscanf (Grid_File, "%i", &TMP_int1);
        Read_Flag = fscanf (Grid_File, "%i", &TMP_int2);
        Read_Flag = fscanf (Grid_File, "%i", &TMP_int3);
        Read_Flag = fscanf (Grid_File, "%i", &TMP_int4);
        Read_Flag = fscanf (Grid_File, "%i", &TMP_int5);
        Read_Flag = fscanf (Grid_File, "%i", &TMP_int6);

        if (Vol_Pent_6_Connectivity != NULL)
        {
          Vol_Pent_6_Connectivity[Index][0] = TMP_int1;
          Vol_Pent_6_Connectivity[Index][1] = TMP_int2;
          Vol_Pent_6_Connectivity[Index][2] = TMP_int3;
          Vol_Pent_6_Connectivity[Index][3] = TMP_int4;
          Vol_Pent_6_Connectivity[Index][4] = TMP_int5;
          Vol_Pent_6_Connectivity[Index][5] = TMP_int6;
        }
      }
    }
    else
    {
      if (Number_of_Read_Vol_Pents_6 > 0 && Vol_Pent_6_Connectivity != NULL)
        Read_Flag = ug_fread (&Vol_Pent_6_Connectivity[1][0],
                              sizeof (INT_), Number_of_Read_Vol_Pents_6*6,
                              Grid_File);
      else
      {
        Read_Flag = 0;

        for (Index = 1; Index <= Number_of_Read_Vol_Pents_6*6; ++Index)
        {
          Read_Flag = Read_Flag + ug_fread (&TMP_int,
                                            sizeof (INT_), 1, Grid_File);
        }
      }

      Read_Flag = Read_Flag - Number_of_Read_Vol_Pents_6*6;
    }

    if (Read_Flag < 0)
    {
      ug_fclose (Grid_File);
      return (338);
    }
  }

  if (Read_Task_Flag == 2 || Read_Task_Flag == -7 || Read_Task_Flag == 3)
  {
    if (Grid_File == NULL)
      return (338);

    Vol_Hex_Connectivity = *Vol_Hex_Connectivity_Ptr;

    if (Read_Task_Flag >= 2)
      Number_of_Read_Vol_Hexs = *Number_of_Vol_Hexs;

    if (File_Format_Flag == 1)
    {
      for (Index = 1; Index <= Number_of_Read_Vol_Hexs; ++Index)
      {
        Read_Flag = fscanf (Grid_File, "%i", &TMP_int1);
        Read_Flag = fscanf (Grid_File, "%i", &TMP_int2);
        Read_Flag = fscanf (Grid_File, "%i", &TMP_int3);
        Read_Flag = fscanf (Grid_File, "%i", &TMP_int4);
        Read_Flag = fscanf (Grid_File, "%i", &TMP_int5);
        Read_Flag = fscanf (Grid_File, "%i", &TMP_int6);
        Read_Flag = fscanf (Grid_File, "%i", &TMP_int7);
        Read_Flag = fscanf (Grid_File, "%i", &TMP_int8);

        if (Vol_Hex_Connectivity != NULL)
        {
          Vol_Hex_Connectivity[Index][0] = TMP_int1;
          Vol_Hex_Connectivity[Index][1] = TMP_int2;
          Vol_Hex_Connectivity[Index][2] = TMP_int3;
          Vol_Hex_Connectivity[Index][3] = TMP_int4;
          Vol_Hex_Connectivity[Index][4] = TMP_int5;
          Vol_Hex_Connectivity[Index][5] = TMP_int6;
          Vol_Hex_Connectivity[Index][6] = TMP_int7;
          Vol_Hex_Connectivity[Index][7] = TMP_int8;
        }
      }
    }
    else
    {
      if (Number_of_Read_Vol_Hexs > 0 && Vol_Hex_Connectivity != NULL)
        Read_Flag = ug_fread (&Vol_Hex_Connectivity[1][0],
                              sizeof (INT_), Number_of_Read_Vol_Hexs*8,
                              Grid_File);
      else
      {
        Read_Flag = 0;

        for (Index = 1; Index <= Number_of_Read_Vol_Hexs*8; ++Index)
        {
          Read_Flag = Read_Flag + ug_fread (&TMP_int,
                                            sizeof (INT_), 1, Grid_File);
        }
      }

      Read_Flag = Read_Flag - Number_of_Read_Vol_Hexs*8;
    }

    if (Read_Flag < 0)
    {
      ug_fclose (Grid_File);
      return (338);
    }
  }

  if (Read_Task_Flag == 2 || Read_Task_Flag == -8 || Read_Task_Flag == 3)
  {
    if (Grid_File == NULL)
      return (338);

    *Number_of_BL_Vol_Tets = 0;

    if (File_Format_Flag == 1)
      Read_Flag = fscanf (Grid_File, "%i", Number_of_BL_Vol_Tets);
    else
      Read_Flag = ug_fread (Number_of_BL_Vol_Tets,
                            sizeof (INT_), 1, Grid_File);
  }

  if (Read_Task_Flag == 2 || Read_Task_Flag == -9 || Read_Task_Flag == 3)
  {
    if (Grid_File == NULL)
      return (338);

    Mode_Flag = ug_get_file_stream_mode_flag (Grid_File);

    if (Mode_Flag == UG_FIO_TMP_FILE_MODE)
      ug_rewind (Grid_File);
    else
      ug_fclose (Grid_File);
  }

  return (0);

}