Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:49:13

0001 // export OPTICKS_RANDOM_SEQPATH=/tmp/$USER/opticks/QSimTest/rng_sequence/rng_sequence_f_ni1000000_nj16_nk16_tranche100000
0002 // name=dirent ; gcc $name.cc -std=c++11 -lstdc++ -o /tmp/$name && /tmp/$name
0003 
0004 #include <iostream>
0005 #include <sstream>
0006 #include <string>
0007 #include <vector>
0008 #include <cstdlib>
0009 #include <cstdio>
0010 #include "dirent.h"
0011 
0012 
0013 void ListDir(std::vector<std::string>& names, const char* path, const char* ext )
0014 {
0015     DIR* dir = opendir(path) ;
0016     if(!dir) return ; 
0017     struct dirent* entry ;
0018     while ((entry = readdir(dir)) != nullptr) 
0019     {
0020         const char* name = entry->d_name ; 
0021         if(strlen(name) > strlen(ext) && strcmp(name + strlen(name) - strlen(ext), ext)==0)
0022         {
0023             //std::cout << name << std::endl;  
0024             names.push_back(name); 
0025         }
0026     }
0027     closedir (dir);
0028     std::sort( names.begin(), names.end() ); 
0029 }
0030 
0031 std::string Desc(const std::vector<std::string>& names)
0032 {
0033     std::stringstream ss ; 
0034     for(unsigned i=0 ; i < names.size() ; i++) ss << names[i] << std::endl ; 
0035     std::string s = ss.str(); 
0036     return s ; 
0037 }
0038 
0039 
0040 
0041 
0042 void test_0()
0043 {
0044     //const char* path = "c:\\src\\" ; 
0045     const char* path = "/private/tmp" ; 
0046 
0047     DIR* dir = opendir(path) ;
0048     if( dir == NULL  )
0049     {
0050         perror ("");
0051         return ;
0052     }
0053 
0054     struct dirent* ent;
0055     while ((ent = readdir(dir)) != NULL) 
0056     {
0057         printf("%s\n", ent->d_name);
0058     }
0059 
0060     closedir (dir);
0061 }
0062 
0063 void test_1()
0064 {
0065     const char* path = getenv("OPTICKS_RANDOM_SEQPATH"); 
0066     const char* ext = ".npy"; 
0067     std::vector<std::string> names ; 
0068     ListDir(names, path, ext);  
0069     std::cout << Desc(names) << std::endl ; 
0070 
0071 }
0072 
0073 
0074 
0075 
0076 int main(int argc, char** argv)
0077 {
0078     //test_0(); 
0079     test_1(); 
0080 
0081     return 0 ; 
0082 }
0083