// EPS: Elgaard Positioning System: GPS navigation software. // Copyright (C) 1997, 1999 Niels Elgaard Larsen // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // Niels Elgaard Larsen, // import java.awt.*; import java.text.*; import java.util.Locale; class Pone { static int ffGPSTRANS=500; static int ffGARLINK=501; static int ffGRM=502; static int DDD=5; static int MDD=1; static int DMM=2; static int DM=3; static int DMS=4; static int MgDD=98; static int MD=99; static int GRM=100; static int pfGARLINK=ffGARLINK; static int pfGPSTRANS=ffGPSTRANS; static String nstr; static DecimalFormatSymbols dFS=new DecimalFormatSymbols(Locale.US); static int MALL=2000; static String dgSign="\u00B0"; static DecimalFormat DDDFormat = new DecimalFormat("#00.000\u00B0;#00.000\u00B0", dFS); static DecimalFormat MDDFormat = new DecimalFormat("###.000", dFS); static DecimalFormat MDFormat = new DecimalFormat("###"); static DecimalFormat GLFormat = new DecimalFormat("#000.000", dFS); // static NumberFormat Min3Format = (new DecimalFormat("###.000")).getInstance(Locale.US); static DecimalFormat Min3Format = new DecimalFormat("###.000", dFS); static DecimalFormat DMMFormat = new DecimalFormat("###.00", dFS); static DecimalFormat DMFormat = new DecimalFormat("###"); static DecimalFormat dgFormat = new DecimalFormat("###"); static DecimalFormat dgMDFormat = new DecimalFormat("###g"); //static String dgSign="°"; static String mnSign="\u0027"; double p; Pone (){ } Pone (double ff) { p = ff; } double r(){ return (((double) p)*Math.PI/180d); } static Pone str2Pone(String sp, int scol, int pf, int filf) { String colStr; colStr = CAux.getCol(sp,scol,(filf==Pone.ffGPSTRANS)?'\t':' '); try { if (filf==Pone.ffGRM || (filf==Pone.ffGPSTRANS && pf == DDD)){ double rv; int gpos,spi=0; double sign=1d; if (colStr.charAt(spi)=='N' || colStr.charAt(spi)=='E'){ spi=1; } else if (colStr.charAt(spi)=='W' || colStr.charAt(spi)=='S'){ spi=1; sign=-1d; } nstr = colStr.substring(spi, colStr.length()); //rv = sign*Double.valueOf(nstr).doubleValue(); rv = (new Double(nstr)).doubleValue(); if (filf==Pone.ffGRM){ rv = rv/100d; } return (new Pone(rv)); } else { int gpos=0,spi=0; double pg, pm; double pr; int sign=1; // System.out.println("s2Pone filf "+ filf +" " + colStr); // don't check for '°'. Strange things happen if (colStr.charAt(spi)=='N' || colStr.charAt(spi)=='E'){ gpos=1; } else if (colStr.charAt(spi)=='W' || colStr.charAt(spi)=='S'){ gpos=1; sign=-1; } while (colStr.charAt(spi) >= '0' && colStr.charAt(spi)<='9') { spi++; }; pg = Double.valueOf(colStr.substring(gpos,spi)).doubleValue(); spi++; gpos = spi; // This was degrees while (colStr.charAt(spi) >= '0' && colStr.charAt(spi)<='9') { spi++; }; pm = Double.valueOf(colStr.substring(gpos,spi)).doubleValue(); spi++; gpos = spi; while (colStr.charAt(spi) < '0' || colStr.charAt(spi)>'9') { // skip ., spi++; }; gpos = spi; // System.out.println("gpos=" + gpos); while (spi < colStr.length() && colStr.charAt(spi) != '\'') { spi++; }; pm += Double.valueOf("0."+colStr.substring(gpos,spi)).doubleValue(); if (pg<0d){ pm = -pm; } pr = sign*(pg + pm/60d); if (colStr.length()>(spi+1) && (colStr.charAt(spi+1)=='S' ||colStr.charAt(spi+1)=='W')){ pr = -pr; } if (filf==Pone.ffGRM){ pr = pr/100d; } return (new Pone(pr)); } } catch (StringIndexOutOfBoundsException ioe) { System.out.println("Pone " + " \""+sp+"\" "+ "colstr= \""+colStr+"\" scol="+ scol+" "+ioe); ioe.printStackTrace(); return(new Pone(0)); } } static public String ffString(int ff) { if (ff==ffGPSTRANS) { return "gpstrans"; } else if (ff==ffGARLINK) { return "garlink"; } else if (ff==ffGRM) { return "grm"; } else return "?ffString"; } public String toStringMin() { double mn; int dg = (int) Math.abs(p); mn = 60*(Math.abs(p) - (double)dg); return(Min3Format.format(mn+0.0005)); } public String toStringMin0() { double mn; int dg = (int) Math.abs(p); mn = 60*(Math.abs(p) - (double)dg); return(""+(int) mn); } public double toStringSec() { double pa = Math.abs(p); double mn; mn = 60*(Math.abs(pa) - (int)pa); return(60*(mn-(int)mn)); } public int toMin() { return((int)Math.rint(p*60)); } public String toString(int pf) { int dg0; double mn0; int dg2; double mn2; int dg3; double mn3; int lpad =0; int ldpad =0; int dprc=3; double psign; double pa; String dgSign1=dgSign; StringBuffer sbuf = new StringBuffer(20); psign = p/Math.abs(p); pa = Math.abs(p); dg0 = (int) pa; mn0 = 60*(pa - (double)dg0); dg2 = (int) Math.abs(pa+0.005/60d); mn2 = 60*(Math.abs(pa+0.005/60d) - (double)dg2); dg3 = (int) Math.abs(pa+0.0005/60d); mn3 = 60*(Math.abs(pa+0.0005/60d) - (double)dg3); if (pf==DDD) { return(DDDFormat.format(p)); } else if (pf==MALL) { return(""+p); } else if (pf==DMS) { /*dd.mm.ss */ return( dgFormat.format(dg3)+"°"+ (int)mn0+"'"+(int)(60*(mn0 - (int)mn0))+"\""); } else if (pf==MDD) { /*dd.mm.mm */ return( dgFormat.format(dg3)+"°"+ MDDFormat.format(mn3)+"'"); } else if (pf==DM) { /*dd.mm */ return( dgFormat.format(dg2)+"\u00b0"+ DMFormat.format(mn2)+"'"); } else if (pf==DMM) { /*dd.mm.mm */ return(dgFormat.format(dg3)+"\u00b0"+ DMMFormat.format(mn3)+"'"); } else if (pf==Pone.pfGPSTRANS) { /*dd.mm.mm */ return(""+p); } else if (pf==Pone.pfGARLINK) { /*dd.mm.mm */ return(dgFormat.format(dg3)+"\u00b0"+ GLFormat.format(mn3)); } else if (pf==MD){ return(dgMDFormat.format(dg0)+ DMFormat.format(mn0)); } else { return("Wrong Format"); } } }