Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- wavenumber wavelength powerspec
- zzleifjl qwefaseklfj asjfieasef //second row was cracked
- 0.00000000002356234 0.00000013431 0.12523125123
- 0.0000000000412512 0.00000054888 0.58382423
- etc..
- /*openfiles according to reprogramed filelist*/
- for(i =2; i<file_count; i++) {
- strcat(filelist[i],".txt");
- if((fp = fopen( filelist[i], "r")) == NULL)
- {
- perror("error to openfiles");
- exit(1);
- }
- /*declare the variables*/
- char data[3][513];
- //char wavenumber[513], wavelength[513], powerspec[513];
- int COL, ROW, MAX_wavenumber, MAX_wavelength, MAX_powerspec;
- int HEIGHT,WIDTH;
- HEIGHT = 513;
- WIDTH = 3;
- //input data to new array
- for(COL = 0; COL < HEIGHT; COL++) {
- for (ROW = 0; ROW < WIDTH; ROW++) {
- fscanf(fp, "%s", &data[ROW][COL]);
- }
- }
- //start of comparison of data
- for(COL = 2; COL < HEIGHT - 1; COL++) { //number starts from the 3rd column
- while(ROW == 1) {
- if( atof(&data[ROW][COL]) < atof(&data[ROW][COL+1]) ) {
- MAX_wavenumber = atof(&data[ROW][COL+1]);
- }
- while(ROW == 2) {
- if( atof(&data[ROW][COL]) < atof(&data[ROW][COL+1]) ) {
- MAX_wavelength = atof(&data[ROW][COL+1]);
- }
- }
- while(ROW == 3)
- if( atof(&data[ROW][COL]) < atof(&data[ROW][COL+1]) ) {
- MAX_powerspec = atof(&data[ROW][COL+1]);
- }
- }
- }
- printf("MAX_wavenumber : %d",MAX_wavenumber);
- printf("MAX_wavelength : %d",MAX_wavelength);
- printf("MAX_powerspec : %d",MAX_powerspec);
- fclose(fp);
- }
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <dirent.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <unistd.h>
- #include <string.h>
- char *remove_ext (char* mystr, char dot, char sep);
- int main()
- {
- char fname1[256],fname2[256];
- char folderpath[256];
- int mod;
- int re_mainder;
- char *tem;
- char filenameNoExtension;
- char **filelist;
- int i,j,l;
- char ***ls = &filelist;
- int file_count = 0;
- char *s;
- DIR* dp = NULL;
- struct dirent* entry = NULL;
- FILE* fp = NULL;
- /*open folder*/
- printf("enter the folder path : ");
- scanf("%s",folderpath);
- /* Err message of opening directory */
- if((dp = opendir(folderpath)) ==NULL) {
- fprintf(stderr,"unidentified folder : %s",folderpath);
- return 0;
- }
- *ls = NULL;
- /*file count*/
- while ((entry = readdir(dp)) != NULL) {
- if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
- continue;
- ++file_count;
- }
- /* rewind the directory and need to reallocate memory for reading 18250 files */
- rewinddir(dp);
- *ls = calloc(file_count, sizeof(char*));
- /*make the array of filelist*/
- file_count = 0;
- entry = readdir(dp);
- while(NULL != entry) {
- (*ls)[file_count++] = strdup(entry->d_name);
- entry = readdir(dp);
- }
- /*remove the extension */
- for(i = 0; i < file_count; i++) {
- filelist[i] = remove_ext(filelist[i], '.', '/');
- }
- closedir(dp);
- //loop starts at 2 for get rid of space & .
- for(i = 2; i< file_count; i++) {
- printf("%sn",filelist[i]);
- }
- /*select the mod & remainder*/
- printf("select the mod number : ");
- scanf("%d", &mod);
- printf("select the remainder : ");
- scanf("%d",&re_mainder);
- /*sort files by the remainder*/
- for(i = 2; i<file_count; i++) {
- if( atoi( filelist[i] )%mod == re_mainder) { /*use atoi function for changing string to int*/
- filelist[i] = filelist[i];
- }
- else
- filelist[i] = "delete";
- }
- //delete the "delete" in array
- l = file_count;
- for(i = 0; i<l; i++) {
- if (strcmp(filelist[i], "delete") == 0 ) {
- for(j = i; j < l; j++)
- filelist[j]=filelist[j+1];
- i--; //check again from same index i
- l--; //Decreasing the length of the array
- }
- }
- /* resize the modified file_count */
- file_count = sizeof(filelist)/sizeof(filelist[0]);
- for(i =2; i<file_count; i++) {
- printf("%sn",filelist[i]);
- }
- /********** **HERE"S MY QUESTION** **********/
- /**********openfiles according to reprogramed filelist**********/
- for(i =2; i<file_count; i++) {
- strcat(filelist[i],".txt");
- if((fp = fopen( filelist[i], "r")) == NULL)
- {
- perror("error to openfiles");
- exit(1);
- }
- /*declare the variables*/
- char data[3][513];
- //char wavenumber[513], wavelength[513], powerspec[513];
- int COL, ROW, MAX_wavenumber, MAX_wavelength, MAX_powerspec;
- int HEIGHT,WIDTH;
- HEIGHT = 513;
- WIDTH = 3;
- //input data to new array
- for(COL = 0; COL < HEIGHT; COL++) {
- for (ROW = 0; ROW < WIDTH; ROW++) {
- fscanf(fp, "%s", &data[ROW][COL]);
- }
- }
- //start of comparison of data
- for(COL = 2; COL < HEIGHT - 1; COL++) { //number starts from the 3rd column
- while(ROW == 1) {
- if( atof(&data[ROW][COL]) < atof(&data[ROW][COL+1]) ) {
- MAX_wavenumber = atof(&data[ROW][COL+1]);
- }
- while(ROW == 2) {
- if( atof(&data[ROW][COL]) < atof(&data[ROW][COL+1]) ) {
- MAX_wavelength = atof(&data[ROW][COL+1]);
- }
- }
- while(ROW == 3)
- if( atof(&data[ROW][COL]) < atof(&data[ROW][COL+1]) ) {
- MAX_powerspec = atof(&data[ROW][COL+1]);
- }
- }
- }
- printf("MAX_wavenumber : %d",MAX_wavenumber);
- printf("MAX_wavelength : %d",MAX_wavelength);
- printf("MAX_powerspec : %d",MAX_powerspec);
- fclose(fp);
- }
- }
- //this is just for removing the extension of files
- char *remove_ext (char* mystr, char dot, char sep) {
- char *retstr, *lastdot, *lastsep;
- // Error checks and allocate string.
- if (mystr == NULL)
- return NULL;
- if ((retstr = malloc (strlen (mystr) + 1)) == NULL)
- return NULL;
- // Make a copy and find the relevant characters.
- strcpy (retstr, mystr);
- lastdot = strrchr (retstr, dot);
- lastsep = (sep == 0) ? NULL : strrchr (retstr, sep);
- // If it has an extension separator.
- if (lastdot != NULL) {
- // and it's before the extenstion separator.
- if (lastsep != NULL) {
- if (lastsep < lastdot) {
- // then remove it.
- *lastdot = '