CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   FLUENT (https://www.cfd-online.com/Forums/fluent/)
-   -   [making animations] fclose fails to close files? (https://www.cfd-online.com/Forums/fluent/28388-making-animations-fclose-fails-close-files.html)

Mika March 30, 2001 09:19

[making animations] fclose fails to close files?
 
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.



All times are GMT -4. The time now is 06:05.