/****************************************************** * meta_init_old: * Reads in a new meta_parameters record from disk with * the given filename. If no .meta exists, it calls * meta_create to construct one. * THIS SHOULD EVENTUALLY BE REMOVED AND raw_init SHOULD * TAKE ITS NAME */ meta_parameters *meta_init(const char *fName) { if (extExists(fName,".meta")) /*Read .meta file if possible*/ return meta_read(fName); else return meta_create(fName); }
/*********************************************************** * meta_create: * Constructs a new meta_parameters record from CEOS, ARDOP * inputs, etc-- whatever it can find.*/ meta_parameters *meta_create(const char *fName) { meta_parameters *meta = raw_init(); //int success=FALSE; char **junk=NULL; int junk2; if (require_ceos_metadata(fName,&junk,&junk2) != NO_CEOS_METADATA) { ceos_init(fName, meta, REPORT_LEVEL_STATUS); //success=TRUE; FREE(junk[0]); FREE(junk[1]); FREE(junk); } if (extExists(fName,".in")) { ardop_init(fName,meta); //success=TRUE; } //if (success) meta_new2old(meta); return meta; }
/******************************************************************************* * fopenImage: * first tries to open the given image name, then appends ".img" and tries again * It returns a pointer to the opened file.*/ FILE *fopenImage(const char *fName,const char *access) { int forWriting=0; FILE *fRet=NULL; char *openName=NULL; /* Check to make sure that the (bone-headed) user didn't ask us to open a .ddr image or .meta file. findExt may return a pointer into its argument string, so fName isn't const anymore. */ char *ext=findExt( (char *) fName); if (NULL!=ext) { if ( (0==strcmp(ext,".ddr")) || (0==strcmp(ext,".meta"))) ext[0]=0;/*Clip off stupid extention-- will append .img later*/ else if ( ((0==strcmp(ext,".D"))||(0==strcmp(ext,".L"))) && (access[0]=='w' || access[0]=='a')) ext[0]=0;/*Clip off stupid extention-- will append .img later*/ } /*Find the file's actual name, with the correct extension.*/ if (access[0]=='w' || access[0]=='a') {/*We're opening for writing-- we have to be conservative.*/ forWriting=1; if (NULL==findExt((char *)fName))/*If there is no extension,*/ openName=appendExt(fName,".img");/*Append .img*/ else /*There was an extension, so */ openName=appendExt(fName,NULL);/*Do nothing to the name.*/ } else {/*We're opening for reading-- search many extensions for the image.*/ char *extTable[]={".img",".dem",".ht",".coh",NULL}; int extNo=-1; do { char *ext=(extNo==-1)?NULL:extTable[extNo]; if (extExists(fName,ext)) {/*We found a file with the given basename and extension!*/ openName=appendExt(fName,ext); break;/*Once we find one, we're done.*/ } extNo++; } while (extTable[extNo]!=NULL); } /*Try to open this name.*/ if (NULL!=openName) { fRet=fopen(openName,access); if (fRet!=NULL) {/*We've sucessfully opened the file.*/ free(openName);/*Free the name.*/ return fRet;/*Return the file pointer.*/ } } /*An error occured-- tell the user and quit.*/ if (errno) { asfPrintStatus("Errno %d: %s\n", errno, strerror(errno)); } asfPrintStatus("Tried to open: %s\n", (openName != NULL && strlen(openName)) ? openName : "invalid filename"); fprintf(stderr, "********************** Error! ***********************\n" "An error occured trying to open for %s the\n" "file named '%s'.\n\n",forWriting?"write or create":"reading", fName); if (forWriting) fprintf(stderr, "This could be because you don't have write permissions\n" "in this directory, because your disk quota is full, or \n" "because your disk is full.\n"); else /*for reading*/ fprintf(stderr, "This could be because the file doesn't exist in this\n" "directory, or you don't have read permissions for the\n" "file. I even searched for common image extensions.\n"); exit(102); return NULL; }
lasErr FUNCTION do_open(struct FDESC *fd) { /*int type, chans, lines, linsiz, labels, labsiz, lun;*/ int opflg; /* open flag */ /*char buf[64];*/ /* buffer to check type of file */ if (fd->acc == IWRITE) { /*lun = glun++;*/ /* org = ORG; */ /*ASF*/ /*chans = fd->nbands;*/ /*lines = fd->nl;*/ /*if (fd->flags & CONVERSION) linsiz = fd->ns * datasize[fd->conv_type]; else linsiz = fd->ns * datasize[fd->dtype];*/ /*labels = NLABELS;*/ /*labsiz = LABSIZ;*/ if (NULL==findExt(fd->fname)) strcpy(fd->fname,appendExt(fd->fname,".img")); opflg = O_RDWR | O_CREAT | O_TRUNC; #ifdef __MWERKS__ if ((fd->dalfd = open(fd->fname,opflg)) == -1) #else if ((fd->dalfd = open(fd->fname,opflg,0777)) == -1) #endif { perror("doopen-dal"); c_errmsg("Error opening file","doopen-open",NON_FATAL); return(E_FAIL); } } else { /*lun = glun++;*/ /*if (fd->acc == IREAD) type = I_INPUT; else type = I_INOUT;*/ /* open file and check to see if it is in compresssed format ----------------------------------------------------------*/ fd->compres = fd->tae = fd->dal = FALSE; fd->dal = TRUE; if (fd->acc == IREAD) opflg = O_RDONLY; else opflg = O_RDWR; if (extExists(fd->fname,".img")) strcpy(fd->fname,appendExt(fd->fname,".img")); else if (extExists(fd->fname,".dem")) strcpy(fd->fname,appendExt(fd->fname,".dem")); #ifdef __MWERKS__ if ((fd->dalfd = open(fd->fname,opflg)) == -1) #else if ((fd->dalfd = open(fd->fname,opflg,0777)) == -1) #endif { perror("doopen-dal"); c_errmsg("Error opening file","doopen-open",NON_FATAL); return(E_FAIL); } } return(E_SUCC); }
int parse_cla(int argc,char *argv[],struct ARDOP_PARAMS *g,meta_parameters **meta_out) { int read_offset = 0, /* Flag - Read resampling offsets from file? */ read_dopplr = 0; /* Flag - Read doppler constant from file? */ int cal_check=0; /* checks if output file needs input cal file */ int debug_help=-1; /* If -debug 0 used, give debug usage */ char fName_slope[256], /* Input slope,intercept (offsets) file */ fName_doppler[256]; /* Input doppler constant file */ FILE *fp; meta_parameters *meta; /* Preset Optional Command Line Parameters ---------------------------------------------------------*/ g->hamFlag=0; g->kaiFlag=0; g->pwrFlag=0; g->sigmaFlag=0; g->gammaFlag=0; g->betaFlag=0; g->nextend=0.0; g->pctbw=g->pctbwaz=0.0; g->fd=0; g->fdd=-99; /*Doppler slope of -99 means to figure it out ourselves.*/ g->fddd=-99; /*Doppler slope of -99 means to figure it out ourselves.*/ g->ifirstline = 0; /* First line to process */ g->npatches = 100; /* (Absurdly Large) Number of patches */ g->ifirst = 0; /* i,q byte samples to skip */ g->isave = 0; /* start range bin */ g->na_valid = -99; /* Valid output samples per patch (-99->determine)*/ g->iflag = 1; /* Debug Flag */ g->deskew=0; g->sloper = g->interr = g->slopea = g->intera = 0.0; g->dsloper = g->dinterr = g->dslopea = g->dintera = 0.0; strcpy(g->CALPRMS,"NO"); /* Process the Command Line Arguments ------------------------------------*/ if (argc<3) {printf("Must give input and output filenames.\n");return 0;} strcpy(g->in1,argv[argc-2]); strcpy(g->out,argv[argc-1]); /*Create ARDOP_PARAMS struct as well as meta_parameters.*/ if (extExists(g->in1,".in")) {/*Read parameters from parameter file*/ read_params(g->in1,g); if (extExists(g->in1,".meta"))/*Input file has .meta attached: read it*/ meta=meta_read(g->in1); else /*No .meta exists--fabricate one*/ meta=raw_init(); } else /*Read parameters & .meta from CEOS.*/ get_params(g->in1,g,&meta); while (currArg < (argc-2)) { char *key=argv[currArg++]; if (strmatch(key,"-log")) {CHK_ARG_ASP(1); strcpy(logFile, GET_ARG(1)); logflag = 1; fLog = FOPEN(logFile, "a");} else if (strmatch(key,"-debug")) { CHK_ARG_ASP(1); g->iflag = atoi(GET_ARG(1)); if (g->iflag==0) return debug_help; } else if (strmatch(key,"-quiet")) {quietflag = 1;} else if (strmatch(key,"-power")) {g->pwrFlag=1;} else if (strmatch(key,"-sigma")) {g->sigmaFlag=1; cal_check=1;} else if (strmatch(key,"-gamma")) {g->gammaFlag=1; cal_check=1;} else if (strmatch(key,"-beta" )) {g->betaFlag=1; cal_check=1;} else if (strmatch(key,"-hamming")) {g->hamFlag = 1;} else if (strmatch(key,"-kaiser")) {g->kaiFlag = 1;} else if (strmatch(key,"-l")) {CHK_ARG_ASP(1); g->ifirstline = atoi(GET_ARG(1));} else if (strmatch(key,"-p")) {CHK_ARG_ASP(1); g->npatches = atoi(GET_ARG(1));} else if (strmatch(key,"-f")) {CHK_ARG_ASP(1); g->isave += atoi(GET_ARG(1));} else if (strmatch(key,"-s")) {CHK_ARG_ASP(1); g->ifirst += atoi(GET_ARG(1));} else if (strmatch(key,"-n")) {CHK_ARG_ASP(1); g->nla = atoi(GET_ARG(1));} else if (strmatch(key,"-r")) {CHK_ARG_ASP(1); g->azres = atof(GET_ARG(1));} else if (strmatch(key,"-e")) {CHK_ARG_ASP(1); g->deskew = atoi(GET_ARG(1)); g->na_valid =-99;} /* If you use the -e flag, then a deskew wedge in the data will need to be removed. Override internal measurement of the number of valid azimuth lines with the -v option flag */ else if (strmatch(key,"-v")) {CHK_ARG_ASP(1); g->na_valid = atoi(GET_ARG(1));} else if (strmatch(key,"-o")) {CHK_ARG_ASP(1); strcpy(fName_slope,GET_ARG(1)); read_offset = 1;} else if (strmatch(key,"-c")) {CHK_ARG_ASP(1); strcpy(fName_doppler,GET_ARG(1)); read_dopplr = 1;} else if (strmatch(key,"-m")) {CHK_ARG_ASP(1);strcpy(g->CALPRMS,GET_ARG(1));} else {printf("**Invalid option: %s\n\n",argv[currArg-1]); return 0;} } if ((strcmp(g->CALPRMS,"NO")==0)&&(cal_check==1)) { printf(" You can only use -sigma, -beta, or -gamma in conjunction with -m\n"); printf(" I will proceed, ignoring the option.\n"); g->sigmaFlag=0; g->gammaFlag=0; g->betaFlag=0; } if (read_offset) { fp=FOPEN(fName_slope,"r"); fscanf(fp,"%f %f %f %f",&g->sloper,&g->interr,&g->slopea,&g->intera); fscanf(fp,"%g %g %g %g",&g->dsloper,&g->dinterr,&g->dslopea,&g->dintera); FCLOSE(fp); } if (read_dopplr) { fp=FOPEN(fName_doppler,"r"); g->fd=g->fdd=g->fddd=0.0; fscanf(fp,"%f %f %f", &g->fd,&g->fdd,&g->fddd); FCLOSE(fp); } /*Copy fields from ARDOP_PARAMS struct to meta_parameters struct.*/ meta->sar->image_type = 'S'; /*Slant range image*/ meta->sar->azimuth_look_count = g->nlooks; meta->sar->range_look_count = 1; meta->sar->deskewed = g->deskew; meta->sar->range_time_per_pixel = 1.0/g->fs; meta->sar->azimuth_time_per_pixel = 1.0/g->prf; meta->sar->slant_shift = g->slantOff; meta->sar->time_shift = g->timeOff; meta->sar->slant_range_first_pixel = g->r00; meta->sar->wavelength = g->wavl; meta->sar->prf = g->prf; meta->sar->earth_radius = g->re; meta->sar->satellite_height = g->re+g->ht; meta->sar->range_doppler_coefficients[0] = g->fd*g->prf; meta->sar->range_doppler_coefficients[1] = g->fdd*g->prf; meta->sar->range_doppler_coefficients[2] = g->fddd*g->prf; meta->sar->azimuth_doppler_coefficients[0] = g->fd*g->prf; meta->sar->azimuth_doppler_coefficients[1] = 0.0; meta->sar->azimuth_doppler_coefficients[2] = 0.0; meta->general->data_type = REAL32; meta->general->band_count = 1; meta->general->x_pixel_size = meta->sar->range_time_per_pixel * (speedOfLight/2.0); meta->general->y_pixel_size = meta->sar->azimuth_time_per_pixel * g->vel * (g->re/g->ht); *meta_out = meta; return 1; }