Home > eeg > egis > egis_file_utils > rd_egis_hdr_v.m

rd_egis_hdr_v

PURPOSE ^

[fhdr,chdr,ename,czeros,cgains,cnames,fcom,ftext, coff]=rd_egis_hdr_v(fid)

SYNOPSIS ^

function [fhdr,chdr,ename,czeros,cgains,cnames,fcom,ftext,coff]=rd_egis_hdr_v(fid)

DESCRIPTION ^

[fhdr,chdr,ename,czeros,cgains,cnames,fcom,ftext, coff]=rd_egis_hdr_v(fid)

This reads the header of an EGIS file (either .ave or .ses) into two matrices.
The first is a row vector containing one element for each field of the 
description, file info, and session info sections. This vector has room 
for NCells LCellHdr variables, beggining at column 24. The second matrix
has NCells rows and a column for each field of the header. The Trial
Specifics begin in column 6. Room is left for the maximum of LSpec/2 2-byte
values per trial. The files 'ses_hdr_offsets.m' and 'ave_hdr_offsets.m' provide
index definitions for the columns of the matrices returned by this function. 

For example the length of the data portion of an EGIS file can be found by

    [my_fhdr, my_chdr]=rd_egis_hdr_v(my)
    L=my_fhdr(LData)

The ExptNam, Cellname, and flexible area fields are optionally read  
this function. To retrieve them add return arguments in the following
order: exp. name, zeros, gains, cell names, comment, text. Arguments
cannot be skipped, i.e. the first extra argument always returns the
exp. name.

The function also optionally returns the physical offsets of the beginning of each
cell's data if coff is passed in the output parameter list

