1
/* BK: simple program to dump binary data for ENVISAT
3
$Id: envisat_dump_data.c,v 1.5 2004/08/09 09:43:28 kampes Exp $
12
#include "epr_api-2.2/src/epr_api.h"
13
#if defined(WIN32) && defined(_DEBUG)
15
#endif /* if defined(WIN32) && defined(_DEBUG) */
18
int main(int argc, char** argv)
20
const char* product_file_path;
23
EPR_SProductId* product_id;
24
EPR_SDatasetId* MAIN_PROC_PM_ID;
28
EPR_SField numlines_field;
29
EPR_SField numpixels_field;
30
EPR_SField line_field;
41
unsigned int l0; // MA due to difference between 32-bit/64-bit data structure: define typedef like Doris see constant.h
46
int x,y; /* loop counter go upto 25.000 or so */
48
short realpart_short;/* written to output file */
49
short imagpart_short;/* written to output file */
52
printf("argc: %f\n", (float)argc);
53
if (argc != 3 && argc !=7)
55
printf("Usage: envisat_dump_data envisat-product outputfile [l0 lN p0 pN]\n");
56
printf(" where envisat-product is the input filename\n");
57
printf(" outputfile is the output filename\n");
58
printf(" l0 is the first azimuth line (starting at 1)\n");
59
printf(" lN is the last azimuth line\n");
60
printf(" p0 is the first range pixel (starting at 1)\n");
61
printf(" pN is the last range pixel\n");
63
printf(" envisat_dump_data ASA_IMS_1PNDPA20021025_175208_000000162010_00356_03416_0005.N1 crop.out 0 10 0 100\n\n");
66
product_file_path = argv[1];
68
printf("infile: %s\n",product_file_path);
69
printf("outfile: %s\n",outfile);
72
status=sscanf(argv[3],"%u",&l0);
73
status=sscanf(argv[4],"%u",&lN);
74
status=sscanf(argv[5],"%u",&p0);
75
status=sscanf(argv[6],"%u",&pN);
76
printf("sscanf l0: %f\n", (float)l0);
77
printf("sscanf lN: %f\n", (float)lN);
78
printf("sscanf p0: %f\n", (float)p0);
79
printf("sscanf pN: %f\n", (float)pN);
80
//printf("sscanf lN: %s\n", typeid(lN));
83
/* Initialize the API. Set log-level to DEBUG and use default log-output (stdout) */
84
epr_init_api(e_log_debug, epr_log_message, NULL);
86
/* Open the product; an argument is a path to product data file */
87
/* PRODUCT dataset record field element */
88
product_id = epr_open_product(product_file_path);
89
/* product DATASET record field element */
90
MAIN_PROC_PM_ID = epr_get_dataset_id(product_id, "MAIN_PROCESSING_PARAMS_ADS");
91
MDS1 = epr_get_dataset_id(product_id, "MDS1");
92
/* product dataset RECORD field element */
93
rec1 = epr_read_record(MAIN_PROC_PM_ID, 0, NULL);
94
/* product dataset record FIELD element */
95
numlines_field = *(epr_get_field(rec1, "num_output_lines"));
96
numpixels_field = *(epr_get_field(rec1, "num_samples_per_line"));
98
epr_free_record(rec1);
100
epr_print_field(&numlines_field, stdout);
101
epr_print_field(&numpixels_field, stdout);
102
numlines = epr_get_field_elem_as_uint(&numlines_field, 0);
103
numpixels = epr_get_field_elem_as_uint(&numpixels_field, 0);
111
/* loop over data record to get data and dump it to file */
112
numberoflines = epr_get_num_records(MDS1);
113
printf("numberoflines: %f\n", (float)numberoflines);
114
printf("numlines: %f\n", (float)numlines);
115
printf("numpixels: %f\n", (float)numpixels);
116
printf("l0: %f\n", (float)l0);
117
printf("lN: %f\n", (float)lN);
118
printf("p0: %f\n", (float)p0);
119
printf("pN: %f\n", (float)pN);
120
/* check if number of records indeed equals the number of lines */
121
if (numberoflines != numlines)
123
printf("numlines not equal in check, ASAR format error?.");
128
/* --- Check if input as acceptable ---------------------------- */
131
printf("l0<1 not allowed. first line is 1 not 0.\n");
136
printf("p0<1 not allowed. first line is 1 not 0.\n");
141
printf("lN>numlines not allowed.\n");
146
printf("pN>numpixels not allowed.\n");
151
/* --- read in whole line of cpx data -------------------------- */
152
outstream = fopen(outfile,"wb");
155
rec5 = epr_read_record(MDS1, y-1, NULL);
156
line_field = *(epr_get_field(rec5, "proc_data"));
157
cnt = 2*(p0-1);/* p0 starts at 1 for first element (BUGFIX!) */
158
/* write out selected pixels */
161
realpart_short = epr_get_field_elem_as_short(&line_field,cnt);
163
imagpart_short = epr_get_field_elem_as_short(&line_field,cnt);
165
status = fwrite(&realpart_short,2,1,outstream);
166
if (status != 1) fprintf(stderr,"fwrite could not write to disk?");
167
status = fwrite(&imagpart_short,2,1,outstream);
168
if (status != 1) fprintf(stderr,"fwrite could not write to disk?");
170
/* this program seemed to fill all memory for some reason? try to free it */
171
epr_free_record(rec5);
174
epr_close_product(product_id);
175
/* Closes product reader API, release all allocated resources */