104ea5bd4SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
304ea5bd4SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
404ea5bd4SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
504ea5bd4SAndrew Rist  * distributed with this work for additional information
604ea5bd4SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
704ea5bd4SAndrew Rist  * to you under the Apache License, Version 2.0 (the
804ea5bd4SAndrew Rist  * "License"); you may not use this file except in compliance
904ea5bd4SAndrew Rist  * with the License.  You may obtain a copy of the License at
1004ea5bd4SAndrew Rist  *
1104ea5bd4SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
1204ea5bd4SAndrew Rist  *
1304ea5bd4SAndrew Rist  * Unless required by applicable law or agreed to in writing,
1404ea5bd4SAndrew Rist  * software distributed under the License is distributed on an
1504ea5bd4SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1604ea5bd4SAndrew Rist  * KIND, either express or implied.  See the License for the
1704ea5bd4SAndrew Rist  * specific language governing permissions and limitations
1804ea5bd4SAndrew Rist  * under the License.
1904ea5bd4SAndrew Rist  *
2004ea5bd4SAndrew Rist  *************************************************************/
2104ea5bd4SAndrew Rist 
2204ea5bd4SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir import java.io.*;
25cdf0e10cSrcweir import java.util.*;
26cdf0e10cSrcweir 
27cdf0e10cSrcweir public class pdbcomparison
28cdf0e10cSrcweir {
29cdf0e10cSrcweir 
30cdf0e10cSrcweir   private String LOGTAG  ="LOGFILE";
31cdf0e10cSrcweir   private String OUTTAG  ="OUTFILE";
32cdf0e10cSrcweir   private String LISTTAG ="LISTFILE";
33cdf0e10cSrcweir   private String PDBTAG1 ="PDBNAME1";
34cdf0e10cSrcweir   private String PDBTAG2 ="PDBNAME2";
35cdf0e10cSrcweir 
36cdf0e10cSrcweir   private String OUTFILE="pdbcomparison.out";
37cdf0e10cSrcweir   private String LOGFILE="pdbcomparison.log";
38cdf0e10cSrcweir 
39cdf0e10cSrcweir   private String pdbarr1[];
40cdf0e10cSrcweir   private String pdbarr2[];
41cdf0e10cSrcweir 
42cdf0e10cSrcweir 
43cdf0e10cSrcweir    /**
44cdf0e10cSrcweir    * Default Constructor
45cdf0e10cSrcweir    *
46cdf0e10cSrcweir    *  @param
47cdf0e10cSrcweir    *  @return
48cdf0e10cSrcweir    *
49cdf0e10cSrcweir    */
pdbcomparison()50cdf0e10cSrcweir    public void pdbcomparison()
51cdf0e10cSrcweir    {
52cdf0e10cSrcweir    }
53cdf0e10cSrcweir 
54cdf0e10cSrcweir    /**
55cdf0e10cSrcweir    * Prints the command line arguments for this class
56cdf0e10cSrcweir    *
57cdf0e10cSrcweir    * @param
58cdf0e10cSrcweir    *
59cdf0e10cSrcweir    * @return void
60cdf0e10cSrcweir    *
61cdf0e10cSrcweir    */
usage()62cdf0e10cSrcweir    public void usage()
63cdf0e10cSrcweir    {
64cdf0e10cSrcweir       String str = new String();
65cdf0e10cSrcweir       str += "********************************************************\n";
66cdf0e10cSrcweir       str += " java pdbcomparison.java <propFile> \n";
67cdf0e10cSrcweir       str += "   where propFile is name of Property File...\n";
68cdf0e10cSrcweir       str += "********************************************************\n";
69cdf0e10cSrcweir 
70cdf0e10cSrcweir       System.out.println(str);
71cdf0e10cSrcweir 
72cdf0e10cSrcweir    }
73cdf0e10cSrcweir 
74cdf0e10cSrcweir    /**
75cdf0e10cSrcweir    * This method, read the Property file and validates the
76cdf0e10cSrcweir    * entries in that file, and accordingly sets the log file
77cdf0e10cSrcweir    * output file and updates the array pdbarr1 and pdbarr2 with
78cdf0e10cSrcweir    * list of pdb's to be compared.
79cdf0e10cSrcweir    *
80cdf0e10cSrcweir    * @param propFile Property filename which list the log/outputfile/list/pdb
81cdf0e10cSrcweir    *                 names
82cdf0e10cSrcweir    * @return
83cdf0e10cSrcweir    *
84cdf0e10cSrcweir    */
parsePropertyFile(String propFile)85cdf0e10cSrcweir    public void parsePropertyFile(String propFile)
86cdf0e10cSrcweir    {
87cdf0e10cSrcweir      Properties defaultProps = new Properties();
88cdf0e10cSrcweir 
89cdf0e10cSrcweir      try {
90cdf0e10cSrcweir        FileInputStream in = new FileInputStream(propFile);
91cdf0e10cSrcweir        defaultProps.load(in);
92cdf0e10cSrcweir        in.close();
93cdf0e10cSrcweir      } catch (IOException e) {
94cdf0e10cSrcweir        System.out.println("Could not open Property File " + propFile);
95cdf0e10cSrcweir        return;
96cdf0e10cSrcweir      }
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 
99cdf0e10cSrcweir      String logFile  = defaultProps.getProperty(this.LOGTAG);
100cdf0e10cSrcweir      String outFile  = defaultProps.getProperty(this.OUTTAG);
101cdf0e10cSrcweir      String listFile = defaultProps.getProperty(this.LISTTAG);
102cdf0e10cSrcweir      String pdbname1 = defaultProps.getProperty(this.PDBTAG1);
103cdf0e10cSrcweir      String pdbname2 = defaultProps.getProperty(this.PDBTAG2);
104cdf0e10cSrcweir 
105cdf0e10cSrcweir     // validate all command line arguments
106cdf0e10cSrcweir     if ((listFile == null) && ((pdbname1 == null) || (pdbname2 == null)))
107cdf0e10cSrcweir     {
108cdf0e10cSrcweir        System.out.println("Missing listFile or missing pdb filenames in Property file " + propFile);
109cdf0e10cSrcweir        return;
110cdf0e10cSrcweir     }
111cdf0e10cSrcweir 
112cdf0e10cSrcweir     if (logFile == null || logFile.length() == 0)
113cdf0e10cSrcweir        logFile = this.LOGFILE;
114cdf0e10cSrcweir 
115cdf0e10cSrcweir     if (outFile == null || outFile.length() == 0)
116cdf0e10cSrcweir        outFile = this.LOGFILE;
117cdf0e10cSrcweir 
118cdf0e10cSrcweir 
119cdf0e10cSrcweir      // validate log and output files
120cdf0e10cSrcweir      if (! validateAndCreateFile(logFile)) return;
121cdf0e10cSrcweir      if (! validateAndCreateFile(outFile)) return;
122cdf0e10cSrcweir      LOGFILE = logFile;
123cdf0e10cSrcweir      OUTFILE = outFile;
124cdf0e10cSrcweir 
125cdf0e10cSrcweir      System.out.println("Output is written to log file... " + LOGFILE);
126cdf0e10cSrcweir      if (listFile != null)
127cdf0e10cSrcweir      {
128cdf0e10cSrcweir        if (! checkFile(listFile)) return;
129cdf0e10cSrcweir        populatePDBArray(listFile);
130cdf0e10cSrcweir      } else {
131cdf0e10cSrcweir        if (! checkFile(pdbname1)) return;
132cdf0e10cSrcweir        if (! checkFile(pdbname2)) return;
133cdf0e10cSrcweir        populatePDBArray(pdbname1, pdbname2);
134cdf0e10cSrcweir      }
135cdf0e10cSrcweir    }
136cdf0e10cSrcweir 
137cdf0e10cSrcweir    /**
138cdf0e10cSrcweir    * This method validates if the file passed exists.
139cdf0e10cSrcweir    * If it does , then it is moved to <filename>.bak and then creates a newFile.
140cdf0e10cSrcweir    * Also validates permissions to create.
141cdf0e10cSrcweir    *
142cdf0e10cSrcweir    *  @param  filename  name of file to be created
143cdf0e10cSrcweir    *  @return true, if file could be created
144cdf0e10cSrcweir    *          false, if could not.
145cdf0e10cSrcweir    *
146cdf0e10cSrcweir    */
validateAndCreateFile(String filename)147cdf0e10cSrcweir    private boolean validateAndCreateFile (String filename)
148cdf0e10cSrcweir    {
149cdf0e10cSrcweir      if (filename == null) return false;
150cdf0e10cSrcweir 
151cdf0e10cSrcweir      File f = null;
152cdf0e10cSrcweir      try {
153cdf0e10cSrcweir        f = new File(filename);
154cdf0e10cSrcweir      } catch (NullPointerException e) {
155cdf0e10cSrcweir        System.out.println("Could not create a File object for file " + filename);
156cdf0e10cSrcweir        return false;
157cdf0e10cSrcweir      }
158cdf0e10cSrcweir 
159cdf0e10cSrcweir      if (f.exists())
160cdf0e10cSrcweir      {
161cdf0e10cSrcweir        String newFile = filename + ".bak";
162cdf0e10cSrcweir        File newF=null;
163cdf0e10cSrcweir        try {
164cdf0e10cSrcweir          newF = new File(newFile);
165cdf0e10cSrcweir        } catch (Exception ex) {
166cdf0e10cSrcweir          System.out.println("Could not get File Object instance for " + newFile);
167cdf0e10cSrcweir          return false;
168cdf0e10cSrcweir        }
169cdf0e10cSrcweir 
170cdf0e10cSrcweir        if (newF.exists())
171cdf0e10cSrcweir        {
172cdf0e10cSrcweir          try {
173cdf0e10cSrcweir            newF.delete();
174cdf0e10cSrcweir          } catch ( SecurityException se) {
175cdf0e10cSrcweir            System.out.println("Could not get delete " + newFile);
176cdf0e10cSrcweir            return false;
177cdf0e10cSrcweir          }
178cdf0e10cSrcweir        }
179cdf0e10cSrcweir 
180cdf0e10cSrcweir        try {
181cdf0e10cSrcweir          if (! f.renameTo(newF))
182cdf0e10cSrcweir          {
183cdf0e10cSrcweir              System.out.println("Could not rename " + filename + "  to " + newFile );
184cdf0e10cSrcweir              return false;
185cdf0e10cSrcweir          }
186cdf0e10cSrcweir        } catch  (SecurityException s) {
187cdf0e10cSrcweir              System.out.println("SecurityException: " + s.toString());
188cdf0e10cSrcweir              return false;
189cdf0e10cSrcweir        } catch  (NullPointerException n) {
190cdf0e10cSrcweir              System.out.println("NullPointerException: " + n.toString());
191cdf0e10cSrcweir              return false;
192cdf0e10cSrcweir        }
193cdf0e10cSrcweir      } else {
194cdf0e10cSrcweir        try {
195cdf0e10cSrcweir         if (! f.createNewFile())
196cdf0e10cSrcweir         {
197cdf0e10cSrcweir            System.out.println("Could not create " + filename + " Check permissions..");
198cdf0e10cSrcweir            return false;
199cdf0e10cSrcweir         }
200cdf0e10cSrcweir        } catch (IOException e) {
201cdf0e10cSrcweir            System.out.println("IOException: " + e.toString());
202cdf0e10cSrcweir            return false;
203cdf0e10cSrcweir        } catch  (SecurityException s) {
204cdf0e10cSrcweir            System.out.println("SecuriityException: " + s.toString() );
205cdf0e10cSrcweir            return false;
206cdf0e10cSrcweir        }
207cdf0e10cSrcweir 
208cdf0e10cSrcweir      }
209cdf0e10cSrcweir 
210cdf0e10cSrcweir      return true;
211cdf0e10cSrcweir 
212cdf0e10cSrcweir    }
213cdf0e10cSrcweir 
214cdf0e10cSrcweir    /**
215cdf0e10cSrcweir    * This method validates if the file exists and is readable
216cdf0e10cSrcweir    *
217cdf0e10cSrcweir    *  @param  filename  name of file to be created
218cdf0e10cSrcweir    *  @return true, if file exists and is readable
219cdf0e10cSrcweir    *          false, if not.
220cdf0e10cSrcweir    *
221cdf0e10cSrcweir    */
checkFile(String filename)222cdf0e10cSrcweir    private boolean  checkFile(String filename)
223cdf0e10cSrcweir    {
224cdf0e10cSrcweir      if (filename == null) return false;
225cdf0e10cSrcweir 
226cdf0e10cSrcweir      File f = null;
227cdf0e10cSrcweir      try {
228cdf0e10cSrcweir        f = new File(filename);
229cdf0e10cSrcweir      } catch (NullPointerException e) {
230cdf0e10cSrcweir        System.out.println("Could not create a File object for file " + filename);
231cdf0e10cSrcweir        return false;
232cdf0e10cSrcweir      }
233cdf0e10cSrcweir 
234cdf0e10cSrcweir      if (! f.exists())
235cdf0e10cSrcweir      {
236cdf0e10cSrcweir        System.out.println("File " + filename + " does not exist... ");
237cdf0e10cSrcweir        return false;
238cdf0e10cSrcweir      }
239cdf0e10cSrcweir 
240cdf0e10cSrcweir      if (! f.canRead())
241cdf0e10cSrcweir      {
242cdf0e10cSrcweir        System.out.println("Cannot read file " + filename);
243cdf0e10cSrcweir        return false;
244cdf0e10cSrcweir      }
245cdf0e10cSrcweir 
246cdf0e10cSrcweir      return true;
247cdf0e10cSrcweir 
248cdf0e10cSrcweir    }
249cdf0e10cSrcweir 
250cdf0e10cSrcweir    /**
251cdf0e10cSrcweir    * This method populates the pdb arrays with the names of the pdbs to
252*86e1cf34SPedro Giffuni    * compare. This listFile lists a series of entries, wherein each
253cdf0e10cSrcweir    * line indicates the PDB names to be compared.
254cdf0e10cSrcweir    * <pdbname1>=<pdbname2>
255cdf0e10cSrcweir    *
256cdf0e10cSrcweir    *  @param  listFile  name of the listfile
257cdf0e10cSrcweir    *  @return
258cdf0e10cSrcweir    *
259cdf0e10cSrcweir    */
populatePDBArray(String listFile)260cdf0e10cSrcweir    private void  populatePDBArray(String listFile)
261cdf0e10cSrcweir    {
262cdf0e10cSrcweir 	// open ListFile and populate the PDB list to be compared
263cdf0e10cSrcweir 	if (listFile != null)
264cdf0e10cSrcweir 	{
265cdf0e10cSrcweir 	    Properties listProps = new Properties();
266cdf0e10cSrcweir 	    try {
267cdf0e10cSrcweir 		FileInputStream in = new FileInputStream(listFile);
268cdf0e10cSrcweir 		listProps.load(in);
269cdf0e10cSrcweir 		in.close();
270cdf0e10cSrcweir 	    } catch (IOException ex) {
271cdf0e10cSrcweir 		 System.out.println("Could not open List File " + listFile);
272cdf0e10cSrcweir 		 return;
273cdf0e10cSrcweir 	    }
274cdf0e10cSrcweir 
275cdf0e10cSrcweir 	    pdbarr1 = new String[listProps.size()];
276cdf0e10cSrcweir 	    pdbarr2 = new String[listProps.size()];
277cdf0e10cSrcweir 	    Enumeration e = listProps.keys();
278cdf0e10cSrcweir 	    int j=0;
279cdf0e10cSrcweir 	    while (e.hasMoreElements())
280cdf0e10cSrcweir 	    {
281cdf0e10cSrcweir 		    pdbarr1[j] = (String)e.nextElement();
282cdf0e10cSrcweir 		    pdbarr2[j] = listProps.getProperty(pdbarr1[j]);
283cdf0e10cSrcweir                     j++;
284cdf0e10cSrcweir 	    }
285cdf0e10cSrcweir 
286cdf0e10cSrcweir         }
287cdf0e10cSrcweir    }
288cdf0e10cSrcweir 
289cdf0e10cSrcweir    /**
290cdf0e10cSrcweir    * This method populates the pdb arrays with the names of the pdbs to
291cdf0e10cSrcweir    * compare.
292cdf0e10cSrcweir    *
293cdf0e10cSrcweir    *  @param  pdbname1 Name of 2nd PDB file to be compared
294cdf0e10cSrcweir    *  @param  pdbname2 Name of 2nd PDB file to be compared
295cdf0e10cSrcweir    *  @return
296cdf0e10cSrcweir    *
297cdf0e10cSrcweir    */
populatePDBArray(String pdbname1, String pdbname2)298cdf0e10cSrcweir    private void  populatePDBArray(String pdbname1, String pdbname2)
299cdf0e10cSrcweir    {
300cdf0e10cSrcweir       if (pdbname1 == null) return;
301cdf0e10cSrcweir       if (pdbname2 == null) return;
302cdf0e10cSrcweir 
303cdf0e10cSrcweir       if ((pdbname1 != null) && (pdbname2 != null))
304cdf0e10cSrcweir       {
305cdf0e10cSrcweir 	 pdbarr1 = new String[1];
306cdf0e10cSrcweir 	 pdbarr2 = new String[1];
307cdf0e10cSrcweir 
308cdf0e10cSrcweir 	 pdbarr1[0] = pdbname1;
309cdf0e10cSrcweir 	 pdbarr2[0] = pdbname2;
310cdf0e10cSrcweir       }
311cdf0e10cSrcweir    }
312cdf0e10cSrcweir 
313cdf0e10cSrcweir    /**
314cdf0e10cSrcweir    * This method populates the pdb arrays with the names of the pdbs to
315cdf0e10cSrcweir    * compare.
316cdf0e10cSrcweir    *
317cdf0e10cSrcweir    *  @param  arrayno  Array number which corresponds to the pdb array
318cdf0e10cSrcweir    *                   containing  list of pdbs
319cdf0e10cSrcweir    *                   If 1 then send pdbarr1, if 2 send pdbarr2 else null
320cdf0e10cSrcweir    *
321cdf0e10cSrcweir    *  @return PDB string array containing list of PDB's
322cdf0e10cSrcweir    *
323cdf0e10cSrcweir    */
getPDBArray(int arrayno)324cdf0e10cSrcweir    private String[]  getPDBArray(int arrayno)
325cdf0e10cSrcweir    {
326cdf0e10cSrcweir     if (arrayno == 1) return pdbarr1;
327cdf0e10cSrcweir     if (arrayno == 2) return pdbarr2;
328cdf0e10cSrcweir 
329cdf0e10cSrcweir     return null;
330cdf0e10cSrcweir    }
331cdf0e10cSrcweir 
332cdf0e10cSrcweir    /**
333cdf0e10cSrcweir    * This method comares 2 PDB's and returns true if comparison is equal.
334cdf0e10cSrcweir    * It uses the PDB Decoder class to decode to a PDB structure and then
335cdf0e10cSrcweir    * does record comparison
336cdf0e10cSrcweir    *
337cdf0e10cSrcweir    * @param  pdbname1 Name of one  PDB file  to be compared
338cdf0e10cSrcweir    * @param  pdbname2 Name of other  PDB file  to be compared
339cdf0e10cSrcweir    *
340cdf0e10cSrcweir    * @return returns true if both PDB's are equal else returns false
341cdf0e10cSrcweir    *
342cdf0e10cSrcweir    */
comparePDB(String pdbname1, String pdbname2)343cdf0e10cSrcweir    private boolean  comparePDB(String pdbname1, String pdbname2)
344cdf0e10cSrcweir    {
345cdf0e10cSrcweir        PalmDB pdb1=null, pdb2=null;
346cdf0e10cSrcweir        PDBDecoder decoder = new PDBDecoder();
347cdf0e10cSrcweir        try {
348cdf0e10cSrcweir          pdb1 = decoder.parse(pdbname1);
349cdf0e10cSrcweir        } catch (Exception e) {
350cdf0e10cSrcweir          System.out.println("Could not parse PDB " + pdbname1);
351cdf0e10cSrcweir          return false;
352cdf0e10cSrcweir        }
353cdf0e10cSrcweir 
354cdf0e10cSrcweir        try {
355cdf0e10cSrcweir          pdb2 = decoder.parse(pdbname2);
356cdf0e10cSrcweir        } catch (Exception e) {
357cdf0e10cSrcweir          System.out.println("Could not parse PDB " + pdbname2);
358cdf0e10cSrcweir          return false;
359cdf0e10cSrcweir        }
360cdf0e10cSrcweir 
361cdf0e10cSrcweir        if (pdb1.equals(pdb2)) {
362cdf0e10cSrcweir         writeToLog("PDB " + pdbname1 + "  and PDB " + pdbname2 + " are equal");
363cdf0e10cSrcweir 
364cdf0e10cSrcweir         return true;
365cdf0e10cSrcweir        } else {
366cdf0e10cSrcweir         writeToLog("PDB " + pdbname1 + "  and PDB " + pdbname2 + " are not equal");
367cdf0e10cSrcweir         return false;
368cdf0e10cSrcweir        }
369cdf0e10cSrcweir    }
370cdf0e10cSrcweir 
371cdf0e10cSrcweir 
372cdf0e10cSrcweir 
373cdf0e10cSrcweir    /**
374cdf0e10cSrcweir    *  Write message to LOGFILE
375cdf0e10cSrcweir    *
376cdf0e10cSrcweir    *  @param msg Message to be written to log file
377cdf0e10cSrcweir    *  @return
378cdf0e10cSrcweir    *
379cdf0e10cSrcweir    */
writeToLog(String msg)380cdf0e10cSrcweir    private void writeToLog(String msg)
381cdf0e10cSrcweir    {
382cdf0e10cSrcweir      if (msg == null) return;
383cdf0e10cSrcweir 
384cdf0e10cSrcweir      // Get Output Stream from Log file
385cdf0e10cSrcweir      RandomAccessFile raf=null;
386cdf0e10cSrcweir      try {
387cdf0e10cSrcweir       raf = new RandomAccessFile(LOGFILE, "rw");
388cdf0e10cSrcweir      } catch (Exception e) {
389cdf0e10cSrcweir       System.out.println ("Could not open file " + LOGFILE);
390cdf0e10cSrcweir       return;
391cdf0e10cSrcweir      }
392cdf0e10cSrcweir 
393cdf0e10cSrcweir      try {
394cdf0e10cSrcweir            long len = raf.length();
395cdf0e10cSrcweir            raf.seek(len);
396cdf0e10cSrcweir            raf.write(msg.getBytes());
397cdf0e10cSrcweir            raf.write("\n".getBytes());
398cdf0e10cSrcweir       } catch (IOException e) {
399cdf0e10cSrcweir          System.out.println("ERROR: Could not write to File " + LOGFILE);
400cdf0e10cSrcweir          return;
401cdf0e10cSrcweir       }
402cdf0e10cSrcweir    }
403cdf0e10cSrcweir 
404cdf0e10cSrcweir    /**
405cdf0e10cSrcweir    *  Write status of comparison  to OUTFILE
406cdf0e10cSrcweir    *
407cdf0e10cSrcweir    *  @param status Indicates whether comparsion of PDB's PASSED or FAILED
408cdf0e10cSrcweir    *  @param pdbname1 file name of pdb which was compared.
409cdf0e10cSrcweir    *  @param pdbname2 file name of pdb which was compared.
410cdf0e10cSrcweir    *
411cdf0e10cSrcweir    *  @return
412cdf0e10cSrcweir    *
413cdf0e10cSrcweir    */
writeToOutputFile(String status, String pdbname1, String pdbname2)414cdf0e10cSrcweir    private void writeToOutputFile(String status, String pdbname1, String pdbname2)
415cdf0e10cSrcweir    {
416cdf0e10cSrcweir      if (status == null) return;
417cdf0e10cSrcweir      if (pdbname1 == null) return;
418cdf0e10cSrcweir      if (pdbname2 == null) return;
419cdf0e10cSrcweir 
420cdf0e10cSrcweir      String msg = pdbname1 + "=" + pdbname2 + ":" + status;
421cdf0e10cSrcweir 
422cdf0e10cSrcweir      // Get Output Stream from Log file
423cdf0e10cSrcweir      RandomAccessFile raf=null;
424cdf0e10cSrcweir      try {
425cdf0e10cSrcweir       raf = new RandomAccessFile(OUTFILE, "rw");
426cdf0e10cSrcweir      } catch (Exception e) {
427cdf0e10cSrcweir       System.out.println ("Could not open file " + OUTFILE);
428cdf0e10cSrcweir       return;
429cdf0e10cSrcweir      }
430cdf0e10cSrcweir 
431cdf0e10cSrcweir      try {
432cdf0e10cSrcweir            long len = raf.length();
433cdf0e10cSrcweir            raf.seek(len);
434cdf0e10cSrcweir 
435cdf0e10cSrcweir            raf.write(msg.getBytes());
436cdf0e10cSrcweir            raf.write("\n".getBytes());
437cdf0e10cSrcweir       } catch (IOException e) {
438cdf0e10cSrcweir          System.out.println("ERROR: Could not write to File " + OUTFILE);
439cdf0e10cSrcweir          return;
440cdf0e10cSrcweir       }
441cdf0e10cSrcweir 
442cdf0e10cSrcweir      try {
443cdf0e10cSrcweir        raf.close();
444cdf0e10cSrcweir      } catch (Exception e) {
445cdf0e10cSrcweir        System.out.println("ERROR: Could not close File " + OUTFILE);
446cdf0e10cSrcweir        return;
447cdf0e10cSrcweir      }
448cdf0e10cSrcweir 
449cdf0e10cSrcweir    }
450cdf0e10cSrcweir 
451cdf0e10cSrcweir 
452cdf0e10cSrcweir 
453cdf0e10cSrcweir    /**
454cdf0e10cSrcweir    *  Main starting block of execution
455cdf0e10cSrcweir    *
456cdf0e10cSrcweir    *  @param command line args captured in an array of Strings
457cdf0e10cSrcweir    *  @return
458cdf0e10cSrcweir    *
459cdf0e10cSrcweir    */
main(String args[])460cdf0e10cSrcweir    public static void main(String args[])
461cdf0e10cSrcweir    {
462cdf0e10cSrcweir 
463cdf0e10cSrcweir      Date startTime = new Date();
464cdf0e10cSrcweir      pdbcomparison pdbcmp = new pdbcomparison();
465cdf0e10cSrcweir      int nargs = args.length;
466cdf0e10cSrcweir      int status=0;
467cdf0e10cSrcweir 
468cdf0e10cSrcweir      if (nargs != 1)
469cdf0e10cSrcweir      {
470cdf0e10cSrcweir          System.out.println("Incorrect no. of arguments passed...");
471cdf0e10cSrcweir          pdbcmp.usage();
472cdf0e10cSrcweir          System.exit(-1);
473cdf0e10cSrcweir 
474cdf0e10cSrcweir      }
475cdf0e10cSrcweir 
476cdf0e10cSrcweir      String propFile = args[0];
477cdf0e10cSrcweir 
478cdf0e10cSrcweir      File f=null;
479cdf0e10cSrcweir      try {
480cdf0e10cSrcweir        f = new File(propFile);
481cdf0e10cSrcweir      } catch (Exception e) {
482cdf0e10cSrcweir        System.out.println("Exception: Could not open file " + propFile);
483cdf0e10cSrcweir        System.exit(-1);
484cdf0e10cSrcweir      }
485cdf0e10cSrcweir 
486cdf0e10cSrcweir      if (! f.canRead()) {
487cdf0e10cSrcweir        System.out.println("Exception: " + propFile + " is not a file ");
488cdf0e10cSrcweir        System.exit(-1);
489cdf0e10cSrcweir      }
490cdf0e10cSrcweir 
491cdf0e10cSrcweir      if (! f.canRead()) {
492cdf0e10cSrcweir        System.out.println("Exception: Cannot open file for reading. Please check permissions ");
493cdf0e10cSrcweir        System.exit(-1);
494cdf0e10cSrcweir      }
495cdf0e10cSrcweir 
496cdf0e10cSrcweir      // parse Property file
497cdf0e10cSrcweir      pdbcmp.parsePropertyFile(propFile);
498cdf0e10cSrcweir 
499cdf0e10cSrcweir      String pdbarr1[] = pdbcmp.getPDBArray(1);
500cdf0e10cSrcweir      String pdbarr2[] = pdbcmp.getPDBArray(2);
501cdf0e10cSrcweir      if ( (pdbarr1 == null) ||
502cdf0e10cSrcweir           (pdbarr2 == null) ||
503cdf0e10cSrcweir           (pdbarr1.length == 0) ||
504cdf0e10cSrcweir           (pdbarr1.length == 0))
505cdf0e10cSrcweir      {
506cdf0e10cSrcweir        System.out.println("pdbArray is empty. No PDBS to compare... \n");
507cdf0e10cSrcweir        System.exit(-1);
508cdf0e10cSrcweir      }
509cdf0e10cSrcweir 
510cdf0e10cSrcweir 
511cdf0e10cSrcweir      pdbcmp.writeToLog("************** Start *****************");
512cdf0e10cSrcweir      pdbcmp.writeToLog("PDB Comparison: start time " + startTime);
513cdf0e10cSrcweir      for (int i=0; i<pdbarr1.length; i++)
514cdf0e10cSrcweir      {
515cdf0e10cSrcweir        Date pdb_startTime = new Date();
516cdf0e10cSrcweir        pdbcmp.writeToLog("\n");
517cdf0e10cSrcweir        pdbcmp.writeToLog("start time " + pdb_startTime);
518cdf0e10cSrcweir        boolean val = pdbcmp.comparePDB(pdbarr1[i], pdbarr2[i]);
519cdf0e10cSrcweir        Date pdb_endTime = new Date();
520cdf0e10cSrcweir        pdbcmp.writeToLog("end time " + pdb_endTime);
521cdf0e10cSrcweir 
522cdf0e10cSrcweir        if (val) {
523cdf0e10cSrcweir         pdbcmp.writeToOutputFile("PASSED", pdbarr1[i], pdbarr2[i]);
524cdf0e10cSrcweir         status=0;
525cdf0e10cSrcweir        } else {
526cdf0e10cSrcweir         pdbcmp.writeToOutputFile("FAILED", pdbarr1[i], pdbarr2[i]);
527cdf0e10cSrcweir         status=-1;
528cdf0e10cSrcweir        }
529cdf0e10cSrcweir      }
530cdf0e10cSrcweir 
531cdf0e10cSrcweir      Date endTime = new Date();
532cdf0e10cSrcweir      pdbcmp.writeToLog("PDB Comparison: end time " + endTime);
533cdf0e10cSrcweir      pdbcmp.writeToLog("************** End *****************n");
534cdf0e10cSrcweir      pdbcmp.writeToLog("\n");
535cdf0e10cSrcweir 
536cdf0e10cSrcweir      System.exit(status);
537cdf0e10cSrcweir    }
538cdf0e10cSrcweir }
539