Closed owang01 closed 3 years ago
Hi @owang01 you might try additional capacity of "dir" (to replace in-line "findfiles") something like dir('*/.nc'), more detail https://www.mathworks.com/help/matlab/ref/dir.html#bvd_n8a
@hongandyan The MATLAB command dir is not as robust as the customized in-line routine findfiles I wrote, since the directory structures are not the same among the directories. For instance, the nc files for nctiles_monthly/OBP are in the sub-directories two levels down, while those for nctiles_daily/OBP are third* levels down. The MATLAB command "dir" can't search files recursively in the sub-directories and we would have to explicitly specify the path. On the other hand, findfiles can search the files recursively and therefore the same calling command can be used for directories having different structures.
@owang01 "findfiles" is very smart. But I guess "dir" is concise. dir('*/.nc') can collect nc files recursively. Then one only needs to assemble the result, something like flist=dir('*/.nc'); file1=fullfile(flist(1).folder,flist(1).name); It's up to you :-)
@hongandyan Thank you for the follow-up. I tired your way to find *.nc under nctiles_monthly/OBP, but can't find any matches. Below please find the commands I used and the two lists: flist from using your way and flist2 from using findfiles. The latter correctly found the 312 monthly-mean files.
>> cd nctiles_monthly/OBP
>> flist=dir('/*nc');
>> whos flist
Name Size Bytes Class Attributes
flist 0x1 384 struct
>> flist2=findfiles('./','*nc');
>> whos flist2
Name Size Bytes Class Attributes
flist2 1x312 85488 cell
@gaelforget I submit a new pull https://github.com/MITgcm/gcmfaces/pull/13 to use the built-in function dir for recursive file search in read_nctiles.m as suggested by @hongandyan. Thank you @hongandyan for the suggestion.
Not that using ** will search directories recursively, see https://uk.mathworks.com/help/matlab/ref/dir.html#bvd_n8a
So "flist=dir('*/nc');" may work?
@emmomp Thank you. That is actually also what @hongandyan had suggested. I had implemented it in my PR #13 in May.
Appologies for not having done this yet -- meant to test it and never did... My understanding is I that should merge #13 instead. Is that right?
I am pretty sure since the ...nctilesv2 branch has both commits. So I willl merge #13 and close this one. Can always reopen the PR if I got this wrong.
Updated read_nctiles.m to improve the performance when reading V4r4 files.