88import hec .heclib .grid .GriddedData ;
99import hec .heclib .util .HecTime ;
1010import hec .heclib .util .HecTimeArray ;
11- import hec .heclib .util .Heclib ;
1211import hec .hecmath .HecMath ;
1312import hec .io .DataContainer ;
1413import hec .io .TimeSeriesContainer ;
2928import java .util .logging .Level ;
3029import java .util .logging .Logger ;
3130import java .util .stream .Collectors ;
32- import java .util .stream .IntStream ;
3331
32+ import static hec .heclib .util .Heclib .UNDEFINED_FLOAT ;
3433import static javax .measure .MetricPrefix .MILLI ;
3534import static mil .army .usace .hec .vortex .VortexVariable .*;
3635import static systems .uom .common .USCustomary .FAHRENHEIT ;
@@ -69,8 +68,9 @@ public void write() {
6968
7069 double noDataValue = grid .noDataValue ();
7170 for (int i = 0 ; i < data .length ; i ++) {
72- if (Double .compare (data [i ], noDataValue ) == 0 || Double .isNaN (data [i ])) {
73- data [i ] = Heclib .UNDEFINED_FLOAT ;
71+ float value = data [i ];
72+ if (Double .compare (value , noDataValue ) == 0 || Double .isNaN (value ) || Double .isInfinite (value )) {
73+ data [i ] = UNDEFINED_FLOAT ;
7474 }
7575 }
7676
@@ -115,12 +115,7 @@ public void write() {
115115 conversion = 1 ;
116116 }
117117
118- for (int i = 0 ; i < data .length ; i ++) {
119- if (data [i ] == Heclib .UNDEFINED_FLOAT )
120- continue ;
121-
122- data [i ] *= conversion ;
123- }
118+ float [] convertedData = RasterUtils .convert (data , conversion , UNDEFINED_FLOAT );
124119
125120 gridInfo .setDataUnits ("MM" );
126121 gridInfo .setDataType (DssDataType .PER_CUM .value ());
@@ -133,25 +128,26 @@ public void write() {
133128 }
134129 }
135130
136- write (data , gridInfo , dssPathname );
131+ write (convertedData , gridInfo , dssPathname );
137132
138133 } else if (cPart .equals ("PRECIPITATION" ) && units .equals (METRE )) {
139- float [] convertedData = new float [data .length ];
140- IntStream .range (0 , data .length ).forEach (i -> convertedData [i ] = data [i ] * 1000 );
141-
134+ float [] convertedData = RasterUtils .convert (data , 1000 , UNDEFINED_FLOAT );
142135 gridInfo .setDataUnits ("MM" );
143136
144137 write (convertedData , gridInfo , dssPathname );
145138 } else if (units .equals (FAHRENHEIT ) || units .equals (KELVIN ) || units .equals (CELSIUS )) {
146139 float [] convertedData = new float [data .length ];
147140 if (units .equals (FAHRENHEIT )) {
148- IntStream . range ( 0 , data . length ). forEach ( i -> convertedData [ i ] = data [ i ] );
141+ System . arraycopy ( data , 0 , convertedData , 0 , data . length );
149142 gridInfo .setDataUnits ("DEG F" );
150143 } else if (units .equals (KELVIN )) {
151- IntStream .range (0 , data .length ).forEach (i -> convertedData [i ] = (float ) (data [i ] - 273.15 ));
144+ for (int i = 0 ; i < data .length ; i ++) {
145+ float value = data [i ];
146+ convertedData [i ] = Float .compare (UNDEFINED_FLOAT , value ) == 0 ? UNDEFINED_FLOAT : (float ) (data [i ] - 273.15 );
147+ }
152148 gridInfo .setDataUnits ("DEG C" );
153149 } else if (units .equals (CELSIUS )) {
154- IntStream . range ( 0 , data . length ). forEach ( i -> convertedData [ i ] = data [ i ] );
150+ System . arraycopy ( data , 0 , convertedData , 0 , data . length );
155151 gridInfo .setDataUnits ("DEG C" );
156152 }
157153
@@ -165,23 +161,17 @@ public void write() {
165161
166162 write (convertedData , gridInfo , dssPathname );
167163 } else if (cPart .equals ("HUMIDITY" ) && units .equals (ONE )) {
168- float [] convertedData = new float [data .length ];
169- IntStream .range (0 , data .length ).forEach (i -> convertedData [i ] = data [i ] * 100 );
170-
164+ float [] convertedData = RasterUtils .convert (data , 100 , UNDEFINED_FLOAT );
171165 gridInfo .setDataUnits ("%" );
172166
173167 write (convertedData , gridInfo , dssPathname );
174168 } else if (units .equals (ONE .divide (INCH .multiply (1000 )))) {
175- float [] convertedData = new float [data .length ];
176- IntStream .range (0 , data .length ).forEach (i -> convertedData [i ] = data [i ] / 1000 );
177-
169+ float [] convertedData = RasterUtils .convert (data , 1E-3f , UNDEFINED_FLOAT );
178170 gridInfo .setDataUnits ("IN" );
179171
180172 write (convertedData , gridInfo , dssPathname );
181173 } else if (units .equals (PASCAL )) {
182- float [] convertedData = new float [data .length ];
183- IntStream .range (0 , data .length ).forEach (i -> convertedData [i ] = data [i ] / 1000 );
184-
174+ float [] convertedData = RasterUtils .convert (data , 1E-3f , UNDEFINED_FLOAT );
185175 gridInfo .setDataUnits ("KPA" );
186176
187177 write (convertedData , gridInfo , dssPathname );
0 commit comments