INT_ ug3_ieliel2b (INT_ nbface, INT_ nelem, INT_ nnode, INT_1D * ibcibf, INT_3D * inibf, INT_4D * iniel, INT_4D * ieliel) { /* * Add boundary faces element to element connectivity. * * UG3 LIB : Unstructured Grid - General Purpose Routine Library * 3D Version : $Id: ug3_ieliel2b.c,v 1.4 2012/08/25 19:01:45 marcum Exp $ * Copyright 1994-2012, David L. Marcum */ INT_1D *ibfjbf = NULL; INT_1D *ibfjn = NULL; INT_1D *ielibf = NULL; INT_1D *ierribf = NULL; INT_ ierr = 0; INT_ minl = 0; INT_ mmsg = 0; INT_ nbfaceu = 0; if (ibcibf == NULL) minl = 2; ibfjbf = (INT_1D *) ug_malloc (&ierr, (nbface+1) * sizeof (INT_1D)); ibfjn = (INT_1D *) ug_malloc (&ierr, (nnode+1) * sizeof (INT_1D)); ielibf = (INT_1D *) ug_malloc (&ierr, (nbface+1) * sizeof (INT_1D)); if (ierr > 0) { ug_free (ibfjbf); ug_free (ibfjn); ug_free (ielibf); return (100309); } ierr = ug3_ielibf (minl, mmsg, nbface, nelem, nnode, &nbfaceu, ibcibf, ieliel, inibf, iniel, ibfjbf, ibfjn, ielibf, ierribf); ug_free (ibfjbf); ug_free (ibfjn); ug_free (ielibf); if (ierr > 0) return (ierr); return (0); }
void ug_json_init (UgJson* json) { // initialize buffer json->buf.allocated = BUFFER_SIZE; json->buf.length = 0; json->buf.at = ug_malloc (json->buf.allocated); // initialize stack json->stack.allocated = 16 * 4; // 16 x PARSER_STACK_UNIT json->stack.length = 0; json->stack.at = ug_malloc (sizeof (void*) * json->stack.allocated); }
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; }
void ug_file_status_monitor (char *Flag) { /* * Turn file status monitor on or off. */ INT_ ierr; if (File_Status_Monitor) { ug_free (stat_struct); stat_struct = NULL; } if (strcmp (Flag, "on") == 0) { ierr = 0; stat_struct = (ug_stat_struct *) ug_malloc (&ierr, sizeof (ug_stat_struct)); File_Status_Monitor = (ierr == 0) ? 1: 0; } else File_Status_Monitor = 0; return; }
char* ug_strndup (const char* string, size_t length) { char* result; result = ug_malloc (length + 1); result[length] = 0; strncpy (result, string, length); return result; }
UgetNode* uget_node_new (UgetNode* node_real) { UgetNode* node; #ifdef HAVE_GLIB node = g_slice_alloc (sizeof (UgetNode)); #else node = ug_malloc (sizeof (UgetNode)); #endif // HAVE_GLIB uget_node_init (node, node_real); return node; }
static INT_ ug_malloc_tmp_file_struct (UG_TMP_File_Struct ** UG_TMP_File_Struct_Ptr) { /* * Malloc binary TMP file structure arrays. */ UG_TMP_File_Struct *Struct_Ptr_Ptr; INT_ Error_Flag = 0; *UG_TMP_File_Struct_Ptr = (UG_TMP_File_Struct *) ug_malloc (&Error_Flag, sizeof (UG_TMP_File_Struct)); if (Error_Flag > 0) return (-1); Struct_Ptr_Ptr = *UG_TMP_File_Struct_Ptr; Struct_Ptr_Ptr->Number_of_TMP_Files = 1; Struct_Ptr_Ptr->TMP_File_Name = (CHAR_UG_MAX *) ug_malloc (&Error_Flag, sizeof (CHAR_UG_MAX)); Struct_Ptr_Ptr->TMP_File_Stream = (FILE **) ug_malloc (&Error_Flag, sizeof (FILE)); Struct_Ptr_Ptr->TMP_File_Status = (INT_1D *) ug_malloc (&Error_Flag, sizeof (INT_1D)); if (Error_Flag > 0) return (-1); return (0); }
static void add_uri_mirrors (UgValue* varray, const char* mirrors) { UgValue* value; const char* curr; const char* prev; for (curr = mirrors; curr && curr[0];) { // skip space ' ' while (curr[0] == ' ') curr++; prev = curr; curr = curr + strcspn (curr, " "); value = ug_value_alloc (varray, 1); value->type = UG_VALUE_STRING; value->c.string = ug_malloc (curr - prev + 1); value->c.string[curr - prev] = 0; // NULL terminated strncpy (value->c.string, prev, curr - prev); } }
int ug_file_copy (const char *src_file_utf8, const char *new_file_utf8) { int src_fd; int new_fd; char* buf; int buf_len; int retval = 0; // new_fd = open (new_file_utf8, // O_BINARY | O_WRONLY | O_CREAT, // S_IREAD | S_IWRITE | S_IRGRP | S_IROTH); new_fd = ug_open (new_file_utf8, UG_O_BINARY | UG_O_WRONLY | UG_O_CREAT, UG_S_IREAD | UG_S_IWRITE | UG_S_IRGRP | UG_S_IROTH); if (new_fd == -1) return -1; // src_fd = open (src_file_utf8, O_BINARY | O_RDONLY, S_IREAD); src_fd = ug_open (src_file_utf8, UG_O_BINARY | UG_O_RDONLY, UG_S_IREAD); if (src_fd == -1) { ug_close (new_fd); return -1; } // read & write buf = ug_malloc (8192); for (;;) { buf_len = ug_read (src_fd, buf, 8192); if (buf_len <=0) break; if (ug_write (new_fd, buf, buf_len) != buf_len) { retval = -1; break; } } // clear ug_free (buf); ug_close (src_fd); ug_close (new_fd); return retval; }
int ug_create_dir_all (const char* dir, int len) { const char* dir_end; const char* element_end; // path element char* element_os; if (len == -1) len = strlen (dir); dir_end = dir + len; element_end = dir; for (;;) { // skip directory separator "\\\\" or "//" for (; element_end < dir_end; element_end++) { if (*element_end != UG_DIR_SEPARATOR) break; } if (element_end == dir_end) return 0; // get directory name [dir, element_end) for (; element_end < dir_end; element_end++) { if (*element_end == UG_DIR_SEPARATOR) break; } element_os = (char*) ug_malloc (element_end - dir + 1); element_os[element_end - dir] = 0; strncpy (element_os, dir, element_end - dir); if (element_os == NULL) break; if (ug_create_dir (element_os) == -1) { if (ug_file_is_exist (element_os) == FALSE) { ug_free (element_os); return -1; } } ug_free (element_os); } return -1; }
static void* ug_file_to_base64 (const char* file, int* length) { int fd; int fsize, fpos = 0; int result_len; void* buffer; void* result; // fd = open (file, O_RDONLY | O_BINARY, S_IREAD); fd = ug_open (file, UG_O_READONLY | UG_O_BINARY, UG_S_IREAD); if (fd == -1) return NULL; // lseek (fd, 0, SEEK_END); ug_seek (fd, 0, SEEK_END); fsize = (int) ug_tell (fd); buffer = ug_malloc (fsize); // lseek (fd, 0, SEEK_SET); ug_seek (fd, 0, SEEK_SET); do { result_len = ug_read (fd, buffer, fsize - fpos); // result_len = read (fd, buffer, fsize - fpos); fpos += result_len; } while (result_len > 0); // close (fd); ug_close (fd); if (fsize != fpos) { ug_free (buffer); return NULL; } result = ug_base64_encode (buffer, fsize, &result_len); ug_free (buffer); if (length) *length = result_len; return result; }
char* ug_strdup_printf (const char* format, ...) { va_list arg_list; char* string; int string_len; va_start (arg_list, format); #ifdef _MSC_VER /* for M$ C only */ string_len = _vscprintf (format, arg_list); #else /* for C99 standard */ string_len = vsnprintf (NULL, 0, format, arg_list); #endif va_end (arg_list); string = ug_malloc (string_len + 1); va_start (arg_list, format); vsprintf (string, format, arg_list); va_end (arg_list); return string; }
INT_ ug_io_malloc_param (char Error_Message[], UG_IO_Param_Struct ** UG_IO_Param_Struct_Ptr) { /* * Malloc UG_IO parameter structure arrays. * * UG_IO LIB : Unstructured Grid - Input/Output Routine Library * $Id: ug_io_malloc_param.c,v 1.16 2012/08/23 04:01:49 marcum Exp $ * Copyright 1994-2012, David L. Marcum */ UG_IO_Param_Struct *Struct_Ptr_Ptr; INT_ Max_File_Compressions = 10; INT_ Max_File_Formats = 10; INT_ Max_File_Modes = 10; INT_ Max_File_Types = 100; INT_ Max_IO_Param_Labels = 21; INT_ Error_Flag = 0; *UG_IO_Param_Struct_Ptr = (UG_IO_Param_Struct *) ug_malloc (&Error_Flag, sizeof (UG_IO_Param_Struct)); if (Error_Flag > 0) { strcpy (Error_Message, "unable to malloc UG_IO parameter structure"); return (616); } Struct_Ptr_Ptr = *UG_IO_Param_Struct_Ptr; Struct_Ptr_Ptr->Max_IO_Param_Labels = Max_IO_Param_Labels; Struct_Ptr_Ptr->Max_File_Types = Max_File_Types; Struct_Ptr_Ptr->Number_of_File_Types = 0; Struct_Ptr_Ptr->Max_File_Formats = Max_File_Formats; Struct_Ptr_Ptr->Number_of_File_Formats = 0; Struct_Ptr_Ptr->Max_File_Modes = Max_File_Modes; Struct_Ptr_Ptr->Number_of_File_Modes = 0; Struct_Ptr_Ptr->Max_File_Compressions = Max_File_Compressions; Struct_Ptr_Ptr->Number_of_File_Compressions = 0; Struct_Ptr_Ptr->File_Data_Type = (INT_1D *) ug_malloc (&Error_Flag, Max_File_Types * sizeof (INT_1D)); Struct_Ptr_Ptr->File_Type_Format_Flag = (INT_1D *) ug_malloc (&Error_Flag, Max_File_Types * sizeof (INT_1D)); Struct_Ptr_Ptr->File_Type_Label = (CHAR_41 *) ug_malloc (&Error_Flag, Max_IO_Param_Labels * Max_File_Types * sizeof (CHAR_41)); Struct_Ptr_Ptr->File_Type_Suffix = (CHAR_21 *) ug_malloc (&Error_Flag, Max_File_Types * sizeof (CHAR_21)); Struct_Ptr_Ptr->File_Format = (INT_1D *) ug_malloc (&Error_Flag, Max_IO_Param_Labels * sizeof (INT_1D)); Struct_Ptr_Ptr->File_Format_Label = (CHAR_41 *) ug_malloc (&Error_Flag, Max_IO_Param_Labels * Max_File_Formats * sizeof (CHAR_41)); Struct_Ptr_Ptr->File_Format_Suffix = (CHAR_11 *) ug_malloc (&Error_Flag, Max_File_Formats * sizeof (CHAR_11)); Struct_Ptr_Ptr->File_Mode = (INT_1D *) ug_malloc (&Error_Flag, Max_IO_Param_Labels * sizeof (INT_1D)); Struct_Ptr_Ptr->File_Mode_Label = (CHAR_41 *) ug_malloc (&Error_Flag, Max_IO_Param_Labels * Max_File_Modes * sizeof (CHAR_41)); Struct_Ptr_Ptr->File_Mode_Suffix = (CHAR_11 *) ug_malloc (&Error_Flag, Max_File_Modes * sizeof (CHAR_11)); Struct_Ptr_Ptr->File_Compression_Label = (CHAR_41 *) ug_malloc (&Error_Flag, Max_IO_Param_Labels * Max_File_Compressions * sizeof (CHAR_41)); Struct_Ptr_Ptr->File_Compression_Suffix = (CHAR_11 *) ug_malloc (&Error_Flag, Max_File_Compressions * sizeof (CHAR_11)); if (Error_Flag > 0) { strcpy (Error_Message, "unable to malloc UG_IO parameter arrays"); return (616); } return (0); }
// return FALSE if plug-in was stopped. static int plugin_sync (UgetPluginAria2* plugin) { int index; UgetNode* node; UgetEvent* event; struct { UgetCommon* common; UgetProgress* progress; } temp; if (plugin->stopped == TRUE) return FALSE; if (plugin->synced == TRUE) return TRUE; node = plugin->node; // ------------------------------------------------ // update progress temp.progress = ug_info_realloc (&node->info, UgetProgressInfo); temp.progress->complete = plugin->completedLength; temp.progress->total = plugin->totalLength; temp.progress->download_speed = plugin->downloadSpeed; temp.progress->upload_speed = plugin->uploadSpeed; temp.progress->uploaded = plugin->uploadLength; temp.progress->consume_time = time(NULL) - plugin->start_time; // ratio if (temp.progress->uploaded && temp.progress->complete) temp.progress->ratio = (double)temp.progress->uploaded / (double)temp.progress->complete; else temp.progress->ratio = 0.0; // If total size is unknown, don't calculate percent. if (temp.progress->total) temp.progress->percent = (temp.progress->complete * 100) / temp.progress->total; else temp.progress->percent = 0; // If total size and average speed is unknown, don't calculate remain time. if (temp.progress->download_speed > 0 && temp.progress->total > 0) temp.progress->remain_time = (temp.progress->total - temp.progress->complete) / temp.progress->download_speed; // ------------------------------------------------ temp.common = ug_info_realloc (&node->info, UgetCommonInfo); // sync changed limit from UgetNode if (plugin->limit[1] != temp.common->max_upload_speed || plugin->limit[0] != temp.common->max_download_speed) { plugin->limit_by_user = TRUE; } // add nodes by files if (plugin->files_per_gid_prev != plugin->files_per_gid) { #ifndef NDEBUG // debug if (temp.common->debug_level) { printf ("n_files: old %d - new %d\n", plugin->files_per_gid_prev, plugin->files_per_gid); } #endif // add child node if aria2 add/create more files index = plugin->files_per_gid_prev; for (; index < plugin->files.length; index++) { if (plugin_insert_node (plugin, plugin->files.at[index].path, FALSE)) { #ifndef NDEBUG // debug if (temp.common->debug_level) printf ("new child node name = %s\n", plugin->files.at[index].path); #endif } } plugin->files_per_gid_prev = plugin->files_per_gid; } // change node name. if (plugin->node_named == FALSE && plugin->files_per_gid > 0) { plugin->node_named = TRUE; if (plugin->uri_type == URI_NET && temp.common->file == NULL) { ug_uri_init (&plugin->uri_part, node->children->name); index = plugin->uri_part.file; if (index != -1) { ug_free (node->name); node->name = ug_uri_get_file (&plugin->uri_part); event = uget_event_new (UGET_EVENT_NAME); uget_plugin_post ((UgetPlugin*) plugin, event); #ifndef NDEBUG // debug if (temp.common->debug_level) printf ("base node name = %s\n", node->name); #endif } } } switch (plugin->status) { case ARIA2_STATUS_ACTIVE: if (plugin->completedLength > 0 && plugin->completedLength == plugin->totalLength) { #ifndef NDEBUG // debug if (temp.common->debug_level) { if ((node->state & UGET_STATE_UPLOADING) == 0) printf ("uploading...\n"); } #endif node->state |= UGET_STATE_UPLOADING; } break; case ARIA2_STATUS_WAITING: // clear uploading state node->state &= ~UGET_STATE_UPLOADING; break; case ARIA2_STATUS_COMPLETE: // clear uploading state node->state &= ~UGET_STATE_UPLOADING; // remove completed gid ug_free (plugin->gids.at[0]); plugin->gids.length -= 1; memmove (plugin->gids.at, plugin->gids.at + 1, sizeof (char*) * plugin->gids.length); // If there is only one followed gid and file, change uri. if (plugin->gids.length == 1 && plugin->files.length == 1) { // If URI scheme is not "magnet" and aria2 runs in local device if (global.data->uri_remote == FALSE && plugin->uri_type != URI_MAGNET) { // change URI ug_free (temp.common->uri); ug_free (temp.common->file); temp.common->file = NULL; if (node->children && node->children->name) temp.common->uri = ug_strdup (node->children->name); else temp.common->uri = ug_strdup (plugin->files.at[0].path); uget_node_set_name_by_uri_string (node, temp.common->uri); // set node type node->children->type = UGET_NODE_ATTACHMENT; #ifndef NDEBUG // debug if (temp.common->debug_level) printf ("uri followed to %s\n", temp.common->uri); #endif } } // If no followed gid, it was completed. else if (plugin->gids.length == 0) { node->state |= UGET_STATE_COMPLETED; event = uget_event_new (UGET_EVENT_COMPLETED); uget_plugin_post ((UgetPlugin*)plugin, event); } // clear plugin->files ug_array_foreach (&plugin->files, (UgForeachFunc)aria2_file_clear, NULL); plugin->files.length = 0; plugin->files_per_gid = 0; plugin->files_per_gid_prev = 0; break; case ARIA2_STATUS_ERROR: // clear uploading state node->state &= ~UGET_STATE_UPLOADING; #ifdef NO_RETRY_IF_CONNECT_FAILED // download speed was too slow if (plugin->errorCode == 5) { #else // download speed was too slow or name resolution failed if (plugin->errorCode == 5 || plugin->errorCode == 19) { #endif // retry if (temp.common->retry_count < temp.common->retry_limit || temp.common->retry_limit == 0) { temp.common->retry_count++; plugin->restart = TRUE; #ifndef NDEBUG // debug if (temp.common->debug_level) printf ("retry %d\n", temp.common->retry_count); #endif } else { // plugin->node->state |= UGET_STATE_ERROR; event = uget_event_new_error ( UGET_EVENT_ERROR_TOO_MANY_RETRIES, NULL); uget_plugin_post ((UgetPlugin*) plugin, event); } } else { if (plugin->errorCode > 30) plugin->errorCode = 1; // if this is last gid. if (plugin->gids.length == 1) { // plugin->node->state |= UGET_STATE_ERROR; #ifdef HAVE_GLIB event = uget_event_new_error (0, gettext (error_string[plugin->errorCode])); #else event = uget_event_new_error (0, error_string[plugin->errorCode]); #endif uget_plugin_post ((UgetPlugin*)plugin, event); } } // remove stopped gid ug_free (plugin->gids.at[0]); plugin->gids.length -= 1; memmove (plugin->gids.at, plugin->gids.at + 1, sizeof (char*) * plugin->gids.length); break; case ARIA2_STATUS_REMOVED: // clear uploading state node->state &= ~UGET_STATE_UPLOADING; // debug event = uget_event_new_normal (0, _("aria2: gid was removed.")); uget_plugin_post ((UgetPlugin*)plugin, event); // remove completed gid ug_free (plugin->gids.at[0]); plugin->gids.length -= 1; memmove (plugin->gids.at, plugin->gids.at + 1, sizeof (char*) * plugin->gids.length); break; } // If we have followed gid, don't restart. if (plugin->gids.length > 0) plugin->restart = FALSE; else { #ifndef NDEBUG // debug if (temp.common->debug_level) printf ("gids.length = %d\n", plugin->gids.length); #endif // If no followed gid and no need to retry, it must stop. if (plugin->restart == FALSE) plugin->stopped = TRUE; else { plugin->retry_delay = temp.common->retry_delay; uget_aria2_request (global.data, plugin->start_request); } } // if plug-in was stopped, don't sync data with thread if (plugin->stopped == FALSE) plugin->synced = TRUE; return TRUE; } // ------------------------------------ static int plugin_insert_node (UgetPluginAria2* plugin, const char* fpath, int is_attachment) { UgetNode* node; char* ctrl_file; // aria2 magnet metadata file // if (plugin->uri_type == URI_MAGNET) { // if (strncmp ("[METADATA]", fpath, 10) == 0) // fpath += 10; // } for (node = plugin->node->children; node; node = node->next) { if (strcmp (node->name, fpath) == 0) return FALSE; } // aria2 control file must add first ctrl_file = ug_malloc (strlen (fpath) + 6 + 1); // + ".aria2" + '\0' ctrl_file[0] = 0; strcat (ctrl_file, fpath); strcat (ctrl_file, ".aria2"); node = uget_node_new (NULL); node->name = ctrl_file; node->type = UGET_NODE_ATTACHMENT; uget_node_prepend (plugin->node, node); // download file node = uget_node_new (NULL); node->name = ug_strdup (fpath); uget_node_prepend (plugin->node, node); if (is_attachment) node->type = UGET_NODE_ATTACHMENT; return TRUE; }
static int plugin_start (UgetPluginAria2* plugin, UgetNode* node) { UgJsonrpcObject* request; UgValue* value; UgValue* member; UgThread thread; char* data = NULL; char* uri; char* user = NULL; char* password = NULL; union { UgetCommon* common; UgetProxy* proxy; UgetHttp* http; UgetHttp* ftp; int ok; } temp; temp.common = ug_info_get (&node->info, UgetCommonInfo); if (temp.common == NULL || temp.common->uri == NULL) return FALSE; uri = temp.common->uri; plugin->uri_type = URI_NET; ug_uri_init (&plugin->uri_part, uri); if ((plugin->uri_part.scheme_len == 4 && strncmp (uri, "file", 4) == 0) || (plugin->uri_part.scheme_len == 0 && plugin->uri_part.file >= 0)) { // file type is torrent or metalink? if (decide_file_type (plugin) == URI_UNSUPPORTED) { uget_plugin_post ((UgetPlugin*) plugin, uget_event_new_error (UGET_EVENT_ERROR_UNSUPPORTED_FILE, NULL)); return FALSE; } // load file and convert it's binary to base64 if (plugin->uri_part.path > 0) data = ug_file_to_base64 (uri + plugin->uri_part.path + 1, NULL); else data = ug_file_to_base64 (uri, NULL); if (data == NULL) { uget_plugin_post ((UgetPlugin*) plugin, uget_event_new_error (UGET_EVENT_ERROR_FILE_OPEN_FAILED, NULL)); return FALSE; } } else if (plugin->uri_part.scheme_len == 6 && strncmp (uri, "magnet", 6) == 0) plugin->uri_type = URI_MAGNET; request = uget_aria2_alloc (global.data, TRUE, TRUE); if (request->params.type == UG_VALUE_NONE) ug_value_init_array (&request->params, 3); switch (plugin->uri_type) { case URI_NET: case URI_MAGNET: request->method_static = "aria2.addUri"; // parameter1 : URIs value = ug_value_alloc (&request->params, 1); ug_value_init_array (value, 8); member = ug_value_alloc (value, 1); member->type = UG_VALUE_STRING; member->c.string = ug_strdup (uri); // mirrors add_uri_mirrors (value, temp.common->mirrors); // parameter2 : options break; case URI_TORRENT: request->method_static = "aria2.addTorrent"; // parameter1 : encoded torrent file value = ug_value_alloc (&request->params, 1); value->type = UG_VALUE_STRING; value->c.string = data; // parameter2 : URIs value = ug_value_alloc (&request->params, 1); ug_value_init_array (value, 0); // parameter3 : options break; case URI_METALINK: // parameter1 : encoded metalink file request->method_static = "aria2.addMetalink"; value = ug_value_alloc (&request->params, 1); value->type = UG_VALUE_STRING; value->c.string = data; // parameter2 : options break; } // parameterX : options value = ug_value_alloc (&request->params, 1); ug_value_init_object (value, 16); member = ug_value_alloc (value, 1); member->name = "continue"; member->type = UG_VALUE_BOOL; member->c.boolean = TRUE; if ((temp.common->user && temp.common->user[0]) || (temp.common->password && temp.common->password[0])) { user = (temp.common->user) ? temp.common->user : ""; password = (temp.common->password) ? temp.common->password : ""; } if (temp.common->folder) { member = ug_value_alloc (value, 1); member->name = "dir"; member->type = UG_VALUE_STRING; member->c.string = ug_strdup (temp.common->folder); } if (temp.common->file) { member = ug_value_alloc (value, 1); member->name = "out"; member->type = UG_VALUE_STRING; member->c.string = ug_strdup (temp.common->file); } member = ug_value_alloc (value, 1); member->name = "remote-time"; member->type = UG_VALUE_BOOL; member->c.boolean = temp.common->timestamp; member = ug_value_alloc (value, 1); member->name = "retry-wait"; member->type = UG_VALUE_STRING; member->c.string = ug_strdup_printf ("%u", temp.common->retry_delay); member = ug_value_alloc (value, 1); member->name = "max-tries"; member->type = UG_VALUE_STRING; member->c.string = ug_strdup_printf ("%u", temp.common->retry_limit); // speed control if (plugin->limit_changed) { plugin->node = node; plugin_ctrl_speed (plugin, plugin->limit); plugin->node = NULL; } member = ug_value_alloc (value, 1); member->name = "max-download-limit"; member->type = UG_VALUE_STRING; // member->c.string = ug_strdup_printf ("%d", temp.common->max_download_speed); member->c.string = ug_strdup_printf ("%d", plugin->limit[0]); member = ug_value_alloc (value, 1); member->name = "max-upload-limit"; member->type = UG_VALUE_STRING; // member->c.string = ug_strdup_printf ("%d", temp.common->max_upload_speed); member->c.string = ug_strdup_printf ("%d", plugin->limit[1]); member = ug_value_alloc (value, 1); member->name = "lowest-speed-limit"; member->type = UG_VALUE_STRING; member->c.string = ug_strdup_printf ("%u", 128); // Don't set connection limit if max_connections is 0. if (temp.common->max_connections != 0) { // aria2 doesn't accept "max-connection-per-server" large than 16. member = ug_value_alloc (value, 1); member->name = "max-connection-per-server"; member->type = UG_VALUE_STRING; member->c.string = ug_strdup_printf ("%u", (temp.common->max_connections <= 16) ? temp.common->max_connections : 16); // split member = ug_value_alloc (value, 1); member->name = "split"; member->type = UG_VALUE_STRING; member->c.string = ug_strdup_printf ("%u", temp.common->max_connections); } temp.proxy = ug_info_get (&node->info, UgetProxyInfo); #ifdef HAVE_LIBPWMD if (temp.proxy && temp.proxy->type == UGET_PROXY_PWMD) { if (uget_plugin_aria2_set_proxy_pwmd (plugin, member) == FALSE) return FALSE; } else #endif if (temp.proxy && temp.proxy->host) { member = ug_value_alloc (value, 1); member->name = "all-proxy"; member->type = UG_VALUE_STRING; if (temp.proxy->port == 0) member->c.string = ug_strdup (temp.proxy->host); else { member->c.string = ug_strdup_printf ("%s:%d", temp.proxy->host, temp.proxy->port); } if ((temp.proxy->user && temp.proxy->user[0]) || (temp.proxy->password && temp.proxy->password[0])) { member = ug_value_alloc (value, 1); member->name = "all-proxy-user"; member->type = UG_VALUE_STRING; member->c.string = ug_strdup ( (temp.proxy->user) ? temp.proxy->user : ""); member = ug_value_alloc (value, 1); member->name = "all-proxy-password"; member->type = UG_VALUE_STRING; member->c.string = ug_strdup ( (temp.proxy->password) ? temp.proxy->password : ""); } } temp.http = ug_info_get (&node->info, UgetHttpInfo); if (temp.http) { if (plugin->uri_part.scheme_len >= 4 && strncmp (uri, "http", 4) == 0) { if ((temp.http->user && temp.http->user[0]) || (temp.http->password && temp.http->password[0])) { user = (temp.http->user) ? temp.http->user : ""; password = (temp.http->password) ? temp.http->password : ""; } } if (temp.http->referrer) { member = ug_value_alloc (value, 1); member->name = "referer"; member->type = UG_VALUE_STRING; member->c.string = ug_strdup (temp.http->referrer); } // if (temp.http->cookie_file) { // member = ug_value_alloc (value, 1); // member->name = "load-cookies"; // member->type = UG_VALUE_STRING; // member->c.string = ug_strdup (temp.http->cookie_file); // } if (temp.http->user_agent) { member = ug_value_alloc (value, 1); member->name = "user-agent"; member->type = UG_VALUE_STRING; member->c.string = ug_strdup (temp.http->user_agent); } } temp.ftp = ug_info_get (&node->info, UgetFtpInfo); if (temp.ftp) { if (plugin->uri_part.scheme_len >= 3 && strncmp (uri, "ftp", 3) == 0) { if ((temp.ftp->user && temp.ftp->user[0]) || (temp.ftp->password && temp.ftp->password[0])) { user = (temp.ftp->user) ? temp.ftp->user : ""; password = (temp.ftp->password) ? temp.ftp->password : ""; } } } if (plugin->uri_type == URI_NET && plugin->uri_part.host != -1) { if (user || password) { data = ug_malloc (strlen (user) + strlen (password) + strlen (uri) + 2 + 1); // + ':' + '@' + '\0' data[plugin->uri_part.host] = 0; strncpy (data, uri, plugin->uri_part.host); strcat (data, user); strcat (data, ":"); strcat (data, password); strcat (data, "@"); strcat (data, uri + plugin->uri_part.host); // reset uri for aria2.addUri, request->params[0][0] value = request->params.c.array->at; value = value->c.array->at; ug_free (value->c.string); value->c.string = ug_strdup (data); } } plugin->files_per_gid = 0; plugin->files_per_gid_prev = 0; plugin->stopped = FALSE; plugin->synced = TRUE; plugin->start_time = time (NULL); plugin->start_request = request; plugin->node = node; uget_node_ref (node); uget_aria2_request (global.data, request); uget_plugin_ref ((UgetPlugin*) plugin); temp.ok = ug_thread_create (&thread, (UgThreadFunc) plugin_thread, plugin); if (temp.ok == UG_THREAD_OK) ug_thread_unjoin (&thread); else { uget_plugin_post ((UgetPlugin*) plugin, uget_event_new_error (UGET_EVENT_ERROR_THREAD_CREATE_FAILED, NULL)); uget_plugin_unref ((UgetPlugin*) plugin); return FALSE; } return TRUE; }
INT_ ug_get_items_from_list (const char *list, const char *sep, CHAR_256 **items, INT_ *n) { /* * Get vector of items in a list. * * UG LIB : Unstructured Grid - General Purpose Routine Library * $Id: ug_get_items_from_list.c,v 1.5 2012/08/25 18:54:13 marcum Exp $ * Copyright 1994-2012, David L. Marcum */ char *str_ptr; CHAR_UG_MAX str; INT_ err, i, length, max_length, j; if (! strstr (list, sep)) return (-1); for (j = 1; j <= 2; ++j) { strcpy (str, list); i = 0; max_length = 0; do { length = (INT_) strcspn (str, sep); if (length) { max_length = MAX (max_length, length); if (max_length >= 256) return (414); if (j == 2) { strcpy ((*items)[i], ""); strncat ((*items)[i], str, (int) length); } ++i; } str_ptr = strstr (str, sep); if (str_ptr) { ++str_ptr; length = (INT_) strlen (str_ptr); if (length) strcpy (str, str_ptr); else str_ptr = NULL; } else str_ptr = NULL; } while (str_ptr); *n = i; if (j == 1) { err = 0; *items = (CHAR_256 *) ug_malloc (&err, *n * sizeof (CHAR_256)); if (err) return (100408); } } return (0); }
INT_ ug3_bnd_vol_nodes (INT_ *nnodeb, INT_ nnode, INT_ nbface, INT_ nelem, INT_ nelemc5, INT_ nelemc6, INT_ nelemc8, INT_ nquad, INT_3D * inibf, INT_4D * iniel, INT_5D * inielc5, INT_6D * inielc6, INT_8D * inielc8, INT_4D * iniq, DOUBLE_1D * del, DOUBLE_1D * ds, DOUBLE_3D * x) { /* * Reorder nodes so that boundary nodes are first followed by interior nodes * and increment all connectivity node indicies by one if the input connectivity * uses node index 0. * * UG3 LIB : Unstructured Grid - General Purpose Routine Library * 3D Version : $Id: ug3_bnd_vol_nodes.c,v 1.6 2012/08/25 19:01:45 marcum Exp $ * Copyright 1994-2012, David L. Marcum */ DOUBLE_1D *save = NULL; INT_1D *node_map = NULL; INT_ i, i0, ibface, ielem, ierr, inode, inode1, inode2, inode3, inode4, inode5, inode6, inode7, inode8, iquad, jnode; inode = 1; ibface = 1; while (ibface <= nbface && inode > 0) { inode1 = inibf[ibface][0]; inode2 = inibf[ibface][1]; inode3 = inibf[ibface][2]; inode = MIN (inode, inode1); inode = MIN (inode, inode2); inode = MIN (inode, inode3); ++ibface; } iquad = 1; while (iquad <= nquad && inode > 0) { inode1 = iniq[iquad][0]; inode2 = iniq[iquad][1]; inode3 = iniq[iquad][2]; inode4 = iniq[iquad][3]; inode = MIN (inode, inode1); inode = MIN (inode, inode2); inode = MIN (inode, inode3); inode = MIN (inode, inode4); ++iquad; } ielem = 1; while (ielem <= nelem && inode > 0) { inode1 = iniel[ielem][0]; inode2 = iniel[ielem][1]; inode3 = iniel[ielem][2]; inode4 = iniel[ielem][3]; inode = MIN (inode, inode1); inode = MIN (inode, inode2); inode = MIN (inode, inode3); inode = MIN (inode, inode4); ++ielem; } ielem = 1; while (ielem <= nelemc5 && inode > 0) { inode1 = inielc5[ielem][0]; inode2 = inielc5[ielem][1]; inode3 = inielc5[ielem][2]; inode4 = inielc5[ielem][3]; inode5 = inielc5[ielem][4]; inode = MIN (inode, inode1); inode = MIN (inode, inode2); inode = MIN (inode, inode3); inode = MIN (inode, inode4); inode = MIN (inode, inode5); ++ielem; } ielem = 1; while (ielem <= nelemc6 && inode > 0) { inode1 = inielc6[ielem][0]; inode2 = inielc6[ielem][1]; inode3 = inielc6[ielem][2]; inode4 = inielc6[ielem][3]; inode5 = inielc6[ielem][4]; inode6 = inielc6[ielem][5]; inode = MIN (inode, inode1); inode = MIN (inode, inode2); inode = MIN (inode, inode3); inode = MIN (inode, inode4); inode = MIN (inode, inode5); inode = MIN (inode, inode6); ++ielem; } ielem = 1; while (ielem <= nelemc8 && inode > 0) { inode1 = inielc8[ielem][0]; inode2 = inielc8[ielem][1]; inode3 = inielc8[ielem][2]; inode4 = inielc8[ielem][3]; inode5 = inielc8[ielem][4]; inode6 = inielc8[ielem][5]; inode7 = inielc8[ielem][6]; inode8 = inielc8[ielem][7]; inode = MIN (inode, inode1); inode = MIN (inode, inode2); inode = MIN (inode, inode3); inode = MIN (inode, inode4); inode = MIN (inode, inode5); inode = MIN (inode, inode6); inode = MIN (inode, inode7); inode = MIN (inode, inode8); ++ielem; } if (inode == 0) { i0 = 1; for (ibface = 1; ibface <= nbface; ++ibface) { inibf[ibface][0] = inibf[ibface][0] + i0; inibf[ibface][1] = inibf[ibface][1] + i0; inibf[ibface][2] = inibf[ibface][2] + i0; } for (iquad = 1; iquad <= nquad; ++iquad) { iniq[iquad][0] = iniq[iquad][0] + i0; iniq[iquad][1] = iniq[iquad][1] + i0; iniq[iquad][2] = iniq[iquad][2] + i0; iniq[iquad][3] = iniq[iquad][3] + i0; } } else i0 = 0; ierr = 0; save = (DOUBLE_1D *) ug_malloc (&ierr, (nnode+1) * sizeof (DOUBLE_1D)); if (ierr > 0) return (100315); ierr = ug3_bnd_nodes (-1, nnodeb, nnode, nbface, nquad, inibf, iniq, &node_map, del, ds, x); if (ierr != 0) { ug_free (save); ug_free (node_map); if (ierr > 0) return (1); else return (0); } for (i = 0; i <=2; ++i) { for (inode = 1; inode <= nnode; ++inode) { save[inode] = x[inode][i]; } for (inode = 1; inode <= nnode; ++inode) { jnode = node_map[inode]; x[jnode][i] = save[inode]; } } if (del != NULL) { for (inode = 1; inode <= nnode; ++inode) { save[inode] = del[inode]; } for (inode = 1; inode <= nnode; ++inode) { jnode = node_map[inode]; del[jnode] = save[inode]; } } if (ds != NULL) { for (inode = 1; inode <= nnode; ++inode) { save[inode] = ds[inode]; } for (inode = 1; inode <= nnode; ++inode) { jnode = node_map[inode]; ds[jnode] = save[inode]; } } ug_free (save); for (ibface = 1; ibface <= nbface; ++ibface) { inode1 = inibf[ibface][0]; inode2 = inibf[ibface][1]; inode3 = inibf[ibface][2]; inibf[ibface][0] = node_map[inode1]; inibf[ibface][1] = node_map[inode2]; inibf[ibface][2] = node_map[inode3]; } for (iquad = 1; iquad <= nquad; ++iquad) { inode1 = iniq[iquad][0]; inode2 = iniq[iquad][1]; inode3 = iniq[iquad][2]; inode4 = iniq[iquad][3]; iniq[iquad][0] = node_map[inode1]; iniq[iquad][1] = node_map[inode2]; iniq[iquad][2] = node_map[inode3]; iniq[iquad][3] = node_map[inode4]; } for (ielem = 1; ielem <= nelem; ++ielem) { inode1 = iniel[ielem][0] + i0; inode2 = iniel[ielem][1] + i0; inode3 = iniel[ielem][2] + i0; inode4 = iniel[ielem][3] + i0; iniel[ielem][0] = node_map[inode1]; iniel[ielem][1] = node_map[inode2]; iniel[ielem][2] = node_map[inode3]; iniel[ielem][3] = node_map[inode4]; } for (ielem = 1; ielem <= nelemc5; ++ielem) { inode1 = inielc5[ielem][0] + i0; inode2 = inielc5[ielem][1] + i0; inode3 = inielc5[ielem][2] + i0; inode4 = inielc5[ielem][3] + i0; inode5 = inielc5[ielem][4] + i0; inielc5[ielem][0] = node_map[inode1]; inielc5[ielem][1] = node_map[inode2]; inielc5[ielem][2] = node_map[inode3]; inielc5[ielem][3] = node_map[inode4]; inielc5[ielem][4] = node_map[inode5]; } for (ielem = 1; ielem <= nelemc6; ++ielem) { inode1 = inielc6[ielem][0] + i0; inode2 = inielc6[ielem][1] + i0; inode3 = inielc6[ielem][2] + i0; inode4 = inielc6[ielem][3] + i0; inode5 = inielc6[ielem][4] + i0; inode6 = inielc6[ielem][5] + i0; inielc6[ielem][0] = node_map[inode1]; inielc6[ielem][1] = node_map[inode2]; inielc6[ielem][2] = node_map[inode3]; inielc6[ielem][3] = node_map[inode4]; inielc6[ielem][4] = node_map[inode5]; inielc6[ielem][5] = node_map[inode6]; } for (ielem = 1; ielem <= nelemc8; ++ielem) { inode1 = inielc8[ielem][0] + i0; inode2 = inielc8[ielem][1] + i0; inode3 = inielc8[ielem][2] + i0; inode4 = inielc8[ielem][3] + i0; inode5 = inielc8[ielem][4] + i0; inode6 = inielc8[ielem][5] + i0; inode7 = inielc8[ielem][6] + i0; inode8 = inielc8[ielem][7] + i0; inielc8[ielem][0] = node_map[inode1]; inielc8[ielem][1] = node_map[inode2]; inielc8[ielem][2] = node_map[inode3]; inielc8[ielem][3] = node_map[inode4]; inielc8[ielem][4] = node_map[inode5]; inielc8[ielem][5] = node_map[inode6]; inielc8[ielem][6] = node_map[inode7]; inielc8[ielem][7] = node_map[inode8]; } ug_free (node_map); return (0); }
INT_ ug3_idiel (INT_ nbface, INT_ nelem, INT_ nnode, INT_ *nv, INT_1D * idiel, INT_3D * inibf, INT_4D * iniel) { /* * Set volume ID flag. * * UG3 LIB : Unstructured Grid - General Purpose Routine Library * 3D Version : $Id: ug3_idiel.c,v 1.9 2012/08/25 19:01:45 marcum Exp $ * Copyright 1994-2012, David L. Marcum */ INT_1D *ibcibf = NULL; INT_1D *ielis = NULL; INT_4D *ieliel = NULL; INT_ idmax, idmin, ierr; idmax = ug_max_int (1, nelem, idiel); idmin = ug_min_int (1, nelem, idiel); *nv = 0; if (idmin != idmax) return (0); ierr = 0; ieliel = (INT_4D *) ug_malloc (&ierr, (nelem+1) * sizeof (INT_4D)); ielis = (INT_1D *) ug_malloc (&ierr, (nelem+1) * sizeof (INT_1D)); if (ierr > 0) { ug_free (ieliel); ug_free (ielis); return (100311); } ierr = ug3_ieliel2 (nelem, nnode, iniel, ieliel); if (ierr > 0) { ug_free (ieliel); ug_free (ielis); return (ierr); } ierr = ug3_ieliel2b (nbface, nelem, nnode, ibcibf, inibf, iniel, ieliel); if (ierr > 0) { ug_free (ieliel); ug_free (ielis); return (ierr); } *nv = 0; ug3_iviel (nelem, nv, ieliel, ielis, idiel); ug_free (ieliel); ug_free (ielis); return (ierr); }
INT_ ug3_idielm (INT_ nelem, INT_ nelemc5, INT_ nelemc6, INT_ nelemc8, INT_ nnode, INT_1D * idiel, INT_4D * iniel, INT_5D * inielc5, INT_6D * inielc6, INT_8D * inielc8) { /* * Set volume ID flag in mixed element region. * * UG3 LIB : Unstructured Grid - General Purpose Routine Library * 3D Version : $Id: ug3_idielm.c,v 1.4 2012/08/25 19:01:45 marcum Exp $ * Copyright 1994-2012, David L. Marcum */ INT_1D *idin = NULL; INT_ id, id1, id2, id3, id4, id5, id6, id7, id8, idmax, idmin, ielem, ielemc, ierr, iit, inode, inode1, inode2, inode3, inode4, inode5, inode6, inode7, inode8, nelemc; nelemc = nelemc5 + nelemc6 + nelemc8; if (nelem == 0 || nelemc == 0) return (0); ierr = 0; idin = (INT_1D *) ug_malloc (&ierr, (nnode+1) * sizeof (INT_1D)); if (ierr > 0) { ug_free (idin); return (100313); } for (inode = 1; inode <= nnode; ++inode) { idin[inode] = 0; } for (ielem = 1; ielem <= nelem; ++ielem) { id = idiel[ielem]; inode1 = iniel[ielem][0]; inode2 = iniel[ielem][1]; inode3 = iniel[ielem][2]; inode4 = iniel[ielem][3]; idin[inode1] = id; idin[inode2] = id; idin[inode3] = id; idin[inode4] = id; } iit = 1; do { for (ielem = 1; ielem <= nelemc5; ++ielem) { inode1 = inielc5[ielem][0]; inode2 = inielc5[ielem][1]; inode3 = inielc5[ielem][2]; inode4 = inielc5[ielem][3]; inode5 = inielc5[ielem][4]; id1 = idin[inode1]; id2 = idin[inode2]; id3 = idin[inode3]; id4 = idin[inode4]; id5 = idin[inode5]; idmax = MAX (id1, id2); idmax = MAX (idmax, id3); idmax = MAX (idmax, id4); idmax = MAX (idmax, id5); if (idmax > 0) { idin[inode1] = idmax; idin[inode2] = idmax; idin[inode3] = idmax; idin[inode4] = idmax; idin[inode5] = idmax; } } for (ielem = 1; ielem <= nelemc6; ++ielem) { inode1 = inielc6[ielem][0]; inode2 = inielc6[ielem][1]; inode3 = inielc6[ielem][2]; inode4 = inielc6[ielem][3]; inode5 = inielc6[ielem][4]; inode6 = inielc6[ielem][5]; id1 = idin[inode1]; id2 = idin[inode2]; id3 = idin[inode3]; id4 = idin[inode4]; id5 = idin[inode5]; id6 = idin[inode6]; idmax = MAX (id1, id2); idmax = MAX (idmax, id3); idmax = MAX (idmax, id4); idmax = MAX (idmax, id5); idmax = MAX (idmax, id6); if (idmax > 0) { idin[inode1] = idmax; idin[inode2] = idmax; idin[inode3] = idmax; idin[inode4] = idmax; idin[inode5] = idmax; idin[inode6] = idmax; } } for (ielem = 1; ielem <= nelemc8; ++ielem) { inode1 = inielc8[ielem][0]; inode2 = inielc8[ielem][1]; inode3 = inielc8[ielem][2]; inode4 = inielc8[ielem][3]; inode5 = inielc8[ielem][4]; inode6 = inielc8[ielem][5]; inode7 = inielc8[ielem][6]; inode8 = inielc8[ielem][7]; id1 = idin[inode1]; id2 = idin[inode2]; id3 = idin[inode3]; id4 = idin[inode4]; id5 = idin[inode5]; id6 = idin[inode6]; id7 = idin[inode7]; id8 = idin[inode8]; idmax = MAX (id1, id2); idmax = MAX (idmax, id3); idmax = MAX (idmax, id4); idmax = MAX (idmax, id5); idmax = MAX (idmax, id6); idmax = MAX (idmax, id7); idmax = MAX (idmax, id8); if (idmax > 0) { idin[inode1] = idmax; idin[inode2] = idmax; idin[inode3] = idmax; idin[inode4] = idmax; idin[inode5] = idmax; idin[inode6] = idmax; idin[inode7] = idmax; idin[inode8] = idmax; } } idmax = idin[1]; idmin = idin[1]; for (inode = 2; inode <= nnode; ++inode) { idmax = MAX (idmax, idin[inode]); idmin = MIN (idmin, idin[inode]); } ++iit; } while (iit < nelemc && idmin == 0); ielemc = nelem; for (ielem = 1; ielem <= nelemc5; ++ielem) { ++ielemc; inode1 = inielc5[ielem][0]; idiel[ielemc] = idin[inode1]; } for (ielem = 1; ielem <= nelemc6; ++ielem) { ++ielemc; inode1 = inielc6[ielem][0]; idiel[ielemc] = idin[inode1]; } for (ielem = 1; ielem <= nelemc8; ++ielem) { ++ielemc; inode1 = inielc8[ielem][0]; idiel[ielemc] = idin[inode1]; } ug_free (idin); 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); }