See Also:ses_hdr_offsets_v, ave_hdr_offsets_v, wt_ses_hdr_v, get_tspec_v, get_tspecs_v.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [fhdr,chdr,ename,czeros,cgains,cnames,fcom,ftext,coff]=rd_egis_hdr_v(fid)
0002 %[fhdr,chdr,ename,czeros,cgains,cnames,fcom,ftext, coff]=rd_egis_hdr_v(fid)
0003 %
0004 %This reads the header of an EGIS file (either .ave or .ses) into two matrices.
0005 %The first is a row vector containing one element for each field of the
0006 %description, file info, and session info sections. This vector has room
0007 %for NCells LCellHdr variables, beggining at column 24. The second matrix
0008 %has NCells rows and a column for each field of the header. The Trial
0009 %Specifics begin in column 6. Room is left for the maximum of LSpec/2 2-byte
0010 %values per trial. The files 'ses_hdr_offsets.m' and 'ave_hdr_offsets.m' provide
0011 %index definitions for the columns of the matrices returned by this function.
0012 %
0013 %For example the length of the data portion of an EGIS file can be found by
0014 %
0015 %    [my_fhdr, my_chdr]=rd_egis_hdr_v(my)
0016 %    L=my_fhdr(LData)
0017 %
0018 %The ExptNam, Cellname, and flexible area fields are optionally read
0019 %this function. To retrieve them add return arguments in the following
0020 %order: exp. name, zeros, gains, cell names, comment, text. Arguments
0021 %cannot be skipped, i.e. the first extra argument always returns the
0022 %exp. name.
0023 %
0024 %The function also optionally returns the physical offsets of the beginning of each
0025 %cell's data if coff is passed in the output parameter list
0026 %
0027 %See Also:ses_hdr_offsets_v, ave_hdr_offsets_v, wt_ses_hdr_v, get_tspec_v, get_tspecs_v.
0028 
0029 %Modification History:
0030 %    Adapted by Petr Janata from rd_ses_hdr_v.m  6/14/95
0031 %    LHeader read as a 'uint16' 4-30-96 - BCR
0032 %
0033 %Modification History from rd_ses_hdr_v.m
0034 %
0035 %    Orginal Version by Brian Rakitin, 3/2/95
0036 %    Output of rest of header added by BCR, 3/12/95
0037 
0038 
0039 %Check number of arguments
0040 if nargin ~=1 | fid==-1
0041     error('Script cut_by_specs requires a valid file id as input.')
0042 end
0043 if nargout == 0 
0044     error('Script rd_egis_hdr_v requires at least two matrix output arguments.')
0045 else if nargout >= 10
0046     error('Too many output arguments.')
0047   end
0048 end
0049 
0050 %Prep file for reading
0051 fhdr=zeros(1,23);
0052 status=fseek(fid,0,'bof');
0053 %Read in fhdr fields.
0054 fhdr(1)=fread(fid,1,'int32'); %BytOrd
0055 fhdr(2)=fread(fid,1,'int16'); %HdrVer
0056 fhdr(3)=fread(fid,1,'uint16'); %LHeader
0057 fhdr(4)=fread(fid,1,'int32'); %LData
0058 status=fseek(fid,80,'cof'); %Skip ExptNam
0059 fhdr(5:10)=fread(fid,6,'int16'); %RunDate and RunTime
0060 
0061 fhdr(11:23)=fread(fid,13,'int16'); %Everything else up to LCellHdr
0062 
0063 fhdr(24:(24+fhdr(18)-1))=fread(fid,fhdr(18),'int16'); %LCellHdr for each cell
0064 
0065 %Read in chdr
0066 if nargout >=2 
0067     chdr=zeros(fhdr(18),5);
0068     status=fseek(fid,(4*fhdr(19)),'cof');
0069     for loop=1:fhdr(18)
0070         chdr(loop,1)=fread(fid,1,'int16');
0071         status=fseek(fid,80,'cof');
0072         chdr(loop, 2:5)=(fread(fid,4,'int16'))';
0073         lspectot=(chdr(loop,2)*(chdr(loop,5)/2));
0074         lastcol=(6+lspectot-1);
0075         if lastcol >= 6
0076           chdr(loop,lastcol)=0;
0077           chdr(loop,6:lastcol)=(fread(fid,lspectot,'int16'))';
0078         end
0079     end
0080 else
0081     return
0082 end
0083 
0084 %Read experiment name if necessary
0085 if nargout >= 3 
0086     status=fseek(fid,12,'bof');
0087     tempstr=fread(fid,80,'char');
0088     ename=setstr(tempstr);
0089 else 
0090     return
0091 end
0092 
0093 %Read  zeros if necessary
0094 if nargout >= 4
0095     status=fseek(fid,(130+(2*fhdr(18))),'bof');
0096     czeros=fread(fid,(fhdr(19)),'int16');
0097 else
0098     return
0099 end
0100 
0101 %Read gains if necessary
0102 if nargout >= 5
0103     status=fseek(fid,(130+(2*fhdr(18))+(2*fhdr(19))),'bof');
0104     cgains=fread(fid,(fhdr(19)), 'int16');
0105 else
0106     return
0107 end
0108 
0109 %Read cellnames if necesaary
0110 if nargout >= 6
0111     status=fseek(fid,(130+(2*fhdr(18))+(4*fhdr(19))),'bof');
0112     status=fseek(fid,2,'cof');
0113     for loop=1:fhdr(18)
0114         cnames(loop,:)=setstr(fread(fid,80,'char')');
0115         status=fseek(fid,fhdr(24+(loop-1))-80,'cof');
0116     end
0117 else
0118     return
0119 end
0120         
0121 %Read comment if necessary
0122 if nargout >= 7
0123     status=fseek(fid,fhdr(3),'bof');
0124     status=fseek(fid,-(fhdr(22)+fhdr(21)+fhdr(20)),'cof');
0125     fcom=fread(fid,fhdr(20),'char');
0126 else
0127     return
0128 end
0129 
0130 %Read text if necessary
0131 if nargout >= 8
0132     status=fseek(fid,fhdr(3),'bof');
0133     status=fseek(fid,-(fhdr(22)+fhdr(21)),'cof');
0134     ftext=fread(fid,fhdr(21),'char');
0135 else
0136     return
0137 end
0138 
0139 %Read cell offsets if necessary
0140 if nargout >= 9
0141     coff=get_cell_offsets(fhdr, chdr);
0142 else
0143     return
0144 end
0145

Generated on Wed 20-Sep-2023 04:00:50 by m2html © 2003