⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cgetdata.cpp

📁 StaMps最新测试版
💻 CPP
📖 第 1 页 / 共 2 页
字号:
#include "CGetData.h"#include <iostream>#include <fstream>#include <math.h>#include <string.h>using namespace std;void bytescale (unsigned char *indat, unsigned char *outdat, int ns, int nl, float        scale, float offset, int dtype, int flipflag) ;int CGetData::bpp [4] = {1, 2, 4, 4} ;CGetData::CGetData () {	red = NULL ;	grn = NULL ;	mag = NULL ;	phase = NULL ;	hgt = NULL ;	raw = NULL ;	} ;int CGetData::setparams (char *ifile, int ns, int startl, int nl) {	strcpy (infile, ifile) ;	nsamps = ns ;	startline = startl ;	nlines   = nl ;	ifstream ifil (infile, ios::in) ;	if (ifil.bad()) {		cout << "Problem with : " << infile << endl ;		return (-1) ;	}		ifil.close() ;	return (1) ;		}CGetData::~CGetData () {	if (red) delete [] red ;	if (grn) delete [] grn ;	if (mag) delete [] mag ;	if (phase) delete [] phase ;	if (hgt) delete [] hgt ;	if (raw) delete [] raw ;}int CGetData::getarrayMag (int dtype, float minval, float maxval, int flipflag) {	// get a byte array based upon the min and max value        unsigned char 	*bytearr ;         unsigned char  	*temparr ;         int  		i, j, i_out, j_out, hflip=0, vflip=0 ;	int  		bytesperpixel ;        long 		lpos ;	float 		scalemag, offmag ;        ifstream ifil (infile, ios::in) ; 	bytesperpixel = bpp [dtype] ;	// scale and offsets for going from orig data to byte array	// first subtract offmag then mult by scalemag	scalemag = 255. / (maxval - minval) ;	offmag = -minval * scalemag ;	cout << "Scale value  : " << scalemag << endl ;	cout << "Offset value : " << offmag << endl ;	//        // exponent apply flag and exponent value are class members	if (flipflag)	{		hflip = flipflag %2 ;		vflip = flipflag /2 ;	}	// allocate the input array and the output arrays	temparr = new unsigned char [nsamps * bytesperpixel] ;	bytearr = new unsigned char [nsamps] ;        ifil.seekg (long(0), ios::end ) ;        lpos = ifil.tellg () ;        totlines = lpos / (nsamps * bytesperpixel) ; 	if (nlines > totlines-startline) {                nlines = totlines - startline ;	}        if (nlines ==0) {                nlines = totlines - startline ;        }	mag = new unsigned char [nsamps * nlines] ;        ifil.seekg (long(startline) * nsamps * bytesperpixel, ios::beg) ;         for (i =startline; i<nlines; i++) {		// read in a line of data then convert                ifil.read ((char*)temparr, nsamps * bytesperpixel) ;		i_out = (vflip)? nlines -i - 1: i ;		bytescale (temparr, bytearr, nsamps, 1, scalemag, offmag, dtype, 0) ;		for (j=0; j<nsamps; j++) {			j_out = (hflip)? nsamps -j - 1: j ;			*(mag + i_out * nsamps + j_out) = *(bytearr + j) ;		}	}	delete [] temparr ;	delete [] bytearr ;	ifil.close() ;	return (1) ;}			int CGetData::getarrayMag (float scalefac, int expfl, float expv, int flipflag, int fifthflag){	// get the magnitude from the standard complex array        unsigned char *optr0 ;        int  i, j, i_out, j_out, count=0, hflip=0, vflip=0 ;        long lpos ;        float *temparr,  *iptr0, *iptr1 ;	float scalemag ;        float b1 ;        double totmag, magval, redval ;        ifstream ifil (infile, ios::in) ;         // exponent apply flag and exponent value are class members        expflag = expfl ;        expval = expv ;	if (flipflag)	{		hflip = flipflag %2 ;		vflip = flipflag /2 ;	}         ifil.seekg (long(0), ios::end ) ;        lpos = ifil.tellg () ;        totlines = lpos / (nsamps * 8) ; 	if (nlines > totlines-startline) {                nlines = totlines - startline ;	}        if (nlines ==0) {                nlines = totlines - startline ;        }         mag = new unsigned char [nsamps * nlines] ;        temparr = new float [nsamps * 2] ;         // get the scaling parameters        if (expflag) cout << "Applying exponent : " << expval << endl ;        if (!expflag) cout << "Not Applying exponent  " << endl  ;        totmag = 0. ;        for (i =startline; i<nlines; i+=32) {                ifil.seekg (long(i) * nsamps * 8, ios::beg) ;                ifil.read ((char*)temparr, nsamps * 8) ;                for (j=32; j<nsamps-32; j+= 32) {                        count += 1 ;			magval = getmag (*(temparr+ j*2), *(temparr + j*2+1));                        if (expflag)                        {                        	totmag += pow ( double(magval), double(expval)) ;                        }                        else {                        	totmag += magval ;                        }                }        }         // get the avereage of the red and grn        totmag /= count ;	scalemag = scalefac * 127. / totmag ;         cout << "Scaling parameter   :   "   << scalemag << endl ;         ifil.seekg (startline * nsamps * 8, ios::beg) ;        for (i=0; i<nlines; i++) {                ifil.read ((char*)temparr, nsamps * 8) ;                for (j=0; j<nsamps; j++)                {			i_out = (vflip) ? nlines -i  -1 : i ;			j_out = (hflip) ? nsamps -j  -1 : j ;                        optr0 = mag + i_out * nsamps + j_out ;                        iptr0 = temparr + j * 2 ;                        iptr1 = temparr + j * 2 + 1;			magval = getmag (*iptr0, *iptr1) ;                        if (expflag) {                                b1 = pow (double(magval), double(expval)) ;                        }                        else {                                b1 = magval ;                        }                        magval = b1 * scalemag ;			redval = magval ;                        redval = (redval < 0) ? 0. : redval ;                        redval = (redval > 255) ? 255. : redval ;                        *optr0 = (unsigned char) redval ;                }        }        delete [] temparr ;        ifil.close() ;        return (1) ;}          int CGetData::getarrayMPH (float scalefac, int expfl, float expv, int flipflag){        unsigned char *optr0, *optr1 ;        int  i, j, count=0, hflip=0, vflip=0, i_out, j_out;        long lpos ;        float *temparr,  *iptr0, *iptr1 ;	float scalemag ;        float b1 ;        double totmag, magval=0, phaseval=0, redval, TWOPI ;        ifstream ifil (infile, ios::in) ;         // exponent apply flag and exponent value are class members        expflag = expfl ;        expval = expv ;	if (flipflag) {		hflip = flipflag % 2 ;			vflip = flipflag / 2 ;		}	TWOPI = 8. * atan (1.) ;         ifil.seekg (long(0), ios::end ) ;        lpos = ifil.tellg () ;        totlines = lpos / (nsamps * 8) ; 	if (nlines > totlines-startline) {                nlines = totlines - startline ;	}        if (nlines ==0) {                nlines = totlines - startline ;        }         mag = new unsigned char [nsamps * nlines] ;	phase = new unsigned char [nsamps * nlines] ;        temparr = new float [nsamps * 2] ;         // get the scaling parameters for magnitude        if (expflag) cout << "Applying exponent : " << expval << endl ;        if (!expflag) cout << "Not Applying exponent  " << endl  ;        totmag = 0. ;        for (i =startline; i<startline+nlines; i+=32) {                ifil.seekg (long(i) * nsamps * 8, ios::beg) ;                ifil.read ((char*)temparr, nsamps * 8) ;                for (j=32; j<nsamps-32; j+= 32) {                        count += 1 ;			magval = getmag (*(temparr+ j*2), *(temparr + j*2+1));                        if (expflag)                        {                        	totmag += pow ( double(magval), double(expval)) ;                        }                        else {                        	totmag += magval ;                        }                }        }         // get the avereage of the red and grn        totmag /= count ;	scalemag = scalefac * 150. / totmag ;         cout << "Scaling parameter   :   "   << scalemag << endl ;	double phasescale = 255. / TWOPI ;          ifil.seekg (startline * nsamps * 8, ios::beg) ;        for (i=0; i<nlines; i++) {                ifil.read ((char*)temparr, nsamps * 8) ;                for (j=0; j<nsamps; j++)                {			i_out = (vflip) ? nlines -i  -1 : i ;			j_out = (hflip) ? nsamps -j  -1 : j ;                        optr0 = mag + i_out * nsamps + j_out ;                        optr1 = phase + i_out * nsamps + j_out ;                        iptr0 = temparr + j * 2 ;                        iptr1 = temparr + j * 2 + 1;			getmph (*iptr0, *iptr1, &magval, &phaseval) ;			if (phaseval < 0.) phaseval += TWOPI ;                        if (expflag) {                                b1 = pow (double(magval), double(expval)) ;                        }                        else {                                b1 = magval ;                        }                        magval = b1 * scalemag ;			phaseval *= phasescale ; 			redval = magval ;                        redval = (redval < 0) ? 0. : redval ;                        redval = (redval > 255) ? 255. : redval ;                        *optr0 = (unsigned char) redval ;			*optr1 = (unsigned char) (phaseval) ;                 }        }        delete [] temparr ;        ifil.close() ;        return (1) ;}          int CGetData::getarrayHgt (float scalefac, int expfl, float expv, float cont_interval, int flipflag){	// this reads in the bil float file with the back scatter as band	// 1 and the height as band 2 	// the arrays created are the height and the bs arrays as byte	// a contour interval is applied to the height so that it can 	// be treated in the same fashion as the cyclical phase        unsigned char *optr1 ;        int  i, j, count=0, hgtval, hflip=0, vflip=0, i_out, j_out ;        long lpos ;        float *temparr,  *iptr0, *iptr1 ;	float scalemag, scalehgt ;        float b1 ;        double totmag, magval=0, redval, contours ;        ifstream ifil (infile, ios::in) ;         // exponent apply flag and exponent value are class members        expflag = expfl ;        expval = expv ;	if (flipflag) {		hflip = flipflag % 2 ;			vflip = flipflag / 2 ;		}         ifil.seekg (long(0), ios::end ) ;        lpos = ifil.tellg () ;        totlines = lpos / (nsamps * 8) ; 	if (nlines > totlines-startline) {                nlines = totlines - startline ;	}        if (nlines ==0) {                nlines = totlines - startline ;        }         mag = new unsigned char [nsamps * nlines] ;	hgt = new unsigned char [nsamps * nlines] ;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -