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.DataInputStream; 032import java.io.IOException; 033import java.io.InputStream; 034 035public class Topo { 036 037 public Topo() { 038 } 039 040 public static int ReadTopoFile(String topofile, double inputlat, double inputlon) throws IOException { 041 042 int num_lon_elev=5760; 043 int num_lat_elev=2880; 044 double first_lon_elev=0.0; 045 double first_lat_elev=90.0; 046 double last_lon_elev=360.0; 047 double last_lat_elev=-90.0; 048 049 double ax = inputlat; 050 double bx = inputlon; /* to make mcidas compliant */ 051 System.out.printf("TOPO: lat: %f lon: %f\n",ax,bx); 052 053 InputStream filestream = Topo.class.getResourceAsStream(topofile); 054 DataInputStream dis = new DataInputStream(filestream); 055 056 double del_lon_elev = (last_lon_elev-first_lon_elev)/num_lon_elev; 057 double del_lat_elev = (first_lat_elev-last_lat_elev)/num_lat_elev; 058 System.out.printf("TOPO: dlat: %f dlon: %f\n",del_lon_elev,del_lat_elev); 059 060 int ay = (int)((90.0-ax)/del_lat_elev); 061 if(bx<0.0) bx = bx+360.0; 062 int by = (int)(bx/del_lon_elev); 063 System.out.printf("TOPO: lat: %d lon: %d \n",ay,by); 064 long position = (long)(2*((ay*((double)num_lon_elev))+by)); 065 System.out.printf("TOPO: position=%d\n",position); 066 // filestream.seek(position+1); 067 dis.skip(position); 068 System.err.println("After skip, about to read val..."); 069 070 int i = dis.readShort(); 071 System.err.println("After read, val: " + i); 072 073 int ichar = (i==0) ? 2 : 1; 074 System.err.println("After read, returning: " + ichar); 075 System.out.printf("TOPO: position=%d Value=%d landflag=%d \n ",position,i,ichar); 076 filestream.close(); 077 078 return ichar; 079 } 080 081}