void ug_rewind_data (char File_Name[]) { /* * Rewind a binary TMP file by file name. */ FILE *File_Stream = NULL; if (File_Status_Monitor) { sprintf (Text, "ug_rewind_data : rewinding TMP file with associated name %s", File_Name); ug_message (Text); } File_Stream = ug_fopen (File_Name, "r_tmp"); if (File_Stream) { ug_rewind (File_Stream); if (File_Status_Monitor) { sprintf (Text, "ug_rewind_data : rewound TMP file with associated name %s", File_Name); ug_message (Text); } } return; }
int ug_file_get_lines (const char* filename_utf8, UgList* list) { UgLink* link; FILE* file; char* buf; int len; int count = 0; file = ug_fopen (filename_utf8, "r"); if (file == NULL) return 0; buf = ug_malloc (8192); if (fread (buf, 1, 3, file) == 3) { // UTF-8 byte-order mark: 0xEF, 0xBB, 0xBF if ((unsigned char)buf[0] != 0xEF || (unsigned char)buf[1] != 0xBB) rewind (file); } while (fgets (buf, 8192, file) != NULL) { count++; len = strlen (buf); if (len > 0 && buf[len-1] == '\n') buf[--len] = 0; if (list) { link = ug_link_new (); link->data = ug_strndup (buf, len); ug_list_append (list, link); } } ug_free (buf); fclose (file); return count; }
int uget_curl_open_file (UgetCurl* ugcurl, const char* file_path) { FILE* output_file; if (ugcurl->file.output) return TRUE; if (file_path) { output_file = ug_fopen (file_path, "rb+"); if (output_file == NULL) return FALSE; ugcurl->file.output = output_file; } return TRUE; }
int uget_curl_set_http (UgetCurl* ugcurl, UgetHttp* http) { CURL* curl; curl = ugcurl->curl; ugcurl->http = http; curl_easy_setopt (curl, CURLOPT_FOLLOWLOCATION, 1L); curl_easy_setopt (curl, CURLOPT_AUTOREFERER, 1L); curl_easy_setopt (curl, CURLOPT_MAXREDIRS, 30L); if (http) { // if (http->referrer == NULL && ugcurl->uri.part.fragment != -1) { // http->referrer = ug_strndup (temp.common->uri, // ugcurl->uri.part.fragment); // } curl_easy_setopt (curl, CURLOPT_REFERER, http->referrer); // if (http->redirection_limit) curl_easy_setopt (curl, CURLOPT_MAXREDIRS, http->redirection_limit); if (http->user_agent) curl_easy_setopt (curl, CURLOPT_USERAGENT, http->user_agent); // else { // curl_easy_setopt (curl, CURLOPT_USERAGENT, // "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)"); // curl_easy_setopt (curl, CURLOPT_USERAGENT, // "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1;" // " .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)"); // } // cookie if (http->cookie_data) curl_easy_setopt (curl, CURLOPT_COOKIE, http->cookie_data); else if (http->cookie_file) curl_easy_setopt (curl, CURLOPT_COOKIEFILE, http->cookie_file); else curl_easy_setopt (curl, CURLOPT_COOKIEFILE, ""); if (http->post_data) { curl_easy_setopt (curl, CURLOPT_POST, 1L); curl_easy_setopt (curl, CURLOPT_POSTFIELDS, http->post_data); curl_easy_setopt (curl, CURLOPT_POSTFIELDSIZE, strlen (http->post_data)); } else if (http->post_file) { ugcurl->file.post = ug_fopen (http->post_file, "r"); if (ugcurl->file.post == NULL) return FALSE; curl_easy_setopt (curl, CURLOPT_POST, 1L); curl_easy_setopt (curl, CURLOPT_READDATA, ugcurl->file.post); #if defined(_MSC_VER) && !defined(__MINGW32__) // for MS VC only curl_easy_setopt (curl, CURLOPT_READFUNCTION , fread); #endif } } // I don't set http->user & http->password here because // uget_curl_decide_login() will decide to use one of below login data // common->user & common->password // http->user & http->password // ftp->user & ftp->password return TRUE; }
INT_ ug3_read_surf_grid_file (char File_Name[], INT_ Read_Task_Flag, INT_ *Number_of_Nodes, INT_ *Number_of_Surf_Quads, INT_ *Number_of_Surf_Trias, INT_1D * Surf_Grid_BC_Flag, INT_1D * Surf_ID_Flag, INT_4D * Surf_Quad_Connectivity, INT_1D * Surf_Reconnection_Flag, INT_3D * Surf_Tria_Connectivity, DOUBLE_3D * Coordinates) { /* * Read grid data from a SURF surface grid file. * * UG3 LIB : Unstructured Grid - General Purpose Routine Library * 3D Version : $Id: ug3_read_surf_grid_file.c,v 1.13 2013/03/16 18:26:24 marcum Exp $ * Copyright 1994-2012, David L. Marcum */ CHAR_UG_MAX drive, dname, fname, ext; CHAR_133 Text; CHAR_31 Name_Text; FILE *Grid_File; INT_ Node_Index, Read_Flag, Surf_Grid_BC_Flag_, Surf_ID_Flag_, Surf_Index, Surf_Quad_Index, Surf_Reconnection_Flag_, Surf_Tria_Index, Try; double BL_Thickness_, Initial_Normal_Spacing_; if (Read_Task_Flag == 1) strcat (File_Name, ".surf"); 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_surf_grid_file : reading SURF file with File_Name=%s Read_Task_Flag=%i", Name_Text, Read_Task_Flag); ug_message (Text); } Grid_File = ug_fopen (File_Name, "r"); if (Grid_File == NULL) return (337); Read_Flag = fscanf (Grid_File, "%i %i %i", Number_of_Surf_Trias, Number_of_Surf_Quads, Number_of_Nodes); if (Read_Flag == EOF) { ug_fclose (Grid_File); return (337); } if (Read_Task_Flag == 2) { Try = 1; do { if (Try == 1) { for (Node_Index = 1; Node_Index <= *Number_of_Nodes; ++Node_Index) { Read_Flag = fscanf (Grid_File, "%lf %lf %lf %lf %lf", &Coordinates[Node_Index][0], &Coordinates[Node_Index][1], &Coordinates[Node_Index][2], &Initial_Normal_Spacing_, &BL_Thickness_); } } else if (Try == 2) { ug_rewind (Grid_File); Read_Flag = fscanf (Grid_File, "%i %i %i", Number_of_Surf_Trias, Number_of_Surf_Quads, Number_of_Nodes); if (Read_Flag == EOF) { ug_fclose (Grid_File); return (337); } for (Node_Index = 1; Node_Index <= *Number_of_Nodes; ++Node_Index) { Read_Flag = fscanf (Grid_File, "%lf %lf %lf %lf", &Coordinates[Node_Index][0], &Coordinates[Node_Index][1], &Coordinates[Node_Index][2], &Initial_Normal_Spacing_); } } else { ug_rewind (Grid_File); Read_Flag = fscanf (Grid_File, "%i %i %i", Number_of_Surf_Trias, Number_of_Surf_Quads, Number_of_Nodes); if (Read_Flag == EOF) { ug_fclose (Grid_File); return (337); } for (Node_Index = 1; Node_Index <= *Number_of_Nodes; ++Node_Index) { Read_Flag = fscanf (Grid_File, "%lf %lf %lf", &Coordinates[Node_Index][0], &Coordinates[Node_Index][1], &Coordinates[Node_Index][2]); } } Surf_Index = 0; for (Surf_Tria_Index = 1; Surf_Tria_Index <= *Number_of_Surf_Trias; ++Surf_Tria_Index) { ++Surf_Index; Read_Flag = fscanf (Grid_File, "%i %i %i %i %i %i", &Surf_Tria_Connectivity[Surf_Tria_Index][0], &Surf_Tria_Connectivity[Surf_Tria_Index][1], &Surf_Tria_Connectivity[Surf_Tria_Index][2], &Surf_ID_Flag_, &Surf_Reconnection_Flag_, &Surf_Grid_BC_Flag_); if (Surf_ID_Flag != NULL) Surf_ID_Flag[Surf_Index] = Surf_ID_Flag_; if (Surf_Reconnection_Flag != NULL) Surf_Reconnection_Flag[Surf_Index] = Surf_Reconnection_Flag_; if (Surf_Grid_BC_Flag != NULL) Surf_Grid_BC_Flag[Surf_Index] = Surf_Grid_BC_Flag_; } for (Surf_Quad_Index = 1; Surf_Quad_Index <= *Number_of_Surf_Quads; ++Surf_Quad_Index) { ++Surf_Index; Read_Flag = fscanf (Grid_File, "%i %i %i %i %i %i %i", &Surf_Quad_Connectivity[Surf_Quad_Index][0], &Surf_Quad_Connectivity[Surf_Quad_Index][1], &Surf_Quad_Connectivity[Surf_Quad_Index][2], &Surf_Quad_Connectivity[Surf_Quad_Index][3], &Surf_ID_Flag_, &Surf_Reconnection_Flag_, &Surf_Grid_BC_Flag_); if (Surf_ID_Flag != NULL) Surf_ID_Flag[Surf_Index] = Surf_ID_Flag_; if (Surf_Reconnection_Flag != NULL) Surf_Reconnection_Flag[Surf_Index] = Surf_Reconnection_Flag_; if (Surf_Grid_BC_Flag != NULL) Surf_Grid_BC_Flag[Surf_Index] = Surf_Grid_BC_Flag_; } ++Try; } while (Try <= 3 && Read_Flag == EOF); if (Read_Flag == EOF) { ug_fclose (Grid_File); return (337); } if (Surf_Reconnection_Flag != NULL) { for (Surf_Index = 1; Surf_Index <= *Number_of_Surf_Trias+*Number_of_Surf_Quads; ++Surf_Index) { Surf_Reconnection_Flag_ = Surf_Reconnection_Flag[Surf_Index]; Surf_Reconnection_Flag_ = MAX (Surf_Reconnection_Flag_, 0); Surf_Reconnection_Flag_ = MIN (Surf_Reconnection_Flag_, 7); Surf_Reconnection_Flag[Surf_Index] = Surf_Reconnection_Flag_; } } } ug_fclose (Grid_File); return (0); }
INT_ ug_io_write_efunc (char Case_Name[], char Error_Message[], CHAR_21 * U_Scalar_Labels, CHAR_21 * U_Vector_Labels, INT_ Number_of_Nodes, INT_ Number_of_U_Scalars, INT_ Number_of_U_Vectors, INT_1D * U_Scalar_Flags, INT_1D * U_Vector_Flags, DOUBLE_1D * U_Scalars, DOUBLE_3D * U_Vectors) { /* * Write function data to Ensight Gold case and function files. * * UG_IO LIB : Unstructured Grid - Input/Output Routine Library * $Id: ug_io_write_efunc.c,v 1.3 2012/08/23 04:01:49 marcum Exp $ * Copyright 1994-2012, David L. Marcum */ #define NCHAR 80 FILE **Scalar_Func_File; FILE **Vector_Func_File; FILE *Case_File = NULL; FILE *Func_File = NULL; FILE *Node_Map_File = NULL; char Text[NCHAR]; INT_1D *Node_Map = NULL; INT_ Dim, Error_Flag, Face_Nodes, ID_Parts, Index, Offset, Node_Index, Number_of_ID_Nodes, Number_of_ID_Parts, Number_of_Parts, Number_of_Read_Items_NM, Number_of_Vol_Elems, Number_of_Write_Items, Read_Flag_NM, Surf_ID, U_Index, Write_Flag; int n; float ui; Error_Flag = 0; Scalar_Func_File = (FILE **) ug_malloc (&Error_Flag, Number_of_U_Scalars * sizeof (FILE)); Vector_Func_File = (FILE **) ug_malloc (&Error_Flag, Number_of_U_Vectors * sizeof (FILE)); if (Error_Flag > 0) { ug_free (Scalar_Func_File); ug_free (Vector_Func_File); strcpy (Error_Message, "unable to malloc Ensight function file work array"); return (1); } for (U_Index = 0; U_Index < Number_of_U_Scalars; ++U_Index) { if (U_Scalar_Flags[U_Index]) { sprintf (Text, "%s.%s.efunc", Case_Name, U_Scalar_Labels[U_Index]); Scalar_Func_File[U_Index] = ug_fopen (Text, "w"); if (Scalar_Func_File[U_Index] == NULL) { ug_free (Scalar_Func_File); ug_free (Vector_Func_File); strcpy (Error_Message, "error opening Ensight scalar function file"); return (1); } } } for (U_Index = 0; U_Index < Number_of_U_Vectors; ++U_Index) { if (U_Vector_Flags[U_Index]) { sprintf (Text, "%s.%s.efunc", Case_Name, U_Vector_Labels[U_Index]); Vector_Func_File[U_Index] = ug_fopen (Text, "a"); if (Vector_Func_File[U_Index] == NULL) { ug_free (Scalar_Func_File); ug_free (Vector_Func_File); strcpy (Error_Message, "error opening Ensight vector function file"); return (1); } } } Number_of_Parts = 0; Number_of_Write_Items = 0; Write_Flag = 0; Error_Flag = 0; Node_Map = (INT_1D *) ug_malloc (&Error_Flag, (Number_of_Nodes+1) * sizeof (INT_1D)); if (Error_Flag > 0) { ug_free (Node_Map); ug_free (Scalar_Func_File); ug_free (Vector_Func_File); strcpy (Error_Message, "unable to malloc Ensight function file work array"); return (1); } Number_of_Read_Items_NM = 0; Read_Flag_NM = 0; sprintf (Text, "%s.ensight.nmap", Case_Name); Node_Map_File = ug_fopen (Text, "r"); if (Node_Map_File == NULL) { ug_free (Node_Map); ug_free (Scalar_Func_File); ug_free (Vector_Func_File); strcpy (Error_Message, "error opening node map data file - try again after re-creating Ensight grid file"); return (1); } Read_Flag_NM = Read_Flag_NM + ug_fread (&Number_of_ID_Parts, sizeof (INT_), 1, Node_Map_File); ++Number_of_Read_Items_NM; Read_Flag_NM = Read_Flag_NM + ug_fread (&Number_of_Vol_Elems, sizeof (INT_), 1, Node_Map_File); ++Number_of_Read_Items_NM; for (ID_Parts = 1; ID_Parts <= Number_of_ID_Parts; ++ID_Parts) { ++Number_of_Parts; Read_Flag_NM = Read_Flag_NM + ug_fread (&Face_Nodes, sizeof (INT_), 1, Node_Map_File); ++Number_of_Read_Items_NM; Read_Flag_NM = Read_Flag_NM + ug_fread (&Surf_ID, sizeof (INT_), 1, Node_Map_File); ++Number_of_Read_Items_NM; Read_Flag_NM = Read_Flag_NM + ug_fread (&Number_of_ID_Nodes, sizeof (INT_), 1, Node_Map_File); ++Number_of_Read_Items_NM; ug_set_int (1, Number_of_Nodes, 0, Node_Map); for (Index = 1; Index <= Number_of_ID_Nodes; ++Index) { Node_Index = 0; Read_Flag_NM = Read_Flag_NM + ug_fread (&Node_Index, sizeof (INT_), 1, Node_Map_File); ++Number_of_Read_Items_NM; Node_Map[Node_Index] = Index; } Offset = 0; for (U_Index = 0; U_Index < Number_of_U_Scalars; ++U_Index) { if (U_Scalar_Flags[U_Index]) { Func_File = Scalar_Func_File[U_Index]; strcpy (Text, "part"); Write_Flag = Write_Flag + ug_fwrite (Text, sizeof (char), NCHAR, Func_File); Number_of_Write_Items = Number_of_Write_Items + NCHAR; n = (int) Number_of_Parts; Write_Flag = Write_Flag + ug_fwrite (&n, sizeof(int), 1, Func_File); ++Number_of_Write_Items; strcpy (Text, "coordinates"); Write_Flag = Write_Flag + ug_fwrite (Text, sizeof (char), NCHAR, Func_File); Number_of_Write_Items = Number_of_Write_Items + NCHAR; for (Index = 1; Index <= Number_of_Nodes; ++Index) { if (Node_Map[Index]) { ui = (float) (U_Scalars[Offset+Index]); Write_Flag = Write_Flag + ug_fwrite (&ui, sizeof (float), 1, Func_File); ++Number_of_Write_Items; } } Offset = Offset + Number_of_Nodes+1; } } Offset = 0; for (U_Index = 0; U_Index < Number_of_U_Vectors; ++U_Index) { if (U_Vector_Flags[U_Index]) { Func_File = Vector_Func_File[U_Index]; strcpy (Text, "part"); Write_Flag = Write_Flag + ug_fwrite (Text, sizeof (char), NCHAR, Func_File); Number_of_Write_Items = Number_of_Write_Items + NCHAR; n = (int) Number_of_Parts; Write_Flag = Write_Flag + ug_fwrite (&n, sizeof(int), 1, Func_File); ++Number_of_Write_Items; strcpy (Text, "coordinates"); Write_Flag = Write_Flag + ug_fwrite (Text, sizeof (char), NCHAR, Func_File); Number_of_Write_Items = Number_of_Write_Items + NCHAR; for (Dim = 0; Dim < 3; ++Dim) { for (Index = 1; Index <= Number_of_Nodes; ++Index) { if (Node_Map[Index]) { ui = (float) (U_Vectors[Offset+Index][Dim]); Write_Flag = Write_Flag + ug_fwrite (&ui, sizeof (float), 1, Func_File); ++Number_of_Write_Items; } } } Offset = Offset + Number_of_Nodes+1; } } } ug_fclose (Node_Map_File); ug_free (Node_Map); if (Read_Flag_NM != Number_of_Read_Items_NM) { strcpy (Error_Message, "error reading node map data file"); return (1); } if (Number_of_Vol_Elems) { ++Number_of_Parts; Offset = 0; for (U_Index = 0; U_Index < Number_of_U_Scalars; ++U_Index) { if (U_Scalar_Flags[U_Index]) { Func_File = Scalar_Func_File[U_Index]; strcpy (Text, U_Scalar_Labels[U_Index]); strcat (Text, " scalar file"); Write_Flag = Write_Flag + ug_fwrite (Text, sizeof (char), NCHAR, Func_File); Number_of_Write_Items = Number_of_Write_Items + NCHAR; strcpy (Text, "part"); Write_Flag = Write_Flag + ug_fwrite (Text, sizeof (char), NCHAR, Func_File); Number_of_Write_Items = Number_of_Write_Items + NCHAR; n = (int) Number_of_Parts; Write_Flag = Write_Flag + ug_fwrite (&n, sizeof(int), 1, Func_File); ++Number_of_Write_Items; strcpy (Text, "coordinates"); Write_Flag = Write_Flag + ug_fwrite (Text, sizeof (char), NCHAR, Func_File); Number_of_Write_Items = Number_of_Write_Items + NCHAR; for (Index = 1; Index <= Number_of_Nodes; ++Index) { ui = (float) (U_Scalars[Offset+Index]); Write_Flag = Write_Flag + ug_fwrite (&ui, sizeof (float), 1, Func_File); ++Number_of_Write_Items; } Offset = Offset + Number_of_Nodes+1; } } Offset = 0; for (U_Index = 0; U_Index < Number_of_U_Vectors; ++U_Index) { if (U_Vector_Flags[U_Index]) { Func_File = Vector_Func_File[U_Index]; strcpy (Text, U_Vector_Labels[U_Index]); strcat (Text, " vector file"); Write_Flag = Write_Flag + ug_fwrite (Text, sizeof (char), NCHAR, Func_File); Number_of_Write_Items = Number_of_Write_Items + NCHAR; strcpy (Text, "part"); Write_Flag = Write_Flag + ug_fwrite (Text, sizeof (char), NCHAR, Func_File); Number_of_Write_Items = Number_of_Write_Items + NCHAR; n = (int) Number_of_Parts; Write_Flag = Write_Flag + ug_fwrite (&n, sizeof(int), 1, Func_File); ++Number_of_Write_Items; strcpy (Text, "coordinates"); Write_Flag = Write_Flag + ug_fwrite (Text, sizeof (char), NCHAR, Func_File); Number_of_Write_Items = Number_of_Write_Items + NCHAR; for (Dim = 0; Dim < 3; ++Dim) { for (Index = 1; Index <= Number_of_Nodes; ++Index) { ui = (float) (U_Vectors[Offset+Index][Dim]); Write_Flag = Write_Flag + ug_fwrite (&ui, sizeof (float), 1, Func_File); ++Number_of_Write_Items; } } Offset = Offset + Number_of_Nodes+1; } } } for (U_Index = 0; U_Index < Number_of_U_Scalars; ++U_Index) { ug_fclose (Scalar_Func_File[U_Index]); } for (U_Index = 0; U_Index < Number_of_U_Vectors; ++U_Index) { ug_fclose (Vector_Func_File[U_Index]); } ug_free (Scalar_Func_File); ug_free (Vector_Func_File); if (Write_Flag != Number_of_Write_Items) { strcpy (Error_Message, "error writing Ensight function file"); return (1); } sprintf (Text, "%s.case", Case_Name); ug_backup_file (Text); Case_File = ug_fopen (Text, "w"); if (Case_File == NULL) { strcpy (Error_Message, "error opening Ensight case file"); return (1); } Write_Flag = fprintf (Case_File, "FORMAT\n"); Write_Flag = fprintf (Case_File, "type: ensight gold\n"); Write_Flag = fprintf (Case_File, "GEOMETRY\n"); Write_Flag = fprintf (Case_File, "model: %s.egrid\n", Case_Name); Write_Flag = fprintf (Case_File, "VARIABLE\n"); for (U_Index = 0; U_Index < Number_of_U_Scalars; ++U_Index) { Write_Flag = fprintf (Case_File, "scalar per node: %s %s.%s.efunc\n", U_Scalar_Labels[U_Index], Case_Name, U_Scalar_Labels[U_Index]); } for (U_Index = 0; U_Index < Number_of_U_Vectors; ++U_Index) { Write_Flag = fprintf (Case_File, "vector per node: %s %s.%s.efunc\n", U_Vector_Labels[U_Index], Case_Name, U_Vector_Labels[U_Index]); } ug_fclose (Case_File); if (Write_Flag < 0) { strcpy (Error_Message, "error writing Ensight case file"); return (1); } return (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); }