Ejemplo n.º 1
0
void Material::read_material() {
    if(!m_df)
        return;

    //read material names    
    m_state_names.insert(SOLID,m_df->read_string(m_address + m_mem->material_offset("solid_name")));
    m_state_names.insert(LIQUID,m_df->read_string(m_address + m_mem->material_offset("liquid_name")));
    m_state_names.insert(GAS,m_df->read_string(m_address + m_mem->material_offset("gas_name")));
    m_state_names.insert(POWDER,m_df->read_string(m_address + m_mem->material_offset("powder_name")));
    m_state_names.insert(PASTE,m_df->read_string(m_address + m_mem->material_offset("paste_name")));
    m_state_names.insert(PRESSED, m_df->read_string(m_address + m_mem->material_offset("pressed_name")));

    QString generic_state_name = m_df->read_string(m_address);
    if(!generic_state_name.isEmpty()){
        VIRTADDR template_addr = m_df->get_material_template(generic_state_name + "_TEMPLATE");
        if(template_addr){
            QString template_state = m_df->read_string(template_addr + m_mem->material_offset("solid_name"));
            if(template_state != generic_state_name)
                generic_state_name = template_state;
        }
    }

    m_flags = FlagArray(m_df,m_flag_address);

    if(m_flags.has_flag(24)){
        generic_state_name = m_state_names[SOLID] + tr(" fabric");
    }

    //int material_value = m_df->read_int(m_address + 0x244);

    m_state_names.insert(GENERIC, generic_state_name);
    //m_flags = new FlagArray(m_df,m_flag_address);
}
Ejemplo n.º 2
0
void Plant::read_plant() {
    m_plant_name = m_df->read_string(m_address + m_mem->plant_offset("name"));
    m_plant_name_plural = m_df->read_string(m_address + m_mem->plant_offset("name_plural"));
    m_leaf_name_plural = m_df->read_string(m_address + m_mem->plant_offset("name_leaf_plural"));
    m_seed_name_plural = m_df->read_string(m_address + m_mem->plant_offset("name_seed_plural"));

    m_flags = FlagArray(m_df,m_address+m_mem->plant_offset("flags"));
}
void ItemArmorSubtype::read_data(){
    ItemSubtype::read_data();

    if(m_offset_props != -1){
        m_layer = m_df->read_int(m_address + m_offset_props + m_mem->armor_subtype_offset("layer"));

        if(m_offset_level != -1){
            m_armor_level = m_df->read_byte(m_address + m_offset_level);
        }else{
            m_armor_level = 0;
        }
        if(m_armor_level == 0){
            m_flags.set_flag(IS_CLOTHING,true);
        }

        //if it has an armor level over 0 or can be made from metal, bone or shell, consider it armor
        m_armor_flags = FlagArray(m_df, m_address+m_offset_props);
        if(m_armor_level > 0 ||
                (m_armor_flags.has_flag(ARMOR_METAL) || m_armor_flags.has_flag(ARMOR_BONE) || m_armor_flags.has_flag(ARMOR_SHELL))){
            m_flags.set_flag(IS_ARMOR,true);
        }

        if(m_armor_flags.has_flag(ARMOR_CHAIN)){
            m_name.prepend(tr("Chain "));
            m_name_plural.prepend(tr("Chain "));
        }

        if(!m_flags.has_flag(IS_ARMOR) && !m_flags.has_flag(IS_CLOTHING)){
            LOGW << m_name_plural << "are neither armor nor clothing. setting to clothing by default...";
            m_flags.set_flag(IS_CLOTHING,true);
        }

    }else{
        m_layer = -1;
        m_armor_flags = FlagArray();
        if(m_iType != SHIELD){
            LOGW << "Failed to read armor properties" << m_name;
        }
    }
}
AveragingMSRowProvider::AveragingMSRowProvider(double nWavelengthsAveraging, const string& msPath, const MSSelection& selection, const std::map<size_t, size_t>& selectedDataDescIds, const string& dataColumnName, bool requireModel) :
	MSRowProvider(msPath, selection, selectedDataDescIds, dataColumnName, requireModel)
{
	casacore::MSAntenna antennaTable(_ms.antenna());
	_nAntennae = antennaTable.nrow();
	
	casacore::ROArrayColumn<double> positionColumn(antennaTable, casacore::MSAntenna::columnName(casacore::MSAntennaEnums::POSITION));
	std::vector<Pos> positions(_nAntennae);

	casacore::Array<double> posArr(casacore::IPosition(1, 3));
	for(size_t i=0; i!=_nAntennae; ++i)
	{
		positionColumn.get(i, posArr);
		positions[i] = Pos(posArr.data()[0], posArr.data()[1], posArr.data()[2]);
	}
	
	// dataDescId x ant x ant
	_nElements = selectedDataDescIds.size() * _nAntennae * _nAntennae;
	_averagingFactors.assign(_nElements, 0.0);
	_buffers.resize(_nElements);
	MultiBandData bands(_ms.spectralWindow(), _ms.dataDescription());
	
	double dt = (EndTime() - StartTime()) / (EndTimestep() - StartTimestep());
	Logger::Debug << "Assuming integration time of " << dt * (24.0*60.0*60.0) << " seconds.\n";
	
	size_t element = 0;
	size_t averagingSum = 0, minAvgFactor = std::numeric_limits<size_t>::max(), maxAvgFactor = 0;
	for(size_t a1=0; a1!=_nAntennae; ++a1)
	{
		Pos pos1 = positions[a1];
		for(size_t a2=0; a2!=_nAntennae; ++a2)
		{
			Pos pos2 = positions[a2];
			double dx = std::get<0>(pos1) - std::get<0>(pos2);
			double dy = std::get<1>(pos1) - std::get<1>(pos2);
			double dz = std::get<2>(pos1) - std::get<2>(pos2);
			double dist = sqrt(dx*dx + dy*dy + dz*dz);
			for(std::map<size_t, size_t>::const_iterator spwIter=selectedDataDescIds.begin();
					spwIter!=selectedDataDescIds.end(); ++spwIter)
			{
				BandData band = bands[spwIter->first];
				double lambda = band.SmallestWavelength();
				double nWavelengthsPerIntegration = 2.0 * M_PI * dist / lambda * dt;
				_averagingFactors[element] = std::max<size_t>(size_t(floor(nWavelengthsAveraging / nWavelengthsPerIntegration)), 1);
				averagingSum += _averagingFactors[element];
				if(a1 != a2)
				{
					minAvgFactor = std::min<size_t>(minAvgFactor, _averagingFactors[element]);
					maxAvgFactor = std::max<size_t>(maxAvgFactor, _averagingFactors[element]);
				}
				//Logger::Debug << a1 << '\t' << a2 << '\t' << _averagingFactors[element] << '\n';
				++element;
			}
		}
	}
	Logger::Info << "Averaging factor for longest baseline: " << minAvgFactor << " x . For the shortest: " << maxAvgFactor << " x \n";
	
	_spwIndexToDataDescId.resize(selectedDataDescIds.size());
	for(std::map<size_t, size_t>::const_iterator spwIter=selectedDataDescIds.begin();
		spwIter!=selectedDataDescIds.end(); ++spwIter)
	{
		_spwIndexToDataDescId[spwIter->second] = spwIter->first;
	}
	
	_averageFactorSum = 0.0;
	_rowCount = 0;
	_averagedRowCount = 0;

	_currentData = DataArray(DataShape());
	_currentModel = DataArray(DataShape());
	_currentFlags = FlagArray(DataShape());
	_currentWeights = WeightArray(DataShape());
	_averagedDataDescId = _currentDataDescId;
	_flushPosition = 0;
	
	if(!MSRowProvider::AtEnd())
	{
		bool timestepAvailable = processCurrentTimestep();
		if(!timestepAvailable)
			NextRow();
	}
}