main() { double ratio; #ifdef MSDOS setmode(0, O_BINARY); setmode(1, O_BINARY); #endif /* call dcmpr to decompress stdin to stdout */ fprintf(stderr, "d3101 - AHA 3101 DCLZ Decompression Demonstration, Copyright 1991.\n"); dcmpr(); if (ERROR_flag != 1) { ratio = out_byte_cnt ? (double) inp_byte_cnt / out_byte_cnt : 0.0; fprintf(stderr, "In, Out, Ratio: %10lu%10lu%12.3f\n", inp_byte_cnt, out_byte_cnt, ratio); } exit(0); }
// some modifications by Luigi Auriemma // note that the "license" at the beginning of the file is not much clear // anyway this code was got from BrainVISA / Anatomist int d3101(unsigned char *in, int insz, unsigned char *out, int outsz) { infile = in; infilel = in + insz; outfile = out; outfilel = out + outsz; inp_code_len = 9; inp_len = 0; inp_code_remainder = 0; inp_byte_cnt = 0; out_byte_cnt = 0; EOR_flag = 0; EOF_flag = 0; ERROR_flag = 0; FREEZE_flag = 0; dcmpr(); if(!outfile || ERROR_flag || FREEZE_flag) return(-1); return(outfile - out); }
int raw_read_current(struct rawfp *fp,struct rawdata *raw_data) { /* read raw data block from file */ int radar_parms_pat[]={1,2,2,17,4,2,2,14,4,4,2,4,0,0}; int i; int16 range; int j; int16 prev_range; int xcf_data; unsigned int stat; int16 num_byte; int32 rec_num=0; unsigned char *inbuf; unsigned char *inbuf_ptr; xcf_data = 0; prev_range = -1; inbuf=malloc(sizeof(struct rawdata)); /* zero out the raw data buffer */ memset(raw_data,0,sizeof(struct rawdata)); fp->rlen=0; do { if (ConvertReadShort(fp->rawfp,&num_byte) !=0) { free(inbuf); return -1; } fp->rlen+=num_byte; fp->ptr+=num_byte; num_byte = num_byte - 2; stat = read(fp->rawfp,inbuf,num_byte); if(stat != num_byte) { free(inbuf); return -1; } inbuf_ptr=inbuf; ConvertToInt(inbuf_ptr,&rec_num); } while (rec_num==0); inbuf_ptr = inbuf_ptr + 12; /* skip rec_num + rawwrite */ num_byte = num_byte - 12; /* zero out the raw data buffer */ /* copy radar_parms */ ConvertBlock(inbuf_ptr,radar_parms_pat); memcpy((void *) &(raw_data->PARMS),inbuf_ptr,sizeof(struct radar_parms)); inbuf_ptr = inbuf_ptr + sizeof(struct radar_parms); num_byte = num_byte - sizeof(struct radar_parms); /* copy the pulse pattern */ for (i=0;i<raw_data->PARMS.MPPUL;i++) { ConvertToShort(inbuf_ptr,&raw_data->PULSE_PATTERN[i]); inbuf_ptr+=sizeof(int16); num_byte-=sizeof(int16); } /* copy the lag table */ for(j=0;j < 2; ++j) for(i=0; i < raw_data->PARMS.MPLGS; ++i) { ConvertToShort(inbuf_ptr,&raw_data->LAG_TABLE[j][i]); inbuf_ptr = inbuf_ptr + sizeof(int16); num_byte = num_byte - sizeof(int16); } /* copy comment buffer */ memcpy(raw_data->COMBF,inbuf_ptr,ORIG_COMBF_SIZE); inbuf_ptr = inbuf_ptr + ORIG_COMBF_SIZE; num_byte = num_byte - ORIG_COMBF_SIZE; /* decompress and copy the lag-0 powers */ for(i=0 ; i < raw_data->PARMS.NRANG ; ++i) { raw_data->pwr0[i] = dcmpr(inbuf_ptr); inbuf_ptr = inbuf_ptr + sizeof(int16); num_byte = num_byte - sizeof(int16); } /* decompress and copy acfs */ while ( num_byte > 0 ) { ConvertToShort(inbuf_ptr,&range); --range; inbuf_ptr = inbuf_ptr + sizeof(int16); num_byte = num_byte - sizeof(int16); if((range <= prev_range) && (raw_data->PARMS.XCF)) xcf_data = 1; for(i = 0; i < raw_data->PARMS.MPLGS ; ++i) { for(j=0 ; j < 2; ++j) { if (xcf_data) raw_data->xcfd[range][i][j] = dcmpr(inbuf_ptr); else raw_data->acfd[range][i][j] = dcmpr(inbuf_ptr); inbuf_ptr = inbuf_ptr + sizeof(int16); num_byte = num_byte - sizeof(int16); } } prev_range = range; } fp->ctime=TimeYMDHMSToEpoch(raw_data->PARMS.YEAR, raw_data->PARMS.MONTH, raw_data->PARMS.DAY, raw_data->PARMS.HOUR, raw_data->PARMS.MINUT, raw_data->PARMS.SEC); free(inbuf); return 0; }