0001 
0002 
0003 
0004 
0005 
0006 s = filesep;
0007 
0008 
0009 
0010 
0011 
0012 
0013 
0014 dir_data = ['data' s 'A590' s 'frames' s 'light_frames' s '2s' s '2012_08_30'];
0015 
0016 
0017 in_ftype = 'DNG';
0018 
0019 
0020 out_ftype = 'PGM';
0021 
0022 
0023 
0024 if strcmp(s, '/') 
0025     dcraw = ['/usr/bin/dcraw'];
0026 elseif strcmp(s, '\') 
0027     dcraw = ['bin' s 'dcraw'];
0028 end
0029 
0030 decode_args = '-c -D -4 -t 0 -j';
0031 finfo_args = '-v -i';
0032 
0033 if strcmpi(out_ftype, 'TIFF')
0034     decode_args = [decode_args ' -T'];
0035 end
0036 
0037 decode_cmd = [dcraw ' ' decode_args ' '];
0038 finfo_cmd = [dcraw ' ' finfo_args ' '];
0039 
0040 flne = {}; 
0041 
0042 g = waitbar(0, ['Decoding raw spectrographs. ' ...
0043                 'This may take several minutes.']);
0044 waitbar(0.001, g); 
0045 dl = list_dir(dir_data, in_ftype, 3);
0046 Ns = length(dl);
0047 
0048 for jj=1:Ns
0049     idir = dl{jj};
0050     [ign, pd] = pop_dirname(idir);
0051     odir = [pd s out_ftype];
0052 
0053     if (exist(odir) == 0)
0054         [status, msg, msgid] = mkdir(odir);
0055         if (status == 0)
0056             error(['batch_raw_decode: error creating ' odir ' . ' msg]);
0057         end
0058     elseif (exist(odir) ~= 7)
0059         error(['batch_raw_decode: ' odir ...
0060                 ' already exists, but is not a directory!']);
0061     end
0062 
0063     fl = list_dir(idir, ['*.' in_ftype], 1);
0064     for kk=1:length(fl)
0065         [ign, fname, ext] = fileparts(fl{kk});
0066         system([decode_cmd fl{kk} ' > ' odir s fname '.' out_ftype]);
0067         flne = fl;
0068     end
0069     waitbar((jj/Ns)-0.001, g);
0070 end
0071 
0072 disp('')
0073 
0074 if ~isempty(flne)
0075     
0076     
0077     [ign, output] = system([finfo_cmd flne{1}]);
0078     si = strfind(output, 'Image size:');
0079     sf = strfind(output, 'Output size:');
0080     hwstr = output(si:(sf-1));
0081     
0082     [ign, ign, ign, M] = regexp(hwstr, '[0-9]+');
0083     w = str2num(M{1});
0084     h = str2num(M{2});
0085 
0086     si = strfind(output, 'Filter pattern:');
0087     sf = strfind(output, 'Daylight multipliers:');
0088     bfpstr = output(si:(sf-1));
0089     [ign, idx] = regexp(bfpstr, ':\s\w');
0090     bfp = bfpstr(idx:idx+3);
0091     fprintf(['These images have width: %d, height: %d, ' ...
0092              'and Bayer filter pattern: %s.\n'], w, h, bfp);
0093 end
0094 
0095 clear all