0001 function [status]=wt_csdm_hdr_v(fid,infhdr,inchdr,ename,cnames,fcom,ftext);
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 size_data_value = 4;
0030
0031 csdm_hdr_offsets_v;
0032
0033 fhdr = infhdr;
0034 chdr = inchdr;
0035
0036
0037
0038
0039
0040
0041 fhdr(HdrVer) = -1;
0042
0043
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
0051 if (fhdr(NChan) == 64 | fhdr(NChan) == 128)
0052 fhdr(NChan) = fhdr(NChan) + 1;
0053 end
0054
0055
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
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
0078
0079
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');
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');
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)']);