00001
00002
00003
00004
00005
00006
00007 #include <assert.h>
00008 #include <errno.h>
00009 #include <stdio.h>
00010 #include <stdlib.h>
00011 #include <string.h>
00012 #include <math.h>
00013 #include <time.h>
00014 #include "epr_api-2.0.1/src/epr_api.h"
00015 #if defined(WIN32) && defined(_DEBUG)
00016 #include <crtdbg.h>
00017 #endif
00018
00019
00020 int main(int argc, char** argv)
00021 {
00022 const char* product_file_path;
00023 const char* outfile;
00024 const char* record_name;
00025 FILE* outstream;
00026 EPR_SProductId* product_id;
00027 EPR_SDatasetId* MAIN_PROC_PM_ID;
00028 EPR_SDatasetId* MDS1;
00029 EPR_SRecord* rec1;
00030 EPR_SRecord* rec5;
00031 EPR_SField* numlines_field;
00032 EPR_SField* numpixels_field;
00033 EPR_SField* line_field;
00034 EPR_SField* line_num_field;
00035 int status;
00036 ulong line_num;
00037 ulong numlines;
00038 ulong numberoflines;
00039 ulong numberoffields;
00040 ulong numpixels;
00041 ulong l0;
00042 ulong lN;
00043 ulong p0;
00044 ulong pN;
00045 ulong cnt;
00046 ulong x,y;
00047 short realpart_short;
00048 short imagpart_short;
00049
00050
00051 printf("argc: %f\n", (float)argc);
00052 if (argc != 3 && argc !=7 && argc !=8)
00053 {
00054 printf("Usage: envisat_dump_VV envisat-product outputfile [l0 lN p0 pN]\n");
00055 printf(" where envisat-product is the input filename of the alternating pol product\n");
00056 printf(" outputfile is the output filename\n");
00057 printf(" l0 is the first azimuth line (starting at 1)\n");
00058 printf(" lN is the last azimuth line\n");
00059 printf(" p0 is the first range pixel (starting at 1)\n");
00060 printf(" pN is the last range pixel\n");
00061 printf("Example:\n");
00062 printf(" envisat_dump_VV ASA_IMS_1PNDPA20021025_175208_000000162010_00356_03416_0005.N1 crop.out 0 10 0 100\n\n");
00063 exit(1);
00064 }
00065 product_file_path = argv[1];
00066 outfile = argv[2];
00067 printf("infile: %s\n",product_file_path);
00068 printf("outfile: %s\n",outfile);
00069 if (argc>=7)
00070 {
00071 status=sscanf(argv[3],"%u",&l0);
00072 status=sscanf(argv[4],"%u",&lN);
00073 status=sscanf(argv[5],"%u",&p0);
00074 status=sscanf(argv[6],"%u",&pN);
00075 printf("sscanf l0: %f\n", (float)l0);
00076 printf("sscanf lN: %f\n", (float)lN);
00077 printf("sscanf p0: %f\n", (float)p0);
00078 printf("sscanf pN: %f\n", (float)pN);
00079 }
00080
00081
00082
00083
00084
00085
00086 epr_init_api(e_log_debug, epr_log_message, NULL);
00087
00088
00089
00090 product_id = epr_open_product(product_file_path);
00091
00092 MAIN_PROC_PM_ID = epr_get_dataset_id(product_id, "MAIN_PROCESSING_PARAMS_ADS");
00093
00094 MDS1 = epr_get_dataset_id(product_id, "MDS2");
00095
00096 rec1 = epr_read_record(MAIN_PROC_PM_ID, 0, NULL);
00097
00098 numlines_field = epr_get_field(rec1, "num_output_lines");
00099 numpixels_field = epr_get_field(rec1, "num_samples_per_line");
00100
00101
00102
00103 epr_print_field(numlines_field, stdout);
00104 epr_print_field(numpixels_field, stdout);
00105 numlines = epr_get_field_elem_as_ulong(numlines_field, 0);
00106 numpixels = epr_get_field_elem_as_ulong(numpixels_field, 0);
00107 if (argc == 3)
00108 {
00109 l0 = 1;
00110 lN = numlines;
00111 p0 = 1;
00112 pN = numpixels;
00113 }
00114
00115 numberoflines = epr_get_num_records(MDS1);
00116 printf("numberoflines: %f\n", (float)numberoflines);
00117 printf("numlines: %f\n", (float)numlines);
00118 printf("numpixels: %f\n", (float)numpixels);
00119 printf("l0: %f\n", (float)l0);
00120 printf("lN: %f\n", (float)lN);
00121 printf("p0: %f\n", (float)p0);
00122 printf("pN: %f\n", (float)pN);
00123
00124 if (numberoflines != numlines)
00125 {
00126 printf("numlines not equal in check, ASAR format error?.");
00127 exit(1);
00128 }
00129
00130 outstream = fopen(outfile,"wb");
00131 for (y=l0;y<=lN;y++)
00132 {
00133 rec5 = epr_read_record(MDS1, y-1, NULL);
00134
00135
00136
00137
00138
00139
00140
00141
00142 line_field = epr_get_field(rec5, "proc_data");
00143 cnt = 2*(p0-1);
00144
00145 for (x=p0;x<=pN;x++)
00146 {
00147 realpart_short = epr_get_field_elem_as_short(line_field,cnt);
00148 cnt = cnt + 1;
00149 imagpart_short = epr_get_field_elem_as_short(line_field,cnt);
00150 cnt = cnt + 1;
00151
00152
00153
00154 status = fwrite(&realpart_short,2,1,outstream);
00155 if (status != 1) fprintf(stderr,"fwrite could not write to disk?");
00156 status = fwrite(&imagpart_short,2,1,outstream);
00157 if (status != 1) fprintf(stderr,"fwrite could not write to disk?");
00158 }
00159
00160
00161 epr_free_record(rec5);
00162 }
00163 fclose(outstream);
00164 epr_close_product(product_id);
00165
00166 epr_close_api();
00167
00168 return 0;
00169 }
00170
00171