77import com .bc .fiduceo .location .PixelLocator ;
88import com .bc .fiduceo .reader .AcquisitionInfo ;
99import com .bc .fiduceo .reader .Reader ;
10+ import com .bc .fiduceo .reader .netcdf .StringVariable ;
1011import com .bc .fiduceo .reader .time .TimeLocator ;
1112import com .bc .fiduceo .reader .time .TimeLocator_MillisSince1970 ;
13+ import com .bc .fiduceo .util .NetCDFUtils ;
1214import com .bc .fiduceo .util .VariableProxy ;
1315import org .esa .snap .core .util .StringUtils ;
1416import ucar .ma2 .Array ;
3133class TaoReader implements Reader {
3234
3335 private final static String REG_EX = "(?:TAO|TRITON)_\\ w+_\\ w+(-\\ w+)??\\ d{4}-\\ d{2}.txt" ;
36+ private static final String TIME = "time" ;
37+ private static final String LONGITUDE = "longitude" ;
38+ private static final String LATITUDE = "latitude" ;
39+ private static final String SSS = "SSS" ;
40+ private static final float SSS_FILL = -9.999f ;
41+ private static final String SST = "SST" ;
42+ private static final float SST_FILL = -9.999f ;
43+ private static final String AIRT = "AIRT" ;
44+ private static final double AIRT_FILL = -9.99 ;
45+ private static final String RH = "RH" ;
46+ private static final double RH_FILL = -9.99 ;
47+ private static final String WSPD = "WSPD" ;
48+ private static final double WSPD_FILL = -99.9 ;
49+ private static final String WDIR = "WDIR" ;
50+ private static final double WDIR_FILL = -99.9 ;
51+ private static final String BARO = "BARO" ;
52+ private static final double BARO_FILL = -9.9 ;
53+ private static final String RAIN = "RAIN" ;
54+ private static final double RAIN_FILL = -9.99 ;
55+ private static final String Q = "Q" ;
56+ private static final String M = "M" ;
3457
3558 private ArrayList <TaoRecord > records ;
3659 private TimeLocator timeLocator ;
@@ -137,17 +160,64 @@ public int[] extractYearMonthDayFromFilename(String fileName) {
137160
138161 @ Override
139162 public Array readRaw (int centerX , int centerY , Interval interval , String variableName ) throws IOException , InvalidRangeException {
140- throw new RuntimeException ("not implemented" );
163+ final TaoRecord record = records .get (centerY );
164+
165+ switch (variableName ) {
166+ case TIME :
167+ return createResultArray (record .time , NetCDFUtils .getDefaultFillValue (DataType .INT , false ), DataType .INT , interval );
168+
169+ case LONGITUDE :
170+ return createResultArray (record .longitude , NetCDFUtils .getDefaultFillValue (DataType .FLOAT , false ), DataType .FLOAT , interval );
171+
172+ case LATITUDE :
173+ return createResultArray (record .latitude , NetCDFUtils .getDefaultFillValue (DataType .FLOAT , false ), DataType .FLOAT , interval );
174+
175+ case SSS :
176+ return createResultArray (record .SSS , SSS_FILL , DataType .FLOAT , interval );
177+
178+ case SST :
179+ return createResultArray (record .SST , SST_FILL , DataType .FLOAT , interval );
180+
181+ case AIRT :
182+ return createResultArray (record .AIRT , AIRT_FILL , DataType .FLOAT , interval );
183+
184+ case RH :
185+ return createResultArray (record .RH , RH_FILL , DataType .FLOAT , interval );
186+
187+ case WSPD :
188+ return createResultArray (record .WSPD , WSPD_FILL , DataType .FLOAT , interval );
189+
190+ case WDIR :
191+ return createResultArray (record .WDIR , WDIR_FILL , DataType .FLOAT , interval );
192+
193+ case BARO :
194+ return createResultArray (record .BARO , BARO_FILL , DataType .FLOAT , interval );
195+
196+ case RAIN :
197+ return createResultArray (record .RAIN , RAIN_FILL , DataType .FLOAT , interval );
198+
199+ case Q :
200+ return createResultArray (record .Q , NetCDFUtils .getDefaultFillValue (DataType .INT , false ), DataType .INT , interval );
201+
202+ case M :
203+ final Array resultArray = Array .factory (DataType .STRING , new int []{1 , 1 });
204+ resultArray .setObject (0 , record .M );
205+ return resultArray ;
206+ }
207+
208+ return null ;
141209 }
142210
143211 @ Override
144212 public Array readScaled (int centerX , int centerY , Interval interval , String variableName ) throws IOException , InvalidRangeException {
145- throw new RuntimeException ( "not implemented" );
213+ return readRaw ( centerX , centerY , interval , variableName ); // no scaled data in this product type tb 2023-05-02
146214 }
147215
148216 @ Override
149217 public ArrayInt .D2 readAcquisitionTime (int x , int y , Interval interval ) throws IOException , InvalidRangeException {
150- throw new RuntimeException ("not implemented" );
218+ final Array timeArray = readRaw (x , y , interval , TIME );
219+
220+ return (ArrayInt .D2 ) timeArray ;
151221 }
152222
153223 @ Override
@@ -157,70 +227,70 @@ public List<Variable> getVariables() throws InvalidRangeException, IOException {
157227 List <Attribute > attributes = new ArrayList <>();
158228 attributes .add (new Attribute (CF_UNITS_NAME , "degree_east" ));
159229 attributes .add (new Attribute (CF_STANDARD_NAME , "longitude" ));
160- variables .add (new VariableProxy ("longitude" , DataType .FLOAT , attributes ));
230+ variables .add (new VariableProxy (LONGITUDE , DataType .FLOAT , attributes ));
161231
162232 attributes = new ArrayList <>();
163233 attributes .add (new Attribute (CF_UNITS_NAME , "degree_north" ));
164234 attributes .add (new Attribute (CF_STANDARD_NAME , "latitude" ));
165- variables .add (new VariableProxy ("latitude" , DataType .FLOAT , attributes ));
235+ variables .add (new VariableProxy (LATITUDE , DataType .FLOAT , attributes ));
166236
167237 attributes = new ArrayList <>();
168238 attributes .add (new Attribute (CF_UNITS_NAME , "seconds since 1970-01-01" ));
169239 attributes .add (new Attribute (CF_STANDARD_NAME , "time" ));
170- variables .add (new VariableProxy ("time" , DataType .INT , attributes ));
240+ variables .add (new VariableProxy (TIME , DataType .INT , attributes ));
171241
172242 attributes = new ArrayList <>();
173243 attributes .add (new Attribute (CF_UNITS_NAME , "psu" ));
174244 attributes .add (new Attribute (CF_STANDARD_NAME , "sea_surface_salinity" ));
175- attributes .add (new Attribute (CF_FILL_VALUE_NAME , - 9.999 ));
176- variables .add (new VariableProxy (" SSS" , DataType .FLOAT , attributes ));
245+ attributes .add (new Attribute (CF_FILL_VALUE_NAME , SSS_FILL ));
246+ variables .add (new VariableProxy (SSS , DataType .FLOAT , attributes ));
177247
178248 attributes = new ArrayList <>();
179249 attributes .add (new Attribute (CF_UNITS_NAME , "degree_Celsius" ));
180250 attributes .add (new Attribute (CF_STANDARD_NAME , "sea_surface_temperature" ));
181- attributes .add (new Attribute (CF_FILL_VALUE_NAME , - 9.999 ));
182- variables .add (new VariableProxy (" SST" , DataType .FLOAT , attributes ));
251+ attributes .add (new Attribute (CF_FILL_VALUE_NAME , SST_FILL ));
252+ variables .add (new VariableProxy (SST , DataType .FLOAT , attributes ));
183253
184254 attributes = new ArrayList <>();
185255 attributes .add (new Attribute (CF_UNITS_NAME , "degree_Celsius" ));
186256 attributes .add (new Attribute (CF_STANDARD_NAME , "air_temperature" ));
187- attributes .add (new Attribute (CF_FILL_VALUE_NAME , - 9.99 ));
188- variables .add (new VariableProxy (" AIRT" , DataType .FLOAT , attributes ));
257+ attributes .add (new Attribute (CF_FILL_VALUE_NAME , AIRT_FILL ));
258+ variables .add (new VariableProxy (AIRT , DataType .FLOAT , attributes ));
189259
190260 attributes = new ArrayList <>();
191261 attributes .add (new Attribute (CF_UNITS_NAME , "percent" ));
192262 attributes .add (new Attribute (CF_STANDARD_NAME , "relative_humidity" ));
193- attributes .add (new Attribute (CF_FILL_VALUE_NAME , - 9.99 ));
194- variables .add (new VariableProxy ("RH" , DataType .FLOAT , attributes ));
263+ attributes .add (new Attribute (CF_FILL_VALUE_NAME , RH_FILL ));
264+ variables .add (new VariableProxy (RH , DataType .FLOAT , attributes ));
195265
196266 attributes = new ArrayList <>();
197267 attributes .add (new Attribute (CF_UNITS_NAME , "m/s" ));
198268 attributes .add (new Attribute (CF_STANDARD_NAME , "wind_speed" ));
199- attributes .add (new Attribute (CF_FILL_VALUE_NAME , - 99.9 ));
200- variables .add (new VariableProxy (" WSPD" , DataType .FLOAT , attributes ));
269+ attributes .add (new Attribute (CF_FILL_VALUE_NAME , WSPD_FILL ));
270+ variables .add (new VariableProxy (WSPD , DataType .FLOAT , attributes ));
201271
202272 attributes = new ArrayList <>();
203273 attributes .add (new Attribute (CF_UNITS_NAME , "degree" ));
204274 attributes .add (new Attribute (CF_STANDARD_NAME , "wind_to_direction" ));
205275 attributes .add (new Attribute (CF_LONG_NAME , "Wind To Direction degree true in Oceanographic Convention" ));
206- attributes .add (new Attribute (CF_FILL_VALUE_NAME , - 99.9 ));
207- variables .add (new VariableProxy (" WDIR" , DataType .FLOAT , attributes ));
276+ attributes .add (new Attribute (CF_FILL_VALUE_NAME , WDIR_FILL ));
277+ variables .add (new VariableProxy (WDIR , DataType .FLOAT , attributes ));
208278
209279 attributes = new ArrayList <>();
210280 attributes .add (new Attribute (CF_UNITS_NAME , "hPa" ));
211281 attributes .add (new Attribute (CF_STANDARD_NAME , "air_pressure_at_mean_sea_level" ));
212- attributes .add (new Attribute (CF_FILL_VALUE_NAME , - 9.9 ));
213- variables .add (new VariableProxy (" BARO" , DataType .FLOAT , attributes ));
282+ attributes .add (new Attribute (CF_FILL_VALUE_NAME , BARO_FILL ));
283+ variables .add (new VariableProxy (BARO , DataType .FLOAT , attributes ));
214284
215285 attributes = new ArrayList <>();
216286 attributes .add (new Attribute (CF_UNITS_NAME , "mm/hour" ));
217287 attributes .add (new Attribute (CF_STANDARD_NAME , "rainfall_rate" ));
218- attributes .add (new Attribute (CF_FILL_VALUE_NAME , - 9.99 ));
219- variables .add (new VariableProxy (" RAIN" , DataType .FLOAT , attributes ));
288+ attributes .add (new Attribute (CF_FILL_VALUE_NAME , RAIN_FILL ));
289+ variables .add (new VariableProxy (RAIN , DataType .FLOAT , attributes ));
220290
221291 attributes = new ArrayList <>();
222292 attributes .add (new Attribute (CF_LONG_NAME , "Data Quality Codes" ));
223- variables .add (new VariableProxy ("Q" , DataType .INT , attributes ));
293+ variables .add (new VariableProxy (Q , DataType .INT , attributes ));
224294/*
225295@todo 1 tb/tb move this to documentation 2023-04-28
226296 Data Quality Codes(Q):
@@ -234,7 +304,7 @@ Data Quality Codes(Q):
234304 */
235305 attributes = new ArrayList <>();
236306 attributes .add (new Attribute (CF_LONG_NAME , "Data Mode Codes" ));
237- variables .add (new VariableProxy ("M" , DataType .STRING , attributes ));
307+ variables .add (new StringVariable ( new VariableProxy (M , DataType .STRING , attributes ), 8 ));
238308
239309 /*
240310 @todo 1 tb/tb move this to documentation 2023-04-28
@@ -274,4 +344,18 @@ private void createTimeLocator() {
274344
275345 timeLocator = new TimeLocator_MillisSince1970 (timeArray );
276346 }
347+
348+ // @todo 2 tb/tb create generic in-itu record and move this method to it tb 2023-05-02
349+ private Array createResultArray (Number value , Number fillValue , DataType dataType , Interval interval ) {
350+ final int windowHeight = interval .getY ();
351+ final int windowWidth = interval .getX ();
352+ final Array windowArray = NetCDFUtils .create (dataType ,
353+ new int []{windowHeight , windowWidth },
354+ fillValue );
355+
356+ final int windowCenterX = windowWidth / 2 ;
357+ final int windowCenterY = windowHeight / 2 ;
358+ windowArray .setObject (windowWidth * windowCenterY + windowCenterX , value );
359+ return windowArray ;
360+ }
277361}
0 commit comments