void write_PDB_dstring (JNIEnv *env, jobject graph, jobject elementRule, void *nGraph, int dimension, dstring *encoding) { char buffer [100], *element; int i, size; void *iterator; g_float *coord; jclass elementRuleClass; jmethodID getElement, getBytes; prepare_get_element (env, elementRule, &elementRuleClass, &getElement, &getBytes); clear_dstring (encoding); size = get_graph_size (nGraph); for (i = 1; i <= size; ++i) { coord = get_3d_coordinates (nGraph, i); element = get_element (env, elementRule, elementRuleClass, getElement, getBytes, graph, i); if (element == NULL) element = "X"; sprintf (buffer, "ATOM %5d %3s %8.3f%8.3f%8.3f \n", i, element, coord [0], coord [1], coord [2]); add_string (encoding, buffer); } for (i = 1; i <= size; ++i) { void *iterator; int k = 0; iterator = get_edge_iterator (nGraph, i); while (has_next_edge (iterator)) { int j; if (k % 6 == 0) { if (k > 0) add_char (encoding, '\n'); add_string (encoding, "CONECT"); sprintf (buffer, "%5d", i); add_string (encoding, buffer); } ++k; j = get_next_edge (iterator); sprintf (buffer, "%5d", j); add_string (encoding, buffer); } free (iterator); add_char (encoding, '\n'); } add_string (encoding, "END\n"); }
void * run_program(void * program_stat) { graph_t c_graph; int memkey, i; status client_program; process_t process_type; mstack_t instruction_stack; thread_status_t thread_info = (thread_status_t)program_stat; instruction_stack = parse_file((char*)thread_info->file); if (instruction_stack != NULL){ c_graph = build_graph(instruction_stack); if (c_graph != NULL) { create_sh_graph(c_graph, get_graph_size(c_graph), &memkey, &client_program.g_header); client_program.cursor = 0; client_program.flag = FALSE; client_program.client_id = thread_info->client_id; for(i = 0; i < MEM_SIZE; i++){ client_program.mem[i] = 0; } process_type = c_graph->first->instruction_process->instruction_type; client_program.mtype = process_type->params->unique_mq_id; free_graph(c_graph); free_stack(instruction_stack); printf("Sending first instruction...\n"); ipc_send(process_type->params, &client_program, sizeof(struct status)); }else{ answer_error_to_client(UNABLE_TO_BUILD_GRAPH, thread_info->client_id); } }else{ answer_error_to_client(errno, thread_info->client_id); errno = 0; } pthread_exit(NULL); }
void * run_program(void * program_stat) { ipc_params_t client_params; stack_t c_stack; graph_t c_graph; int memkey, i; status client_program; process_t process_type; thread_status_t thread_info = (thread_status_t)program_stat; c_stack = parse_file((char*)thread_info->file); c_graph = build_graph(c_stack); if (c_graph != NULL) { create_sh_graph(c_graph, get_graph_size(c_graph), &memkey, &client_program.g_header); client_program.cursor = 0; client_program.flag = FALSE; for(i = 0; i < MEM_SIZE; i++) { client_program.mem[i] = 0; } process_type = c_graph->first->instruction_process->instruction_type; client_program.mtype = process_type->params->unique_mq_id; ipc_send(process_type->params, &client_program, sizeof(struct status)); } else { printf("Entrada incorrecta\n"); } while(!ipc_receive(server_receive_params, &client_program, sizeof(struct status))) sleep(1); client_params = get_params_from_pid(thread_info->client_id, PROGRAM_STATUS, sizeof(struct status)); ipc_open(client_params, O_WRONLY); ipc_send(client_params, &client_program, sizeof(struct status)); ipc_close(client_params); }
void write_CML_dstring (JNIEnv *env, jobject graph, jobject elementRule, void *nGraph, int dimension, dstring *encoding) { char buffer [100], *sep, *element; dstring from, to; int i, k, n; void *iterator; g_float **coordinate; jclass elementRuleClass; jmethodID getElement, getBytes; prepare_get_element (env, elementRule, &elementRuleClass, &getElement, &getBytes); clear_dstring (encoding); n = get_graph_size (nGraph); add_string (encoding, "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"); add_string (encoding, "<!DOCTYPE molecule SYSTEM \"cml.dtd\" []>\n"); add_string (encoding, "<molecule convention=\"MathGraph\">\n"); add_string (encoding, " <atomArray>\n"); add_string (encoding, " <stringArray builtin=\"id\">"); sep = ""; for (i = 1; i <= n; ++i) { add_string (encoding, sep); add_string (encoding, "a"); sprintf (buffer, "%d", i); add_string (encoding, buffer); sep = " "; } add_string (encoding, "</stringArray>\n"); add_string (encoding, " <stringArray builtin=\"elementType\">"); sep = ""; for (i = 1; i <= n; ++i) { element = get_element (env, elementRule, elementRuleClass, getElement, getBytes, graph, i); if (element == NULL) element = "X"; add_string (encoding, sep); add_string (encoding, element); sep = " "; } add_string (encoding, "</stringArray>\n"); coordinate = malloc (n * sizeof (*coordinate)); for (i = 0, k = 1; i < n; i = k++) { coordinate [i] = dimension == 2 ? get_2d_coordinates (nGraph, k) : get_3d_coordinates (nGraph, k); } for (k = 0; k < dimension; ++k) { add_string (encoding, " <floatArray builtin=\""); add_char (encoding, 'x' + k); sprintf (buffer, "%d", dimension); add_string (encoding, buffer); add_string (encoding, "\">"); sep = ""; for (i = 0; i < n; ++i) { add_string (encoding, sep); if (sizeof (g_float) == sizeof (float)) { sprintf (buffer, "%-g", coordinate [i][k]); } else { sprintf (buffer, "%-lg", coordinate [i][k]); } add_string (encoding, buffer); sep = " "; } add_string (encoding, "</floatArray>\n"); } add_string (encoding, " </atomArray>\n"); add_string (encoding, " <bondArray>\n"); from = new_dstring; to = new_dstring; sep = ""; for (i = 1; i <= n; ++i) { void *iterator; iterator = get_edge_iterator (nGraph, i); while (has_next_edge (iterator)) { int j = get_next_edge (iterator); if (j <= i) continue; sprintf (buffer, "%sa", sep); add_string (&from, buffer); add_string (&to, buffer); sprintf (buffer, "%d", i); add_string (&from, buffer); sprintf (buffer, "%d", j); add_string (&to, buffer); sep = " "; } } add_string (encoding, " <stringArray builtin=\"atomRef\">"); add_bytes (encoding, from.base, from.length); add_string (encoding, "</stringArray>\n"); add_string (encoding, " <stringArray builtin=\"atomRef\">"); add_bytes (encoding, to.base, to.length); add_string (encoding, "</stringArray>\n"); add_string (encoding, " </bondArray>\n"); add_string (encoding, "</molecule>\n"); clear_dstring (&from); clear_dstring (&to); }