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 20040716-142300 except for
016     * an optional suffix. Thus, valid filenames include  20040716-142300.txt
017     * and ltg_20040716-142300
018     * 
019     * The data in the files should be formatted as follows:
020     * <pre>
021     * 03/28/08, 17:35:25.141, 26.735, -74.764, -23.0, 0
022     * 03/28/08, 17:36:13.838, 26.765, -74.777, -26.0, 1
023     * 03/28/08, 17:36:13.865, 26.766, -74.758, -25.0, 0
024     * 03/28/08, 17:37:06.856, 26.765, -74.803, -24.0, 0
025     * </pre>
026     * where the columns are date, time, latitude, longitude, peak current, CG/IC
027     * It's assumed that all flash counts are 1.
028     * 
029     * You can change some aspects of this by invoking the appropriate setter methods.
030     * 
031     * @author lakshman
032     * @see LighningWithFlashCountIngest
033     */
034    public class LightningWithDischargeTypeIngest extends AbstractAsciiLightningIngest {
035            private static Log log = LogFactory.getLog(LightningWithDischargeTypeIngest.class);
036    
037            public LightningWithDischargeTypeIngest(){
038                    setDateFormatInFileName("yyyyMMdd-HHmmss");
039                    setDateFormatInData("MM/dd/yy, HH:mm:ss");
040            }
041            
042            @Override
043            protected void addRow(DataTable table, Date ltgTime, String[] fields) {
044                    String latitude = fields[2];
045                    String longitude = fields[3];
046                    String peakCurrent = fields[4];
047                    boolean positive = Double.parseDouble(peakCurrent) > 0;
048                    String count = "1";
049                    boolean isCg = (fields[5].equals("0"));
050                    table.addRow(new String[]{
051                            Integer.toString(table.getNumRows() + 1),
052                            ltgTime.toString(),
053                            latitude,
054                            longitude,
055                            peakCurrent,
056                            (positive? "+" : "-"),
057                            count,
058                            (isCg? "CG" : "IC"),
059                            "1.5"
060                    });
061            }
062    
063            public static void main(String[] args) {
064                    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");
065                    final LightningWithDischargeTypeIngest alg = new LightningWithDischargeTypeIngest();
066                    alg.setupAndExecute(args);
067            }
068    }