// Code for reading in the fetch and depth data (raw files from pre_proc.cpp) // and modifying according to the averaging schemes (IDW depth and cosine weighted fetch) // based on the parameters entered here. // This code eliminates having to re-run pre_proc.cpp for updating averaging parameters. // The final result is 3 modified files (depth, fetch, and bottom slope) that are used with // param_wave.cpp to compute wave heights. // // By: Samuel Carter Boyd #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int line=0; int x=0; int x1=0; int x2=0; int node_tot,elm_tot; char content[10],temp[10]; string s; int dir_tot,node,k3,k1,k2,direction,num_depths; int Angres; //const int Angres=2; double Eff_top,Eff_bot,Eff_fetch,depth_temp,depth_tot; double pi = 4*atan(1); bool check; bool check2=true; double p=1; double p_temp; double Up; double Eff_res; double depth_cur,depth_prev,denominator,Eff_depth; int res; int i,n,di_low,di_high,c,c2; double Hw,Hwabove,Hwbelow,u,di_temp,di_input,dir,y3,PRN, HWEMO,HSPM,HCEM,HTMA,WSPM,TSPM,TCEM,TTMA,Tw; double WEMO_shoal,WEMO_fric,WEMO_cum,H_break; double kSPM,LSPM,ksSPM,kfSPM,SPM_shoal,SPM_fric,SPM_cum; double kCEM,LCEM,ksCEM,kfCEM,CEM_shoal,CEM_fric,CEM_cum; double kTMA,LTMA,ksTMA,kfTMA,TMA_shoal,TMA_fric,TMA_cum; double sigma; double tol; double eps; double knew,kold,k0; double k; double L; double ks,kf,Tm,fm; double g=9.7918; //gravity at meanlat (28.1091 deg) int NDSETSE,NP,DTDP,NSPOOLGE,IRTYPE,TIME,IT; int Ftop,Ftop2,Favg=0; double Dtop,Dtop2,Davg,dconst,Mtop,Mtop2,Mavg=0; int main(){ ifstream infile; infile.open("fort.14"); //name of grid file if(infile.is_open()){ cout<> content){ //reading element and node total from fort.14 x=x+1; if(x==2){ elm_tot = atoi(content); } if(x==3){ node_tot = atoi(content); break; } } x=0; infile.close(); cout<>Angres; cout<>res; double fetch[node_tot][360/Angres]; double F[node_tot][360/Angres]; double depth[node_tot][360/Angres]; double d[node_tot][360/Angres]; double slope[node_tot][360/Angres]; //double p[node_tot][360/Angres]; double WVX[node_tot]; double WVY[node_tot]; double WDIR[node_tot]; double WVEL[node_tot]; ifstream infile1; infile1.open("Distance_data_2_deg.txt"); //reading in fetch data float clock_t,time_req; time_req=clock(); //initializing the clock for timing tasks if(infile1.is_open()){ cout<<"Reading Fetch Data"<3 && line<126773){ //ignoring header lines if(s.length()>7){ //if the length of line > 7 characters stringstream ss; ss<>content; //read number by number from s as (content) x=0; //indexing variable reset to 0 while(!ss.eof()){ //while values in the line (string ss) ss>>temp; //read each value x=x+1; //indexing variable if(x==1){ //if first number, store value as node number node=atof(content); //cout<<"NODE: "<7 } //close if header >3 and <126773 } //close while getline for "Distance_data4.txt" } //close if "Distance_data4.txt" is open else{ cout<<"!!! ERROR Distance_data_2_deg.txt not read !!!"<>p_temp; // VARIABLE WEIGHTING SHOULD NOT BE USED UNTIL A BETTER P-VALUE RELATIONSHIP IS DETERMINED check=false; if(p_temp>0){ check=true; cout<>Up; cout<>p_temp; if(p_temp>0){ check=true; cout<>Eff_res; cout<<"Effective angular averaging will consider "<>content; node_tot=atof(content); //cout<<"Node_tot: "<>temp; dir_tot=atof(temp); //cout<<"Dir_tot: "<2){ //for all other lines x2=x2+1; //indexing variable 2 progress x1=0; //indexing variable 1 reset when there is a new line stringstream ss; ss<>content; while(!ss.eof()){ x2=0; //indexing varriable 2 reset when there is a new value ss>>temp; //read in each value of ss x1=x1+1; //progress indexing variable 1 check=false; //reset boolean check value to false if(x1==1){ //first value is direction (1:4*Ares) direction=atof(temp); check=true; //if the direction value is read, check is reset //to true because you know a new node has been reached } if(check=true && depth_tot!=0){ //if a new node has been reached direction=direction-1; //reset direction to the previous if(direction==0){ //if==0 reset to the last value direction=360/Angres; } //depth averaging scheme d[node][direction]=depth_tot/denominator; //cout<<"p["<2){ //skip 2nd line, built into special case, read 3rd line+ in the depths and sum together for average depth_temp = atof(content); depth_tot = depth_tot+(depth_temp/(pow(((x2-1)*res),p))); denominator = denominator+(1/(pow(((x2-1)*res),p))); //cout<<"depth["< 2 } //close while getline } //close if infile2 is_open else{ cout<<"!!! ERROR Depth_data_2_deg.txt not read !!!"<> content){ x=x+1; if(x%(dir_tot+1)==0){ n=n+1; //node counter increment i=-1; //direction counter reset at new node } i=i+1; //direction counter increment slope[n][i]=atof(content); //fetch values //if(n>6 && n<9){ //cout<<"slope["<0){ Ftop=Ftop+fetch[j][i]; Dtop=Dtop+d[j][i]; if(slope[j][i] < 1){ Mtop=Mtop+slope[j][i]; } c2=c2+1; if(j>6 && j<10){ //cout<<"slope["<k1){//direction within Eff_res deg left or right of //the current node. for values that go below 1 k1=i+n+(360/Angres); //reset index to (33:36) //cout<<"k1: "<36 is encountered //for values that go above max direction if(i+n > 360/Angres && i+n-360/Angres>k2){ k2=i+n-(360/Angres); //reset index to (1:4) //cout<<"k2: "<