Skip to content

Commit

Permalink
Fix formatting in main.c
Browse files Browse the repository at this point in the history
  • Loading branch information
echoix committed Dec 30, 2023
1 parent a5fd00f commit ce39449
Showing 1 changed file with 44 additions and 34 deletions.
78 changes: 44 additions & 34 deletions src/raster/r.damflood/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* COPYRIGHT: (C) 2008 by Istituto Scienze della Terra-SUPSI
*
* This program is free software under the GNU General Public
* Licence (>=2). Read the file COPYING that cames with GRASS
* Licence (>=2). Read the file COPYING that comes with GRASS
* for details.
*
***************************************************************************/
Expand All @@ -30,6 +30,7 @@
#include <grass/dbmi.h>
#include <grass/linkm.h>
#include <grass/bitmap.h>

/* Functions defined in here */
#include "SWE.h" /* Function that solves the shallow water equations*/

Expand Down Expand Up @@ -190,6 +191,7 @@ int main(int argc, char *argv[])
DCELL *outrast_IMAX;
DCELL *outrast_T_IMAX;
DCELL *outrast_WAVEFRONT;

/* Cell counters */
int nrows, ncols;
int row, col;
Expand All @@ -205,6 +207,7 @@ int main(int argc, char *argv[])
float **m_hmax, **m_t_hmax, **m_i_hmax, **m_vmax, **m_t_vmax, **m_i_vmax,
**m_dir_vmax, **m_imax, **m_t_imax, **m_wavefront;
int **m_lake;

/* Other variables */
double water_elevation, profondita_soglia;
double hmin = 0.1;
Expand All @@ -215,23 +218,24 @@ int main(int argc, char *argv[])
int m = 1, M = 1;
int i, i_cont;
double vel_0 = 0.0, vel_max = 0.0, t;

/**********************************************************************************/
// Parameters for the optimization of timestep using the CFL stability
// condition
float timestep, velocity;
float timestep_ct, timestep_ct_temp;
/**********************************************************************************/

int DELTAT, TSTOP;
char name1[20], name2[20], name3[20], name4[20], name5[20], name6[20],
name7[20], name8[20], name9[20];
int tmp_int;
char tmp[15];
/********************/
// Optional instants//

// Optional instants
int ntimes, pp;
double *times;
double opt_t, time;
/********************/

/* Variables to handle user inputs and outputs */
char *ELEV, *LAKE, *DAMBREAK, *MANNING, *U, *V, *OUT_VEL, *OUT_H, *OUT_HMAX,
Expand Down Expand Up @@ -284,9 +288,10 @@ int main(int argc, char *argv[])

/* LEGEND
total_dambreak-without_hypotesis = No hypothesis about initial velocity
total_dambreak = Hypothesis critical height --> initial velocity (critical h) =
0.93*sqrt(h); small_dam_breach = Hypothesis spillway --> initial velocity =
0.4*sqrt(2*g*h)
total_dambreak = Hypothesis critical height
--> initial velocity (critical h) = 0.93*sqrt(h)
small_dam_breach = Hypothesis spillway
--> initial velocity = 0.4*sqrt(2*g*h)
*/

