lasErr FUNCTION c_eopens(struct FDESC **fdesc,char *fname,int bands[], int *sl,int *ss,int *nl,int *ns,int offset[], int *acc,int *dtype,int *nbuf,int opt[]) { struct DDR ddr; register struct FDESC *fd; int dflag; int filesize; int i; /* counter -- current band */ int nbands; int stati; /*int linsiz;*/ char errtxt[ERRLEN]; /*char system[DDSYLN];*/ *fdesc = (struct FDESC *)calloc(1,sizeof(struct FDESC)); if (*fdesc == NULL) { c_errmsg("Error allocating dynamic memory","eopens-alloc",NON_FATAL); return(E_FAIL); } fd = *fdesc; /* used to simplify expressions */ fd->nl = fd->img_nl = *nl; fd->ns = fd->img_ns = *ns; fd->sl = *sl; fd->ss = *ss; fd->offset = offset; fd->acc = *acc; fd->method = STEP; fd->dtype = *dtype; fd->nbuf = *nbuf; fd->linsiz = (*ns * datasize[*dtype] + 511) & ~0x1ff; (void)strcpy(fd->fname, fname); fd->flags = 0; /* clear flags */ fd->cnvlsz = 0; /* set conversion line size 0 */ if ((fd->acc == IREAD) || (fd->acc == IUPDATE)) { /* Compare the system that the data is stored on and the system that will process the data. --------------------------------------------------------------------------*/ c_getddr(fname, &ddr); if ((dflag == 3) || ((dflag == 1) && (ddr.dtype == EREAL)) || ((dflag == 2) && (ddr.dtype != EBYTE))) { c_errmsg("Data type of image is not compatible with the processor", "eopens-dtype",NON_FATAL); return(E_FAIL); } /*linsiz = (ddr.ns * datasize[ddr.dtype] + 511) & ~0x1ff;*/ /* if a zero was specified for bands all the bands are specified ----------------------------------------------------------------*/ nbands = 0; if (bands[0] == 0) { for (i = 1; i <= ddr.nbands; i++) { fd->bands[nbands] = i; nbands++; } } else { while (bands[nbands] != 0) { if (bands[nbands] > ddr.nbands) { sprintf(errtxt,"More bands specified than exist for %s", fd->fname); c_errmsg(errtxt,"eopens-nbands",NON_FATAL); return(E_FAIL); } fd->bands[nbands] = bands[nbands]; nbands++; } } fd->nbands = nbands; stati = do_open(fd); if (stati != E_SUCC) { c_errmsg("Error returned from doopen","eopens-call",NON_FATAL); return(E_FAIL); } if (*dtype == 0) { *dtype = ddr.dtype; fd->dtype = ddr.dtype; } if (ddr.dtype != fd->dtype) { fd->flags |= CONVERSION; fd->conv_type = ddr.dtype; if ((fd->tae) || (fd->compres)) fd->cnvlsz = (ddr.ns * datasize[ddr.dtype] + 511) & ~0x1ff; else if (fd->dal) fd->cnvlsz = ddr.ns * datasize[ddr.dtype]; } if (nbands == 0) for(i=1; i<=ddr.nbands; i++) fd->bands[i-1] = i; if (*nl == 0) { *nl = ddr.nl; fd->nl = *nl; } if (*ns == 0) { *ns = ddr.ns; fd->ns = *ns; } if ((fd->tae) || (fd->compres)) { fd->linsiz = (ddr.ns * datasize[ddr.dtype] + 511) & ~0x1ff; /*linsiz = (ddr.ns * datasize[ddr.dtype] + 511) & ~0x1ff;*/ } else if (fd->dal) { fd->linsiz = ddr.ns * datasize[ddr.dtype]; /*linsiz = ddr.ns * datasize[ddr.dtype];*/ fd->img_nl = ddr.nl; fd->img_ns = ddr.ns; } if (check_window(fd, &ddr) != E_SUCC) { sprintf(errtxt,"Invalid window for file %s",fd->fname); c_errmsg(errtxt,"eopens-invalwind",NON_FATAL); return(E_FAIL); } } /* if (fd->acc == IREAD) || (fd->acc == IUPDATE) */ else { /* else fd->acc == IWRITE */ fd->compres = fd->tae = FALSE; fd->dal = TRUE; nbands = bands[0]; fd->nbands = nbands; if (nbands < 1) { sprintf(errtxt, "No Bands Specified for file %s", fd->fname); c_errmsg(errtxt,"eopens-nobands",NON_FATAL); return(E_FAIL); } else { for (i=0; i<nbands; i++) fd->bands[i] = i + 1; } fd->compres = FALSE; if (opt[0] != 0) if ((opt[0] > 0) && (opt[0] < NDTYPES)) { if (opt[0] != fd->dtype) { fd->flags |= CONVERSION; fd->conv_type = opt[0]; if ((fd->tae) || (fd->compres)) fd->cnvlsz = (*ns * datasize[opt[0]] +511) & ~0x1ff; else if (fd->dal) fd->cnvlsz = *ns * datasize[opt[0]]; } } else { c_errmsg("Invalid option specified","eopens-option", NON_FATAL); return(E_FAIL); } if (fd->dal) { fd->linsiz = *ns * datasize[*dtype]; filesize = fd->linsiz * fd->nl * fd->nbands; if (opt[0] != 0 && opt[0] != 5) if (opt[0] != fd->dtype) filesize = fd->cnvlsz * fd->nl * fd->nbands; } else { filesize = 11 * 512 + fd->linsiz * fd->nl * fd->nbands; if (opt[0] != 0 && opt[0] != 5) if (opt[0] != fd->dtype) filesize = 11 * 512 + fd->cnvlsz * fd->nl * fd->nbands; } stati = c_dkcre(fd->fname, filesize); if (stati != E_SUCC) { c_errmsg("Error returned from dkcre","eopens-call",NON_FATAL); return(E_FAIL); } stati = do_open(fd); if (stati != E_SUCC) { c_errmsg("Error returned from doopen","eopens-call", NON_FATAL); return(E_FAIL); } c_intddr(&ddr); ddr.nl = fd->nl; ddr.ns = fd->ns; ddr.nbands = fd->nbands; if (fd->flags & CONVERSION) ddr.dtype = fd->conv_type; else ddr.dtype = fd->dtype; stati = c_putddr(fname, &ddr); if (stati != E_SUCC) { c_errmsg("Error returned from putddr","eopens-call", NON_FATAL); return(E_FAIL); } } #ifdef DEBUG_IMAGEIO pfd(fd); #endif if ((fd->tae) || (fd->compres)) { fd->linsiz = (ddr.ns * datasize[*dtype] + 511) & ~0x1ff; fd->file_linsiz = (ddr.ns * datasize[ddr.dtype] + 511) & ~0x1ff; } else if (fd->dal) { fd->linsiz = ddr.ns * datasize[*dtype]; fd->file_linsiz = ddr.ns * datasize[ddr.dtype]; } return(E_SUCC); }
void prep_specan_file(int nLooks,int quality,double aspect, struct ARDOP_PARAMS *g,meta_parameters *meta) { getRec *inFile; FILE *outFile; int outLines,outSamples/*,x*/; /*char command[1024];*/ int i; specan_struct rng={1.0/RFS, RSLOPE, RCEN, RBW, RLEN_INIT}; specan_struct az={1.0/AFS, ASLOPE, ACEN, ABW, ALEN_INIT}; /*Set quality: longer FFT's -> bigger image, better quality.*/ for (i=0;i<quality;i++) { rng.fftLen*=2; az.fftLen*=2; } rng.fftLen=(int)(rng.fftLen*aspect); /*Open files.*/ if (!quietflag) printf("Opening input files...\n"); inFile=fillOutGetRec(g->in1); outFile=fopenImage(g->out,"wb"); /*Init. Range Variables*/ if (!quietflag) printf("Init SPECAN\n"); rng.iSamp=1.0/g->fs;/*Sample size, range (s)= 1.0/sample freqency (Hz)*/ rng.chirpSlope=g->slope;/*Range chirp slope (Hz/Sec)*/ specan_init(&rng); /*Init. Azimuth Variables*/ if (!quietflag) printf("Estimate Doppler\n"); az.iSamp=1.0/g->prf;/*Sample size, azimuth (s)=1.0/sample freqency (Hz)*/ if (meta->stVec==NULL) { fprintf(stderr, "Can only quicklook scenes with state vectors!\n"); exit(1);} else { /*Find doppler rate (Hz/sec) <=> azimuth chirp slope*/ double dopRate,yaw=0.0; GEOLOCATE_REC *g=init_geolocate_meta(&meta->stVec->vecs[0].vec,meta); double look; int ret; ret=getLook(g,meta->geo->slantFirst,yaw,&look); assert(ret==0); getDoppler(g,look,yaw,NULL,&dopRate,NULL,NULL); az.chirpSlope=dopRate; free_geolocate(g); } az.chirpCenter=g->fd*(1.0/az.iSamp);/*Convert doppler central freqency to Hz*/ /*For de-scalloping, compute the most powerful doppler freqency.*/ az.powerCenter=(1.0/az.iSamp)* fftEstDop(inFile,inFile->nLines/2,1,az.fftLen); if (!quietflag) printf("Doppler centroid at %.0f Hz, %.0f Hz/sec\n",az.chirpCenter,az.chirpSlope); specan_init(&az); if (!quietflag) printf("Efficiency: Range(%d): %.0f%% Azimuth(%d): %.0f%%\n", rng.fftLen,100.0*rng.oNum/rng.fftLen, az.fftLen,100.0*az.oNum/az.fftLen); /*Process image.*/ specan_file(inFile,nLooks,outFile,&rng,&az,&outLines,&outSamples); FCLOSE(outFile); freeGetRec(inFile); /*Create DDR for output file.*/ { struct DDR ddr;/*Output DDR*/ c_intddr(&ddr); ddr.dtype=DTYPE_FLOAT; ddr.nbands=1; ddr.nl=outLines; ddr.ns=outSamples; ddr.sample_inc=rng.oSamp/rng.iSamp; ddr.line_inc=az.oSamp/az.iSamp; c_putddr(g->out,&ddr); } /*Copy over metadata*/ if (meta->info) sprintf(meta->info->processor,"ASF/QUICKLOOK/%.2f",VERSION); meta_write(meta,g->out); }
void meta2ddr(meta_parameters *meta, struct DDR *ddr) { int ii; int proj_invalid = 0; /* Initialize ddr values */ c_intddr(ddr); /* Number of lines & samples; both int */ ddr->nl = meta->general->line_count; ddr->ns = meta->general->sample_count; /* Number of bands; int */ ddr->nbands = 1; /* Data type; int */ switch (meta->general->data_type) { case BYTE: ddr->dtype = DTYPE_BYTE; break; case INTEGER16: ddr->dtype = DTYPE_SHORT; break; case INTEGER32: ddr->dtype = DTYPE_LONG; break; case REAL32: ddr->dtype = DTYPE_FLOAT; break; case REAL64: ddr->dtype = DTYPE_DOUBLE; break; case COMPLEX_REAL32: ddr->dtype = DTYPE_COMPLEX; break; default: printf("WARNING * There is not a direct conversion from meta.general.data_type\n" " * to ddr.dtype. Setting ddr.dtype value to -1.\n"); ddr->dtype = -1; break; } /* Worthless date & time fields; both char[12] */ strcpy (ddr->last_used_date,""); strcpy (ddr->last_used_time,""); /* System byte ordering style; char[12] */ if (0==strcmp(meta_get_system(),"big_ieee")) strcpy(ddr->system,"ieee-std"); else if (0==strcmp(meta_get_system(),"lil_ieee")) strcpy(ddr->system,"ieee-lil"); //strcpy(ddr->system,"linux"); else if (0==strcmp(meta_get_system(),"cray_float")) strcpy(ddr->system,"cray-unicos"); /* Projection units; char[12] */ if (meta->projection) /* if projection struct has been allocated */ strncpy(ddr->proj_units, meta->projection->units, 12); else strcpy(ddr->proj_units, "meters"); /* Safe to assume meters */ ddr->valid[DDPUV] = VALID; /* Increment per sample in x & y directions; both double */ if (meta->sar) { ddr->line_inc = meta->sar->line_increment; ddr->sample_inc = meta->sar->sample_increment; ddr->valid[DDINCV] = ((meta->sar->line_increment == meta->sar->line_increment) &&(meta->sar->sample_increment == meta->sar->sample_increment)) ? VALID : INVAL; } else { ddr->line_inc = 1; ddr->sample_inc = 1; ddr->valid[DDINCV] = VALID; } /* Line/sample relative to master image; both int */ ddr->master_line = meta->general->start_line + 1; ddr->master_sample = meta->general->start_sample + 1; /* Projection distance per pixel; both double (pixel size)*/ ddr->pdist_y = meta->general->y_pixel_size; ddr->pdist_x = meta->general->x_pixel_size; ddr->valid[DDPDV] = ((meta->general->y_pixel_size == meta->general->y_pixel_size) &&(meta->general->x_pixel_size == meta->general->x_pixel_size)) ? VALID : INVAL; /* Projection dependent stuff */ if (meta->projection) { meta_projection *proj = meta->projection; /* UTM zone code or 62 if n/a; int */ ddr->zone_code = (proj->type==UNIVERSAL_TRANSVERSE_MERCATOR) ? proj->param.utm.zone : 62; ddr->valid[DDZCV] = VALID; /* If the projection block perX and perY are available, we should use them for the pixel sizes. */ if ( meta->projection->type != SCANSAR_PROJECTION ) { ddr->pdist_x = fabs(meta->projection->perX); ddr->pdist_y = fabs(meta->projection->perY); } /* Projection type; int * AND * Projection coefficients array; double[15] * Entire coefficients array is 0.0 for Geographic and UTM; * meta structure does not currently support geographic or albers projections */ switch (proj->type) { case SCANSAR_PROJECTION: /* Along-track/cross-track... ddr has no atct projection, default to UTM */ /*Can't do anything here until we add AT/CT to asf_geolib.*/ proj_invalid=1; /* printf("Warning in asf_meta library function meta2ddr:\n" " DDR files do not support JPL's along-track/cross-track projection.\n" " For valid DDR data, you should geocode your data under a different\n" " projection (use ASF tool 'geocode').\n");*/ break; case ALBERS_EQUAL_AREA:/* Albers Conic Equal Area */ ddr->proj_code = ALBERS; ddr->valid[DDPCV] = VALID; ddr->proj_coef[0] = proj->re_major; ddr->proj_coef[1] = proj->re_minor; ddr->proj_coef[2] = packed_deg(proj->param.albers.std_parallel1); /*standard parallel1*/ ddr->proj_coef[3] = packed_deg(proj->param.albers.std_parallel2); /*standard parallel2*/ ddr->proj_coef[4] = packed_deg(proj->param.albers.center_meridian); /*Center longitude of proj*/ ddr->proj_coef[5] = packed_deg(proj->param.albers.orig_latitude); /*Center latitude of proj*/ ddr->proj_coef[6] = 0.0; /*False Easting*/ ddr->proj_coef[7] = 0.0; /*False Northing*/ ddr->valid[DDPPV] = VALID; /* Validity of proj_coef array */ break; case LAMBERT_CONFORMAL_CONIC:/* Lambert Conformal Conic */ ddr->proj_code = LAMCC; ddr->valid[DDPCV] = VALID; ddr->proj_coef[0] = proj->re_major; ddr->proj_coef[1] = proj->re_minor; ddr->proj_coef[2] = packed_deg(proj->param.lamcc.plat1); /*standard parallel1*/ ddr->proj_coef[3] = packed_deg(proj->param.lamcc.plat2); /*standard parallel2*/ ddr->proj_coef[4] = packed_deg(proj->param.lamcc.lon0); /*Center longitude of proj*/ ddr->proj_coef[5] = packed_deg(proj->param.lamcc.lat0); /*Center latitude of proj*/ ddr->proj_coef[6] = 0.0; /*False Easting*/ ddr->proj_coef[7] = 0.0; /*False Northing*/ ddr->valid[DDPPV] = VALID; /* Validity of proj_coef array */ break; case POLAR_STEREOGRAPHIC:/* Polar Stereographic */ ddr->proj_code = PS; ddr->valid[DDPCV] = VALID; ddr->proj_coef[0] = proj->re_major; ddr->proj_coef[1] = proj->re_minor; ddr->proj_coef[4] = packed_deg(proj->param.ps.slon);/*Longitude down below pole of map*/ ddr->proj_coef[5] = packed_deg(proj->param.ps.slat);/*Latitude of true scale*/ ddr->proj_coef[6] = 0.0; /*False Easting*/ ddr->proj_coef[7] = 0.0; /*False Northing*/ ddr->valid[DDPPV] = VALID; /* Validity of proj_coef array */ break; case UNIVERSAL_TRANSVERSE_MERCATOR:/* Universal Transverse Mercator */ ddr->proj_code = UTM; ddr->valid[DDPCV] = VALID; /*Unnecessary since the zone is specified*/ ddr->proj_coef[0] = meta->general->center_latitude; /*any longitude in proj*/ ddr->proj_coef[1] = meta->general->center_longitude;/*any latitude in proj*/ ddr->valid[DDPPV] = VALID; /* Validity of proj_coef array */ break; case LAT_LONG_PSEUDO_PROJECTION: /* Geographic */ ddr->proj_code = GEO; ddr->valid[DDPCV] = VALID; break; default:/*Der?*/ printf("Unrecognized map projection type '%c' passed to meta2ddr!\n",proj->type); printf("Continuing...\n"); proj_invalid=1; ddr->proj_code = -1; break; } /* Datum Code; int */ ddr->datum_code = earth_radius2datum(proj->re_major, proj->re_minor); ddr->valid[DDDCV] = (ddr->datum_code==-1) ? INVAL : VALID; /* Corner Coordinates; all double[2] */ ddr->upleft[0] = proj->startY; ddr->upleft[1] = proj->startX; ddr->loleft[0] = proj->startY + meta->general->line_count * proj->perY; ddr->loleft[1] = proj->startX; ddr->upright[0] = proj->startY; ddr->upright[1] = proj->startX + meta->general->sample_count * proj->perX; ddr->loright[0] = proj->startY + meta->general->line_count * proj->perY; ddr->loright[1] = proj->startX + meta->general->sample_count * proj->perX; ddr->valid[DDCCV] = ((proj->startY == proj->startY) &&(proj->startX == proj->startX)) ? VALID : INVAL; if (proj_invalid) { for (ii=0;ii<4;ii++) ddr->valid[ii] = UNKNOW; ddr->valid[DDCCV] = INVAL; } } /* End projection info */ }
void airsar2ddr(char* airsarname, struct DDR *ddrOut) { char dtype[50]; int dt, i; printf("Starting AirSAR Header -> DDR conversion!\n"); /* The necessary parts of a DDR file: setting up. * *------------------------------------------------* ********************void airsar2ddr(char* airsarname, struct DDR *ddrOut) ******************************/ c_intddr(ddrOut); /* number of lines in image */ ddrOut->nl = atoi(get_airsar(airsarname, "FIRST", "NUMBER OF LINES IN IMAGE")); printf("."); /* number of samples in image */ ddrOut->ns = atoi(get_airsar(airsarname, "FIRST", "NUMBER OF SAMPLES PER RECORD")); printf("."); /* number of bands in image */ ddrOut->nbands = 1; printf("."); ddrOut->pdist_y = atof(get_airsar(airsarname, "FIRST", "AZIMUTH PIXEL SPACING (METERS)")); printf("."); ddrOut->pdist_x = atof(get_airsar(airsarname, "FIRST", "RANGE PIXEL SPACING (METERS)")); printf("."); strcpy(dtype, get_airsar(airsarname, "FIRST", "DATA TYPE")); if(!strcmp(dtype, "BYTE")) dt=EBYTE; else if(!strcmp(dtype, "INTEGER*2")) dt=EWORD; else if(!strcmp(dtype, "INTEGER*4")) dt=ELONG; else if(!strcmp(dtype, "REAL*4")) dt=EREAL; else if(!strcmp(dtype, "REAL*8")) dt=EDOUBLE; else asfPrintError("Unknown data type '%s'\n",dtype); /* data type of pixels (unsigned char, short int, float)*/ ddrOut->dtype = dt; printf("."); /* computer system data is on */ strcpy(ddrOut->system, "ieee-std"); printf("."); /* line relative to master image. */ ddrOut->master_line = 1; printf("."); /* sample relative to master image */ ddrOut->master_sample = 1; printf("."); for(i=0; i<8; i++) { ddrOut->valid[i] = INVAL; /* valid flags: 0, 1, 2 */ printf("."); } ddrOut->valid[4] = VALID; /* Projection Units */ ddrOut->valid[5] = VALID; /* Projection Distance */ ddrOut->valid[7] = VALID; /* Increment */ /* Projection units (GCTP units+other) */ strcpy(ddrOut->proj_units, "METERS"); printf("."); /* Not currently implemented ddrOut->upleft[0] = atof(get_airsar(airsarname, "DEM", "LATITUDE OF CORNER 2")); ddrOut->upleft[1] = atof(get_airsar(airsarname, "DEM", "LONGITUDE OF CORNER 2")); ddrOut->loleft[0] = atof(get_airsar(airsarname, "DEM", "LATITUDE OF CORNER 4")); ddrOut->loleft[1] = atof(get_airsar(airsarname, "DEM", "LONGITUDE OF CORNER 4")); ddrOut->upright[0] = atof(get_airsar(airsarname, "DEM", "LATITUDE OF CORNER 1")); ddrOut->upright[1] = atof(get_airsar(airsarname, "DEM", "LONGITUDE OF CORNER 1")); ddrOut->loright[0] = atof(get_airsar(airsarname, "DEM", "LATITUDE OF CORNER 3")); ddrOut->loright[1] = atof(get_airsar(airsarname, "DEM", "LONGITUDE OF CORNER 3")); ddrOut->pdist_y = atof(get_airsar(airsarname, "DEM", "Y-DIRECTION POST SPACING")); ddrOut->pdist_x = atof(get_airsar(airsarname,"DEM", "X-DIRECTION POST SPACING")); */ /* line increment for sampling */ ddrOut->line_inc = 1.0; printf("."); /* sample increment for sampling */ ddrOut->sample_inc = 1.0; printf(".\n"); printf("Finished DDR conversion!\n"); return; }