001    /**
002     * 
003     */
004    package org.wdssii.ltgingest;
005    
006    import java.util.Date;
007    
008    import org.apache.commons.logging.Log;
009    import org.apache.commons.logging.LogFactory;
010    import org.wdssii.core.DataTable;
011    
012    /**
013     * Reads specifically-formatted ASCII files that match a filename convention.
014     * 
015     * The filenames should end in dates of the form 2004071614 except for
016     * an optional suffix. Thus, valid filenames include  2004071614.txt
017     * and ltg_2004071614
018     * 
019     * The data in the files should be formatted as follows:
020     * <pre>
021     * 07/16/04 14:00:06 28.713  -77.425   -18.0  2
022     * 07/16/04 14:00:07 25.184  -79.218   -78.0  2
023     * 07/16/04 14:00:07 25.051  -79.063   -28.0  3
024     * where the columns are date, time, latitude, longitude, peak current, flash-count
025     * It's assumed that all flashes are cloud-to-ground.
026     * 
027     * You can change some aspects of this by invoking the appropriate setter methods.
028     * 
029     * @author lakshman
030     * @see LighningWithDischargeTypeIngest
031     */
032    public class LightningWithFlashCountIngest extends AbstractAsciiLightningIngest {
033            private static Log log = LogFactory.getLog(LightningWithFlashCountIngest.class);
034    
035            public LightningWithFlashCountIngest(){
036                    setDateFormatInFileName("yyyyMMddHH");
037                    setDateFormatInData("MM/dd/yy HH:mm:ss");
038            }
039            
040            @Override
041            protected void addRow(DataTable table, Date ltgTime, String[] fields) {
042                    String latitude = fields[2];
043                    String longitude = fields[3];
044                    String peakCurrent = fields[4];
045                    boolean positive = Double.parseDouble(peakCurrent) > 0;
046                    String count = "1";
047                    boolean isCg = (fields[5].equals("0"));
048                    table.addRow(new String[]{
049                            Integer.toString(table.getNumRows() + 1),
050                            ltgTime.toString(),
051                            latitude,
052                            longitude,
053                            peakCurrent,
054                            (positive? "+" : "-"),
055                            count,
056                            (isCg? "CG" : "IC"),
057                            "1.5"
058                    });
059            }
060    
061            public static void main(String[] args) {
062                    log.warn("Warning! The last column in the ASCII data should be 0 or 1 depending on whether it is Cloud-to-ground or inter-cloud");
063                    final LightningWithFlashCountIngest alg = new LightningWithFlashCountIngest();
064                    alg.setupAndExecute(args);
065            }
066    }