|
[Sponsors] |
[making animations] fclose fails to close files? |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
March 30, 2001, 09:19 |
[making animations] fclose fails to close files?
|
#1 |
Guest
Posts: n/a
|
Hello,
As I said previously, I'm working on a scheme program to automate the processing of data in transient calculations. My objective is to write a simple program to export the same contour maps for each data files. With the maps saved in graphic format (TIFF for example), it becomes easy to animate them with Imagemagick for example (Nb: (convert *.tiff *.miff)(cat *.miff > animate.miff)(animate animate.miff)). I would like to have the same scale on each maps (the same color represents the same value - manual scale). So I have written a little UDF file which writes in a file the value of the maximum and minimum of each data i want to represent (pressure, x velocity...) By makimg a loop on each data file, i have the maximum and the minimum of all my data files, and so the range of my scales. The UDF seems to work good too, but aftrer 11 data files, the program hangs (BUS ERROR). After some hours of debugging, i realize that my program file seems to be bugs less, and it's the system which doesn't close correctly my file. So I don't know how I can make it work? Can someone help me? Thnks a lot. Mika. PS: here are the scheme and UDF files. ------------------------------------------------------- SCHEME FILE ------------------------------------------------------- ;; ;; minimax.scm ;; ;; search and write the maximum and the minimum ;; in all data files ;; ;; ex: ;; (minimax "/fluent/calculs/" "calcul-0001.cas" ;; "calcul-*.dat") ;; (define (minimax filepath cas dat) ;; path to minimax udf function (define path2minimax "/fluent/udf/minimax") ;; complete path to the .cas file of my result (define filecas(string-append filepath cas)) ;; complete path to .dat(s) file(s) of my result (define filesdat (string-append filepath dat)) ;; open for writing (initalization) (define file (open-output-file (string-append filepath "minimax.dat"))) ;; writes 0 (display "0 0 0 0 0 0 0 0" file) ;; close of the file (close-output-port file) ;; read the UDF file (ti-menu-load-string (format #f (string-append "/define/user-defined/compiled-functions " path2minimax ))) ;; read the .cas file (ti-menu-load-string (format #f "/file/read-case ~a" filecas)) ;; loop on all data files (let loop ((files (file-pattern-exists? filesdat))) (if (pair? files) (begin ;; read .dat file (ti-menu-load-string (format #f "/file/read-data ~a" (car files))) ;; execute UDF function minimax (ti-menu-load-string (format #f "/define/user-defined/udf-on-demand \"minimax\"")) ;; continue loop (loop (cdr files)))))) ------------------------------------------------------- UDF FILE ------------------------------------------------------- #include <stdio.h> #include "udf.h" extern Domain* domain; DEFINE_ON_DEMAND(minimax) { Thread *t; cell_t c; real p; real vx; real vy; real v; real p0p; real vx0p; real vy0p; real v0p; real p0m; real vx0m; real vy0m; real v0m; FILE* file; FILE* file2; FILE* file3; char path[500]; if((file=fopen("/fluent/udf/minimax/minimax.ini","r"))==NULL) { fprintf(stdout,"\nerror while opening the file 1\n"); exit(-1); } fscanf(file,"%s",path); if((fclose(file))==NULL) { fprintf(stdout,"error while closing file 1\n"); } if((file2=fopen(path,"r"))==NULL) { fprintf(stdout,"error while opening file 2\n"); exit(-1); } fscanf(file2,"%f %f %f %f %f %f %f %f",&p0m, &p0p, &vx0m, &vx0p, &vy0m, &vy0p, &v0m, &v0p); if((fclose(file2))==NULL) { fprintf(stdout,"error while closing 2\n"); } thread_loop_c(t,domain) { begin_c_loop(c,t) { p = C_P(c,t); vx = C_U(c,t); vy = C_V(c,t); v = sqrt(pow(vx,2)+pow(vy,2)); if(p < p0m) p0m=p; if(p > p0p) p0p=p; if(vx < vx0m) vx0m=vx; if(vx > vx0p) vx0p=vx; if(vy < vy0m) vy0m=vy; if(vy > vy0p) vy0p=vy; if(v < v0m) v0m=v; if(vy > v0p) v0p=v; } end_c_loop(c,t) } thread_loop_f(t,domain) if((file3=fopen(path,"w"))==NULL) { fprintf(stdout,"error while opening file 3\n"); exit(-1); } fprintf(file3,"%f %f %f %f %f %f %f %f",p0m, p0p, vx0m, vx0p, vy0m, vy0p, v0m, v0p); if((fclose(file3))==NULL) { fprintf(stdout,"error while closing 3\n"); } } ----------------------------------------------------- The file minimax.ini contains a string which indicates the path to write the minimax.dat file. |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
UDF issue | MASOUD | Fluent UDF and Scheme Programming | 14 | December 6, 2012 14:39 |
critical error during installation of openfoam | Fabio88 | OpenFOAM Installation | 21 | June 2, 2010 04:01 |
OF 1.6 | Ubuntu 9.10 (64bit) | GLIBCXX_3.4.11 not found | piprus | OpenFOAM Installation | 22 | February 25, 2010 14:43 |
Problems in compiling paraview in Suse 10.3 platform | chiven | OpenFOAM Installation | 3 | December 1, 2009 08:21 |
OpenFOAM15 paraFoam bug | koen | OpenFOAM Bugs | 19 | June 30, 2009 11:46 |