001    /**
002     * 
003     */
004    package org.wdssii.dualpol;
005    
006    import org.apache.commons.logging.Log;
007    import org.apache.commons.logging.LogFactory;
008    import org.wdssii.core.Location;
009    
010    import ucar.nc2.Attribute;
011    
012    
013    /**
014     * 
015     * Deals with properties that may be missing in the IDL files themselves
016     * These are obtained from the environment, so set a Java property of the
017     * form  org.wdssii.dualpol.deltaLat=0.005 to change the value
018     * 
019     * @author lakshman
020     *
021     */
022    public class IDLGridProperties  {
023            private static Log log = LogFactory.getLog(IDLGridProperties.class);
024    
025            private static String getProperty(String name, String defaultValue){
026                    String result = defaultValue;
027                    String userValue = System.getProperty(name);
028                    if ( userValue != null ){
029                            result = userValue;
030                    }
031                    log.info("Using " + result + " for " + name);
032                    return result;
033            }
034            
035            private static float getProperty(String name, float defaultValue){
036                    float result = defaultValue;
037                    String userValue = System.getProperty(name);
038                    if ( userValue != null ){
039                            result = Float.parseFloat(userValue);
040                    }
041                    log.info("Using " + result + " for " + name);
042                    return result;
043            }
044            
045            private float deltaLat;
046            private float deltaLon;
047            private float deltaHeightKms;
048            private float radarLat;
049            private float radarLon;
050            private float radarHtKms;
051            
052            public IDLGridProperties(Attribute radarlat, Attribute radarlon,
053                            Attribute ident, Attribute xdelta, Attribute ydelta, Attribute zdelta){
054            
055                    if ( radarlat != null && radarlon != null ){
056                            radarLat = radarlat.getNumericValue().floatValue();
057                            radarLon = radarlon.getNumericValue().floatValue();
058                            radarHtKms = 0;
059                            log.info("Initializing radar location to " + new Location(radarLat, radarLon, radarHtKms));
060                    } else if ( ident != null && ident.getStringValue().equals("KOUN")){
061                            radarLat = 35.236f;
062                            radarLon = -97.463f;
063                            radarHtKms = 0.377f;
064                            log.info("Initializing radar location to known value for KOUN");
065                    } else {
066                            radarLat = getProperty("org.wdssii.dualpol.radarLat",35.236f);
067                            radarLon = getProperty("org.wdssii.dualpol.radarLon",-97.463f);
068                            radarHtKms  = getProperty("org.wdssii.dualpol.radarHtKms",0.377f);
069                    }
070                    
071                    if ( xdelta != null ){
072                            deltaLon = xdelta.getNumericValue().floatValue() * 0.01f; // km to degrees (approx)
073                    } else {
074                            deltaLon = getProperty("org.wdssii.dualpol.deltaLon",0.005f);
075                    }
076                    
077                    if ( ydelta != null ){
078                            deltaLat = ydelta.getNumericValue().floatValue() * 0.01f; // km to degrees (approx);
079                    } else {
080                            deltaLat = getProperty("org.wdssii.dualpol.deltaLat",0.005f);
081                    }
082                    
083                    if ( zdelta != null ){
084                            deltaHeightKms = zdelta.getNumericValue().floatValue();
085                    } else {
086                            deltaHeightKms = getProperty("org.wdssii.dualpol.deltaHeightKms",0.25f);
087                    }
088                    
089                    log.info("deltaLat=" + deltaLat + " deltaLon=" + deltaLon + " deltaHt=" + deltaHeightKms);
090            }
091    
092            public float getDeltaLat() {
093                    return deltaLat;
094            }
095    
096            public float getDeltaLon() {
097                    return deltaLon;
098            }
099    
100            public float getDeltaHeightKms() {
101                    return deltaHeightKms;
102            }
103    
104            public float getRadarLat() {
105                    return radarLat;
106            }
107    
108            public float getRadarLon() {
109                    return radarLon;
110            }
111    
112            public float getRadarHtKms() {
113                    return radarHtKms;
114            }
115            
116            public String getTypeName(String variableName){
117                    if ( variableName.equals("RH") ){
118                            return "RhoHV";
119                    } else if ( variableName.equals("DZ") ){
120                            return "Reflectivity";
121                    } else if ( variableName.equals("DR") ){
122                            return "Zdr";
123                    } else if ( variableName.equals("KD") ){
124                            return "Kdp";
125                    } else {
126                            return variableName;
127                    }
128            }
129            
130            public static String getFileNameDateFormat(){
131                    return getProperty("org.wdssii.dualpol.fileNameDateFormat","MMddyy_HHmmss");
132            }
133    }