001/*
002 * This file is part of McIDAS-V
003 *
004 * Copyright 2007-2024
005 * Space Science and Engineering Center (SSEC)
006 * University of Wisconsin - Madison
007 * 1225 W. Dayton Street, Madison, WI 53706, USA
008 * https://www.ssec.wisc.edu/mcidas/
009 * 
010 * All Rights Reserved
011 * 
012 * McIDAS-V is built on Unidata's IDV and SSEC's VisAD libraries, and
013 * some McIDAS-V source code is based on IDV and VisAD source code.  
014 * 
015 * McIDAS-V is free software; you can redistribute it and/or modify
016 * it under the terms of the GNU Lesser Public License as published by
017 * the Free Software Foundation; either version 3 of the License, or
018 * (at your option) any later version.
019 * 
020 * McIDAS-V is distributed in the hope that it will be useful,
021 * but WITHOUT ANY WARRANTY; without even the implied warranty of
022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
023 * GNU Lesser Public License for more details.
024 * 
025 * You should have received a copy of the GNU Lesser Public License
026 * along with this program.  If not, see https://www.gnu.org/licenses/.
027 */
028
029package edu.wisc.ssec.mcidasv.adt;
030
031public class Intensity {
032
033    private static int MWAnalysisFlag;
034    private static int Rule9StrengthFlag;
035
036    private static double[] BDCurve_Points = { 30.0, 9.0, -30.0, -42.0, -54.0, -64.0, -70.0, -76.0,
037            -80.0, -84.0, -100.0 };
038
039    public Intensity() {
040        MWAnalysisFlag = 0;
041        Rule9StrengthFlag = 0;
042    }
043
044    /**
045     * Compute intensity values CI, Final T#, and Raw T#.
046     *
047     * @param RedoIntensityFlagValue
048     *            Recalculate Intensity flag value.
049     * @param RunFullAnalysis
050     *            Whether or not a full analysis should be performed.
051     * @param HistoryFileName
052     *            Path to history file.
053     *
054     */
055    public static void CalculateIntensity(int RedoIntensityFlagValue, boolean RunFullAnalysis,
056            String HistoryFileName) {
057        double TnoRaw = 0.0;
058        double TnoFinal = 0.0;
059        double CI = 0.0;
060        double CIadjP = 0.0;
061
062        boolean InitStrengthTF = Env.InitStrengthTF;
063        boolean LandFlagTF = Env.LandFlagTF;
064
065        int RecLand = History.IRCurrentRecord.land;
066        double Latitude = History.IRCurrentRecord.latitude;
067        double Longitude = History.IRCurrentRecord.longitude;
068
069        if ((LandFlagTF) && (RecLand == 1)) {
070            /* Initialize Missing Record */
071            /* throw exception ?? */
072        } else {
073            double RetVal[] = adt_TnoRaw(RedoIntensityFlagValue, HistoryFileName);
074            TnoRaw = RetVal[0];
075            MWAnalysisFlag = (int) RetVal[1];
076            /*
077             * System.out.printf("RawT#Adj=%f  MWAnalysisFlag=%d\n",TnoRaw,
078             * MWAnalysisFlag);
079             */
080            History.IRCurrentRecord.Traw = TnoRaw;
081        }
082
083        /* System.out.printf("RunFullAnalysis=%b\n",RunFullAnalysis); */
084        if (!RunFullAnalysis) {
085            /* Perform Spot Analysis (only T#raw) */
086            History.IRCurrentRecord.Tfinal = TnoRaw;
087            History.IRCurrentRecord.CI = TnoRaw;
088            // CIadjP =
089            // adt_latbias(InitStrengthTF,LandFlagTF,HistoryFileName,TnoRaw,Latitude,Longitude);
090            CIadjP = adt_latbias(InitStrengthTF, LandFlagTF, HistoryFileName, Latitude, Longitude);
091            History.IRCurrentRecord.CIadjp = CIadjP;
092            History.IRCurrentRecord.rule9 = 0;
093        } else {
094            int NumRecsHistory = History.HistoryNumberOfRecords();
095            /*
096             * System.out.printf("numrecs=%d  inistrength=%b historyfilename=%s*\n"
097             * ,NumRecsHistory,InitStrengthTF,HistoryFileName);
098             */
099            /* System.out.printf("MWanalysisflag=%d\n",MWAnalysisFlag); */
100            if ((((NumRecsHistory == 0) && (InitStrengthTF)) && (HistoryFileName != null))
101                    || (MWAnalysisFlag == 1)) {
102                System.out.printf("tnoraw=%f\n", TnoRaw);
103                History.IRCurrentRecord.Tfinal = TnoRaw;
104                History.IRCurrentRecord.CI = TnoRaw;
105                History.IRCurrentRecord.CIadjp = 0.0;
106                if (MWAnalysisFlag == 1) {
107                    double[] RetVals = adt_CIno(HistoryFileName);
108                    CI = RetVals[0];
109                    Rule9StrengthFlag = (int) RetVals[1];
110                    History.IRCurrentRecord.CI = CI;
111                    History.IRCurrentRecord.rule9 = Rule9StrengthFlag;
112                    // CIadjP =
113                    // adt_latbias(InitStrengthTF,LandFlagTF,HistoryFileName,TnoRaw,Latitude,Longitude);
114                    CIadjP = adt_latbias(InitStrengthTF, LandFlagTF, HistoryFileName, Latitude,
115                            Longitude);
116                    History.IRCurrentRecord.CIadjp = CIadjP;
117                } else {
118                    History.IRCurrentRecord.CI = TnoRaw;
119                    History.IRCurrentRecord.rule9 = 0;
120                }
121            } else {
122                /* System.out.printf("rawt=%f\n",History.IRCurrentRecord.Traw); */
123                TnoFinal = adt_TnoFinal(1);
124                /* System.out.printf("FinalT#=%f\n",TnoFinal); */
125                History.IRCurrentRecord.Tfinal = TnoFinal;
126                double[] RetVals2 = adt_CIno(HistoryFileName);
127                CI = RetVals2[0];
128                Rule9StrengthFlag = (int) RetVals2[1];
129                /*
130                 * System.out.printf("CI#=%f Rule9StrengthFlag=%d \n",CI,
131                 * Rule9StrengthFlag);
132                 */
133                History.IRCurrentRecord.CI = CI;
134                History.IRCurrentRecord.rule9 = Rule9StrengthFlag;
135            }
136        }
137    }
138
139    /**
140     * Compute initial Raw T-Number value using original Dvorak rules
141     *
142     * @param RedoIntensityFlag
143     *            Recalculate Intensity flag value.
144     * @param HistoryFileName
145     *            Path to history file.
146     *
147     * @return Array of two doubles. First value represents intensity estimate,
148     *         and the second is the analysis flag.
149     */
150    public static double[] adt_TnoRaw(int RedoIntensityFlag, String HistoryFileName) {
151        int XInc;
152        int CloudBDCategory = 0;
153        int Rule8AdjCatValue = 0;
154        int PreviousHistoryRecPtr = 0;
155        double CloudTnoIntensity = -909.0;
156        double TnoRawValue = 0.0;
157        double IntensityEstimateValue = 0.0;
158        double TnoInterpAdjValue = 0.0;
159        double FinalIntensityEstimateValue = 0.0;
160        double ShearInterpAdjValue = 0.0;
161        double CDOSizeRegressionAdjValue = 0.0;
162        double EyeCloudTempDifferenceAdjValue = 0.0;
163        double CDOSymmatryRegressionAdjValue = 0.0;
164        double PreviousHistoryCIValue = 0.0;
165        double CIValueAdjustmentFactorValue = 0.0;
166        double HistoryRecTime = 0.0;
167        boolean First48HourShearTF = false;
168        boolean MWOFFTF = false;
169        boolean LandCheckTF = true;
170
171        /* EYE SCENE REGRESSION BASE VALUES */
172        double[][] EyeRegressionBaseArray =
173        /* DG MG LG B W CMG CDG */
174        { { 1.00, 2.00, 3.25, 4.00, 4.75, 5.25, 5.75, 6.50, 7.25, 7.75, 8.25 },
175                { 1.50, 2.25, 3.30, 3.85, 4.50, 4.75, 5.15, 5.50, 6.00, 6.25, 6.75 } };
176        /* CLOUD SCENE REGRESSION BASE VALUES */
177        double[][] CloudRegressionBaseArray =
178        /* DG MG LG B W CMG CDG */
179        { { 2.00, 2.40, 3.25, 3.50, 3.75, 4.00, 4.10, 4.20, 4.30, 4.40, 4.70 },
180                { 2.05, 2.40, 3.00, 3.20, 3.40, 3.55, 3.65, 3.75, 3.80, 3.90, 4.10 } };
181        /*
182         * Curved Band Scene Type Intensity Values (each 20% of wrap around
183         * center)
184         */
185        double[] CurvedBandIntensityArray = { 1.5, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0 };
186        /* Shear Scene Type Distance Threshold Values (distance in km) */
187        double[] ShearDistanceArray = { 0.0, 35.0, 50.0, 80.0, 110.0, 140.0 };
188        /* Shear Scene Type Intensity Values */
189        double[] ShearIntensityArray = { 3.50, 3.00, 2.50, 2.25, 2.00, 1.50 };
190
191        /*
192         * Rule 8 Adjustments Row 1 - Shear Scenes (original rule 8) Row 2 - Eye
193         * Scenes (original + 0.5) Row 3 - Other Scenes (original - 0.5)
194         */
195        double[][] Rule8AdjArray =
196        /* 1hr 6hr 12hr 18hr 24hr */
197        { { 0.0, 0.51, 1.01, 1.71, 2.21, 2.71, 0.0, 0.0, 0.21, 0.51 },
198                { 0.0, 0.51, 1.01, 2.71, 3.21, 3.71, 1.31, 0.0, 0.21, 0.51 },
199                { 0.0, 0.51, 0.71, 1.21, 1.71, 2.21, 0.0, 0.0, 0.21, 0.51 } };
200        /* Eye Regression Factor (Atlantic, Pacific) */
201        double[] EyeCloudTempDifferenceRegressionFactorArrayEYE = { 0.011, 0.015 };
202        /*
203         * Cloud Region Symmatry Regression Factor - Eye Scene (Atlantic,
204         * Pacific)
205         */
206        double[] CloudSymmatryRegressionFactorArrayEYE = { -0.015, -0.015 };
207        /* CDO size (km - Dark Gray BD Curve) - Cloud Scene (Atlantic, Pacific) */
208        double[] CDOSizeRegressionFactorArrayCLD = { 0.002, 0.001 };
209        /*
210         * Cloud Region Symmatry Regression Factor - Cloud Scene (Atlantic,
211         * Pacific)
212         */
213        double[] CloudSymmatryRegressionFactorArrayCLD = { -0.030, -0.015 };
214
215        double CurrentTime = 1900001.0;
216        int ImageDate = 1900001;
217        int ImageTime = 000000;
218        ;
219        int RecDate = 1900001;
220        int RecTime = 000000;
221        int RecLand = 0;
222        boolean LandFlagTF = Env.LandFlagTF;
223        boolean InitStrengthTF = Env.InitStrengthTF;
224        double InitStrengthValue = Env.InitRawTValue;
225        int LandFlagCurrent = History.IRCurrentRecord.land;
226        double RecTnoRaw = 0.0;
227
228        int NumRecsHistory = History.HistoryNumberOfRecords();
229        /* System.out.printf("numrecs=%d\n",NumRecsHistory); */
230        if ((NumRecsHistory == 0) && (HistoryFileName != null)) {
231            /*
232             * History file does not exist and current analysis is first
233             * analysis for the storm
234             */
235            if (InitStrengthTF) {
236                History.IRCurrentRecord.TrawO = InitStrengthValue;
237                return new double[] { InitStrengthValue, 0.0 }; /* EXIT */
238            }
239        } else {
240            double LastValidRecordTime = 1900001.0;
241            ImageDate = History.IRCurrentRecord.date;
242            ImageTime = History.IRCurrentRecord.time;
243            CurrentTime = Functions.calctime(ImageDate, ImageTime);
244            /* System.out.printf("CurrentTime=%f\n",CurrentTime); */
245            double FirstHistoryRecTime = LastValidRecordTime;
246            if (NumRecsHistory != 0) {
247                RecDate = History.HistoryFile[0].date;
248                RecTime = History.HistoryFile[0].time;
249                FirstHistoryRecTime = Functions.calctime(RecDate, RecTime);
250                if ((CurrentTime - FirstHistoryRecTime) <= 2.0) {
251                    First48HourShearTF = true;
252                }
253            } else {
254                FirstHistoryRecTime = LastValidRecordTime;
255            }
256
257            /*
258             * System.out.printf("FirstHistoryRecTime=%f\n",FirstHistoryRecTime);
259             */
260            XInc = 0;
261            while (XInc < NumRecsHistory) {
262                RecDate = History.HistoryFile[XInc].date;
263                RecTime = History.HistoryFile[XInc].time;
264                HistoryRecTime = Functions.calctime(RecDate, RecTime);
265                /*
266                 * System.out.printf("XInc= %d  HistoryRecTime%f\n",XInc,
267                 * HistoryRecTime);
268                 */
269                if (HistoryRecTime > CurrentTime) {
270                    break;
271                }
272                RecLand = History.HistoryFile[XInc].land;
273                RecTnoRaw = History.HistoryFile[XInc].Traw;
274                LandCheckTF = true;
275                if (((LandFlagTF) && (RecLand == 1)) || (RecTnoRaw < 1.0)) {
276                    LandCheckTF = false;
277                }
278                if (LandCheckTF) {
279                    if ((HistoryRecTime == CurrentTime) && (XInc == 0)
280                            && (InitStrengthValue != 0.0)) {
281                        /*
282                         * Current analysis is at or before first record in
283                         * existing history file - return global initial
284                         * strength value
285                         */
286                        System.out.printf("FIRST RECORD in NON-empty file\n");
287                        History.IRCurrentRecord.TrawO = InitStrengthValue;
288                        /* InitStrengthValue = 0.0; */
289                        /* Env.InitRawTValue = 0.0; */
290                        return new double[] { InitStrengthValue, 0.0 }; /* EXIT */
291                    }
292                    PreviousHistoryRecPtr = XInc;
293                    LastValidRecordTime = HistoryRecTime;
294                }
295                XInc++;
296            }
297            if (HistoryFileName != null) {
298                PreviousHistoryCIValue = History.HistoryFile[PreviousHistoryRecPtr].CI;
299            } else {
300                PreviousHistoryCIValue = 4.0;
301            }
302
303            /*
304             * System.out.printf("PreviousHistoryCIValue=%f\n",
305             * PreviousHistoryCIValue);
306             */
307            if (((CurrentTime - LastValidRecordTime) > 1.0) && (HistoryFileName != null)) {
308                /*
309                 * The history file either begins with all land scenes or there
310                 * is a break in the history file of greater than 24 hours.
311                 * Reinitialize the storm with the input Initial Classification
312                 * value
313                 */
314                History.IRCurrentRecord.TrawO = InitStrengthValue;
315                Env.InitRawTValue = -1.0;
316                /* System.out.printf("returning...\n"); */
317                return new double[] { InitStrengthValue, 0.0 }; /* EXIT */
318            }
319        }
320
321        double CloudTemperatureCurrent = History.IRCurrentRecord.cloudt;
322        double EyeTemperatureCurrent = History.IRCurrentRecord.eyet;
323
324        /*
325         * System.out.printf("current cloudT=%f  eyeT=%f\n",CloudTemperatureCurrent
326         * ,EyeTemperatureCurrent);
327         */
328        for (XInc = 0; XInc < 10; XInc++) {
329            /* compute cloud category */
330            if ((CloudTemperatureCurrent <= BDCurve_Points[XInc])
331                    && (CloudTemperatureCurrent > BDCurve_Points[XInc + 1])) {
332                CloudBDCategory = XInc;
333                CloudTnoIntensity = (CloudTemperatureCurrent - BDCurve_Points[CloudBDCategory])
334                        / (BDCurve_Points[CloudBDCategory + 1] - BDCurve_Points[CloudBDCategory]);
335            }
336            /* compute eye category for eye adjustment */
337            if ((EyeTemperatureCurrent <= BDCurve_Points[XInc])
338                    && (EyeTemperatureCurrent > BDCurve_Points[XInc + 1])) {
339            }
340        }
341
342        /*
343         * System.out.printf("cloudBD=%d  CloudTnoIntensity= %f eyeBD=%d  \n",
344         * CloudBDCategory,CloudTnoIntensity,EyeBDCategory);
345         */
346        int EyeSceneCurrent = History.IRCurrentRecord.eyescene;
347        if (EyeSceneCurrent == 1) {
348            /* this matches DT used at NHC (jack beven) */
349            /* EyeTemperature=(9.0+EyeTemperature)/2.0; */
350            /* Eye Temp is between +9C (beven) and measured eye temp (turk) */
351            EyeTemperatureCurrent = (EyeTemperatureCurrent + 9.0) / 2.0;
352            History.IRCurrentRecord.eyet = EyeTemperatureCurrent;
353        }
354
355        /*
356         * System.out.printf("EyeCloudBDCategoryDifference=%f\n",
357         * EyeCloudBDCategoryDifference);
358         */
359
360        /* if scenetype is EYE */
361        int CurvedBandBDAmountCurrent = History.IRCurrentRecord.ringcbval;
362        int CurvedBandBDCategoryCurrent = History.IRCurrentRecord.ringcb;
363        double MWScoreValueCurrent = History.IRCurrentRecord.mwscore;
364        /* System.out.printf("MWScoreValueCurrent=%f\n",MWScoreValueCurrent); */
365
366        MWAnalysisFlag = 0;
367        if (RedoIntensityFlag == 1) {
368            Env.MWJulianDate = History.IRCurrentRecord.mwdate;
369            Env.MWHHMMSSTime = History.IRCurrentRecord.mwtime;
370            System.out
371                    .printf("****REDO : MW DATE=%d Time=%d\n", Env.MWJulianDate, Env.MWHHMMSSTime);
372        }
373
374        int CloudScene = History.IRCurrentRecord.cloudscene;
375        int EyeScene = History.IRCurrentRecord.eyescene;
376        int DomainID = Env.DomainID;
377        double CloudSymAveCurrent = History.IRCurrentRecord.cloudsymave;
378        double EyeCDOSizeCurrent = History.IRCurrentRecord.eyecdosize;
379        /* System.out.printf("CloudScene=%d\n",CloudScene); */
380        if (CloudScene == 3) {
381            /* CURVED BAND */
382            CurvedBandBDAmountCurrent = Math.min(30, CurvedBandBDAmountCurrent + 1);
383            int CurvedBandBDPercentage = CurvedBandBDAmountCurrent / 5;
384            double IncrementMultFactor = 0.1;
385            if (CurvedBandBDPercentage == 1) {
386                IncrementMultFactor = 0.2;
387            }
388            IntensityEstimateValue = CurvedBandIntensityArray[CurvedBandBDPercentage];
389            TnoInterpAdjValue = IncrementMultFactor
390                    * ((double) (CurvedBandBDAmountCurrent - (CurvedBandBDPercentage * 5)));
391            /*
392             * System.out.printf(
393             * "CurvedBandBDAmount=%d  CurvedBandBDPercentage=%d CurvedBandBDCategory=%d  IntensityEstimateValue=%f TnoInterpAdjValue=%f\n"
394             * , CurvedBandBDAmountCurrent,CurvedBandBDPercentage,
395             * CurvedBandBDCategoryCurrent,IntensityEstimateValue,
396             * TnoInterpAdjValue);
397             */
398            IntensityEstimateValue = IntensityEstimateValue + TnoInterpAdjValue;
399            if (CurvedBandBDCategoryCurrent == 5) {
400                IntensityEstimateValue = Math.min(4.0, IntensityEstimateValue + 0.5);
401            }
402            if (CurvedBandBDCategoryCurrent == 6) {
403                IntensityEstimateValue = Math.min(4.5, IntensityEstimateValue + 1.0);
404            }
405            Rule8AdjCatValue = 2;
406        } else if (CloudScene == 4) {
407            /* POSSIBLE SHEAR -- new definition from NHC */
408            XInc = 0;
409            IntensityEstimateValue = 1.5;
410            double ShearDistanceCurrent = History.IRCurrentRecord.eyecdosize;
411            while (XInc < 5) {
412                if ((ShearDistanceCurrent >= ShearDistanceArray[XInc])
413                        && (ShearDistanceCurrent < ShearDistanceArray[XInc + 1])) {
414                    ShearInterpAdjValue = (ShearDistanceCurrent - ShearDistanceArray[XInc])
415                            / (ShearDistanceArray[XInc + 1] - ShearDistanceArray[XInc]);
416                    TnoInterpAdjValue = (ShearInterpAdjValue * (ShearIntensityArray[XInc + 1] - ShearIntensityArray[XInc]));
417                    IntensityEstimateValue = ShearIntensityArray[XInc] + TnoInterpAdjValue;
418                    XInc = 5;
419                } else {
420                    XInc++;
421                }
422            }
423            Rule8AdjCatValue = 0;
424            if (First48HourShearTF) {
425                IntensityEstimateValue = Math.min(2.5, IntensityEstimateValue);
426                if (Env.DEBUG == 100) {
427                    System.out
428                            .printf("Constraining SHEAR Intensity to 2.5 or less during first 48 hours\n");
429                }
430            }
431        } else {
432            /* EYE or NO EYE */
433            /* int DomainID_Local = Env.DomainID = DomainID; */
434            if (EyeScene <= 2) {
435                /* EYE */
436                /*
437                 * System.out.printf(
438                 * "EYE : EyeTemperature=%f  CloudTemperature=%f\n",
439                 * EyeTemperatureCurrent,CloudTemperatureCurrent);
440                 * System.out.printf
441                 * ("EYE : CloudTnoIntensity=%f  DomainID=%d CloudBDCategory=%d\n"
442                 * ,CloudTnoIntensity,DomainID, CloudBDCategory);
443                 */
444                TnoInterpAdjValue = (CloudTnoIntensity * (EyeRegressionBaseArray[DomainID][CloudBDCategory + 1] - EyeRegressionBaseArray[DomainID][CloudBDCategory]));
445                EyeCloudTempDifferenceAdjValue = EyeCloudTempDifferenceRegressionFactorArrayEYE[DomainID]
446                        * (EyeTemperatureCurrent - CloudTemperatureCurrent);
447                CDOSymmatryRegressionAdjValue = CloudSymmatryRegressionFactorArrayEYE[DomainID]
448                        * (CloudSymAveCurrent);
449
450                /*
451                 * System.out.printf(
452                 * "EYE : cloudsymave=%f  CDOSymmatryRegressionAdjValue=%f\n",
453                 * CloudSymAveCurrent,CDOSymmatryRegressionAdjValue);
454                 */
455
456                IntensityEstimateValue = EyeRegressionBaseArray[DomainID][CloudBDCategory]
457                        + TnoInterpAdjValue + EyeCloudTempDifferenceAdjValue
458                        + CDOSymmatryRegressionAdjValue;
459
460                /*
461                 * System.out.printf(
462                 * "EYE :TnoInterpAdjValue=%f EyeCloudTempDifferenceAdjValue=%f CDOSymmatryRegressionAdjValue=%f IntensityEstimateValue=%f\n"
463                 * , TnoInterpAdjValue,EyeCloudTempDifferenceAdjValue,
464                 * CDOSymmatryRegressionAdjValue,IntensityEstimateValue);
465                 */
466
467                IntensityEstimateValue = Math.min(IntensityEstimateValue, 9.0);
468                /*
469                 * System.out.printf("IntensityEstimateValue=%f\n",
470                 * IntensityEstimateValue);
471                 */
472                if (EyeScene == 2) {
473                    /* LARGE EYE adjustment */
474                    IntensityEstimateValue = Math.min(IntensityEstimateValue - 0.5, 6.5);
475                }
476                Rule8AdjCatValue = 1;
477            } else {
478                /* NO EYE */
479                /* CDO */
480                TnoInterpAdjValue = (CloudTnoIntensity * (CloudRegressionBaseArray[DomainID][CloudBDCategory + 1] - CloudRegressionBaseArray[DomainID][CloudBDCategory]));
481                CDOSizeRegressionAdjValue = CDOSizeRegressionFactorArrayCLD[DomainID]
482                        * EyeCDOSizeCurrent;
483
484                /*
485                 * System.out.printf(
486                 * "CDO : dgraysize=%f  CDOSymmatryRegressionAdjValue=%f\n",
487                 * EyeCDOSizeCurrent,CDOSizeRegressionAdjValue);
488                 */
489
490                CDOSymmatryRegressionAdjValue = CloudSymmatryRegressionFactorArrayCLD[DomainID]
491                        * (CloudSymAveCurrent);
492
493                /*
494                 * System.out.printf(
495                 * "CDO : cloudsymave=%f  CDOSymmatryRegressionAdjValue=%f\n",
496                 * CloudSymAveCurrent,CDOSymmatryRegressionAdjValue);
497                 */
498
499                IntensityEstimateValue = CloudRegressionBaseArray[DomainID][CloudBDCategory]
500                        + TnoInterpAdjValue + CDOSizeRegressionAdjValue
501                        + CDOSymmatryRegressionAdjValue;
502                IntensityEstimateValue = IntensityEstimateValue - 0.1; /*
503                                                                        * bias
504                                                                        * adjustment
505                                                                        */
506                /* CDO adjustment for very weak or very strong CDOs */
507                if (CloudScene == 0) {
508                    CIValueAdjustmentFactorValue = 0.0;
509                    if (PreviousHistoryCIValue >= 4.5) {
510                        CIValueAdjustmentFactorValue = Math.max(0.0,
511                                Math.min(1.0, PreviousHistoryCIValue - 4.5));
512                    }
513                    if (PreviousHistoryCIValue <= 3.0) {
514                        CIValueAdjustmentFactorValue = Math.min(0.0,
515                                Math.max(-1.0, PreviousHistoryCIValue - 3.0));
516                    }
517                    IntensityEstimateValue = IntensityEstimateValue + CIValueAdjustmentFactorValue;
518                }
519
520                /*
521                 * System.out.printf(
522                 * "CDO : TnoInterpAdjValue=%f CDOSizeRegressionAdjValue=%f CDOSymmatryRegressionAdjValue=%f IntensityEstimateValue=%f\n"
523                 * , TnoInterpAdjValue,CDOSizeRegressionAdjValue,
524                 * CDOSymmatryRegressionAdjValue,IntensityEstimateValue);
525                 */
526
527                CIValueAdjustmentFactorValue = 0.0;
528                /* EMBEDDED CENTER */
529                if (CloudScene == 1) {
530                    CIValueAdjustmentFactorValue = Math.max(0.0,
531                            Math.min(1.5, PreviousHistoryCIValue - 4.0));
532
533                    /*
534                     * System.out.printf(
535                     * "EMBC : PreviousHistoryCIValue=%f TnoInterpAdjValue=%f\n"
536                     * , PreviousHistoryCIValue,CIValueAdjustmentFactorValue);
537                     */
538
539                    IntensityEstimateValue = IntensityEstimateValue + CIValueAdjustmentFactorValue;
540                }
541                /* IRREGULAR CDO (PT=3.5) */
542                if (CloudScene == 2) {
543                    /* additional IrrCDO bias adjustment */
544                    IntensityEstimateValue = IntensityEstimateValue + 0.3;
545                    IntensityEstimateValue = Math.min(3.5, Math.max(2.5, IntensityEstimateValue));
546                }
547                Rule8AdjCatValue = 2;
548            }
549        }
550
551        FinalIntensityEstimateValue = ((double) ((int) ((IntensityEstimateValue + 0.01) * 10.0))) / 10.0;
552        History.IRCurrentRecord.TrawO = FinalIntensityEstimateValue;
553
554        /* System.out.printf("RawT#orig=%f\n",FinalIntensityEstimateValue); */
555
556        /* NEW Microwave Eye Score logic */
557        if (Env.DEBUG == 100) {
558            System.out.printf("***IntensityEstimateValue=%f\n", IntensityEstimateValue);
559        }
560
561        /* moved MW analysis here to work with all scenes */
562
563        double[] RetVals2 = MWAdj.adt_calcmwadjustment(MWScoreValueCurrent,
564                FinalIntensityEstimateValue);
565        MWAnalysisFlag = (int) RetVals2[0];
566        IntensityEstimateValue = RetVals2[1];
567
568        if (Env.DEBUG == 100) {
569            System.out.printf("MWAnalysisFlag=%d  IntensityEstimateValue=%f\n", MWAnalysisFlag,
570                    IntensityEstimateValue);
571        }
572        FinalIntensityEstimateValue = (double) ((int) ((IntensityEstimateValue + 0.01) * 10.0)) / 10.0;
573        /*
574         * System.out.printf("FinalIntensityEstimateValue=%f\n",
575         * FinalIntensityEstimateValue);
576         */
577
578        int Rule8Current = History.IRCurrentRecord.rule8;
579
580        if (Rule8Current == 34)
581            MWOFFTF = true;
582
583        boolean SpecialPostMWRule8EYEFlag = false;
584        if ((MWOFFTF) && (Rule8AdjCatValue == 1)) {
585            /*
586             * System.out.printf("USING NEW POST-MW EYE RULE 8 CONSTRAINTS!!!\n")
587             * ;
588             */
589            SpecialPostMWRule8EYEFlag = true;
590        }
591
592        /* System.out.printf("MWAnalysisFlag=%d\n",MWAnalysisFlag); */
593        if (MWAnalysisFlag == 0) {
594            /*
595             * perform Dvorak EIR Rule 8 Constrants on Raw T# value
596             * "velden rule" (actually 86.4 minutes... 0.06 of a day)
597             * "additional velden rule", only over first 6 hours All cases :
598             * delT of 0.5 over 1 hour : rule8 = 9 "velden rule" delT of 0.1
599             * over 1 hour : rule8 = 8 "additional" Raw T# < 4.0 : delT of 1.0
600             * over 6 hours : rule8 = 2 No threshold exceeded : rule8 = 0 Raw T#
601             * >= 4.0 : delT of 1.0 over 6 hours : rule8 = 2 delT of 1.5 over 12
602             * hours : rule8 = 3 delT of 2.0 over 18 hours : rule8 = 4 delT of
603             * 2.5 over 24 hours : rule8 = 5 No threshold exceeded : rule8 = 0
604             */
605            double PreviousHistoryFinalTnoValue = FinalIntensityEstimateValue;
606            int EyeSceneCounter = 0;
607            int NonEyeSceneCounter = 0;
608            double TnoValueMinus1hr = FinalIntensityEstimateValue;
609            double TnoValueMinus6hr = FinalIntensityEstimateValue;
610            double TnoValueMinus12hr = FinalIntensityEstimateValue;
611            double TnoValueMinus18hr = FinalIntensityEstimateValue;
612            double TnoValueMinus24hr = FinalIntensityEstimateValue;
613            double RawTnoValueMinus6hrTime = CurrentTime;
614            double RawTnoValueMinus6hr = FinalIntensityEstimateValue;
615            double RawTnoValueMinus1hr = FinalIntensityEstimateValue;
616            boolean First6hrRecordTF = false;
617            if (NumRecsHistory != 0) {
618                /*
619                 * 0.0416 is one hour... round to 0.05 to make sure I catch the
620                 * hour previous report
621                 */
622                double CurrentTimeMinus1hr = CurrentTime - 0.05;
623                double CurrentTimeMinus6hr = CurrentTime - 0.26;
624                double CurrentTimeMinus12hr = CurrentTime - 0.51;
625                double CurrentTimeMinus18hr = CurrentTime - 0.76;
626                double CurrentTimeMinus24hr = CurrentTime - 1.01;
627                double TnoDifferenceValueMinus1hr;
628                double TnoDifferenceValueMinus6hr;
629                double TnoDifferenceValueMinus12hr;
630                double TnoDifferenceValueMinus18hr;
631                double TnoDifferenceValueMinus24hr;
632                RecDate = History.HistoryFile[0].date;
633                RecTime = History.HistoryFile[0].time;
634                double FirstHistoryRecTime = Functions.calctime(RecDate, RecTime);
635                boolean FirstHistoryLandRecTF = true;
636                boolean CurrentTimeMinus24hrTF = false;
637                boolean CurrentTimeMinus18hrTF = false;
638                boolean CurrentTimeMinus12hrTF = false;
639                boolean CurrentTimeMinus6hrTF = false;
640                boolean CurrentTimeMinus1hrTF = false;
641                boolean HistoryVeldenRuleFlagTF = false;
642                boolean ApplyVeldenRuleTF = true;
643                double RecTFinal;
644                double RecTRaw;
645                int RecRule9;
646                int RecRapidDiss;
647                int RecEyeScene;
648                int Rule8Val = 0;
649                int PreviousHistoryRule9Value = 0;
650                int PreviousHistoryRapidDissIDValue = 0;
651                double Rule8TESTValue;
652
653                if (FirstHistoryRecTime >= CurrentTimeMinus6hr) {
654                    First6hrRecordTF = true;
655                }
656                XInc = 0;
657                while (XInc < NumRecsHistory) {
658                    RecDate = History.HistoryFile[XInc].date;
659                    RecTime = History.HistoryFile[XInc].time;
660                    RecLand = History.HistoryFile[XInc].land;
661                    HistoryRecTime = Functions.calctime(RecDate, RecTime);
662                    RecTFinal = History.HistoryFile[XInc].Tfinal;
663                    RecTRaw = History.HistoryFile[XInc].Traw;
664                    RecRule9 = History.HistoryFile[XInc].rule9;
665                    RecRapidDiss = History.HistoryFile[XInc].rapiddiss;
666                    RecEyeScene = History.HistoryFile[XInc].eyescene;
667                    /*
668                     * System.out.printf("currenttime=%f  historyrectime=%f\n",
669                     * CurrentTime,HistoryRecTime);
670                     */
671                    if (HistoryRecTime >= CurrentTime) {
672                        /* System.out.printf("outta here\n"); */
673                        break;
674                    }
675                    LandCheckTF = true;
676                    /* System.out.printf("**RecLand=%d\n",RecLand); */
677                    if (((LandFlagTF) && (RecLand == 1)) || (RecTnoRaw < 1.0)) {
678                        LandCheckTF = false;
679                        if (FirstHistoryLandRecTF) {
680                            FirstHistoryLandRecTF = false;
681                        }
682                    } else {
683                        FirstHistoryLandRecTF = true;
684                    }
685                    /* System.out.printf("**LandCheckTF=%b\n",LandCheckTF); */
686                    if ((HistoryRecTime >= CurrentTimeMinus24hr) && (HistoryRecTime < CurrentTime)
687                            && (!CurrentTimeMinus24hrTF) && (LandCheckTF)) {
688                        CurrentTimeMinus24hrTF = true;
689                        TnoValueMinus24hr = RecTFinal;
690                    }
691                    if ((HistoryRecTime >= CurrentTimeMinus18hr) && (HistoryRecTime < CurrentTime)
692                            && (!CurrentTimeMinus18hrTF) && (LandCheckTF)) {
693                        CurrentTimeMinus18hrTF = true;
694                        TnoValueMinus18hr = RecTFinal;
695                    }
696                    if ((HistoryRecTime >= CurrentTimeMinus12hr) && (HistoryRecTime < CurrentTime)
697                            && (!CurrentTimeMinus12hrTF) && (LandCheckTF)) {
698                        CurrentTimeMinus12hrTF = true;
699                        TnoValueMinus12hr = RecTFinal;
700                    }
701                    if ((HistoryRecTime >= CurrentTimeMinus6hr) && (HistoryRecTime < CurrentTime)
702                            && (!CurrentTimeMinus6hrTF) && (LandCheckTF)) {
703                        CurrentTimeMinus6hrTF = true;
704                        TnoValueMinus6hr = RecTFinal;
705                        RawTnoValueMinus6hr = RecTRaw;
706                        RawTnoValueMinus6hrTime = HistoryRecTime;
707                    }
708                    if ((HistoryRecTime >= CurrentTimeMinus1hr) && (HistoryRecTime < CurrentTime)
709                            && (!CurrentTimeMinus1hrTF) && (LandCheckTF)) {
710                        CurrentTimeMinus1hrTF = true;
711                        TnoValueMinus1hr = RecTFinal;
712                        RawTnoValueMinus1hr = RecTRaw;
713                    }
714                    if ((HistoryRecTime < CurrentTime) && (LandCheckTF)) {
715                        PreviousHistoryFinalTnoValue = RecTFinal;
716                        PreviousHistoryRule9Value = RecRule9;
717                        PreviousHistoryRapidDissIDValue = RecRapidDiss;
718                        if (RecEyeScene <= 2) {
719                            EyeSceneCounter++;
720                            NonEyeSceneCounter = 0;
721                            if (EyeSceneCounter >= 3 || HistoryVeldenRuleFlagTF) {
722                                ApplyVeldenRuleTF = false;
723                                HistoryVeldenRuleFlagTF = true;
724                            }
725                        } else {
726                            EyeSceneCounter = 0;
727                            NonEyeSceneCounter++;
728                            if (NonEyeSceneCounter >= 3) {
729                                ApplyVeldenRuleTF = true;
730                                HistoryVeldenRuleFlagTF = false;
731                            }
732                        }
733                        if (PreviousHistoryRapidDissIDValue >= 2) {
734                            ApplyVeldenRuleTF = false;
735                        }
736                    }
737                    XInc++;
738                }
739
740                /* System.out.printf("LandFlagCurrent=%d\n",LandFlagCurrent); */
741                /* added to correctly analyze current record (08/27/13) */
742                if (LandFlagCurrent == 2) {
743                    if (EyeScene <= 2) {
744                        if (EyeSceneCounter >= 2 || HistoryVeldenRuleFlagTF) {
745                            ApplyVeldenRuleTF = false;
746                        }
747                    } else {
748                        ApplyVeldenRuleTF = true;
749                    }
750                }
751                /*
752                 * System.out.printf("ApplyVeldenRuleTF=%b\n",ApplyVeldenRuleTF);
753                 */
754                Rule8Val = (Rule8AdjCatValue * 10) + 0;
755                /*
756                 * System.out.printf("Rule8AdjCatValue=%d Rule8Val=%d\n",
757                 * Rule8AdjCatValue,Rule8Val);
758                 */
759                History.IRCurrentRecord.rule8 = Rule8Val;
760                /*
761                 * System.out.printf("PreviousHistoryFinalTnoValue=%f\n",
762                 * PreviousHistoryFinalTnoValue);
763                 */
764                /*
765                 * System.out.printf("Rule8 value = %d\n",History.IRCurrentRecord
766                 * .rule8);
767                 */
768                if (PreviousHistoryFinalTnoValue < 4.0) {
769                    /* System.out.printf(" LESS THAN 4.0\n"); */
770                    /* Raw T# < 4.0 */
771                    /*
772                     * System.out.printf("First6hrRecordTF=%b\n",First6hrRecordTF
773                     * );
774                     */
775                    if (First6hrRecordTF) {
776                        if (CurrentTimeMinus1hrTF) {
777                            TnoDifferenceValueMinus1hr = Math.abs(RawTnoValueMinus1hr
778                                    - FinalIntensityEstimateValue);
779                            if (TnoDifferenceValueMinus1hr > Rule8AdjArray[Rule8AdjCatValue][8]) {
780                                FinalIntensityEstimateValue = Math
781                                        .max((RawTnoValueMinus1hr - Rule8AdjArray[Rule8AdjCatValue][8]),
782                                                Math.min(
783                                                        (RawTnoValueMinus1hr + Rule8AdjArray[Rule8AdjCatValue][8]),
784                                                        FinalIntensityEstimateValue));
785                                Rule8Val = (Rule8AdjCatValue * 10) + 8;
786                                History.IRCurrentRecord.rule8 = Rule8Val;
787                            }
788                        } else {
789                            /*
790                             * * no value available within past hour...* must
791                             * determine approx value
792                             */
793                            TnoDifferenceValueMinus1hr = 0.1 * (Math.abs(CurrentTime
794                                    - RawTnoValueMinus6hrTime) / .0416);
795                            double RawTnoMinimumValue = RawTnoValueMinus6hr
796                                    - TnoDifferenceValueMinus1hr;
797                            double RawTnoMaximumValue = RawTnoValueMinus6hr
798                                    + TnoDifferenceValueMinus1hr;
799                            if ((FinalIntensityEstimateValue > RawTnoMaximumValue)
800                                    || (FinalIntensityEstimateValue < RawTnoMinimumValue)) {
801                                FinalIntensityEstimateValue = Math.max(RawTnoMinimumValue,
802                                        Math.min(RawTnoMaximumValue, FinalIntensityEstimateValue));
803                                Rule8Val = (Rule8AdjCatValue * 10) + 8;
804                                History.IRCurrentRecord.rule8 = Rule8Val;
805                            }
806                        }
807                    } else {
808                        TnoDifferenceValueMinus1hr = Math.abs(TnoValueMinus1hr
809                                - FinalIntensityEstimateValue);
810                        /*
811                         * System.out.printf("TnoDifferenceValueMinus1hr=%f\n",
812                         * TnoDifferenceValueMinus1hr);
813                         */
814                        if ((TnoDifferenceValueMinus1hr > Rule8AdjArray[Rule8AdjCatValue][9])
815                                && (CurrentTimeMinus1hrTF) && (ApplyVeldenRuleTF)) {
816                            FinalIntensityEstimateValue = Math.max(TnoValueMinus1hr
817                                    - Rule8AdjArray[Rule8AdjCatValue][9], Math.min(TnoValueMinus1hr
818                                    + Rule8AdjArray[Rule8AdjCatValue][9],
819                                    FinalIntensityEstimateValue));
820                            Rule8Val = (Rule8AdjCatValue * 10) + 9;
821                            History.IRCurrentRecord.rule8 = Rule8Val;
822                        }
823                        TnoDifferenceValueMinus6hr = Math.abs(TnoValueMinus6hr
824                                - FinalIntensityEstimateValue);
825                        /*
826                         * System.out.printf("TnoDifferenceValueMinus6hr=%f\n",
827                         * TnoDifferenceValueMinus6hr);
828                         */
829                        /*
830                         * System.out.printf("PreviousHistoryRule9Value=%d\n",
831                         * PreviousHistoryRule9Value);
832                         */
833                        if (PreviousHistoryRule9Value < 2) {
834                            if ((TnoDifferenceValueMinus6hr > Rule8AdjArray[Rule8AdjCatValue][2])
835                                    && (CurrentTimeMinus6hrTF)) {
836                                FinalIntensityEstimateValue = Math.max(TnoValueMinus6hr
837                                        - Rule8AdjArray[Rule8AdjCatValue][2], Math.min(
838                                        TnoValueMinus6hr + Rule8AdjArray[Rule8AdjCatValue][2],
839                                        FinalIntensityEstimateValue));
840                                Rule8Val = (Rule8AdjCatValue * 10) + 2;
841                                History.IRCurrentRecord.rule8 = Rule8Val;
842                            }
843                        } else {
844                            if ((TnoDifferenceValueMinus6hr > Rule8AdjArray[Rule8AdjCatValue][1])
845                                    && (CurrentTimeMinus6hrTF)) {
846                                FinalIntensityEstimateValue = Math.max(TnoValueMinus6hr
847                                        - Rule8AdjArray[Rule8AdjCatValue][1], Math.min(
848                                        TnoValueMinus6hr + Rule8AdjArray[Rule8AdjCatValue][1],
849                                        FinalIntensityEstimateValue));
850                                Rule8Val = (Rule8AdjCatValue * 10) + 1;
851                                History.IRCurrentRecord.rule8 = Rule8Val;
852                            }
853                        }
854                    }
855                } else {
856                    /* System.out.printf(" GREATER THAN 4.0\n"); */
857                    /* Raw T# >= 4.0 */
858                    TnoDifferenceValueMinus1hr = Math.abs(TnoValueMinus1hr
859                            - FinalIntensityEstimateValue);
860                    /*
861                     * System.out.printf("TnoDifferenceValueMinus1hr=%f\n",
862                     * TnoDifferenceValueMinus1hr);
863                     */
864                    if ((TnoDifferenceValueMinus1hr > Rule8AdjArray[Rule8AdjCatValue][9])
865                            && (CurrentTimeMinus1hrTF) && (ApplyVeldenRuleTF)) {
866                        FinalIntensityEstimateValue = Math.max(TnoValueMinus1hr
867                                - Rule8AdjArray[Rule8AdjCatValue][9], Math.min(TnoValueMinus1hr
868                                + Rule8AdjArray[Rule8AdjCatValue][9], FinalIntensityEstimateValue));
869                        Rule8Val = (Rule8AdjCatValue * 10) + 9;
870                        History.IRCurrentRecord.rule8 = Rule8Val;
871                    }
872                    TnoDifferenceValueMinus6hr = Math.abs(TnoValueMinus6hr
873                            - FinalIntensityEstimateValue);
874                    TnoDifferenceValueMinus12hr = Math.abs(TnoValueMinus12hr
875                            - FinalIntensityEstimateValue);
876                    TnoDifferenceValueMinus18hr = Math.abs(TnoValueMinus18hr
877                            - FinalIntensityEstimateValue);
878                    TnoDifferenceValueMinus24hr = Math.abs(TnoValueMinus24hr
879                            - FinalIntensityEstimateValue);
880                    /*
881                     * System.out.printf("Rule8AdjCatValue=%d\n",Rule8AdjCatValue
882                     * ); /* System.out.printf(
883                     * "current6hrTF=%b TnoDifferenceValueMinus6hr=%f arrayval=%f \n"
884                     * , CurrentTimeMinus6hrTF,TnoDifferenceValueMinus6hr,
885                     * Rule8AdjArray[Rule8AdjCatValue][2]);
886                     */
887                    /*
888                     * System.out.printf(
889                     * "current12hrTF=%b TnoDifferenceValueMinus12hr=%f arrayval=%f \n"
890                     * , CurrentTimeMinus12hrTF,TnoDifferenceValueMinus12hr,
891                     * Rule8AdjArray[Rule8AdjCatValue][3]);
892                     */
893                    /*
894                     * System.out.printf(
895                     * "current18hrTF=%b TnoDifferenceValueMinus18hr=%f arrayval=%f \n"
896                     * , CurrentTimeMinus18hrTF,TnoDifferenceValueMinus18hr,
897                     * Rule8AdjArray[Rule8AdjCatValue][4]);
898                     */
899                    /*
900                     * System.out.printf(
901                     * "current24hrTF=%b TnoDifferenceValueMinus24hr=%f arrayval=%f \n"
902                     * , CurrentTimeMinus24hrTF,TnoDifferenceValueMinus24hr,
903                     * Rule8AdjArray[Rule8AdjCatValue][5]);
904                     */
905
906                    /* NEW Rule 8 MW adjustment */
907                    if (SpecialPostMWRule8EYEFlag) {
908                        Rule8TESTValue = Rule8AdjArray[Rule8AdjCatValue][6];
909                    } else {
910                        Rule8TESTValue = Rule8AdjArray[Rule8AdjCatValue][2];
911                    }
912
913                    if ((TnoDifferenceValueMinus6hr > Rule8TESTValue) && (CurrentTimeMinus6hrTF)) {
914                        /* System.out.printf("6 hr\n"); */
915                        FinalIntensityEstimateValue = Math.max(TnoValueMinus6hr - Rule8TESTValue,
916                                Math.min(TnoValueMinus6hr + Rule8TESTValue,
917                                        FinalIntensityEstimateValue));
918                        if (SpecialPostMWRule8EYEFlag) {
919                            Rule8Val = (Rule8AdjCatValue * 10) + 6;
920                        } else {
921                            Rule8Val = (Rule8AdjCatValue * 10) + 2;
922                        }
923                        History.IRCurrentRecord.rule8 = Rule8Val;
924                    } else if ((TnoDifferenceValueMinus12hr > Rule8AdjArray[Rule8AdjCatValue][3])
925                            && (CurrentTimeMinus12hrTF)) {
926                        /* System.out.printf("12 hr\n"); */
927                        FinalIntensityEstimateValue = Math.max(TnoValueMinus12hr
928                                - Rule8AdjArray[Rule8AdjCatValue][3], Math.min(TnoValueMinus12hr
929                                + Rule8AdjArray[Rule8AdjCatValue][3], FinalIntensityEstimateValue));
930                        Rule8Val = (Rule8AdjCatValue * 10) + 3;
931                        History.IRCurrentRecord.rule8 = Rule8Val;
932                    } else if ((TnoDifferenceValueMinus18hr > Rule8AdjArray[Rule8AdjCatValue][4])
933                            && (CurrentTimeMinus18hrTF)) {
934                        /* System.out.printf("18 hr\n"); */
935                        FinalIntensityEstimateValue = Math.max(TnoValueMinus18hr
936                                - Rule8AdjArray[Rule8AdjCatValue][4], Math.min(TnoValueMinus18hr
937                                + Rule8AdjArray[Rule8AdjCatValue][4], FinalIntensityEstimateValue));
938                        Rule8Val = (Rule8AdjCatValue * 10) + 4;
939                        History.IRCurrentRecord.rule8 = Rule8Val;
940                    } else if ((TnoDifferenceValueMinus24hr > Rule8AdjArray[Rule8AdjCatValue][5])
941                            && (CurrentTimeMinus24hrTF)) {
942                        /* System.out.printf("24 hr\n"); */
943                        FinalIntensityEstimateValue = Math.max(TnoValueMinus24hr
944                                - Rule8AdjArray[Rule8AdjCatValue][5], Math.min(TnoValueMinus24hr
945                                + Rule8AdjArray[Rule8AdjCatValue][5], FinalIntensityEstimateValue));
946                        Rule8Val = (Rule8AdjCatValue * 10) + 5;
947                        History.IRCurrentRecord.rule8 = Rule8Val;
948                    } else {
949                        /* System.out.printf("default \n"); */
950                        History.IRCurrentRecord.rule8 = Rule8Val;
951                    }
952                }
953            }
954        }
955        /*
956         * System.out.printf("Rule 8 value @ end of intensity calc=%d\n",History.
957         * IRCurrentRecord.rule8);
958         */
959        if (MWOFFTF) {
960            /* printf("holding Rule 8 flag to 34\n"); */
961            History.IRCurrentRecord.rule8 = 34;
962        }
963        /*
964         * * NOTE : additional function return points above* - return Global
965         * Initial Strength Value if new history file or* inserting before first
966         * record in existing file
967         */
968
969        if (Env.DEBUG == 100) {
970            System.out.printf("FinalIntensityEstimateValue=%f\n", FinalIntensityEstimateValue);
971        }
972
973        TnoRawValue = FinalIntensityEstimateValue;
974        double ReturnMWAnalysisFlag = (double) MWAnalysisFlag;
975
976        return new double[] { TnoRawValue, ReturnMWAnalysisFlag };
977    }
978
979    /**
980     * Compute time averaged T-Number value using previous and current intensity
981     * estimates.
982     *
983     * <p>
984     * Average using a time-weighted averaging scheme.
985     * </p>
986     *
987     * @param TimeAvgDurationID
988     *            Time average duration flag. Use {@code 0} for 6 hour and
989     *            {@code 1} for 3 hour.
990     *
991     * @return Final T# value.
992     */
993    public static double adt_TnoFinal(int TimeAvgDurationID) {
994        /* double TnoFinalValue = 0.0; */
995
996        double TnoFinalValue = History.IRCurrentRecord.Traw;
997
998        /* int TimeAvgDurationID = 0; */
999        double OneHourInterval = 1.0 / 24.0;
1000        double BaseTimeAvgValueHrs;
1001        double FinalTnoValue;
1002        double AverageValue = 0.0;
1003        double AverageValueSum = 0.0;
1004        double WeightValue = 0.0;
1005        double WeightValueSum = 0.0;
1006        boolean FoundValuesTF = false;
1007        boolean LandCheckTF = false;
1008
1009        if (TimeAvgDurationID == 1) {
1010            BaseTimeAvgValueHrs = 3.0; /* for NHC 3-hour time average value */
1011        } else if (TimeAvgDurationID == 2) {
1012            BaseTimeAvgValueHrs = 12.0; /* for TIE Model time average value */
1013        } else {
1014            BaseTimeAvgValueHrs = 6.0;
1015        }
1016
1017        int ImageDate = History.IRCurrentRecord.date;
1018        int ImageTime = History.IRCurrentRecord.time;
1019        double CurrentTime = Functions.calctime(ImageDate, ImageTime);
1020        int NumRecsHistory = History.HistoryNumberOfRecords();
1021        boolean LandFlagTF = Env.LandFlagTF;
1022
1023        /*
1024         * compute average with current value with any values from previous 6
1025         * hours
1026         */
1027        double BeginningTime = CurrentTime - (BaseTimeAvgValueHrs / 24.0);
1028
1029        int XInc = 0;
1030        while (XInc < NumRecsHistory) {
1031            int RecDate = History.HistoryFile[XInc].date;
1032            int RecTime = History.HistoryFile[XInc].time;
1033            double HistoryRecTime = Functions.calctime(RecDate, RecTime);
1034            if ((HistoryRecTime >= BeginningTime) && (HistoryRecTime < CurrentTime)) {
1035                LandCheckTF = true;
1036                if (TimeAvgDurationID <= 1) {
1037                    AverageValue = History.HistoryFile[XInc].Traw;
1038                } else {
1039                    if (AverageValue < 0.0) {
1040                        AverageValue = 0.0;
1041                    }
1042                }
1043
1044                int RecLand = History.HistoryFile[XInc].land;
1045                if (((LandFlagTF) && (RecLand == 1)) || (AverageValue < 1.0)) {
1046                    LandCheckTF = false;
1047                }
1048                if (LandCheckTF) {
1049                    double TimeDifference = CurrentTime - HistoryRecTime;
1050                    if (TimeAvgDurationID == 0) {
1051                        /* time weighted average */
1052                        WeightValue = (BaseTimeAvgValueHrs - (TimeDifference / OneHourInterval));
1053                    } else {
1054                        /* straight average */
1055                        WeightValue = BaseTimeAvgValueHrs;
1056                    }
1057                    AverageValueSum = AverageValueSum + (WeightValue * AverageValue);
1058                    WeightValueSum = WeightValueSum + WeightValue;
1059                    FoundValuesTF = true;
1060                }
1061            } else {
1062                if (FoundValuesTF) {
1063                    break;
1064                }
1065            }
1066            XInc++;
1067        }
1068        /*
1069         * compute time-averaged T# value. if no previous records found, return
1070         * Raw T#
1071         */
1072        /* System.out.printf("TRAW=%f\n",History.IRCurrentRecord.Traw); */
1073        if (TimeAvgDurationID <= 1) {
1074            AverageValue = History.IRCurrentRecord.Traw;
1075        } else {
1076            if (AverageValue <= 1.0) {
1077                FoundValuesTF = false;
1078            }
1079        }
1080        /*
1081         * System.out.printf("foundvaluestf=%b averagevalue=%f\n",FoundValuesTF,
1082         * AverageValue);
1083         */
1084        if (FoundValuesTF) {
1085            AverageValueSum = AverageValueSum + (BaseTimeAvgValueHrs * AverageValue);
1086            WeightValueSum = WeightValueSum + BaseTimeAvgValueHrs;
1087            /* remove any value remainder past tenths */
1088            FinalTnoValue = (double) ((int) (((AverageValueSum / WeightValueSum) + 0.01) * 10.0)) / 10.0;
1089        } else {
1090            FinalTnoValue = AverageValue;
1091        }
1092        /* System.out.printf("finaltnovalue=%f\n",FinalTnoValue); */
1093
1094        TnoFinalValue = FinalTnoValue;
1095
1096        return TnoFinalValue;
1097    }
1098
1099    /**
1100     * Compute final CI-Number applying various Dvorak Rules, such as the now
1101     * famous Rule 9.
1102     *
1103     * @param HistoryFileName
1104     *            Path to history file.
1105     *
1106     * @return Array of two doubles. First value represents current intensity,
1107     *         and the second represents the current strengthening/weakening
1108     *         flag.
1109     */
1110    // TODO(jon): WHAT IS THIS FAMOUS RULE NUMBER 9!?
1111    public static double[] adt_CIno(String HistoryFileName) {
1112        int RapidDissIDValue = 0;
1113        int CurrentStrengthIDValue;
1114        int PreviousHistoryRule9Value = 0;
1115        ;
1116        int Rule9IDValue;
1117        double PreviousHistoryFinalTnoValue;
1118        double IntensityValue;
1119        double TnoMinimumValue = 9.0; /* T# minimum value */
1120        double TnoMaximumValue = 0.0; /* T# maximum value */
1121        double Rule9AdditiveValue = 1.0;
1122        double CIadjP;
1123        boolean LandOnly12hrTF = true; /* land only during last 12hrs logical */
1124        boolean LandCheckTF = true;
1125
1126        int ImageDate = History.IRCurrentRecord.date;
1127        int ImageTime = History.IRCurrentRecord.time;
1128        double CurrentTime = Functions.calctime(ImageDate, ImageTime);
1129        double Latitude = History.IRCurrentRecord.latitude;
1130        double Longitude = History.IRCurrentRecord.longitude;
1131        boolean LandFlagTF = Env.LandFlagTF;
1132        double InitStrengthValue = Env.InitRawTValue;
1133        boolean InitStrengthTF = Env.InitStrengthTF;
1134
1135        int NumRecsHistory = History.HistoryNumberOfRecords();
1136        if (NumRecsHistory == 0) {
1137            /* no records in history file */
1138            IntensityValue = History.IRCurrentRecord.Traw;
1139            CurrentStrengthIDValue = 0;
1140            /*
1141             * this will trip the RULE 9 FLAG for an initial classification of
1142             * >=6.0
1143             */
1144            if (InitStrengthValue >= 6.0) {
1145                CurrentStrengthIDValue = 2;
1146            }
1147            /* Apply Latitude Bias Adjustment to CI value */
1148            // CIadjP =
1149            // adt_latbias(InitStrengthTF,LandFlagTF,HistoryFileName,IntensityValue,Latitude,Longitude);
1150            CIadjP = adt_latbias(InitStrengthTF, LandFlagTF, HistoryFileName, Latitude, Longitude);
1151            History.IRCurrentRecord.CIadjp = CIadjP;
1152            /* return Raw T# for CI# for initial analysis */
1153            return new double[] { IntensityValue, (double) CurrentStrengthIDValue }; /* EXIT */
1154        }
1155        /*
1156         * MW Eye Score Adjustment being applied... let CI# = Final T# and
1157         * return
1158         */
1159        int Rule8Current = History.IRCurrentRecord.rule8;
1160        if ((Rule8Current >= 30) && (Rule8Current <= 33)) {
1161            IntensityValue = History.IRCurrentRecord.Tfinal;
1162            /* Apply Latitude Bias Adjustment to CI value */
1163            // CIadjP =
1164            // adt_latbias(InitStrengthTF,LandFlagTF,HistoryFileName,IntensityValue,Latitude,Longitude);
1165            CIadjP = adt_latbias(InitStrengthTF, LandFlagTF, HistoryFileName, Latitude, Longitude);
1166            History.IRCurrentRecord.CIadjp = CIadjP;
1167            CurrentStrengthIDValue = 0;
1168            return new double[] { IntensityValue, (double) CurrentStrengthIDValue }; /* EXIT */
1169        }
1170
1171        /* determine various time threshold values */
1172        double CurrentTimeMinus6Hrs = CurrentTime - 0.25;
1173        double CurrentTimeMinus24Hrs = CurrentTime - 1.0;
1174
1175        /* find record just prior to current record */
1176        double PreviousHistoryTnoMaximumValue = 0.0;
1177        double PreviousHistoryTnoMaximum6hrValue = 0.0;
1178        double PreviousHistoryCIValue = 0.0;
1179        double PreviousHistoryRapidDissIDValue = 0;
1180        double PreviousHistoryRapidDissIDMinimumValue = 99;
1181        int XInc = 0;
1182        while (XInc < NumRecsHistory) {
1183            int RecDate = History.HistoryFile[XInc].date;
1184            int RecTime = History.HistoryFile[XInc].time;
1185            double HistoryRecTime = Functions.calctime(RecDate, RecTime);
1186            if (HistoryRecTime >= CurrentTime) {
1187                break;
1188            }
1189            int RecLand = History.HistoryFile[XInc].land;
1190            double Traw = History.HistoryFile[XInc].Traw;
1191            LandCheckTF = true;
1192            if (((LandFlagTF) && (RecLand == 1)) || (Traw < 1.0)) {
1193                LandCheckTF = false;
1194            }
1195            if (LandCheckTF) {
1196                PreviousHistoryFinalTnoValue = History.HistoryFile[XInc].Tfinal;
1197                PreviousHistoryCIValue = History.HistoryFile[XInc].CI;
1198                PreviousHistoryRule9Value = History.HistoryFile[XInc].rule9;
1199                PreviousHistoryRapidDissIDValue = History.HistoryFile[XInc].rapiddiss;
1200                /* check Rule 9 */
1201                if (HistoryRecTime >= CurrentTimeMinus6Hrs) {
1202                    /*
1203                     * find largest finalT# in last 6 hours prior to current
1204                     * record
1205                     */
1206                    if (PreviousHistoryFinalTnoValue > PreviousHistoryTnoMaximumValue) {
1207                        PreviousHistoryTnoMaximumValue = PreviousHistoryFinalTnoValue;
1208                    }
1209                }
1210                if (HistoryRecTime >= CurrentTimeMinus6Hrs) {
1211                    /*
1212                     * if storm is over land for SIX hours, turn off Rule 9
1213                     * (changed from 12 hours)
1214                     */
1215                    LandOnly12hrTF = false;
1216
1217                    /* rapid dissapation check */
1218                    if (PreviousHistoryRapidDissIDValue < PreviousHistoryRapidDissIDMinimumValue) {
1219                        PreviousHistoryRapidDissIDMinimumValue = PreviousHistoryRapidDissIDValue;
1220                    }
1221                    if (PreviousHistoryFinalTnoValue > PreviousHistoryTnoMaximum6hrValue) {
1222                        PreviousHistoryTnoMaximum6hrValue = PreviousHistoryFinalTnoValue;
1223                    }
1224                }
1225                if (HistoryRecTime >= CurrentTimeMinus24Hrs) {
1226                    /*
1227                     * find min and max finalT# in last 24 hours prior to
1228                     * current record
1229                     */
1230                    if (PreviousHistoryFinalTnoValue < TnoMinimumValue) {
1231                        TnoMinimumValue = PreviousHistoryFinalTnoValue;
1232                    }
1233                    if (PreviousHistoryFinalTnoValue > TnoMaximumValue) {
1234                        TnoMaximumValue = PreviousHistoryFinalTnoValue;
1235                    }
1236                }
1237            }
1238            XInc++;
1239        }
1240
1241        IntensityValue = History.IRCurrentRecord.Tfinal;
1242
1243        if (XInc == 0) {
1244            /* current record is before first record in history file */
1245            CurrentStrengthIDValue = 0;
1246            /* Apply Latitude Bias Adjustment to CI value */
1247            // CIadjP =
1248            // adt_latbias(InitStrengthTF,LandFlagTF,HistoryFileName,IntensityValue,Latitude,Longitude);
1249            CIadjP = adt_latbias(InitStrengthTF, LandFlagTF, HistoryFileName, Latitude, Longitude);
1250            History.IRCurrentRecord.CIadjp = CIadjP;
1251            /* return Final T# for CI# for initial analysis */
1252            return new double[] { IntensityValue, (double) CurrentStrengthIDValue }; /* EXIT */
1253        }
1254
1255        Rule9IDValue = PreviousHistoryRule9Value;
1256        int[] ReturnValues3 = Functions.adt_oceanbasin(Latitude, Longitude);
1257        int BasinID_Local = ReturnValues3[0];
1258
1259        /* rapid dissipation determination */
1260        double Slope6hrValue = Functions.adt_slopecal(6.0, 2);
1261        if (PreviousHistoryRapidDissIDValue <= 1) {
1262            RapidDissIDValue = 0;
1263            /* if(Slope6hrValue>=2.0) { */
1264            /* relax rapid weakening criteria for the East Pac */
1265            if (((BasinID_Local != 2) && (Slope6hrValue >= 2.0))
1266                    || ((BasinID_Local == 2) && (Slope6hrValue >= 1.5))) {
1267                /* 2.0/24 hours or 1.5/24 hours for East Pac */
1268                RapidDissIDValue = 1;
1269            }
1270            if ((PreviousHistoryRapidDissIDMinimumValue == 1) && (RapidDissIDValue == 1)) {
1271                Rule9AdditiveValue = 0.5;
1272                RapidDissIDValue = 2;
1273            }
1274        } else {
1275            Rule9AdditiveValue = 0.5;
1276            RapidDissIDValue = 2;
1277            /* if(Slope6hrValue<1.5) { */
1278            if (((BasinID_Local != 2) && (Slope6hrValue < 1.5))
1279                    || ((BasinID_Local == 2) && (Slope6hrValue < 1.0))) {
1280                /* 1.5/24 hours or 1.0/24 hours for East Pac */
1281                RapidDissIDValue = 3;
1282            }
1283            if ((PreviousHistoryRapidDissIDMinimumValue == 3) && (RapidDissIDValue == 3)) {
1284                Rule9AdditiveValue = 1.0;
1285                RapidDissIDValue = 0;
1286            }
1287        }
1288
1289        /*
1290         * strength flags : 0 - strengthening, but not significant 1 - applying
1291         * Max's 12 hour max Tno. rule
1292         */
1293        /* determine CI# */
1294        double CurrentTnoValue = IntensityValue;
1295        double CurrentTnoPlusRule9Value = IntensityValue + Rule9AdditiveValue;
1296        /*
1297         * We have once again returned to using the 6 hour Max T# value for all
1298         * basins for the Rule 9 check
1299         */
1300        double CIValue = Math.min(CurrentTnoPlusRule9Value,
1301                Math.max(PreviousHistoryTnoMaximumValue, CurrentTnoValue));
1302
1303        /* will utilize Max's Rule all of the time */
1304        if (CIValue > CurrentTnoValue) {
1305            Rule9IDValue = 1;
1306        }
1307        if ((PreviousHistoryRule9Value == 1) && (PreviousHistoryCIValue <= CurrentTnoValue)) {
1308            Rule9IDValue = 0;
1309        }
1310
1311        /*
1312         * check for land interaction if undergoing interactation with land
1313         * "turn off" Rule 9 application and return CI value to Adjusted Raw Tno
1314         * value for >= 3 hours (was 12 hours)
1315         */
1316        if (LandOnly12hrTF) {
1317            /*
1318             * if land flag is TRUE, turn off Rule 9 and let CI value be equal
1319             * to the current Adjusted Raw T# value, and return (was Final T#)
1320             * current intensity flag to "insignificant value" until another
1321             * significant strengtheing cycle occurs
1322             */
1323            Rule9IDValue = 0;
1324            CIValue = History.IRCurrentRecord.Traw;
1325            RapidDissIDValue = 0;
1326        }
1327        /* Apply Latitude Bias Adjustment to CI value */
1328        // CIadjP =
1329        // adt_latbias(InitStrengthTF,LandFlagTF,HistoryFileName,CIValue,Latitude,Longitude);
1330        CIadjP = adt_latbias(InitStrengthTF, LandFlagTF, HistoryFileName, Latitude, Longitude);
1331        /* System.out.printf("CIno: ciadjp=%f\n",CIadjP); */
1332        History.IRCurrentRecord.CIadjp = CIadjP;
1333        History.IRCurrentRecord.rapiddiss = RapidDissIDValue;
1334
1335        CurrentStrengthIDValue = Rule9IDValue;
1336
1337        return new double[] { CIValue, (double) CurrentStrengthIDValue };
1338    }
1339
1340    /**
1341     * Apply Latitude Bias Adjustment to CI value.
1342     *
1343     * @param InitStrengthTF
1344     * @param LandFlagTF
1345     *            Flag that represents land status.
1346     * @param HistoryFileName
1347     *            Path to history file.
1348     * @param InputLatitude
1349     *            Current latitude of storm.
1350     * @param InputLongitude
1351     *            Current longitude of storm.
1352     *
1353     * @return Adjusted MSLP value.
1354     */
1355    public static double adt_latbias(boolean InitStrengthTF, boolean LandFlagTF,
1356            String HistoryFileName, double InputLatitude, double InputLongitude) {
1357        double ReturnCIPressureAdjValue = 0.0;
1358        boolean UseCKZTF = Env.UseCKZTF;
1359        if (!UseCKZTF) {
1360            double[] RetVals = adt_scenesearch(HistoryFileName, InitStrengthTF, LandFlagTF);
1361            int LatBiasAdjFlagID = (int) RetVals[0];
1362            double AdjustmentMultFactor = RetVals[1];
1363            History.IRCurrentRecord.LBflag = LatBiasAdjFlagID;
1364            /* System.out.printf("latbiasadjflagid=%d\n",LatBiasAdjFlagID); */
1365            if (LatBiasAdjFlagID >= 2) {
1366                /* EIR scene */
1367                if ((InputLatitude >= 0.0)
1368                        && ((InputLongitude >= -100.0) && (InputLongitude <= -40.0))) {
1369                    /* do not make adjustment in N Indian Ocean */
1370                    ReturnCIPressureAdjValue = 0.0;
1371                } else {
1372                    /* apply bias adjustment to pressure */
1373                    ReturnCIPressureAdjValue = AdjustmentMultFactor
1374                            * (7.325 - (0.302 * Math.abs(InputLatitude)));
1375                }
1376            }
1377        }
1378        return ReturnCIPressureAdjValue;
1379    }
1380
1381    /**
1382     * Search for valid scene range for Latitude Bias Adjustment application.
1383     * Inputs : None Outputs : AdjustmentMultFactor_Return - multiplicative
1384     * value for merging Return : 0 - first record in new history file 1 - non
1385     * Enhanced Infrared scene or intermediate/merging application 2 -
1386     * entering/leaving valid adjustment time period. Also used for non-history
1387     * file intensity analysis (full adjustment)
1388     *
1389     * @param HistoryFileName
1390     *            Path to history file.
1391     * @param InitStrengthTF
1392     * @param LandFlagTF
1393     *            Over land?
1394     *
1395     * @return Array of two doubles. The first value represents latitude bias
1396     *         adjustment, while the second value represents the adjustment's
1397     *         multiplicative factor.
1398     */
1399    public static double[] adt_scenesearch(String HistoryFileName, boolean InitStrengthTF,
1400            boolean LandFlagTF) {
1401        int LatBiasAdjFlagID = -1;
1402        double AdjustmentMultFactor = 0.0;
1403
1404        int NumRecsHistory = History.HistoryNumberOfRecords();
1405        if (((NumRecsHistory == 0) && (InitStrengthTF)) && (HistoryFileName != null)) {
1406            return new double[] { 0.0, -999.9 };
1407        }
1408        if (HistoryFileName == null) {
1409            return new double[] { 2.0, 1.0 };
1410        }
1411
1412        int HistoryRecLatBiasAdjFlagIDValue = 0;
1413
1414        int CloudScene = History.IRCurrentRecord.cloudscene;
1415        /* System.out.printf("cloudscene=%d\n",CloudScene); */
1416        if ((CloudScene >= 2) && (CloudScene < 6))
1417            LatBiasAdjFlagID = 0;
1418
1419        int ImageDate = History.IRCurrentRecord.date;
1420        int ImageTime = History.IRCurrentRecord.time;
1421        double CurrentTime = Functions.calctime(ImageDate, ImageTime);
1422        double CurrentTimeMinus6hr = CurrentTime - 0.26;
1423        double MergePeriodFirstTime = CurrentTime;
1424
1425        int RecDate, RecTime, RecLand;
1426        double HistoryRecTime;
1427        double RecTnoRaw;
1428        boolean LandCheckTF = true;
1429        boolean EIRSceneTypeTF = true;
1430        boolean FoundMergePeriodFirstRecordTF = false;
1431        double FirstHistoryRecTime = -99999.0;
1432
1433        int XInc = 0;
1434        while (XInc < NumRecsHistory) {
1435            RecDate = History.HistoryFile[XInc].date;
1436            RecTime = History.HistoryFile[XInc].time;
1437            HistoryRecTime = Functions.calctime(RecDate, RecTime);
1438            RecLand = History.HistoryFile[XInc].land;
1439            RecTnoRaw = History.HistoryFile[XInc].Traw;
1440            if (((LandFlagTF) && (RecLand == 1)) || (RecTnoRaw < 1.0)) {
1441                LandCheckTF = false;
1442            }
1443            if ((HistoryRecTime < CurrentTime) && (LandCheckTF)) {
1444                HistoryRecLatBiasAdjFlagIDValue = History.HistoryFile[XInc].LBflag;
1445                /*
1446                 * System.out.printf(
1447                 * "Historyrectime=%f  Currtimem6=%f  eirscenetypetf=%b\n"
1448                 * ,HistoryRecTime,CurrentTimeMinus6hr,EIRSceneTypeTF);
1449                 */
1450                if ((HistoryRecTime >= CurrentTimeMinus6hr) && (EIRSceneTypeTF)) {
1451                    if (FirstHistoryRecTime < 0.0) {
1452                        FirstHistoryRecTime = HistoryRecTime;
1453                    }
1454                    /*
1455                     * System.out.printf("HistoryRecLatBiasAdjFlagIDValue=%d\n",
1456                     * HistoryRecLatBiasAdjFlagIDValue);
1457                     */
1458                    if (HistoryRecLatBiasAdjFlagIDValue == 0) {
1459                        EIRSceneTypeTF = false;
1460                    }
1461                    if (HistoryRecLatBiasAdjFlagIDValue == 2) {
1462                        if (!FoundMergePeriodFirstRecordTF) {
1463                            MergePeriodFirstTime = HistoryRecTime;
1464                            FoundMergePeriodFirstRecordTF = true;
1465                        }
1466                    }
1467                }
1468            }
1469            XInc++;
1470        }
1471
1472        /*
1473         * System.out.printf("scenesearch: FirstHistoryRecTime=%f\n",
1474         * FirstHistoryRecTime);
1475         */
1476        if (FirstHistoryRecTime < 0.0) {
1477            /*
1478             * there is a six hour gap in the data for some reason... I will use
1479             * the last value available
1480             */
1481            LatBiasAdjFlagID = HistoryRecLatBiasAdjFlagIDValue;
1482            if (HistoryRecLatBiasAdjFlagIDValue >= 1) {
1483                LatBiasAdjFlagID = 2;
1484            }
1485            AdjustmentMultFactor = 1.0;
1486        } else {
1487            /*
1488             * System.out.printf("scenesearch: eirscenetypetf=%b",EIRSceneTypeTF)
1489             * ;
1490             */
1491            if (EIRSceneTypeTF) {
1492                /* entering or in valid lat bias adjustment period */
1493                LatBiasAdjFlagID = 2;
1494                /* return value from 0 to 1 */
1495                AdjustmentMultFactor = (CurrentTime - MergePeriodFirstTime)
1496                        / (CurrentTime - FirstHistoryRecTime);
1497            } else {
1498                /* LatBiasAdjFlagID = LatBiasAdjFlagID; */
1499                AdjustmentMultFactor = -999.0;
1500            }
1501        }
1502        return new double[] { (double) LatBiasAdjFlagID, AdjustmentMultFactor };
1503    }
1504}