Skip to content

Commit

Permalink
Apply clang-format (#852)
Browse files Browse the repository at this point in the history
  • Loading branch information
nilason committed Jan 30, 2023
1 parent 0d67db0 commit 5fb6b1a
Show file tree
Hide file tree
Showing 730 changed files with 85,025 additions and 86,326 deletions.
106 changes: 55 additions & 51 deletions src/imagery/i.destripe/fourier.c
Original file line number Diff line number Diff line change
@@ -1,58 +1,62 @@
#include<stdio.h>
#include<math.h>
#include <stdio.h>
#include <math.h>
#include <grass/gis.h>
#include <grass/raster.h>

#define PI 3.1415926
#define PI 3.1415926
#define HARMONIC_MAX 5000

void fourier(DCELL *outrast, DCELL *inrast, int length, int harmonic_number)
{
int u, t, col, original_length, count = 0;
double t_obs[HARMONIC_MAX] = {0.0};
double t_sim[HARMONIC_MAX] = {0.0};
for (col = 0; col < length; col++) {
if (Rast_is_d_null_value(&((DCELL *)inrast)[col])) {
Rast_set_d_null_value(&outrast[col], 1);
}
else {
t_obs[count] = (double)inrast[col];
outrast[col] = 0.0;
count++;
}
}
// Adjust length to actual count without null values
original_length = length;
length = count;
double fcos[HARMONIC_MAX] = {0.0};
double fsin[HARMONIC_MAX] = {0.0};
double fm[HARMONIC_MAX] = {0.0};
double fp[HARMONIC_MAX] = {0.0};

void fourier(DCELL *outrast,DCELL *inrast,int length,int harmonic_number){
int u, t, col, original_length, count=0;
double t_obs[HARMONIC_MAX] = {0.0};
double t_sim[HARMONIC_MAX] = {0.0};
for (col = 0; col < length; col++){
if (Rast_is_d_null_value(&((DCELL *) inrast)[col])){
Rast_set_d_null_value(&outrast[col],1);
} else {
t_obs[count] = (double) inrast[col];
outrast[col] = 0.0;
count++;
}
}
//Adjust length to actual count without null values
original_length=length;
length = count;
double fcos[HARMONIC_MAX] = {0.0};
double fsin[HARMONIC_MAX] = {0.0};
double fm[HARMONIC_MAX] = {0.0};
double fp[HARMONIC_MAX] = {0.0};

//Generate F[u], Fm[u] and Fp[u] for u=1 to q
//u is spectral dimension
//t is temporal dimension
for (u=0;u<harmonic_number;u++){
for (t=0;t<length;t++){
fcos[u] += t_obs[t]*cos(2*PI*u*t/length);
fsin[u] += t_obs[t]*sin(2*PI*u*t/length);
}
fcos[u] /= length;
fsin[u] /= length;
fm[u] = pow(pow(fcos[u],2)+pow(fsin[u],2),0.5);
fp[u] = atan2(fcos[u],fsin[u]);
}
for (t=0;t<length;t++){
for (u=0;u<harmonic_number;u++){
t_sim[t] = t_sim[t]+fm[u]*(cos((2*PI*u*t/length)-fp[u])+sin((2*PI*u*t/length)+fp[u]));
}
}
count=0;
for (col = 0; col < original_length; col++){
if (Rast_is_d_null_value(&((DCELL *) outrast)[col])){
/*Do nothing*/
} else {
outrast[col] = (DCELL) t_sim[count];
count++;
}
}
// Generate F[u], Fm[u] and Fp[u] for u=1 to q
// u is spectral dimension
// t is temporal dimension
for (u = 0; u < harmonic_number; u++) {
for (t = 0; t < length; t++) {
fcos[u] += t_obs[t] * cos(2 * PI * u * t / length);
fsin[u] += t_obs[t] * sin(2 * PI * u * t / length);
}
fcos[u] /= length;
fsin[u] /= length;
fm[u] = pow(pow(fcos[u], 2) + pow(fsin[u], 2), 0.5);
fp[u] = atan2(fcos[u], fsin[u]);
}
for (t = 0; t < length; t++) {
for (u = 0; u < harmonic_number; u++) {
t_sim[t] =
t_sim[t] + fm[u] * (cos((2 * PI * u * t / length) - fp[u]) +
sin((2 * PI * u * t / length) + fp[u]));
}
}
count = 0;
for (col = 0; col < original_length; col++) {
if (Rast_is_d_null_value(&((DCELL *)outrast)[col])) {
/*Do nothing*/
}
else {
outrast[col] = (DCELL)t_sim[count];
count++;
}
}
}
50 changes: 23 additions & 27 deletions src/imagery/i.destripe/main.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/****************************************************************************
*
* MODULE: i.destripe
Expand All @@ -9,84 +8,83 @@
* COPYRIGHT: (C) 2014 by the GRASS Development Team
*
* This program is free software under the GNU General Public
* License (>=v2). Read the file COPYING that comes with GRASS
* for details.
* License (>=v2). Read the file COPYING that comes with
* GRASS for details.
*
*****************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <grass/gis.h>
#include <grass/raster.h>
#include <grass/glocale.h>

void fourier(DCELL *t_sim,DCELL *t_obs,int length,int harmonic_number);
void fourier(DCELL *t_sim, DCELL *t_obs, int length, int harmonic_number);

int main(int argc, char *argv[])
int main(int argc, char *argv[])
{
int nrows, ncols;
int row, col;
struct GModule *module;
struct Option *input1, *input2;
struct Option *output;
struct History history; /*metadata */
struct History history; /*metadata */
struct Colors colors;
char *result; /*output raster name */
char *result; /*output raster name */
int infd, outfd, ha;
char *in;
DCELL *inrast, *outrast;
CELL val1, val2;
/************************************/

/************************************/
G_gisinit(argv[0]);
module = G_define_module();
G_add_keyword(_("imagery"));
G_add_keyword(_("destripe"));
G_add_keyword("Fourier");
module->description =
_("Destripes regularly, about vertical, striped image using Fourier.");
/* Define the different options */
_("Destripes regularly, about vertical, striped image using Fourier.");

/* Define the different options */
input1 = G_define_standard_option(G_OPT_R_INPUT);

input2 = G_define_option();
input2->key = "harmonic";
input2->type = TYPE_INTEGER;
input2->required = YES;
input2->description =
_("Number of harmonics to use (less is smoother output)");
_("Number of harmonics to use (less is smoother output)");
input2->answer = "8";

output = G_define_standard_option(G_OPT_R_OUTPUT);
/********************/
/********************/
if (G_parser(argc, argv))
exit(EXIT_FAILURE);
exit(EXIT_FAILURE);

in = input1->answer;
ha = atoi(input2->answer);
result = output->answer;
/***************************************************/
/***************************************************/
infd = Rast_open_old(in, "");
inrast = Rast_allocate_d_buf();

nrows = Rast_window_rows();
ncols = Rast_window_cols();
outrast = Rast_allocate_d_buf();
/* Create New raster files */

/* Create New raster files */
outfd = Rast_open_new(result, DCELL_TYPE);

/* Process each row */
for (row = 0; row < nrows; row++)
{
for (row = 0; row < nrows; row++) {
G_percent(row, nrows, 2);
Rast_get_d_row(infd, inrast, row);
fourier(outrast,inrast,ncols,ha);
fourier(outrast, inrast, ncols, ha);
Rast_put_d_row(outfd, outrast);
}
/* Color table for biomass */

/* Color table for biomass */
Rast_init_colors(&colors);
val1 = 0;
val2 = 1;
Expand All @@ -101,5 +99,3 @@ int main(int argc, char *argv[])

exit(EXIT_SUCCESS);
}


8 changes: 4 additions & 4 deletions src/imagery/i.eb.deltat/delta_t.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include<stdio.h>
#include<stdlib.h>
#include <stdio.h>
#include <stdlib.h>

/* Difference of temperature between surface skin and about 2m
* Initialization parameter of sensible heat flux iteration in SEBAL
Expand All @@ -12,10 +12,10 @@ double delta_t(double tempk)

result = -321.147 + 1.095 * tempk;
if (result < 1) {
result = 1.0;
result = 1.0;
}
else if (result > 13) {
result = 13.0;
result = 13.0;
}
return result;
}

0 comments on commit 5fb6b1a

Please sign in to comment.