Home > . > calibsimfd.m

calibsimfd

PURPOSE ^

CALIBSIMFD - converts time-series in strain -> AS-Q counts

SYNOPSIS ^

function [asqSeries, abcache] = calibsimfd(IFO,gpsSec,strainSeries,fs,varargin)

DESCRIPTION ^

 CALIBSIMFD - converts time-series in strain -> AS-Q counts
       -- Uses Frequency-Domain conversion
   asqSeries = calibsimfd(IFO,gpsSec,strainSeries,fs)
   IFO     - IFO name ('H1','H2','L1')
   gpsSec - GPS time of sim (whole seconds)
   strainSeries - time-series vector in strain amplitude
   fs    - time interval of time-series elements
   varargin - holder for filter cache
   
   asqSeries - output time-series vector in AS-Q counts

   [asqSeries,abcache] = calibsim_fd(abcache)
       - abcache is cached Alpha-Beta constants

 NEEDS: read_alphabetafile, h2asq_fd

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [asqSeries, abcache] = calibsimfd(IFO,gpsSec,strainSeries,fs,varargin)
0002 % CALIBSIMFD - converts time-series in strain -> AS-Q counts
0003 %       -- Uses Frequency-Domain conversion
0004 %   asqSeries = calibsimfd(IFO,gpsSec,strainSeries,fs)
0005 %   IFO     - IFO name ('H1','H2','L1')
0006 %   gpsSec - GPS time of sim (whole seconds)
0007 %   strainSeries - time-series vector in strain amplitude
0008 %   fs    - time interval of time-series elements
0009 %   varargin - holder for filter cache
0010 %
0011 %   asqSeries - output time-series vector in AS-Q counts
0012 %
0013 %   [asqSeries,abcache] = calibsim_fd(abcache)
0014 %       - abcache is cached Alpha-Beta constants
0015 %
0016 % NEEDS: read_alphabetafile, h2asq_fd
0017 
0018 % To run, open the OS's .cshrc file and add the following:
0019 % setenv LIGO_CALIB_DATA xxxx
0020 % where xxx is the directory containing the calibration files
0021 
0022 % $Id: calibsimfd.m,v 1.4 2004/05/18 21:19:42 stuver Exp $
0023 inOk = nargchk(nargin,4,5);
0024 outOk = nargchk(nargout,1,2);
0025 if(~inOk | ~outOk)
0026     error ('syntax is [asqSeries[,abcache]] = calibsim_fd(IFO,gpsSec,strainSeries,fs[,abcache])');
0027     return
0028 end
0029 if(nargin > 4)
0030     if length(varargin) > 1
0031         error('varargin only designed for abcache')
0032     else
0033         abcache=varargin{1};
0034     end
0035 else
0036     abcache=[];
0037 end
0038 
0039 % SET file path to LIGO_CALIB_DATA value
0040 % IF calibration directory not defined yet
0041 %   IF calib data environment variable is defined
0042 %       SET calibration directory to calib data environment variable
0043 %   ELSE
0044 %       SET calibration directory to default path
0045 %   ENDIF
0046 % ENDIF
0047 DEFAULT_CALIB_DIR = '/usr/center/raid1/s2/calibration';
0048 persistent calDir;
0049 persistent oldAbFile;
0050 persistent oldOlgFile;
0051 persistent oldSfFile;
0052 if isempty(calDir)
0053     calDir = getenv('LIGO_CALIB_DATA');
0054     if isempty(calDir)
0055         calDir = DEFAULT_CALIB_DIR;
0056         fprintf(' LIGO_CALIB_DATA not defined - use %s\n',calDir);
0057     end    
0058 end
0059 
0060 time=find(abcache >= gpsSec-60 & abcache <= gpsSec-1); % search abcache for filter coefficents
0061 if ~isempty(time) % if the coefficents are cached, use them
0062     alpha=abcache(time,2);
0063     beta=abcache(time,3);
0064 else % if the coefficients are not cached
0065 %   SET alpha, beta file names for IFO
0066 %   IF file path is not empty
0067 %       ADD file path to file name
0068 %   ENDIF
0069 %   IF file does not exist
0070 %       EXIT with error
0071 %   ELSE
0072 %       IF alpha-beta file is new
0073 %           WRITE message to logging
0074 %       ENDIF
0075 %   ENDIF
0076 %   GET alpha, beta values for this GPS time
0077     nd=size(abcache,1)+1;
0078     abFile = strcat(IFO,'AlphaBeta.txt');
0079     if ~isempty(calDir)
0080         abFile = strcat(calDir,'/',abFile);
0081     end
0082     if exist(abFile,'file') == 0
0083         msg = sprintf(' Oops - AlphaBeta file %s not found!\n',abFile);
0084         error(msg);            
0085     else
0086         oldAbFile = checkfilechange(oldAbFile,abFile,'ALPHA-BETA');
0087     end    
0088     duration = 0.5; % read the filter coefficients from file:
0089     [gpsStartMin,alphaRay,betaRay] = read_alphabetafile(abFile,gpsSec,duration);
0090     abcache(nd,1)=gpsStartMin(1); % add this time to the cache
0091     alpha = alphaRay(1);
0092     if alpha==0
0093         alpha=1;
0094     end
0095     beta = betaRay(1);
0096     if beta==0
0097         beta=1;
0098     end
0099     abcache(nd,2)=alpha; % add the newly read coefficents to the cache
0100     abcache(nd,3)=beta;
0101 end
0102 % GET gain, response file names for IFO
0103 % IF file path is not empty
0104 %    ADD file path to file names
0105 % END
0106 % IF gain, response files are new
0107 %   WRITE message to logging
0108 % ENDIF
0109 if(IFO == 'H1')
0110     olgFile = 'H1_olg_734073939.txt';
0111     sfFile = 'H1_sf_734073939.txt';
0112 else 
0113     if( IFO == 'H2')
0114         if(gpsSec < 731849043)
0115             olgFile = 'H2_olg_734234126.txt';
0116             sfFile = 'H2_sf_734234126.txt';
0117         else
0118             olgFile = 'H2_olg_734234127.txt';
0119             sfFile = 'H2_sf_734234127.txt';
0120         end    
0121     else 
0122         if( IFO == 'L1')
0123             olgFile = 'H2_olg_734234126.txt';
0124             sfFile = 'H2_sf_734234126.txt';
0125         end
0126     end
0127 end
0128 if ~isempty(calDir)
0129     olgFile = strcat(calDir,'/',olgFile);
0130     sfFile = strcat(calDir,'/',sfFile);
0131 end
0132 oldOlgFile = checkfilechange(oldOlgFile,olgFile,'OPEN-LOOP GAIN');
0133 oldSfFile = checkfilechange(oldSfFile,sfFile,'SENSING FUNCTION');
0134 % ADD zero-padding to input series (pad on both ends)
0135 % CONVERT input series to AS-Q counts
0136 % REMOVE zero-padding
0137 nsamp = length(strainSeries);
0138 padSeries = zeros([2*nsamp,1]);
0139 nstart  = floor(nsamp/2);
0140 nend = nstart + (nsamp-1);
0141 padSeries(nstart:nend) = strainSeries(1:nsamp);
0142 outSeries = h2asq_fd(olgFile,sfFile,alpha,beta,padSeries,fs);
0143 asqSeries = outSeries(nstart:nend);
0144 return
0145 
0146 function [oldFile] = checkfilechange(oldFile,newFile,fileType)
0147 % CHECKFILECHANGE - write message if file changes
0148 
0149 % IF old file is defined
0150 %   IF new file not the same as old file
0151 %       WRITE message about new file
0152 %       SET old file = new file
0153 %   ENDIF
0154 % ELSE
0155 %   WRITE message about new file
0156 %   SET old file = new file
0157 % ENDIF
0158 if ~isempty(oldFile)
0159     if newFile ~= oldFile
0160         fprintf(' %s file: %s\n',fileType,newFile);
0161         oldFile = newFile;
0162     end
0163 else
0164     fprintf(' %s file: %s\n',fileType,newFile);
0165     oldFile = newFile;
0166 end
0167 return

Generated on Tue 05-Oct-2004 10:40:50 by m2html © 2003