function [csd]=readcortex_savefile(filename) % READCORTEX_SAVEFILE reads a Cortex save file and returns parameters found stored % in the binary ("save" files are a.k.a. "store" or "set" files) % % [csd] = READCORTEX_SAVEFILE(filename) % % NOTE: Works on Cortex and VCortex save files, but only certain versions. % VCortex 1.0-2.1 - tested & working % Cortex 5.9.5 - tested & working % Cortex 5.9.1-5.9.4 - should work, but not tested % Cortex 5.7beta4 - DOES NOT WORK, warning issued % Cortex other versions - untested, warning issued % % It may work on other versions, but use at your own risk. The function % will issue a warning if you try to run this code on untested versions of % Cortex save files. % Information for this reader program is from the function "FILEIOrecall" in % FILEIO.C in the Cortex code. % static DISK_ENTRY Storage[] = { % { "Params", PARAMSsave, PARAMSrecall, }, % { "Block", BLOCKstore, BLOCKrestore, }, % { "Items", save_items, recall_items, }, % { "Conditions", save_conditions, recall_conditions, }, % { "CSS", CSSstore, CSSretrieve, }, % { "CLT", CLTstore, CLTrecall, }, % { "Diskio", DISKIOstore, DISKIOrecall, }, % }; % % Matthew A. Smith % Revised: 20050921 fid = fopen(filename, 'r','ieee-le'); if (fid == -1) error(['Cannot open file: ',filename]); end endian_test = fread(fid,1,'uchar'); if (char(endian_test) == 'C' | char(endian_test) == 'V') fseek(fid,0,-1); % everything OK, return to beginning of file else fclose(fid); fid = fopen(filename, 'r','ieee-be'); endian_test = fread(fid,1,'uchar'); if (char(endian_test) == 'C' | char(endian_test) == 'V') fseek(fid,0,-1); % everything OK, return to beginning of file else fclose(fid); error(['Incorrect file format - Version String Error: ',filename]); end end cortex_type = char(endian_test); % 'V' for VCortex, 'C' for Cortex % The Cortex Save Data Struct csd = struct('NAME',[], ... 'VER',[], ... 'VER_NUM',[], ... 'PARAMS',[], ... 'PARAMS2',[], ... 'BLOCK',[], ... 'BLOCK_STATS',[], ... 'COND_STATS',[], ... 'ITEMS',[], ... 'CONDITIONS',[], ... 'CSS',[], ... 'CLT',[], ... 'DISKIO',[]); csd.NAME = filename; % Read Cortex Version String for I=1:50 % 50 is the maximum number of characters in the Cortex Version String readtmp(I) = fread(fid, 1, 'uchar'); if (readtmp(I) == 0) % we've reached the end of the cortex version string readtmp(I) = []; % clear the null character at the end of the string break; end end csd.VER = char(readtmp); clear readtmp; csd.VER_NUM = csd.VER(8:length(csd.VER)); cortex_version = str2double(csd.VER_NUM(1:3)); % major version number (5.9, 1.0, 1.1, etc) if (cortex_type == 'C') % find minor version for regular Cortex files periods = find(csd.VER_NUM == '.'); if (length(periods) == 2) % e.g., 5.9.5 startchar = periods(2) + 1; stopchar = length(csd.VER_NUM); cortex_version_minor = str2double(csd.VER_NUM(startchar:stopchar)); % minor version number (.5, .6, etc) elseif (length(periods) == 1) % e.g., 5.7beta4 % Remove the 'beta' from the version betastart = find (csd.VER_NUM == 'b'); newstring = csd.VER_NUM; newstring(betastart) = '.'; newstring(betastart+1:betastart+3) = []; periods(2) = betastart; % Now find the minor version as usual startchar = periods(2) + 1; stopchar = length(newstring); cortex_version_minor = newstring(startchar:stopchar); % minor version number (.5, .6, etc) end end %% Version Check if (cortex_type == 'C') if (cortex_version < 5.9) warning(['Store File Version = ',csd.VER_NUM,'; This function may not work with Cortex version 5.8 and lower.']); end end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Start reading PARAMS - see function PARAMSrecall() in PARAMENU.C % See PARAMS.H for PARAMS structure (4 ints, 3 floats, and 15 ints) csd.PARAMS = struct('ref_item',[], ... 'total_items_no',[], ... 'total_conditions_no',[], ... 'save_eye_data',[], ... 'window_x',[], ... 'window_y',[], ... 'mc',[], ... 'show_x_rasters_per_cond',[], ... 'kHz_resolution',[], ... 'eog_gain',[], ... 'dynamic_eyewin_size',[], ... 'TIMERrun_Hz',[], ... 'TIMERplay_Hz',[], ... 'add_errs_to_hist',[], ... 'eye_update_rate',[], ... 'allow_hists_in_play',[], ... 'kHz_choices',[], ... 'eog_xoffset',[], ... 'eog_yoffset',[], ... 'ms_reward_duration',[], ... 'show_play_position',[], ... 'keep_current_conds',[], ... 'hz',[]); csd.PARAMS2 = struct('eye_storage_rate_ticks',[], ... 'epp_storage_rate_ticks',[], ... 'bar_response',[], ... 'rand_cutoff',[], ... 'CLT_start_index',[], ... 'depth_conflict',[], ... 'TIMERverbose',[], ... 'display_on',[], ... 'htg_scale',[]); % PARAMS struct csd.PARAMS.ref_item = fread(fid,1,'int32'); csd.PARAMS.total_items_no = fread(fid,1,'int32'); csd.PARAMS.total_conditions_no = fread(fid,1,'int32'); csd.PARAMS.save_eye_data = fread(fid,1,'int32'); csd.PARAMS.window_x = fread(fid,1,'float32'); csd.PARAMS.window_y = fread(fid,1,'float32'); csd.PARAMS.mc = fread(fid,1,'float32'); csd.PARAMS.show_x_rasters_per_cond = fread(fid,1,'int32'); csd.PARAMS.kHz_resolution = fread(fid,1,'int32'); csd.PARAMS.eog_gain = fread(fid,1,'int32'); csd.PARAMS.dynamic_eyewin_size = fread(fid,1,'int32'); csd.PARAMS.TIMERrun_Hz = fread(fid,1,'int32'); csd.PARAMS.TIMERplay_Hz = fread(fid,1,'int32'); csd.PARAMS.add_errs_to_hist = fread(fid,1,'int32'); csd.PARAMS.eye_update_rate = fread(fid,1,'int32'); csd.PARAMS.allow_hists_in_play = fread(fid,1,'int32'); csd.PARAMS.kHz_choices = fread(fid,1,'int32'); csd.PARAMS.eog_xoffset = fread(fid,1,'int32'); csd.PARAMS.eog_yoffset = fread(fid,1,'int32'); csd.PARAMS.ms_reward_duration = fread(fid,1,'int32'); csd.PARAMS.show_play_position = fread(fid,1,'int32'); csd.PARAMS.keep_current_conds = fread(fid,1,'int32'); if (cortex_type == 'V') if ((cortex_version >= 2.0)) % The "hz" parameter is only present in VCortex version 2.0 and higher csd.PARAMS.hz = fread(fid,1,'int32'); % 'long' end end % Other info read in PARAMSrecall csd.PARAMS2.eye_storage_rate_ticks = fread(fid,1,'int32'); csd.PARAMS2.epp_storage_rate_ticks = fread(fid,1,'int32'); csd.PARAMS2.bar_response = fread(fid,1,'int32'); csd.PARAMS2.rand_cutoff = fread(fid,1,'int32'); csd.PARAMS2.CLT_start_index = fread(fid,1,'int32'); csd.PARAMS2.depth_conflict = fread(fid,1,'int32'); csd.PARAMS2.bits_per_pixel = fread(fid,1,'int32'); csd.PARAMS2.TIMERverbose = fread(fid,1,'int32'); csd.PARAMS2.display_on = fread(fid,1,'int32'); csd.PARAMS2.htg_scale = fread(fid,1,'int32'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Start reading BLOCKS - see function BLOCKrestore() in BLOCK.C % See BLOCK.H for BLOCK structures % 4 ints, BLOCK_INFO, BLOCK_DATA, BLOCK_INFO (global), BLOCK_DATA (global), 17 ints csd.BLOCK = struct('num_conds',[], ... 'num_blocks',[], ... 'malloc_error',[], ... 'menu_len',[], ... 'BLOCK_INFO',[], ... 'BLOCK_DATA',[], ... 'BLOCK_INFO_GLOBAL',[], ... 'BLOCK_DATA_GLOBAL',[], ... 'num_correct',[], ... 'num_errors',[], ... 'block_circ_buf_size',[], ... 'cond_circ_buf_size',[], ... 'clear_block_cbuf_when',[], ... 'clear_cond_cbuf_when',[], ... 'num_repeats',[], ... 'final_repeat',[], ... 'repeat_counter',[], ... 'pause',[], ... 'command',[], ... 'current_block',[], ... 'current_cond',[], ... 'next_block',[], ... 'next_cond',[], ... 'last_cond',[], ... 'last_block',[]); % 2 ints, 1 pointer to a char csd.BLOCK_STATS = struct('num_correct',[], ... 'num_errors',[], ... 'circ_buf',[]); csd.COND_STATS = csd.BLOCK_STATS; % 6 ints, 1 float, 6 ints, 1 float csd.BLOCK.BLOCK_INFO = struct('randomness',[], ... 'on_error',[], ... 'done_when',[], ... 'max_trials',[], ... 'first',[], ... 'last',[], ... 'minPctOK',[], ... 'minTrials',[], ... 'recentOK',[], ... 'recentDone',[], ... 'max_errors',[], ... 'max_retries',[], ... 'recentOKtooLow',[], ... 'PctOKtooLow',[]); csd.BLOCK.BLOCK_INFO_GLOBAL = csd.BLOCK.BLOCK_INFO; % 4 ints, 1 float, 5 ints csd.BLOCK.BLOCK_DATA = struct('initialized',[], ... 'num_retries',[], ... 'num_trials',[], ... 'recentOK',[], ... 'PctOK',[], ... 'cbuf_len',[], ... 'num_entries',[], ... 'current_index',[], ... 'entries',[], ... 'counts',[]); csd.BLOCK.BLOCK_DATA_GLOBAL = csd.BLOCK.BLOCK_DATA; % BLOCK_GLOBAL struct csd.BLOCK.num_conds = fread(fid,1,'int32'); csd.BLOCK.num_blocks = fread(fid,1,'int32'); csd.BLOCK.malloc_error = fread(fid,1,'int32'); csd.BLOCK.menu_len = fread(fid,1,'int32'); readtmp = fread(fid,1,'int32'); % read the pointer to BLOCK_INFO *bi % BLOCK_DATA struct csd.BLOCK.BLOCK_DATA.initialized = fread(fid,1,'int32'); csd.BLOCK.BLOCK_DATA.num_retries = fread(fid,1,'int32'); csd.BLOCK.BLOCK_DATA.num_trials = fread(fid,1,'int32'); csd.BLOCK.BLOCK_DATA.recentOK = fread(fid,1,'int32'); csd.BLOCK.BLOCK_DATA.PctOK = fread(fid,1,'float32'); csd.BLOCK.BLOCK_DATA.cbuf_len = fread(fid,1,'int32'); csd.BLOCK.BLOCK_DATA.num_entries = fread(fid,1,'int32'); csd.BLOCK.BLOCK_DATA.current_index = fread(fid,1,'int32'); readtmp = fread(fid,1,'int32'); % entries_pointer readtmp = fread(fid,1,'int32'); % counts_pointer % BLOCK_INFO struct csd.BLOCK.BLOCK_INFO_GLOBAL.randomness = fread(fid,1,'int32'); csd.BLOCK.BLOCK_INFO_GLOBAL.on_error = fread(fid,1,'int32'); csd.BLOCK.BLOCK_INFO_GLOBAL.done_when = fread(fid,1,'int32'); csd.BLOCK.BLOCK_INFO_GLOBAL.max_trials = fread(fid,1,'int32'); csd.BLOCK.BLOCK_INFO_GLOBAL.first = fread(fid,1,'int32'); csd.BLOCK.BLOCK_INFO_GLOBAL.last = fread(fid,1,'int32'); csd.BLOCK.BLOCK_INFO_GLOBAL.minPctOK = fread(fid,1,'float32'); csd.BLOCK.BLOCK_INFO_GLOBAL.minTrials = fread(fid,1,'int32'); csd.BLOCK.BLOCK_INFO_GLOBAL.recentOK = fread(fid,1,'int32'); csd.BLOCK.BLOCK_INFO_GLOBAL.recentDone = fread(fid,1,'int32'); csd.BLOCK.BLOCK_INFO_GLOBAL.max_errors = fread(fid,1,'int32'); csd.BLOCK.BLOCK_INFO_GLOBAL.max_retries = fread(fid,1,'int32'); csd.BLOCK.BLOCK_INFO_GLOBAL.recentOKtooLow = fread(fid,1,'int32'); csd.BLOCK.BLOCK_INFO_GLOBAL.PctOKtooLow = fread(fid,1,'float32'); % BLOCK_DATA_GLOBAL struct csd.BLOCK.BLOCK_DATA_GLOBAL.initialized = fread(fid,1,'int32'); csd.BLOCK.BLOCK_DATA_GLOBAL.num_retries = fread(fid,1,'int32'); csd.BLOCK.BLOCK_DATA_GLOBAL.num_trials = fread(fid,1,'int32'); csd.BLOCK.BLOCK_DATA_GLOBAL.recentOK = fread(fid,1,'int32'); csd.BLOCK.BLOCK_DATA_GLOBAL.PctOK = fread(fid,1,'float32'); csd.BLOCK.BLOCK_DATA_GLOBAL.cbuf_len = fread(fid,1,'int32'); csd.BLOCK.BLOCK_DATA_GLOBAL.num_entries = fread(fid,1,'int32'); csd.BLOCK.BLOCK_DATA_GLOBAL.current_index = fread(fid,1,'int32'); readtmp = fread(fid,1,'int32'); % entries_pointer readtmp = fread(fid,1,'int32'); % counts_pointer % rest of BLOCK_GLOBAL struct csd.BLOCK.num_correct = fread(fid,1,'int32'); csd.BLOCK.num_errors = fread(fid,1,'int32'); csd.BLOCK.block_circ_buf_size = fread(fid,1,'int32'); csd.BLOCK.cond_circ_buf_size = fread(fid,1,'int32'); csd.BLOCK.clear_block_cbuf_when = fread(fid,1,'int32'); csd.BLOCK.clear_cond_cbuf_when = fread(fid,1,'int32'); csd.BLOCK.num_repeats = fread(fid,1,'int32'); csd.BLOCK.final_repeat = fread(fid,1,'int32'); csd.BLOCK.repeat_counter = fread(fid,1,'int32'); csd.BLOCK.pause = fread(fid,1,'int32'); csd.BLOCK.command = fread(fid,1,'int32'); csd.BLOCK.current_block = fread(fid,1,'int32'); csd.BLOCK.current_cond = fread(fid,1,'int32'); csd.BLOCK.next_block = fread(fid,1,'int32'); csd.BLOCK.next_cond = fread(fid,1,'int32'); csd.BLOCK.last_cond = fread(fid,1,'int32'); csd.BLOCK.last_block = fread(fid,1,'int32'); for I=1:csd.BLOCK.num_blocks; csd.BLOCK.BLOCK_INFO(I).randomness = fread(fid,1,'int32'); csd.BLOCK.BLOCK_INFO(I).on_error = fread(fid,1,'int32'); csd.BLOCK.BLOCK_INFO(I).done_when = fread(fid,1,'int32'); csd.BLOCK.BLOCK_INFO(I).max_trials = fread(fid,1,'int32'); csd.BLOCK.BLOCK_INFO(I).first = fread(fid,1,'int32'); csd.BLOCK.BLOCK_INFO(I).last = fread(fid,1,'int32'); csd.BLOCK.BLOCK_INFO(I).minPctOK = fread(fid,1,'float32'); csd.BLOCK.BLOCK_INFO(I).minTrials = fread(fid,1,'int32'); csd.BLOCK.BLOCK_INFO(I).recentOK = fread(fid,1,'int32'); csd.BLOCK.BLOCK_INFO(I).recentDone = fread(fid,1,'int32'); csd.BLOCK.BLOCK_INFO(I).max_errors = fread(fid,1,'int32'); csd.BLOCK.BLOCK_INFO(I).max_retries = fread(fid,1,'int32'); csd.BLOCK.BLOCK_INFO(I).recentOKtooLow = fread(fid,1,'int32'); csd.BLOCK.BLOCK_INFO(I).PctOKtooLow = fread(fid,1,'float32'); end % read entries & counts if (csd.BLOCK.BLOCK_DATA_GLOBAL.num_entries > 0) len = csd.BLOCK.BLOCK_DATA_GLOBAL.num_entries; csd.BLOCK.BLOCK_DATA_GLOBAL.entries = fread(fid,len,'int32'); csd.BLOCK.BLOCK_DATA_GLOBAL.counts = fread(fid,len,'int32'); end if (csd.BLOCK.BLOCK_DATA.num_entries > 0) len = csd.BLOCK.BLOCK_DATA.num_entries; csd.BLOCK.BLOCK_DATA.entries = fread(fid,len,'int32'); csd.BLOCK.BLOCK_DATA.counts = fread(fid,len,'int32'); end % read BLOCK_STATS count = csd.BLOCK.num_blocks; len = csd.BLOCK.block_circ_buf_size+1; for I=1:count csd.BLOCK_STATS(I).num_correct = fread(fid,1,'int32'); csd.BLOCK_STATS(I).num_errors = fread(fid,1,'int32'); readtmp = fread(fid,1,'int32'); % circ_buf pointer readtmp = fread(fid,len,'uchar'); readtmp(length(readtmp)) = []; csd.BLOCK_STATS(I).circ_buf = readtmp; clear readtmp; end % read COND_STATS count = csd.BLOCK.num_conds; len = csd.BLOCK.cond_circ_buf_size+1; for I=1:count csd.COND_STATS(I).num_correct = fread(fid,1,'int32'); csd.COND_STATS(I).num_errors = fread(fid,1,'int32'); readtmp = fread(fid,1,'int32'); % circ_buf pointer readtmp = fread(fid,len,'uchar'); readtmp(length(readtmp)) = []; csd.COND_STATS(I).circ_buf = readtmp; clear readtmp; end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Start reading ITEMS - see function recall_items() in FILEIO.C % See ITEM.H for STM_ITEM structure % uint, int, F_POINT, STM_COLOR, int, F_POINT, int, 5 floats, char, 2 char % arrays, 2 floats, int csd.ITEMS = struct('size',[], ... 'object_type',[], ... 'CENTER',[], ... 'COLOR',[], ... 'bitpan',[], ... 'WINDOW',[], ... 'filled',[], ... 'tall',[], ... 'wide',[], ... 'outer',[], ... 'inner',[], ... 'orient',[], ... 'ascii',[], ... 'filename',[], ... 'pattern',[], ... 'float1',[], ... 'float2',[], ... 'int1',[]); csd.ITEMS.CENTER = struct('x',[],'y',[]); csd.ITEMS.COLOR = struct('id',[],'index',[],'r',[],'g',[],'b',[]); csd.ITEMS.WINDOW = struct('x',[],'y',[]); % constant set in ITEM.H MAX_ITEM_FILENAME = 25; % read all of the items ITEMS_SIZE = csd.PARAMS.total_items_no; for I=1:ITEMS_SIZE csd.ITEMS(I).size = fread(fid,1,'uint32'); csd.ITEMS(I).object_type = fread(fid,1,'int32') + 1; % plus one here to reflect .ITM file csd.ITEMS(I).CENTER.x = fread(fid,1,'float32'); csd.ITEMS(I).CENTER.y = fread(fid,1,'float32'); csd.ITEMS(I).COLOR.id = fread(fid,1,'int32'); csd.ITEMS(I).COLOR.index = fread(fid,1,'int32'); csd.ITEMS(I).COLOR.r = fread(fid,1,'int32'); csd.ITEMS(I).COLOR.g = fread(fid,1,'int32'); csd.ITEMS(I).COLOR.b = fread(fid,1,'int32'); csd.ITEMS(I).bitpan = fread(fid,1,'int32'); csd.ITEMS(I).WINDOW.x = fread(fid,1,'float32'); csd.ITEMS(I).WINDOW.y = fread(fid,1,'float32'); csd.ITEMS(I).filled = fread(fid,1,'int32'); csd.ITEMS(I).tall = fread(fid,1,'float32'); csd.ITEMS(I).wide = fread(fid,1,'float32'); csd.ITEMS(I).outer = fread(fid,1,'float32'); csd.ITEMS(I).inner = fread(fid,1,'float32'); csd.ITEMS(I).orient = fread(fid,1,'float32'); csd.ITEMS(I).ascii = fread(fid,1,'uchar'); csd.ITEMS(I).filename = char(fread(fid,MAX_ITEM_FILENAME,'uchar'))'; csd.ITEMS(I).pattern = char(fread(fid,MAX_ITEM_FILENAME,'uchar'))'; csd.ITEMS(I).float1 = fread(fid,1,'float32'); csd.ITEMS(I).float2 = fread(fid,1,'float32'); csd.ITEMS(I).int1 = fread(fid,1,'int32'); if (cortex_type == 'C') readtmp = fread(fid,1,'uchar'); % get rid of extra char padding out the struct end if (cortex_type == 'V') if (cortex_version >= 2.0) % don't do this in VCortex 1.0/1.1 readtmp = fread(fid,1,'uchar'); % get rid of extra char padding out the struct end end end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Start reading CONDITIONS - see function recall_conditions() in FILEIO.C % See ITEM.H for STM_CONDITION structure % STM_GROUP (1 int, 1 int array), 4 ints, 1 char array csd.CONDITIONS = struct('GROUPS',[], ... 'timing_sequence_id',[], ... 'trial_type',[], ... 'background_item',[], ... 'fixspot_item',[], ... 'color_file',[]); csd.CONDITIONS.GROUPS = struct('num_els',[],'items',[]); % constants set in ITEM.H MAX_ITEMS_PER_GROUP = 16; if (cortex_type == 'C') if (cortex_version >= 5.9) if (cortex_version_minor >= 6) % The MAX_GROUPS define is set to 16 in Cortex 5.9.6 MAX_GROUPS = 16; else MAX_GROUPS = 10; end else MAX_GROUPS = 10; end end if (cortex_type == 'V') if (cortex_version >= 1.1) % The MAX_GROUPS define is set to 16 in VCortex 1.1 and higher MAX_GROUPS = 16; else MAX_GROUPS = 10; end end % read all of the conditions CONDITIONS_SIZE = csd.PARAMS.total_conditions_no; for I=1:CONDITIONS_SIZE for J=1:MAX_GROUPS csd.CONDITIONS(I).GROUPS(J).num_els = fread(fid,1,'int32'); csd.CONDITIONS(I).GROUPS(J).items = fread(fid,MAX_ITEMS_PER_GROUP,'int32'); end csd.CONDITIONS(I).timing_sequence_id = fread(fid,1,'int32'); csd.CONDITIONS(I).trial_type = fread(fid,1,'int32'); csd.CONDITIONS(I).background_item = fread(fid,1,'int32'); csd.CONDITIONS(I).fixspot_item = fread(fid,1,'int32'); csd.CONDITIONS(I).color_file = char(fread(fid,MAX_ITEM_FILENAME,'uchar'))'; if (cortex_type == 'C') readtmp = fread(fid,3,'uchar'); % get rid of extra 3 chars padding out the struct end if (cortex_type == 'V') if (cortex_version >= 2.0) % don't do this in VCortex 1.0/1.1 readtmp = fread(fid,3,'uchar'); % get rid of extra 3 chars padding out the struct end end end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Start reading CSS - see function CSSretrieve() in CSSDISK.C % Also CSS_STAMPread and CSSio_read are essential csd.CSS = struct('ext_num',[], ... 'sys_num',[], ... 'csum',[], ... 'buf',[], ... 'total_len',[], ... 'transfer_size',[], ... 'CSSDIR',[], ... 'data',[]); csd.CSS.CSSDIR = struct('ifd',[],'ofd',[],'eof',[],'num',[],'total',[],'offsets',[]); % variable that designates the CSS version CSSstamp = 'CSS-6.02'; % CSS_STAMPread csd.CSS.ext_num = fread(fid,1,'int32'); csd.CSS.sys_num = fread(fid,1,'int32'); csd.CSS.csum = fread(fid,1,'int32'); % 'long' csd.CSS.buf = char(fread(fid,length(CSSstamp)+1,'uchar'))'; % CSSio_read csd.CSS.total_len = fread(fid,1,'int32'); % 'long' % CSSdir DIRECTORY struct (2 int, 1 long, 2 int, 1 pointer to long) csd.CSS.CSSDIR.ifd = fread(fid,1,'int32'); csd.CSS.CSSDIR.ofd = fread(fid,1,'int32'); csd.CSS.CSSDIR.eof = fread(fid,1,'int32'); % 'long' csd.CSS.CSSDIR.num = fread(fid,1,'int32'); csd.CSS.CSSDIR.total = fread(fid,1,'int32'); readtmp = fread(fid,1,'int32'); % offsets pointer; 'long' len = csd.CSS.CSSDIR.total; csd.CSS.CSSDIR.offsets = fread(fid,len,'int32'); % 'long' % This part is not really needed MAX_MALLOC_LEN = hex2dec('FE00'); if (csd.CSS.total_len > MAX_MALLOC_LEN) csd.CSS.transfer_size = MAX_MALLOC_LEN; else csd.CSS.transfer_size = csd.CSS.total_len; end % read the block of CSS data csd.CSS.data = fread(fid,csd.CSS.total_len,'uchar'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Start reading CLT - see function CLTrecall() in CLT.C csd.CLT = struct('new_val',[],'CLTS',[]); % CLT_ENTRY struct - 1 int, 1 char array (CLT_MAX_FILENAME long) csd.CLT.CLTS = struct('size',[],'name',[],'RGBS',[]); % BYTE_RGB struct from GKERNEL.H - 3 unsigned chars csd.CLT.CLTS.RGBS = struct('r',[],'g',[],'b',[]); % constant set in CLT.C CLT_MAX_FILENAME = 50; csd.CLT.new_val = fread(fid,1,'int32'); % number of CLTs to read NUM_CLTS = csd.CLT.new_val; for I=1:NUM_CLTS csd.CLT.CLTS(I).size = fread(fid,1,'int32'); csd.CLT.CLTS(I).name = char(fread(fid,CLT_MAX_FILENAME,'uchar'))'; readtmp = fread(fid,2,'uchar'); % get rid of extra 2 chars padding out the struct for J=1:256 csd.CLT.CLTS(I).RGBS(J).r = fread(fid,1,'uchar'); csd.CLT.CLTS(I).RGBS(J).g = fread(fid,1,'uchar'); csd.CLT.CLTS(I).RGBS(J).b = fread(fid,1,'uchar'); end end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Start reading DISKIO - see function DISKIOrecall() in DISKIO.C csd.DISKIO = struct('data_file',[], ... 'data_ext',[], ... 'item_file',[], ... 'cond_file',[], ... 'css_file',[], ... 'ext_file',[]); % constant set in DISKIO.H MAX_DISKIO_FILENAME = 80; csd.DISKIO.data_file = char(fread(fid,MAX_DISKIO_FILENAME+1,'uchar'))'; csd.DISKIO.data_ext = char(fread(fid,4,'uchar'))'; csd.DISKIO.item_file = char(fread(fid,MAX_DISKIO_FILENAME+1,'uchar'))'; csd.DISKIO.cond_file = char(fread(fid,MAX_DISKIO_FILENAME+1,'uchar'))'; csd.DISKIO.css_file = char(fread(fid,MAX_DISKIO_FILENAME+1,'uchar'))'; csd.DISKIO.ext_file = char(fread(fid,MAX_DISKIO_FILENAME+1,'uchar'))'; %%%%%%%%%% Done, now close the file fclose(fid);