-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c63edfc
commit bab689b
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
## Usage [status,errmsg, train_file] = verify_and_create_train_file ( train_input, outdir ) | ||
## | ||
## 1st Looks for files ending with .h5 in train_input directory | ||
## and verifies there are 16 of them. 2nd code creates a | ||
## train_file.txt in the outdir directory that has a list | ||
## of full paths to these h5 files. | ||
## | ||
## Upon success train_file will have the path to the train_file.txt created | ||
## by this function. | ||
## | ||
## If there is an error status will be set to a non zero numeric | ||
## value and errmsg will explain the issue. | ||
|
||
function [status,errmsg, train_file] = verify_and_create_train_file (train_input, outdir) | ||
errmsg = ''; | ||
train_file = ''; | ||
status = 0; | ||
H_FIVE_SUFFIX='.h5'; | ||
|
||
if isdir(train_input) == 0; | ||
errmsg = sprintf('%s is not a directory', train_input); | ||
status = 1; | ||
return; | ||
endif | ||
|
||
train_files = glob(strcat(train_input, filesep(),'*', H_FIVE_SUFFIX)); | ||
|
||
if rows(train_files) != 16; | ||
errmsg = sprintf('Expecting 16 .h5 files, but got: %d', rows(train_files)); | ||
status = 3; | ||
return; | ||
endif | ||
|
||
create_dir(outdir); | ||
|
||
train_file = strcat(outdir, filesep(),'train_file.txt'); | ||
train_out = fopen(train_file, "w"); | ||
for i = 1:rows(train_files) | ||
fprintf(train_out,'%s\n',char(train_files(i))); | ||
endfor | ||
fclose(train_out); | ||
endfunction | ||
|
||
%!test | ||
%! [status,errmsg, tf] = verify_and_create_train_file('',''); | ||
%! assert(status, 1); | ||
|
||
%!test | ||
%! test_fname = tempname(); | ||
%! mkdir(test_fname); | ||
%! dest_dir = strcat(test_fname,filesep(),'out'); | ||
%! mkdir(dest_dir); | ||
%! for i = 1:16 | ||
%! hfile = sprintf('%s%sfoo_v%d.h5',test_fname,filesep(),i); | ||
%! fout = fopen(hfile, "w"); | ||
%! fprintf(fout,"hi\n"); | ||
%! fclose(fout); | ||
%! endfor | ||
%! [status,errmsg, tf] = verify_and_create_train_file(test_fname,dest_dir); | ||
%! assert(status, 0); | ||
%! assert(errmsg, ''); | ||
%! assert(tf, strcat(dest_dir,filesep(),"train_file.txt")); | ||
%! rmdir(test_fname, 's'); |