usrp idl routines

Last modified: Thu Mar 16 13:07:13 2023.


List of Routines


Routine Descriptions

USRPCLPAVGSPC - AVERAGE CLP SPECTRA FILES

[Next Routine] [List of Routines]
NAME:
usrpclpavgspc - average clp spectra files
SYNTAX: nout=usrpclpavgspc(inpdir,outdir,yyyymmddst,hhmmddst,toavg,toskip)
ARGS:
inpdir: string   directory to read spectra
outdir: string   directory to write spectra
yyyymmddst:long  year,month,date to start
hhmmssst  :long  hour,min,sec to start
toAvgInCycle :long  number of files in cycle the we can average
toSkipInCycle:long    number of files inc cycle after the avg to skip 
toavg     :long   files to avg
RETURNS:
nout      : >= 0  number of files output
          -1 error
DESCRIPTION:
 	Average usrp spectra file together.
The user specifies the input directory and the output directory for the data.
They must both exist before calling this routine.
The start date,time to begin averaging is also input.
	This is mainly used to average heater on or heater off spectra.
heating typically uses an on off cycle:
 eg:  1 3secOn, 1 3secOff  ( 2 files in cycle)
      1 1 secOn, 3 1 secOffs (4 files in cycle)
 You specify the cycle length vai toavg and toskip number of files
The routine will avg toavg files and then output the averaged spectra. The averaging 
can span multiple cylces.
	Note that the start time is the first file to avg. If you have on,offs and you want to avg
the offs, you need to specify the start time of the first off (not the first on).
 	Once it starts averaging, it will go to end of directory... maybe want to add
a stop time parameter?

(See /pkg/rsi/local/libao/phil/usrp/usrpclpavgspc.pro)


USRPCLPCHKIPP - SEE IF THIS IS CLP IPP

[Previous Routine] [Next Routine] [List of Routines]
NAME:
usrpclpchkipp - see if this is clp ipp
SYNTAX: istat=usrpclpchkipp(d,smpUsec=smpUsec,codeUsec=codeUsec,uncoded=uncoded,$
				corRatio=corRatio,mintxVal=mintxVal)
ARGS:
d[N]    : complex  input data
KEYWORDS:
smpUsec   : float   sample rate in usecs (def=.04 usecs)
codeUsec  : float   codelength in usecs (def=440 usecs)
minTxVal  : float   min power to be tx puls
                    default 8e5
uncoded   : int     if true then we want correlation (topside). def: clp

RETURNS:
istat[n]  : 1 - is a ipp
            0   not a clp ipp
            one for each tx buf passed in
corRatio  :  float  acf of txbuf . 0..1
DESCRIPTION:
  Check to see if this ipp is a clp ipp by looking at the power across the
transmitter pulse
 values used:

  midipp: 150.. must have power .. gets rid of power profile which may have
                                   echo at 440,500
  power : 52 usecs
  clpipp: 440. 
  topSid: 500 usecs
  mracf : 300 usecs
  txSmpDelayUsecs .. usually about 5.6 usecs
  slopEnd : 5 usecs; .. move this far back from falling  edge of pulse before average start
  avgSmpls:100= 20 secs
  make sure power at 440 - 6 usecs
  acf:
  - compute acf for lags 0 .. 50  (0 to 10 usecs)
  - avg lags 20-50 ( 4 to 10 usecs)
  - normalize to 0 lag
    make sure correlation is less than acfLim (.4)
  - this gets rid of topsid.. so i'll remove the topside  limits
  -  mracf, pwr, clp all have low correlation
  

(See /pkg/rsi/local/libao/phil/usrp/usrpclpchkipp.pro)


USRPCLPFIXAZZA - ADD AZ,ZA TO ASCII HEADER FILES

[Previous Routine] [Next Routine] [List of Routines]
NAME:
usrpclpfixazza - add az,za to ascii header files
SYNTAX: n=usrpclpfixazza(inpdir,outdir,firsthdr=firsthdr,lasthdr=lasthdr)
ARGS:
inpdir: string input directory holding the ascii .hdr files
outdir: string output directory to write the new  ascii .hdr files
               with the azza,
