home *** CD-ROM | disk | FTP | other *** search
/ linuxmafia.com 2016 / linuxmafia.com.tar / linuxmafia.com / pub / palmos / astro-src-2.1.0beta.tar.gz / astro-src-2.1.0beta.tar / astro-src-2.1.0beta / java / ParseCatalog.java < prev    next >
Text File  |  2000-08-09  |  6KB  |  173 lines

  1. import palmutils.pdb.*;
  2. import java.io.*;
  3. import java.util.*;
  4.  
  5. class CatalogRecord
  6. {
  7.     String harvardRevisedNumber; // 1-4
  8.     String name; // 5-11
  9.     String constellation; //12-14
  10.     String saoCatalog; // 32-37
  11.     String raH2000; //76-77
  12.     String raM2000; //78-79
  13.     String raS2000; //80-83
  14.     String decH2000; //84-86
  15.     String decM2000; //87-88
  16.     String decS2000; //89-90
  17.     String vMag; //103-107
  18.  
  19.     public String toString() 
  20.     {
  21.         return
  22.             name +
  23.             ": CON="+constellation+
  24.             ": HRN="+harvardRevisedNumber+
  25.             ", SAO="+saoCatalog+
  26.             ", RA="+raH2000+":"+raM2000+":"+raS2000+
  27.             ", DEC="+decH2000+":"+decM2000+":"+decS2000+
  28.             ", Mag="+vMag;
  29.     }       
  30. }   
  31.     
  32.     
  33. public class ParseCatalog 
  34. {
  35.     static void encode(String source,
  36.                        String north,
  37.                        String south)
  38.     {
  39.         FileReader fr = null;
  40.         BufferedReader br = null;
  41.         FileWriter fw = null;
  42.         PrintWriter pwNorth = null;
  43.         PrintWriter pwSouth = null;
  44.         
  45.         try 
  46.         {
  47.             /*
  48.              * Open the files
  49.              */
  50.             fr = new FileReader(source);
  51.             br = new BufferedReader(fr);
  52.         }
  53.         catch(Exception e) 
  54.         {
  55.             System.err.println("Could not open "+source+".");
  56.             System.err.println(e.getMessage());
  57.             return;
  58.         }
  59.         try 
  60.         {
  61.             fw = new FileWriter(north);
  62.             pwNorth = new PrintWriter(fw,true);
  63.         }
  64.         catch(Exception ioe) 
  65.         {
  66.             System.err.println("Could not open "+north+".");
  67.             System.err.println(ioe.getMessage());
  68.             return;
  69.         }
  70.         try 
  71.         {
  72.             fw = new FileWriter(south);
  73.             pwSouth = new PrintWriter(fw,true);
  74.         }
  75.         catch(Exception ioe) 
  76.         {
  77.             System.err.println("Could not open "+south+".");
  78.             System.err.println(ioe.getMessage());
  79.             return;
  80.         }
  81.  
  82.         try 
  83.         {
  84.             pwSouth.println("Bright Southern Stars");
  85.             pwNorth.println("Bright Northern Stars");
  86.             
  87.             CatalogRecord cr = new CatalogRecord();
  88.             
  89.             /*
  90.              * Read the records, loading them into the vector
  91.              */
  92.             while (br.ready()) 
  93.             {
  94.                 String buffer = br.readLine();
  95.  
  96.                 cr.harvardRevisedNumber=buffer.substring(0,4).trim();
  97.                 cr.name=buffer.substring(4,11).trim();
  98.                 cr.constellation=buffer.substring(11,14).trim();
  99.                 cr.saoCatalog=buffer.substring(31,37).trim();
  100.                 cr.raH2000=buffer.substring(75,77).trim();
  101.                 cr.raM2000=buffer.substring(77,79).trim();
  102.                 cr.raS2000=buffer.substring(79,83).trim();
  103.                 
  104.                 if (buffer.charAt(83)=='+') // skip plus signs.
  105.                     cr.decH2000=buffer.substring(84,86).trim();
  106.                 else
  107.                     cr.decH2000=buffer.substring(83,86).trim();
  108.                 
  109.                 cr.decM2000=buffer.substring(86,88).trim();
  110.                 cr.decS2000=buffer.substring(88,90).trim();
  111.                 cr.vMag=buffer.substring(102,107).trim();
  112.  
  113.                 try 
  114.                 {
  115.                     String description;
  116.                     if (cr.constellation.length() != 0 &&
  117.                         cr.name.length() != 0)
  118.                         description = cr.constellation +
  119.                             ": " +
  120.                             cr.name +
  121.                             " (SAO"+cr.saoCatalog+")";
  122.                     else
  123.                         description = "SAO"+cr.saoCatalog;
  124.  
  125.                     double decH = Double.valueOf(cr.decH2000).doubleValue();
  126.                     double vMag = Double.valueOf(cr.vMag).doubleValue();
  127.                     if (vMag < 5 && decH > -40) 
  128.                     {
  129.                         pwNorth.println(description+"\t"+
  130.                                         cr.raH2000+"\t"+
  131.                                         cr.raM2000+"\t"+
  132.                                         cr.raS2000+"\t"+
  133.                                         cr.decH2000+"\t"+
  134.                                         cr.decM2000+"\t"+
  135.                                         cr.decS2000+"\t"+
  136.                                         cr.vMag+"\t--");
  137.                     }
  138.                     if (vMag < 5 && decH < 40) 
  139.                     {
  140.                         pwSouth.println(description+"\t"+
  141.                                         cr.raH2000+"\t"+
  142.                                         cr.raM2000+"\t"+
  143.                                         cr.raS2000+"\t"+
  144.                                         cr.decH2000+"\t"+
  145.                                         cr.decM2000+"\t"+
  146.                                         cr.decS2000+"\t"+
  147.                                         cr.vMag+"\t--");
  148.                     }
  149.                 }
  150.                 catch (Exception e) 
  151.                 {
  152.                     System.out.println("Skip:"+cr);
  153.                 }
  154.             }            
  155.         }
  156.         catch (EOFException ee) 
  157.         {
  158.             // do nothing
  159.         }
  160.         catch (Exception e) 
  161.         {
  162.             System.err.println(e);
  163.             e.printStackTrace();
  164.             return;
  165.         }
  166.     }
  167.     
  168.     static void main(String args[]) throws IOException
  169.     {
  170.         encode(args[0],args[1], args[2]);
  171.     }    
  172. }
  173.