|
[Sponsors] |
How to read a Value from Text File and store it in Variables (writing in UDF) |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
October 26, 2020, 04:50 |
How to read a Value from Text File and store it in Variables (writing in UDF)
|
#1 |
Member
Amirreza Niazmehr
Join Date: Nov 2018
Posts: 40
Rep Power: 8 |
Hi guys
This is my text file (Data.txt): rho_0 10 kp_0 8 Beta_kp 6 x_min 5 x_max 8 y_min 9 y_max 5 z_min 4 z_max 7 I want to read from this text file line by line and store each Value in the parameter at the same line. for example, for the first line store 10 in rho_0. I have written as below.At the next end I want to use x_min and x_max ... to calculate Volume. I mean Volume=(x_max-x_min)*(y_max-y_min)*(z_max-z_min). I have written this code (as below) in C and now I want to use it in my UDF. First I want to define the Macros and then use this code. I just want to know if my code works, if I first use and define the proper Macros. I mean,is the body of my code proper for using in UDF? Code:
#include <stdio.h> #include <math.h> #include <stdlib.h> int main() { double rho_0, kp_0, Beta_kp; double x_min, x_max ,y_min ,y_max ,z_min, z_max, V_plasmazone; char param_name[100]; FILE *inputfile; char inputpath[100]; char path [100] ; strcpy(inputpath, path); strcat(inputpath, "Dataa.txt"); inputfile = fopen(inputpath, "r"); /* if(inputfile) { ScanCheck(fscanf(inputfile, "%s", inputpath), 1, inputfile, "Data.txt", 1); strcat(path, inputpath); strcat(path, "/"); } else { Error("Error opening input.txt - file!"); }*/ //inputfile =fopen ("Data.txt","r") ; if(inputfile == NULL) { perror("Unable to open file!"); exit (1); } fscanf(inputfile, "%s %lf\n", param_name, &rho_0); printf("%s %lf\n", param_name, rho_0); fscanf(inputfile, "%s %lf\n", param_name, &kp_0); printf("%s %lf\n", param_name, kp_0); fscanf(inputfile, "%s %lf\n", param_name, &Beta_kp); printf("%s %lf\n", param_name, Beta_kp); fscanf(inputfile, "%s %lf\n", param_name, &x_min); printf("%s %f\n", param_name, x_min); fscanf(inputfile, "%s %lf\n", param_name, &x_max); printf("%s %f\n", param_name, x_max) ; fscanf(inputfile, "%s %lf\n", param_name, &y_min); printf("%s %f\n", param_name, y_min); fscanf(inputfile, "%s %lf\n", param_name, &y_max); printf("%s %f\n", param_name, y_max); fscanf(inputfile, "%s %lf\n", param_name, &z_min); printf("%s %f\n", param_name, z_min); fscanf(inputfile, "%s %lf\n", param_name, &z_max); printf("%s %f\n", param_name, z_max); V_plasmazone = ( x_max - x_min )*( y_max - y_min )*( z_max - z_min ); printf( "V_plasmazone %lf\n", V_plasmazone ); fclose(inputfile); return 0; } |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to read a Value from Text File and store it in Variables | Amirreza_pro | Fluent UDF and Scheme Programming | 5 | April 5, 2024 16:14 |
simple UDF doesn't read input from external file. interprets/compiles without errors | ahmad_xjtu | Fluent UDF and Scheme Programming | 5 | March 23, 2018 03:03 |
UDF macro to read the name of the case file | polaritus | Fluent UDF and Scheme Programming | 2 | March 23, 2015 05:59 |
writing data to file using UDF | sawa | FLUENT | 0 | November 8, 2005 06:51 |
Results saving in CFD | hawk | Main CFD Forum | 16 | July 21, 2005 21:51 |