use of org.orekit.time.Month in project Orekit by CS-SI.
the class MarshallSolarActivityFutureEstimation method loadData.
/**
* {@inheritDoc}
*/
public void loadData(final InputStream input, final String name) throws IOException, ParseException, OrekitException {
// select the groups we want to store
final int f107Group;
final int apGroup;
switch(strengthLevel) {
case STRONG:
f107Group = 3;
apGroup = 6;
break;
case AVERAGE:
f107Group = 4;
apGroup = 7;
break;
default:
f107Group = 5;
apGroup = 8;
break;
}
// read the data
final BufferedReader reader = new BufferedReader(new InputStreamReader(input, "UTF-8"));
boolean inData = false;
final TimeScale utc = TimeScalesFactory.getUTC();
DateComponents fileDate = null;
for (String line = reader.readLine(); line != null; line = reader.readLine()) {
line = line.trim();
if (line.length() > 0) {
final Matcher matcher = dataPattern.matcher(line);
if (matcher.matches()) {
// we are in the data section
inData = true;
// extract the data from the line
final int year = Integer.parseInt(matcher.group(1));
final Month month = Month.parseMonth(matcher.group(2));
final AbsoluteDate date = new AbsoluteDate(year, month, 1, utc);
if (fileDate == null) {
// so we compute the file date by adding 6 months to its first entry
if (month.getNumber() > 6) {
fileDate = new DateComponents(year + 1, month.getNumber() - 6, 1);
} else {
fileDate = new DateComponents(year, month.getNumber() + 6, 1);
}
}
// check if there is already an entry for this date or not
boolean addEntry = false;
final Iterator<TimeStamped> iterator = data.tailSet(date).iterator();
if (iterator.hasNext()) {
final LineParameters existingEntry = (LineParameters) iterator.next();
if (existingEntry.getDate().equals(date)) {
// there is an entry for this date
if (existingEntry.getFileDate().compareTo(fileDate) < 0) {
// the entry was read from an earlier file
// we replace it with the new entry as it is fresher
iterator.remove();
addEntry = true;
}
} else {
// it is the first entry we get for this date
addEntry = true;
}
} else {
// it is the first entry we get for this date
addEntry = true;
}
if (addEntry) {
// we must add the new entry
data.add(new LineParameters(fileDate, date, Double.parseDouble(matcher.group(f107Group)), Double.parseDouble(matcher.group(apGroup))));
}
} else {
if (inData) {
// we consider the file is corrupted
throw new OrekitException(OrekitMessages.NOT_A_MARSHALL_SOLAR_ACTIVITY_FUTURE_ESTIMATION_FILE, name);
}
}
}
}
if (data.isEmpty()) {
throw new OrekitException(OrekitMessages.NOT_A_MARSHALL_SOLAR_ACTIVITY_FUTURE_ESTIMATION_FILE, name);
}
firstDate = data.first().getDate();
lastDate = data.last().getDate();
}
Aggregations