List of usage examples for java.util Scanner nextDouble
public double nextDouble()
From source file:simcommunity.TheSim.java
public static void batchSim_completa_percentuali() { Scanner valore = new Scanner(System.in).useLocale(Locale.US); double o; //omogeneit System.out.print("\n==================================="); System.out.print("\nSIMULAZIONE BATCH completa con collegamenti espressi in percentuali\n"); System.out.print("\n==================================="); System.out.print("\n\nNumero individui iniziale "); int comIniziali = valore.nextInt(); System.out.print("Numero individui finale "); int comFinale = valore.nextInt(); System.out.print("Incremento individui "); int incrementocomunita = valore.nextInt(); System.out.print("Percentuale (sul numero di individui) di collegamenti iniziale "); int pcolIniziali = valore.nextInt(); System.out.print("Percentuale (sul numero di individui) di collegamenti finale "); int pcolFinali = valore.nextInt(); System.out.print("Incremento percentuale dei collegamenti "); int pincrementocollegamenti = valore.nextInt(); System.out.print("Dimensione del DNA (meglio multipli di 9) "); GlobalVar.dimDNA = valore.nextInt(); System.out.print(/* w ww. j av a 2 s. c om*/ "Soglia ere massima (limite di cicli oltre i quali il tentativo di omogeneizzazione termina "); GlobalVar.numERE = valore.nextInt(); System.out.print("Soglia di omogeneit "); GlobalVar.omoSoglia = valore.nextDouble(); //modifica //System.out.println("\nind\tcon\tere\tomo"); //Riga degli individui for (int i = comIniziali; i <= comFinale; i = i + incrementocomunita) System.out.print("\t" + i); System.out.println("\tnumero membri della comunit"); for (int j = pcolIniziali; j <= pcolFinali; j = j + pincrementocollegamenti) { System.out.print(j + "%\t"); for (int i = comIniziali; i <= comFinale; i = i + incrementocomunita) { GlobalVar.dimensionecom = i; GlobalVar.numcollegamenti = Math.round(j * i / 100); //il j% della comunit i deve essere connessa o = ciclocomunita(); System.out.print(GlobalVar.ereEffettuate + "\t"); } System.out.println(); } }
From source file:gdsc.smlm.ij.plugins.SpotAnalysis.java
private void saveTraces() { if (!onFrames.isEmpty() && updated) { GenericDialog gd = new GenericDialog(TITLE); gd.enableYesNoCancel();/*from w ww . j ava2 s . co m*/ gd.hideCancelButton(); gd.addMessage("The list contains unsaved selected frames.\n \nDo you want to continue?"); gd.showDialog(); if (!gd.wasOKed()) return; } // For all spots in the results window, get the ID and then save the traces to memory if (!resultsWindowShowing()) return; // Create a results set in memory MemoryPeakResults results = new MemoryPeakResults(); results.setName(TITLE); results.begin(); MemoryPeakResults.addResults(results); ArrayList<TraceResult> traceResults = new ArrayList<TraceResult>( resultsWindow.getTextPanel().getLineCount()); for (int i = 0; i < resultsWindow.getTextPanel().getLineCount(); i++) { String line = resultsWindow.getTextPanel().getLine(i); Scanner s = new Scanner(line); s.useDelimiter("\t"); int id = s.nextInt(); s.nextDouble(); // cx s.nextDouble(); // cy double signal = s.nextDouble(); s.close(); Trace trace = traces.get(id); if (trace != null) { results.addAll(trace.getPoints()); traceResults.add(new TraceResult(new Spot(id, signal), trace)); } } results.end(); saveTracesToFile(traceResults); IJ.showStatus("Saved traces"); }
From source file:org.orekit.files.sp3.SP3Parser.java
/** Parses a header line from the SP3 file (line number 1 - 22). * @param lineNumber the current line number * @param line the line as read from the SP3 file * @param pi the current {@link ParseInfo} object * @throws OrekitException if a non-supported construct is found *///from w ww . jav a 2s . com private void parseHeaderLine(final int lineNumber, final String line, final ParseInfo pi) throws OrekitException { final SP3File file = pi.file; Scanner scanner = null; try { scanner = new Scanner(line).useDelimiter("\\s+").useLocale(Locale.US); // CHECKSTYLE: stop FallThrough check switch (lineNumber) { // version, epoch, data used and agency information case 1: { scanner.skip("#"); final String v = scanner.next(); final char version = v.substring(0, 1).toLowerCase().charAt(0); if (version != 'a' && version != 'b' && version != 'c') { throw new OrekitException(OrekitMessages.SP3_UNSUPPORTED_VERSION, version); } pi.hasVelocityEntries = "V".equals(v.substring(1, 2)); final int year = Integer.parseInt(v.substring(2)); final int month = scanner.nextInt(); final int day = scanner.nextInt(); final int hour = scanner.nextInt(); final int minute = scanner.nextInt(); final double second = scanner.nextDouble(); final AbsoluteDate epoch = new AbsoluteDate(year, month, day, hour, minute, second, TimeScalesFactory.getGPS()); file.setEpoch(epoch); final int numEpochs = scanner.nextInt(); file.setNumberOfEpochs(numEpochs); // data used indicator file.setDataUsed(scanner.next()); file.setCoordinateSystem(scanner.next()); file.setOrbitType(SP3OrbitType.valueOf(scanner.next())); file.setAgency(scanner.next()); break; } // additional date/time references in gps/julian day notation case 2: { scanner.skip("##"); // gps week file.setGpsWeek(scanner.nextInt()); // seconds of week file.setSecondsOfWeek(scanner.nextDouble()); // epoch interval file.setEpochInterval(scanner.nextDouble()); // julian day file.setJulianDay(scanner.nextInt()); // day fraction file.setDayFraction(scanner.nextDouble()); break; } // line 3 contains the number of satellites case 3: pi.maxSatellites = Integer.parseInt(line.substring(4, 6).trim()); // fall-through intended - the line contains already the first entries // the following 4 lines contain additional satellite ids case 4: case 5: case 6: case 7: { final int lineLength = line.length(); int count = file.getSatelliteCount(); int startIdx = 9; while (count++ < pi.maxSatellites && (startIdx + 3) <= lineLength) { final String satId = line.substring(startIdx, startIdx + 3).trim(); file.addSatellite(satId); startIdx += 3; } break; } // the following 5 lines contain general accuracy information for each satellite case 8: case 9: case 10: case 11: case 12: { final int lineLength = line.length(); int satIdx = (lineNumber - 8) * 17; int startIdx = 9; while (satIdx < pi.maxSatellites && (startIdx + 3) <= lineLength) { final SatelliteInformation satInfo = file.getSatellite(satIdx++); final int exponent = Integer.parseInt(line.substring(startIdx, startIdx + 3).trim()); // the accuracy is calculated as 2**exp (in m) -> can be safely // converted to an integer as there will be no fraction satInfo.setAccuracy((int) Math.pow(2d, exponent)); startIdx += 3; } break; } case 13: { file.setType(getFileType(line.substring(3, 5).trim())); // now identify the time system in use final String tsStr = line.substring(9, 12).trim(); final TimeSystem ts = TimeSystem.GPS; if (!tsStr.equalsIgnoreCase("ccc")) { TimeSystem.valueOf(tsStr); } file.setTimeSystem(ts); switch (ts) { case GPS: pi.timeScale = TimeScalesFactory.getGPS(); break; case GAL: pi.timeScale = TimeScalesFactory.getGST(); break; case GLO: case QZS: throw new OrekitException(OrekitMessages.SP3_UNSUPPORTED_TIMESYSTEM, ts.name()); case TAI: pi.timeScale = TimeScalesFactory.getTAI(); break; case UTC: pi.timeScale = TimeScalesFactory.getUTC(); break; default: pi.timeScale = TimeScalesFactory.getGPS(); break; } break; } case 14: // ignore additional custom fields break; // load base numbers for the standard deviations of // position/velocity/clock components case 15: { // String base = line.substring(3, 13).trim(); // if (!base.equals("0.0000000")) { // // (mm or 10**-4 mm/sec) // pi.posVelBase = Double.valueOf(base); // } // base = line.substring(14, 26).trim(); // if (!base.equals("0.000000000")) { // // (psec or 10**-4 psec/sec) // pi.clockBase = Double.valueOf(base); // } break; } case 16: case 17: case 18: // ignore additional custom parameters break; case 19: case 20: case 21: case 22: // ignore comment lines break; default: // ignore -> method should only be called up to line 22 break; } // CHECKSTYLE: resume FallThrough check } finally { if (scanner != null) { scanner.close(); } } }
From source file:gdsc.smlm.ij.plugins.DriftCalculator.java
/** * Read the drift file storing the T,X,Y into the class level calculatedTimepoints, lastdx and lastdy * arrays. Ignore any records where T is outside the limits. * //from w ww. j ava 2 s.c o m * @param limits * @return The number of records read */ private int readDriftFile(int[] limits) { int ok = 0; BufferedReader input = null; try { FileInputStream fis = new FileInputStream(driftFilename); input = new BufferedReader(new UnicodeReader(fis, null)); String line; Pattern pattern = Pattern.compile("[\t, ]+"); while ((line = input.readLine()) != null) { if (line.length() == 0) continue; if (Character.isDigit(line.charAt(0))) { try { Scanner scanner = new Scanner(line); scanner.useDelimiter(pattern); scanner.useLocale(Locale.US); final int t = scanner.nextInt(); if (t < limits[0] || t > limits[1]) continue; final double x = scanner.nextDouble(); final double y = scanner.nextDouble(); calculatedTimepoints[t] = ++ok; lastdx[t] = x; lastdy[t] = y; scanner.close(); } catch (InputMismatchException e) { } catch (NoSuchElementException e) { } } } } catch (IOException e) { // ignore } finally { try { if (input != null) input.close(); } catch (IOException e) { // Ignore } } return ok; }
From source file:gdsc.smlm.ij.plugins.pcpalm.PCPALMFitting.java
/** * Load a correlation curve from file. Will set the global gr, peakDensity and spatialDomain variables. If the data * fails to be loaded then the method will return false. * // www. j av a2 s . c o m * @return True if loaded */ private boolean loadCorrelationCurve() { inputFilename = Utils.getFilename("Input_Correlation_File", inputFilename); if (inputFilename == null) return false; // Set the analysis variables boolean spatialDomainSet = false; boolean peakDensitySet = false; BufferedReader input = null; try { FileInputStream fis = new FileInputStream(inputFilename); input = new BufferedReader(new UnicodeReader(fis, null)); String line; int count = 0; Pattern pattern = Pattern.compile("#([^=]+) = ([^ ]+)"); // Read the header while ((line = input.readLine()) != null) { count++; if (line.length() == 0) continue; if (line.charAt(0) != '#') { // This is the first record break; } // This is a header line. Extract the key-value pair Matcher match = pattern.matcher(line); if (match.find()) { if (match.group(1).equals(HEADER_SPATIAL_DOMAIN)) { // Do not use Boolean.parseBoolean because this will not fail if the field is // neither true/false - it only return true for a match to true spatialDomainSet = true; if (match.group(2).equalsIgnoreCase("true")) spatialDomain = true; else if (match.group(2).equalsIgnoreCase("false")) spatialDomain = false; else // We want to know if the field is not true/false spatialDomainSet = false; } else if (match.group(1).equals(HEADER_PEAK_DENSITY)) { try { peakDensity = Double.parseDouble(match.group(2)); peakDensitySet = true; } catch (NumberFormatException e) { // Ignore this. } } } } if (!peakDensitySet) { IJ.error(TITLE, "No valid " + HEADER_PEAK_DENSITY + " record in file " + inputFilename); return false; } if (!spatialDomainSet) { IJ.error(TITLE, "No valid " + HEADER_SPATIAL_DOMAIN + " record in file " + inputFilename); return false; } // Read the data: gr[0][i], gr[1][i], gr[2][i] ArrayList<double[]> data = new ArrayList<double[]>(); while (line != null) { if (line.length() == 0) continue; if (line.charAt(0) == '#') continue; // Extract the first 3 fields Scanner scanner = new Scanner(line); scanner.useDelimiter("[\t ,]+"); double r, g; try { r = scanner.nextDouble(); g = scanner.nextDouble(); } catch (InputMismatchException e) { IJ.error(TITLE, "Incorrect fields on line " + count); scanner.close(); return false; } catch (NoSuchElementException e) { IJ.error(TITLE, "Incorrect fields on line " + count); scanner.close(); return false; } // Allow the file to be missing the curve error. This is only used for plotting anyway. double error = 0; try { error = scanner.nextDouble(); } catch (InputMismatchException e) { } catch (NoSuchElementException e) { } scanner.close(); data.add(new double[] { r, g, error }); // Read the next line line = input.readLine(); count++; } if (data.isEmpty()) { IJ.error(TITLE, "No data in file " + inputFilename); return false; } gr = new double[3][data.size()]; for (int i = 0; i < data.size(); i++) { final double[] d = data.get(i); gr[0][i] = d[0]; gr[1][i] = d[1]; gr[2][i] = d[2]; } } catch (IOException e) { IJ.error(TITLE, "Unable to read from file " + inputFilename); return false; } finally { try { if (input != null) input.close(); } catch (IOException e) { // Ignore } } return true; }
From source file:InternalFrame.InternalFrameproject.java
private void loadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadActionPerformed String userhome = System.getProperty(constants.getProgrampath()); JFileChooser chooser = new JFileChooser(userhome + "\\" + constants.getProject_input_folder()); FileNameExtensionFilter txtfilter = new FileNameExtensionFilter("emft files (*Emft)", "Emft"); chooser.setDialogTitle(language_internal_frame.LangLabel(constants.getLanguage_option(), 7)); chooser.setFileFilter(txtfilter);/*from w w w .j av a2 s. c om*/ chooser.showOpenDialog(null); File f = chooser.getSelectedFile(); File subor = new File(f.getParent() + "\\" + f.getName()); int pocet_Vysok = 0; try { Scanner input = new Scanner(subor); basicInfoPanel.jTextField_mano.setText(input.nextLine()); basicInfoPanel.jTextField_mano_projektu.setText(input.nextLine()); basicSettingsPanel.jTextField_A.setText(String.valueOf(input.nextDouble())); basicSettingsPanel.jTextField_Z.setText(String.valueOf(input.nextDouble())); basicSettingsPanel.jTextField_H.setText(String.valueOf(input.nextDouble())); basicSettingsPanel.jTextField_krok.setText(String.valueOf(input.nextDouble())); basicSettingsPanel.jTextField_krok_pozorovatela.setText(String.valueOf(input.nextDouble())); input.nextLine(); pocet_Vysok = input.nextInt(); input.nextLine(); int rowCount = observerPanel1.DTMTable.getRowCount();// odsrrani riadky z DTM table for (int i = rowCount - 1; i >= 0; i--) { observerPanel1.isListener = false; observerPanel1.DTMTable.removeRow(i); observerPanel1.isListener = true; } for (int i = 0; i < pocet_Vysok; i++) { observerPanel1.isListener = false; observerPanel1.DTMTable.addRow(new Object[] { input.nextLine() }); observerPanel1.isListener = true; } observerPanel1.Table.selectAll(); // ozna? potom vetky stplce observerPanel1.isListener = false; observerPanel1.DTMTable.addRow(new Object[0]); observerPanel1.isListener = true; int pocet_catenary_riadkov = input.nextInt(); input.nextLine(); rowCount = catenaryPanel1.DTMTable.getRowCount();// odsrrani riadky z DTM table for (int i = rowCount - 1; i >= 0; i--) { catenaryPanel1.isListener = false; catenaryPanel1.DTMTable.removeRow(i); catenaryPanel1.isListener = true; } for (int i = 0; i < pocet_catenary_riadkov; i++) { catenaryPanel1.isListener = false; double V1 = input.nextDouble(); double V2 = input.nextDouble(); double I1 = input.nextDouble(); double I2 = input.nextDouble(); double W1 = input.nextDouble(); double W2 = input.nextDouble(); double X1 = input.nextDouble(); double X2 = input.nextDouble(); int zvazok = input.nextInt(); double alpha = input.nextDouble(); double d = input.nextDouble(); int CH = input.nextInt(); boolean ch = false; if (CH == 1) { ch = true; } double val = input.nextDouble(); double r = input.nextDouble(); double U = input.nextDouble(); double I = input.nextDouble(); double Phi = input.nextDouble(); int pocitaj = input.nextInt(); String lano = input.nextLine(); lano = lano.substring(1); boolean poc = false; if (pocitaj == 1) { poc = true; } // najdi lano v databaze int index = 0; for (int j = 0; j < catenaryPanel1.getConductor_Name_Matrix().size(); j++) { if (lano.equals(catenaryPanel1.getConductor_Name_Matrix().get(j))) { index = j; } } catenaryPanel1.DTMTable.addRow(new Object[] { V1, V2, I1, I2, W1, W2, X1, X2, zvazok, alpha, d, ch, val, r, U, I, Phi, "-", "-", "-", poc, false, lano }); catenaryPanel1.isListener = true; } catenaryPanel1.isListener = false; catenaryPanel1.DTMTable.addRow(new Object[0]); catenaryPanel1.isListener = true; } catch (FileNotFoundException ex) { Logger.getLogger(terenmodel_jDialog.class.getName()).log(Level.SEVERE, null, ex); } }