CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT

Parse error in UDF code

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree3Likes
  • 2 Post By pakk
  • 1 Post By pakk

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 13, 2013, 07:31
Default Parse error in UDF code
  #1
New Member
 
Join Date: Oct 2013
Posts: 25
Rep Power: 13
stuart230588 is on a distinguished road
Hi,

I am very new to c coding. I am trying to define temperature dependent material properties and have come across a parse error in my code, getting the error:

UDF.c: line 2: parse error

My code at this stage is:

#include “udf.h”
DEFINE_PROPERTY(argon_density, cell, thread)
{
float temp, rho;
temp = C_T(cell, thread);

So it's in the define property line.

Probably simple but can someone point out what I've done wrong and how to correct it?

Thanks,
Stuart
stuart230588 is offline   Reply With Quote

Old   November 14, 2013, 08:51
Default
  #2
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
I compiled this without parse error:
Code:

#include"udf.h"
DEFINE_PROPERTY(argon_density, cell, thread)
{
float temp, rho;
temp = C_T(cell, thread);
return temp;
}
Are you sure your code is exactly as you wrote above?
pakk is offline   Reply With Quote

Old   November 14, 2013, 09:07
Default
  #3
Super Moderator
 
flotus1's Avatar
 
Alex
Join Date: Jun 2012
Location: Germany
Posts: 3,427
Rep Power: 49
flotus1 has a spectacular aura aboutflotus1 has a spectacular aura about
Depending on where you copied the code from, the text may contain "invisible" characters that lead to errors during compilation.
Copying the code again for example from this forum post can indeed lead to a better result.
flotus1 is offline   Reply With Quote

Old   November 14, 2013, 09:40
Default
  #4
New Member
 
Join Date: Oct 2013
Posts: 25
Rep Power: 13
stuart230588 is on a distinguished road
Thanks for your replies.

However, I am still getting the same parse code error.

I have attached a screenshot and the UDF code that I am trying to interpret. If you could help out that would be much appreciated.

Thanks,
Stuart
Attached Images
File Type: jpg Parse code error.jpg (98.0 KB, 120 views)
Attached Files
File Type: c Argon density UDF.c (1.7 KB, 46 views)
stuart230588 is offline   Reply With Quote

Old   November 14, 2013, 10:29
Default
  #5
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
I got the same result when I interpreted your code.

I was able to fix it by changing the format from UNICODE to ASCII, and using linux-style Line-endings. I don't know which of those solved the problem.

If you don't know how to do this yourself, I can not give you a clear advice on how to do it, but in that case I hope google can help you or somebody else on this forum.
pakk is offline   Reply With Quote

Old   November 14, 2013, 11:03
Default
  #6
New Member
 
Join Date: Oct 2013
Posts: 25
Rep Power: 13
stuart230588 is on a distinguished road
Thanks for your response Pakk,

How did you convert from UNICODE to ASCII? I found websites online that convert the format but because of my lack of programming knowledge I'm not sure if what it changes it to is correct. Either way it still wouldn't interpret.

How did you convert the line endings to Linux? Is this something that can be done without any Linux programming knowledge or a Linux OS?

Also, could you send the file that you managed to interpret so I can try and figure it out?

Cheers,
Stuart
stuart230588 is offline   Reply With Quote

Old   November 20, 2013, 08:17
Default
  #7
New Member
 
Join Date: Oct 2013
Posts: 25
Rep Power: 13
stuart230588 is on a distinguished road
Does anyone know how to fix this?
stuart230588 is offline   Reply With Quote

Old   November 20, 2013, 08:20
Default
  #8
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
What I think could help:
-Open the file in Textpad
-Select 'Save as'
-File format: UNIX
-Encoding: ANSI
-Save the file
pakk is offline   Reply With Quote

Old   November 20, 2013, 09:14
Default
  #9
New Member
 
Join Date: Oct 2013
Posts: 25
Rep Power: 13
stuart230588 is on a distinguished road
This is driving me demented!

When I change the file format from .c to .unix Fluent does not recognise this as a source file. When I change UDF source files to All files in the search box and select the new .unix file I get the same parse code error.

You mentioned linux-style line endings - how do I go about doing that?

Thanks
stuart230588 is offline   Reply With Quote

Old   November 20, 2013, 09:20
Default
  #10
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
I never said you should change the extension from .c to .unix...
I gave you an explanation at 13:20 today on how to use Textpad to change your file to unix-style endings.

(In my vocabulary, "unix-style endings" and "linux-style endings" are the same thing. I know that one of them is a wrong term.)
pakk is offline   Reply With Quote

Old   November 20, 2013, 09:30
Default
  #11
New Member
 
Join Date: Oct 2013
Posts: 25
Rep Power: 13
stuart230588 is on a distinguished road
Ok, I think I must be missing something as I don't have the option to select UNIX file format and ANSI encoding...

What have I done wrong this time?

Sorry to be a pest
Attached Images
File Type: jpg Save screen.jpg (93.4 KB, 79 views)
stuart230588 is offline   Reply With Quote

Old   November 20, 2013, 09:44
Default
  #12
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
You used Notepad, I used Textpad. Notepad does not have this option, Textpad does.

(And Notepad does have the ANSI encoding option, I can see it in your screenshot. But it looks like you already selected that one.)
pakk is offline   Reply With Quote

Old   November 20, 2013, 10:18
Post
  #13
New Member
 
Join Date: Oct 2013
Posts: 25
Rep Power: 13
stuart230588 is on a distinguished road
Thanks for your help Pakk

Downloaded Textpad but still having the parse error after following your steps above.

So frustrating!
stuart230588 is offline   Reply With Quote

Old   November 20, 2013, 10:48
Default
  #14
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
Are you 100% sure that you tried my UDF that I posted on November 14, 2013, 13:51, and that this gave the same error for you?
pakk is offline   Reply With Quote

Old   November 20, 2013, 11:23
Default
  #15
New Member
 
Join Date: Oct 2013
Posts: 25
Rep Power: 13
stuart230588 is on a distinguished road
I am using the code that I uploaded on 14th November at 14.40.

The error has changed to "invalid expression type for if: float"

referring to the line "rho = 0.098;"
stuart230588 is offline   Reply With Quote

Old   November 20, 2013, 11:40
Default
  #16
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
I think you initially received an error message because you used the wrong quotes in your first line.
Code:
#include “udf.h” //your version
#include "udf.h"//correct version
The error message that you see now, is because you use a single minus sign where you should use two. So:
Code:
if (temp = 293. )
should be
Code:
if (temp == 293. )
This also happens at other places in your code.

In fact, this line can be removed, which will make your code easier:
Code:
if (temp == 293. )
rho = 1.623;
elseif (temp > 293. && temp < 500. )
rho = 1.623 + ((0.999 - 1.623) / 207. ) * (temp - 293. );
is the same as
Code:
if ((temp >= 293.) && (temp < 500.))
rho = 1.623 + ((0.999 - 1.623) / 207. ) * (temp - 293. );
I also added extra brackets in the if-statement for clarity.
Finally, note that in the current code, if the temperature is below 293K your argon will have a low density (0.098), which is not physical. If you are sure that the temperature will not drop below 293K, it is not a problem, but it could be safer to start with a line "if (temp<293.) ...".
stuart230588 likes this.
pakk is offline   Reply With Quote

Old   November 21, 2013, 04:45
Default
  #17
New Member
 
Join Date: Oct 2013
Posts: 25
Rep Power: 13
stuart230588 is on a distinguished road
Thanks very much for the help Pakk.

The UDFs appear to be interpreting now although I haven't run a simulation yet.
stuart230588 is offline   Reply With Quote

Reply

Tags
c coding, parse error, programming, udf error

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
udf code for anisotropy turbulence model- square duct Eliasjal Fluent UDF and Scheme Programming 1 August 29, 2012 11:26
parse error while interpreting udf Kristin Fluent UDF and Scheme Programming 3 March 15, 2012 07:43
Parse Error Message While interpreting UDF in FLUENT dhimans Fluent UDF and Scheme Programming 1 July 10, 2009 07:29
UDF parse error alemenchaca FLUENT 0 July 1, 2009 20:45
PARSE ERROR Message when interpreting UDF in FLUENT dhimans FLUENT 0 May 24, 2009 12:40


All times are GMT -4. The time now is 19:53.