[GRASS-SVN] r62474 - grass/trunk/imagery/i.eb.hsebal01
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Oct 29 03:59:26 PDT 2014
Author: neteler
Date: 2014-10-29 03:59:26 -0700 (Wed, 29 Oct 2014)
New Revision: 62474
Modified:
grass/trunk/imagery/i.eb.hsebal01/main.c
Log:
i.eb.hsebal01: source code indenting with grass_indent.sh
Modified: grass/trunk/imagery/i.eb.hsebal01/main.c
===================================================================
--- grass/trunk/imagery/i.eb.hsebal01/main.c 2014-10-29 10:42:27 UTC (rev 62473)
+++ grass/trunk/imagery/i.eb.hsebal01/main.c 2014-10-29 10:59:26 UTC (rev 62474)
@@ -43,16 +43,17 @@
int main(int argc, char *argv[])
{
struct Cell_head cellhd;
+
/* buffer for in, tmp and out raster */
void *inrast_Rn, *inrast_g0;
void *inrast_z0m, *inrast_t0dem;
DCELL *outrast;
- int nrows=0, ncols=0;
- int row=0, col=0;
- int row_wet=0, col_wet=0;
- int row_dry=0, col_dry=0;
- double m_row_wet=0.0, m_col_wet=0.0;
- double m_row_dry=0.0, m_col_dry=0.0;
+ int nrows = 0, ncols = 0;
+ int row = 0, col = 0;
+ int row_wet = 0, col_wet = 0;
+ int row_dry = 0, col_dry = 0;
+ double m_row_wet = 0.0, m_col_wet = 0.0;
+ double m_row_dry = 0.0, m_col_dry = 0.0;
int infd_Rn, infd_g0;
int infd_z0m, infd_t0dem;
int outfd;
@@ -69,29 +70,33 @@
struct Option *input_row_wet, *input_col_wet;
struct Option *input_row_dry, *input_col_dry;
struct Flag *flag2, *flag3;
+
/********************************/
- double xp=0.0, yp=0.0;
- double xmin=0.0, ymin=0.0;
- double xmax=0.0, ymax=0.0;
- double stepx=0.0, stepy=0.0;
- double latitude=0.0, longitude=0.0;
- int rowDry=0, colDry=0, rowWet=0, colWet=0;
+ double xp = 0.0, yp = 0.0;
+ double xmin = 0.0, ymin = 0.0;
+ double xmax = 0.0, ymax = 0.0;
+ double stepx = 0.0, stepy = 0.0;
+ double latitude = 0.0, longitude = 0.0;
+ int rowDry = 0, colDry = 0, rowWet = 0, colWet = 0;
+
/********************************/
+
/********************************/
- xp=yp;
- yp=xp;
- xmin=ymin;
- ymin=xmin;
- xmax=ymax;
- ymax=xmax;
- stepx=stepy;
- stepy=stepx;
- latitude=longitude;
- longitude=latitude;
- rowDry=colDry;
- colDry=rowDry;
- rowWet=colWet;
- colWet=rowWet;
+ xp = yp;
+ yp = xp;
+ xmin = ymin;
+ ymin = xmin;
+ xmax = ymax;
+ ymax = xmax;
+ stepx = stepy;
+ stepy = stepx;
+ latitude = longitude;
+ longitude = latitude;
+ rowDry = colDry;
+ colDry = rowDry;
+ rowWet = colWet;
+ colWet = rowWet;
+
/********************************/
G_gisinit(argv[0]);
@@ -101,7 +106,8 @@
G_add_keyword(_("soil moisture"));
G_add_keyword(_("evaporative fraction"));
G_add_keyword(_("SEBAL"));
- module->description = _("Computes sensible heat flux iteration SEBAL 01.");
+ module->description =
+ _("Computes sensible heat flux iteration SEBAL 01.");
/* Define different options */
input_Rn = G_define_standard_option(G_OPT_R_INPUT);
@@ -130,7 +136,8 @@
input_ustar->required = YES;
input_ustar->gisprompt = "old,value";
input_ustar->answer = "0.32407";
- input_ustar->description = _("Value of the height independent friction velocity (u*) [m/s]");
+ input_ustar->description =
+ _("Value of the height independent friction velocity (u*) [m/s]");
input_ustar->guisection = _("Parameters");
input_ea = G_define_option();
@@ -138,7 +145,8 @@
input_ea->type = TYPE_DOUBLE;
input_ea->required = YES;
input_ea->answer = "1.511";
- input_ea->description = _("Value of the actual vapour pressure (e_act) [KPa]");
+ input_ea->description =
+ _("Value of the actual vapour pressure (e_act) [KPa]");
input_ea->guisection = _("Parameters");
input_row_wet = G_define_option();
@@ -170,8 +178,9 @@
input_col_dry->guisection = _("Parameters");
output = G_define_standard_option(G_OPT_R_OUTPUT);
- output->description = _("Name for output sensible heat flux raster map [W/m2]");
-
+ output->description =
+ _("Name for output sensible heat flux raster map [W/m2]");
+
/* Define the different flags */
flag2 = G_define_flag();
flag2->key = 'a';
@@ -196,26 +205,25 @@
ustar = atof(input_ustar->answer);
ea = atof(input_ea->answer);
- /*If automatic flag, just forget the rest of options*/
- if(flag2->answer)
- G_message(_("Automatic mode selected"));
- /*If not automatic & all pixels locations in col/row given*/
- else if (!flag2->answer &&
- input_row_wet->answer&&
- input_col_wet->answer&&
- input_row_dry->answer&&
- input_col_dry->answer){
- m_row_wet = atof(input_row_wet->answer);
- m_col_wet = atof(input_col_wet->answer);
- m_row_dry = atof(input_row_dry->answer);
- m_col_dry = atof(input_col_dry->answer);
- /*If pixels locations are in projected coordinates*/
- if (flag3->answer)
+ /*If automatic flag, just forget the rest of options */
+ if (flag2->answer)
+ G_message(_("Automatic mode selected"));
+ /*If not automatic & all pixels locations in col/row given */
+ else if (!flag2->answer &&
+ input_row_wet->answer &&
+ input_col_wet->answer &&
+ input_row_dry->answer && input_col_dry->answer) {
+ m_row_wet = atof(input_row_wet->answer);
+ m_col_wet = atof(input_col_wet->answer);
+ m_row_dry = atof(input_row_dry->answer);
+ m_col_dry = atof(input_col_dry->answer);
+ /*If pixels locations are in projected coordinates */
+ if (flag3->answer)
G_message(_("Manual wet/dry pixels in image coordinates"));
G_message(_("Wet Pixel=> x:%f y:%f"), m_col_wet, m_row_wet);
G_message(_("Dry Pixel=> x:%f y:%f"), m_col_dry, m_row_dry);
}
- /*If not automatic & missing any of the pixel location, Fatal Error*/
+ /*If not automatic & missing any of the pixel location, Fatal Error */
else {
G_fatal_error(_("Either auto-mode either wet/dry pixels coordinates should be provided!"));
}
@@ -242,6 +250,7 @@
/***************************************************/
/* Setup pixel location variables */
+
/***************************************************/
stepx = cellhd.ew_res;
stepy = cellhd.ns_res;
@@ -256,9 +265,11 @@
/***************************************************/
/* Allocate output buffer */
+
/***************************************************/
outrast = Rast_allocate_d_buf();
outfd = Rast_open_new(h0, DCELL_TYPE);
+
/***************************************************/
/* Allocate memory for temporary images */
double **d_Roh, **d_Rah;
@@ -267,33 +278,36 @@
G_message("Unable to allocate memory for temporary d_Roh image");
if ((d_Rah = G_alloc_matrix(nrows, ncols)) == NULL)
G_message("Unable to allocate memory for temporary d_Rah image");
+
/***************************************************/
/* MANUAL T0DEM WET/DRY PIXELS */
- DCELL d_Rn_dry=0.0,d_g0_dry=0.0;
- DCELL d_t0dem_dry=0.0,d_t0dem_wet=0.0;
+ DCELL d_Rn_dry = 0.0, d_g0_dry = 0.0;
+ DCELL d_t0dem_dry = 0.0, d_t0dem_wet = 0.0;
if (flag2->answer) {
/* Process tempk min / max pixels */
/* Internal use only */
- DCELL d_Rn_wet=0.0,d_g0_wet=0.0;
- DCELL d_Rn,d_g0,d_h0;
- DCELL t0dem_min=1000.0,t0dem_max=0.0;
- /*********************/
+ DCELL d_Rn_wet = 0.0, d_g0_wet = 0.0;
+ DCELL d_Rn, d_g0, d_h0;
+ DCELL t0dem_min = 1000.0, t0dem_max = 0.0;
+
+ /*********************/
for (row = 0; row < nrows; row++) {
DCELL d_t0dem;
+
G_percent(row, nrows, 2);
- Rast_get_d_row(infd_t0dem,inrast_t0dem,row);
- Rast_get_d_row(infd_Rn,inrast_Rn,row);
- Rast_get_d_row(infd_g0,inrast_g0,row);
+ Rast_get_d_row(infd_t0dem, inrast_t0dem, row);
+ Rast_get_d_row(infd_Rn, inrast_Rn, row);
+ Rast_get_d_row(infd_g0, inrast_g0, row);
/*process the data */
for (col = 0; col < ncols; col++) {
d_t0dem = ((DCELL *) inrast_t0dem)[col];
d_Rn = ((DCELL *) inrast_Rn)[col];
d_g0 = ((DCELL *) inrast_g0)[col];
if (Rast_is_d_null_value(&d_t0dem) ||
- Rast_is_d_null_value(&d_Rn) ||
- Rast_is_d_null_value(&d_g0)) {
+ Rast_is_d_null_value(&d_Rn) ||
+ Rast_is_d_null_value(&d_g0)) {
/* do nothing */
}
else {
@@ -335,7 +349,7 @@
G_message("rnet_dry=%f", d_Rn_dry);
G_message("g0_dry=%f", d_g0_dry);
G_message("h0_dry=%f", d_Rn_dry - d_g0_dry);
- }/* END OF FLAG2 */
+ } /* END OF FLAG2 */
G_message("Passed here");
@@ -384,41 +398,52 @@
G_message("t0dem_dry = %f", d_t0dem_dry);
G_message("t0dem_wet = %f", d_t0dem_wet);
- DCELL d_rah_dry=0.0;
- DCELL d_roh_dry=0.0;
+ DCELL d_rah_dry = 0.0;
+ DCELL d_roh_dry = 0.0;
- DCELL d_t0dem,d_z0m;
+ DCELL d_t0dem, d_z0m;
DCELL d_u5;
DCELL d_roh1;
- DCELL d_h1,d_h2,d_h3;
- DCELL d_rah1,d_rah2,d_rah3;
- DCELL d_L,d_x,d_psih,d_psim;
+ DCELL d_h1, d_h2, d_h3;
+ DCELL d_rah1, d_rah2, d_rah3;
+ DCELL d_L, d_x, d_psih, d_psim;
/* INITIALIZATION */
for (row = 0; row < nrows; row++) {
G_percent(row, nrows, 2);
/* read a line input maps into buffers */
Rast_get_d_row(infd_z0m, inrast_z0m, row);
- Rast_get_d_row(infd_t0dem, inrast_t0dem,row);
+ Rast_get_d_row(infd_t0dem, inrast_t0dem, row);
/* read every cell in the line buffers */
for (col = 0; col < ncols; col++) {
- d_z0m = ((DCELL *) inrast_z0m)[col];
- d_t0dem = ((DCELL *) inrast_t0dem)[col];
- if (Rast_is_d_null_value(&d_t0dem) || Rast_is_d_null_value(&d_z0m)) {
+ d_z0m = ((DCELL *) inrast_z0m)[col];
+ d_t0dem = ((DCELL *) inrast_t0dem)[col];
+ if (Rast_is_d_null_value(&d_t0dem) ||
+ Rast_is_d_null_value(&d_z0m)) {
/* do nothing */
d_Roh[row][col] = -999.9;
d_Rah[row][col] = -999.9;
}
else {
d_u5 = (ustar / 0.41) * log(5 / d_z0m);
- d_rah1=(1/(d_u5*pow(0.41,2)))*log(5/d_z0m)*log(5/(d_z0m*0.1));
- d_roh1=((998-ea)/(d_t0dem*2.87))+(ea/(d_t0dem*4.61));
- if (d_roh1 > 5) d_roh1 = 1.0;
- else d_roh1=((1000-4.65)/(d_t0dem*2.87))+(4.65/(d_t0dem*4.61));
+ d_rah1 =
+ (1 / (d_u5 * pow(0.41, 2))) * log(5 / d_z0m) * log(5 /
+ (d_z0m
+ *
+ 0.1));
+ d_roh1 =
+ ((998 - ea) / (d_t0dem * 2.87)) + (ea / (d_t0dem * 4.61));
+ if (d_roh1 > 5)
+ d_roh1 = 1.0;
+ else
+ d_roh1 =
+ ((1000 - 4.65) / (d_t0dem * 2.87)) +
+ (4.65 / (d_t0dem * 4.61));
if (row == rowDry && col == colDry) { /*collect dry pix info */
d_rah_dry = d_rah1;
d_roh_dry = d_roh1;
- G_message("d_rah_dry=%f d_roh_dry=%f",d_rah_dry,d_roh_dry);
+ G_message("d_rah_dry=%f d_roh_dry=%f", d_rah_dry,
+ d_roh_dry);
}
d_Roh[row][col] = d_roh1;
d_Rah[row][col] = d_rah1;
@@ -438,40 +463,47 @@
double sumy = d_dT_dry + 0.0;
double sumx2 = pow(d_t0dem_wet, 2) + pow(d_t0dem_dry, 2);
double sumxy = (d_t0dem_wet * 0.0) + (d_t0dem_dry * d_dT_dry);
+
a = (sumxy - ((sumx * sumy) / 2.0)) / (sumx2 - (pow(sumx, 2) / 2.0));
b = (sumy - (a * sumx)) / 2.0;
G_message("d_dT_dry=%f", d_dT_dry);
G_message("dT1=%f * t0dem + (%f)", a, b);
- DCELL d_h_dry=0.0;
+ DCELL d_h_dry = 0.0;
/* ITERATION 1 */
for (row = 0; row < nrows; row++) {
G_percent(row, nrows, 2);
/* read a line input maps into buffers */
Rast_get_d_row(infd_z0m, inrast_z0m, row);
- Rast_get_d_row(infd_t0dem, inrast_t0dem,row);
+ Rast_get_d_row(infd_t0dem, inrast_t0dem, row);
/* read every cell in the line buffers */
for (col = 0; col < ncols; col++) {
- d_z0m = ((DCELL *) inrast_z0m)[col];
- d_t0dem = ((DCELL *) inrast_t0dem)[col];
+ d_z0m = ((DCELL *) inrast_z0m)[col];
+ d_t0dem = ((DCELL *) inrast_t0dem)[col];
d_rah1 = d_Rah[row][col];
d_roh1 = d_Roh[row][col];
- if (Rast_is_d_null_value(&d_t0dem) || Rast_is_d_null_value(&d_z0m)) {
+ if (Rast_is_d_null_value(&d_t0dem) ||
+ Rast_is_d_null_value(&d_z0m)) {
/* do nothing */
}
else {
- if (d_rah1 < 1.0)
+ if (d_rah1 < 1.0)
d_h1 = 0.0;
- else
+ else
d_h1 = (1004 * d_roh1) * (a * d_t0dem + b) / d_rah1;
- d_L =-1004*d_roh1*pow(ustar,3)*d_t0dem/(d_h1*9.81*0.41);
- d_x = pow((1-16*(5/d_L)),0.25);
- d_psim =2*log((1+d_x)/2)+log((1+pow(d_x,2))/2)-2*atan(d_x)+0.5*M_PI;
- d_psih =2*log((1+pow(d_x,2))/2);
- d_u5 =(ustar/0.41)*log(5/d_z0m);
- d_rah2 = (1/(d_u5*pow(0.41,2)))*log((5/d_z0m)-d_psim)
- *log((5/(d_z0m*0.1))-d_psih);
- if (row == rowDry && col == colDry) {/*collect dry pix info */
+ d_L =
+ -1004 * d_roh1 * pow(ustar,
+ 3) * d_t0dem / (d_h1 * 9.81 * 0.41);
+ d_x = pow((1 - 16 * (5 / d_L)), 0.25);
+ d_psim =
+ 2 * log((1 + d_x) / 2) + log((1 + pow(d_x, 2)) / 2) -
+ 2 * atan(d_x) + 0.5 * M_PI;
+ d_psih = 2 * log((1 + pow(d_x, 2)) / 2);
+ d_u5 = (ustar / 0.41) * log(5 / d_z0m);
+ d_rah2 =
+ (1 / (d_u5 * pow(0.41, 2))) * log((5 / d_z0m) - d_psim)
+ * log((5 / (d_z0m * 0.1)) - d_psih);
+ if (row == rowDry && col == colDry) { /*collect dry pix info */
d_rah_dry = d_rah2;
d_h_dry = d_h1;
}
@@ -497,20 +529,23 @@
G_message("dT1=%f * t0dem + (%f)", a, b);
/* ITERATION 2 */
+
/***************************************************/
+
/***************************************************/
for (row = 0; row < nrows; row++) {
G_percent(row, nrows, 2);
/* read a line input maps into buffers */
- Rast_get_d_row(infd_z0m,inrast_z0m,row);
- Rast_get_d_row(infd_t0dem,inrast_t0dem,row);
+ Rast_get_d_row(infd_z0m, inrast_z0m, row);
+ Rast_get_d_row(infd_t0dem, inrast_t0dem, row);
/* read every cell in the line buffers */
for (col = 0; col < ncols; col++) {
- d_z0m = ((DCELL *) inrast_z0m)[col];
- d_t0dem = ((DCELL *) inrast_t0dem)[col];
+ d_z0m = ((DCELL *) inrast_z0m)[col];
+ d_t0dem = ((DCELL *) inrast_t0dem)[col];
d_rah2 = d_Rah[row][col];
d_roh1 = d_Roh[row][col];
- if (Rast_is_d_null_value(&d_t0dem) || Rast_is_d_null_value(&d_z0m)) {
+ if (Rast_is_d_null_value(&d_t0dem) ||
+ Rast_is_d_null_value(&d_z0m)) {
/* do nothing */
}
else {
@@ -518,17 +553,23 @@
d_h2 = 0.0;
}
else {
- d_h2 =(1004*d_roh1)*(a*d_t0dem+b)/d_rah2;
+ d_h2 = (1004 * d_roh1) * (a * d_t0dem + b) / d_rah2;
}
- d_L =-1004*d_roh1*pow(ustar,3)*d_t0dem/(d_h2*9.81*0.41);
+ d_L =
+ -1004 * d_roh1 * pow(ustar,
+ 3) * d_t0dem / (d_h2 * 9.81 * 0.41);
d_x = pow((1 - 16 * (5 / d_L)), 0.25);
- d_psim =2*log((1+d_x)/2)+log((1+pow(d_x,2))/2)-
- 2*atan(d_x)+0.5*M_PI;
- d_psih =2*log((1+pow(d_x,2))/2);
- d_u5 =(ustar/0.41)*log(5/d_z0m);
- d_rah3=(1/(d_u5*pow(0.41,2)))*log((5/d_z0m)-d_psim)*
- log((5/(d_z0m*0.1))-d_psih);
- if (row == rowDry && col == colDry) {/*collect dry pix info */
+ d_psim = 2 * log((1 + d_x) / 2) + log((1 + pow(d_x, 2)) / 2) -
+ 2 * atan(d_x) + 0.5 * M_PI;
+ d_psih = 2 * log((1 + pow(d_x, 2)) / 2);
+ d_u5 = (ustar / 0.41) * log(5 / d_z0m);
+ d_rah3 =
+ (1 / (d_u5 * pow(0.41, 2))) * log((5 / d_z0m) -
+ d_psim) * log((5 /
+ (d_z0m *
+ 0.1)) -
+ d_psih);
+ if (row == rowDry && col == colDry) { /*collect dry pix info */
d_rah_dry = d_rah3;
d_h_dry = d_h2;
}
@@ -536,7 +577,7 @@
}
}
}
-
+
/*Calculate dT_dry */
d_dT_dry = (d_h_dry * d_rah_dry) / (1004 * d_roh_dry);
/*Calculate coefficients for next dT equation */
@@ -554,21 +595,24 @@
G_message("dT1=%f * t0dem + (%f)", a, b);
/* ITERATION 3 */
+
/***************************************************/
+
/***************************************************/
for (row = 0; row < nrows; row++) {
G_percent(row, nrows, 2);
/* read a line input maps into buffers */
Rast_get_d_row(infd_z0m, inrast_z0m, row);
- Rast_get_d_row(infd_t0dem,inrast_t0dem,row);
+ Rast_get_d_row(infd_t0dem, inrast_t0dem, row);
/* read every cell in the line buffers */
for (col = 0; col < ncols; col++) {
- d_z0m = ((DCELL *) inrast_z0m)[col];
- d_t0dem = ((DCELL *) inrast_t0dem)[col];
+ d_z0m = ((DCELL *) inrast_z0m)[col];
+ d_t0dem = ((DCELL *) inrast_t0dem)[col];
d_rah3 = d_Rah[row][col];
d_roh1 = d_Roh[row][col];
- if (Rast_is_d_null_value(&d_t0dem) || Rast_is_d_null_value(&d_z0m)) {
+ if (Rast_is_d_null_value(&d_t0dem) ||
+ Rast_is_d_null_value(&d_z0m)) {
Rast_set_d_null_value(&outrast[col], 1);
}
else {
More information about the grass-commit
mailing list