Home > eeg > egis > egis_file_utils > wt_csdm_hdr_v.m

wt_csdm_hdr_v

PURPOSE ^

[status]=wt_csdm_hdr_v(fid,fhdr,chdr,ename,cnames,fcom,ftext)

SYNOPSIS ^

function [status]=wt_csdm_hdr_v(fid,infhdr,inchdr,ename,cnames,fcom,ftext);

DESCRIPTION ^

[status]=wt_csdm_hdr_v(fid,fhdr,chdr,ename,cnames,fcom,ftext)


 1/10/96 PJ Changing calculation of LData to reflect fact that 4-byte floats
         are now being written

 1/9/96  PJ & RS Length of Header is being written into old BytOrd field
         This gives it int32 representation to handle overly large header.

This function creates a new EGIS average file header in the file with id fid.
The structures which are passed to this routine are the same as
are returned from function rd_ses_hdr_v (c.f.) and which are
passed to wt_ses_hdr_v.  
This routine reformats the file header and recalculates its size.
The total number of elements written is returned.
Note that this number is NOT the header size in bytes.

NOTE:     The NObs (NTrials) and NAvg (number of trials in average) fields in 
        the Average Cell Specifics must be set prior to calling this routine
        The same if true for the LastDone field of fhdr (Average File Description)

