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