int main (int argc, char **argv) { int c, errflg = 0; char *in, *out; int orbin, orbout; double maxpkts = VERY_LARGE_NUMBER ; int quit; char *pktmatch = strdup(".*/pf/evtinfo"), *reject = 0; int nmatch; int specified_after = 0; double after = 0.0, until = VERY_LARGE_NUMBER ; double start_time, end_time, delta_t ; double totpkts = 0, totbytes = 0; Flags flags; static int last_pktid = -1; static double last_pkttime = 0.0; char *statefile = 0; double last_burial = 0.0; double decent_interval = 300.0; int mode = PKT_NOSAMPLES; int rcode; char srcname[ORBSRCNAME_SIZE]; double pkttime = 0.0 ; int pktid; int nbytes; char *packet = 0; int packetsz = 0; Packet *unstuffed = 0; Pf *pf; Tbl *tbl; Arr *arr; char *arrkey; char *pffilename; Tbl *channels; char *net; char *sta; char *chan; char netstachan[ORBSRCNAME_SIZE]; Srcname parts; double maxtime,mintime,starttime,triggertime,duration,min_g,max_g,snr; char *datalogger; int evtfilesize,channelno,maxcts,mincts; char *errors,*evtfilename,*ft,*filter,*srcid; char *line; int i; Pf *pfnew; Dbptr db; int put_tests=0; char *chanmatch=0; Hook *hook=0; char *tdummy=0; char *match=malloc(100); memset (&flags, 0, sizeof (flags)); elog_init (argc, argv); elog_notify (0, "%s $Revision: 1.5 $ $Date: 2005/05/10 07:34:43 $\n", Program_Name); while ((c = getopt (argc, argv, "m:n:r:S:c:tvV")) != -1) { switch (c) { case 'm': match = optarg; sprintf(pktmatch,"%s/pf/evtinfo",match); break; case 'c': chanmatch = optarg; break; case 't': put_tests = 1; break; case 'n': maxpkts = atoi (optarg); break; case 'r': reject = optarg; break; case 'S': statefile = optarg; break; case 'v': flags.verbose++; break; case 'V': flags.verbose++; flags.verbose++; break; case '?': errflg++; } } if (errflg || argc - optind < 2 || argc - optind > 4) usage (); in = argv[optind++]; out = argv[optind++]; if (argc > optind) { after = str2epoch (argv[optind++]); specified_after = 1; if (argc > optind) { until = str2epoch (argv[optind++]); if (until < after) { until += after ; } } } if ((orbin = orbopen (in, "r&")) < 0) die (0, "Can't open input '%s'\n", in); if (statefile != 0) { char *s; if (exhume (statefile, &quit, RT_MAX_DIE_SECS, 0) != 0) { elog_notify (0, "read old state file\n"); } if (orbresurrect (orbin, &last_pktid, &last_pkttime) == 0) { elog_notify (0, "resurrection successful: repositioned to pktid #%d @ %s\n", last_pktid, s = strtime (last_pkttime)); free (s); } else { complain (0, "resurrection unsuccessful\n"); } } if ((orbout = orbopen (out, "w&")) < 0) { die (0, "Can't open output '%s'\n", out); } if (pktmatch) { nmatch = orbselect (orbin, pktmatch); } if (nmatch < 0) { die (1, "select '%s' returned %d\n", pktmatch, nmatch); } if (reject) { nmatch = orbreject (orbin, reject); } if (nmatch < 0) { elog_die (1, "reject '%s' returned %d\n", reject, nmatch); } else { if (flags.verbose) { elog_notify (1,"%d sources selected\n", nmatch); } } if (specified_after) { pktid = orbafter (orbin, after); if (pktid < 0) { char *s; elog_complain (1, "seek to %s failed\n", s = strtime (after)); free (s); pktid = forbtell (orbin); elog_complain (1,"pktid is still #%d\n", pktid); } else { if (flags.verbose) elog_notify (1,"new starting pktid is #%d\n", pktid); } } start_time = now (); db = dbtmp("rt1.0"); while (!quit && pkttime < until && totpkts < maxpkts) { rcode = orbreap (orbin, &pktid, srcname, &pkttime, &packet, &nbytes, &packetsz); switch (rcode) { case 0: totpkts++; totbytes += nbytes; if (flags.verbose>2) { showPkt (pktid, srcname, pkttime, packet, nbytes, stdout, mode); } if (statefile != 0 && last_pkttime - last_burial > decent_interval) { bury (); last_burial = pkttime; } if ((unstuffPkt (srcname, pkttime, packet, nbytes, &unstuffed))==Pkt_pf) { pf = unstuffed->pf; tbl= pfkeys(pf); arrkey= gettbl(tbl,0); pfget(pf,arrkey,&pfnew); datalogger= pfget_string(pfnew,"datalogger"); duration= pfget_double(pfnew,"duration"); errors= pfget_string(pfnew,"errors"); evtfilename= pfget_string(pfnew,"evtfilename"); evtfilesize= pfget_int(pfnew,"evtfilesize"); ft= pfget_string(pfnew,"ft"); starttime= pfget_double(pfnew,"time"); triggertime= pfget_double(pfnew,"triggertime"); channels=pfget_tbl(pfnew,"channels"); if (strcasecmp(ft,"no")==0 || put_tests == 1) { for (i=0; i<maxtbl(channels);i++) { line=gettbl(channels,i); sscanf(line,"%s %d %lf %d %lf %lf %d %lf", netstachan,&channelno,&maxtime,&maxcts,&max_g,&mintime,&mincts,&min_g); split_srcname(netstachan,&parts); strcpy(parts.src_suffix,"GENC"); join_srcname(&parts,netstachan); if (flags.verbose>1) printf("%s,%s\n", netstachan,tdummy=strtime(triggertime)); if (chanmatch == 0 || strmatches(parts.src_chan,chanmatch,&hook)) { if (flags.verbose) elog_notify(1,"putting detev for %s,%s\n", netstachan,tdummy=strtime(triggertime)); db=dblookup(db,0,"detev",0,"dbSCRATCH"); dbputv(db,0,"sta",parts.src_sta,"chan",parts.src_chan, "filter",K2_FILTER, "time", triggertime, "tron", starttime - triggertime, "troff", starttime - triggertime + duration, "iphase","K2", "snr",(max_g * 1000.0 - min_g * 1000.0)/2.0, 0); db2orbpkt(db,orbout); } else { if (flags.verbose>1) elog_notify(1,"ignoring %s,%s\n", netstachan,tdummy=strtime(triggertime)); } } } } last_pktid = pktid; last_pkttime = pkttime; } } if (statefile != 0) bury (); end_time = now (); delta_t = end_time - start_time; if (flags.verbose>1) { if (totpkts > 0) { elog_notify (1,"\n%.0f %.2f byte packets (%.1f kbytes) in %.3f seconds\n\t%10.3f kbytes/s\n\t%10.3f kbaud\n\t%10.3f pkts/s\n", totpkts, totbytes / totpkts, totbytes / 1024, delta_t, totbytes / delta_t / 1024, totbytes / delta_t / 1024 * 8, totpkts / delta_t); } else { elog_notify (1,"\nno packets read\n"); } } if (orbclose (orbin)) { elog_complain (1, "error closing read orb\n"); } if (orbclose (orbout)) { elog_complain (1, "error closing write orb\n"); } return 0; }
int main(int argc, char *argv[]) { int addSpeckle = TRUE; int water = FALSE; char *inFile, *outFile; handle_license_and_version_args(argc, argv, ASF_NAME_STRING); asfSplashScreen(argc, argv); if (argc<=1) usage(ASF_NAME_STRING); else if (strmatches(argv[1],"-help","--help",NULL)) print_help(); while (currArg < (argc-NUM_ARGS)) { char *key = argv[currArg++]; if (strmatches(key,"-water","--water",NULL)) { water = TRUE; } else { printf( "\n**Invalid option: %s\n", argv[currArg-1]); usage(ASF_NAME_STRING); } } if ((argc-currArg) < NUM_ARGS) { printf("Insufficient arguments.\n"); usage(ASF_NAME_STRING); } inFile = argv[currArg]; outFile = argv[currArg+1]; shaded_relief(inFile, outFile, addSpeckle, water); exit(EXIT_SUCCESS); }
// Main program body. int main (int argc, char *argv[]) { char *inFile, *maskFile, *outFile; int currArg = 1; int NUM_ARGS = 3; handle_license_and_version_args(argc, argv, ASF_NAME_STRING); asfSplashScreen(argc, argv); if (argc<=1) usage(ASF_NAME_STRING); else if (strmatches(argv[1],"-help","--help",NULL)) print_help(); while (currArg < (argc-NUM_ARGS)) { char *key = argv[currArg++]; if (strmatches(key,"-help","--help",NULL)) { print_help(); // doesn't return } else if (strmatches(key,"-log","--log",NULL)) { CHECK_ARG(1); strcpy(logFile,GET_ARG(1)); fLog = FOPEN(logFile, "a"); logflag = TRUE; } else if (strmatches(key,"-quiet","--quiet","-q",NULL)) { quietflag = TRUE; } else { --currArg; break; } } if ((argc-currArg) < NUM_ARGS) { printf("Insufficient arguments.\n"); usage(argv[0]); } else if ((argc-currArg) > NUM_ARGS) { printf("Unknown argument: %s\n", argv[currArg]); usage(argv[0]); } inFile = argv[currArg]; maskFile = argv[currArg+1]; outFile = argv[currArg+2]; char *in_base = get_basename(inFile); char *out_base = get_basename(outFile); asfPrintStatus("Clipping image: %s -> %s\n", in_base, out_base); clip(inFile, maskFile, outFile); asfPrintStatus("Done.\n"); free(in_base); free(out_base); return EXIT_SUCCESS; }
// Main program body. int main (int argc, char *argv[]) { int currArg = 1; int NUM_ARGS = 2; char *inFile, *outFile; handle_license_and_version_args(argc, argv, ASF_NAME_STRING); asfSplashScreen(argc, argv); if (argc >= 2 && strmatches(argv[1],"-help","--help",NULL)) print_help(); if (argc<2) scale_usage(ASF_NAME_STRING); while (currArg < (argc-NUM_ARGS)) { char *key = argv[currArg++]; if (strmatches(key,"-help","--help",NULL)) { print_help(); // doesn't return } else if (strmatches(key,"-log","--log",NULL)) { CHECK_ARG(1); strcpy(logFile,GET_ARG(1)); fLog = FOPEN(logFile, "a"); logflag = TRUE; } else if (strmatches(key,"-quiet","--quiet","-q",NULL)) { quietflag = TRUE; } else { --currArg; break; } } if ((argc-currArg) < NUM_ARGS) { printf("Insufficient arguments. Expected %d, got %d.\n", NUM_ARGS, argc-currArg); scale_usage(argv[0]); } else if ((argc-currArg) > NUM_ARGS) { printf("Unknown argument: %s\n", argv[currArg]); scale_usage(argv[0]); } inFile = argv[currArg]; outFile = argv[currArg+1]; int fail = asf_logscale(inFile, outFile); int ok = !fail; asfPrintStatus(ok ? "Done.\n" : "Failed.\n"); return ok ? EXIT_SUCCESS : EXIT_FAILURE; }
// Main program body. int main (int argc, char *argv[]) { int currArg = 1; int NUM_ARGS = 4; handle_license_and_version_args(argc, argv, ASF_NAME_STRING); asfSplashScreen(argc, argv); if (argc >= 2 && strmatches(argv[1],"-help","--help",NULL)) print_help(); if (argc<3) rtc_usage(ASF_NAME_STRING); while (currArg < (argc-NUM_ARGS)) { char *key = argv[currArg++]; if (strmatches(key,"-help","--help",NULL)) { print_help(); // doesn't return } else if (strmatches(key,"-log","--log",NULL)) { CHECK_ARG(1); strncpy_safe(logFile,GET_ARG(1),256); fLog = FOPEN(logFile, "a"); logflag = TRUE; } else if (strmatches(key,"-quiet","--quiet","-q",NULL)) { quietflag = TRUE; } else { --currArg; break; } } if ((argc-currArg) < NUM_ARGS) { printf("Insufficient arguments. Expected %d, got %d.\n", NUM_ARGS, argc-currArg); rtc_usage(argv[0]); } else if ((argc-currArg) > NUM_ARGS) { printf("Unknown argument: %s\n", argv[currArg]); rtc_usage(argv[0]); } int fail = uavsar_rtc(argv[currArg], argv[currArg+1], argv[currArg+2], argv[currArg+3]); asfPrintStatus(fail ? "Failed.\n" : "Done.\n"); return fail ? EXIT_FAILURE : EXIT_SUCCESS; }
static PyObject * string2PyObject( char *s ) { PyObject *obj; int tf; if( strmatches( s, "^[-+]{0,1}[[:digit:]]{1,}$", 0 ) == 1 ) { obj = Py_BuildValue( "i", atol( s ) ); } else if( ( tf = yesno( s ) ) <= 0 ) { /* Test for true/false after testing for integers since not every 0 or 1 is a boolean, yet 0 and 1 will almost always work as booleans */ if( tf ) { Py_INCREF( Py_True ); obj = Py_True; } else { Py_INCREF( Py_False ); obj = Py_False; } } else if( strmatches( s, "^[-+[:digit:].eE]{1,}$", 0 ) == 1 ) { obj = Py_BuildValue( "d", atof( s ) ); } else if( strmatches( s, "^[[:digit:]]{1,}[GMkmu]$", 0 ) == 1 ) { obj = Py_BuildValue( "d", sz2dbl( s ) ); } else { obj = Py_BuildValue( "s", s ); } return obj; }
// Main program body. int main (int argc, char *argv[]) { char *inFile, *outFile; int currArg = 1; int NUM_ARGS = 2; int insar=FALSE, polarimetry=FALSE; handle_license_and_version_args(argc, argv, ASF_NAME_STRING); asfSplashScreen(argc, argv); if (argc<=1) usage(ASF_NAME_STRING); else if (strmatches(argv[1],"-help","--help",NULL)) print_help(); while (currArg < (argc-NUM_ARGS)) { char *key = argv[currArg++]; if (strmatches(key,"-help","--help",NULL)) { print_help(); // doesn't return } else if (strmatches(key,"-log","--log",NULL)) { CHECK_ARG(1); strcpy(logFile,GET_ARG(1)); fLog = FOPEN(logFile, "a"); logflag = TRUE; } else if (strmatches(key,"-quiet","--quiet","-q",NULL)) { quietflag = TRUE; } else if (strmatches(key,"-insar_stack","--insar_stack","-i",NULL)) { insar = TRUE; } else if (strmatches(key,"-polarimetry_stack","--polarimetry_stack","-p",NULL)) { polarimetry = TRUE; } else { --currArg; break; } } if ((argc-currArg) < NUM_ARGS) { printf("Insufficient arguments.\n"); usage(argv[0]); } else if ((argc-currArg) > NUM_ARGS) { printf("Unknown argument: %s\n", argv[currArg]); usage(argv[0]); } inFile = argv[currArg]; outFile = argv[currArg+1]; asf_airsar_import(inFile, outFile, insar, polarimetry); asfPrintStatus("\nDone.\n"); return EXIT_SUCCESS; }
static void parse_orbname( char *orbname, char *orb_address, int *orb_port ) { char *split_orbname; Tbl *orbname_parts; char orbname_port[STRSZ]; Hook *hook = 0; static Pf *pfnames = 0; int len = 0; if( STREQ( orbname, ":" ) ) { strcpy( orb_address, "127.0.0.1" ); strcpy( orbname_port, "" ); } else { split_orbname = strdup( orbname ); orbname_parts = split( split_orbname, ':' ); if( maxtbl( orbname_parts ) == 1 && orbname[0] == ':' ) { strcpy( orb_address, "127.0.0.1" ); strcpy( orbname_port, poptbl( orbname_parts ) ); } else if( maxtbl( orbname_parts ) == 1 ) { strcpy( orb_address, shifttbl( orbname_parts ) ); strcpy( orbname_port, "" ); } else if( maxtbl( orbname_parts ) == 2 ) { strcpy( orb_address, shifttbl( orbname_parts ) ); strcpy( orbname_port, poptbl( orbname_parts ) ); } else { elog_complain( 0, "pforbstat: unexpected error translating orb2orb argument <%s>\n", orbname ); strcpy( orb_address, "" ); strcpy( orbname_port, "" ); } free( split_orbname ); freetbl( orbname_parts, 0 ); } if( ( len = strlen( orbname_port ) ) > 0 ) { if( orbname_port[len-1] == '@' ) { orbname_port[len-1] = '\0'; } } if( STREQ( orbname_port, "" ) ) { *orb_port = ORB_TCP_PORT; } else if( strmatches( orbname_port, "^[0-9]+$", &hook ) ) { *orb_port = atoi( orbname_port ); } else { if( pfnames == 0 ) { pfread( "orbserver_names", &pfnames ); } if( pfget_string( pfnames, orbname_port ) == 0 ) { elog_complain( 0, "pforbstat: couldn't translate orb port \":%s\"\n", orbname_port ); *orb_port = 0; } else { *orb_port = pfget_int( pfnames, orbname_port ); } } return; }
// Main program body. int main (int argc, char *argv[]) { char *inFile, *outFile; int currArg = 1; int NUM_ARGS = 2; // process log/quiet/license/etc options handle_common_asf_args(&argc, &argv, ASF_NAME_STRING); asfSplashScreen(argc, argv); char classFile[255]; int classify = extract_string_options(&argc,&argv,classFile,"-c",NULL); int debug = extract_flag_options(&argc,&argv,"-debug","-d",NULL); int pauli = extract_flag_options(&argc,&argv,"-pauli","-p",NULL); int sinclair = extract_flag_options(&argc,&argv,"-sinclair","-s",NULL); int freeman = extract_flag_options(&argc,&argv,"-freeman","-f",NULL); int sz; int make_boundary_file = extract_int_options(&argc,&argv,&sz,"-make-feasible-boundary",NULL); if (make_boundary_file) { const char *fname = "ea_boundary.txt"; asfPrintStatus("Generating entropy/alpha boundary curve file: %s\n", fname); asfPrintStatus("Number of points: %d\n", sz); make_entropy_alpha_boundary(fname, sz); // if no other arguments were supplied, we are done - can exit // without making a fuss. if (argc==1) { asfPrintStatus("Done.\n"); exit(1); } } if (classify + pauli + sinclair + freeman > 1) { asfPrintError("Use only one of the -pauli, -sinclair, -freeman " "or -c options.\n"); } if (argc<=1) usage(ASF_NAME_STRING); else if (strmatches(argv[1],"-help","--help",NULL)) print_help(); else if (argc<=2) usage(ASF_NAME_STRING); while (currArg < (argc-NUM_ARGS)) { char *key = argv[currArg++]; if (strmatches(key,"-help","--help",NULL)) { print_help(); // doesn't return } else { --currArg; break; } } if ((argc-currArg) < NUM_ARGS) { printf("Insufficient arguments.\n"); usage(argv[0]); } else if ((argc-currArg) > NUM_ARGS) { printf("Unknown argument: %s\n", argv[currArg]); usage(argv[0]); } inFile = argv[currArg]; outFile = argv[currArg+1]; if (debug) { asfPrintError("Debug mode no longer available.\n"); //cpx2debug(inFile,outFile); } else if (classify) { polarimetric_decomp(inFile,outFile,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, classFile,1); } else if (pauli) { cpx2pauli(inFile,outFile,TRUE); } else if (sinclair) { cpx2sinclair(inFile,outFile,FALSE); } else if (freeman) { cpx2freeman_durden(inFile,outFile,TRUE); } else { polarimetric_decomp(inFile,outFile,0,1,2,3,4,5,6,7,8,9,-1,-1,-1,NULL,-1); } asfPrintStatus("Done.\n"); return EXIT_SUCCESS; }
void mexFunction ( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) { Dbptr db; Point *polygon; char *pname; char *ptype; char *auth; char *dir; char *dfile; char *s_pcode; int pcode; double *lat; double *lon; long nsamp; mwSize nlat,nlon; const mwSize *dimensions; int i; int retcode; char *dbfile_name; char *dbschema_name; char errmsg[STRSZ]; if ( nrhs != 9 ) { antelope_mexUsageMsgTxt ( USAGE ); return; } else if ( ! get_dbptr( prhs[0], &db ) ) { antelope_mexUsageMsgTxt ( USAGE ); return; } else if ( !mxIsDouble( prhs[1] ) ) { antelope_mexUsageMsgTxt ( USAGE ); return; } else if ( !mxIsDouble( prhs[2] ) ) { antelope_mexUsageMsgTxt ( USAGE ); return; } else if ( !mxIsChar( prhs[3] ) ) { antelope_mexUsageMsgTxt ( USAGE ); return; } else if ( !mxIsChar( prhs[4] ) ) { antelope_mexUsageMsgTxt ( USAGE ); return; } else if ( !mxIsChar( prhs[5] ) ) { antelope_mexUsageMsgTxt ( USAGE ); return; } else if ( !mxIsChar( prhs[6] ) ) { antelope_mexUsageMsgTxt ( USAGE ); return; } else if ( !mxIsChar( prhs[7] ) ) { antelope_mexUsageMsgTxt ( USAGE ); return; } else if ( !mxIsChar( prhs[8] ) ) { antelope_mexUsageMsgTxt ( USAGE ); return; } dimensions= (mwSize*) mxGetDimensions( prhs[1] ); if (dimensions[1] != 1 && dimensions[0] != 1) { mexErrMsgTxt("writepolygondata: LAT must have dimensions Nx1 or 1xN\n"); } if (dimensions[1] == 1) { nlat= dimensions[0]; } else { nlat= dimensions[1]; } dimensions= (mwSize *)mxGetDimensions( prhs[2] ); if (dimensions[1] != 1 && dimensions[0] != 1) { mexErrMsgTxt("writepolygondata: LON must have dimensions Nx1 or 1xN\n"); } if (dimensions[1] == 1) { nlon= dimensions[0]; } else { nlon= dimensions[1]; } if (nlat != nlon) { mexErrMsgTxt("writepolygondata: LAT and LON must be of same size\n"); } if( ( retcode = dbquery(db, dbDATABASE_FILENAME, &dbfile_name) ) < 0 ) { mexErrMsgTxt("writepolygondata: problem getting descriptor filename\n"); } if ( is_file(dbfile_name)==1 ) { if( ( retcode = dbquery(db, dbSCHEMA_NAME, &dbschema_name) ) < 0 ) { mexErrMsgTxt("writepolygondata: problem getting schema name\n"); } else { if (strmatches(dbschema_name,"polygon1.2.*", 0) != 1) { sprintf(errmsg, "writepolygondata: wrong schema '%s' for output database '%s'\n",dbschema_name,dbfile_name); mexErrMsgTxt(errmsg); } } } else { sprintf(errmsg, "writepolygondata: please create database schema '%s' with schema polygon1.2\n",dbfile_name); mexErrMsgTxt(errmsg); //there might be a fix, but for the moment this simply does NOT work if (dbcreate(dbfile_name,"polygon1.2",0, 0, 0) != 0 ) { mexErrMsgTxt("writepolygondata: problem with dbcreate\n"); } } nsamp= (long) nlat; lat= mxGetPr(prhs[1]); lon= mxGetPr(prhs[2]); polygon= mxCalloc(nsamp+1,sizeof(Point)); for (i= 0; i < nsamp; i++) { polygon[i].lat=lat[i]; polygon[i].lon=lon[i]; } get_malloced_string(prhs[3],&pname); get_malloced_string(prhs[4],&ptype); get_malloced_string(prhs[5],&auth); get_malloced_string(prhs[6],&dir); get_malloced_string(prhs[7],&dfile); get_malloced_string(prhs[8],&s_pcode); pcode= polycode(s_pcode); /*maybe nsamp -1, check later...*/ writePolygonData(db,polygon,nsamp,pname,1,1,ptype,auth,dir,dfile,pcode); antelope_mex_clear_register(1); mxFree(polygon); mxFree(s_pcode); mxFree(dfile); mxFree(dir); mxFree(auth); mxFree(ptype); mxFree(pname); }
// Main program body. int main (int argc, char *argv[]) { char *inFile, *demFile, *inMaskFile, *outFile; double pixel_size = -1; int dem_grid_size = 20; int currArg = 1; int clean_files = TRUE; int do_resample = TRUE; int do_interp = TRUE; int do_fftMatch_verification = TRUE; int do_corner_matching = FALSE; int generate_water_mask = FALSE; int save_clipped_dem = FALSE; int doRadiometric = FALSE; int update_original_metadata_with_offsets = FALSE; float mask_height_cutoff = 1.0; int mask_height_cutoff_specified = FALSE; int smooth_dem_holes = FALSE; int no_matching = FALSE; int use_gr_dem = FALSE; int add_speckle = TRUE; int if_coreg_fails_use_zero_offsets = FALSE; int save_ground_dem = FALSE; int save_incid_angles = FALSE; int use_nearest_neighbor = FALSE; double range_offset = 0.0; double azimuth_offset = 0.0; char *other_files[MAX_OTHER]; int i,n_other = 0; for (i=0; i<MAX_OTHER; ++i) other_files[i]=NULL; // -1 -> no masking, other values mean fill it with that value int fill_value = 0; handle_common_asf_args(&argc, &argv, ASF_NAME_STRING); asfSplashScreen(argc, argv); inMaskFile = NULL; if (argc<=1) usage(ASF_NAME_STRING); else if (strmatches(argv[1],"-help","--help",NULL)) print_help(); while (currArg < (argc-NUM_ARGS)) { char *key = argv[currArg++]; if (strmatches(key,"-keep","--keep","-k",NULL)) { clean_files = FALSE; } else if (strmatches(key,"-no-resample","--no-resample",NULL)) { do_resample = FALSE; } else if (strmatches(key,"-no-verify-match","--no-verify-match",NULL)) { do_fftMatch_verification = FALSE; } else if (strmatches(key,"-no-corner-match","--no-corner-match",NULL)) { do_corner_matching = FALSE; } else if (strmatches(key,"-no-interp","--no-interp",NULL)) { do_interp = FALSE; } else if (strmatches(key,"-no-match","--no-match",NULL)) { no_matching = TRUE; } else if (strmatches(key,"-use-gr-dem", "--use-gr-dem",NULL)) { use_gr_dem = TRUE; } else if (strmatches(key,"-use-sr-dem", "--use-sr-dem",NULL)) { use_gr_dem = FALSE; } else if (strmatches(key,"-no-speckle", "--no-speckle",NULL)) { add_speckle = FALSE; } else if (strmatches(key,"-use-zero-offsets-if-match-fails", "--use-zero-offsets-if-match-fails",NULL)) { if_coreg_fails_use_zero_offsets = TRUE; } else if (strmatches(key,"-pixel-size","--pixel-size","-ps",NULL)) { CHECK_ARG(1); pixel_size = atof(GET_ARG(1)); } else if (strmatches(key,"-dem-grid-size","--dem-grid-size",NULL)) { CHECK_ARG(1); dem_grid_size = atoi(GET_ARG(1)); } else if (strmatches(key,"-mask-file","--mask-file",NULL)) { CHECK_ARG(1); inMaskFile = GET_ARG(1); } else if (strmatches(key,"-auto-water-mask","--auto-water-mask",NULL)) { generate_water_mask = TRUE; } else if (strmatches(key,"-mask-height-cutoff","--mask-height-cutoff",NULL)) { CHECK_ARG(1); mask_height_cutoff = atof(GET_ARG(1)); mask_height_cutoff_specified = TRUE; } else if (strmatches(key, "-u", "-update-original-meta", "--update-original-meta", NULL)) { update_original_metadata_with_offsets = TRUE; } else if (strmatches(key,"-fill","--fill",NULL)) { CHECK_ARG(1); fill_value = atoi(GET_ARG(1)); // user requested a specific fill value } else if (strmatches(key,"-offsets","--offsets",NULL)) { CHECK_ARG(2); range_offset = atof(GET_ARG(2)); azimuth_offset = atof(GET_ARG(1)); no_matching = TRUE; } else if (strmatches(key,"-no-fill","--no-fill",NULL)) { // leave masked regions alone - fill with sar data fill_value = LEAVE_MASK; } else if (strmatches(key,"-do-radiometric","--do-radiometric",NULL)) { // for the 3.1 release, we will always do formula #5 // it's the only one we've had time to test. In later releases, // we can switch to the other version ... this does mean // that -do-radiometric will change from a flag to an option with // an argument. #ifndef ALLOW_ALL_RADIOMETRIC_TC_FORMULAS doRadiometric = 5; #else CHECK_ARG(1); char *form = strdup(GET_ARG(1)); doRadiometric = atoi(form); // give the do-radiometric help in here for now, later should be // put into the rest of the help (when it is officially supported) if (strmatches(form, "help", "?", NULL) || doRadiometric==0) { asfPrintStatus( "Specify a radiometric terrain correction formula to use.\n" "Formula numbers are as follows:\n" " 1 : LI\n" " 2 : GO\n" " 3 : SQ\n" " 4 : VX\n" " 5 : 1 - .7*pow(cos(li), 7)\n" "\n" "e.g.,\n" " asf_terrcorr -do-radiometric 1 ...\n\n"); exit(1); } free(form); #endif } else if (strmatches(key,"-smooth-dem-holes","--smooth-dem-holes",NULL)) { smooth_dem_holes = TRUE; } else if (strmatches(key,"-save-ground-range-dem","--save-ground-range-dem", NULL)) { save_ground_dem = TRUE; } else if (strmatches(key,"-use-nearest-neighbor","--use-nearest-neighbor",NULL)) { use_nearest_neighbor = TRUE; } else if (strmatches(key,"-use-bilinear","--use-bilinear",NULL)) { use_nearest_neighbor = FALSE; } else if (strmatches(key,"-help","--help",NULL)) { print_help(); // doesn't return } else if (strmatches(key,"-other-file","--other-file",NULL)) { CHECK_ARG(1); if (n_other >= MAX_OTHER) asfPrintError("-other-file option only supported %d times.\n", MAX_OTHER); other_files[n_other++] = STRDUP(GET_ARG(1)); } else { printf( "\n**Invalid option: %s\n", argv[currArg-1]); usage(ASF_NAME_STRING); } } if ((argc-currArg) < NUM_ARGS) { printf("Insufficient arguments.\n"); usage(ASF_NAME_STRING); } if (mask_height_cutoff_specified && !generate_water_mask) { asfPrintWarning("Ignoring -mask-height-cutoff option, as you did not " "request a water mask.\n"); } inFile = argv[currArg]; demFile = argv[currArg+1]; outFile = argv[currArg+2]; int ret = asf_terrcorr_ext(inFile, demFile,inMaskFile,outFile, pixel_size, clean_files, do_resample, do_corner_matching, do_interp, do_fftMatch_verification, dem_grid_size, TRUE, fill_value, generate_water_mask, save_clipped_dem, update_original_metadata_with_offsets, mask_height_cutoff, doRadiometric, smooth_dem_holes, other_files, no_matching, range_offset, azimuth_offset, use_gr_dem, add_speckle, if_coreg_fails_use_zero_offsets, save_ground_dem, save_incid_angles, use_nearest_neighbor); for (i=0; i<MAX_OTHER; ++i) if (other_files[i]) free(other_files[i]); return ret==0 ? EXIT_SUCCESS : EXIT_FAILURE; }
int main(int argc, char **argv) { char inFormat[25], outFormat[25], configFile[255]; int currArg = 1, NUM_ARGS = 1, configFlag = FALSE; c2v_config *cfg=NULL; if (argc < 3) { usage(argv[0]); exit(1); } // Check for configuration file option first while (currArg < (argc-NUM_ARGS)) { char *key = argv[currArg++]; if (strmatches(key, "-help", "--help", NULL)) { usage(argv[0]); char format[25], data_dictionary[512]; CHECK_ARG(1); strcpy(format, GET_ARG(1)); sprintf(data_dictionary, "%s%c%s_data_dictionary.csv", get_asf_share_dir(), DIR_SEPARATOR, format); if (fileExists(data_dictionary)) { asfPrintStatus("\nFormat defined in %s_data_dictionary.csv\n\n", format); catFile(data_dictionary); asfPrintStatus("\n\n"); } else asfPrintWarning("Could not find a data dictionary for format (%s)!\n\n", format); exit(1); } else if (strmatches(key, "-config", "--config", "-c", NULL)) { CHECK_ARG(1); strcpy(configFile, GET_ARG(1)); cfg = read_c2v_config(configFile); configFlag = TRUE; } } if (!configFlag) { sprintf(configFile, "%s%cconvert2vector.config", get_asf_share_dir(), DIR_SEPARATOR); asfPrintStatus("\nReading parameters from default configuration file:\n" "%s\n", configFile); cfg = read_c2v_config(configFile); } // Pick up the rest of the arguments currArg = 1; NUM_ARGS = 2; while (currArg < (argc-NUM_ARGS)) { char *key = argv[currArg++]; if (strmatches(key, "-config", "--config", "-c", NULL)) { ; } else if (strmatches(key, "-log", "--log", NULL)) { CHECK_ARG(1); strcpy(logFile,GET_ARG(1)); fLog = FOPEN(logFile, "a"); logflag = TRUE; } else if (strmatches(key, "-quiet", "--quiet", "-q", NULL)) quietflag = TRUE; else if (strmatches(key, "-list", "--list", NULL)) cfg->list = TRUE; else if (strmatches(key, "-nosplit", "--nosplit", "-ns", NULL)) cfg->nosplit = TRUE; else if (strmatches(key, "-input-format", "--input-format", "-i", NULL)) { CHECK_ARG(1); strcpy(cfg->input_format, GET_ARG(1)); } else if (strmatches(key, "-output-format", "--output-format", "-o", NULL)) { CHECK_ARG(1); strcpy(cfg->output_format, GET_ARG(1)); } else { --currArg; break; } } if ((argc-currArg) < NUM_ARGS) { printf("Insufficient arguments.\n"); usage(argv[0]); } if (!configFlag) { sprintf(cfg->input_file, "%s", argv[currArg++]); sprintf(cfg->output_file, "%s", argv[currArg]); } asfSplashScreen (argc, argv); sprintf(inFormat, "%s", uc(cfg->input_format)); sprintf(outFormat, "%s", uc(cfg->output_format)); // Check whether you can find information about the format in the header // list file in the share directory dbf_header_t *dbf; int nCols; char shape_type[25]; if (strcmp_case(inFormat, "CSV") == 0 || read_header_config(inFormat, &dbf, &nCols, shape_type)) asfPrintStatus(" Converting a %s format file to %s\n", inFormat, outFormat); else asfPrintError(" Unsupported input format (%s)\n", inFormat); // Set output directory as the temporary directory -- where all temp files // created during import should be put char *tmpdir = get_dirname(cfg->output_file); if (tmpdir && strlen(tmpdir) > 0) set_asf_tmp_dir(tmpdir); convert2vector(cfg); asfPrintStatus("Done.\n\n"); return(0); }
// Main program body. int main (int argc, char *argv[]) { int currArg = 1; int NUM_ARGS = 2; handle_license_and_version_args(argc, argv, ASF_NAME_STRING); asfSplashScreen(argc, argv); if (argc<2) usage(ASF_NAME_STRING); else if (strmatches(argv[1],"-help","--help",NULL)) print_help(); while (currArg < (argc-NUM_ARGS)) { char *key = argv[currArg++]; if (strmatches(key,"-help","--help",NULL)) { print_help(); // doesn't return } else if (strmatches(key,"-log","--log",NULL)) { CHECK_ARG(1); strcpy(logFile,GET_ARG(1)); fLog = FOPEN(logFile, "a"); logflag = TRUE; } else if (strmatches(key,"-quiet","--quiet","-q",NULL)) { quietflag = TRUE; } else { --currArg; break; } } if ((argc-currArg) < NUM_ARGS) { printf("Insufficient arguments. Expected %d, got %d.\n", NUM_ARGS, argc-currArg); usage(argv[0]); } else if ((argc-currArg) > NUM_ARGS) { printf("Unknown argument: %s\n", argv[currArg]); usage(argv[0]); } char *in_file = argv[currArg]; char *out_file = argv[currArg+1]; char *in_img = appendExt(in_file, ".img"); char *out_img = appendExt(out_file, ".img"); char *in_meta = appendExt(in_file, ".meta"); char *out_meta = appendExt(out_file, ".meta"); meta_parameters *meta = meta_read(in_meta); if (!meta) asfPrintError("Failed to read metadata for: %s\n", in_file); FILE *ifp = FOPEN(in_img, "r"); FILE *ofp = FOPEN(out_img, "w"); float *buf = MALLOC(sizeof(float)*meta->general->sample_count); int ii,jj; for (ii=0; ii<meta->general->line_count; ++ii) { get_float_line(ifp, meta, ii, buf); for (jj=0; jj<meta->general->sample_count; ++jj) { if (buf[jj] < 0) { buf[jj] = 0; } else { buf[jj] = sqrt(buf[jj]); } } put_float_line(ofp, meta, ii, buf); asfLineMeter(ii,meta->general->line_count); } FCLOSE(ifp); FCLOSE(ofp); FREE(buf); if (meta->stats) { FREE(meta->stats); meta->stats = NULL; } meta_write(meta, out_meta); meta_free(meta); FREE(in_img); FREE(out_img); FREE(in_meta); FREE(out_meta); asfPrintStatus("Done.\n"); return EXIT_SUCCESS; }
static PyObject * python_pf2xml( PyObject *self, PyObject *args ) { char *usage = "Usage: _stock._pf2xml( pfname, flags = 0, prolog = None, name = None )\n"; char *pfname; Pf *pf; char *value; PyObject *obj; PyObject *flags_object; char *flags_string; char *prolog = 0; char *name = 0; int flags = 0; char errmsg[STRSZ]; if( ! PyArg_ParseTuple( args, "sOzz", &pfname, &flags_object, &prolog, &name ) ) { USAGE; return NULL; } if( ( pf = getPf( pfname ) ) == (Pf *) NULL ) { sprintf( errmsg, "Failure opening parameter file '%s'\n", pfname ); raise_elog( ELOG_COMPLAIN, errmsg ); return NULL; } if( name == (char *) NULL ) { name = pfname; } if( PyInt_Check( flags_object ) ) { flags = (int) PyInt_AsLong( flags_object ); } else if( PyString_Check( flags_object ) ) { flags_string = PyString_AsString( flags_object ); if( flags_string != NULL && strmatches( flags_string, ".*PFXML_STRONG.*", 0 ) ) { flags |= PFXML_STRONG; } if( flags_string != NULL && strmatches( flags_string, ".*PFXML_NEWLINES.*", 0 ) ) { flags |= PFXML_NEWLINES; } if( flags_string != NULL && strmatches( flags_string, ".*PFXML_PRESERVE_PFFILE.*", 0 ) ) { flags |= PFXML_PRESERVE_PFFILE; } } else { USAGE; return NULL; } value = pf2xml( pf, name, prolog, flags ); obj = Py_BuildValue( "s", value ); free( value ); return obj; }
int main(int argc, char **argv) { char *listFile, *projFile, *key, line[255]; FILE *fp; project_parameters_t pps; projection_type_t proj_type; datum_type_t datum; spheroid_type_t spheroid; meta_projection *meta_proj; double lat, lon, projX, projY; int listFlag = FALSE; extern int currArg; /* from cla.h in asf.h... initialized to 1 */ currArg = 1; if (argc < 4) { printf("Insufficient arguments.\n"); usage(argv[0]); } key = argv[currArg]; if (strmatches(key,"-list","--list",NULL)) { currArg++; CHECK_ARG(1); listFile = GET_ARG(1); projFile = argv[currArg]; listFlag = TRUE; } else { projX = atof(argv[currArg++]); projY = atof(argv[currArg++]); projFile = argv[currArg]; } system("date"); printf("Program: proj2latLon\n\n"); // Read projection file read_proj_file(projFile, &pps, &proj_type, &datum, &spheroid); // Check whether UTM projection has a zone defined if (proj_type == UNIVERSAL_TRANSVERSE_MERCATOR && (pps.utm.zone < 0 || pps.utm.zone > 60)) asfPrintError("Undefined zone for UTM projection\n"); // Report the conversion type if (proj_type == ALBERS_EQUAL_AREA) printf("Albers Equal Area to Lat/Lon\n\n"); else if (proj_type == LAMBERT_AZIMUTHAL_EQUAL_AREA) printf("Lambert Azimuthal Equal Area to Lat/Lon\n\n"); else if (proj_type == LAMBERT_CONFORMAL_CONIC) printf("Lambert Conformal Conic to Lat/Lon\n\n"); else if (proj_type == POLAR_STEREOGRAPHIC) printf("Polar Stereographic to Lat/Lon\n\n"); else if (proj_type == UNIVERSAL_TRANSVERSE_MERCATOR) printf("UTM to Lat/Lon\n\n"); // Initialize meta_projection block meta_proj = meta_projection_init(); meta_proj->type = proj_type; meta_proj->datum = datum; meta_proj->param = pps; // Read coordinates from list if needed and convert to map coordinates if (listFlag) { fp = FOPEN(listFile, "r"); while (fgets(line, 255, fp) != NULL) { if (strlen(line) > 1) { double junk_height; sscanf(line, "%lf %lf", &projX, &projY); proj_to_latlon(meta_proj, projX, projY, 0.0, &lat, &lon, &junk_height); printf("%.3lf\t%.3lf\t%.4lf\t%.4lf\n", projX, projY, lat*R2D, lon*R2D); } } FCLOSE(fp); } else { double junk_height; proj_to_latlon(meta_proj, projX, projY, 0.0, &lat, &lon, &junk_height); printf("%.3lf\t%.3lf\t%.4lf\t%.4lf\n", projX, projY, lat*R2D, lon*R2D); } printf("\n"); return 0; }
// Main program body. int main (int argc, char *argv[]) { char *faraday_rotation_file, *tec_map_dir, *output_file; char granule_name[255], data_granule_type[255]; int frame_id, revolution, year, day, hour, minute; double look_angle, center_lat, center_lon, faraday_rotation; int currArg = 1; int NUM_ARGS = 2; // process log/quiet/license/etc options handle_common_asf_args(&argc, &argv, ASF_NAME_STRING); asfSplashScreen(argc, argv); if (argc<=1) usage(ASF_NAME_STRING); else if (strmatches(argv[1],"-help","--help",NULL)) print_help(); else if (argc<=2) usage(ASF_NAME_STRING); while (currArg < (argc-NUM_ARGS)) { char *key = argv[currArg++]; if (strmatches(key,"-help","--help",NULL)) { print_help(); // doesn't return } else { --currArg; break; } } if ((argc-currArg) < NUM_ARGS) { printf("Insufficient arguments.\n"); usage(argv[0]); } else if ((argc-currArg) > NUM_ARGS) { printf("Unknown argument: %s\n", argv[currArg]); usage(argv[0]); } faraday_rotation_file = argv[currArg]; tec_map_dir = argv[currArg+1]; output_file = (char *) MALLOC(sizeof(char)*(strlen(faraday_rotation_file)+9)); sprintf(output_file, "%s_wFR.txt", faraday_rotation_file); char *line = (char *) MALLOC(sizeof(char)*4096); // Read granule information FILE *fpIn = FOPEN(faraday_rotation_file, "r"); FILE *fpOut = FOPEN(output_file, "w"); while (fgets(line, 1024, fpIn)) { sscanf(line, "%s %s %d %lf %d %d %d %d %d %lf %lf", granule_name, data_granule_type, &frame_id, &look_angle, &revolution, &year, &day, &hour, &minute, ¢er_lat, ¢er_lon); // Determine CODG file to read from char *codg_file = (char *) MALLOC(sizeof(char)*strlen(tec_map_dir)+20); sprintf(codg_file, "%s%c%d%cCODG%d0.%02dI", tec_map_dir, DIR_SEPARATOR, year, DIR_SEPARATOR, day, year-2000); if (!fileExists(codg_file)) asfPrintError("CODG file (%s) does not exist.\n" "Could not calculate Faraday rotation\n", codg_file); // Determine Faraday rotation faraday_rotation = faraday_prediction(frame_id, look_angle, year, day, hour, minute, center_lat, center_lon, codg_file); // Drop a line in the output file fprintf(fpOut, "%s\t%d\t%.1lf\t%d\t%d\t%d\t%d\t%.4lf\t%.4lf\t%.2lf\n", granule_name, frame_id, look_angle, year, day, hour, minute, center_lat, center_lon, faraday_rotation); } FCLOSE(fpIn); FCLOSE(fpOut); asfPrintStatus("Done.\n"); return EXIT_SUCCESS; }
// Main program body. int main (int argc, char *argv[]) { char *leader_file_list, *output_file, file[255]; struct dataset_sum_rec *dssr; struct att_data_rec *atdr; struct VFDRECV *facdr; int currArg = 1; int NUM_ARGS = 2; // process log/quiet/license/etc options handle_common_asf_args(&argc, &argv, ASF_NAME_STRING); asfSplashScreen(argc, argv); if (argc<=1) usage(ASF_NAME_STRING); else if (strmatches(argv[1],"-help","--help",NULL)) print_help(); else if (argc<=2) usage(ASF_NAME_STRING); while (currArg < (argc-NUM_ARGS)) { char *key = argv[currArg++]; if (strmatches(key,"-help","--help",NULL)) { print_help(); // doesn't return } else { --currArg; break; } } if ((argc-currArg) < NUM_ARGS) { printf("Insufficient arguments.\n"); usage(argv[0]); } else if ((argc-currArg) > NUM_ARGS) { printf("Unknown argument: %s\n", argv[currArg]); usage(argv[0]); } leader_file_list = argv[currArg]; output_file = argv[currArg+1]; // Read granule information FILE *fpIn = FOPEN(leader_file_list, "r"); FILE *fpOut = FOPEN(output_file, "w"); fprintf(fpOut, "Leader_file, Yaw, Doppler_range, Doppler_azimuth\n"); dssr = (struct dataset_sum_rec *) MALLOC(sizeof(struct dataset_sum_rec)); atdr = (struct att_data_rec *) MALLOC(sizeof(struct att_data_rec)); facdr = (struct VFDRECV *) MALLOC(sizeof(struct VFDRECV)); double yaw; while (fgets(file, 1024, fpIn)) { file[strlen(file)-1] = '\0'; if (get_dssr(file, dssr) < 0) { asfPrintWarning("Leader file (%s) does not contain data set summary" " record\n", file); continue; } if (get_atdr(file, atdr) < 0) { asfPrintWarning("Leader file (%s) does not contain attitude data record", "\n", file); continue; } if (get_asf_facdr(file, facdr) < 0) { asfPrintWarning("Leader file (%s) does not contain facility related data" " record\n", file); continue; } yaw = facdr->scyaw; if (FLOAT_EQUIVALENT(yaw, 0.0)) yaw = atdr->data->yaw; fprintf(fpOut, "%s, %.4lf, %.3lf, %.3lf\n", file, yaw, dssr->crt_dopcen[0], dssr->alt_dopcen[0]); } FCLOSE(fpIn); FCLOSE(fpOut); FREE(dssr); FREE(atdr); FREE(facdr); asfPrintStatus("Done.\n"); return EXIT_SUCCESS; }
/* Start of main progam */ int main(int argc, char *argv[]) { char szOut[255], szImg1[255], szImg2[255], *maskFile; int x1, x2, y1, y2; int goodPoints=0, attemptedPoints=0; FILE *fp_output; meta_parameters *masterMeta, *slaveMeta; int logflag=FALSE, ampFlag=TRUE, currArg=1; while (currArg < (argc-NUM_ARGS)) { char *key = argv[currArg++]; if (strmatches(key,"-log","--log",NULL)) { CHECK_ARG(1); strcpy(logFile,GET_ARG(1)); fLog = FOPEN(logFile, "a"); logflag = TRUE; } else if (strmatches(key,"-mask","--mask",NULL)) { CHECK_ARG(1); maskFile = GET_ARG(1); } else { printf("\n**Invalid option: %s\n", argv[currArg-1]); usage(argv[0]); } } if ((argc-currArg) < NUM_ARGS) { printf("Insufficient arguments.\n"); usage(argv[0]); } // Fetch required arguments strcpy(szImg1,argv[argc - 3]); strcpy(szImg2,argv[argc - 2]); strcpy(szOut, argv[argc - 1]); /* Read metadata */ masterMeta = meta_read(szImg1); slaveMeta = meta_read(szImg2); if (masterMeta->general->line_count != slaveMeta->general->line_count || masterMeta->general->sample_count != slaveMeta->general->sample_count) asfPrintWarning("Input images have different dimension!\n"); else if (masterMeta->general->data_type != slaveMeta->general->data_type) asfPrintError("Input image have different data type!\n"); else if (masterMeta->general->data_type > 5 && masterMeta->general->data_type != COMPLEX_REAL32) asfPrintError("Cannot compare raw images for offsets!\n"); lines = masterMeta->general->line_count; samples = masterMeta->general->sample_count; if (masterMeta->general->data_type == COMPLEX_REAL32) { srcSize = 32; ampFlag = FALSE; cZero = Czero(); } /* Create output file */ fp_output=FOPEN(szOut, "w"); /* Loop over grid, performing forward and backward correlations */ while (getNextPoint(&x1,&y1,&x2,&y2)) { float dx=0.0, dy=0.0, snr=0.0, dxFW, dyFW, snrFW, dxBW, dyBW, snrBW; attemptedPoints++; // Check bounds and mask if (!(outOfBounds(x1, y1, srcSize, maskFile))) { /* ...check forward correlation... */ if (ampFlag) { if (!(findPeak(x1,y1,szImg1,x2,y2,szImg2,&dxFW,&dyFW,&snrFW))) { attemptedPoints--; continue; /* next point if chip in complete background fill */ } } else { getPeak(x1,y1,szImg1,x2,y2,szImg2,&dxFW,&dyFW,&snrFW); } if ((!ampFlag && snrFW>minSNR) || (ampFlag)) { /* ...check backward correlation... */ if (ampFlag) { if (!(findPeak(x2,y2,szImg2,x1,y1,szImg1,&dxBW,&dyBW,&snrBW))) { attemptedPoints--; continue; /* next point if chip in complete background fill */ printf("dxFW: %.2f, dyFW: %.2f\n", dxFW, dyFW); } } else { getPeak(x2,y2,szImg2,x1,y1,szImg1,&dxBW,&dyBW,&snrBW); } dxBW*=-1.0;dyBW*=-1.0; if (((!ampFlag && snrFW>minSNR) || (ampFlag)) && (fabs(dxFW-dxBW) < maxDisp) && (fabs(dyFW-dyBW) < maxDisp)) { dx = (dxFW+dxBW)/2; dy = (dyFW+dyBW)/2; snr = snrFW*snrBW; if (dx < maxDxDy && dy < maxDxDy) goodPoints++; } } fprintf(fp_output,"%6d %6d %8.5f %8.5f %4.2f\n", x1, y1, x2+dx, y2+dy, snr); fflush(fp_output); } } if (goodPoints < attemptedPoints) printf("\n WARNING: %i out of %i points moved by " "more than one pixel!\n\n", (attemptedPoints-goodPoints), attemptedPoints); else printf("\n There is no difference between the images\n\n"); FCLOSE(fp_output); FREE(masterMeta); FREE(slaveMeta); return(0); }
// Main program body. int main (int argc, char *argv[]) { char *inFile, *outFile; int currArg = 1; int kernel_size = -1; int NUM_ARGS = 2; handle_license_and_version_args(argc, argv, ASF_NAME_STRING); asfSplashScreen(argc, argv); if (argc<=1) usage(ASF_NAME_STRING); else if (strmatches(argv[1],"-help","--help",NULL)) print_help(); while (currArg < (argc-NUM_ARGS)) { char *key = argv[currArg++]; if (strmatches(key,"-help","--help",NULL)) { print_help(); // doesn't return } else if (strmatches(key,"-log","--log",NULL)) { CHECK_ARG(1); strcpy(logFile,GET_ARG(1)); fLog = FOPEN(logFile, "a"); logflag = TRUE; } else if (strmatches(key,"-quiet","--quiet","-q",NULL)) { quietflag = TRUE; } else if (strmatches(key,"-kernel-size","--kernel-size","-ks","-k",NULL)) { CHECK_ARG(1); kernel_size = atoi(GET_ARG(1)); } else { --currArg; break; } } if ((argc-currArg) < NUM_ARGS) { printf("Insufficient arguments.\n"); usage(argv[0]); } else if ((argc-currArg) > NUM_ARGS) { printf("Unknown argument: %s\n", argv[currArg]); usage(argv[0]); } inFile = argv[currArg]; outFile = argv[currArg+1]; if (kernel_size < 0) asfPrintError("No kernel size specified!\n" "Use the option '-kernel-size'.\n"); char *in_base = get_basename(inFile); char *out_base = get_basename(outFile); asfPrintStatus("Smoothing image: %s -> %s\n", in_base, out_base); smooth(inFile, outFile, kernel_size, EDGE_TRUNCATE); asfPrintStatus("Done.\n"); free(in_base); free(out_base); return EXIT_SUCCESS; }
int main(int argc,char *argv[]) { char infile1[256], infile2[256], infile3[256]; // Input file name char outfile[256]; // Output file name char tmpPath[1024]; browse_type_t mode = NOTYPE; int i,j; int sample_count; double scale; extern int currArg; strcpy(tmpPath, ""); // Parse command line if ((argc-currArg)<1) { printf("Insufficient arguments.\n"); usage(""); } while (currArg < (argc-2)) { char *key = argv[currArg++]; if (strmatches(key, "-sentinel", "--sentinel", NULL)) { CHECK_ARG(1); scale = atof(GET_ARG(1)); mode = SENTINEL_DUAL; } else if (strmatches(key, "-tmpDir", "--tmpDir", NULL)) { CHECK_ARG(1); strcpy(tmpPath, GET_ARG(1)); } else if (strmatches(key, "-log", "--log", NULL)) { CHECK_ARG(1); strcpy(logFile,GET_ARG(1)); fLog = FOPEN(logFile, "a"); logflag = TRUE; } else if (strmatches(key, "-quiet", "--quiet", "-q", NULL)) quietflag = TRUE; else { --currArg; break; } } if ((argc-currArg) < 2) { printf("Insufficient arguments.\n"); usage(argv[0]); } if (mode == NOTYPE && argc == 4) mode = PALSAR_FBD; else if (mode == NOTYPE && argc == 5) mode = PALSAR_PLR; if (!quietflag) asfSplashScreen(argc, argv); if (mode == PALSAR_FBD) { asfPrintStatus("Creating colorized browse image from PALSAR FBD data\n"); create_name(infile1,argv[1],".img"); create_name(infile2,argv[2],".img"); create_name(outfile,argv[3],".img"); meta_parameters *meta1 = meta_read(infile1); meta_parameters *meta2 = meta_read(infile2); if (meta1->general->line_count != meta2->general->line_count || meta1->general->sample_count != meta2->general->sample_count) { asfPrintError("Images must be the same size!!!\n"); exit(1); } strcpy(meta1->general->bands,"HH"); strcpy(meta2->general->bands,"HV"); int pixel_count = meta1->general->line_count*meta1->general->sample_count; float *buf1 = MALLOC(pixel_count * sizeof(float)); float *buf2 = MALLOC(pixel_count * sizeof(float)); float *buf3 = MALLOC(pixel_count * sizeof(float)); unsigned char *cbuf1, *cbuf2, *cbuf3; FILE *fp1 = FOPEN(infile1, "r"); FILE *fp2 = FOPEN(infile2, "r"); FILE *ofp = FOPEN(outfile, "w"); char ofile1[256]; char ofile2[256]; strcpy(ofile1,argv[1]); strcat(ofile1,"_DB.img"); strcpy(ofile2,argv[2]); strcat(ofile2,"_DB.img"); printf("Creating output DB files %s and %s\n",ofile1,ofile2); FILE *ofp1 = FOPEN(ofile1, "w"); FILE *ofp2 = FOPEN(ofile2, "w"); get_float_lines(fp1,meta1,0,meta1->general->line_count, buf1); get_float_lines(fp2,meta2,0,meta2->general->line_count, buf2); /* Convert data from sigma0 to dB */ sample_count = 0; for (i=0; i<meta1->general->line_count; ++i) { for (j=0; j<meta1->general->sample_count; ++j) { if (meta_is_valid_double(buf1[sample_count])) { if (buf1[sample_count] != 0) buf1[sample_count] = 10.0 * log10f(buf1[sample_count]); if (buf2[sample_count] != 0) buf2[sample_count] = 10.0 * log10f(buf2[sample_count]); } sample_count++; } } put_float_lines(ofp1, meta1, 0,meta1->general->line_count,buf1); put_float_lines(ofp2, meta2, 0,meta1->general->line_count,buf2); meta_write(meta1, ofile1); meta_write(meta2, ofile2); fclose(fp1); fclose(fp2); fclose(ofp1); fclose(ofp2); /* Scale the data to a byte range using given min/max values */ cbuf1 = my_floats_to_bytes(buf1,(long long) pixel_count, 0.0,MINMAX,-30.0,-1.0); cbuf2 = my_floats_to_bytes(buf2,(long long) pixel_count, 0.0,MINMAX,-30.0,-10.0); /* cbuf1 = my_floats_to_bytes(buf1,(long long) pixel_count, 0.0,MINMAX,-31.0,7.1); cbuf2 = my_floats_to_bytes(buf2,(long long) pixel_count, 0.0,MINMAX,-31.0,7.1); */ strcpy(ofile1,argv[1]); strcat(ofile1,"_byte.img"); strcpy(ofile2,argv[2]); strcat(ofile2,"_byte.img"); printf("Creating output byte files %s and %s\n",ofile1,ofile2); ofp1 = FOPEN(ofile1, "w"); ofp2 = FOPEN(ofile2, "w"); meta1->general->data_type=REAL32; meta2->general->data_type=REAL32; sample_count = 0; for (i=0; i<meta1->general->line_count; ++i) { for (j=0; j<meta1->general->sample_count; ++j) { buf1[sample_count] = (float) cbuf1[sample_count]; buf2[sample_count] = (float) cbuf2[sample_count]; sample_count++; } } put_float_lines(ofp1,meta1,0,meta1->general->line_count,buf1); put_float_lines(ofp2,meta2,0,meta2->general->line_count,buf2); meta_write(meta1, ofile1); meta_write(meta2, ofile2); fclose(ofp1); fclose(ofp2); /* Create the third band for the color image */ sample_count = 0; for (i=0; i<meta1->general->line_count; ++i) { for (j=0; j<meta1->general->sample_count; ++j) { if (buf2[sample_count] != 0) { /* buf3[sample_count] = (buf1[sample_count] / buf2[sample_count]); */ buf3[sample_count] = (buf1[sample_count] - buf2[sample_count]); if (buf3[sample_count] < 1) buf3[sample_count] = 1; else if (buf3[sample_count] > 255) buf3[sample_count] = 255; } else buf3[sample_count] = 0; sample_count++; } } cbuf3 = my_floats_to_bytes(buf3,(long long) pixel_count, 0.0,SIGMA ,-25.0,-10.0); sample_count = 0; for (i=0; i<meta1->general->line_count; ++i) { for (j=0; j<meta1->general->sample_count; ++j) { buf3[sample_count] = (float) cbuf3[sample_count]; sample_count++; } } /* Finally, create the 3 banded image we were looking for */ strcpy(meta1->general->bands,"HH,HV,DIV"); meta1->general->band_count=3; put_band_float_lines(ofp,meta1,0,0,meta1->general->line_count,buf1); put_band_float_lines(ofp,meta1,1,0,meta1->general->line_count,buf2); put_band_float_lines(ofp,meta1,2,0,meta1->general->line_count,buf3); meta_write(meta1,outfile); } else if (mode == PALSAR_PLR) { /* Mode 1 - Create Color Browse from 3 bands using 3sigma stretch */ asfPrintStatus("Creating colorized browse image from PALSAR PLR data\n"); create_name(infile1,argv[1],".img"); create_name(infile2,argv[2],".img"); create_name(infile3,argv[3],".img"); create_name(outfile,argv[4],".img"); meta_parameters *meta1 = meta_read(infile1); meta_parameters *meta2 = meta_read(infile2); meta_parameters *meta3 = meta_read(infile3); if (meta1->general->line_count != meta2->general->line_count || meta1->general->sample_count != meta2->general->sample_count) { asfPrintError("Images must be the same size!!!\n"); exit(1); } if (meta3->general->line_count != meta2->general->line_count || meta3->general->sample_count != meta2->general->sample_count) { asfPrintError("Images must be the same size!!!\n"); exit(1); } int pixel_count = meta1->general->line_count*meta1->general->sample_count; float *buf1 = MALLOC(pixel_count * sizeof(float)); float *buf2 = MALLOC(pixel_count * sizeof(float)); float *buf3 = MALLOC(pixel_count * sizeof(float)); float *buf4 = MALLOC(pixel_count * sizeof(float)); unsigned char *cbuf1, *cbuf2, *cbuf3, *cbuf4; FILE *fp1 = FOPEN(infile1, "r"); FILE *fp2 = FOPEN(infile2, "r"); FILE *fp3 = FOPEN(infile3, "r"); FILE *ofp = FOPEN(outfile, "w"); get_float_lines(fp1,meta1,0,meta1->general->line_count, buf1); get_float_lines(fp2,meta2,0,meta2->general->line_count, buf2); get_float_lines(fp3,meta3,0,meta3->general->line_count, buf3); /* Convert data from sigma0 to dB */ sample_count = 0; for (i=0; i<meta1->general->line_count; ++i) { for (j=0; j<meta1->general->sample_count; ++j) { if (meta_is_valid_double(buf1[sample_count])) { if (buf1[sample_count] != 0) buf1[sample_count] = 10.0 * log10f(buf1[sample_count]); if (buf2[sample_count] != 0) buf2[sample_count] = 10.0 * log10f(buf2[sample_count]); if (buf3[sample_count] != 0) buf3[sample_count] = 10.0 * log10f(buf3[sample_count]); } sample_count++; } } /* Scale the data to a byte range using 3-sigma stretch values */ cbuf1 = my_floats_to_bytes(buf1,(long long) pixel_count, 0.0,SIGMA3,-30.0,-1.0); cbuf2 = my_floats_to_bytes(buf2,(long long) pixel_count, 0.0,SIGMA3,-30.0,-10.0); cbuf3 = my_floats_to_bytes(buf3,(long long) pixel_count, 0.0,SIGMA3,-30.0,-10.0); meta1->general->data_type=REAL32; //meta2->general->data_type=ASF_BYTE; //meta3->general->data_type=ASF_BYTE; sample_count = 0; for (i=0; i<meta1->general->line_count; ++i) { for (j=0; j<meta1->general->sample_count; ++j) { buf1[sample_count] = (float) cbuf1[sample_count]; buf2[sample_count] = (float) cbuf2[sample_count]; buf3[sample_count] = (float) cbuf3[sample_count]; sample_count++; } } /* Finally, create the 3 banded image we were looking for */ strcpy(meta1->general->bands,"HH,HV,VV"); meta1->general->band_count=3; put_band_float_lines(ofp,meta1,0,0,meta1->general->line_count,buf1); put_band_float_lines(ofp,meta1,1,0,meta1->general->line_count,buf2); put_band_float_lines(ofp,meta1,2,0,meta1->general->line_count,buf3); meta_write(meta1,outfile); } else if (mode == SENTINEL_DUAL) { asfPrintStatus("Creating colorized browse image from Sentinel dual-pol " "data\n"); if (strlen(tmpPath) > 0) { create_name(infile1,argv[5],".img"); create_name(infile2,argv[6],".img"); create_name(outfile,argv[7],".tif"); } else { create_name(infile1,argv[3],".img"); create_name(infile2,argv[4],".img"); create_name(outfile,argv[5],".tif"); } // Create temporary directory char tmpDir[1024]; if (strlen(tmpPath) > 0) sprintf(tmpDir, "%s%cbrowse-", tmpPath, DIR_SEPARATOR); else strcpy(tmpDir, "browse-"); strcat(tmpDir, time_stamp_dir()); create_clean_dir(tmpDir); asfPrintStatus("Temp dir is: %s\n", tmpDir); // Calculate ratio image char tmpRatio[512], tmpRed[512], tmpGreen[512], tmpBlue[512], tmpIn[512]; char *inFiles[2]; inFiles[0] = (char *) MALLOC(sizeof(char)*255); inFiles[1] = (char *) MALLOC(sizeof(char)*255); strcpy(inFiles[0], infile1); strcpy(inFiles[1], infile2); sprintf(tmpRatio, "%s%cdiv.img", tmpDir, DIR_SEPARATOR); raster_calc(tmpRatio, "a/b", 2, inFiles); // Resample all three bands and scale to byte meta_parameters *metaIn = meta_read(tmpRatio); double scaleFactor = 1.0/(scale/metaIn->general->x_pixel_size); meta_free(metaIn); sprintf(tmpIn, "%s%cred.img", tmpDir, DIR_SEPARATOR); resample(infile1, tmpIn, scaleFactor, scaleFactor); sprintf(tmpRed, "%s%cred_byte.img", tmpDir, DIR_SEPARATOR); floats_to_bytes_from_file(tmpIn, tmpRed, NULL, -40.0, SIGMA); sprintf(tmpIn, "%s%cgreen.img", tmpDir, DIR_SEPARATOR); resample(infile2, tmpIn, scaleFactor, scaleFactor); sprintf(tmpGreen, "%s%cgreen_byte.img", tmpDir, DIR_SEPARATOR); floats_to_bytes_from_file(tmpIn, tmpGreen, NULL, -40.0, SIGMA); sprintf(tmpIn, "%s%cblue.img", tmpDir, DIR_SEPARATOR); resample(tmpRatio, tmpIn, scaleFactor, scaleFactor); sprintf(tmpBlue, "%s%cblue_byte.img", tmpDir, DIR_SEPARATOR); floats_to_bytes_from_file(tmpIn, tmpBlue, NULL, -40.0, SIGMA); // Layer stack the bands char tmpBrowse[512]; sprintf(tmpBrowse, "%s%cbrowse.img", tmpDir, DIR_SEPARATOR); FILE *fpOut = FOPEN(tmpBrowse, "w"); meta_parameters *metaOut = meta_read(tmpRed); metaOut->general->band_count = 3; metaIn = meta_read(tmpRed); int line_count = metaIn->general->line_count; int sample_count = metaIn->general->sample_count; float *buf = (float *) MALLOC(sizeof(float)*line_count*sample_count); FILE *fpIn = FOPEN(tmpBlue, "r"); get_float_lines(fpIn, metaIn, 0, line_count, buf); put_band_float_lines(fpOut, metaOut, 0, 0, line_count, buf); FCLOSE(fpIn); fpIn = FOPEN(tmpGreen, "r"); get_float_lines(fpIn, metaIn, 0, line_count, buf); put_band_float_lines(fpOut, metaOut, 1, 0, line_count, buf); FCLOSE(fpIn); fpIn = FOPEN(tmpRed, "r"); get_float_lines(fpIn, metaIn, 0, line_count, buf); put_band_float_lines(fpOut, metaOut, 2, 0, line_count, buf); FCLOSE(fpIn); FCLOSE(fpOut); FREE(buf); strcpy(metaOut->general->bands, "red,green,blue"); meta_write(metaOut, tmpBrowse); // Export to GeoTIFF char *band_names[3] = { "blue", "green", "red" }; asf_export_bands(GEOTIFF, NONE, TRUE, FALSE, FALSE, FALSE, FALSE, tmpBrowse, outfile, band_names, NULL, NULL); // Clean up asfPrintStatus("Removing temporary directory: %s\n", tmpDir); remove_dir(tmpDir); meta_free(metaIn); meta_free(metaOut); } else asfPrintError("Mode is not defined!\n"); asfPrintStatus("Done.\n"); exit(EXIT_SUCCESS); }
// Main program body. int main (int argc, char *argv[]) { int currArg = 1; int NUM_ARGS = 3; int dbFlag = FALSE; int wh_scaleFlag = FALSE; radiometry_t radiometry; char *inFile, *outFile, *radio; handle_license_and_version_args(argc, argv, ASF_NAME_STRING); asfSplashScreen(argc, argv); if (argc >= 2 && strmatches(argv[1],"-help","--help",NULL)) print_help(); if (argc<3) calibrate_usage(ASF_NAME_STRING); while (currArg < (argc-NUM_ARGS)) { char *key = argv[currArg++]; if (strmatches(key,"-help","--help",NULL)) { print_help(); // doesn't return } else if (strmatches(key,"-db","--db",NULL)) { dbFlag = TRUE; } else if (strmatches(key,"-wh_scale","--wh_scale",NULL)) { wh_scaleFlag = TRUE; } else if (strmatches(key,"-log","--log",NULL)) { CHECK_ARG(1); strcpy(logFile,GET_ARG(1)); fLog = FOPEN(logFile, "a"); logflag = TRUE; } else if (strmatches(key,"-quiet","--quiet","-q",NULL)) { quietflag = TRUE; } else { --currArg; break; } } if ((argc-currArg) < NUM_ARGS) { printf("Insufficient arguments. Expected %d, got %d.\n", NUM_ARGS, argc-currArg); calibrate_usage(argv[0]); } else if ((argc-currArg) > NUM_ARGS) { printf("Unknown argument: %s\n", argv[currArg]); calibrate_usage(argv[0]); } radio = argv[currArg]; inFile = argv[currArg+1]; outFile = argv[currArg+2]; if (strcmp_case(radio, "-GAMMA") == 0) { if (dbFlag) radiometry = r_GAMMA_DB; else radiometry = r_GAMMA; } else if (strcmp_case(radio, "-BETA") == 0) { if (dbFlag) radiometry = r_BETA_DB; else radiometry = r_BETA; } else if (strcmp_case(radio, "-SIGMA") == 0) { if (dbFlag) radiometry = r_SIGMA_DB; else radiometry = r_SIGMA; } else asfPrintError("Unknown radiometry (%s)\n", radio); int fail = asf_calibrate(inFile, outFile, radiometry, wh_scaleFlag); int ok = !fail; asfPrintStatus(ok ? "Done.\n" : "Failed.\n"); return ok ? EXIT_SUCCESS : EXIT_FAILURE; }