See also:rd_ses_hdr_v.m

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [status]=wt_csdm_hdr_v(fid,infhdr,inchdr,ename,cnames,fcom,ftext);
0002 %[status]=wt_csdm_hdr_v(fid,fhdr,chdr,ename,cnames,fcom,ftext)
0003 %
0004 %
0005 % 1/10/96 PJ Changing calculation of LData to reflect fact that 4-byte floats
0006 %         are now being written
0007 %
0008 % 1/9/96  PJ & RS Length of Header is being written into old BytOrd field
0009 %         This gives it int32 representation to handle overly large header.
0010 %
0011 %This function creates a new EGIS average file header in the file with id fid.
0012 %The structures which are passed to this routine are the same as
0013 %are returned from function rd_ses_hdr_v (c.f.) and which are
0014 %passed to wt_ses_hdr_v.
0015 %This routine reformats the file header and recalculates its size.
0016 %The total number of elements written is returned.
0017 %Note that this number is NOT the header size in bytes.
0018 %
0019 %NOTE:     The NObs (NTrials) and NAvg (number of trials in average) fields in
0020 %        the Average Cell Specifics must be set prior to calling this routine
0021 %        The same if true for the LastDone field of fhdr (Average File Description)
0022 %
0023 %See also:rd_ses_hdr_v.m
0024 
0025 %  Modification history:
0026 %    6/6/95    PJ    Created the file based on wt_ses_hdr_v
0027 %
0028 
0029 size_data_value = 4;  % 4=float
0030 
0031 csdm_hdr_offsets_v;
0032 
0033 fhdr = infhdr;
0034 chdr = inchdr;
0035 
0036 %
0037 % Perform necessary transformations on the header
0038 %
0039 
0040 %% Modify Average File Description
0041     fhdr(HdrVer) = -1;
0042     
0043 %% Modify Average Information
0044     fhdr(5:10) = zeros(1,6);
0045     fhdr(ScaleBins) = 500;
0046     fhdr(ScaleCal) = 50;
0047     fhdr(BaseDur) = 0;
0048     fhdr(15:17) = zeros(1,3);
0049 
0050 %% Modify Average File Data Description
0051     if (fhdr(NChan) == 64 | fhdr(NChan) == 128)
0052         fhdr(NChan) = fhdr(NChan) + 1;    % add a channel now that the average reference has been computed
0053     end
0054     
0055 %% Modify Average Cell Headers
0056 if any(chdr(:, LSpec) < 28)
0057   error(['Length of specs in cell(s) [' find(chdr(:,LSpec) < 28) '] is less than required minimum']);
0058 end
0059 
0060 if infhdr(HdrVer) == 1    % session file
0061     ses_hdr_offsets_v;
0062     chdr(:,RunDateMo_Ave) = ones(fhdr(NCells),1).*infhdr(RunDateMo);
0063     chdr(:,RunDateDay_Ave) = ones(fhdr(NCells),1).*infhdr(RunDateDay);
0064     chdr(:,RunDateYr_Ave) = ones(fhdr(NCells),1).*infhdr(RunDateYr);
0065     chdr(:,RunTimeHr_Ave) = ones(fhdr(NCells),1).*infhdr(RunTimeHr);
0066     chdr(:,RunTimeMin_Ave) = ones(fhdr(NCells),1).*infhdr(RunTimeMin);
0067     chdr(:,RunTimeSec_Ave) = ones(fhdr(NCells),1).*infhdr(RunTimeSec);
0068     chdr(:,SubjID_Ave) = ones(fhdr(NCells),1).*infhdr(SubjID);
0069     chdr(:,Handed_Ave) = ones(fhdr(NCells),1).*infhdr(Handed);
0070     chdr(:,Sex_Ave) = ones(fhdr(NCells),1).*infhdr(Sex);
0071     chdr(:,Age_Ave) = ones(fhdr(NCells),1).*infhdr(Age);
0072     chdr(:,ExperID_Ave) = ones(fhdr(NCells),1).*infhdr(ExperID);
0073     chdr(:,EdVer_Ave) = ones(fhdr(NCells),1).*infhdr(EdVer);
0074     chdr(:,CalFlag_Ave) = ones(fhdr(NCells),1);
0075 end
0076 
0077 %% Recompute header length
0078 
0079 %disp('Computing length variables in header of average EGIS file...')
0080 L = ((chdr(:,LSpec).*chdr(:,NObs))'+90);
0081 fhdr(LCellHdr:(LCellHdr+(fhdr(NCells)-1))) = L';
0082 nlcellhdr = fhdr(NCells)*2;
0083 lhdr = 130+nlcellhdr+ fhdr(NChan) * 4 + sum(L)+fhdr(LComment)+fhdr(LText);
0084 fhdr(LPad) = (512-rem(lhdr,512));
0085 lhdr = lhdr+fhdr(LPad);
0086 fhdr(LHeader_CSDM) = lhdr;
0087 fhdr(LData) = sum((chdr(:,NPoints).*chdr(:,NObs))*fhdr(NChan))*size_data_value;
0088 
0089 status=fseek(fid,0,'bof');
0090 status=fwrite(fid,fhdr(LHeader_CSDM),'int32');
0091 message=ferror(fid);
0092 if message ~= '',error(message),end
0093 
0094 status=fwrite(fid,fhdr(HdrVer),'int16');
0095 message=ferror(fid);
0096 if message ~= '', error(message),end
0097 
0098 status=fwrite(fid,fhdr(LHeader),'int16');
0099 message=ferror(fid);
0100 if message ~= '',error(message),end
0101 
0102 status=fwrite(fid,fhdr(LData),'int32');
0103 message=ferror(fid);
0104 if message ~= '',error(message),end
0105 
0106 status=fwrite(fid,abs(ename),'char');
0107 message=ferror(fid);
0108 if message ~= '',error(message),end
0109 
0110 status=fwrite(fid,zeros(6,1),'int16');  % empty fields -- run date and time in ses files
0111 message=ferror(fid);
0112 if message ~= '',error(message),end
0113 
0114 status=fwrite(fid,fhdr(LastDone:BaseDur),'int16');
0115 message=ferror(fid);
0116 if message ~= '',error(message),end
0117 
0118 status=fwrite(fid,zeros(3,1),'int16');
0119 message=ferror(fid);
0120 if message ~= '',error(message),end
0121 
0122 status=fwrite(fid,fhdr(NCells:BrdGain),'int16');
0123 message=ferror(fid);
0124 if message ~= '',error(message),end
0125 
0126 status=fwrite(fid,fhdr(LCellHdr:(LCellHdr+(fhdr(NCells)-1))),'int16');
0127 message=ferror(fid);
0128 if message ~= '',error(message),end
0129 
0130 status=fwrite(fid,zeros(fhdr(NChan)*2, 1),'int16');  % fill with zeros
0131 message=ferror(fid);
0132 if message ~= '',error(message),end
0133 
0134 for loop=1:fhdr(NCells)
0135     status=fwrite(fid,chdr(loop,CellID),'int16');
0136     message=ferror(fid);
0137     if message ~= '',error(message),end
0138     status=fwrite(fid,abs(cnames(loop,:)),'char');
0139     message=ferror(fid);
0140     if message ~= '',error(message),end
0141     lastrow=5+((chdr(loop,LSpec)/2)*chdr(loop,NObs));
0142     status=fwrite(fid,chdr(loop,NObs:lastrow),'int16');
0143     message=ferror(fid);
0144     if message ~= '',error(message),end
0145 end
0146 
0147 status=fwrite(fid,fcom,'char');
0148 message=ferror(fid);
0149 if message ~= '',error(message),end
0150 
0151 status=fwrite(fid,ftext,'char');
0152 message=ferror(fid);
0153 if message ~= '',error(message),end
0154 
0155 status=fwrite(fid,zeros(fhdr(LPad),1),'char');
0156 message=ferror(fid);
0157 if message ~= '',error(message),end
0158 
0159 status = 0;
0160 disp(['Successfully wrote the average file header. ' '(' num2str(fhdr(LHeader_CSDM)) ' bytes long)']);

Generated on Sat 24-Aug-2019 04:00:39 by m2html © 2003