void compute_location(Location_options o, RTlocate_Options rtopts, Arr *stations, Arr *arrays, Arr *phases, Pf *pf, Dbptr master_db, Dbptr dbtmp, ORB_Hypocenter hyp, int orbout) { Tbl *ta,*tu; /* Arrival and slowness tables respectively */ Hypocenter h0; int ret_code; Tbl *converge_history,*reason_converged,*residual; Hypocenter *hypo; int niterations; char *vmodel; int i; char *s; int orid; Point origin; double delta, seaz; double **C; float *emodel; int nass; initialize_hypocenter(&h0); /* It is inefficient to reread these from the parameter space on each entry, but preferable to a burdensome argument list */ origin.lat = pfget_double(pf,"center_latitude"); origin.lon = pfget_double(pf,"center_longitude"); origin.z = 0.0; /* This routine translates hyp structure to return tbl of arrival object pointers */ ta = orbhypo_to_genloc(&hyp,phases,stations); /* this is a pure place holder */ tu = newtbl(0); vmodel = pfget_string(pf,"velocity_model_name"); /* By default we use the location transmitted by orbassoc. This can be overriden in the parameter file by using the other options allowed in genloc*/ s=pfget_string(pf,"initial_location_method"); h0.lat = hyp.lat; h0.lon = hyp.lon; h0.z = hyp.depth; h0.time = hyp.time; /* this strange logic is to allow this parameter to be defaulted. If the "initial_location_method" is not defined, or set to "manual", we use the location given by orbassoc. Otherwise we utilize genlocs suite of initial locate options. */ if(s != NULL) if(strcmp(s,"manual")) h0 = initial_locate(ta, tu, o, pf); /* Now compute distance from origin, and process only if the event falls in the specified range */ dist(rad(origin.lat),rad(origin.lon),rad(h0.lat),rad(h0.lon), &delta,&seaz); delta = deg(delta); /* this is the distance sifting test to ignore things outside specified distance range */ if( ((delta>=rtopts.minimum_distance) && (delta <= rtopts.maximum_distance)) ) { /* Location with Generic Gauss_Newton code */ orid = -1; nass = maxtbl(ta); ret_code = ggnloc(h0,ta,tu,o, &converge_history,&reason_converged,&residual); if(ret_code < 0) { elog_notify (0,"ggnloc failed to produce a solution for evid %d\n",hyp.evid); } else { if(ret_code > 0) elog_notify(0,"Warning: %d travel time calculator failures in ggnloc\nSolution ok for evid %d\n", ret_code,hyp.evid); C = dmatrix(0,3,0,3); emodel = (float *) calloc(4,sizeof(float)); if((emodel == NULL) || (*C == NULL) ) elog_die(0,"Malloc error for error arrays\n"); niterations = maxtbl(converge_history); hypo = (Hypocenter *)gettbl(converge_history, niterations-1); predicted_errors(*hypo, ta, tu, o, C, emodel); orid = save_origin(nass,hyp.evid,master_db, dbtmp,*hypo,o,orbout); save_origerr(orid,*hypo,C,dbtmp,orbout); save_assoc(ta, tu, orid, vmodel, *hypo, dbtmp,orbout); elog_notify(0,"orid %d converged in %d iterations\n", orid,niterations); elog_notify(0,"Reason(s) for convergence: \n"); for(i=0;i<maxtbl(reason_converged);++i) elog_notify(0,"%s",gettbl(reason_converged,i)); elog_notify(0,"\n"); s=format_hypo(hypo); elog_notify(0,"%s\n",s); free(emodel); free_matrix((char **)C,0,3,0); free(s); } write_to_logfile(rtopts, orid, hyp.evid, pf, converge_history, reason_converged,residual); if(maxtbl(converge_history)>0)freetbl(converge_history,free); if(maxtbl(reason_converged)>0)freetbl(reason_converged,free); if(maxtbl(residual)>0)freetbl(residual,free); } destroy_data_tables(ta, tu); return; }
void child_processing(int newsockfd, struct sockaddr_in cli_addr) { int read_error; int file_to_send = 0; char buffer[BUFFER_SIZE]; char *buffer_for_log; char *ptr; char *p; char *path_to_file_relativ; char *response_header; char str_GET[] = "GET"; char str_HEAD[] = "HEAD"; set_http_status(HTTP_STATUS_OK); //printf("You are in the Childprocess: %d\n", getpid()); bzero(buffer, BUFFER_SIZE); read_error = read(newsockfd, buffer, BUFFER_SIZE - 1); buffer_for_log = buffer; ptr = ""; if(read_error < 0) { error("Error reading from socket"); set_http_status(HTTP_STATUS_INTERNAL_SERVER_ERROR); } path_to_file_relativ = parse_HTTP_msg(buffer); //printf("Path to file relativ: %s\n", path_to_file_relativ); char actualpath [PATH_MAX]; p = strtok(buffer, " "); ptr = realpath(path_to_file_relativ, actualpath); printf("Realpath to File: %s\n", actualpath); printf("Ptr: %s\n", ptr); if(strcmp(p, str_GET) == 0) { if( access( actualpath, F_OK ) == -1 ) { printf("NOT FOUND ACCESS GET "); set_http_status(HTTP_STATUS_NOT_FOUND); } //printf("........test............."); if((file_to_send = open(actualpath, O_RDWR, S_IWRITE | S_IREAD)) < 0) { printf("NOT FOUND FILE TO SEND GET "); set_http_status(HTTP_STATUS_NOT_FOUND); response_header = create_HTTP_response_header(actualpath, buffer); send(newsockfd, response_header, strlen(response_header), 0); error("Error opening file"); } //printf("File to send: %i\n", file_to_send); } if(strcmp(p, str_HEAD) == 0) { struct stat buf; int check; check = stat(actualpath, &buf); if(check < 0) { printf("NOT FOUND ACCESS HEAD "); set_http_status(HTTP_STATUS_NOT_FOUND); } else{ set_http_status(HTTP_STATUS_OK); } } response_header = create_HTTP_response_header(actualpath, buffer); send(newsockfd, response_header, strlen(response_header), 0); if(strcmp(p, str_GET) == 0) { int read_count_bytes = read(file_to_send, buffer, BUFFER_SIZE); int read_count_bytes_for_log = read_count_bytes; while(read_count_bytes > 0) { if(write_to_socket(newsockfd, buffer, read_count_bytes, 1) < 0) { error("Error writing to socket"); set_http_status(HTTP_STATUS_INTERNAL_SERVER_ERROR); } read_count_bytes = read(file_to_send, buffer, BUFFER_SIZE); read_count_bytes_for_log += read_count_bytes; } if(read_count_bytes < 0) { error("Error reading from socket"); set_http_status(HTTP_STATUS_INTERNAL_SERVER_ERROR); } //printf("Here is the message: %.*s\n", read_count_bytes, buffer); if(read_error < 0) { error("Error writing to socket"); set_http_status(HTTP_STATUS_INTERNAL_SERVER_ERROR); } write_to_logfile(cli_addr, path_to_file_relativ, buffer_for_log, read_count_bytes_for_log); } close(newsockfd); }