import java.io.*; public class Arccheck { // Copyleft Harvey Greenberg, UW hgreen@u.washington.edu Feb 5 14:59:45 1997 // This loads an ARC/INFO AAT file into an array of objects (see ConArc.java), // processes them, and writes a report. // The first argument is the name of an arc cover. // The second argument is the name of a data item, such as ELEV. // This version can be called only from another class, such as CheckMany.java. // See MainArccheck.java for the standalone version. // This program checks each arc to make certain that the given item matches // on connected arcs. // Exceptions are written to standard error. // The bytelength of the record is hardcoded; this relates to limitations // in ConArc.java // Caveats: // Error handling is neither complete nor elegant // This class and class Arccheck assume a unix style "/" separator, which is // probably not portable. // This will not recognize AAT files which are not stored as "aat.adf". // Class Arccheck assumes a specific item list for the arcs being checked. // Although this is very fast on small files, it uses an n-squared search, // and is slower on larger files. // A commented-out block of code for writing to the AAT is included only for // your edification. // This was compiled and checked under JDK Beta3 under Solaris. public static void acheck (String args[]) throws IOException { int maxid,from,to,elv,reclength = 42, remainder; long fsize; String covername,itemname; System.out.println("starting arc attribute check, version 1.01"); if (args.length < 2){ System.err.println("The cover name and item name are required arguments."); return; } else{ covername = args[0]; itemname = args[1]; } System.err.println("Cover: " + covername + ", itemname: " + itemname ); File f = new File (covername + "/aat.adf"); DataInputStream s = new DataInputStream(new FileInputStream(f)); fsize = f.length(); maxid = (int) fsize / reclength; // System.out.println("File size is " + fsize + " bytes, the max id is " + maxid); ConArc arcs[] = new ConArc[maxid]; if ((fsize % reclength) != 0){ System.err.println("The file size is not a multiple of the expected record length!\nABORTING"); return; } for(int i = 0;i < maxid;i++) { arcs[i] = new ConArc(); arcs[i].readArc(s); } // for s.close(); for(int i = 0;i < maxid;i++){ elv = arcs[i].elev; from = arcs[i].fnode; to = arcs[i].tnode; for(int j = i + 1;j< maxid;j++){ if((arcs[j].tnode == to) || (arcs[j].tnode == from) || (arcs[j].fnode == to) || (arcs[j].fnode == from)){ if(arcs[j].elev != elv) System.err.println("arc-id " + arcs[i].id + " elevation of " + elv + " does not match connected arc-id " + arcs[j].id + " elevation of " + arcs[j].elev); } } } /* No need to write to AAT DataOutputStream t = new DataOutputStream(new FileOutputStream(f)); System.err.println("Writing to to the AAT file."); for(int i = 0;i < maxid;i++){ arcs[i].writeArc(t); } t.close(); */ } }