Skip to content

Commit 80b0cd3

Browse files
committed
Merge branch 'initcube' into develop
2 parents c0bfac3 + e794e2a commit 80b0cd3

File tree

6 files changed

+495
-253
lines changed

6 files changed

+495
-253
lines changed

Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ FORCE_EXE = force force-cube force-higher-level force-import-modis \
7272
force-magic-parameters force-mdcp force-mosaic force-parameter \
7373
force-procmask force-pyramid force-qai-inflate force-stack \
7474
force-synthmix force-tabulate-grid force-tile-extent \
75-
force-tile-finder force-train force-level2-report
75+
force-tile-finder force-train force-level2-report force-cube-init
7676

7777
FORCE_MISC = force-level2-report.Rmd
7878

@@ -84,7 +84,7 @@ GPP=g++
8484
G11=g++ -std=c++11
8585

8686
CFLAGS=-O3 -Wall -fopenmp
87-
#CFLAGS=-g -Wall -fopenmp
87+
CFLAGS=-g -Wall -fopenmp
8888

8989

9090
### DIRECTORIES
@@ -112,7 +112,7 @@ cross: string_cl enum_cl cite_cl utils_cl alloc_cl brick_cl imagefuns_cl param_c
112112
lower: table_ll param_ll meta_ll cube_ll equi7_ll glance7_ll atc_ll sunview_ll read_ll radtran_ll topo_ll cloud_ll gas_ll brdf_ll atmo_ll aod_ll resmerge_ll coreg_ll coregfuns_ll acix_ll modwvp_ll
113113
higher: param_hl progress_hl tasks_hl read-aux_hl read-ard_hl quality_hl bap_hl level3_hl cso_hl tsa_hl index_hl interpolate_hl stm_hl fold_hl standardize_hl pheno_hl polar_hl trend_hl ml_hl texture_hl lsm_hl lib_hl sample_hl imp_hl cfimp_hl l2imp_hl spec-adjust_hl pyp_hl udf_hl
114114
aux: param_aux param_train_aux train_aux
115-
exe: force force-parameter force-qai-inflate force-tile-finder force-tabulate-grid force-l2ps force-higher-level force-train force-lut-modis force-mdcp force-stack force-import-modis
115+
exe: force force-parameter force-qai-inflate force-tile-finder force-tabulate-grid force-l2ps force-higher-level force-train force-lut-modis force-mdcp force-stack force-import-modis force-cube-init
116116
.PHONY: temp all install install_ bash python clean build check
117117

