Commit 54ba4f18 authored by no_author's avatar no_author
Browse files

This commit was manufactured by cvs2svn to create tag 'v6r14'.

git-svn-id: https://svn.ego-gw.it/svn/advsw/Fr/tags/v6r14@22323 47e613b6-93f3-4244-b775-e06b1756610f
parent 20a8c531
Frame Library Software Terms and Conditions
The authors hereby grant permission to use, copy, and distribute this
software and its documentation for any purpose, provided that existing
copyright notices are retained in all copies and that this notice is
included verbatim in any distributions. Additionally, the authors grant
permission to modify this software and its documentation for any purpose,
provided that such modifications are not distributed without the explicit
consent of the authors and that existing copyright notices are retained in
all copies. Users of the software are asked to feed back problems, benefits,
and/or suggestions about the authors.
Support for this software - fixing of bugs, incorporation of new features -
is done on a best effort basis. All bug fixes and enhancements will be made
available under the same terms and conditions as the original software,
IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR
DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF,
EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE IS
PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO
OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
MODIFICATIONS.
include $(CMTROOT)/src/Makefile.header
include $(CMTROOT)/src/constituents.make
package Fr
use VirgoPolicy v1r4
macro Fr_linkopts " -L$(FRROOT)/$(Fr_tag) -lFrame -lm "
macro+ Fr_linkopts "" \
Linux " -Wl,-rpath,$(FRROOT)/$(Fr_tag)"
alias FrDump "${FRROOT}/${Fr_tag}/FrDump.exe"
alias FrCopy "${FRROOT}/${Fr_tag}/FrCopy.exe"
alias FrCheck "${FRROOT}/${Fr_tag}/FrCheck.exe"
private
macro+ cflags " -O "
macro utilities_constituents "FrDump FrCopy FrCheck"
macro examples_constituents "FrCompress FrCopyFile FrCopyFrame FrFileDump \
FrFull FrMark FrMultiR FrMultiTOC FrMultiW FrOnline FrReshape FrSpeed FrStat"
macro constituents "Frame $(utilities_constituents) "
macro+ constituents "" \
OSF1 "$(examples_constituents)" \
Linux "$(examples_constituents)"
public
# The constituents
# The standard library
library Frame -no_prototypes FrameL.c FrIO.c FrFilter.c -s=zlib *.c
# The standard utilities
application FrDump FrDump.c
application FrCopy FrCopy.c
application FrCheck FrCheck.c
# The examples and test program
application FrCompress exampleCompress.c
application FrCopyFile exampleCopyFile.c
application FrCopyFrame exampleCopyFrame.c
application FrFileDump exampleFileDump.c
application FrFull exampleFull.c
application FrMark exampleMark.c
application FrMultiR exampleMultiR.c
application FrMultiTOC exampleMultiTOC.c
application FrMultiW exampleMultiW.c
application FrOnline exampleOnline.c
application FrReshape exampleReshape.c
application FrSpeed exampleSpeed.c
application FrStat exampleStat.c
File added
File added
File added
%---- define file name and channel name
%
file = '../data/test.dat';
channel = 'fastAdc1';
%
% ---first extarct data from frames -------------
%
[a,t,f,t0,t0s,c,u,more] = frextract(file, channel,2,5);
%
%---------- plot time serie --------------------
%
subplot(2,1,1)
plot(t,a)
ylabel(channel)
xlabel('time [s]')
title(t0s)
%
%------ compute and plot FFT --------------------
%
b = fft(a);
m = abs(b(1:length(b)/2));
subplot(2,1,2)
semilogy(f,m)
ylabel('power')
xlabel('frequency [Hz]')
title(['FFT for ',channel])
%
%---- write an audio file (listen it with Netscape) ----
%
auwrite(a/max(abs(a)),16384.,'audio.au')
%---- define file name and channel name
%
file = '../data/test.dat';
channel = 'fastAdc1';
%
% ---first extract data from frames -------------
%
[a,t,f,t0,t0s,c,u,more] = frextract(file,channel,2,3);
%
%---------- plot time serie --------------------
%
subplot(2,1,1)
plot(t,a)
ylabel(channel)
xlabel('time [s]')
title(t0s)
%
%------ compute and plot FFT --------------------
%
b = fft(a);
m = abs(b(1:length(b)/2));
subplot(2,1,2)
loglog(f,m)
ylabel('power')
xlabel('frequency [Hz]')
title(['FFT for ',channel])
%---- define file name and channel name
%
file = '../data/test.dat';
channel = 'fastProc';
%
% ---first extract data from frames (sequential read) ---
%
[a,t,f,t0,t0s,c,u,more] = frextract(file,channel,2,3);
%
subplot(3,1,1)
plot(t,a)
ylabel(channel)
xlabel('time [s]')
title(t0s)
%
%----- then do a random access to extract the same data --
%
[a,t,f,t0,t0s,c,u] = frgetvect(file,channel,t0,3.);
%
subplot(3,1,2)
plot(t,a)
ylabel(channel)
xlabel('time [s]')
title(t0s)
%
%----- then do a random access to extract part of the data --
%
[a,t,f,t0,t0s,c,u] = frgetvect(file,channel,t0+.6,0.6);
%
subplot(3,1,3)
plot(t,a)
ylabel(channel)
xlabel('time [s]')
title(t0s)
%---- define file name and channel name
%
file = '../data/test.dat';
channel = 'fastAdc1';
%
% ---first get data from frames -------------
%
[a,t,f,t0,t0s,c,u] = frgetvect(file,channel,719312538.,4.);
[a,t,f,t0,t0s,c,u] = frgetvect(file,channel,0.,4.,1);
%
%---------- plot time serie --------------------
%
subplot(2,1,1)
plot(t,a)
ylabel(channel)
xlabel('time [s]')
title(t0s)
%
%------ compute and plot FFT --------------------
%
b = fft(a);
m = abs(b(1:length(b)/2));
subplot(2,1,2)
loglog(f,m)
ylabel('power')
xlabel('frequency [Hz]')
title(['FFT for ',channel])
/*---------------------------------------------------------------------*/
/* FrExtract.c by B. Mours LAPP Oct 22, 2002 */
/* */
/* This Matlab mex file extract from a frame file the data for */
/* one ADC channel (this is for Matlab version 5) */
/* */
/* The input arguments are: */
/* 1) file name(s). This could be a single file, a list of file */
/* separeted by space or a frame file list (ffl) */
/* 2) ADC or PROC name */
/* 3) (optional) first frame (default= first frame in the file) */
/* 4) (optional) number of frame (default = 1 Frames) */
/* 5) (optional) debug level (default = 0 = no output) */
/* */
/* Returned matlab data: */
/* 1) ADC or PROC data (time serie) */
/* 2) (optional) x axis values relative to the first data point. */
/* This is usual time but it could be frequency in the case */
/* of a frequency serie (double) */
/* 3) (optional) frequency values in the case of time series (double)*/
/* 4) (optional) GPS starting time (in second.nanosec) */
/* 5) (optional) starting time as a string */
/* 6) (optional) ADC comment as a string */
/* 7) (optional) ADC unit as a string */
/* 8) (optional) additional info: it is a 9 words vector which */
/* content:crate #, channel#, nBits#, biais, slope, */
/* sampleRate, timeOffset(S.N), fShift, overRange */
/* All this values are stored as double */
/*---------------------------------------------------------------------*/
#include "mex.h"
#include "FrameL.h"
void mexFunction( int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{FrFile *iFile;
FrameH *frame;
FrAdcData *adc;
FrVect *vect;
FrProcData *proc;
int status, first, nFrames;
long buffSize, debugLvl, i, nBin, nData, index, utc;
double *data, *datai, dt, df, sampleRate;
char *buff, *name, fileName[100],adcName[100], *comment, *units;
/*--------------- check arguments ---------------------*/
if(nrhs<2)
{mexErrMsgTxt("Please provide the file name(s) and ADC or PROC name as argument\n");
return;}
if(!mxIsChar(prhs[0]))
{mexErrMsgTxt("The first arguement is not a filename\n");
return;}
if(!mxIsChar(prhs[1]))
{mexErrMsgTxt("The second arguement is not the adc name \n");
return;}
if(nlhs==0)
{mexErrMsgTxt("Please provide at least one output argument\n");
return;}
if(nrhs > 2)
{data = mxGetPr(prhs[2]);
first = data[0];}
else{first = 0;}
if(nrhs > 3)
{data = mxGetPr(prhs[3]);
nFrames = data[0];}
else{nFrames = 1;}
if(nrhs > 4)
{data = mxGetPr(prhs[4]);
debugLvl = data[0];
FrLibSetLvl(debugLvl);}
else{debugLvl = 0;}
/*----------- open file --------------------------*/
status=mxGetString(prhs[0],fileName,100);
status=mxGetString(prhs[1],adcName,100);
if(debugLvl > 0)
{mexPrintf(" Open file:%s for channel:%s\n",fileName,adcName);
mexPrintf(" first frame:%d nFrames=%d\n",first,nFrames);}
iFile = FrFileINew(fileName);
if(iFile == NULL)
{mexPrintf("Error during file opening\n"
" Last errors are:\n%s",FrErrorGetHistory());
return;}
/*--------- read the first frame ------------------*/
while((frame = FrameRead(iFile)) != NULL)
{
if(debugLvl > 0) mexPrintf(" Frame %d run %d GPS : %d\n",
frame->frame, frame->run,frame->GTimeS);
if(first == 0) break;
if(frame->frame >= first) break;
FrameFree(frame);}
if(frame == NULL)
{FrFileIEnd(iFile);
return;}
/*------ find ADC and create output matrix ---------*/
adc = FrAdcDataFind(frame,adcName);
if(adc != NULL)
{vect = adc->data;
nBin = adc->data->nData;
sampleRate = adc->sampleRate;
comment = adc->comment;
units = adc->units;}
else if((proc = FrProcDataFind(frame, adcName)) != NULL)
{vect = proc->data;
nBin = proc->data->nData;
dt = vect->dx[0];
sampleRate = 1./vect->dx[0];
comment = proc->comment;
units = proc->data->unitY;}
else
{FrFileIEnd(iFile);
FrameFree(frame);
return;}
nData = nBin*nFrames;
dt = 1./sampleRate;
df = sampleRate/((double)nData);
if ( vect->type == FR_VECT_8C || vect->type == FR_VECT_16C ) {
plhs[0] = mxCreateDoubleMatrix(nData,1,mxCOMPLEX);
} else {
plhs[0] = mxCreateDoubleMatrix(nData,1,mxREAL);
}
/*------ fill time and frequency array ---------------*/
if(nlhs > 1)
{plhs[1] = mxCreateDoubleMatrix(nData,1,mxREAL);
data = mxGetPr(plhs[1]);
for(i=0; i<nData; i++)
{data[i] = (double)i*dt;}}
if(nlhs > 2)
{plhs[2] = mxCreateDoubleMatrix(nData/2,1,mxREAL);
data = mxGetPr(plhs[2]);
for(i=0; i<nData/2; i++)
{data[i] = (double)i*df;}}
if(nlhs > 3)
{plhs[3] = mxCreateDoubleMatrix(1,1,mxREAL);
data = mxGetPr(plhs[3]);
data[0] = (double)frame->GTimeS + 1.e-9*(double)frame->GTimeN;}
if(nlhs > 4)
{utc = frame->GTimeS - frame->ULeapS + FRGPSTAI;
name = mxCalloc(200,sizeof(char));
sprintf(name,"Starting GPS time:%d UTC=%s",frame->GTimeS,FrStrGTime(utc));
plhs[4] = mxCreateString(name);
mxFree(name);}
if(nlhs > 5)
{if(comment != NULL)
{name = mxCalloc(strlen(comment)+1,sizeof(char));
strcpy(name, comment);
plhs[5] = mxCreateString(name);
mxFree(name);}
else{plhs[5] = mxCreateString("no comment");}}
if(nlhs > 6)
{if(units != NULL)
{name = mxCalloc(strlen(units)+1,sizeof(char));
strcpy(name, units);
plhs[6] = mxCreateString(name);
mxFree(name);}
else{plhs[6] = mxCreateString("no unit");}}
if(nlhs > 7)
{plhs[7] = mxCreateDoubleMatrix(1,9,mxREAL);
data = mxGetPr(plhs[7]);
if(adc != NULL)
{data[0] = (double) adc->channelGroup;
data[1] = (double) adc->channelNumber;
data[2] = (double) adc->nBits;
data[3] = (double) adc->bias;
data[4] = (double) adc->slope;
data[5] = (double) sampleRate;
data[6] = (double) adc->timeOffset;
data[7] = (double) adc->fShift;
data[8] = (double) adc->dataValid;
vect = adc->data;}
else
{data[0] = (double) 0;
data[1] = (double) 0;
data[2] = (double) proc->data->wSize;
data[3] = (double) 0;
data[4] = (double) 0;
data[5] = (double) sampleRate;
data[6] = (double) proc->timeOffset;
data[7] = (double) proc->fShift;
data[8] = (double) 0;
vect = proc->data;}}
/*-------- copy data and read the next frames -------*/
data = mxGetPr(plhs[0]);
datai = mxGetPi(plhs[0]);
index = 0;
while(1)
{if(vect == NULL)
{mexPrintf(" no data for frame %ld\n",frame->frame);}
else if(vect->type == FR_VECT_C)
{for(i=0; i<nBin; i++) {data[i+index] = vect->data[i];}}
else if(vect->type == FR_VECT_2S)
{for(i=0; i<nBin; i++) {data[i+index] = vect->dataS[i];}}
else if(vect->type == FR_VECT_4S)
{for(i=0; i<nBin; i++) {data[i+index] = vect->dataI[i];}}
else if(vect->type == FR_VECT_8S)
{for(i=0; i<nBin; i++) {data[i+index] = vect->dataL[i];}}
else if(vect->type == FR_VECT_1U)
{for(i=0; i<nBin; i++) {data[i+index] = vect->dataU[i];}}
else if(vect->type == FR_VECT_2U)
{for(i=0; i<nBin; i++) {data[i+index] = vect->dataUS[i];}}
else if(vect->type == FR_VECT_4U)
{for(i=0; i<nBin; i++) {data[i+index] = vect->dataUI[i];}}
else if(vect->type == FR_VECT_8U)
{for(i=0; i<nBin; i++) {data[i+index] = vect->dataUL[i];}}
else if(vect->type == FR_VECT_4R)
{for(i=0; i<nBin; i++) {data[i+index] = vect->dataF[i];}}
else if(vect->type == FR_VECT_8R)
{for(i=0; i<nBin; i++) {data[i+index] = vect->dataD[i];}}
else if(vect->type == FR_VECT_8C)
{
for(i=0; i<nBin; i++) {
data[i+index] = vect->dataF[2*i];
datai[i+index] = vect->dataF[2*i+1];
}
}
else if(vect->type == FR_VECT_16C)
{
for(i=0; i<nBin; i++) {
data[i+index] = vect->dataD[2*i];
datai[i+index] = vect->dataD[2*i+1];
}
}
else
{mexPrintf("Error: cannot handle the data type of this vector\n");
return;}
index += nBin;
FrameFree(frame);
frame = FrameRead(iFile);
if(frame == NULL) break;
if(index >= nFrames*nBin) break;
vect = FrameFindVect(frame,adcName);}
if(frame != NULL) FrameFree(frame);
FrFileIEnd(iFile); /* Close file and release descriptor */
}
/*---------------------------------------------------------------------*/
/* FrGetVect.c by B. Mours Caltech&LAPP May 2, 2002 */
/* */
/* This Matlab mex file extract from a frame file the data for one */
/* vector (ADC ot Proc or Sim data) (this is for Matlab version 5) */
/* */
/* The input arguments are: */
/* 1) file name(s). This could be a single file, a list of file */
/* separeted by space or a frame file list (ffl) */
/* 2) channel name (it could be an ADC, SIM or PROC channel) */
/* 3) (optional) starting GPS time(default= first frame in the file) */
/* 4) (optional) vector length in second (default = 1 second) */
/* 5) (optional) debug level (default = 0 = no output) */
/* */
/* Returned matlab data: */
/* 1) ADC or SIM or PROC data stored as double */
/* 2) (optional) x axis values relative to the first data point. */
/* This is usual time but it could be frequency in the case */
/* of a frequency serie (double) */
/* 3) (optional) frequency values in the case of time series (double)*/
/* 4) (optional) GPS starting time (in second, stored in double) */
/* 5) (optional) starting time as a string */
/* 6) (optional) vector unitX as a string */
/* 7) (optional) vector unitY as a string */
/* All values are stored as double */
/* */
/* Warning types: */
/* frgetvect:info -- informational messages */
/* frgetvect:dt==0 -- channel metadata dt == 0 */
/* */
/* Error types: */
/* frgetvect:inputArgCount -- too many or too few input arguments */
/* frgetvect:outputArgCount -- too many or too few output arguments*/
/* frgetvect:inputArg -- first two arguments are not strings */
/* frgetvect:mxGetStringFail -- memory allocation failure */
/* frgetvect:fileOpen -- failure to open file */
/* frgetvect:channelNotFound -- channel not in frame */
/* frgetvect:noMatlabType -- no matlab type for channel data */
/*---------------------------------------------------------------------*/
#include "mex.h"
#include "FrameL.h"
void mexFunction( int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
struct FrFile *iFile;
struct FrVect *vect;
int status;
long debugLvl, i, nData, utc, t0;
int nFrames;
double *data, *datai, dt, df;
char *name, fileName[100],vectName[100];
/*--------------- check arguments ---------------------*/
if (nrhs < 2 || nrhs > 5)
{
const char *msgId = "frgetvect:inputArgCount";
mexErrMsgIdAndTxt(
msgId,"%s:nRhs = %d, must be between 2 and 5",
msgId,nrhs);
}
if (nlhs < 1 || nlhs > 7)
{
const char *msgId = "frgetvect:outputArgCount";
mexErrMsgIdAndTxt(
msgId,"%s: nLhs = %d, must be between 1 and 7",
msgId,nlhs);
}
if(!mxIsChar(prhs[0]))
{
const char *msgId = "frgetvect:inputArg";
mexErrMsgIdAndTxt(msgId,"%s: first arg must be filename",msgId);
}
if(!mxIsChar(prhs[1]))
{
const char *msgId = "frgetvect:inputArg";
const char *msg = "%s: second arg must be channel name";
mexErrMsgIdAndTxt(msgId,msg,msgId);
}
if(nrhs > 2)
{
data = mxGetPr(prhs[2]);
t0 = data[0];
}
else
{
t0 = 0;
}
if(nrhs > 3)
{
data = mxGetPr(prhs[3]);
nFrames = data[0];
}
else
{
nFrames = 1;
}
if(nrhs > 4)
{
data = mxGetPr(prhs[4]);
debugLvl = data[0];
FrLibSetLvl(debugLvl);
}
else
{
debugLvl = 0.0;
FrLibSetLvl(debugLvl);
}
/*
{
const char* msgId = "frgetvect:info";