KEYWORDS:
 firsthdr: string if supplied, then first header file to process
 lasthdr : string if supplied then last header file to process
RETURNS:
n     : long   number of .hdr files rewritten.
DESCRIPTION:
	The aeronomy usrp data taking system does not record the az,za positions
in the data files. This routine will add the az,za info to the ascii header
files (generated after the decoding step).
	The routine will :
 - read all of the .hdr files found in inpdir, 
 - input the az,za data for that date
 - interpolate to the az,za to the time for this data file
 - output the ascii header file back out to outdir/ 

 Note that this should be run after the decoding has completed...
 It should probably be ok to have inpdir=outdir

 an example of using the program:
 - decode the data
 - in idl
   @agcinit
   inpdir='/share/tstor0/clp/t1193_20160106/'   
   outdir='./newhdr/'
   n=usrpclpfixazza(inpdir,outdir)

  The new headers should be in outdir/

(See /pkg/rsi/local/libao/phil/usrp/usrpclpfixazza.pro)


USRPCLPIMG- MAKE IMAGE OF DECODED CLP FILE

[Previous Routine] [Next Routine] [List of Routines]
NAME:
usrpclpimg- make image of decoded clp file
SYNTAX:istat=usrpclpimg,file,img=img,hdr=hdr,$
			bpcind=bpcind,medlen=medlen,cfr=cfr,useimg=useimg,
			nsig=nsig,zx=zx,zy=zy,title=title,nhghts=nhghts,$
           wintouse=wintouse,freqToUse=freqToUse,rangeToUse=rangeToUse,fast=fast,combine=combine,$
           maxFreq=maxfreq,freqsmo=freqsmo,tmI=tmI,freqAr=freqAr
ARGS:
file: string	    filename holding decoded info (xxx.dcd)

KEYWORDS:
bpcInd[2]:long     first last height indices to use for bpc
                   default last 100 hghts
medlen:   long     length median filter each spc. default=71 channels
cfr : float        cfr in Mhz for band. 
useimg:            if set then user is passing in img. useit
nsig[2]: float		for scaling the image. default=[-nsig[0],nsig[1]]*sig
                   def. 6 sigma.         
zx  : int   	    scaling for x axis (neg is smaller)
zy  : int   	    scaling for y axis (neg is smaller)
nhghts:int         limit to this number of heights (def all)
title: string      title
wintouse: int      window number to use for display. Default=1
freqToUse[2] :float freq range to use (in Mhz). Currently combine does not work with this
rangeToUse[2]:float ranges to use (in km). overrides nghts
                    [0.,x] will start with first range
                    [x,999] will end with last range
fast         :int   if supplied then compute median bandpass to subtract
                    every fast rows
combine      :int   if set then combine up and downshifted spectra
                    note: if you set /useimg, you still need to set
                    this to reflect how the image was made (so we get the
                    freq correct).
maxFreq      :float 0..12.5 Mhz .. max freq offset to display
                    default is 12.5 Mhz, <= 0 --> use default
freqsmo      :int   number of freq chan to smooth,decimate before output.
                    the medlen length above will still be relative to the original 
                    number of chan.
                    zx should be relative to the smoothed/decimated value

RETURNS:

istat:  0 ok, -1 error
img[*,*]:  float selected channel image. this is the image from the file
                 before max freq selection or smoothing/decimation
hdr: {}    struct from .hdr file
tmI:{}     struct holding tming info.. read, median filter
freqAr[]: float   freq of each channel in img

DESCRIPTION:
	Make a dynamic spectra image of decoded usrp file (.dcd).
Take info from the .hdr file (it should be in the same directory
as the .dcd file).

(See /pkg/rsi/local/libao/phil/usrp/usrpclpimg.pro)


USRPCLPIMGMONSCAN - SCAN FOR PROCESSED USRP CLP FILES

