0001 function ix = create_index_dicom(fid)
0002
0003
0004
0005
0006
0007
0008
0009 fseek(fid, 0, 'bof');
0010 ix = {sparse(0), sparse(0)};
0011 SQdepth = 0;
0012
0013 if 1
0014 while 1
0015 tag = fread(fid, 2, 'uint16');
0016 len = fread(fid, 1, 'uint32');
0017 if feof(fid)
0018 break;
0019 end
0020 if tag(1) < 0 | tag(2) < 0
0021 break;
0022 end
0023 if len >= hex2dec('FFFFFFFF')
0024 SQdepth = SQdepth + 1;
0025 end
0026 if SQdepth < 1
0027 ix{1}(tag(1)+1, tag(2)+1) = ftell(fid);
0028 ix{2}(tag(1)+1, tag(2)+1) = len;
0029 else
0030 if tag(1) == hex2dec('FFFE') & tag(2) == hex2dec('E0DD')
0031 SQdepth = SQdepth - 1;
0032 end
0033 if tag(1) == hex2dec('FFFE') & tag(2) == hex2dec('E00D')
0034 SQdepth = SQdepth - 1;
0035 end
0036 end
0037 if len < hex2dec('FFFFFFFF')
0038 fseek(fid, len, 'cof');
0039 end
0040 end
0041 else
0042 fseek(fid, 128 + 4, 'bof');
0043 long_len_vr = strvcat('OB','OW','SQ','UN');
0044 while 1
0045 tag = fread(fid, 2, 'uint16');
0046 vr = char(fread(fid, 2, 'uchar')')
0047 if strmatch(vr, long_len_vr, 'exact');
0048 len = fread(fid, 1, 'uint32');
0049 else
0050 len = fread(fid, 1, 'uint16');
0051 end
0052 if feof(fid)
0053 break;
0054 end
0055 if tag(1) < 0 | tag(2) < 0
0056 break;
0057 end
0058 ix{1}(tag(1)+1, tag(2)+1) = ftell(fid);
0059 ix{2}(tag(1)+1, tag(2)+1) = len;
0060 fseek(fid, len, 'cof');
0061 end
0062 end