/* * Parse arguments. We want: * 0. (name of dexopt command -- ignored) * 1. "--zip" * 2. zip fd (input, read-only) * 3. cache fd (output, read-write, locked with flock) * 4. filename of zipfile being optimized (used for debug messages and * for comparing against BOOTCLASSPATH; does not need to be * accessible or even exist) * 5. dexopt flags * * The BOOTCLASSPATH environment variable is assumed to hold the correct * boot class path. If the filename provided appears in the boot class * path, the path will be truncated just before that entry (so that, if * you were to dexopt "core.jar", your bootclasspath would be empty). * * This does not try to normalize the boot class path name, so the * filename test won't catch you if you get creative. */ static int fromZip(int argc, char* const argv[]) { int result = -1; int zipFd, cacheFd; const char* zipName; char* bcpCopy = NULL; const char* dexoptFlags; if (argc != 6) { ALOGE("Wrong number of args for --zip (found %d)", argc); goto bail; } /* skip "--zip" */ argc--; argv++; GET_ARG(zipFd, strtol, "bad zip fd"); GET_ARG(cacheFd, strtol, "bad cache fd"); zipName = *++argv; --argc; dexoptFlags = *++argv; --argc; result = processZipFile(zipFd, cacheFd, zipName, dexoptFlags); bail: return result; }
//______________________________________________________________________________ // [] // Изменение параметров существующего языка. // [] void CGI_BX_Language_PutData (const char * inStr, const char * outStr, void ** ppData) { CGI_WRAPPER_START; AVOID_WARNING_ON_ARGS; // Переменные, необходимые для вызова проблемной функции: BX_Language_Args cgi_args; int cgi_result; // Записать нужные аргументы из строки inStr в структуру cgi_args: GET_ARG (objID); GET_ARG (OwnName); GET_ARG (Name); GET_ARG (Language); // Вызвать проблемную функцию: cgi_result = BX_Language_PutData (cgi_args); // Если функция отработала успешно, то упакуем требуемые выходные аргументы: if (cgi_result == CGI_OK) { // Выходных аргументов нет. } CGI_WRAPPER_END; }
static void get_command(char *line, char *com, char *arg1, char *arg2) { char *s; *com = *arg1 = *arg2 = '\0'; SKIP_SPACE(); GET_ARG(com); SKIP_SPACE(); GET_ARG(arg1); SKIP_SPACE(); GET_ARG(arg2); }
int main(int argc, char *argv[]) { char inDEMfile[255],outDEMfile[255],outAmpFile[255],inMetafile[255]; system("date"); printf("Program: reskew_dem\n\n"); /* parse commandline arguments */ logflag=FALSE; /* FIXME: WTF? */ currArg=1; while (currArg < (argc-NUM_ARGS)) { char *key = argv[currArg++]; if (strmatch(key,"-log")) { CHECK_ARG(1); strcpy(logFile,GET_ARG(1)); fLog = FOPEN(logFile, "a"); logflag = TRUE; } 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]); } strcpy(inMetafile, argv[currArg]); strcpy(inDEMfile, argv[currArg+1]); strcpy(outDEMfile,argv[currArg+2]); strcpy(outAmpFile,argv[currArg+3]); reskew_dem(inMetafile, inDEMfile, outDEMfile, outAmpFile, NULL, TRUE); 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; }
int main(int argc, char **argv) { char *unwrapped_phase, *phase_mask, *baseline, *seeds, *slant_amplitude; char *slant_coherence, *ground_elevation, *ground_elevation_error; char *ground_amplitude, *ground_coherence, slant_elevation[255]; char slant_elevation_error[255]; extern int currArg; /* pre-initialized to 1; like optind */ logflag=quietflag=0; /* parse command line */ while (currArg < (argc-10)) { char *key = argv[currArg++]; if (strmatch(key,"-log")) { CHECK_ARG(1) strcpy(logFile, GET_ARG(1)); fLog = FOPEN(logFile, "a"); logflag=1; } else if (strmatch(key,"-quiet")) { quietflag=1; } else { printf( "\n**Invalid option: %s\n",argv[currArg-1]); usage(argv[0]); } } if ((argc-currArg) < 10) { printf("Insufficient arguments.\n"); usage(argv[0]); } unwrapped_phase = argv[currArg++]; phase_mask = argv[currArg++]; baseline = argv[currArg++]; seeds = argv[currArg++]; sprintf(slant_elevation, "slant_ht"); sprintf(slant_elevation_error, "slant_ht_err"); slant_amplitude = argv[currArg++]; slant_coherence = argv[currArg++]; ground_elevation = argv[currArg++]; ground_elevation_error = argv[currArg++]; ground_amplitude = argv[currArg++]; ground_coherence = argv[currArg]; asfSplashScreen (argc, argv); if (!logflag) //sprintf(logFile, "tmp%d.log", (int)getpid()); strcpy(logFile, get_tmp_log_file("asf_elevation")); // Call library function that gets the work done asf_elevation(unwrapped_phase, phase_mask, baseline, seeds, slant_elevation, slant_elevation_error, slant_amplitude, slant_coherence, ground_elevation, ground_elevation_error, ground_amplitude, ground_coherence); return(0); }
// 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 ActionSkBuff filter_generic(arguments_t args, SkBuff b) { predicate_t pred_ = GET_ARG(predicate_t, args); if (EVAL_PREDICATE(pred_, b)) return Pass(b); return Drop(b); }
static Action_SkBuff inv(arguments_t args, SkBuff b) { function_t expr = GET_ARG(function_t, args); SkBuff nb = EVAL_FUNCTION(expr, b).value; if (!nb.skb || is_drop(PFQ_CB(nb.skb)->monad->fanout)) return Copy(nb); return Drop(nb); }
// 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; }
//______________________________________________________________________________ // [] // BX_EnumObject_Delete () // [] void CGI_BX_EnumObject_Delete (const char * inStr, const char * outStr, void ** ppData) { CGI_WRAPPER_START; AVOID_WARNING_ON_ARGS; // Переменные, необходимые для вызова проблемной функции: BX_EnumObject_Args cgi_args; int cgi_result; // Записать нужные аргументы из строки inStr в структуру cgi_args: GET_ARG (ObjType); GET_ARG (objID); // Вызвать проблемную функцию: cgi_result = BX_EnumObject_Delete (cgi_args); // Если функция отработала успешно, то упакуем требуемые выходные аргументы: if (cgi_result == CGI_OK) { PACK_ARG (objID); } CGI_WRAPPER_END; }
// 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; }
TERM bpx_get_arg(BPLONG i, TERM t) { BPLONG n, j; XDEREF(t); switch (XTAG(t)) { case STR: n = GET_ARITY(GET_STR_SYM_REC(t)); j = 0; break; case LST: n = 2; j = 1; break; default: bpx_raise("compound expected"); } if (i < 1 || i > n) { bpx_raise("bad argument index"); } return GET_ARG(t, i - j); }
int main(int argc, char *argv[]) { char *baseFile; meta_parameters *meta; baseline base; int wid, len, /* Width and Length of input scene */ ss, sl; /* Offsets of input scene in original */ int x,y; double xScale,yScale; float percent=5.0; FILE *fin, *fout; char szInPhase[255], szInAmp[255], szOutPhase[255], szOutAmp[255]; float *data; double *sflat,*cflat; double derampDirection=1.0;/*1.0=forward deramping. -1.0=backward deramping.*/ logflag=0; /* process command line args */ currArg=1; /* from cla.h in asf.h */ /* optional args */ while (currArg < (argc-3)) { char *key = argv[currArg++]; if (strmatch(key,"-log")) { CHECK_ARG(1); strcpy(logFile,GET_ARG(1)); fLog = FOPEN(logFile, "a"); logflag=1; } else if (strmatch(key,"-backward")) { derampDirection = -1.0; } else {printf("**Invalid option: %s\n",argv[currArg-1]); usage(argv[0]);} } if ((argc-currArg) < 3) {printf("Insufficient arguments.\n"); usage(argv[0]);} /* required args */ create_name(szInAmp, argv[currArg], "_amp.img"); create_name(szInPhase, argv[currArg], "_phase.img"); baseFile = argv[currArg+1]; asfSplashScreen(argc, argv); /* Get input scene size and windowing info, check validity */ meta = meta_read(szInPhase); wid = meta->general->sample_count; len = meta->general->line_count; ss = meta->general->start_sample - 1; sl = meta->general->start_line - 1; xScale = meta->sar->sample_increment; yScale = meta->sar->line_increment; create_name(szOutAmp,argv[currArg+2],"_amp.img"); meta_write(meta, szOutAmp); create_name(szOutPhase,argv[currArg+2],"_phase.img"); meta_write(meta, szOutPhase); /*Link over ".amp" file, if it exists.*/ if (fileExists(szInAmp)&&!fileExists(szOutAmp)) { char command[1024]; sprintf(command,"ln -s %s %s\n", szInAmp, szOutAmp); system(command); } /* buffer mallocs, read data file */ data = (float *)MALLOC(sizeof(float)*wid); sflat = (double *)MALLOC(sizeof(double)*wid); cflat = (double *)MALLOC(sizeof(double)*wid); fin = fopenImage(szInPhase,"rb"); fout = fopenImage(szOutPhase,"wb"); /* read in CEOS parameters & convert to meters */ base=read_baseline(baseFile); /* calculate slant ranges and look angles - Ian's thesis eqn 3.10 */ for (x = 0; x < wid; x++) { double flat=meta_flat(meta,0.0,x*xScale+ss); sflat[x]=sin(flat); cflat[x]=cos(flat); } /* Deramp 'data' array */ /* printf("\n starting in-place deramp of input data \n\n");*/ for (y = 0; y < len; y++) { double Bn_y,Bp_y; double twok=derampDirection*2.0*meta_get_k(meta); meta_interp_baseline(meta,base,y*(int)yScale+sl,&Bn_y,&Bp_y); /* read in the next row of data */ get_float_line(fin, meta, y, data); /* calculate flat-earth range phase term & remove it */ for (x = 0; x < wid; x++) { double d=data[x]; if (d!=0.0) /*Ignore points which didn't phase unwrap.*/ d -= twok*(Bp_y*cflat[x]-Bn_y*sflat[x]); /*Was: d-=ceos_flat_phase(ceos,base,x,y);*/ data[x]=d; } /* write out this row of data */ put_float_line(fout, meta, y, data); if (y*100/len==percent) { printf(" Completed %3.0f percent\n", percent); percent+=5.0; } } /* printf("\nDone with deramp\n\n");*/ /* save and scram */ FCLOSE(fin); FCLOSE(fout); FREE(data); FREE(sflat);FREE(cflat); printf(" Completed 100 percent\n\n"); if (logflag) { sprintf(logbuf, " Wrote %lld bytes of data\n\n", (long long)(len*wid*4)); printLog(logbuf); } return 0; }
int main(int argc, char **argv) { double min, max; /* Minimum & maximum sample values */ double sum_of_samples=0.0; /* Sum of all samples accounted for */ double sum_of_squared_samples=0.0; /* Sum of all squared samples accounted for*/ double trim_fraction; /* Fraction used to trim the histogram */ int ii; /* Loop index */ long samples_counted=0; /* Number of all samples accounted for */ float *data_line; /* Buffer for a line of samples */ long line, sample; /* Line and sample indices */ long num_lines, num_samples; /* Number of lines and samples */ int percent_complete=0; /* Percent of data sweep completed */ int overmeta_flag=FALSE; /* If TRUE write over current .meta file */ int overstat_flag=FALSE; /* If TRUE write over current .stat file */ int nometa_flag=FALSE; /* If TRUE do not write .meta file */ int nostat_flag=FALSE; /* If TRUE do not write .stat file */ int mask_flag=FALSE; /* TRUE if user specifies a mask value */ int trim_flag=FALSE; /* If TRUE trim histogram */ double mask=NAN; /* Value to ignore while caculating stats*/ char meta_name[261]; /* Meta file name */ meta_parameters *meta; /* SAR meta data structure */ char sar_name[256]; /* SAR file name WITH extention */ FILE *sar_file; /* SAR data file pointer to take stats on*/ stat_parameters *stats; /* Statistics structure */ char stat_name[261]; /* Stats file name */ extern int currArg; /* Pre-initialized to 1 */ /* We initialize these to a magic number for checking. */ long start_line = -1; /* Window starting line. */ long start_sample = -1; /* Window starting sample. */ long window_height = -1; /* Window height in lines. */ long window_width = -1; /* Window width in samples. */ /* parse command line */ handle_license_and_version_args(argc, argv, "stats"); logflag=quietflag=FALSE; while (currArg < (argc-1)) { char *key = argv[currArg++]; if (strmatch(key,"-quiet")) { quietflag=TRUE; } else if (strmatch(key,"-log")) { CHECK_ARG(1); strcpy(logFile,GET_ARG(1)); fLog = FOPEN(logFile, "a"); logflag=TRUE; } else if (strmatch(key,"-mask")) { CHECK_ARG(1); mask = atof(GET_ARG(1)); mask_flag=TRUE; } else if (strmatch(key,"-overmeta")) { overmeta_flag=TRUE; } else if (strmatch(key,"-overstat")) { overstat_flag=TRUE; } else if (strmatch(key,"-nometa")) { nometa_flag=TRUE; } else if (strmatch(key,"-nostat")) { nostat_flag=TRUE; } else if (strmatch(key,"-startline")) { CHECK_ARG(1); nometa_flag=TRUE; /* Implied. */ start_line = atol(GET_ARG(1)); if ( start_line < 0 ) { printf("error: -startline argument must be greater than or equal to zero\n"); usage(argv[0]); } } else if (strmatch(key,"-startsample")) { CHECK_ARG(1); nometa_flag=TRUE; /* Implied. */ start_sample = atol(GET_ARG(1)); if ( start_sample < 0 ) { printf("error: -startsample argument must be greater than or equal to zero\n"); usage(argv[0]); } } else if (strmatch(key,"-width")) { CHECK_ARG(1); nometa_flag=TRUE; /* Implied. */ window_width = atol(GET_ARG(1)); if ( window_width < 0 ) { printf("error: -width argument must be greater than or equal to zero\n"); usage(argv[0]); } } else if (strmatch(key,"-height")) { CHECK_ARG(1); nometa_flag=TRUE; /* Implied. */ window_height = atol(GET_ARG(1)); if ( window_height < 0 ) { printf("error: -height argument must be greater than or equal to zero\n"); usage(argv[0]); } } else if (strmatch(key,"-trim")) { CHECK_ARG(1); trim_flag=TRUE; /* Implied. */ trim_fraction = atof(GET_ARG(1)); } else {printf( "\n**Invalid option: %s\n",argv[currArg-1]); usage(argv[0]);} } if ((argc-currArg)<1) {printf("Insufficient arguments.\n"); usage(argv[0]);} strcpy (sar_name, argv[currArg]); char *ext = findExt(sar_name); if (ext == NULL || strcmp("IMG", uc(ext)) != 0) { strcpy(sar_name, appendExt(sar_name, ".img")); } create_name(meta_name, sar_name, ".meta"); create_name(stat_name, sar_name, ".stat"); printf("\nProgram: stats\n\n"); if (logflag) { fprintf(fLog, "\nProgram: stats\n\n"); } printf("\nCalculating statistics for %s\n\n", sar_name); if (logflag) { fprintf(fLog,"\nCalculating statistics for %s\n\n", sar_name); } meta = meta_read(meta_name); num_lines = meta->general->line_count; num_samples = meta->general->sample_count; if ( start_line == -1 ) start_line = 0; if ( start_line > num_lines ) { printf("error: -startline argument is larger than index of last line in image\n"); exit(EXIT_FAILURE); } if ( start_sample == -1 ) start_sample = 0; if ( start_sample > num_samples ) { printf("error: -startsample argument is larger than index of last sample in image\n"); exit(EXIT_FAILURE); } if ( window_height == -1 ) window_height = num_lines; if ( start_line + window_height > num_lines ) { printf("warning: window specified with -startline, -height options doesn't fit in image\n"); } if ( window_width == -1 ) window_width = num_samples; if ( start_sample + window_width > num_samples ) { printf("warning: window specified with -startsample, -width options doesn't fit in image\n"); } /* Make sure we don't over write any files that we don't want to */ if (meta->stats && !overmeta_flag && !nometa_flag) { printf(" ** The meta file already has a populated statistics structure.\n" " ** If you want to run this program and replace that structure,\n" " ** then use the -overmeta option to do so. If you want to run\n" " ** this program, but don't want to replace the structure, use\n" " ** the -nometa option.\n"); if (logflag) { fprintf(fLog, " ** The meta file already has a populated statistics structure.\n" " ** If you want to run this program and replace that structure,\n" " ** then use the -overmeta option to do so. If you want to run\n" " ** this program, but don't want to replace the structure, use\n" " ** the -nometa option.\n"); } exit(EXIT_FAILURE); } if (fileExists(stat_name) && !overstat_flag && !nostat_flag) { printf(" ** The file, %s, already exists. If you want to\n" " ** overwrite it, then use the -overstat option to do so.\n" " ** If you want to run the progam but don't want to write\n" " ** over the current file, then use the -nostat option.\n", stat_name); if (logflag) { fprintf(fLog, " ** The file, %s, already exists. If you want to\n" " ** overwrite it, then use the -overstat option to do so.\n" " ** If you want to run the progam but don't want to write\n" " ** over the current file, then use the -nostat option.\n", stat_name); } exit(EXIT_FAILURE); } /* Let user know the window in which the stats will be taken */ if ((start_line!=0) || (start_sample!=0) || (window_height!=num_lines) || (window_width!=num_samples)) { if (!quietflag) { printf("Taking statistics on a window with upper left corner (%ld,%ld)\n" " and lower right corner (%ld,%ld)\n", start_sample, start_line, window_width+start_sample, window_height+start_line); } if (logflag && !quietflag) { fprintf(fLog, "Taking statistics on a window with upper left corner (%ld,%ld)\n" " and lower right corner (%ld,%ld)\n", start_sample, start_line, window_width+start_sample, window_height+start_line); } } /* Allocate line buffer */ data_line = (float *)MALLOC(sizeof(float)*num_samples); if (meta->stats) FREE(meta->stats); if (meta->general->band_count <= 0) { printf(" ** Band count in the existing data is missing or less than zero.\nDefaulting to one band.\n"); if (logflag) { fprintf(fLog, " ** Band count in the existing data is missing or less than zero.\nDefaulting to one band.\n"); } meta->general->band_count = 1; } meta->stats = meta_statistics_init(meta->general->band_count); if (!meta->stats) { printf(" ** Cannot allocate memory for statistics data structures.\n"); if (logflag) { fprintf(fLog, " ** Cannot allocate memory for statistics data structures.\n"); } exit(EXIT_FAILURE); } stats = (stat_parameters *)MALLOC(sizeof(stat_parameters) * meta->stats->band_count); if (!stats) { printf(" ** Cannot allocate memory for statistics data structures.\n"); if (logflag) { fprintf(fLog, " ** Cannot allocate memory for statistics data structures.\n"); } exit(EXIT_FAILURE); } int band; long band_offset; for (band = 0; band < meta->stats->band_count; band++) { /* Find min, max, and mean values */ if (!quietflag) printf("\n"); if (logflag && !quietflag) fprintf(fLog,"\n"); min = 100000000; max = -100000000; sum_of_samples=0.0; sum_of_squared_samples=0.0; percent_complete=0; band_offset = band * meta->general->line_count; sar_file = FOPEN(sar_name, "r"); for (line=start_line+band_offset; line<start_line+window_height+band_offset; line++) { if (!quietflag) asfPercentMeter((float)(line-start_line-band_offset)/(float)(window_height-start_line)); get_float_line(sar_file, meta, line, data_line); for (sample=start_sample; sample<start_sample+window_width; sample++) { if ( mask_flag && FLOAT_EQUIVALENT(data_line[sample],mask) ) continue; if (data_line[sample] < min) min=data_line[sample]; if (data_line[sample] > max) max=data_line[sample]; sum_of_samples += data_line[sample]; sum_of_squared_samples += SQR(data_line[sample]); samples_counted++; } } if (!quietflag) asfPercentMeter(1.0); // if (!quietflag) printf("\rFirst data sweep: 100%% complete.\n"); FCLOSE(sar_file); stats[band].min = min; stats[band].max = max; stats[band].upper_left_line = start_line; stats[band].upper_left_samp = start_sample; stats[band].lower_right_line = start_line + window_height; stats[band].lower_right_samp = start_sample + window_width; stats[band].mask = mask; stats[band] = calc_hist(stats[band], sar_name, band, meta, sum_of_samples, samples_counted, mask_flag); /* Remove outliers and trim the histogram by resetting the minimum and and maximum */ if (trim_flag) { register int sum=0, num_pixels, minDex=0, maxDex=255; double overshoot, width; num_pixels = (int)(samples_counted*trim_fraction); minDex = 0; while (sum < num_pixels) sum += stats[band].histogram[minDex++]; if (minDex-1>=0) overshoot = (double)(num_pixels-sum)/stats[band].histogram[minDex-1]; else overshoot = 0; stats[band].min = (minDex-overshoot-stats[band].offset)/stats[band].slope; sum=0; while (sum < num_pixels) sum += stats[band].histogram[maxDex--]; if (maxDex+1<256) overshoot = (double)(num_pixels-sum)/stats[band].histogram[maxDex+1]; else overshoot = 0; stats[band].max = (maxDex+1+overshoot-stats[band].offset)/stats[band].slope; /* Widening the range for better visual effect */ width = (stats[band].max-stats[band].min)*(1/(1.0-2*trim_fraction)-1); stats[band].min -= width/2; stats[band].max += width/2; /* Couple useful corrections borrowed from SARview */ if ((stats[band].max-stats[band].min) < 0.01*(max-min)) { stats[band].max = max; stats[band].min = min; } if (min == 0.0) stats[band].min=0.0; if (stats[band].min == stats[band].max) stats[band].max = stats[band].min + MICRON; stats[band].slope = 255.0/(stats[band].max-stats[band].min); stats[band].offset = -stats[band].slope*stats[band].min; stats[band] = calc_hist(stats[band], sar_name, band, meta, sum_of_samples, samples_counted, mask_flag); } } if(data_line)FREE(data_line); /* Populate meta->stats structure */ char **band_names = NULL; if (meta_is_valid_string(meta->general->bands) && strlen(meta->general->bands) && meta->general->band_count > 0) { band_names = extract_band_names(meta->general->bands, meta->general->band_count); } else { if (meta->general->band_count <= 0) meta->general->band_count = 1; band_names = (char **) MALLOC (meta->general->band_count * sizeof(char *)); int i; for (i=0; i<meta->general->band_count; i++) { band_names[i] = (char *) MALLOC (64 * sizeof(char)); sprintf(band_names[i], "%02d", i); } } int band_no; for (band_no = 0; band_no < meta->stats->band_count; band_no++) { strcpy(meta->stats->band_stats[band_no].band_id, band_names[band_no]); meta->stats->band_stats[band_no].min = stats[band_no].min; meta->stats->band_stats[band_no].max = stats[band_no].max; meta->stats->band_stats[band_no].mean = stats[band_no].mean; meta->stats->band_stats[band_no].rmse = stats[band_no].rmse; meta->stats->band_stats[band_no].std_deviation = stats[band_no].std_deviation; meta->stats->band_stats[band_no].mask = stats[band_no].mask; } if (band_names) { int i; for (i=0; i<meta->general->band_count; i++) { if (band_names[i]) FREE (band_names[i]); } FREE(band_names); } /* Print findings to the screen (and log file if applicable)*/ if (!quietflag) { printf("\n"); printf("Statistics found:\n"); if (mask_flag) { printf("Used mask %-16.11g\n",mask); } printf("Number of bands: %d\n", meta->stats->band_count); for (band=0; band<meta->stats->band_count; band++) { printf("\n\nBand name = \"%s\"\n", meta->stats->band_stats[band].band_id); printf("Minimum = %-16.11g\n",stats[band].min); printf("Maximum = %-16.11g\n",stats[band].max); printf("Mean = %-16.11g\n",stats[band].mean); printf("Root mean squared error = %-16.11g\n", stats[band].rmse); printf("Standard deviation = %-16.11g\n", stats[band].std_deviation); printf("\n"); printf("Data fit to [0..255] using equation: byte = %g * sample + %g\n", stats[band].slope, stats[band].offset); if (trim_flag) printf("Trimming fraction = %.3g\n", trim_fraction); printf("\n"); printf("Histogram:\n"); for (ii=0; ii<256; ii++) { if (ii%8 == 0) { printf("%s%3i-%3i:", (ii==0) ? "" : "\n", ii, ii+7); } printf(" %8i", stats[band].histogram[ii]); } printf("\n"); } } if (logflag && !quietflag) { fprintf(fLog,"Statistics found:\n"); if (mask_flag) { fprintf(fLog,"Used mask %-16.11g\n",mask); } fprintf(fLog,"Number of bands: %d\n", meta->stats->band_count); for (band=0; band<meta->stats->band_count; band++) { fprintf(fLog,"\n\nBand name = \"%s\"\n", meta->stats->band_stats[band].band_id); fprintf(fLog,"Minimum = %-16.11g\n",stats[band].min); fprintf(fLog,"Maximum = %-16.11g\n",stats[band].max); fprintf(fLog,"Mean = %-16.11g\n",stats[band].mean); fprintf(fLog,"Root mean squared error = %-16.11g\n", stats[band].rmse); fprintf(fLog,"Standard deviation = %-16.11g\n", stats[band].std_deviation); fprintf(fLog,"\n"); fprintf(fLog,"Data fit to [0..255] using equation: byte = %g * sample + %g\n", stats[band].slope, stats[band].offset); if (trim_flag) fprintf(fLog,"Trimming fraction = %.3g\n", trim_fraction); fprintf(fLog,"\n"); fprintf(fLog,"Histogram:\n"); for (ii=0; ii<256; ii++) { if (ii%8 == 0) { fprintf(fLog,"%s%3i-%3i:", (ii==0) ? "" : "\n", ii, ii+7); } fprintf(fLog," %8i", stats[band].histogram[ii]); } fprintf(fLog,"\n"); } } /* Write out .meta and .stat files */ if (!nometa_flag) meta_write(meta, meta_name); if (!nostat_flag) stat_write(stats, stat_name, meta->stats->band_count); /* Free the metadata structure */ meta_free(meta); /* Report */ if (!quietflag) { printf("\n"); printf("Statistics taken on image file %s.\n",sar_name); if (!nometa_flag) printf("Statistics written to the stats block in %s.\n", meta_name); if (!nostat_flag) printf("Statistics plus histogram written to %s.\n", stat_name); printf("\n"); } if (logflag && !quietflag) { fprintf(fLog,"\n"); fprintf(fLog,"Statistics taken on image file '%s'\n",sar_name); if (!nometa_flag) fprintf(fLog,"Statistics written to the stats block in %s\n", meta_name); if (!nostat_flag) fprintf(fLog,"Statistics plus histogram written to %s\n", stat_name); fprintf(fLog,"\n"); } if (fLog) FCLOSE(fLog); return 0; }
static int setup_touch_txt() { int pos, i, sdid, t; static char filename[256]; static char pakname[256]; char *buf, *command, *value; size_t size; ArgList arglist; char argbuf[MAX_ARG_LEN + 1] = ""; float w = nativeWidth; float h = nativeHeight; float hh = w * 480 / 800; SDL_Surface *ts; char *pngb; size_t pngs; getPakName(pakname, -1); sprintf(filename, "/mnt/sdcard/OpenBOR/Saves/%s", pakname); dirExists(filename, 1); sprintf(filename, "/mnt/sdcard/OpenBOR/Saves/%s/touch.txt", pakname); // Read file if( buffer_pakfile(filename, &buf, &size) != 1 && buffer_pakfile("data/touch.txt", &buf, &size) != 1 && buffer_pakfile("/mnt/sdcard/OpenBOR/Saves/touch.txt", &buf, &size) != 1) { return 0; } // Now interpret the contents of buf line by line pos = 0; while(pos < size) { if(ParseArgs(&arglist, buf + pos, argbuf)) { command = GET_ARG(0); if(command && command[0]) { if(stricmp(command, "button") == 0) { sdid = translate_SDID(GET_ARG(1)); if(sdid >= 0) { bx[sdid] = GET_FLOAT_ARG(2) * hh; by[sdid] = GET_FLOAT_ARG(3) * hh; br[sdid] = GET_FLOAT_ARG(4) * hh; t = GET_INT_ARG(5); /* corners: 0 1 3 2 */ if(t == 1 || t == 2) { bx[sdid] = w - bx[sdid]; } if(t == 2 || t == 3) { by[sdid] = h - by[sdid]; } } } else if(stricmp(command, "texture") == 0) { if(buffer_pakfile(GET_ARG(1), &pngb, &pngs)) { ts = pngToSurface(pngb); if(!ts || !(buttons = SDL_CreateTextureFromSurface(renderer, ts))) { printf("error: %s\n", SDL_GetError()); } if(ts) { SDL_FreeSurface(ts); } if(pngb) { free(pngb); } } } else if(stricmp(command, "screendocking") == 0) // change screen position to avoid buttons { screendocking = 0; for(i = 1; ; i++) { value = GET_ARG(i); if(!value || !value[0]) { break; } if(stricmp(value, "left") == 0) { screendocking |= DOCKLEFT; } else if(stricmp(value, "right") == 0) { screendocking |= DOCKRIGHT; } else if(stricmp(value, "top") == 0) { screendocking |= DOCKTOP; } else if(stricmp(value, "bottom") == 0) { screendocking |= DOCKBOTTOM; } else { screendocking = GET_INT_ARG(i); } } } } } // Go to next line pos += getNewLineStart(buf + pos); } if(buf != NULL) { free(buf); buf = NULL; } return 1; }
/* * Parse arguments for an "old-style" invocation directly from the VM. * * Here's what we want: * 0. (name of dexopt command -- ignored) * 1. "--dex" * 2. DALVIK_VM_BUILD value, as a sanity check * 3. file descriptor, locked with flock, for DEX file being optimized * 4. DEX offset within file * 5. DEX length * 6. filename of file being optimized (for debug messages only) * 7. modification date of source (goes into dependency section) * 8. CRC of source (goes into dependency section) * 9. flags (optimization level, isBootstrap) * 10. bootclasspath entry #1 * 11. bootclasspath entry #2 * ... * * dvmOptimizeDexFile() in dalvik/vm/analysis/DexOptimize.c builds the * argument list and calls this executable. * * The bootclasspath entries become the dependencies for this DEX file. * * The open file descriptor MUST NOT be for one of the bootclasspath files. * The parent has the descriptor locked, and we'll try to lock it again as * part of processing the bootclasspath. (We can catch this and return * an error by comparing filenames or by opening the bootclasspath files * and stat()ing them for inode numbers). */ static int fromDex(int argc, char* const argv[]) { int result = -1; bool vmStarted = false; char* bootClassPath = NULL; int fd, flags, vmBuildVersion; long offset, length; const char* debugFileName; u4 crc, modWhen; char* endp; bool onlyOptVerifiedDex = false; DexClassVerifyMode verifyMode; DexOptimizerMode dexOptMode; if (argc < 10) { /* don't have all mandatory args */ ALOGE("Not enough arguments for --dex (found %d)", argc); goto bail; } /* skip "--dex" */ argc--; argv++; /* * Extract the args. */ GET_ARG(vmBuildVersion, strtol, "bad vm build"); if (vmBuildVersion != DALVIK_VM_BUILD) { ALOGE("DexOpt: build rev does not match VM: %d vs %d", vmBuildVersion, DALVIK_VM_BUILD); goto bail; } GET_ARG(fd, strtol, "bad fd"); GET_ARG(offset, strtol, "bad offset"); GET_ARG(length, strtol, "bad length"); debugFileName = *++argv; --argc; GET_ARG(modWhen, strtoul, "bad modWhen"); GET_ARG(crc, strtoul, "bad crc"); GET_ARG(flags, strtol, "bad flags"); ALOGV("Args: fd=%d off=%ld len=%ld name='%s' mod=%#x crc=%#x flg=%d (argc=%d)", fd, offset, length, debugFileName, modWhen, crc, flags, argc); assert(argc > 0); if (--argc == 0) { bootClassPath = strdup(""); } else { int i, bcpLen; char* const* argp; char* cp; bcpLen = 0; for (i = 0, argp = argv; i < argc; i++) { ++argp; ALOGV("DEP: '%s'", *argp); bcpLen += strlen(*argp) + 1; } cp = bootClassPath = (char*) malloc(bcpLen +1); for (i = 0, argp = argv; i < argc; i++) { int strLen; ++argp; strLen = strlen(*argp); if (i != 0) *cp++ = ':'; memcpy(cp, *argp, strLen); cp += strLen; } *cp = '\0'; assert((int) strlen(bootClassPath) == bcpLen-1); } ALOGV(" bootclasspath is '%s'", bootClassPath); /* start the VM partway */ /* ugh -- upgrade these to a bit field if they get any more complex */ if ((flags & DEXOPT_VERIFY_ENABLED) != 0) { if ((flags & DEXOPT_VERIFY_ALL) != 0) verifyMode = VERIFY_MODE_ALL; else verifyMode = VERIFY_MODE_REMOTE; } else { verifyMode = VERIFY_MODE_NONE; } if ((flags & DEXOPT_OPT_ENABLED) != 0) { if ((flags & DEXOPT_OPT_ALL) != 0) dexOptMode = OPTIMIZE_MODE_ALL; else dexOptMode = OPTIMIZE_MODE_VERIFIED; } else { dexOptMode = OPTIMIZE_MODE_NONE; } if (dvmPrepForDexOpt(bootClassPath, dexOptMode, verifyMode, flags) != 0) { ALOGE("VM init failed"); goto bail; } vmStarted = true; /* do the optimization */ if (!dvmContinueOptimization(fd, offset, length, debugFileName, modWhen, crc, (flags & DEXOPT_IS_BOOTSTRAP) != 0)) { ALOGE("Optimization failed"); goto bail; } result = 0; bail: /* * In theory we should gracefully shut the VM down at this point. In * practice that only matters if we're checking for memory leaks with * valgrind -- simply exiting is much faster. * * As it turns out, the DEX optimizer plays a little fast and loose * with class loading. We load all of the classes from a partially- * formed DEX file, which is unmapped when we're done. If we want to * do clean shutdown here, perhaps for testing with valgrind, we need * to skip the munmap call there. */ #if 0 if (vmStarted) { ALOGI("DexOpt shutting down, result=%d", result); dvmShutdown(); } #endif free(bootClassPath); ALOGV("DexOpt command complete (result=%d)", result); return result; }
int main(int argc, char *argv[]) { int seedX=-1,seedY=-1; char szWrap[MAXNAME], szUnwrap[MAXNAME]; meta_parameters *meta; logflag=0; while (currArg < (argc-2)) { char *key = argv[currArg++]; if (strmatch(key,"-log")) { CHECK_ARG(1); strcpy(logFile,GET_ARG(1)); fLog = FOPEN(logFile, "a"); logflag = 1; } else if (strmatch(key,"-x")) { CHECK_ARG(1); sscanf(GET_ARG(1), "%d", &seedX); } else if (strmatch(key,"-y")) { CHECK_ARG(1); sscanf(GET_ARG(1), "%d", &seedY); } else { printf("\n ***Invalid option: %s\n", argv[currArg-1]); usage(argv[0]); } } create_name(szWrap, argv[currArg++], ".img"); create_name(szUnwrap, argv[currArg], ".img"); printf("%s\n",date_time_stamp()); printf("Program: escher\n\n"); if (logflag) { StartWatchLog(fLog); printLog("Program: escher\n\n"); } meta = meta_read(szWrap); wid = meta->general->sample_count; len = meta->general->line_count; if ((seedX==-1)&&(seedY==-1)) { seedX=wid/2; seedY=len/2; } meta_write(meta, szUnwrap); size = wid*len; mask = (Uchar *)calloc(size, sizeof(Uchar)); im = (Uchar *)calloc(size, sizeof(Uchar)); phase = (float *)MALLOC(sizeof(float)*size); /*coh = (float *)MALLOC(sizeof(float)*size);*/ /* perform steps*/ printf("\n begin unwrapping phase...\n"); loadWrappedPhase(szWrap); groundBorder(); makeMask(); doStats(" after makeMask():"); installCordon("cordon"); cutMask(); doStats(" after cutMask():"); #if DO_DEBUG_CHECKS saveMask((char *)mask, "test"); verifyCuts(); #endif checkSeed(&seedX, &seedY); integratePhase(seedX, seedY); doStats(" after integratePhase():"); finishUwp(); saveMask(mask, szUnwrap); saveUwp(szUnwrap); /* clean up & save*/ free(mask); free(im); free(phase); return(0); }
static ActionSkBuff filter_dst_port(arguments_t args, SkBuff b) { const u16 port = GET_ARG(u16, args); return has_dst_port(b, port) ? Pass(b) : Drop(b); }
static ActionSkBuff filter_l3_proto(arguments_t args, SkBuff b) { const u16 type = GET_ARG(u16, args); return is_l3_proto(b, type) ? Pass(b) : Drop(b); }
// 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; }
ER net_syslog (UINT prio, const char *format, ...) { LONGEST val; SYSLOG log; va_list ap; char padchar, *str; int ch, width, longflag, left, i, c; if (connected) { syscall(wai_sem(SEM_TCP_SYSLOG)); va_start(ap, format); while ((ch = *format ++) != '\0') { if (ch != '%') { /* 書式指定以外 */ put_char(TCP_CEPID, (char)ch); continue; } width = longflag = 0; padchar = ' '; if (ch == '-') { /* 左詰め */ format ++; left = -1; } else left = 1; if ((ch = *format ++) == '0') { /* 上位桁の 0 */ padchar = '0'; ch = *format ++; } while ('0' <= ch && ch <= '9') { /* 出力幅 */ width = width * 10 + ch - '0'; ch = *format ++; } while (ch == 'l') { /* long (long) の指定 */ longflag ++; ch = *format ++; } switch (ch) { case 'd': val = GET_ARG(ap, longflag); if (val >= 0) put_num(TCP_CEPID, val, 10, radhex, width * left, FALSE, padchar); else put_num(TCP_CEPID, -val, 10, radhex, width * left, TRUE, padchar); break; case 'u': val = GET_ARG(ap, longflag); put_num(TCP_CEPID, val, 10, radhex, width * left, FALSE, padchar); break; case 'x': val = GET_ARG(ap, longflag); put_num(TCP_CEPID, val, 16, radhex, width * left, FALSE, padchar); break; case 'X': val = GET_ARG(ap, longflag); put_num(TCP_CEPID, val, 16, radHEX, width * left, FALSE, padchar); break; case 'c': ch = va_arg(ap, int); put_char(TCP_CEPID, (char)ch); break; case 's': str = va_arg(ap, char*); while ((ch = *str ++) != '\0') { put_char(TCP_CEPID, (char)ch); width --; } while (width -- > 0) put_char(TCP_CEPID, ' '); break; case 'I': #ifdef SUPPORT_INET4 val = GET_ARG(ap, longflag); put_ipv4addr(TCP_CEPID, (ULONGEST *)val, width); #endif /* of #ifdef SUPPORT_INET4 */ #ifdef SUPPORT_INET6 str = va_arg(ap, char*); put_ipv6addr(TCP_CEPID, (T_IN6_ADDR *)str, width); #endif /* of #ifdef SUPPORT_INET6 */ break; case 'M': str = va_arg(ap, char*); put_macaddr(TCP_CEPID, str, width); break; case '%': put_char(TCP_CEPID, '%'); break; case '0': format --; break; default: break; } } va_end(ap); put_char(TCP_CEPID, '\n'); flush_snd_buff(TCP_CEPID); syscall(sig_sem(SEM_TCP_SYSLOG)); return E_OK; } else {
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 *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; }
// 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; }
int main(int argc, const char *argv[]) { int returnCode; struct FLContext *handle = NULL; FLStatus status; const char *error = NULL; uint8 byte = 0x10; uint8 buf[256]; bool flag; bool isNeroCapable, isCommCapable; uint32 fileLen; uint8 *buffer = NULL; uint32 numDevices, scanChain[16], i; const char *vp = NULL, *ivp = NULL, *queryPort = NULL, *portConfig = NULL, *progConfig = NULL, *dataFile = NULL; const char *const prog = argv[0]; printf("FPGALink \"C\" Example Copyright (C) 2011-2013 Chris McClelland\n\n"); argv++; argc--; while ( argc ) { if ( argv[0][0] != '-' ) { unexpected(prog, *argv); FAIL(1); } switch ( argv[0][1] ) { case 'h': usage(prog); FAIL(0); break; case 'q': GET_ARG("q", queryPort, 2); break; case 'd': GET_ARG("d", portConfig, 3); break; case 'v': GET_ARG("v", vp, 4); break; case 'i': GET_ARG("i", ivp, 5); break; case 'p': GET_ARG("p", progConfig, 6); break; case 'f': GET_ARG("f", dataFile, 7); break; default: invalid(prog, argv[0][1]); FAIL(8); } argv++; argc--; } if ( !vp ) { missing(prog, "v <VID:PID>"); FAIL(9); } status = flInitialise(0, &error); CHECK(10); printf("Attempting to open connection to FPGALink device %s...\n", vp); status = flOpen(vp, &handle, NULL); if ( status ) { if ( ivp ) { int count = 60; printf("Loading firmware into %s...\n", ivp); status = flLoadStandardFirmware(ivp, vp, &error); CHECK(11); printf("Awaiting renumeration"); flSleep(1000); do { printf("."); fflush(stdout); flSleep(100); status = flIsDeviceAvailable(vp, &flag, &error); CHECK(12); count--; } while ( !flag && count ); printf("\n"); if ( !flag ) { fprintf(stderr, "FPGALink device did not renumerate properly as %s\n", vp); FAIL(13); } printf("Attempting to open connection to FPGLink device %s again...\n", vp); status = flOpen(vp, &handle, &error); CHECK(14); } else { fprintf(stderr, "Could not open FPGALink device at %s and no initial VID:PID was supplied\n", vp); FAIL(15); } } if ( portConfig ) { printf("Configuring ports...\n"); status = flPortConfig(handle, portConfig, &error); CHECK(16); flSleep(100); } isNeroCapable = flIsNeroCapable(handle); isCommCapable = flIsCommCapable(handle); if ( queryPort ) { if ( isNeroCapable ) { status = jtagScanChain(handle, queryPort, &numDevices, scanChain, 16, &error); CHECK(17); if ( numDevices ) { printf("The FPGALink device at %s scanned its JTAG chain, yielding:\n", vp); for ( i = 0; i < numDevices; i++ ) { printf(" 0x%08X\n", scanChain[i]); } } else { printf("The FPGALink device at %s scanned its JTAG chain but did not find any attached devices\n", vp); } } else { fprintf(stderr, "JTAG chain scan requested but FPGALink device at %s does not support NeroJTAG\n", vp); FAIL(18); } } if ( progConfig ) { printf("Executing programming configuration \"%s\" on FPGALink device %s...\n", progConfig, vp); if ( isNeroCapable ) { status = flProgram(handle, progConfig, NULL, &error); CHECK(19); } else { fprintf(stderr, "Program operation requested but device at %s does not support NeroProg\n", vp); FAIL(20); } } if ( dataFile ) { if ( isCommCapable ) { printf("Enabling FIFO mode...\n"); status = flFifoMode(handle, true, &error); CHECK(21); printf("Zeroing registers 1 & 2...\n"); byte = 0x00; status = flWriteChannel(handle, 1000, 0x01, 1, &byte, &error); CHECK(22); status = flWriteChannel(handle, 1000, 0x02, 1, &byte, &error); CHECK(23); buffer = flLoadFile(dataFile, &fileLen); if ( buffer ) { uint16 checksum = 0x0000; uint32 i; for ( i = 0; i < fileLen; i++ ) { checksum += buffer[i]; } printf( "Writing %0.2f MiB (checksum 0x%04X) from %s to FPGALink device %s...\n", (double)fileLen/(1024*1024), checksum, dataFile, vp); status = flWriteChannel(handle, 30000, 0x00, fileLen, buffer, &error); CHECK(24); } else { fprintf(stderr, "Unable to load file %s!\n", dataFile); FAIL(25); } printf("Reading channel 0..."); status = flReadChannel(handle, 1000, 0x00, 1, buf, &error); CHECK(26); printf("got 0x%02X\n", buf[0]); printf("Reading channel 1..."); status = flReadChannel(handle, 1000, 0x01, 1, buf, &error); CHECK(27); printf("got 0x%02X\n", buf[0]); printf("Reading channel 2..."); status = flReadChannel(handle, 1000, 0x02, 1, buf, &error); CHECK(28); printf("got 0x%02X\n", buf[0]); } else { fprintf(stderr, "Data file load requested but device at %s does not support CommFPGA\n", vp); FAIL(29); } } returnCode = 0; cleanup: if ( error ) { fprintf(stderr, "%s\n", error); flFreeError(error); } flFreeFile(buffer); flClose(handle); return returnCode; }
static ActionSkBuff filter_l4_proto(arguments_t args, SkBuff b) { const u8 proto = GET_ARG(u8, args); return is_l4_proto(b, proto) ? Pass(b) : Drop(b); }
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); }
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); }
static int do_dump(int argc, char **argv) { struct btf *btf = NULL; __u32 root_type_ids[2]; int root_type_cnt = 0; __u32 btf_id = -1; const char *src; int fd = -1; int err; if (!REQ_ARGS(2)) { usage(); return -1; } src = GET_ARG(); if (is_prefix(src, "map")) { struct bpf_map_info info = {}; __u32 len = sizeof(info); if (!REQ_ARGS(2)) { usage(); return -1; } fd = map_parse_fd_and_info(&argc, &argv, &info, &len); if (fd < 0) return -1; btf_id = info.btf_id; if (argc && is_prefix(*argv, "key")) { root_type_ids[root_type_cnt++] = info.btf_key_type_id; NEXT_ARG(); } else if (argc && is_prefix(*argv, "value")) { root_type_ids[root_type_cnt++] = info.btf_value_type_id; NEXT_ARG(); } else if (argc && is_prefix(*argv, "all")) { NEXT_ARG(); } else if (argc && is_prefix(*argv, "kv")) { root_type_ids[root_type_cnt++] = info.btf_key_type_id; root_type_ids[root_type_cnt++] = info.btf_value_type_id; NEXT_ARG(); } else { root_type_ids[root_type_cnt++] = info.btf_key_type_id; root_type_ids[root_type_cnt++] = info.btf_value_type_id; } } else if (is_prefix(src, "prog")) { struct bpf_prog_info info = {}; __u32 len = sizeof(info); if (!REQ_ARGS(2)) { usage(); return -1; } fd = prog_parse_fd(&argc, &argv); if (fd < 0) return -1; err = bpf_obj_get_info_by_fd(fd, &info, &len); if (err) { p_err("can't get prog info: %s", strerror(errno)); goto done; } btf_id = info.btf_id; } else if (is_prefix(src, "id")) { char *endptr; btf_id = strtoul(*argv, &endptr, 0); if (*endptr) { p_err("can't parse %s as ID", **argv); return -1; } NEXT_ARG(); } else if (is_prefix(src, "file")) { err = btf_load_from_elf(*argv, &btf); if (err) goto done; NEXT_ARG(); } else { err = -1; p_err("unrecognized BTF source specifier: '%s'", src); goto done; } if (!btf) { err = btf__get_from_id(btf_id, &btf); if (err) { p_err("get btf by id (%u): %s", btf_id, strerror(err)); goto done; } if (!btf) { err = ENOENT; p_err("can't find btf with ID (%u)", btf_id); goto done; } } dump_btf_raw(btf, root_type_ids, root_type_cnt); done: close(fd); btf__free(btf); return err; }