<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package usda.weru.weps.wepsRunControl;

import de.schlichtherle.truezip.file.TFile;
import de.schlichtherle.truezip.file.TFileReader;
import java.io.BufferedReader;
import java.io.EOFException;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; 

/**
 *
 * @author wjr
 */
public class ExtractStationFromWDB {

    private static final Logger LOGGER = LogManager.getLogger(ExtractStationFromWDB.class);

    static String wdbName = "c:/weps.svn/weps.install/db/wind_gen/wind_gen_his_upper_US.wdb";
    static String testStat = "722615";
    static String outDir = "c:/weps.svn/weps.install/test";
    /*
     * one less than actual since 1st is already in inpLin
     */
    static int linesToCopy = 212;

    /**
     *
     * @param wdb
     * @param outDir
     * @param stat
     * @throws FileNotFoundException
     * @throws IOException
     */
    public ExtractStationFromWDB(TFile wdb, String outDir, String stat) throws FileNotFoundException, IOException {

        BufferedReader bfr = new BufferedReader(new TFileReader(wdb));
        while (true) {
            String inpLin = bfr.readLine();
            if (inpLin == null) {
                bfr.close();
                throw new EOFException("station not found");
            }
            if (inpLin.length() &gt; 10) {
                String[] inpArr = inpLin.substring(0, 10).split(" ");
                if ("#".equals(inpArr[0])) {
//                    System.out.println("inplin " + inpLin);
                    if (stat.equals(inpArr[1])) {
                        try (PrintWriter pw = new PrintWriter(new TFile(outDir, stat))) {
                            pw.println(inpLin);
                            for (int idx = 0; idx &lt; linesToCopy; idx++) {
                                inpLin = bfr.readLine();
                                pw.println(inpLin);
                            }
                        }
                        bfr.close();
                        break;
                    }
                }
            }
        }
    }

    /**
     *
     * @param args
     */
    public static void main(String[] args) {
        try {
            ExtractStationFromWDB esf = new ExtractStationFromWDB(new TFile(wdbName), outDir, testStat);
        } catch (FileNotFoundException ex) {
            LOGGER.fatal("File not found", ex);
        } catch (IOException ex) {
            LOGGER.fatal("IO Error", ex);
        }
    }
}
</pre></body></html>