001/* 002 * This file is part of McIDAS-V 003 * 004 * Copyright 2007-2018 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 http://www.gnu.org/licenses. 027 */ 028 029package edu.wisc.ssec.mcidasv.adt; 030 031import java.io.File; 032import java.io.IOException; 033 034public class Main { 035 036 public static String HistoryFileName; 037 public static String ReturnOutputString; 038 039 public Main() { 040 HistoryFileName = null; 041 ReturnOutputString = null; 042 } 043 044 public int GetInitialPosition() { 045 046 Auto AutoMode = new Auto(); 047 048 String ForecastFileName = null; 049 double[] AutoMode1Return = null; 050 051 boolean RunAuto = Env.AutoTF; 052 ForecastFileName = Env.ForecastFileName; 053 int ForecastFileType = Env.ForecastFileType; 054 055 System.out.printf("Run AUTO=%b\n", RunAuto); 056 if (RunAuto) { 057 try { 058 AutoMode1Return = AutoMode.AutoMode1(ForecastFileName, ForecastFileType); 059 060 if (AutoMode1Return == null) 061 return -1; 062 063 if (((int) AutoMode1Return[0]) < 0) { 064 System.out.printf("ERROR with interpolation/extrapolation : return code %d\n", 065 (int) AutoMode1Return[0]); 066 return -1; 067 } 068 } catch (IOException exception) { 069 System.out.printf("ERROR with reading forecast file\n"); 070 return -2; 071 } 072 int ForecastReturnFlag = (int) AutoMode1Return[0]; 073 double ForecastLatitude = AutoMode1Return[1]; 074 double ForecastLongitude = AutoMode1Return[2]; 075 double ForecastIntensity = AutoMode1Return[3]; 076 double ForecastMethodID = AutoMode1Return[4]; 077 078 Env.SelectedLatitude = ForecastLatitude; 079 Env.SelectedLongitude = ForecastLongitude; 080 081 History.IRCurrentRecord.latitude = ForecastLatitude; 082 History.IRCurrentRecord.longitude = ForecastLongitude; 083 History.IRCurrentRecord.autopos = 1; // forecast interpolation 084 System.out 085 .printf("AutoMode1 output position info : Latitude=%f Longitude=%f Intensity=%f MethodID=%f Flag=%d\n", 086 ForecastLatitude, ForecastLongitude, ForecastIntensity, 087 ForecastMethodID, ForecastReturnFlag); 088 089 } else { 090 System.out.printf("Manual Mode : latitude=%f longitude=%f", Env.SelectedLatitude, 091 Env.SelectedLongitude); 092 History.IRCurrentRecord.latitude = Env.SelectedLatitude; 093 History.IRCurrentRecord.longitude = Env.SelectedLongitude; 094 History.IRCurrentRecord.autopos = 0; // Manual 095 } 096 097 return 1; 098 099 } 100 101 public void GetARCHERPosition() { 102 103 double[] AutoMode2Return = null; 104 double InputLatitude = Env.SelectedLatitude; 105 double InputLongitude = Env.SelectedLongitude; 106 try { 107 AutoMode2Return = Auto.AutoMode2(InputLatitude, InputLongitude); 108 } catch (IOException exception) { 109 System.out.printf("ERROR with Automode2 routine\n"); 110 return; 111 } 112 113 double FinalLatitude = AutoMode2Return[0]; 114 double FinalLongitude = AutoMode2Return[1]; 115 int FinalPositioningMethod = (int) AutoMode2Return[2]; 116 History.IRCurrentRecord.latitude = FinalLatitude; 117 History.IRCurrentRecord.longitude = FinalLongitude; 118 History.IRCurrentRecord.autopos = FinalPositioningMethod; 119 120 Env.SelectedLatitude = History.IRCurrentRecord.latitude; 121 Env.SelectedLongitude = History.IRCurrentRecord.longitude; 122 123 return; 124 125 } 126 127 public String RunADTAnalysis(boolean RunFullAnalysis, String InputHistoryFile) 128 throws IOException { 129 130 String BulletinOutput = null; 131 int HistoryFileRecords; 132 133 History CurrentHistory = new History(); 134 135 HistoryFileName = InputHistoryFile; 136 137 boolean OverrideScene = Env.OverSceneTF; 138 int OverrideSceneTypeValue = Env.OverrideSceneTypeIndex; 139 140 /* 141 * System.out.printf("MW Info : Date=%s JulianDate=%d Time=%d Score=%f\n" 142 * ,MWDate,Env.MWJulianDate,MWTime,MWScore); 143 */ 144 145 /* READ HISTORY FILE INFORMATION */ 146 if (RunFullAnalysis && HistoryFileName != null) { 147 try { 148 CurrentHistory.ReadHistoryFile(HistoryFileName); 149 } catch (IOException exception) { 150 System.out.printf("History file %s not found\n", HistoryFileName); 151 } 152 } else { 153 System.out.printf("Not utilizing a history file\n"); 154 } 155 HistoryFileRecords = History.HistoryNumberOfRecords(); 156 System.out.printf("Number of records in history file %s is %d\n", HistoryFileName, 157 HistoryFileRecords); 158 159 /* read topography file at center position */ 160 double PositionLatitude = History.IRCurrentRecord.latitude; 161 double PositionLongitude = History.IRCurrentRecord.longitude; 162 String topoPath = new File(".").getCanonicalPath(); 163 System.err.println("topoPath: " + topoPath); 164 String TopoFileName = "/edu/wisc/ssec/mcidasv/resources/digelev_hires_le.map"; 165 166 int TopographyFlag = 0; 167 System.out.printf("TOPO Info : File=%s Lat=%f Lon=%f\n", TopoFileName, PositionLatitude, 168 PositionLongitude); 169 try { 170 TopographyFlag = Topo.ReadTopoFile(TopoFileName, PositionLatitude, PositionLongitude); 171 } catch (IOException e) { 172 System.err.printf("ERROR reading topography file\n"); 173 e.printStackTrace(); 174 return null; 175 } 176 /* System.out.printf("after topo read flag=%d\n",TopographyFlag); */ 177 History.IRCurrentRecord.land = TopographyFlag; 178 179 /* Calculate Eye and Cloud region temperatures */ 180 Data.CalcEyeCloudTemps(); 181 /* System.out.printf("after calceyecloudtemps\n"); */ 182 /* 183 * double Eye_Temperature = History.IRCurrentRecord.eyet; double 184 * CWCloud_Temperature = History.IRCurrentRecord.cwcloudt; double 185 * Cloud_Temperature = History.IRCurrentRecord.cloudt; double 186 * Cloud2_Temperature = History.IRCurrentRecord.cloudt2; double 187 * Cloud_Symmetry = History.IRCurrentRecord.cloudsymave; double Eye_STDV 188 * = History.IRCurrentRecord.eyestdv; int CWRing_Distance = 189 * History.IRCurrentRecord.cwring; 190 * System.out.printf("Eye Temperature=%f\n",Eye_Temperature); 191 * System.out.printf("CWCloud Temperature=%f\n",CWCloud_Temperature); 192 * System.out.printf("CWRing Distance=%d\n",CWRing_Distance); 193 * System.out.printf("Cloud Temperature=%f\n",Cloud_Temperature); 194 * System.out.printf("Cloud2 Temperature=%f\n",Cloud2_Temperature); 195 * System.out.printf("Cloud Symmetry=%f\n",Cloud_Symmetry); 196 * System.out.printf("Eye STDV=%f\n",Eye_STDV); 197 */ 198 199 /* Calculate Eye and Cloud region Scene Type */ 200 201 /* 202 * System.out.printf("overridescenetypevalue=%d\n", 203 * OverrideSceneTypeValue); 204 */ 205 if (OverrideSceneTypeValue >= 0) { 206 /* System.out.printf("setting old scene types\n"); */ 207 History.IRCurrentRecord.cloudsceneold = History.IRCurrentRecord.cloudscene; 208 History.IRCurrentRecord.eyesceneold = History.IRCurrentRecord.eyescene; 209 History.IRCurrentRecord.cloudscene = Math.max(0, (OverrideSceneTypeValue - 3)); 210 History.IRCurrentRecord.eyescene = Math.min(3, OverrideSceneTypeValue); 211 212 } else { 213 Scene.DetermineSceneType(RunFullAnalysis); 214 /* System.out.printf("after scene type determination\n"); */ 215 /* System.out.printf("OverrideScene=%b\n",OverrideScene); */ 216 if (OverrideScene) { 217 /* 218 * System.out.printf("overriding scene type : eye=%d cloud=%d\n", 219 * History 220 * .IRCurrentRecord.eyescene,History.IRCurrentRecord.cloudscene 221 * ); 222 */ 223 if (History.IRCurrentRecord.eyescene < 3) { 224 Env.OverrideSceneTypeIndex = History.IRCurrentRecord.eyescene; 225 } else { 226 Env.OverrideSceneTypeIndex = 3 + History.IRCurrentRecord.cloudscene; 227 } 228 /* 229 * System.out.printf("ADTEnv.overridescenetype=%d\n", 230 * Env.OverrideSceneType); 231 */ 232 return "override"; 233 } 234 } 235 236 /* Calculate Intensity Estimate Values */ 237 238 int RedoIntensityFlag = 0; 239 Intensity.CalculateIntensity(RedoIntensityFlag, RunFullAnalysis, HistoryFileName); 240 /* System.out.printf("after calcintensity\n"); */ 241 /* Write Bulletin Output */ 242 243 BulletinOutput = Output.TextScreenOutput(HistoryFileName); 244 /* System.out.printf("\n *** Bulletin Output ***\n%s\n",BulletinOutput); */ 245 /* System.out.printf("after textscreenoutput\n"); */ 246 ReturnOutputString = BulletinOutput; 247 248 return ReturnOutputString; 249 250 } 251}