예제 #1
0
void free_stages(struct stage *stage_ptr) {
  struct blkt *this_blkt, *next_blkt;

  if(stage_ptr != (struct stage *)NULL) {
    free_stages(stage_ptr->next_stage);
    this_blkt = stage_ptr->first_blkt;
    while(this_blkt != (struct blkt *)NULL) {
      next_blkt = this_blkt->next_blkt;
      switch (this_blkt->type) {
      case LAPLACE_PZ:
      case ANALOG_PZ:
      case IIR_PZ:
        free_pz(this_blkt);
        break;
      case FIR_SYM_1:
      case FIR_SYM_2:
      case FIR_ASYM:
        free_fir(this_blkt);
        break;
      case FIR_COEFFS:
        free_coeff(this_blkt);
        break;
      case LIST:
        free_list(this_blkt);
        break;
      case GENERIC:
        free_generic(this_blkt);
        break;
      case DECIMATION:
        free_deci(this_blkt);
        break;
      case GAIN:
        free_gain(this_blkt);
        break;
      case REFERENCE:
        free_ref(this_blkt);
        break;
      default:
        break;
      }
      this_blkt = next_blkt;
    }
    free(stage_ptr);
  }
}
예제 #2
0
파일: mkfir.c 프로젝트: tarzan0820/BIOMDI
int
main(int argc, char *argv[])
{
	FILE *out_fp = NULL;	// for the output file
	FILE *hdr_fp = NULL;	// the header input file
	FILE *fivr_fp = NULL;	// the finger image view record files
	int h_opt, f_opt, o_opt, to_opt, p_opt;
	struct finger_image_record *fir;
	struct stat sb;
	char ch;
	int ret, exit_code;
	int out_type;
	char pm;

	exit_code = EXIT_SUCCESS;
	h_opt = f_opt = o_opt = to_opt = p_opt = 0;
	out_type = FIR_STD_ANSI;
	while ((ch = getopt(argc, argv, "h:f:o:t:p")) != -1) {
		switch (ch) {
			case 'h':
				if ((hdr_fp = fopen(optarg, "r")) == NULL)
					OPEN_ERR_EXIT(optarg);
				h_opt = 1;
				break;
			case 'f':
				if ((fivr_fp = fopen(optarg, "r")) == NULL)
					OPEN_ERR_EXIT(optarg);
				f_opt = 1;
				break;
			case 't':
				pm = *(char *)optarg;
				switch (pm) {
					case 'o':
						out_type = fir_stdstr_to_type(
						    argv[optind]);
						if (out_type < 0)
							usage();
						optind++;
						to_opt++;
						break;
					default:
						usage();
						break;	/* not reached */
				}
				break;
			case 'o':
				if (stat(optarg, &sb) == 0)
					ERR_EXIT("File '%s' exists, remove it first.\n", optarg);

				if ((out_fp = fopen(optarg, "wb")) == NULL)
					OPEN_ERR_EXIT(optarg);
				o_opt = 1;
				break;
			case 'p':
				p_opt = 1;
				break;
			default:
				usage();
				break;
		}
	}
	if ((h_opt && f_opt && o_opt) == 0)
		usage();

	// Read in the file containing the header information
	if (new_fir(out_type, &fir) < 0)
		ALLOC_ERR_EXIT("Finger Image Record (general header)");

	if (load_hdr(hdr_fp, fir) != READ_OK) {
		exit_code = EXIT_FAILURE;
		ERR_OUT("Could not read header");
	}

	// Read in each Finger Image View Record add to the Finger Image Record
	do {
		ret = load_fivr(fivr_fp, fir);
		if (ret == READ_ERROR) {
			exit_code = EXIT_FAILURE;
			ERRP("Reading image view record");
			goto err_out;
		}
	} while (ret == READ_OK);

	fir->record_length = total_length;

	// Validate the Finger Image Record
	if (validate_fir(fir) != VALIDATE_OK) {
		fprintf(stdout, "Finger Image Record is invalid.\n");
	} else {
		fprintf(stdout, "Finger Image Record is valid.\n");
	}

	if (p_opt)
		print_fir(stdout, fir);

	// Write out the FIR
	if (write_fir(out_fp, fir) != WRITE_OK) {
		fprintf(stderr, "Error writing the Finger Image Record\n");
	} else {
		fprintf(stdout, "Finger Image Record written.\n");
	}

err_out:
	free_fir(fir);

	if (o_opt) 
		fclose(out_fp);
	if (h_opt) 
		fclose(hdr_fp);

	if (f_opt)
		fclose(fivr_fp);

	exit(exit_code);
}