1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
#include<iostream>
#include<fstream>
#include<cmath>
#include<math.h>
#include<string>
using namespace std;
int main(){
float longitude, latitude;
int i=0, k=0, linenumber=0, wordnumber=0;
int ConvertToInt, direction, velocity, level;
string word, line, hour, date;
ifstream windIn;
ofstream windOut;
windIn.open("file.win", ios::in);
windOut.open("wind.txt", ios::out);//this is the file I use now to put all the info but that's
//not what I want as you will see.
windOut << "Longitude,Latitude,Direction,Velocity,Date-Hour-Level\n";
if(windIn.is_open()){
while(!windIn.eof()){
while(linenumber<20){ //Before the 20th line it's just a header.
getline(windIn,line);
linenumber++;
}
if(linenumber==20||linenumber==96||linenumber==172){//these are the lines with information
//about the date, hour, etc.
linenumber++;
for(wordnumber=0;wordnumber<=13;wordnumber++){
windIn >> word;
if(wordnumber==5){//word number 5 (actually number 4!!) corresponds to the hour.
hour=word;
}
if(wordnumber==8){//word number 8 (actually number 7!!) corresponds to the date.
date=word;
}
if(wordnumber==11){//word number 11 (actually number 10!!) corresponds to the height.
if(word=="medium"){
level=0;
}
else{
ConvertToInt=atoi(word.c_str());
level=ConvertToInt;
wordnumber++;
}
}
}
}
//latitude and longitude are known points not read from the file.
while(linenumber>20 && linenumber<96){
//Here should appear the command to open an output file called "Wind-Hour-Date-Level.txt"
//where Hour, Date and Level correspond to the respective variables.
for(i=0;i<25;i++){
longitude=-20.0+i*1.0;
for(k=0;k<18;k++){
windIn >> word;
windOut << longitude << ",";
latitude=30.0+k*1.0;
windOut << latitude << ",";
ConvertToInt=atoi(word.c_str());
velocity=ConvertToInt%1000;
direction=ConvertToInt/1000;
windOut << direction << "," << velocity << ",";
windOut << year << "-" << month << "-" << day << "---" << hour << "--" << level << "\n";
}
linenumber=linenumber+3;//I put +3 and not +1 because this is implicated by
//the input file. This is no trouble. More will appear.
}
}
while(linenumber>96 && linenumber<172){
//Again here should appear the command to open an output file called "Wind-Hour-Date-Level.txt"
//where Hour, Date and Level correspond to the respective variables.
for(i=0;i<25;i++){
longitude=-20.0+i*1.0;
for(k=0;k<18;k++){
windIn >> word;
windOut << longitude << ",";
latitude=30.0+k*1.0;
windOut << latitude << ",";
ConvertToInt=atoi(word.c_str());
velocity=ConvertToInt%1000;
direction=ConvertToInt/1000;
windOut << direction << "," << velocity << ",";
windOut << year << "-" << month << "-" << day << "---" << hour << "--" << level << "\n";
}
linenumber=linenumber+3;
}
}
while(linenumber>172 && linenumber<248){
//Again here should appear the command to open an ouput file called "Wind-Hour-Date-Level.txt"
//where Hour, Date and Level correspond to the respective variables.
for(i=0;i<25;i++){
longitude=-20.0+i*1.0;
for(k=0;k<18;k++){
windIn >> word;
windOut << longitude << ",";
latitude=30.0+k*1.0;
windOut << latitude << ",";
ConvertToInt=atoi(word.c_str());
velocity=ConvertToInt%1000;
direction=ConvertToInt/1000;
windOut << direction << "," << velocity << ",";
windOut << year << "-" << month << "-" << day << "---" << hour << "--" << level << "\n";
}
linenumber=linenumber+3;
}
}
getline(windIn,line);
}
}
else{
cout << "ERROR: The File file.win wasn't found.\n";
}
windOut.close();
windIn.close();
return 0;
}
|