[go: up one dir, main page]

Menu

[r2]: / trunk / src / convert_gome.cc  Maximize  Restore  History

Download this file

118 lines (102 with data), 2.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "getopt.h"
#include "read_gome.h"
#include "read_spec_file.cc"
#define MAXLL 100
//#define MAXSPEC 1000
int main(int argc, char ** argv) {
char *infile, *outfile;
FILE *spin;
float **spec;
int *nchan;
int nb;
char line[MAXLL];
gome_data * data;
char tstring[30];
int get_pmd=0;
int def_spec=0;
int rawread=0;
char c;
int b1b=1, b2b=1, b3=1, b4=1;
while ((c = getopt (argc, argv, "rpdb:")) != -1) {
switch (c) {
case ('p'):
get_pmd=1;
break;
case ('d'):
def_spec=1;
break;
case ('r'):
rawread=1;
break;
case ('b'):
if (strlen(optarg) < 4) {
fprintf(stderr, "argument for -b must have at least four characters\n");
exit(2);
}
if (optarg[0]!='y') b1b=0;
if (optarg[1]!='y') b2b=0;
if (optarg[2]!='y') b3=0;
if (optarg[3]!='y') b4=0;
break;
case ('?'):
fprintf(stderr, "Unknown option: %c --ignored\n", optopt);
break;
default:
fprintf(stderr, "Error parsing command line\n");
exit(2);
}
}
argc=argc-optind;
argv=argv+optind;
if (argc != 3 && argc != 2) {
printf("Usage: convert_gome [-b ????] [-d] [-p] [spectra] infile outfile\n");
printf(" where:\n");
printf("spectra file containing desired spectra\n");
printf("infile input file\n");
printf("outfile output file\n");
printf(" options:\n");
printf("-b ???? selected bands, choose y to include, n to exclude\n");
printf(" where 1b, 2b, 3 and 4 are the bands; default is all four\n");
printf("-r file is in raw, binary format (to be added...)\n");
printf("-d use default spectra: 1000 channels between 290 and 790 nm\n");
printf(" in geometric series\n");
printf("-p include PMD data\n");
printf("\n");
return 1;
}
printf("%d\n", get_pmd);
if (argc==3) {
spec=read_spec_file(argv[0], nchan, nb);
infile=argv[1];
outfile=argv[2];
} else {
infile=argv[0];
outfile=argv[1];
spec=NULL;
nchan=NULL;
nb=0;
if (def_spec) {
spec=new float *[1];
nchan=new int [1];
spec[0]=default_spectra(LAMBDA0, LAMBDAN, NLAMBDA);
nchan[0]=NLAMBDA;
nb=1;
}
}
rg_select_band(b1b, b2b, b3, b4);
data=read_gome(infile, spec, nchan, nb, get_pmd);
if (data == NULL) {
printf("Read error, exiting... \n");
return -1;
}
rawwrite_gome(outfile, data);
if (nb!=0) {
delete [] nchan;
for (int i=0; i<nb; i++) delete [] spec[i];
delete [] spec;
}
delete_gome_data(data);
}