~ubuntu-branches/ubuntu/saucy/doris/saucy-proposed

« back to all changes in this revision

Viewing changes to .pc/tools-build.patch/ENVISAT_TOOLS/envisat_dump_data.c

  • Committer: Package Import Robot
  • Author(s): Antonio Valentino
  • Date: 2012-12-19 19:29:21 UTC
  • Revision ID: package-import@ubuntu.com-20121219192921-wzijb38bxndmwl3m
Tags: 4.06~beta2+dfsg-1
Initial release (Closes: #696520)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* BK: simple program to dump binary data for ENVISAT 
 
2
   08-July-2004
 
3
   $Id: envisat_dump_data.c,v 1.5 2004/08/09 09:43:28 kampes Exp $
 
4
*/
 
5
#include <assert.h>
 
6
#include <errno.h>
 
7
#include <stdio.h>
 
8
#include <stdlib.h>
 
9
#include <string.h>
 
10
#include <math.h>
 
11
#include <time.h>
 
12
#include "epr_api-2.2/src/epr_api.h"
 
13
#if defined(WIN32) && defined(_DEBUG)
 
14
#include <crtdbg.h>
 
15
#endif /* if defined(WIN32) && defined(_DEBUG) */
 
16
//#include <typeinfo>
 
17
 
 
18
int main(int argc, char** argv) 
 
19
  {
 
20
  const char*     product_file_path;
 
21
  const char*     outfile;
 
22
  FILE*           outstream;
 
23
  EPR_SProductId* product_id;
 
24
  EPR_SDatasetId* MAIN_PROC_PM_ID;
 
25
  EPR_SDatasetId* MDS1;
 
26
  EPR_SRecord*    rec1;
 
27
  EPR_SRecord*    rec5;
 
28
  EPR_SField      numlines_field;
 
29
  EPR_SField      numpixels_field;
 
30
  EPR_SField      line_field;
 
31
  int             status;
 
32
  ulong           line_num;
 
33
  ulong           numlines;
 
34
  ulong           numberoflines;
 
35
  ulong           numberoffields;
 
36
  ulong           numpixels;
 
37
  //ulong           l0;
 
38
  //ulong           lN;
 
39
  //ulong           p0;
 
40
  //ulong           pN;
 
41
  unsigned int           l0;  // MA due to difference between 32-bit/64-bit data structure: define typedef like Doris see constant.h
 
42
  unsigned int           lN;
 
43
  unsigned int           p0;
 
44
  unsigned int           pN;
 
45
  int             cnt;
 
46
  int             x,y;  /* loop counter go upto 25.000 or so */
 
47
 
 
48
  short           realpart_short;/* written to output file */
 
49
  short           imagpart_short;/* written to output file */
 
50
 
 
51
  /* handle input */
 
52
  printf("argc: %f\n", (float)argc);
 
53
  if (argc != 3 && argc !=7)
 
54
    {
 
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");
 
62
    printf("Example:\n");
 
63
    printf("  envisat_dump_data ASA_IMS_1PNDPA20021025_175208_000000162010_00356_03416_0005.N1 crop.out 0 10 0 100\n\n");
 
64
    exit(1);
 
65
    }
 
66
  product_file_path = argv[1];
 
67
  outfile           = argv[2];
 
68
  printf("infile:  %s\n",product_file_path);
 
69
  printf("outfile: %s\n",outfile);
 
70
  if (argc==7)
 
71
    {
 
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));
 
81
    }
 
82
 
 
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);
 
85
 
 
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"));
 
97
  /*
 
98
  epr_free_record(rec1);
 
99
  */
 
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);
 
104
  if (argc == 3)
 
105
    {
 
106
    l0 = 1;
 
107
    lN = numlines;
 
108
    p0 = 1;
 
109
    pN = numpixels;
 
110
    }
 
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)
 
122
    {
 
123
    printf("numlines not equal in check, ASAR format error?.");
 
124
    exit(1);
 
125
    }
 
126
 
 
127
 
 
128
  /* --- Check if input as acceptable ---------------------------- */
 
129
  if (l0 < 1)  
 
130
    {
 
131
    printf("l0<1 not allowed.  first line is 1 not 0.\n");
 
132
    exit(1);
 
133
    }
 
134
  if (p0 < 1)  
 
135
    {
 
136
    printf("p0<1 not allowed.  first line is 1 not 0.\n");
 
137
    exit(1);
 
138
    }
 
139
  if (lN > numlines)  
 
140
    {
 
141
    printf("lN>numlines not allowed.\n");
 
142
    exit(1);
 
143
    }
 
144
  if (pN > numpixels)  
 
145
    {
 
146
    printf("pN>numpixels not allowed.\n");
 
147
    exit(1);
 
148
    }
 
149
 
 
150
 
 
151
  /* --- read in whole line of cpx data -------------------------- */
 
152
  outstream = fopen(outfile,"wb");
 
153
  for (y=l0;y<=lN;y++)
 
154
    {
 
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 */
 
159
    for (x=p0;x<=pN;x++)
 
160
      {
 
161
      realpart_short = epr_get_field_elem_as_short(&line_field,cnt);
 
162
      cnt++;
 
163
      imagpart_short = epr_get_field_elem_as_short(&line_field,cnt);
 
164
      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?");
 
169
      }
 
170
    /* this program seemed to fill all memory for some reason?  try to free it */
 
171
    epr_free_record(rec5);
 
172
    }
 
173
  fclose(outstream);
 
174
  epr_close_product(product_id);
 
175
  /* Closes product reader API, release all allocated resources */
 
176
  epr_close_api();
 
177
  return 0;
 
178
  }
 
179
 
 
180