void parse_command_line(int argc, char **argv) { comm_port *port; comm comn = _com1; int i; if (argc > 0) { for (i=1; i<argc; i++) { if (!strcmp(argv[i], "-h")) { give_usage(stderr); exit(0); } else { port = comm_port_init(comn++); if (port == NULL) { dz_print_comm_err(); exit(1); } if (comm_port_load_settings(port, argv[i]) != 1) { dz_print_comm_err(); exit(1); } if (!port1) port1 = port; else port2 = port; } } } /* Default condition: One port, use COM A */ if (port1 == NULL) { port1 = comm_port_init(comn++); if (port1 == NULL) { dz_print_comm_err(); exit(1); } } if (port1) { if (comm_port_install_handler(port1) != 1) { dz_print_comm_err(); exit(1); } } if (port2) { if (comm_port_install_handler(port2) != 1) { dz_print_comm_err(); exit(1); } } }
int main (int argc, char *argv []) { int give_usage_action = 0; struct INPUT_ARDOP_PARAMS *params_in; logflag=quietflag=0; params_in = get_input_ardop_params_struct("", ""); give_usage_action=parse_cla(argc,argv,params_in); if (give_usage_action==0) give_usage(argv[0]); if (give_usage_action==-1) give_debug_usage(); asfSplashScreen(argc, argv); if (logflag) { StartWatchLog(fLog); printLog("Program: ardop\n\n"); } ardop(params_in); free(params_in); exit(EXIT_SUCCESS); }
int main(int argc, char **argv) { int fpStdout; int fpStdin; char *cp; char c; int pos = -1; char *progname; int nBuf, p; char ca[1024]; char *title = ""; char *name = "iSelect"; int stripco = FALSE; int stripws = FALSE; int resultline = FALSE; int keyresultline = FALSE; int browsealways = FALSE; int allselectable = FALSE; int multiselect = FALSE; int exitnoselect = FALSE; int i; char *keystr; char *abortstr = NULL; char *tagbegin = "<"; char *tagend = ">"; /* * argument handling */ /* canonicalize program name */ if ((cp = strrchr(argv[0], '/')) != NULL) progname = cp+1; else progname = argv[0]; argv[0] = progname; /* parse the option arguments */ opterr = 0; while ((c = getopt_long(argc, argv, "d:cfaep:k:mn:t:SPKQ:Vh", options, NULL)) != (char)(-1)) { if (optarg == NULL) optarg = "(null)"; switch (c) { case 'd': tagbegin = strdup(optarg); if ((cp = strchr(tagbegin, ',')) == NULL) { fprintf(stderr, "iSelect: bad argument to option '%c'\n", optopt); fprintf(stderr, "Try `%s --help' for more information.\n", progname); exit(EX_USAGE); } *cp++ = NUL; tagend = cp; break; case 'c': stripco = TRUE; break; case 'f': browsealways = TRUE; break; case 'a': allselectable = TRUE; break; case 'e': exitnoselect = TRUE; break; case 'p': pos = atoi(optarg); break; case 'k': configure_custom_key(optarg); break; case 'm': multiselect = TRUE; break; case 'n': name = strdup(optarg); break; case 't': title = strdup(optarg); break; case 'S': stripws = TRUE; break; case 'P': resultline = TRUE; break; case 'K': keyresultline = TRUE; break; case 'Q': abortstr = strdup(optarg); break; case 'V': give_version(progname); exit(EX_OK); case 'h': give_usage(progname); exit(EX_OK); case '?': fprintf(stderr, "iSelect: invalid option: '%c'\n", optopt); fprintf(stderr, "Try `%s --help' for more information.\n", progname); exit(EX_USAGE); case ':': fprintf(stderr, "iSelect: missing argument to option '%c'\n", optopt); fprintf(stderr, "Try `%s --help' for more information.\n", progname); exit(EX_USAGE); } } /* * read input */ if (optind < argc) { /* browsing text is given as arguments */ nBuf = 0; for (; optind < argc; ++optind) { cp = (argv[optind] == NULL ? "" : argv[optind]); sprintf(caBuf+nBuf, "%s\n", cp); nBuf += strlen(cp)+1; } caBuf[nBuf++] = NUL; } else if (optind == argc && !feof(stdin)) { /* browsing text is given on stdin */ nBuf = 0; while ((c = fgetc(stdin)) != (char)(EOF)) { caBuf[nBuf++] = c; } caBuf[nBuf++] = NUL; /* save stdin filehandle and reconnect it to tty */ fpStdin = dup(0); close(0); open("/dev/tty", O_RDONLY); } else { give_usage(progname); exit(EX_USAGE); } /* * preserve stdout filehandle for result string, i.e. * use the terminal directly for output */ fpStdout = dup(1); close(1); open("/dev/tty", O_RDWR); pos = (pos < 1 ? 1 : pos); p = iSelect(caBuf, pos-1, title, name, tagbegin, tagend, stripco, stripws, browsealways, allselectable, multiselect, exitnoselect, &keystr); /* * give back the result string to the user via * the stdout file handle */ if (p != -1) { for (i = 0; i < nLines; i++) { if (spaLines[i]->fSelected) { if (resultline) { sprintf(ca, "%d:", i+1); write(fpStdout, ca, strlen(ca)); } if (keyresultline) { sprintf(ca, "%s:", keystr); write(fpStdout, ca, strlen(ca)); } write(fpStdout, spaLines[i]->cpResult, strlen(spaLines[i]->cpResult)); sprintf(ca, "\n"); write(fpStdout, ca, strlen(ca)); } } } else { if (abortstr != NULL) write(fpStdout, abortstr, strlen(abortstr)); } exit(0); }
main(int argc, char *argv[]) { FILE *fpin, *fpout; float ibuff[CPX_PIX*2*LD]; float **obuff; float b[CPX_PIX]; float c[CPX_PIX/LA]; int cla,nl; int i,j,k,line; int olines, osamps; int oline, osamp; double t; char basefile[256], infile[256], outbasefile[256], outfile[256], roifile[256]; char *hdrfile; ymd_date date; hms_time time; meta_parameters *meta; char *mon[13]={"","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep", "Oct","Nov","Dec"}; char dir; // orbit direction - A or D double x, y, z; // state vector positions at start of segment double xdot, ydot, zdot; // state vector veloctiy at start of segment int META_ONLY = 0; // only create meta file, no img file int SEPARATE_ROI_FILE = 0; // CLA roi file given? int USE_TLES = 1; // TLE/state vector switch int ESA_FRAME = 0; // switch to control output file names int node = 0; asfSplashScreen(argc, argv); if (argc<2 || argc>9) { give_usage(argc,argv); exit(1); } while ((cla=getopt(argc,argv,"mvcE:r:")) != -1) switch(cla) { case 'm': META_ONLY = 1; printf("Using meta only option\n"); break; case 'r': strcpy(roifile,optarg); SEPARATE_ROI_FILE = 1; break; case 'E': ESA_FRAME = 1; node = atoi(optarg); break; case 'v': USE_TLES = 0; break; case 'c': USE_CLOCK_DRIFT = 1; break; case '?': give_usage(argc,argv); printf("Unknown option %s\n",optarg); exit(1); default: give_usage(argc,argv); exit(1); } strcpy(basefile,argv[optind]); strcpy(infile,basefile); strcat(infile,".slc"); /* if no separate roi.in file is specified, use the main name */ if (SEPARATE_ROI_FILE == 0) { strcpy(roifile,basefile); strcat(roifile,".roi.in"); } /* Read parameters from the ROI.in file */ read_roi_infile(roifile); nl = npatches * patch_size; hdrfile = get_basename(datfilename); strcat(hdrfile,".hdr"); /* Read the start time for this image from the hdr file */ read_hdrfile(hdrfile); if (USE_TLES == 0) { int cnt; int year, month, day, hour, min; double sec, thisSec; FILE *fpvec, *fpo; char tmp[256]; sprintf(tmp,"/home/talogan/Seasat_State_Vectors/%3i.ebf",start_date); fpvec = fopen(tmp,"r"); if (fpvec == NULL) { printf("Unable to open state vector file for day %i\n",start_date); printf("Defaulting to using TLEs instead\n"); USE_TLES = 1; } else { cnt = fscanf(fpvec,"%i %i %i %i %i %lf %lf %lf %lf %lf %lf %lf",&year,&month,&day,&hour,&min,&sec,&x,&y,&z,&xdot,&ydot,&zdot); thisSec = (double) ((hour*60+min)*60)+sec; /* seek to the correct second of the day for the START of this file -----------------------------------------------------------------*/ while (cnt == 12 && start_sec > (thisSec+1.0)) { cnt = fscanf(fpvec,"%i %i %i %i %i %lf %lf %lf %lf %lf %lf %lf",&year,&month,&day,&hour,&min,&sec,&x,&y,&z,&xdot,&ydot,&zdot); thisSec = (double) ((hour*60+min)*60)+sec; } printf("Found closest second %lf\n",thisSec); /* need to create a state vector file the start of this image ------------------------------------------------------------*/ stateVector vec, last_vec; last_vec.pos.x = x; last_vec.pos.y = y; last_vec.pos.z = z; last_vec.vel.x = xdot; last_vec.vel.y = ydot; last_vec.vel.z = zdot; vec = propagate(last_vec,thisSec,start_sec); x = vec.pos.x; y = vec.pos.y; z = vec.pos.z; xdot = vec.vel.x; ydot = vec.vel.y; zdot = vec.vel.z; } } if (USE_TLES == 1) { /* get the correct state vector */ printf("Propagating state vectors to requested time...\n"); create_input_tle_file(s_date,s_time,"tle1.txt"); propagate_state_vector("tle1.txt"); printf("\n\nConverting state vectors from ECI to ECEF\n"); fix_state_vectors(s_date.year,s_date.jd,s_time.hour,s_time.min,s_time.sec); remove("tle1.txt"); remove("propagated_state_vector.txt"); printf("Reading first state vector\n"); FILE *fpvec = fopen("fixed_state_vector.txt","r"); if (fscanf(fpvec,"%lf %lf %lf %lf %lf %lf %lf\n",&t,&x,&y,&z,&xdot,&ydot,&zdot)!=7) { printf("ERROR: Unable to find state vector in fixed_state_vector.txt file\n"); exit(1); } fclose(fpvec); remove("fixed_state_vector.txt"); } if (zdot > 0.0) dir = 'A'; else dir = 'D'; /* set up output image parameters */ olines = nl / LD; osamps = ns / LA; /* Create the meta file */ printf("Initializing the meta structure\n"); meta = raw_init(); /* Propagate the state vectors */ printf("Creating state vectors\n"); stateVector stVec;/*Source state vector*/ stVec.pos.x = x; stVec.pos.y = y; stVec.pos.z = z; stVec.vel.x = xdot; stVec.vel.y = ydot; stVec.vel.z = zdot; date_jd2ymd(&s_date,&date); meta->state_vectors = meta_state_vectors_init(1); meta->state_vectors->vecs[0].vec = stVec; meta->state_vectors->year = date.year; meta->state_vectors->julDay = s_date.jd; meta->state_vectors->second = date_hms2sec(&s_time); meta->state_vectors->vecs[0].time = 0; int num_vecs = 2 + (int)(nl*PRI)/30.0; propagate_state(meta, num_vecs+1, (nl*PRI)/num_vecs); printf("Calculating scene geometry parameters\n"); double RE = r_awgs84; double RP = r_awgs84 * sqrt(1-r_e2wgs84); double imgSec=date2sec(&s_date,&s_time); // time at start of image int num = meta->state_vectors->num / 2; // closest state vector to center of image double sourceSec = imgSec+meta->state_vectors->vecs[num].time; // time at closest state vector double destSec = imgSec+meta->state_vectors->vecs[meta->state_vectors->num-1].time/2; // time at center of image printf("Finding center state vector\n"); stateVector midVec = propagate(meta->state_vectors->vecs[num].vec,sourceSec,destSec); // state vector at middle time of image x = midVec.pos.x; y = midVec.pos.y; z = midVec.pos.z; xdot = midVec.vel.x; ydot = midVec.vel.y; zdot = midVec.vel.z; double geocentric_lat_nadir = asin(z / sqrt (x*x+y*y+z*z)); double lon_nadir = atan2(x,y)*180/M_PI; double RE_nadir = (RE * RP) / sqrt((RP*cos(geocentric_lat_nadir)*RP*cos(geocentric_lat_nadir)) + (RE*sin(geocentric_lat_nadir)*RE*sin(geocentric_lat_nadir))); double Rsc = sqrt(x*x+y*y+z*z); double geodetic_lat_nadir = atan(tan(geocentric_lat_nadir)/(1-r_e2wgs84)); double lat_nadir = geodetic_lat_nadir*180/M_PI; double gamma = geodetic_lat_nadir - geocentric_lat_nadir; printf("Filling in meta->general parameters\n"); strcpy(meta->general->sensor,"SEASAT"); strcpy(meta->general->sensor_name,"SAR"); strcpy(meta->general->mode,"STD"); strcpy(meta->general->processor,"ASPS-v" ASPS_VERSION_STRING); meta->general->data_type = REAL32; meta->general->image_data_type = AMPLITUDE_IMAGE; meta->general->radiometry = r_AMP; sprintf(meta->general->acquisition_date, "%02d-%s-%4d %02d:%02d:%02.0f", date.day, mon[date.month], date.year, s_time.hour, s_time.min, s_time.sec); meta->general->orbit = time2rev(s_date,s_time); meta->general->orbit_direction = dir; if (ESA_FRAME == 1) meta->general->frame = node; meta->general->band_count = 1; strcpy(meta->general->bands,"HH"); meta->general->line_count = nl/LD; meta->general->sample_count = ns/LA; meta->general->start_line = 0; meta->general->start_sample = 0; meta->general->line_scaling = 1; meta->general->sample_scaling = 1; meta->general->x_pixel_size = (C / (2.0 * fs)) * LA; switch (station_code) { case 5: strcpy(meta->general->receiving_station, "ULA"); break; case 6: strcpy(meta->general->receiving_station, "GDS"); break; case 7: strcpy(meta->general->receiving_station, "MIL"); break; case 9: strcpy(meta->general->receiving_station, "UKO"); break; case 10: strcpy(meta->general->receiving_station, "SNF"); break; } double orbit_vel = sqrt(9.81*RE_nadir*RE_nadir / Rsc); double swath_vel = orbit_vel * RE_nadir / Rsc; meta->general->y_pixel_size = (swath_vel * PRI) * LD; // TAL - Check the sc_vel... meta->general->re_major = r_awgs84; meta->general->re_minor = r_awgs84 * sqrt(1-r_e2wgs84); // meta->general->bit_error_rate = ??? // meta->general->missing_lines = ??? // meta->general->no_data = ??? /*Create the SAR metadata block*/ printf("Creating the meta->sar block\n"); if (!meta->sar) meta->sar = meta_sar_init(); meta->sar->image_type = 'S'; meta->sar->look_direction = 'R'; meta->sar->azimuth_look_count = LD; meta->sar->range_look_count = LA; meta->sar->deskewed = 0; meta->sar->original_line_count = nl; meta->sar->original_sample_count = ns; meta->sar->line_increment = 1; meta->sar->sample_increment = 1; meta->sar->range_time_per_pixel = 1/(2*fs); // Should be this, right??? meta->sar->azimuth_time_per_pixel = PRI; // Second try is this one meta->sar->azimuth_time_per_pixel = (destSec - imgSec) / (meta->sar->original_line_count/2); meta->sar->azimuth_time_per_pixel = meta->general->y_pixel_size / swath_vel; meta->sar->azimuth_time_per_pixel *= -1; meta->sar->time_shift = fabs(meta->general->line_count*meta->sar->azimuth_time_per_pixel); // meta->sar->slant_shift = -1080; // emperical value from a single delta scene // meta->sar->time_shift = 0.18; // emperical value from a single delta scene if (USE_CLOCK_DRIFT ==1) meta->sar->slant_shift = SEASAT_SLANT_SHIFT; // -1000.0; else meta->sar->slant_shift = 0.0; meta->sar->slant_range_first_pixel = srf; meta->sar->wavelength = wavelength; meta->sar->prf = prf; meta->sar->earth_radius = meta_get_earth_radius(meta, meta->general->line_count/2.0, meta->general->sample_count/2.0); meta->sar->satellite_height = Rsc; meta->sar->range_doppler_coefficients[0] = dop1*prf; meta->sar->range_doppler_coefficients[1] = dop2*prf; meta->sar->range_doppler_coefficients[2] = dop3*prf; meta->sar->azimuth_doppler_coefficients[0] = dop1*prf; meta->sar->azimuth_doppler_coefficients[1] = 0; meta->sar->azimuth_doppler_coefficients[2] = 0; /// meta->sar->azimuth_processing_bandwidth = ???? meta->sar->chirp_rate = chirp_slope; meta->sar->pulse_duration = pulse_duration; meta->sar->range_sampling_rate = fs; strcpy(meta->sar->polarization,"HH"); meta->sar->multilook = 1; meta->sar->pitch = 0; meta->sar->roll = 0; meta->sar->yaw = 0; /// meta->sar->incid_a[0-5] = ??? printf("Creating the meta->location block\n"); if (!meta->location) meta->location = meta_location_init(); meta_get_corner_coords(meta); meta_get_latLon(meta,meta->general->line_count/2,meta->general->sample_count/2,0, &meta->general->center_latitude, &meta->general->center_longitude); if (ESA_FRAME==0) { strcpy(outbasefile,basefile); } else { sprintf(outbasefile,"SS_%.5i_SLANT_F%.4i",meta->general->orbit,meta->general->frame); } strcpy(outfile,outbasefile); strcat(outfile,".img"); strcpy(meta->general->basename,outbasefile); if (META_ONLY==0) { obuff = (float **) malloc (sizeof(float *)*olines); for (i=0; i<olines; i++) obuff[i] = (float *) malloc (sizeof(float)*osamps); /* Open the input slc file and output img file*/ fpin = fopen(infile,"rb"); if (fpin==NULL) {printf("ERROR: Unable to open input file %s\n",infile); exit(1);} fpout = fopen(outfile,"wb"); /* Take the complex looks from the slc file to create the img file */ printf("Taking complex looks from file %s to create %s\n",infile,outfile); oline = 0; for (line=0; line < nl; line+=LD) { if (line%2560==0) printf("\t%i\n",line); fread(ibuff,sizeof(float),ns*2*LD,fpin); /* take looks down */ for (j=0; j<ns; j++) { b[j] = 0; for (i=0; i<LD; i++) b[j] = b[j] + (ibuff[(2*j)+(i*ns*2)]*ibuff[2*j+(i*ns*2)]) + (ibuff[(2*j+1)+(i*ns*2)]*ibuff[(2*j+1)+(i*ns*2)]); } /* take looks across */ for (j=0; j<ns/LA; j++) { c[j] = 0; for (k=0;k<LA;k++) c[j] = c[j] + b[j*LA+k]; c[j] = sqrt(c[j]); } byteswap(c,ns/LA); for (j=0; j<osamps; j++) obuff[oline][j] = c[j]; oline++; } /* write out image in reverse order */ for (j=0; j<olines; j++) fwrite(obuff[olines-j-1],sizeof(float),osamps,fpout); fclose(fpout); fclose(fpin); free(obuff); } /* END IF META_ONLY */ printf("Writing out the meta file\n"); meta_write(meta, outbasefile); if (META_ONLY == 0) { char grfilename[256]; float grPixSiz = 12.5; int err = 0; if (ESA_FRAME == 1) { char tmpstr[256]; char cropfile[256]; char tmpfile[256]; /* create the ground range image */ sprintf(grfilename,"temp_%.5i_STD_F%.4i",meta->general->orbit,meta->general->frame); sr2gr_pixsiz(outbasefile, grfilename, grPixSiz); /* crop the image to exact size */ sprintf(cropfile,"SS_%.5i_STD_F%.4i",meta->general->orbit,meta->general->frame); trim(grfilename,cropfile,(long long)0,(long long)0,(long long)8000,(long long)8000); /* remove the non-cropped ground range image */ strcat(strcpy(tmpstr,grfilename),".img"); remove(tmpstr); strcat(strcpy(tmpstr,grfilename),".meta"); remove(tmpstr); /* geocode and export to geotiff */ sprintf(tmpstr,"asf_geocode -p utm %s %s_utm\n",cropfile,cropfile); err = system(tmpstr); if (err) {printf("Error returned from asf_geocode\n"); exit(1);} sprintf(tmpstr,"asf_export -format geotiff %s_utm %s\n",cropfile,cropfile); err = system(tmpstr); if (err) {printf("Error returned from asf_export to geotiff\n"); exit(1);} /* remove the utm projected internal format image */ strcat(strcpy(tmpstr,cropfile),"_utm.img"); remove(tmpstr); strcat(strcpy(tmpstr,cropfile),"_utm.meta"); remove(tmpstr); /* this changes the basename in the metadata from blah_SLANT to blah_STD */ meta_parameters *crop_meta = meta_read(cropfile); strcpy(crop_meta->general->basename, cropfile); meta_write(crop_meta, cropfile); meta_free(crop_meta); /* create the dowsized QC image */ sprintf(tmpstr,"resample -scale 0.125 %s %s_small\n",cropfile,cropfile); err = system(tmpstr); if (err) {printf("Error returned from resample\n"); exit(1);} sprintf(tmpfile,"%s_QCFULL",cropfile); sprintf(tmpstr,"asf_export -format jpeg %s_small %s\n",cropfile,tmpfile); err = system(tmpstr); if (err) {printf("Error returned from asf_export to jpeg\n"); exit(1);} /* remove the small .img file */ strcat(strcpy(tmpstr,cropfile),"_small.img"); remove(tmpstr); strcat(strcpy(tmpstr,cropfile),"_small.meta"); remove(tmpstr); /* create the subsampled QC image */ sprintf(tmpfile,"%s_QCSUB",cropfile); trim(cropfile,tmpfile,(long long)3500,(long long)3500,(long long)1000,(long long)1000); sprintf(tmpstr,"asf_export -format jpeg %s %s\n",tmpfile,tmpfile); err = system(tmpstr); if (err) {printf("Error returned from asf_export\n"); exit(1);} /* run make_seasat_h5 */ sprintf(tmpstr,"make_seasat_h5 -gap %s.dis %s %s",basefile,cropfile,cropfile); err = system(tmpstr); if (err) {printf("Error returned from make_seasat_h5\n"); exit(1);} /* remove the subsampled QC .img file */ strcat(strcpy(tmpstr,tmpfile),".img"); remove(tmpstr); strcat(strcpy(tmpstr,tmpfile),".meta"); remove(tmpstr); /* rename the ROI.in file to match the new file name */ sprintf(tmpfile,"%s.roi.in",cropfile); rename(roifile,tmpfile); } else { strcpy(grfilename,basefile); strcat(grfilename,"G12"); sr2gr_pixsiz(basefile, grfilename, grPixSiz); } } exit(0); }
int main (int argc, char *argv []) { FILE *fp; getRec *signalGetRec; file *f; int ii, kk, ll, mm, give_usage_action=0, offset; int filter_azimuth, filter_range, filter_size; struct ARDOP_PARAMS params; meta_parameters *meta; complexFloat *image_in, *image_out, impulse_response, sum; double lines=0.0, samples=0.0; double time, range_time, azimuth_time, beam_center_time, pulse_duration; double pulse_envelope, antenna_beam_pattern, wavelength, chirp_slope; double slant_range, pulse_repetition_frequency, range_sampling_rate; double exposure_time, r, theta; printf("%s\n",date_time_stamp()); fflush(NULL); printf("Program: atdp\n\n"); logflag=0; quietflag=1; give_usage_action=parse_cla(argc,argv,¶ms,&meta); if (give_usage_action==0) give_usage(argv[0]); if (logflag) { StartWatchLog(fLog); printLog("Program: atdp\n\n"); } printf(" Initialization ...\n"); /* Read input out of SAR processing parameter file */ atdp_setup(¶ms,meta,&f,&signalGetRec); /* Define some parameters */ beam_center_time = samples * lines / 2; // check!!! pulse_duration = params.pulsedur; wavelength = params.wavl; chirp_slope = params.slope; pulse_repetition_frequency = params.prf; range_sampling_rate = params.fs; exposure_time = 0.64; // fix me filter_azimuth = (int)(exposure_time * pulse_repetition_frequency / 2 + 0.5); filter_range = (int)(pulse_duration * range_sampling_rate / 2 + 0.5); filter_size = filter_azimuth * filter_range * 4; /* Write metadata */ lines = signalGetRec->nLines; samples = signalGetRec->nSamples; meta->general->line_count = lines - filter_azimuth*2; meta->general->sample_count = samples - filter_range*2; meta->general->data_type = COMPLEX_REAL32; meta->general->image_data_type = COMPLEX_IMAGE; meta_write(meta, f->out_cpx); /* Arrange for memory */ image_in = (complexFloat *) MALLOC (sizeof(complexFloat)*samples*lines); image_out = (complexFloat *) MALLOC (sizeof(complexFloat)*meta->general->sample_count); /* Read raw SAR image */ for (ii=0; ii<lines; ii++) getSignalLine(signalGetRec,ii,&image_in[ii],0,samples); /* Open output image */ fp = FOPEN(f->out_cpx, "wb"); /* Loop through the image */ printf(" Start SAR processing raw image ...\n"); printf(" Match filter size: %i lines, %i samples\n", filter_azimuth*2, filter_range*2); for (ii=filter_azimuth; ii<lines-filter_azimuth; ii++) { for (kk=filter_range; kk<samples-filter_range; kk++) { offset = ii*samples + kk; ll=0;mm=0; /* Apply match filter */ for (ll=0; ll<filter_azimuth*2; ll++) { for (mm=0; mm<filter_range*2; mm++) { sum.real = 0.0; sum.imag = 0.0; /* Determine range and azimuth time */ range_time = (kk+mm) * meta->sar->range_time_per_pixel; azimuth_time = (ii+ll) * meta->sar->azimuth_time_per_pixel; /* Envelope of transmitted radar pulse */ slant_range = meta_get_slant(meta, ii+ll, kk+mm); time = range_time - 2*slant_range/speedOfLight; pulse_envelope = rect(time, pulse_duration); /* Antenn beam pattern */ time = azimuth_time - beam_center_time; antenna_beam_pattern = rect(time, pulse_duration); /* Impulse response function - Straight out of Ian Cumming's book (4-42), written in polar coordinates. For complex data, we have z = r * exp(i*theta). The real part out of that is r*cos(theta), the imaginary part is r*sin(theta).*/ r = pulse_envelope * antenna_beam_pattern; theta = (-4*PI * slant_range * wavelength) + (PI * chirp_slope * SQR(range_time - 2*slant_range / speedOfLight)); /* Real and imaginary part of impulse response function */ impulse_response.real = r * cos(theta); impulse_response.imag = r * sin(theta); /* Multiplication of raw image with time reversed complex conjugate impulse response function */ sum.real += image_in[offset + ll*filter_range*2 + mm].real * impulse_response.real + image_in[offset + ll*filter_range*2 + mm].imag * impulse_response.imag; sum.imag += image_in[offset + ll*filter_range*2 + mm].imag * impulse_response.real - image_in[offset + ll*filter_range*2 + mm].real * impulse_response.imag; } } image_out[kk].real = sum.real / filter_size; image_out[kk].imag = sum.imag / filter_size; //printf(" image: line = %5i, sample = %5i\r", ii, kk); } put_complexFloat_line(fp, meta, ii, image_out); if (ii%200 == 0) printf(" Processed line %5d\n", ii); } FCLOSE(fp); return(0); }