input_TIMESTEP = G_define_option();
Expand Down Expand Up @@ -832,8 +837,8 @@ int main(int argc, char *argv[])
if (m_h2[row][col] <= 0) {
m_h2[row][col] = 0.0;
if (m_h1[row][col] > 0) {
// This warning must be modified since it is valid for every
// cell ---> You have to put a generic one
// This warning must be modified since it is valid
// for every cell ---> You have to put a generic one
// that is valid when all cells have h=0
num_break--;
if (num_break == 0) {
Expand Down Expand Up @@ -902,7 +907,7 @@ int main(int argc, char *argv[])
m_u2, m_v2, row, col, nrows, ncols, timestep, res_ew,
res_ns, method, num_cell, num_break, t);

//*************************************** Overwriting *********************************************
//**************************** Overwriting ****************************/
timestep_ct = 0;
if (t < TSTOP) {
/* Open new cycle */
Expand Down Expand Up @@ -1028,31 +1033,32 @@ int main(int argc, char *argv[])
}
}

/*------------------------------ New timestep -------------------------------------*/
/*--------------------------- New timestep ---------------------------*/
timestep = 0.1 / timestep_ct;
/*-------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
// G_message("timestep =%f,m=%d, t=%f",timestep,m, t);

/*----------------------------------------------------------------------------------------------*/
/* Something is wrong with this if */
/*----------------------------------------------------------------------------------------------*/
/*--------------------------------------------------------------------
* Something is wrong with this if
/*--------------------------------------------------------------------*/

/* Check if we need to write outputs */
if ((input_DELTAT->answer != NULL) || (parm.opt_t->answer != NULL)) {
if ((((m * DELTAT - t) <= timestep && (m * DELTAT) < TSTOP) &&
(input_DELTAT->answer != NULL)) ||
((pp < ntimes && (times[pp] - t) < timestep) &&
(parm.opt_t->answer != NULL))) {
if ((m * DELTAT - t) <= timestep &&
m * DELTAT < TSTOP) { /* We need to change the raster name and add _timestep at each time */
if ((m * DELTAT - t) <= timestep && m * DELTAT < TSTOP) {
/* We need to change the raster name and add _timestep at
* each time */
if (OUT_H) {
sprintf(name1, "%s%d", OUT_H, m*DELTAT);
sprintf(name1, "%s%d", OUT_H, m * DELTAT);
}
if (OUT_VEL){
sprintf(name2,"%s%d",OUT_VEL,m*DELTAT);
sprintf(name3,"%s%s%d","dir_",OUT_VEL,m*DELTAT);
if (OUT_VEL) {
sprintf(name2, "%s%d", OUT_VEL, m * DELTAT);
sprintf(name3, "%s%s%d", "dir_", OUT_VEL, m * DELTAT);
}
G_message("Time: %d, writing the output maps",m*DELTAT);
G_message("Time: %d, writing the output maps", m * DELTAT);
m++;
}
else {
Expand All @@ -1063,6 +1069,7 @@ int main(int argc, char *argv[])
G_message("Time: %lf, writing an optional output maps %d",
t, pp);
}

/* Controlling if we can write the raster */
if (OUT_H) {
if ((outfd_H = Rast_open_new(name1, DCELL_TYPE)) < 0) {
Expand Down Expand Up @@ -1148,6 +1155,7 @@ int main(int argc, char *argv[])
}

} /* end_col*/

/* Copy lines */
if (OUT_VEL) {
Rast_put_d_row(outfd_VEL, outrast_VEL);
Expand All @@ -1159,6 +1167,7 @@ int main(int argc, char *argv[])
Rast_put_d_row(outfd_VEL_DIR, outrast_VEL_DIR);
}
} /* End row */

/* Memory cleanup */
if (OUT_VEL) {
G_free(outrast_VEL);
Expand All @@ -1169,6 +1178,7 @@ int main(int argc, char *argv[])
if (flag_d->answer) {
G_free(outrast_VEL_DIR);
}

/* Close the raster maps */
if (OUT_VEL) {
Rast_close(outfd_VEL);
Expand All @@ -1182,14 +1192,14 @@ int main(int argc, char *argv[])
// timestep=0.1/timestep_ct;
}
} /* End if write outputs*/
/* else {
//G_message("timestep =%f,t=%f",timestep,t);
//pippo=1;
G_message("Function SWE - t=%f, TSTOP=%d",t,TSTOP);
//G_percent(t, TSTOP, timestep);
} */
// G_message("Function SWE applied - t=%f, TSTOP=%d",t,TSTOP);
// G_message("timestep =%f,t=%f",timestep,t);
/* else {
// G_message("timestep =%f,t=%f", timestep, t);
// pippo = 1;
G_message("Function SWE - t=%f, TSTOP=%d", t, TSTOP);
// G_percent(t, TSTOP, timestep);
} */
// G_message("Function SWE applied - t=%f, TSTOP=%d", t, TSTOP);
// G_message("timestep =%f,t=%f", timestep, t);
} /* End time loop*/

//*******************************************************************
Expand Down Expand Up @@ -1415,12 +1425,12 @@ int main(int argc, char *argv[])
((DCELL *)outrast_WAVEFRONT)[col] = m_wavefront[row][col];
}
}
} /* end_col */

} /* end_col*/
if (OUT_H) {
Rast_put_row(outfd_H, outrast_H, TYPE_DOUBLE);
/*if (G_put_raster_row (outfd_H, outrast_H, TYPE_DOUBLE) < 0)
G_fatal_error (_("Cannot write to <%s>"),name2);*/
/* if (G_put_raster_row(outfd_H, outrast_H, TYPE_DOUBLE) < 0)
G_fatal_error(_("Cannot write to <%s>"), name2); */
}
if (OUT_VEL) {
Rast_put_row(outfd_VEL, outrast_VEL, TYPE_DOUBLE);
Expand Down Expand Up @@ -1454,8 +1464,8 @@ int main(int argc, char *argv[])
}
// G_message("pippo, row=%d e nrows=%d", row, nrows);
} // end row
/* Close files */

/* Close files */
if (OUT_H) {
G_message("Writing the output final map %s", name1);
}
Expand Down

0 comments on commit ce39449

Please sign in to comment.