0001 function [F,time_labels,Rcoils,Ocoils,stim_num,coilWeights,nc_montage,bad_channels_list,baseline_variance,EEGwf, ...
0002 EEGpickupLoc,EEGreferenceLoc,EEGpickupRadius,EEGreferenceRadius,success] = load_AvgNetCDFv5( ...
0003 ncfnames,stim_num)
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
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042 success = 1;
0043
0044
0045 [nfiles,d] = size(ncfnames);
0046 Rcoils = [];
0047 Ocoils = [];
0048
0049
0050 for ifile = 1:nfiles
0051
0052
0053 filename = ncfnames(ifile,:);
0054 nc = netcdf(filename,'nowrite');
0055
0056
0057 variables = var(nc);
0058 var_names = ncnames(variables);
0059
0060
0061 nc_montage = nc.MontageName(:);
0062 bad_channels_list = nc.BadChannelsDeleted(:);
0063 nc_version = nc.netCDFfileVersion(:);
0064
0065 samp_int = nc{'SamplingInterval'}(:);
0066 prestim = nc{'LengthOfPrestim'}(stim_num);
0067 npts = nc{'numSamples'}(stim_num);
0068
0069 time_labels = (0:npts-1)*samp_int - prestim;
0070
0071 if (strcmp(nc_version(7:9),'1.1') | strcmp(nc_version(7:9),'1.2') )
0072 disp(' ')
0073 disp('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ')
0074 disp('ERROR: ')
0075 disp('Your netMEG file is an obsolete version.')
0076 disp('You can read it into MEGAN to update it.')
0077 disp('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ')
0078 disp(' ')
0079 success = 0;
0080 return
0081 end
0082 if (strcmp(nc_version(7:9),'1.3') )
0083 disp('Your netMEG file is a bad version.')
0084 disp('Only a few of these files exist. There is no')
0085 disp('way to update them. Please discard the file.')
0086 success = 0;
0087 return
0088 end
0089
0090
0091 ind = find(strcmp(var_names,'ChannelTypes'));
0092 if length(ind) ~= 0
0093 ChannelTypes = nc{'ChannelTypes'}(:);
0094 else
0095 disp('Returning: netMEG Error reading reading ChannelTypes')
0096 success = 0;
0097 return;
0098 end
0099 [nchans,dummy] = size(ChannelTypes);
0100
0101
0102
0103 ind = find(strcmp(var_names,'ChannelStatus'));
0104 if length(ind) ~= 0
0105 ChannelStatus = nc{'ChannelStatus'}(:);
0106 else
0107 ChannelStatus = ones(nchans(1),1)
0108 end
0109
0110
0111
0112
0113
0114
0115 ind = find(strcmp(var_names,'EEGpickupLocation'));
0116 if length(ind) ~= 0
0117 EEGpickupLoctmp = nc{'EEGpickupLocation'}(:);
0118 [neeg_sensors,dummy] = size(EEGpickupLoctmp);
0119 else
0120 neeg_sensors = 0;
0121 end
0122
0123 if neeg_sensors > 0
0124 ind = find(strcmp(var_names,'EEGreferenceLocation'));
0125 if length(ind) ~= 0
0126 EEGreferenceLoctmp = nc{'EEGreferenceLocation'}(:);
0127 else
0128 disp('Returning: netMEG Error reading EEGreferenceLocation')
0129 success = 0;
0130 return;
0131 end
0132
0133 ind = find(strcmp(var_names,'EEGpickupRadius'));
0134 if length(ind) ~= 0
0135 EEGpickupRadiustmp = nc{'EEGpickupRadius'}(:);
0136 else
0137 disp('Returning: netMEG Error reading EEGpickupRadius')
0138 success = 0;
0139 return;
0140 end
0141
0142 ind = find(strcmp(var_names,'EEGreferenceRadius'));
0143 if length(ind) ~= 0
0144 EEGreferenceRadiustmp = nc{'EEGreferenceRadius'}(:);
0145 else
0146 disp('Returning: netMEG Error reading EEGreferenceRadius')
0147 success = 0;
0148 return;
0149 end
0150 end
0151
0152
0153
0154
0155 good_MEG_indices = find(ChannelTypes(:,1)=='M' & ChannelTypes(:,2) == 'E' & ...
0156 ChannelTypes(:,3) == 'G' & ChannelStatus == 1);
0157 ngood_MEG = size(good_MEG_indices,1);
0158
0159 if (neeg_sensors > 0)
0160 good_EEG_indices = find(ChannelTypes(:,1)=='E' & ChannelTypes(:,2) == 'E' & ...
0161 ChannelTypes(:,3) == 'G' & ChannelStatus == 1);
0162 EEG_indices = find(ChannelTypes(:,1)=='E' & ChannelTypes(:,2) == 'E' & ...
0163 ChannelTypes(:,3) == 'G' );
0164 EEG_sensor_status = ChannelStatus(EEG_indices);
0165 good_EEG_sensors = find(EEG_sensor_status == 1);
0166
0167 ngood_EEG = size(good_EEG_indices,1);
0168 if ifile == 1
0169 EEGpickupLoc = EEGpickupLoctmp(good_EEG_sensors,:)';
0170 EEGreferenceLoc = EEGreferenceLoctmp(good_EEG_sensors,:)';
0171 EEGpickupRadius = EEGpickupRadiustmp(good_EEG_sensors);
0172 EEGreferenceRadius = EEGreferenceRadiustmp(good_EEG_sensors);
0173 else
0174 EEGpickupLoc = [EEGpickupLoc,EEGpickupLoctmp(good_EEG_sensors,:)'];
0175 EEGreferenceLoc = [EEGreferenceLoc,EEGreferenceLoctmp(good_EEG_sensors,:)'];
0176 EEGpickupRadius = [EEGpickupRadius;EEGpickupRadiustmp(good_EEG_sensors)];
0177 EEGreferenceRadius = [EEGreferenceRadius;EEGreferenceRadiustmp(good_EEG_sensors)];
0178 end
0179 else
0180 ngood_EEG = 0;
0181 EEGpickupLoc = 0;
0182 EEGreferenceLoc = 0;
0183 EEGpickupRadius = 0;
0184 EEGreferenceRadius = 0;
0185 end
0186
0187 if (ngood_MEG > 0 )
0188
0189
0190
0191 ind = find(strcmp(var_names,'SensorElementsOrient'));
0192 if length(ind) ~= 0
0193 SensorElementsOrient = nc{'SensorElementsOrient'}(:);
0194 else
0195 disp('Returning: netMEG Error reading SensorElementsOrient')
0196 success = 0;
0197 return;
0198 end
0199
0200 ind = find(strcmp(var_names,'SensorElementsLoc'));
0201 if length(ind) ~= 0
0202 SensorElementsLoc = nc{'SensorElementsLoc'}(:);
0203 else
0204 disp('Returning: netMEG Error reading SensorElementsLoc')
0205 success = 0;
0206 return;
0207 end
0208
0209 [dum1,max_sens_elem,dum2] = size(SensorElementsLoc);
0210
0211
0212
0213
0214
0215 for igood = 1:ngood_MEG
0216 isn = good_MEG_indices(igood);
0217 coil_loc = reshape(SensorElementsLoc(isn,:,:),max_sens_elem,3);
0218 sens_orient = reshape(SensorElementsOrient(isn,:,:),max_sens_elem,3);
0219
0220
0221 if ifile == 1 & igood == 1
0222 Rcoils = [coil_loc(1,:)];
0223 Ocoils = [sens_orient(1,:)];
0224 for j = 2: max_sens_elem
0225 Rcoils = [Rcoils,coil_loc(j,:)];
0226 Ocoils = [Ocoils,sens_orient(j,:)];
0227 end
0228 else
0229 Rcoils_row = [coil_loc(1,:)];
0230 Ocoils_row = [sens_orient(1,:)];
0231 for j = 2: max_sens_elem
0232 Rcoils_row = [Rcoils_row,coil_loc(j,:)];
0233 Ocoils_row = [Ocoils_row,sens_orient(j,:)];
0234 end
0235 Rcoils = [Rcoils;Rcoils_row];
0236 Ocoils = [Ocoils;Ocoils_row];
0237 end
0238 end
0239
0240
0241
0242
0243 ind = find(strcmp(var_names,'CoilWeight'));
0244 if length(ind) ~= 0
0245 coilWeight = nc{'CoilWeight'}(:);
0246 else
0247 disp('Returning: netMEG Error reading CoilWeight')
0248 success = 0;
0249 return;
0250 end
0251 coilWeights = coilWeight(1,:)';
0252
0253
0254 ind = find(strcmp(var_names,'BaselineVariance'));
0255 if length(ind) ~= 0
0256 baseline_variance_tmp = nc{'BaselineVariance'}(:);
0257 else
0258 disp('Returning: netMEG Error reading BaselineVariance')
0259 success = 0;
0260 return;
0261 end
0262
0263 end
0264
0265
0266
0267
0268 ind = find(strcmp(var_names,'Waveforms'));
0269 if length(ind) ~= 0
0270 Ftmp = nc{'Waveforms'}(stim_num,1:npts,:);
0271 [np,nch,dum] = size(Ftmp);
0272 Ftmp = Ftmp';
0273 else
0274 disp('Returning: netMEG Error reading Waveforms')
0275 success = 0;
0276 return;
0277 end
0278
0279
0280 if (ngood_MEG > 0)
0281 if ifile == 1
0282 F = Ftmp(good_MEG_indices,:);
0283 baseline_variance = baseline_variance_tmp(stim_num,good_MEG_indices)';
0284 else
0285 F = [F ; Ftmp(good_MEG_indices,:)];
0286 baseline_variance = [baseline_variance;baseline_variance_tmp(stim_num,good_MEG_indices)'];
0287 end
0288 end
0289
0290
0291 if (ngood_EEG > 0)
0292
0293 if ifile == 1
0294 EEGwf = Ftmp(good_EEG_indices,:);
0295 else
0296 EEGwf = [EEGwf ; Ftmp(good_EEG_indices,:)];
0297 end
0298 else
0299 EEGwf = 0;
0300 end
0301
0302
0303 nc = close(nc);
0304
0305 end
0306 time_labels = time_labels';
0307
0308 end
0309
0310 return