diff --git a/src/ac/ed/lurg/ModelConfig.java b/src/ac/ed/lurg/ModelConfig.java index cd225506b48c0277e27b42de48ddf3ac8e832255..0bf0e6ef4b5b310cc4b747cae25fb00bfc3abbf3 100644 --- a/src/ac/ed/lurg/ModelConfig.java +++ b/src/ac/ed/lurg/ModelConfig.java @@ -226,6 +226,8 @@ public class ModelConfig { public static final String DOMESTIC_OUTPUT_FILE = OUTPUT_DIR + File.separator + "domestic.txt"; public static final String COUNTRY_DEMAND_FILE = OUTPUT_DIR + File.separator + "countryDemand.txt"; public static final String FOOD_BALANCE_SHEET_FILE = OUTPUT_DIR + File.separator + "fbs.txt"; + public static final String CRAFTY_PRICES_FILE = OUTPUT_DIR + File.separator + "craftyPriceFile.txt"; + public static final String UK_LAND_COVER_OUTPUT_FILE = OUTPUT_DIR + File.separator + "ukLC.txt"; public static final boolean OUTPUT_FOR_LPJG = getBooleanProperty("OUTPUT_FOR_LPJG", true); public static final boolean INTERPOLATE_OUTPUT_YEARS = getBooleanProperty("INTERPOLATE_OUTPUT_YEARS", true); diff --git a/src/ac/ed/lurg/ModelMain.java b/src/ac/ed/lurg/ModelMain.java index b7ebed0cbc29f2e1bc2f83922dddb1d8cb24bb69..a30e8cf4c24f99b2b7c353bb948918d5cd54e711 100644 --- a/src/ac/ed/lurg/ModelMain.java +++ b/src/ac/ed/lurg/ModelMain.java @@ -167,6 +167,8 @@ public class ModelMain { // doesn't change through time if (ModelConfig.GENERATE_NEW_YIELD_CLUSTERS && timestep.isInitialTimestep()) clusterIdRaster.putAll(ca.getYieldClusters()); + + if (ca.getCountry().getName().equals("United Kingdom")) writeUKLandCoverFile(timestep, ca); } internationalMarket.determineInternationalTrade(countryAgents, gen2EcDDemand, timestep); @@ -312,6 +314,46 @@ public class ModelMain { LogWriter.print(e); } } + +private void writeCraftyPricesFile(Timestep timestep){ + + try { + StringBuffer sbHeadings = new StringBuffer("Year, Country, Crop,Import_price, Export_price"); + BufferedWriter outputFile = getFileWriter(timestep, ModelConfig.CRAFTY_PRICES_FILE, sbHeadings.toString()); + + for (CropType crop : CropType.getAllItems()) { + for (CountryAgent country : countryAgents) { + + Map<CropType, CropUsageData> cropUsageAllCrops = country.getCropUsageData(); + CropUsageData cropUsage = cropUsageAllCrops.get(crop); + + if (cropUsage == null) + continue; + + Double importPrice = null; + Double exportPrice = null; + + if (crop.isImportedCrop()) { + CountryPrice px = country.getCurrentCountryPrices().get(crop); + importPrice = px.getImportPrice(); + exportPrice = px.getExportPrice(); + } + + StringBuffer sbData = new StringBuffer(); + sbData.append(String.format("%d,%s,%s", timestep.getYear(), country.getCountry(), crop.getGamsName())); + sbData.append(String.format(",%.3f,%.3f",importPrice, exportPrice)); + + outputFile.write(sbData.toString()); + outputFile.newLine(); + } + } + outputFile.close(); + + } catch (IOException e) { + LogWriter.print(e); + } +} + private void writeDomesticProductionFile(Timestep timestep) { try { @@ -361,6 +403,40 @@ private void writeDomesticProductionFile(Timestep timestep) { } } +private void writeUKLandCoverFile(Timestep timestep, CountryAgent ca){ + + try { + StringBuffer sbHeadings = new StringBuffer("Year,Cropland,Pasture,ManForest,UnmanForest,Natural,AbPasture,EnergyCrop,FertCrop,IrrigCrop"); + BufferedWriter outputFile = getFileWriter(timestep, ModelConfig.UK_LAND_COVER_OUTPUT_FILE, sbHeadings.toString()); + + StringBuffer sbData = new StringBuffer(); + + Collection<RasterKey> countryKeys = countryBoundaryRaster.getKeysFor(ca.getCountry()); + + RasterSet<LandUseItem> ukLandUse = globalLandUseRaster.createSubsetForKeys(countryKeys); + + + sbData.append(String.format("%d,%.1f,%.1f,%.1f,%.1f,%.1f,%.1f", timestep.getYear(), + LandUseItem.getTotalLandCover(ukLandUse.values(), LandCoverType.CROPLAND), + LandUseItem.getTotalLandCover(ukLandUse.values(), LandCoverType.PASTURE), + LandUseItem.getTotalLandCover(ukLandUse.values(), LandCoverType.MANAGED_FOREST), + LandUseItem.getTotalLandCover(ukLandUse.values(), LandCoverType.UNMANAGED_FOREST), + LandUseItem.getTotalLandCover(ukLandUse.values(), LandCoverType.OTHER_NATURAL), + LandUseItem.getAbandonedPasture(ukLandUse.values())) + ); + + sbData.append(String.format(",%.1f", LandUseItem.getTotalCropArea(ukLandUse.values(), CropType.ENERGY_CROPS))); + sbData.append(String.format(",%.1f", LandUseItem.getFertiliserTotal(ukLandUse.values(), CropType.getCropsLessPasture()) / 1000)); + sbData.append(String.format(",%.1f", LandUseItem.getIrrigationTotal(ukLandUse.values(), CropType.getCropsLessPasture()))); + + outputFile.write(sbData.toString()); + outputFile.newLine(); + outputFile.close(); + } catch (IOException e) { + LogWriter.print(e); + } +} + private void writeCountryDemandFile(Timestep timestep){ try { @@ -395,6 +471,7 @@ private void writeDomesticProductionFile(Timestep timestep) { writeGlobalMarketFile(timestep); writeDemandFile(timestep); writeDomesticProductionFile(timestep); + writeCraftyPricesFile(timestep); writeCountryDemandFile(timestep); writeGlobalFoodBalanceSheet(timestep, landUseRaster);