/******************************************************************************* * CRU CL 2.0 Data Extraction Routines - retrieves site based readings from 10'x10' * Global climate data set available at http://www.cru.uea.ac.uk/cru/data/hrg.htm * Date : 22/5/05 * Copyright (C) 2005 Daniel Falster * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * The GNU General Public License can be viewed at http://www.gnu.org/copyleft/gpl.html * or obtained from the Free Software Foundation, * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. * * Contact details: Daniel Falster, dfalster@bio.mq.edu.au * ARC-NZ Research Network for vegetation Function * Dept Biological Sciences, Macquarie University 2109, Australia * http://www.bio.mq.edu.au/ecology/vegfunction/ ***********************************************************************************/ #include #include #include #include #include #include using namespace std; float StrToFloat(string one); string read(ifstream& File, char stop); string read_no(ifstream& File, int length); double distance(double x1, double y1, double x2, double y2); struct site_data{string locality; float lat; float lon; int row; double dist; string data;}; //data to hold site data int main(int argc, char *argv[]) { long int i,j,s; string line; double dist; //Open data files cout<<"Enter climate data filename: "; cin >>line; ifstream inFile(line.c_str()); if(!inFile){cerr<<"File "<>line; ofstream outFile( line.c_str()); if(!outFile) {cerr<<"OUTFile not opened"<> line; ifstream latlonFile(line.c_str()); if(!latlonFile) {cerr<<"File not opened"< sites; site_data site; while ((latlonFile >> ws) && (! latlonFile.eof()) ) {latlonFile >> site.locality >> site.lat >> site.lon; site.dist=1000000.0; sites.push_back(site);} //PRINT sites to screen: cout<<"Sites\n";for(i=0; i lat, lon; vector data; // vectors hold file info for seraching while(!inFile.eof()) {lat.push_back(StrToFloat(read_no(inFile, 9))); lon.push_back(StrToFloat(read_no(inFile, 9))); data.push_back(read(inFile, '\n'));} //Find closest location for each site for(j=0; j