[Previous Routine] [Next Routine] [List of Routines]
NAME:
usrpclpimgmonscan - scan for processed usrp clp files
SYNTAX: nfiles=usrpclpimgmonscan(dir,hdrAr,firsttime=firsttime 
ARGS:
dir     : string   to search for .hdr files. Include the 
                   '/' at the end of the dir name
KEYWORDS:
firstTime:         if set then this is the first time the routine
                   is called with this dir,fbase. If not set then
                   hdrAr will have the info from the previous call.
                   the routine will add new info to this array.
                   with firsttime=1
RETURNS:
nfiles:  long   number of raw input files found
hdrAr[nfiles]:{}  stuct holding info on all the image files found:

DESCRIPTION:
	Scan for usrp clp  processed hdrfiles(.dcd). 
It returns the number of  input files found and the an array holding the headers. 
EXAMPLES:
	dir='/net/wombat/data/phil/usrpproc/150217/'
   n=usrpclpimgmonscan(dir,hdrAr,first=1)
 help,hdrar[0],/st
 Structure <170f688>, 4 tags, length=196, data length=196, refs=1:
;** Structure <62db38>, 18 tags, length=100, data length=100, refs=2:
   FILENUM         LONG        1421784512
   BLKINFILE       LONG                 1
   NIPPSACCUM      LONG              1000
   CUMIPPSTART     LONG               211
   SMPTMUSEC       FLOAT         0.0400000
   HGHTRESUSEC     FLOAT           1.00000
   NHGHTS          LONG              4000
   HGHTDELAYUSEC   FLOAT           533.320
   FFTLEN          LONG             16384
   TXSMPIPP        LONG             11000
   HGHTSMPIPP      LONG            110975
   CODELENUSEC     FLOAT           440.000
   DATE            LONG          20150120
   SECMID          LONG             58112
   AZ              FLOAT           0.00000
   ZAGREG          FLOAT           0.00000
   ZACH            FLOAT           0.00000
   lblkkinfile     string          "001"             if hires..
   TMI             STRUCT    ->  Array[1]

(See /pkg/rsi/local/libao/phil/usrp/usrpclpimgmonscan.pro)


USRPCLPIMG_HC- MAKE HARDCOPY IMAGE OF DECODED USRP CLP FILE

[Previous Routine] [Next Routine] [List of Routines]
NAME:
usrpclpimg_hc- make hardcopy image of decoded usrp clp file
SYNTAX:n=usrpclpimg_hc,inpDir,outDir,startTm=startTm,endTm=endTm,cfr=cfr,
                  bpcind=bpcind,medlen=medlen,combine=combine,$
                  maxFreq=maxFreq,freqsmo=freqsmo,$
                 rangeToUse=rangeToUse,freqToUse=freqToUse,$
                 nsig=nsig,zx=zx,zy=zy,title=title,nhghts=nhghts,$
                 logtmfile=logtmfile,$
				   noimg=noimg,nsig=nsig,ftype=ftype,useHdrArout=usehdrArout,hdrArOut=hdrArOut
ARGS:
inpDir: string     input directory of reduced files to process
outDir: string     where to write the images

KEYWORDS:
startTm  :long     use files >= this time. default is first file
endTm    :long     last time to include . default all
cfr      :float    cfr for band. default=430
bpcInd[2]:long     first last height indices to use for bpc
                   default last 100 hghts
medlen:   long     length median filter each spc. default=71 channels
combine:  int      if set then combine upshifted, downshifted spectra
nsig: float        for scaling the image. default=6 sigma
zx  : int          scaling for x axis (neg is smaller)
zy  : int          scaling for y axis (neg is smaller)
title: string      title
nhghts:int         limit to this number of heights. (<=0 --> all)
maxFreq:float      0..12.5 Mhz .. max freq offset to use for image
                   default is 12.5 Mhz
rangeToUse[2]: float range in km to use for the image. overrides nhghts
freqToUsep2]: float  freq range to use(MHz at 430) to use. Overrides
                   maxfreq. If provided, smoothing not supported.
freqsmo: int       number of freq channels to smo/decimate. zx should be
                   relative to this final number of channels
                   eg. maxFreq/25. * fftlen/freqsmo
noimg: int         if set then don't make images, just return
                   fiarout.. files we'll use 
