Advertisement
Guest User

Untitled

a guest
Oct 20th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.15 KB | None | 0 0
  1. wavenumber wavelength powerspec
  2. zzleifjl qwefaseklfj asjfieasef //second row was cracked
  3. 0.00000000002356234 0.00000013431 0.12523125123
  4. 0.0000000000412512 0.00000054888 0.58382423
  5. etc..
  6.  
  7. /*openfiles according to reprogramed filelist*/
  8. for(i =2; i<file_count; i++) {
  9. strcat(filelist[i],".txt");
  10. if((fp = fopen( filelist[i], "r")) == NULL)
  11. {
  12. perror("error to openfiles");
  13. exit(1);
  14. }
  15.  
  16. /*declare the variables*/
  17. char data[3][513];
  18. //char wavenumber[513], wavelength[513], powerspec[513];
  19. int COL, ROW, MAX_wavenumber, MAX_wavelength, MAX_powerspec;
  20. int HEIGHT,WIDTH;
  21. HEIGHT = 513;
  22. WIDTH = 3;
  23.  
  24.  
  25. //input data to new array
  26. for(COL = 0; COL < HEIGHT; COL++) {
  27. for (ROW = 0; ROW < WIDTH; ROW++) {
  28. fscanf(fp, "%s", &data[ROW][COL]);
  29. }
  30. }
  31.  
  32. //start of comparison of data
  33.  
  34. for(COL = 2; COL < HEIGHT - 1; COL++) { //number starts from the 3rd column
  35. while(ROW == 1) {
  36. if( atof(&data[ROW][COL]) < atof(&data[ROW][COL+1]) ) {
  37. MAX_wavenumber = atof(&data[ROW][COL+1]);
  38. }
  39. while(ROW == 2) {
  40. if( atof(&data[ROW][COL]) < atof(&data[ROW][COL+1]) ) {
  41. MAX_wavelength = atof(&data[ROW][COL+1]);
  42. }
  43. }
  44. while(ROW == 3)
  45. if( atof(&data[ROW][COL]) < atof(&data[ROW][COL+1]) ) {
  46. MAX_powerspec = atof(&data[ROW][COL+1]);
  47. }
  48. }
  49. }
  50.  
  51. printf("MAX_wavenumber : %d",MAX_wavenumber);
  52. printf("MAX_wavelength : %d",MAX_wavelength);
  53. printf("MAX_powerspec : %d",MAX_powerspec);
  54.  
  55. fclose(fp);
  56. }
  57.  
  58. #include <stdio.h>
  59. #include <stdlib.h>
  60. #include <math.h>
  61. #include <dirent.h>
  62. #include <sys/types.h>
  63. #include <sys/stat.h>
  64. #include <unistd.h>
  65. #include <string.h>
  66.  
  67. char *remove_ext (char* mystr, char dot, char sep);
  68.  
  69. int main()
  70. {
  71. char fname1[256],fname2[256];
  72. char folderpath[256];
  73. int mod;
  74. int re_mainder;
  75. char *tem;
  76. char filenameNoExtension;
  77.  
  78. char **filelist;
  79. int i,j,l;
  80. char ***ls = &filelist;
  81.  
  82. int file_count = 0;
  83.  
  84. char *s;
  85.  
  86. DIR* dp = NULL;
  87. struct dirent* entry = NULL;
  88.  
  89. FILE* fp = NULL;
  90.  
  91.  
  92. /*open folder*/
  93. printf("enter the folder path : ");
  94. scanf("%s",folderpath);
  95.  
  96. /* Err message of opening directory */
  97. if((dp = opendir(folderpath)) ==NULL) {
  98. fprintf(stderr,"unidentified folder : %s",folderpath);
  99. return 0;
  100. }
  101.  
  102. *ls = NULL;
  103.  
  104. /*file count*/
  105. while ((entry = readdir(dp)) != NULL) {
  106. if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
  107. continue;
  108. ++file_count;
  109. }
  110.  
  111. /* rewind the directory and need to reallocate memory for reading 18250 files */
  112. rewinddir(dp);
  113. *ls = calloc(file_count, sizeof(char*));
  114.  
  115. /*make the array of filelist*/
  116. file_count = 0;
  117. entry = readdir(dp);
  118. while(NULL != entry) {
  119. (*ls)[file_count++] = strdup(entry->d_name);
  120. entry = readdir(dp);
  121. }
  122.  
  123. /*remove the extension */
  124. for(i = 0; i < file_count; i++) {
  125. filelist[i] = remove_ext(filelist[i], '.', '/');
  126. }
  127. closedir(dp);
  128. //loop starts at 2 for get rid of space & .
  129. for(i = 2; i< file_count; i++) {
  130. printf("%sn",filelist[i]);
  131. }
  132.  
  133.  
  134.  
  135. /*select the mod & remainder*/
  136. printf("select the mod number : ");
  137. scanf("%d", &mod);
  138. printf("select the remainder : ");
  139. scanf("%d",&re_mainder);
  140.  
  141.  
  142. /*sort files by the remainder*/
  143. for(i = 2; i<file_count; i++) {
  144. if( atoi( filelist[i] )%mod == re_mainder) { /*use atoi function for changing string to int*/
  145. filelist[i] = filelist[i];
  146. }
  147. else
  148. filelist[i] = "delete";
  149. }
  150.  
  151. //delete the "delete" in array
  152. l = file_count;
  153. for(i = 0; i<l; i++) {
  154. if (strcmp(filelist[i], "delete") == 0 ) {
  155. for(j = i; j < l; j++)
  156. filelist[j]=filelist[j+1];
  157. i--; //check again from same index i
  158. l--; //Decreasing the length of the array
  159. }
  160. }
  161. /* resize the modified file_count */
  162. file_count = sizeof(filelist)/sizeof(filelist[0]);
  163. for(i =2; i<file_count; i++) {
  164. printf("%sn",filelist[i]);
  165. }
  166.  
  167.  
  168. /********** **HERE"S MY QUESTION** **********/
  169. /**********openfiles according to reprogramed filelist**********/
  170.  
  171.  
  172. for(i =2; i<file_count; i++) {
  173.  
  174. strcat(filelist[i],".txt");
  175. if((fp = fopen( filelist[i], "r")) == NULL)
  176. {
  177. perror("error to openfiles");
  178. exit(1);
  179. }
  180.  
  181. /*declare the variables*/
  182. char data[3][513];
  183. //char wavenumber[513], wavelength[513], powerspec[513];
  184. int COL, ROW, MAX_wavenumber, MAX_wavelength, MAX_powerspec;
  185. int HEIGHT,WIDTH;
  186. HEIGHT = 513;
  187. WIDTH = 3;
  188.  
  189.  
  190. //input data to new array
  191. for(COL = 0; COL < HEIGHT; COL++) {
  192. for (ROW = 0; ROW < WIDTH; ROW++) {
  193. fscanf(fp, "%s", &data[ROW][COL]);
  194. }
  195. }
  196.  
  197. //start of comparison of data
  198.  
  199. for(COL = 2; COL < HEIGHT - 1; COL++) { //number starts from the 3rd column
  200. while(ROW == 1) {
  201. if( atof(&data[ROW][COL]) < atof(&data[ROW][COL+1]) ) {
  202. MAX_wavenumber = atof(&data[ROW][COL+1]);
  203. }
  204. while(ROW == 2) {
  205. if( atof(&data[ROW][COL]) < atof(&data[ROW][COL+1]) ) {
  206. MAX_wavelength = atof(&data[ROW][COL+1]);
  207. }
  208. }
  209. while(ROW == 3)
  210. if( atof(&data[ROW][COL]) < atof(&data[ROW][COL+1]) ) {
  211. MAX_powerspec = atof(&data[ROW][COL+1]);
  212. }
  213. }
  214. }
  215.  
  216. printf("MAX_wavenumber : %d",MAX_wavenumber);
  217. printf("MAX_wavelength : %d",MAX_wavelength);
  218. printf("MAX_powerspec : %d",MAX_powerspec);
  219.  
  220.  
  221. fclose(fp);
  222. }
  223. }
  224.  
  225.  
  226. //this is just for removing the extension of files
  227. char *remove_ext (char* mystr, char dot, char sep) {
  228. char *retstr, *lastdot, *lastsep;
  229.  
  230. // Error checks and allocate string.
  231.  
  232. if (mystr == NULL)
  233. return NULL;
  234. if ((retstr = malloc (strlen (mystr) + 1)) == NULL)
  235. return NULL;
  236.  
  237. // Make a copy and find the relevant characters.
  238.  
  239. strcpy (retstr, mystr);
  240. lastdot = strrchr (retstr, dot);
  241. lastsep = (sep == 0) ? NULL : strrchr (retstr, sep);
  242.  
  243. // If it has an extension separator.
  244.  
  245. if (lastdot != NULL) {
  246. // and it's before the extenstion separator.
  247.  
  248. if (lastsep != NULL) {
  249. if (lastsep < lastdot) {
  250. // then remove it.
  251.  
  252. *lastdot = '';
  253. }
  254. } else {
  255. // Has extension separator with no path separator.
  256.  
  257. *lastdot = '';
  258. }
  259. }
  260. // Return the modified string.
  261.  
  262. return retstr;
  263. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement