void operations(int op, FILE *stream, int row, int col, int grey_scale){ int mask_dim; int **conv_image; double **mask; char *mask_file; FILE *fp; switch(op) { case 1: //Produção do negativo. negativeTransform(stream, row, col, grey_scale); break; case 2: //Filtragem Espacial. mask_file = readLine(); //Lê o nome do arquivo de máscara. fp = fopen(mask_file, "r"); if(!fp) noFile(mask_file, fp); mask = readMask(fp, &mask_dim);//Armazena o seu conteúdo. //Recebe a imagem já com a filtragem espacial conv_image = convolution(stream, mask, row, col, grey_scale, mask_dim); //Libera o conteúdo relacionado com a máscara. freeMask(mask_dim, mask, mask_file, fp); printImage(row, col, grey_scale, conv_image); break; default: //Caso não seja digitado nenhum operador esperado printf("Unknown Operator.\n"); break; } }
int movie(char *command, const char *frameFile) { int failed = TRUE; double step; LINEBUF frameData[1]; register int j; static const char noDataMsg[] = "/** Data file does not define any fields **/"; if (*command == 'R' || *command == 'D' || *command == 'I') { loadData(infile); if (npnts < 1) return TRUE; step = (qmax - qmin) / (double) (npnts - 1); for (j = 0; j < npnts; j++) xtemp[j] = (double) j * step + qmin; if (extend(xtemp, npnts, lambda, lamdel, thedel) == NULL) return TRUE; } if (openBuf(frameFile, "r", frameData, FBUFFLEN) == NULL) noFile(frameFile); else { int frames; long headerOffset; frames = countData(frameData); headerOffset = locateHeader(frameData); if (headerOffset == -1) puts(noDataMsg); else { int numFields; setNextLine(frameData, headerOffset); getNextLine(frameData); numFields = loadFields(frameData, frameData->buffer+1); if (numFields == 0) puts(noDataMsg); else if (numFields > 0) { FILE *gnuPipe; genva(fields, 1, fitlist); gnuPipe = popen("gnuplot", "w"); if (gnuPipe != NULL) { failed = runMovie(npnts, frames, numFields, frameData, gnuPipe, command); pclose(gnuPipe); } } } closeBuf(frameData, 0); } return failed; }
int movie(char *command, int xspin[4], const char *frameFile) { int failed = TRUE; LINEBUF frameData[1]; static const char noDataMsg[] = "/** Data file does not define any fields **/"; /* Determine reflectivities to print */ setPspin(pspin, xspin, command + 1); if ((*command == 'R' || *command == 'D' || *command == 'I') && ( loadData(infile, xspin) || extend(q4x, n4x, lambda, lamdel, thedel) == NULL ) ) return TRUE; if (openBuf(frameFile, "r", frameData, FBUFFLEN) == NULL) noFile(frameFile); else { int frames; long headerOffset; frames = countData(frameData); headerOffset = locateHeader(frameData); if (headerOffset == -1) puts(noDataMsg); else { int numFields; setNextLine(frameData, headerOffset); getNextLine(frameData); numFields = loadFields(frameData, frameData->buffer + 1); if (numFields == 0) puts(noDataMsg); else if (numFields > 0) { FILE *gnuPipe; genva(fields, 1, fitlist); gnuPipe = popen("gnuplot", "w"); if (gnuPipe != NULL) { failed = runMovie(frames, numFields, frameData, gnuPipe, command); pclose(gnuPipe); } } } closeBuf(frameData, 0); } return failed; }
int getR8(int xdim, int ydim, char *image, char *pal, int compress) { FILE *fp; int32 length; char *buf; if (!fileOpen()) { noFile(); return FAIL; } if (pal) if (setPal(pal) < 0) /* Error already signalled by setPal */ return FAIL; length = xdim * ydim; buf = (char *) HDmalloc(length); if ((fp = fopen(image, "r")) == NULL) { fprintf(stderr, "Error opening image file: %s.\n", image); return FAIL; } if (fread(buf, (size_t)xdim, (size_t)ydim, fp) < (size_t)ydim) { fprintf(stderr, "Error reading image file: %s.\n", image); return FAIL; } fclose(fp); if (DFR8addimage(he_file, buf, (int32) xdim, (int32) ydim, (uint16) compress) < 0) { HEprint(stderr, 0); return FAIL; } HDfree(buf); if (updateDesc() < 0) return FAIL; return HE_OK; }
int main(int argc, char *argv[]) { int op, row, col, grey_scale; char *image_file; FILE *fp; scanf("%d\n", &op); //Recebe a operação desejada. image_file = readLine(); //Lê o nome do arquivo. fp = fopen(image_file, "r"); //executa a função caso o arquivo esteja vazio: if(!fp) noFile(image_file, fp); imageDim(&row, &col, &grey_scale, fp); //Recebrá as dimensões. operations(op, fp, row, col, grey_scale);//Executa a operação desejada. free(image_file); fclose(fp); return 0; }
int main(int argc, char *argv[]) { int i, tamanho; unsigned int *file = NULL; char *nome; FILE *fp_input; nome = readLine(); //recebe o nome do arquivo fp_input = fopen(nome, "rb");//abre o arquivo com o nome informado //usa-se "rb" pois o arquivo está salvo como binário(.bin) if(fp_input == NULL) noFile(nome, fp_input);//executa a função caso o arquivo esteja vazio tamanho = size(fp_input); //recebe o tamanho, em bytes, do arquivo file = alocateFile(tamanho, fp_input); //recebe o conteúdo do arquivo reverseVec(file, tamanho); //Função para desinverter o vetor chooseFunction(file, tamanho, nome); //Função para o usuário escolher a operação a ser executada //É liberado tudo que foi salvo na Heap. free(file); free(nome); return 0; }
/* Convert Q4X to an array of equal intervals */ if (n4x <= 1) { puts("Not enough data points"); failed = TRUE; } else { qstep = (q4x[n4x - 1] - q4x[0]) / (double) (n4x - 1); qi = q4x[0]; for (n = 0; n < n4x; n++) { q4x[n] = qi; qi += qstep; } extres(q4x, lambda, lamdel, thedel, n4x); printf("Npnts: %6d\n" "Nlow: %6d; Qmin: %#15.7G\n" "Nhigh: %6d; Qmax: %#15.7G\n", n4x, nlow, q4x[0] - (double) nlow * (q4x[1] - q4x[0]), nhigh, q4x[n4x - 1] + (double) nhigh * (q4x[n4x - 1] - q4x[n4x - 2])); } return failed; } #if 0 /* Unused code, questionable algorithm */ int calcConvolve(char *polstat) { int failed = FALSE; int l, ntot, npnts; double qmin, qmax; register int j; FILE *unit1; /* Read data from INFILEs */ l = lenc(infile); strcpy(filnam, infile); npntsa = 0; npntsb = 0; npntsc = 0; npntsd = 0; ntot = 0; npnts = 0; aspin = FALSE; bspin = FALSE; cspin = FALSE; dspin = FALSE; for (j = 0; j < (int) strlen(polstat); j++) { filnam[l] = polstat[j]; filnam[l + 1] = 0; unit1 = fopen(filnam, "r"); if (unit1 == NULL) { noFile(filnam); failed = TRUE; break; } while (!feof(unit1)) { fgets(filebuf, FBUFFLEN, unit1); if ( sscanf(filebuf, "%lf %lf %lf", &(xdat[npnts]), &(ydat[npnts]), &(srvar[npnts])) == 3 ) npnts++; } switch (polstat[j]) { case 'a': npntsa = npnts - ntot; qmin = xdat[ntot]; qmax = xdat[npnts - 1]; aspin = TRUE; break; case 'b': npntsb = npnts - ntot; qmin = xdat[ntot]; qmax = xdat[npnts - 1]; bspin = TRUE; if (aspin) { if (npntsb != npntsa) { puts("data files must be same size"); failed = TRUE; } } else { register int nb; /* Shift data to appropriate location in YDAT for MANCON4 */ for (nb = 1; nb <= npntsb; nb++) ydat[npntsb + nb] = ydat[nb]; } npnts = 2 * npntsb; break; case 'c': npntsc = npnts - ntot; qmin = xdat[ntot]; qmax = xdat[npnts - 1]; cspin = TRUE; if (aspin && (npntsc != npntsa)) { puts("data files must be same size"); failed = TRUE; } else if (bspin && (npntsc != npntsb)) { puts("data files must be same size"); failed = TRUE; } else { register int nc; /* Shift data to appropriate location in YDAT for MANCON4 */ for (nc = 1; nc <= npntsc; nc++) ydat[2 * npntsc + nc] = ydat[npntsa + npntsb + nc]; } npnts = 3 * npntsc; break; case 'd': npntsd = npnts - ntot; qmin = xdat[ntot]; qmax = xdat[npnts - 1]; dspin = TRUE; if (aspin && (npntsd != npntsa)) { puts("data files must be same size"); failed = TRUE; } else if (bspin && (npntsd != npntsb)) { puts("data files must be same size"); failed = TRUE; } else if (cspin && (npntsd != npntsc)) { puts("data files must be same size"); failed = TRUE; } else { register int nd; /* Shift data to appropriate location in YDAT for MANCON4 */ for (nd = 1; nd <= npntsd; nd ++) ydat[3 * npntsd + nd] = ydat[npntsa + npntsb + npntsc + nd]; } npnts = 4 * npntsd; break; } ntot = npnts; fclose(unit1); } if (!failed) { int n, noff; /* n4x = sortq(xdat, npntsa, npntsb, npntsc, npntsd, q4x, nqa, nqb, nqc, nqd); */ /****** Here I will cheat because I am still lazy ******/ fputs("Enter nlow, nhigh: ", stdout); fgets(filebuf, FBUFFLEN, stdin); sscanf(filebuf, "%d %d", &nlow, &nhigh); for (j = 0; j < npntsa; j++) q4x[j] = xdat[j]; n4x = npntsa; mancon4(q4x, lambda, lamdel, thedel, ydat, yfit, n4x - nlow - nhigh, nlow, nhigh, ncross, FALSE); npnts = n4x - nlow - nhigh; ncross = aspin + bspin + cspin + dspin; /* Dress with intensity factors */ for (n = 0; n < ncross; n++) { noff = n * npnts; for (j = 0; j < npnts; j++) ydat[j + noff] = log10(fabs(bki + bmintns * ydat[j + noff])); } /* Send to appropriate output files */ l = lenc(outfile); if (l >= 1) strcpy(filnam, outfile); else { l = copyBasename(filnam, infile); strcat(filnam, ".fit "); l += 4; } for (n = 0; n < ncross; n++) { filnam[l] = polstat[n]; unit1 = fopen(filnam, "w"); for (j = 0; j < npnts; j++) fprintf(unit1, "%#15.7G%#15.7G\n", xdat[j + nlow], ydat[j + noff]); fclose(unit1); } } return failed; }