/************************************************************************* Description: This function uses the NOVAS software library to compute the position of the Sun on the local horizon, but for an input time, instead of the current time. Inputs: here - The point on the surface of the earth we are at. time_in - The UTC time in seconds that we need to compute the Sun's position. Outputs: *SunAz - The returned sun azimuth, in degrees from true north. *SunEl - The returned sun elevation, in degrees above the local horizon. **************************************************************************/ void ORPGSUN_NovasComputePosAtTime( site_info here, double *SunAz, double *SunEl, time_t time_in ){ /* The earth and sun body structures. See NOVAS documentation for more information. */ body earth, sun; /* The right ascension, and declination of the sun */ double ra, declination; /* The terrestrial dynamical time (TDT) julian date */ double tdt_julian_date; /* Zenith distance, measured from the local vertical. */ double zenith_distance; /* The Sun's azimuth is measured from the north */ double azimuth; /* rar -right ascension. decr -declination. In equatorial coordinate system */ double rar, decr; /* The distance to the Sun, units of AU, not returned by this function. */ double distanceAU; /* Call NOVAS subroutine set_body to setup Sun and Earth body structures. */ set_body( 0, 10, "Sun", &sun ); set_body( 0, 3, "Earth", &earth ); /* Get the TDT date for the input time. */ Get_tdt_julian_date_at_time( &tdt_julian_date, time_in, ORPGSUN_DELTAT ); /* Call NOVAS routine topo_planet to get the right ascension and declination of the Sun in topographic/equatorial coordinate system. */ topo_planet( tdt_julian_date, &sun, &earth, ORPGSUN_DELTAT, &here, &ra, &declination, &distanceAU ); /* Call NOVAS subroutine equ2hor to convert the Sun's position to local horizon coordinates. */ equ2hor( tdt_julian_date, ORPGSUN_DELTAT, 0.0 /* x_ephemeris */, 0.0 /* y_ephemeris */, &here, ra, declination, 1 /* normal refraction */, &zenith_distance, &azimuth, &rar, &decr ); /* Convert zenith_distance reference point so that the Sun's elevation is referenced to the local horizon. */ *SunEl = 90.0 - zenith_distance; /* Azimuth needs no conversion, its local horizon reference is already true north. */ *SunAz = azimuth; } /* End of ORPGSUN_NovasComputePosAtTime() */
/** * This function uses the NOVAS software library to compute the position * of the Sun on the local horizon, but for an input time, instead of the current time. * * -------------------------------------------------------- * * @param here (site_info) The point on the surface of the earth we are at. * @param deltat (double) The difference between terrestrial dynamical time system 1 time, and universal time. * @param *SunAz (double *) The returned sun azimuth, in degrees from true north. * @param *SunEl (double *) The returned sun elevation, in degrees above the local horizon. * @param time_in (time_t) The utc time in seconds that we need to compute the Sun's position. * * -------------------------------------------------------- */ void rsts_SunNovasComputePosAtTime( site_info here, double deltat, double *SunAz, double *SunEl, time_t time_in ) { /** <b> Local Variables </b> */ /** <ul> */ /** <li><b> body earth,sun </b> - The earth and sun body structures. See NOVAS documentation for more information. </li> */ body earth,sun; /** <li><b> double ra,declination </b> - The right ascension, and declination of the sun </li> */ double ra,declination; /** <li><b> double tdt_julian_date </b> - the current terrestrial dynamical time (TDT) julian date </li> */ double tdt_julian_date; /** <li><b> double zenith_distance </b> - Zenith distance, measured from the local vertical. </li> */ double zenith_distance; /** <li><b> double azimuth </b> - The Sun's azimuth is measured from the north </li> */ double azimuth; /** <li><b> double rar,decr </b> - rar -right ascension. decr -declination. In equatorial coordinate system </li> */ double rar,decr; /** <li><b> double distanceAU </b> - The distance to the Sun, units of AU, not returned by this function. </li> */ double distanceAU; /** </ul> */ /**------------------------------------------------------*/ /** <h3> The following is a detailed description of the steps for rsts_SunNovasComputePosAtTime(): </h3> */ /** Call NOVAS subroutine set_body to setup Sun and Earth body structures. */ set_body(0,10,"Sun",&sun); set_body(0,3,"Earth",&earth); /** Get the TDT date for the input time. */ rsts_get_tdt_julian_date_at_time( &tdt_julian_date, time_in); /** Call NOVOS routine topo_planet to get the right ascension and declination * of the Sun in topographic/equatorial coordinate system. */ topo_planet( tdt_julian_date, &sun, &earth, deltat, &here , &ra , &declination , &distanceAU); /** Call NOVAS subroutine equ2hor to convert the Sun's position to local horizon coordinates. */ equ2hor( tdt_julian_date, deltat, 0.0 /*x_ephemeris*/, 0.0 /*y_ephemeris*/, &here,ra,declination,1/*normal refraction*/, &zenith_distance, &azimuth, &rar,&decr); /** Convert zenith_distance reference point so that the Sun's elevation is referenced to the local horizon. */ *SunEl = 90.0 - zenith_distance; /** Azimuth needs no conversion, its local horizon reference is already true north. */ *SunAz = azimuth; /** Log a message to the test log with the input time, and position of the sun given. */ /** RSTS_LOG_MSG(LOG_RDA_OTEST,"Sun Pos at TDT JD %f - Az %f El %f",tdt_julian_date,*SunAz,*SunEl); */ /** If this is a stand alone unit test, the results of the subroutine are printed * for comparison with the naval observatory's web pages. */ #ifdef _RSTS_SUN_POS_UNIT_TEST printf(" El : %f Az : %f \n", *SunEl, *SunAz); #endif }
void SessionImpl::transmit( const Response& response, const function< void ( const error_code&, size_t ) >& callback ) const { auto hdrs = m_settings->get_default_headers( ); if ( m_resource not_eq nullptr ) { const auto m_resource_headers = m_resource->m_pimpl->m_default_headers; hdrs.insert( m_resource_headers.begin( ), m_resource_headers.end( ) ); } hdrs.insert( m_headers.begin( ), m_headers.end( ) ); auto response_headers = response.get_headers( ); hdrs.insert( response_headers.begin( ), response_headers.end( ) ); auto payload = make_shared< Response >( ); payload->set_headers( hdrs ); payload->set_body( response.get_body( ) ); payload->set_version( response.get_version( ) ); payload->set_protocol( response.get_protocol( ) ); payload->set_status_code( response.get_status_code( ) ); payload->set_status_message( response.get_status_message( ) ); if ( payload->get_status_message( ).empty( ) ) { payload->set_status_message( m_settings->get_status_message( payload->get_status_code( ) ) ); } m_request->m_pimpl->m_socket->start_write( Http::to_bytes( payload ), callback ); }
TEST_F(TaskTest, CreateAndDelete) { auto start_time = ews::date_time("2015-01-17T12:00:00Z"); auto end_time = ews::date_time("2015-01-17T12:30:00Z"); auto task = ews::task(); task.set_subject("Something really important to do"); task.set_body(ews::body("Some descriptive body text")); task.set_start_date(start_time); task.set_due_date(end_time); task.set_reminder_enabled(true); task.set_reminder_due_by(start_time); const auto item_id = service().create_item(task); auto created_task = service().get_task(item_id); // Check properties EXPECT_STREQ("Something really important to do", created_task.get_subject().c_str()); EXPECT_EQ(start_time, created_task.get_start_date()); EXPECT_EQ(end_time, created_task.get_due_date()); EXPECT_TRUE(created_task.is_reminder_enabled()); EXPECT_EQ(start_time, created_task.get_reminder_due_by()); ASSERT_NO_THROW({ service().delete_task( std::move(created_task), // Sink argument ews::delete_type::hard_delete, ews::affected_task_occurrences::all_occurrences); });
////////////////////////////////////////////////////////////////////////// // acl AclTask::AclTask( const CString& buckname, const CString& objname, std::map<CString, char>& acls ) : _buckname(buckname) , _objname(objname) { _type = kAcl; char* pow[] = {"read", "write", "read_acp", "write_acp"}; Json::Value json_root; std::map<CString, char>::iterator it = acls.begin(); for (; it != acls.end(); ++ it) { std::string name = CString2string(it->first); char acl = it->second; for (int i = 0; i < ACL_COUNT; ++ i) { if (acl & 0x1) { json_root[name.c_str()].append(pow[i]); } acl >>= 1; } } Json::FastWriter json_writer; std::string body_str = json_writer.write(json_root); set_body(body_str); }
SKY_BOX::SKY_BOX() { set_name("Skybox"); // for debugging // set_color(Color::blue); // build the skybox mesh: LMESHptr sky_mesh = make_shared<LMESH>(); Patch* p = nullptr; //sky_mesh->Sphere(); sky_mesh->UV_BOX(p); p->set_sps_regularity(8.0); p-> set_do_lod(false); //sky_mesh->Cube(); //sky_mesh->Icosahedron(); //sky_mesh->read_file(**(Config::JOT_ROOT()+"/../models/simple/sphere.sm")); //sky_mesh->read_file(**(Config::JOT_ROOT()+"/../models/simple/sphere-no-uvs.sm")); //sky_mesh->read_file(**(Config::JOT_ROOT()+"/../models/simple/icosahedron.sm")); // sky_mesh->update_subdivision(3); //flip normals const double RADIUS =1000; Wvec d = Wpt::Origin()-sky_mesh->get_bb().center(); sky_mesh->transform(Wtransf::scaling(RADIUS)* Wtransf::translation(d),MOD()); //sky_mesh->reverse(); // TODO : make it use skybox texture for the reference image // and proxy surface for the main draw //Skybox renders in default style now //skybox texture only draws the gradient //Translation bug fixed for the 10th time he he //the skybox GEOM contains a bode with the sphere geometry set_body(sky_mesh); //world creation if (_sky_instance) err_msg("SKY_BOX::SKY_BOX: warning: instance exists"); _sky_instance = this; atexit(SKY_BOX::clean_on_exit); WORLD::create(_sky_instance, false); WORLD::undisplay(_sky_instance, false);//otherwise it starts up visible if (Config::get_var_bool("SHOW_SKYBOX",false)) show(); }
void final_error(int c_, const char *m_) { if (!finalized) { set_body(NULL, 0); set_status(c_, m_); finalize(); cleanup(); } }
CharLook::CharLook(const LookEntry& entry) { reset(); set_body(entry.skin); set_hair(entry.hairid); set_face(entry.faceid); for (auto& equip : entry.equips) { add_equip(equip.second); } }
void do_tbb_threads( int max_threads, flogged_ets a[] ) { std::vector< tbb::tbb_thread * > threads; for (int p = 0; p < max_threads; ++p) { threads.push_back( new tbb::tbb_thread ( set_body( a ) ) ); } for (int p = 0; p < max_threads; ++p) { threads[p]->join(); } for(int p = 0; p < max_threads; ++p) { delete threads[p]; } }
SsaCfg* new_ssa_cfg(Cfg *cfg, OptUnit *unit, unsigned flags) { claim(cfg->get_parent() == NULL || cfg->get_parent() == unit, "CFG's parent is not the given optimization unit"); // Must orphan the CFG before reparenting it. Do this by detaching it // from the unit. Otherwise, when the unit body is updated later // (i.e., set to the new SSA form), the parent of its old body (the // CFG) gets set to NULL. set_body(unit, NULL); SsaCfg *ssa = create_ssa_cfg(the_suif_env, cfg, unit, false, false, false, false, false, false, false, false, false); ssa->core.set_underlying_ptr(new SsaCore(ssa)); ssa->core->build(flags); return ssa; }
void Webserver::onHttp(connection_hdl handle){ auto con = socketServer.get_con_from_hdl(handle); std::string path = con->get_resource().substr(1); if(path.length() == 0){ // Default file to serve path = "index.html"; } auto resourcePath = webUtils::pathToResource(path); std::ifstream fin(resourcePath, std::ios::in | std::ios::binary); if(!fin.is_open()){ con->set_status(websocketpp::http::status_code::not_found); return; } std::ostringstream oss; oss << fin.rdbuf(); std::string fileContent = oss.str(); con->set_status(websocketpp::http::status_code::ok); con->set_body(fileContent); }
/* Returns an instance of message_t allocated via new */ message_t *create_message(fish_message_type_t type, const wchar_t *key_in, const wchar_t *val_in) { message_t *msg = new message_t; msg->count = 0; char *key=0; // debug( 4, L"Crete message of type %d", type ); if (key_in) { if (wcsvarname(key_in)) { debug(0, L"Illegal variable name: '%ls'", key_in); return 0; } key = wcs2utf(key_in); if (!key) { debug(0, L"Could not convert %ls to narrow character string", key_in); return 0; } } switch (type) { case SET: case SET_EXPORT: { if (!val_in) { val_in=L""; } wcstring esc = full_escape(val_in); char *val = wcs2utf(esc.c_str()); set_body(msg, (type==SET?SET_MBS:SET_EXPORT_MBS), " ", key, ":", val, "\n", NULL); free(val); break; } case ERASE: { set_body(msg, ERASE_MBS, " ", key, "\n", NULL); break; } case BARRIER: { set_body(msg, BARRIER_MBS, "\n", NULL); break; } case BARRIER_REPLY: { set_body(msg, BARRIER_REPLY_MBS, "\n", NULL); break; } default: { debug(0, L"create_message: Unknown message type"); } } free(key); // debug( 4, L"Message body is '%s'", msg->body ); return msg; }
basic_spaceship::basic_spaceship(phys_agent_specification const& spec, phys_system* system): simple_rigid_body(spec, system), m_t_cfg(new thruster_config< WorldDimensionality::dim2D >(thruster_presets::square_complete())), m_t_system(m_t_cfg) { m_half_width = spec.spec_acc["size"].as< double >() * 0.5; m_mass = spec.spec_acc["mass"].as< double >(); m_rotational_inertia = spec.spec_acc["rotational_inertia"].as< double >(); m_thruster_strength = spec.spec_acc["thruster_strength"].as< double >(); m_sensor_range = spec.spec_acc["sensor_range"].as< double >(); auto world = system->get_world(); b2BodyDef bd; bd.type = b2_dynamicBody; bd.position.Set(0.0f, 0.0f); bd.angle = 0.0f; auto body = world->CreateBody(&bd); b2PolygonShape shape; shape.SetAsBox(m_half_width, m_half_width); b2FixtureDef fd; fd.shape = &shape; fd.density = 1.0f; body->CreateFixture(&fd); // Override mass and rotational inertia // TODO: should be optional parameters, and if unspecified, left as auto b2d defaults b2MassData md; md.center = b2Vec2(0, 0); md.mass = m_mass; md.I = m_rotational_inertia; body->SetMassData(&md); set_body(body); /* phys_sensor_defn sdef(SensorType::Fan); sdef.body = body; sdef.pos = b2Vec2(0, 0); sdef.orientation = 0; sdef.range = m_sensor_range; sdef.type_specific = fan_sensor_data{ b2_pi / 3 }; m_front_sensor = create_sensor(sdef); sdef.orientation = b2_pi; m_rear_sensor = create_sensor(sdef); sdef.orientation = b2_pi / 2; m_left_sensor = create_sensor(sdef); sdef.orientation = -b2_pi / 2; m_right_sensor = create_sensor(sdef); */ phys_sensor_defn sdef(SensorType::Directional); sdef.body = body; sdef.pos = b2Vec2(0, 0); sdef.orientation = 0; sdef.range = m_sensor_range; sdef.type_specific = directional_sensor_data{}; m_front_sensor = create_sensor(sdef); sdef.orientation = b2_pi; m_rear_sensor = create_sensor(sdef); sdef.orientation = b2_pi / 2; m_left_sensor = create_sensor(sdef); sdef.orientation = -b2_pi / 2; m_right_sensor = create_sensor(sdef); m_collisions = 0; m_damage = 0.0; }
static apr_status_t upload_filter(ap_filter_t *f, apr_bucket_brigade *bbout, ap_input_mode_t mode, apr_read_type_e block, apr_off_t nbytes) { char* buf = 0 ; char* p = buf ; char* e ; int ret = APR_SUCCESS ; apr_size_t bytes = 0 ; apr_bucket* b ; apr_bucket_brigade* bbin ; upload_ctx* ctx = (upload_ctx*) f->ctx ; if ( ctx->parse_state == p_done ) { // send an EOS APR_BRIGADE_INSERT_TAIL(bbout, apr_bucket_eos_create(bbout->bucket_alloc) ) ; return APR_SUCCESS ; } /* should be more efficient to do this in-place without resorting * to a new brigade */ bbin = apr_brigade_create(f->r->pool, f->r->connection->bucket_alloc) ; if ( ret = ap_get_brigade(f->next, bbin, mode, block, nbytes) , ret != APR_SUCCESS ) return ret ; for ( b = APR_BRIGADE_FIRST(bbin) ; b != APR_BRIGADE_SENTINEL(bbin) ; b = APR_BUCKET_NEXT(b) ) { const char* ptr = buf ; if ( APR_BUCKET_IS_EOS(b) ) { ctx->parse_state = p_done ; APR_BRIGADE_INSERT_TAIL(bbout, apr_bucket_eos_create(bbout->bucket_alloc) ) ; apr_brigade_destroy(bbin) ; return APR_SUCCESS ; } else if ( apr_bucket_read(b, &ptr, &bytes, APR_BLOCK_READ) == APR_SUCCESS ) { const char* p = ptr ; while ( e = strchr(p, '\n'), ( e && ( e < (ptr+bytes) ) ) ) { const char* ptmp = p ; *e = 0 ; if ( ctx->leftover ) { // this'll be grossly inefficient if we get lots of // little buckets (we don't in my setup:-) ptmp = apr_pstrcat(f->r->pool, ctx->leftover, p, NULL) ; ctx->leftover = 0 ; } switch ( ctx->parse_state ) { case p_none: if ( is_boundary(ctx, ptmp) == boundary_part ) ctx->parse_state = p_head ; break ; case p_head: if ( (! *ptmp) || ( *ptmp == '\r') ) ctx->parse_state = p_field ; else set_header(ctx, ptmp) ; break ; case p_field: switch ( is_boundary(ctx, ptmp) ) { case boundary_part: end_body(ctx) ; ctx->parse_state = p_head ; break ; case boundary_end: end_body(ctx) ; ctx->parse_state = p_end ; break ; case boundary_none: if ( ctx->is_file ) { apr_brigade_puts(bbout, ap_filter_flush, f, ptmp) ; apr_brigade_putc(bbout, ap_filter_flush, f, '\n') ; } else set_body(ctx, ptmp) ; break ; } break ; case p_end: //APR_BRIGADE_INSERT_TAIL(bbout, // apr_bucket_eos_create(bbout->bucket_alloc) ) ; ctx->parse_state = p_done ; case p_done: break ; } if ( e - ptr >= bytes ) break ; p = e + 1 ; } if ( ( ctx->parse_state != p_end ) && ( ctx->parse_state != p_done ) ) { size_t bleft = bytes - (p-ptr) ; ctx->leftover = apr_pstrndup(f->r->pool, p, bleft ) ; #ifdef DEBUG ap_log_rerror(APLOG_MARK,APLOG_DEBUG,0, f->r, "leftover %d bytes\n\t%s\n\t%s\n", bleft, ctx->leftover, p) ; #endif } } } apr_brigade_destroy(bbin) ; return ret ; }
void set_body_gba(GByteArray *gba) { gsize len = gba->len; guint8 *data = g_byte_array_free(gba, FALSE); set_body(data, len); }
void set_body_gstr(GString *gstr) { gsize len = gstr->len; guint8 *data = (guint8*) g_string_free(gstr, FALSE); set_body(data, len); }