%% script; whacked from write_ensblk.m (because it's called twice)



% open the new files                                                    
logfile = fullfile(ldcodas_path,    [blkbase_str  '.log'])
cmdfile = fullfile(ldcodas_path,    [blkbase_str  '.cmd']);             
binfile = fullfile(ldcodas_path,    [blkbase_str  '.bin']);             
nav1file = fullfile(ldcodas_path,   [blkbase_str  '.gps1']);            
nav2file = fullfile(ldcodas_path,   [blkbase_str  '.gps2']);            
                                                                         
fid_log  = fopen(logfile,  'a'); 
fid_nav1 = fopen(nav1file, 'a'); 
fid_nav2 = fopen(nav2file, 'a'); 
fid_cmd  = fopen(cmdfile,  'a'); 
fid_bin  = fopen(binfile,  'a'); 
                                                                          
if profnum == 0
   %% write the new block info to the cmd file
   dbinfo = setup_dbinfo(rawdir, ensinfo(end), params);                                  
   fprintf(fid_cmd, 'binary_file: %s\n', binfile);
   fprintf(fid_cmd, 'new_block\n');
   fprintf(fid_cmd, 'dp_mask: 1\n');
   bin_float('DEPTH', round(dbinfo.depth));
   bin_double('CONFIGURATION_1', dbinfo.config1);
   %% write the new block info to the log file
   fprintf(fid_log, '% rawfilebase    last ensemble   secs(ens)   profile_num\n');
   fprintf(fid_log, '% -----------   -------------    -------    ------------\n');
   %% notify user
   fprintf( '------------   New Block\n');
 end
   
if fid_log  == -1, error(['Can''t open ', logfile]); return, end             
if fid_nav1 == -1, error(['Can''t open ', nav1file]); return, end           
if fid_nav2 == -1, error(['Can''t open ', nav2file]); return, end           
if fid_cmd  == -1, error(['Can''t open ', cmdfile]);   return, end           
if fid_bin  == -1, error(['Can''t open ', binfile]);   return, end           
     
