%% gallery_png % Creates taxon_png.html in current directory with figures of directory entries %% function gallery_png(taxon, info) % created 2021/06/24 Bas Kooijman, modified 2023/03/14 %% Syntax % <../gallery_png.m *gallery_png*> (taxon, info) %% Description % Writes fig_png.html file with png's for figure files in the directory entries with name taxon_png.html in current directory, where taxon is replaced by name of taxon. % The html is opened in the system browser. % A click on a picture to go to the entry % % Input % % * pets: cell-array with names of entries % * info: optional boolean to search locally if true (only for curators) %% Remarks % if info==0: png-files are read from internet %% Example of use % gallery_png('Cephalopoda'), which results in opening fig_png.html WD = pwd; % current work directory path = [set_path2server, 'add_my_pet/entries/']; if ~exist('info','var') info = 0; end if ischar(taxon) pets = select(taxon); else pets = taxon; end n_pets = length(pets); n_row = 4; fnm = 'fig_png.html'; oid = fopen(fnm, 'w+'); % open file for writing, delete existing content path2pet = [set_path2server, 'add_my_pet/entries/']; path2sys = [set_path2server, 'add_my_pet/sys/']; pet = cell(0,1); png = cell(0,1); for i = 1:n_pets if info % png's are read locally cdEntr(pets{i}); if ismac || isunix list = strsplit(ls); list(end) = []; else list = cellstr(ls); end list = list(Contains(list,'.png')); n_pngi = length(list); for j = 1:n_pngi pet = [pet; pets{i}]; png = [png; list{j}]; end else % png's are read from internet if ismac || isunix system(['wget -O pngls.txt ', path, pets{i}, '/']); else eval(['!powershell wget -o pngls.txt ', path, pets{i}, '/']); end pngls = fileread('pngls.txt'); in_0 = 6+strfind(pngls,'.png"'); n_pngi = length(in_0); for j = 1:n_pngi in_1 = strfind(pngls(in_0(j):end),''); pet = [pet; pets{i}]; png = [png; pngls(in_0(j):in_0(j)+in_1(1)-2)]; end end end n_png = length(png); cd(WD); fprintf(oid, '\n'); fprintf(oid, '\n'); fprintf(oid, '\n'); fprintf(oid, ' %s\n', fnm); fprintf(oid, ' \n\n', path2sys); fprintf(oid, ' \n', path2sys); fprintf(oid, ' \n', path2sys); fprintf(oid, ' \n'); fprintf(oid, '\n\n'); fprintf(oid, '\n\n'); fprintf(oid, '
\n'); fprintf(oid, '
\n'); fprintf(oid, '
\n\n'); for i = 1:n_png if mod(i,n_row) == 1 fprintf(oid, '
\n'); end fprintf(oid, '
\n'); fprintf(oid, ' \n', path2pet, pet{i}, png{i}); fprintf(oid, ' \n', path2pet, pet{i}, pet{i}); fprintf(oid, '
\n'); if mod(i,n_row) == 0 fprintf(oid, '
\n\n'); end end % end of entry scan if mod(i,n_row) > 0 % close last div if necessary fprintf(oid, '
\n\n'); end fprintf(oid, '
\n\n'); fprintf(oid, '
\n'); fprintf(oid, ' \n'); fprintf(oid, '\n'); fprintf(oid, '\n'); fclose(oid); web(fnm,'-browser') end function sel = Contains(nm, str) % this fuction is the same as Matlab built-in-function contains, but the R2016a version does not work with cell input n = length(nm); sel = true(n,1); for i=1:n sel(i) = ~isempty(strfind(nm{i}, str)); end end