int main() { printf("Hello boys!\n"); createfile(); readtxt(); readall(); return 0; }
int main(int argc, char *argv[]) { FILE *fin, *report, *ftxt, *fsad; int rows, cols, bands, nendmembers, i, nthreads; char ersfile[100], binfile[100], tiffile[100], sysstring[200], txtfile[100], sadfile[100]; float **a; if(argc!=7){ puts(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *"); puts(" * *"); puts(" * SAD: Calculate Spectral Angle Distance of a set Signatures *"); puts(" * with an Image *"); puts(" * *"); puts(" * - Input parameters (at command line) : *"); puts(" * - Image filename *"); puts(" * - Text file Path *"); puts(" * - Number of Rows *"); puts(" * - Number of Columns *"); puts(" * - Number of Bands *"); puts(" * - Number of Signatures *"); puts(" * *"); puts(" * - Works on the file types supported by GDAL *"); puts(" * *"); puts(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *"); puts(" * *"); puts(" * Output : - Report : Imagename_SAD_report.txt *"); puts(" * - SAD Image : Imagename_SAD *"); puts(" * *"); puts(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *"); puts(" * *"); puts(" * SAD by Dimitris Kefalos ([email protected]) *"); puts(" * *"); puts(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *"); system("PAUSE"); exit(1); } /* File Manipulation */ strcpy(tiffile, argv[1]); i=(strlen(tiffile)-4); memcpy(binfile, tiffile, strlen(tiffile)-4); binfile[i]='\0'; i=(strlen(binfile)); memcpy(ersfile, binfile, strlen(binfile)); ersfile[i]='\0'; sprintf(ersfile, "%s.ers", binfile); memcpy(txtfile, binfile, strlen(binfile)); txtfile[i]='\0'; sprintf(txtfile, "%s_SAD_report.txt", binfile); i=(strlen(binfile)); memcpy(sadfile, binfile, strlen(binfile)); sadfile[i]='\0'; sprintf(sadfile, "%s_SAD", binfile); /* Argument Handling */ rows=atoi(argv[3]); cols=atoi(argv[4]); bands=atoi(argv[5]); nendmembers=atoi(argv[6]); if (rows<0){ puts("Please give a valid number of rows"); exit(-1); } if (cols<0){ puts("Please give a valid number of columns"); exit(-1); } if (bands<0){ puts("Please give a valid number of bands"); exit(-1); } if (nendmembers<0){ puts("Please give a valid number of endmembers"); exit(-1); } /* GDAL Call */ sprintf(sysstring, "gdal_translate -ot Float32 -of ERS %s %s", tiffile, ersfile); printf("\n"); printf(sysstring); printf("\n"); if ((i=system(sysstring))!=0 && (i=system(sysstring))!=1){ puts("\nGDAL did not run correctly"); exit(-1); } puts("GDAL has Executed"); /* File Opening */ if ( (fin=fopen(binfile , "rb")) == NULL){ printf("\nCannot open %s file.\n", binfile); exit (-1); } if ( (fsad=fopen(sadfile , "wb+")) == NULL){ printf("\nCannot open %s file.\n", sadfile); exit (-1); } if ( (report=fopen(txtfile , "wt")) == NULL){ printf("\nCannot open %s file.\n", txtfile); exit (-1); } if ((ftxt=fopen(argv[2], "rt")) == NULL){ printf("\nCannot open text file.\n"); exit (-1); } if ( (a = malloc(nendmembers*sizeof(float*))) == NULL){ puts("\nBad Memory Allocation.\n"); return(-1); } for (i=0; i< nendmembers; i++){ if ( (a[i] = malloc(bands*sizeof(float))) == NULL){ puts("\nBad Memory Allocation.\n"); return(-1); } } /* Read Signature Text File */ readtxt(ftxt, report, bands, nendmembers, a); /* Create SAD Image */ SAD_image(fin, fsad, report, rows, cols, bands, nendmembers, a); /* Closing */ for (i=0; i<nendmembers; i++){ free(a[i]); } free(a); fflush(NULL); if (fclose(ftxt)!=0){ puts("Error in txt closing"); } if (fclose(report)!=0){ puts("Error in report closing"); } if (fclose(fsad)!=0){ puts("Error in fin closing"); } if (fclose(fin)!=0){ puts("Error in fin closing"); } return(0); }