nsig[2]: float     clip to -nsig[0],nsig[1] sigmas
ftype  : string    file type: gif,png,jpg. default=jpg
useHdrArOut:int    if set then use hdrArOut as files to process.
                   user passes this in
verb   :  int       if set then  print number of files found to process
logtmfile: string   file name to log times. '' --> no logging
                   
RETURNS:

n :    >=0         number of images we made
          -1       error
hdrArOut[n]: {}    array of .hdr from each ,dcd file, (unless useHdrArOut 
                   is set. in this case just pass back what is passed in.
tmI:{}             times for i/o and bandpass/medianviltering..

DESCRIPTION:
   Make a dynamic spectra image of decoded usrp files (.dcd) and then write
the graphics file to disc. Do this for all of the files in the inpdir subject
to:
 - start at >= startTm
 - end   at <= endTm

(See /pkg/rsi/local/libao/phil/usrp/usrpclpimg_hc.pro)


USRPCLPRDHDR- READ .HDR FILE FROM CLP DECODING

[Previous Routine] [Next Routine] [List of Routines]
NAME:
usrpclprdhdr- read .hdr file from clp decoding
SYNTAX:istat=usrpclprdhdr,file,hdr
ARGS:
file: string	header filename  xxxx.hdr
KEYWORDS:
RETURNS:
istat:	0 ok -1 error
hdr  : {}    header holding info
DESCRIPTION:
	Read the .hdr file created by the clp decoding (clpGpu).
Return info in struct hdr
Take info from the .hdr file (it should be in the same directory
as the .dcd file.

(See /pkg/rsi/local/libao/phil/usrp/usrpclprdhdr.pro)


USRPCLPWRHDR- WRITE .HDR FILE FROM CLP DECODING

[Previous Routine] [Next Routine] [List of Routines]
NAME:
usrpclpwrhdr- write .hdr file from clp decoding
SYNTAX:istat=usrpclpwrhdr,file,hdr
ARGS:
file: string	header filename  xxxx.hdr
hdr : {}       header from usrpclprdhdr()
KEYWORDS:
RETURNS:
istat:	0 ok -1 error
DESCRIPTION:
	Write the .hdr file using struct from usrpclprdhdr().

(See /pkg/rsi/local/libao/phil/usrp/usrpclpwrhdr.pro)


USRPCOUNTPEAKS - COUNT PEAKS IN IPPS.

[Previous Routine] [Next Routine] [List of Routines]
NAME:
usrpcountpeaks - count peaks in ipps.
SYNTAX  nipps=usrpcountpeaks(dir,subdir,si,indFile=indFile,nfiles=nfiles,$
		minTxPwr=minTxpwr,ippusec=ippusec,rfusec=rfusec,$
       kmAvg=kmAvg,limPk=limPk,kmPk=kmPk,verb=verb,var=var,har=har)
ARGS:
 dir  : ''  base dir for usrp data
subDir: ' ' subdir to process
KEYWORDS:
indFile: int file index in subdir to start on (count from 0)
             def=0
nfiles : int number of files (seconds) to process.  def=3600
             or we hit end of directory
minTxPwr: float  to define tx pulse. def=.8e6
ippusec:  float  ipp in usec. def=10000.
rfUsec :  float  rf in usec . def=440.
kmAvg[2]: float  if supplied then avg all samples between these
                 2 ranges. It will be stored for each ipp,.
                 def= no averging done.
limPk   : float  defines a peak. This is a power level.
                 def=[1.5e6]
kmPk[2] : float  search for peaks between these two ranges.
                 def=[360,1200.]  km. lets you exclude fregion, cals.
verb    : int    if > 0 the do plots every this many ipps.
                 def: no plots.. A warning message will be output
                 if verb  >0 and  < 100. it will slow down processing.
har[2]  : float  horizontal scale if plottting. def:[0,10000.] usecs
var[2]  : float  vertical scale if plotting. def:[0,3e6]
RETURNS:
nipps   : long   -1  error initializing dataset
                 number of ipps returned in pkI. 
si      : {}     si struct opened by usrpinitset. It is left
                 pointed after the last read. (probably end of set).
pkI[nipps]:{}    struct holding info for each ipp read.

DESCRIPTION:
	This routine will read data in a subdir, counting the peaks between
the specified km range. It will also optionally average pwr over a hght
range (giving a single number). This info will then be stored fore each
ipp.
 the program flow is:
 - initialize a dataset (usrpinitset)
     if si was previously used and has an lun open, it will be closed.
 - call usrpsync() to synchronize to the first rf pulse found
   minTxPwr is used for this.
 - loop reading ipps until nfiles have been processed or we hit the end of
   the subdir.
 For each ipp:
 - compute the power
   search for levels above the limPk. save this count
 - optionally compute average over the specified height range.

	This will continue until nfiles have been processed or we hit the 
end of the  subdir.

 pkI[nipps] is returned with each entry containg:
IDL>  help,pkI,/st
** Structure <22cf808>, 5 tags, length=20, data length=20, refs=2:
   FIND       LONG        0     ; file index in dir. count from 0
   TIME       ULONG 1487867130  ; secs 1970. filename=rf@time.000.h5 
   kmAvg      FLOAT    33587.7  ; power average over km range
   PKCNT      LONG          0   ; samples above pkLim
   BYTEPOS    ULONG    973196   ; in file start of ipp.

the index of pkI[] is the continuous ipp number.
You can use the bytepos to position into the file and then read
the entire ipp. The bytepos includes the header offset.
EXAMPLE:
 run on cpu (gpuserv0) that has access to the usrp raw data.
 @usrpinit
 dir='/media/USRP170223/ch/'
 subDir='2017-02-23T16-25-30' 
 indFile=0 ; def
 kmPk= [400,1000.]
 kmAvg=[120,300]
 verb=1000   ; print every 10 secs of data

 nipps=usrpcountpeaks(dir,subdir,si,indFile=indFile,nfiles=nfiles,$
		minTxPwr=minTxpwr,ippusec=ippusec,rfusec=rfusec,$
       kmAvg=kmAvg,limPk=limPk,kmPk=kmPk,verb=verb,var=var,har=har)

(See /pkg/rsi/local/libao/phil/usrp/usrpcountpeaks.pro)


USRPFINDRF - FIND RF IN IPP

[Previous Routine] [Next Routine] [List of Routines]
NAME:
usrpfindrf - find rf in ipp
SYNTAX: ind=usrpfindrf(si,d,nsmp=nsmp,tp=tp)
ARGS:
d[2,nsmp]:int    voltage samples (i,q) by n
                or complex d[nsmp] 
rflen  : long   num samples in rf pulse
KEYWORDS:
nsmp: long   if supplied then number samples in dcmp to use
RETURNS;
ind: long index in dcmp for start of rf pulse;
tp[nsmp]:float  total power for nsmp
DESCRIPTION:
	find the index in dmp array where the rf starts.
cmp power then convolve a window of rflenSmp and then
find the peak.
returns:
  istat : -2 (found peak but too close to end of d)
          -1 (found peak  but not clpipp)
          >=0 index into d where rf starts

(See /pkg/rsi/local/libao/phil/usrp/usrpfindrf.pro)


USRPGETDATA - INPUT DATA

[Previous Routine] [Next Routine] [List of Routines]
NAME:
usrpgetdata - input data
SYNTAX: nsmp=usrpgetdata(si,nsmpReq,d)
ARGS:
SI     :{}        from usrpinitset
nsmpreq:long      number of samples requested
RETURNS:
 nsmp	: long	   -99  .. no more files left
                  < nsmpReq. read this many,
                  next file has time jump
                  (next file is current file) 
                  
 d[nsmp]: complex  data input as floats

DESCRIPTION:
	Read the next requested number of samples
from the si dataset. Return the number of samples
read in nsmp, and the data in d[nsmp] as complex floats.
	This will read across files unless there is a time jump between
 files. In this case it just returns the samples read and positions at
the start of the new file.

(See /pkg/rsi/local/libao/phil/usrp/usrpgetdata.pro)


USRPGETSPC - INPUT DECODED SPECTRA

[Previous Routine] [Next Routine] [List of Routines]
NAME:
usrpgetspc - input decoded spectra
SYNTAX: nspc=usrpgetspc(dir,fbase,spcar,freq,hdr)
ARGS:
dir    :string    directory holding file
fbase  :string    file basename (see below)
RETURNS:
 nspc  : long     < 0 error.. 
                  > 0  number of spectra in array
spcar[nchn,nspc]:float  spectra
freq[nchn]: float   freq for spectra
hdr       : {}     header info

DESCRIPTION:
   Read a usrp decoded averaged spectra file (typically avged for 10 secs).
This has been processed by clpGpu.cu program.
	The user inputs the directory and base filename (see below).
The spectra, freq array, and header struct will be returned.
	This routine is normally used for debugging...
EXAMPLE:
  Suppose the integrated files you want are:
/net/rserv2/data/atm/clp/1465014926.1.hdr
/net/rserv2/data/atm/clp/1465014926.1.dcd
The call would be:
 dir  ='/net/rserv2/data/atm/clp/'
 fbase='1465014926.1'    ; note no trailing .
nspc=usrpgetspc(dir,fbase,spcar,freq,hdr

(See /pkg/rsi/local/libao/phil/usrp/usrpgetspc.pro)


USRPINITSET - INITIALIZE FOR A SET OF USRP FILES

[Previous Routine] [Next Routine] [List of Routines]
NAME:
usrpinitset - initialize for a set of usrp files
SYNTAX: istat=usrpinitset(dir,sI,expI=expI,$
                      subDirSt=subDirSt,indFile=indFile,minTxPwr=minTxPwr}
ARGS:
dir: string    directory holding the 1 hour blocks of data
KEYWORDS:
expI    :{}    struct holding exp info that user can define
               expI.rfUsec  - rf pulse in usecs (def=440)
               expI.ippUsec - ipp usecs (def=10000)
subDirSt :''  first subdir to start with (just the base name)
              default is first in directory
indFile  :0L  index in subdir for file to start
              count from 0
minTxPwr :0.  minimum allowable value for tx pulse. def: .8e6
	           If you also supply expI{}, this will override the
              value in expi.minTxPwr

RETURNS:
	istat: 0 ok
          -1 error initializing set
   sI   :{}    set info, used to access the data
DESCRIPTION:
	initialize the sI struct for access to the usrp
data files. After this, you can call usrpgetdata(sI,xx)

(See /pkg/rsi/local/libao/phil/usrp/usrpinitset.pro)


USRPNEXTFILE - MOVE TO NEXT FILE

[Previous Routine] [Next Routine] [List of Routines]
NAME:
usrpnextfile - move to next file
SYNTAX: istat=usrpnextfile(si,find=find)
ARGS:
SI     :{}        from usrpinitset
KEYWORDS:
find   : 0l   if present the move to start of find in the
              current directory..
RETURNS:
 istat :   -1 no files currently open. try init
       :   -2 no more files
       :   -3 find no found in this directory
       :    0 next file openned  is contiguous
       :    1 next file, but time jump
DESCRIPTION:
	Open next file in the set. Position to start of read.
If find=  supplied then this will be the next file (count from 0).
Note: 31may17 added jump to  next directory.

(See /pkg/rsi/local/libao/phil/usrp/usrpnextfile.pro)


USRPPLOTTP - TOTAL POWER PLOT OF USRP FILE

[Previous Routine] [Next Routine] [List of Routines]
NAME:
usrpplottp - total power plot of usrp file
SYNTAX: usrpplottp,si,ippfile=ippfile,nsmpipp=nsmpipp,delay=delay,limline=limline
ARGS:
si : {}   structure returned from usrpinitset()
KEYWORDS:
ippfile: long   number of ipps in file to plot. def:100 
nsmpipp: long   number of samples in ipp. def:250000
delay  : float  secs to delay between plots. def:.001
limline: float  draw red horizontal on each plot here.
RETURNS:
	None. the si struct will be updated to the last 
data read.
DESCRIPTION:
	Read raw usrp file compute power and plot it. The read is done
nsmpipp at a time. ippfile ipps will be done in the file.
It also places a horizonal line at the value of
limline. You can use this to see if the txPower samples
ever falls below this value (the tx threshold is used in searching
for the tx pulse during clp decoding).
	The routine will process ippfile ipps in the file .. and
then it stops (doesn't move to the next file yet..);

Example:
  @usrpinit
  dir='/export/usrp/20160106/ch'
  ; data is stored by hour in each dir. to start at a later
  ; directory use subdirst
  subDirSt='2016-01-06T13-03-33'
  istat=usrpinitset(dir,sI,subdirst=subdirst)

(See /pkg/rsi/local/libao/phil/usrp/usrpplottp.pro)


USRPSECTODIRNM - CONVERT SEC1970 TO DIR DATE FORMAT

[Previous Routine] [Next Routine] [List of Routines]
NAME:
usrpsectodirnm - convert sec1970 to dir date format
SYNTAX: dirnm=usrpsectodirnm(sec)
ARGS:
sec      : double 1970 secs
RETURNS;
dirnm: string yyyy-mm-ddThh-mm-ss
DESCRIPTION:
	Convert from secMidnite to directory name format.
The times/dates are utc.

(See /pkg/rsi/local/libao/phil/usrp/usrpsectodirnm.pro)


USRP_IOBUF_GET - READ RAW DATA FROM USRP DATASET

[Previous Routine] [Next Routine] [List of Routines]
NAME:
usrp_iobuf_get - read raw data from usrp dataset
SYNTAX: istat=usrp_iobuf_get(fI,nsmp,buf,pI)
ARGS
 fI:  {}   File info from  usrp_iobuf_init()
nsmp: long number of samples to return in buf
buf[nsmp]:complexarr  return data here. User should preallocate
RETURNS:
 istat: int    
 pI : {}   position info for this databuf
 buf: complex buffer they want

 istat: 1  nsmp samples  data returned in buf
        2  pI.smpRet < nsmp returned
           (pI.smpRet is always the actual number returned)
        0  hit end of dataset, no data left
       -1  error returned from usrp_iobuf_inpfile()
buf[] :complexarr   return data. The number of samples =pI.smpRet
                 the user should preallocate this array.
pI    : {}  structure holding info on the returned buffer
DESCRIPTION:
	Return the next data from the usrp dataset.
The data is returned in the complex arr buf[]. The user requests
nsmp samples. Reads can span files and directories. 
The actual number of samples  returned will be recorded in pI.smpRet.
The routine can return fewer than the requested samples if the data would end up 
being non contiquous in time.
	The user must call usrp_iobuf_init() once to initialize fI, before
calling this routine.
   Position info on the returned buf is set in pI:
IDL> help,pI,/st
   IDIR            LONG        0   .. index into fI.dI[] for directory for this buf. 0 based
   IFILE           LONG        0   .. index for file in directory. 0 based
   ISMP            LONG        0   .. sample within file. 0 based
   SMPRET          LONG  1048576   .. number of samples returned in buf[]
   MFILE           INT         0   .. multiple files. set to 1 if buf crossed file boundary.
   TMJUMP          INT         0   .. 1 if this buffer is discontinuous in time from the
                                      previous buffer.
See usrp_iobuf_init() for a description of fI.

(See /pkg/rsi/local/libao/phil/usrp/usrp_iobuf_get.pro)


USRP_IOBUF_INIT - INITIALIZE FOR USRP_IOBUF I/O

[Previous Routine] [Next Routine] [List of Routines]
NAME:
usrp_iobuf_init - initialize for usrp_iobuf i/o
SYNTAX: istat=usrp_iobuf_init(dirl,fI)
ARGS:
dirL[]: strarr array of directories holding the data
               they should be in time order.
RETURNS:
fI    : {}     structure holding the file info for the
               iobuf routines
DESCRIPTION:
	The usrp_iobuf_xxxx() routines will read raw data from 
the usrp data files. The routines will read across files and directories.
To use the routines:
	- file_search('/media/USRPyymmdd/gr/*,/test_dir)
     get a list of directories to read from
   - istat=usrp_iobuf_init(dirl,fI) 
     call this routine to initialize things
   - loop calling istat=usrp_iobuf_get(fI,buflen,buf,pI)
	The status info for each buf comes back in pI structure.

	The routines read and buffer a 1 second file at a time.
The user then requests data. It will be returned from the buffer, and 
another file will be read if needed to complete the sample request.

	If a buffer request would create a gap in time (needs a new file to 
complete the buf, and the file is not the next second),then the
routines return the samples left before the gap. The next call
will set a flag saying that this new buffer is a time jump from
the previous buffer.

	The fI struct contains:
** Structure <21c1708>, 12 tags, length=200000320, data length=200000314, refs=1:
   NDIR         LONG       11   .. number of directories in dirl=[]
   MAXFILESDIR  LONG       3600 .. each dir is max of 3600 1 sec files
   MAXSMPFILE   LONG       25000000 .. 1 sec of data at 25 Mhz
   DI           STRUCT ->  Array[11]. info on each directory
   IDIR         LONG          0     index into fi.dI[idir] current dir. 0based.
   IFILE        LONG          0     index into file in fi.dI[idir] directory. 0based   
   FNAME        STRING    '/media/USRPJUHA/eregion/gr/2018-05-04T14-35-46/rf@15'... cur file
   TMSEC        LONG      1525444546  file time start of buf
   ISMP         LONG      1048576     index for next sample in buf
   SMPINBUF     LONG      25000000    samples in buf
   TMJUMP       INT       0           if 1 this buf has time jump from previous.
   BUF          COMPLEX   Array[25000000]

 The struct array fI.dI[] contains:
** Structure <19ca4f8>, 3 tags, length=24, data length=24, refs=2:
  DIRN            STRING    '/media/USRPJUHA/eregion/gr/2018-05-04T14-35-46'.. dir name
  SEC1            LONG        1525444546                    .. first sec in dir
  NFILES          LONG              3600                    .. number of files in dir

(See /pkg/rsi/local/libao/phil/usrp/usrp_iobuf_init.pro)


USRP_IOBUF_INPFILE - READ A 1 SECOND FILE

[Previous Routine] [Next Routine] [List of Routines]
NAME:
usrp_iobuf_inpfile - read a 1 second file
SYNTAX: istat=usrp_iobuf_inpfile(fI,firsttime=firsttime)
ARGS
 fI:  {}   File info from  usrp_iobuf_init()
KEYWORDS:
firsttime: int if true then initialize pointer to start.
RETURNS:
 istat: int    
 pI : {}   position info for this databuf
 buf: complex buffer they want

 istat: 1  got full 1 second of data
        2  got less than 1 second of data (but > 0)
        0  hit end of dataset, no data left
       -1  open error
DESCRIPTION:
   Read the next 1 second file into fi.buf. This is used by the
routines: usrp_iobuf_get(), usrp_iobuf_init()
	Set firsttime true if this is the first call to this routine (normally
done in usrp_iobuf_init().

 This routine is not normally called by the user

(See /pkg/rsi/local/libao/phil/usrp/usrp_iobuf_inpfile.pro)


USRP_IOBUF_POS - POSITION TO A FILE IN DATASET

[Previous Routine] [List of Routines]
NAME:
usrp_iobuf_pos - position to a file in dataset
SYNTAX: istat=usrp_iobuf_pos(fI,idir,ifile)
ARGS
 fI:  {}   File info from  usrp_iobuf_init()
nsmp: long number of samples to return in buf
idir: long directory index to position to. 0 based
ifile:long file index in dir to position to. 0 based
RETURNS:
 istat: int   1 positioned ok
              -1  open error
              -2  directory not available    
              -3  file not in directory
DESCRIPTION:
	Position to a directory, file in the iobuf dataset. The
user inputs the directory index (0 based) and the file index (0 based).
The routine will read this file into the local buffer. 
	It is an error if the file does not exist.
	You can then call usrp_iobuf_get() to access the data

(See /pkg/rsi/local/libao/phil/usrp/usrp_iobuf_pos.pro)