118118
### TEMP
@@ -406,6 +406,9 @@ force-stack: temp cross $(DA)/_stack.c
406406
force-import-modis: temp cross lower $(DL)/_import-modis.c
407407
$(G11) $(CFLAGS) $(GDAL) $(GSL) $(CURL) -o $(TB)/force-import-modis $(DL)/_import-modis.c $(TC)/*.o $(TL)/*.o $(LDGDAL) $(LDGSL) $(LDCURL)
408408

409+
force-cube-init: temp cross lower $(DA)/_init-cube.c
410+
$(G11) $(CFLAGS) $(GDAL) $(GSL) $(CURL) -o $(TB)/force-cube-init $(DA)/_init-cube.c $(TC)/*.o $(TL)/*.o $(LDGDAL) $(LDGSL) $(LDCURL)
411+
409412
### dummy code for testing stuff
410413

411414
dummy: temp cross aux higher src/dummy.c

src/aux-level/_init-cube.c

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
/**+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2+
3+
This file is part of FORCE - Framework for Operational Radiometric
4+
Correction for Environmental monitoring.
5+
6+
Copyright (C) 2013-2021 David Frantz
7+
8+
FORCE is free software: you can redistribute it and/or modify
9+
it under the terms of the GNU General Public License as published by
10+
the Free Software Foundation, either version 3 of the License, or
11+
(at your option) any later version.
12+
13+
FORCE is distributed in the hope that it will be useful,
14+
but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
GNU General Public License for more details.
17+
18+
You should have received a copy of the GNU General Public License
19+
along with FORCE. If not, see <http://www.gnu.org/licenses/>.
20+
21+
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++**/
22+
23+
/**+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
24+
This program initializes a datacube-definition.prj
25+
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++**/
26+
27+
28+
#include <stdio.h> // core input and output functions
29+
#include <stdlib.h> // standard general utilities library
30+
31+
#include <ctype.h> // testing and mapping characters
32+
#include <unistd.h> // standard symbolic constants and types
33+
34+
#include "../cross-level/const-cl.h"
35+
#include "../cross-level/konami-cl.h"
36+
#include "../cross-level/cube-cl.h"
37+
//#include "../cross-level/warp-cl.h"
38+
#include "../lower-level/param-ll.h"
39+
#include "../lower-level/cube-ll.h"
40+
41+
42+
typedef struct {
43+
int n;
44+
double geo[2]; // lon/lat
45+
double tilesize;
46+
double chunksize;
47+
char dcube[NPOW_10];
48+
char proj[NPOW_10];
49+
} args_t;
50+
51+
52+
void usage(char *exe, int exit_code){
53+
54+
55+
printf("Usage: %s [-h] [-v] [-i] [-d datacube-dir] [-o lon/lat] \n", exe);
56+
printf(" [-t tile-size] [-c chunk-size] projection\n");
57+
printf("\n");
58+
printf(" -h = show this help\n");
59+
printf(" -v = show version\n");
60+
printf(" -i = show program's purpose\n");
61+
printf("\n");
62+
printf(" -d datacube-dir = output directory for datacube definition\n");
63+
printf(" default: current working directory\n");
64+
printf("\n");
65+
printf(" -o lon,lat = origin coordinates of the grid\n");
66+
printf(" use geographic coordinates!\n");
67+
printf(" longitude is X!\n");
68+
printf(" latitude is Y!\n");
69+
printf(" default: -25,60, is ignored for pre-defined projections!\n");
70+
printf("\n");
71+
printf(" -t tile-size\n");
72+
printf(" default: 30km, is ignored for pre-defined projections!\n");
73+
printf("\n");
74+
printf(" -c chunk-size\n");
75+
printf(" default: 3km, is ignored for pre-defined projections!\n");
76+
printf("\n");
77+
printf(" Positional arguments:\n");
78+
printf(" - Projection (custom WKT string or built-in projection\n");
79+
printf("\n");
80+
81+
exit(exit_code);
82+
return;
83+
}
84+
85+
86+
void parse_args(int argc, char *argv[], args_t *args){
87+
int opt;
88+
char buffer[NPOW_10];
89+
char *ptr = NULL;
90+
const char *separator = ",";
91+
int i;
92+
93+
94+
opterr = 0;
95+
96+
// default parameters
97+
args->tilesize = 30000;
98+
args->chunksize = 3000;
99+
args->geo[_X_] = -25;
100+
args->geo[_Y_] = 60;
101+
copy_string(args->dcube, 1024, ".");
102+
103+
// optional parameters
104+
while ((opt = getopt(argc, argv, "hvid:o:t:c:")) != -1){
105+
switch(opt){
106+
case 'h':
107+
usage(argv[0], SUCCESS);
108+
case 'v':
109+
printf("FORCE version: %s\n", _VERSION_);
110+
exit(SUCCESS);
111+
case 'i':
112+
printf("Initialize a datacube definition\n");
113+
exit(SUCCESS);
114+
case 'd':
115+
copy_string(args->dcube, NPOW_10, optarg);
116+
break;
117+
case 'o':
118+
copy_string(buffer, NPOW_10, optarg);
119+
ptr = strtok(buffer, separator);
120+
i = 0;
121+
while (ptr != NULL){
122+
if (i < 2) args->geo[i] = atof(ptr);
123+
ptr = strtok(NULL, separator);
124+
i++;
125+
}
126+
if (i != 2){
127+
fprintf(stderr, "Coordinate must have 2 numbers.\n");
128+
usage(argv[0], FAILURE);
129+
}
130+
break;
131+
case 't':
132+
args->tilesize = atof(optarg);
133+
if (args->tilesize <= 0){
134+
fprintf(stderr, "Tile size must be > 0.\n");
135+
usage(argv[0], FAILURE);
136+
}
137+
break;
138+
case 'c':
139+
args->chunksize = atof(optarg);
140+
if (args->chunksize <= 0){
141+
fprintf(stderr, "Chunk size must be > 0.\n");
142+
usage(argv[0], FAILURE);
143+
}
144+
break;
145+
case '?':
146+
if (isprint(optopt)){
147+
fprintf(stderr, "Unknown option `-%c'.\n", optopt);
148+
} else {
149+
fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
150+
}
151+
usage(argv[0], FAILURE);
152+
default:
153+
fprintf(stderr, "Error parsing arguments.\n");
154+
usage(argv[0], FAILURE);
155+
}
156+
}
157+
158+
// non-optional parameters
159+
args->n = 1;
160+
161+
if (optind < argc){
162+
konami_args(argv[optind]);
163+
if (argc-optind == args->n){
164+
copy_string(args->proj, NPOW_10, argv[optind++]);
165+
} else if (argc-optind < args->n){
166+
fprintf(stderr, "some non-optional arguments are missing.\n");
167+
usage(argv[0], FAILURE);
168+
} else if (argc-optind > args->n){
169+
fprintf(stderr, "too many non-optional arguments.\n");
170+
usage(argv[0], FAILURE);
171+
}
172+
} else {
173+
fprintf(stderr, "non-optional arguments are missing.\n");
174+
usage(argv[0], FAILURE);
175+
}
176+
177+
return;
178+
}
179+
180+
181+
int main(int argc, char *argv[]){
182+
args_t args;
183+
par_ll_t pl2;
184+
multicube_t *multicube = NULL;
185+
186+
187+
parse_args(argc, argv, &args);
188+
189+
pl2.res = 1;
190+
pl2.doreproj = true;
191+
pl2.dotile = true;
192+
193+
pl2.d_level2 = args.dcube;
194+
copy_string(pl2.proj, NPOW_10, args.proj);
195+
pl2.tilesize = args.tilesize;
196+
pl2.chunksize = args.chunksize;
197+
pl2.orig_lon = args.geo[_X_];
198+
pl2.orig_lat = args.geo[_Y_];
199+
200+
if ((multicube = start_multicube(&pl2, NULL)) == NULL){
201+
printf("Starting datacube(s) failed.\n"); return FAILURE;}
202+
203+
free_multicube(multicube);
204+
205+
return SUCCESS;
206+
}
207+

src/cross-level/enum-cl.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,14 @@ enum { _CLOCK_NULL_, _CLOCK_TICK_, _CLOCK_TOCK_, _CLOCK_LENGTH_ };
276276
// user-defined function type
277277
enum { _UDF_PIXEL_, _UDF_BLOCK_, _UDF_LENGTH_ };
278278

279+
280+
// projection
281+
enum { _PROJ_CUSTOM_, _PROJ_EQUI7_, _PROJ_GLANCE7_, _PROJ_LENGTH_ };
282+
283+
// continent
284+
enum { _CONTINENT_AF_, _CONTINENT_AN_, _CONTINENT_AS_, _CONTINENT_EU_,
285+
_CONTINENT_NA_, _CONTINENT_OC_, _CONTINENT_SA_, _CONTINENT_LENGTH_ };
286+
279287
// tagged enums
280288
extern const tagged_enum_t _TAGGED_ENUM_RESAMPLE_[_RESAMPLE_LENGTH_];
281289
extern const tagged_enum_t _TAGGED_ENUM_RES_MERGE_[_RES_MERGE_LENGTH_];

0 commit comments

Comments
 (0)