Discussion Closed This discussion was created more than 6 months ago and has been closed. To start a new discussion with a link back to this one, click here.

Format of Exported Data

Please login with a confirmed email address before reporting spam

Does any one know if there is a way of controlling the format (i.e. specify floating point precision, comma or tab delimiter etc) of how data is output from the export node? For data, plot, mesh or table there is no option to do this!

The advanced tab states full precision but matlab 15a doesn't open these that well - it is variable space delimited with different formats of output (i.e. some written to 3 decimal places, some 5 decimal places) which seems to cause a problem.

Although python doesn't have a problem opening these files once you have handled the '%' as a comment character.


4 Replies Last Post 11 ago 2016, 08:26 GMT-4
Lars Gregersen COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 8 years ago 5 lug 2016, 06:40 GMT-4
Hi

The data formats that COMSOL exports to are explained in the Programming Reference Manual in the "The COMSOL File Formats". Depending on what you are trying to export there are different allowed formats, but you have little control of how things are formatted when exporting.

The problem with importing into Matlab is most likely not that the precision varies, but rather that the number of interesting values to read in each line varies from line to line (for most of our file formats). This requires special handling in Matlab.

If you have access to LiveLink for Matlab I recommend you retrieve the data directly in to Matlab using one on the many import functions. Most notably if you can create a plot of the data you need you can do
pd = mphplot(model, 'pg1')
and then the variable pd will contain all the data that are needed to recreate the plot.

--
Lars Gregersen
Comsol Denmark
Hi The data formats that COMSOL exports to are explained in the Programming Reference Manual in the "The COMSOL File Formats". Depending on what you are trying to export there are different allowed formats, but you have little control of how things are formatted when exporting. The problem with importing into Matlab is most likely not that the precision varies, but rather that the number of interesting values to read in each line varies from line to line (for most of our file formats). This requires special handling in Matlab. If you have access to LiveLink for Matlab I recommend you retrieve the data directly in to Matlab using one on the many import functions. Most notably if you can create a plot of the data you need you can do pd = mphplot(model, 'pg1') and then the variable pd will contain all the data that are needed to recreate the plot. -- Lars Gregersen Comsol Denmark

Please login with a confirmed email address before reporting spam

Posted: 8 years ago 10 ago 2016, 06:50 GMT-4
Sure - If I am using the Matlab livelink I can easily have access to the variables in the workspace. For example, using mphplot I can access the field data, which in my case is vector as pd{1,1}{1,1}.p. This is single precision, and I guess there is no way of specifying the precision in this context?

It would be a suggestion for a new release to include some control (in an advanced tab for example) as to how the data is written to an ASCII file, using standard C formatting say. (I guess it should be straightforward to implement, although this is pure speculation).

If you don't have access to the matlab livelink module (or even matlab) this would help.
Sure - If I am using the Matlab livelink I can easily have access to the variables in the workspace. For example, using mphplot I can access the field data, which in my case is vector as pd{1,1}{1,1}.p. This is single precision, and I guess there is no way of specifying the precision in this context? It would be a suggestion for a new release to include some control (in an advanced tab for example) as to how the data is written to an ASCII file, using standard C formatting say. (I guess it should be straightforward to implement, although this is pure speculation). If you don't have access to the matlab livelink module (or even matlab) this would help.

Lars Gregersen COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 8 years ago 11 ago 2016, 04:35 GMT-4
Hi

Just a technical note: All calculations in Comsol is carried out in double precision. When extracting numerical data from Comsol (e.g. using mphinterp) the data will be calculated using double precision as well. When you export files from Comsol the data will be exported using double precision.

Plotting is different. Most graphics cards do not work (well) with double precision data so numbers are converted to single precision (floats) and integers, which also saves space.

For each type of data you can export from Comsol there are a choice of the format to export into. For many of these data types the output doesn't produce a simple 2D table than can easily be imported into all kinds of software. This is simply a result of the structure of the exported data. I think that the only export format that is easy to read is the spreadsheet format. For most exported file formats some tweaking (or specialised software) is needed in order to read the data.

...but it doesn't mean that we can make things more intuitive! I suggest you send an email to support@comsol.com where you describe what options you wish to have. Please submit a model (if you can) and be as specific as possible.


Sure - If I am using the Matlab livelink I can easily have access to the variables in the workspace. For example, using mphplot I can access the field data, which in my case is vector as pd{1,1}{1,1}.p. This is single precision, and I guess there is no way of specifying the precision in this context?

It would be a suggestion for a new release to include some control (in an advanced tab for example) as to how the data is written to an ASCII file, using standard C formatting say. (I guess it should be straightforward to implement, although this is pure speculation).

If you don't have access to the matlab livelink module (or even matlab) this would help.





--
Lars Gregersen
Comsol Denmark
Hi Just a technical note: All calculations in Comsol is carried out in double precision. When extracting numerical data from Comsol (e.g. using mphinterp) the data will be calculated using double precision as well. When you export files from Comsol the data will be exported using double precision. Plotting is different. Most graphics cards do not work (well) with double precision data so numbers are converted to single precision (floats) and integers, which also saves space. For each type of data you can export from Comsol there are a choice of the format to export into. For many of these data types the output doesn't produce a simple 2D table than can easily be imported into all kinds of software. This is simply a result of the structure of the exported data. I think that the only export format that is easy to read is the spreadsheet format. For most exported file formats some tweaking (or specialised software) is needed in order to read the data. ...but it doesn't mean that we can make things more intuitive! I suggest you send an email to support@comsol.com where you describe what options you wish to have. Please submit a model (if you can) and be as specific as possible. [QUOTE] Sure - If I am using the Matlab livelink I can easily have access to the variables in the workspace. For example, using mphplot I can access the field data, which in my case is vector as pd{1,1}{1,1}.p. This is single precision, and I guess there is no way of specifying the precision in this context? It would be a suggestion for a new release to include some control (in an advanced tab for example) as to how the data is written to an ASCII file, using standard C formatting say. (I guess it should be straightforward to implement, although this is pure speculation). If you don't have access to the matlab livelink module (or even matlab) this would help. [/QUOTE] -- Lars Gregersen Comsol Denmark

Gunnar Andersson COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 8 years ago 11 ago 2016, 08:26 GMT-4

Does any one know if there is a way of controlling the format (i.e. specify floating point precision, comma or tab delimiter etc) of how data is output from the export node?


If you export to a .csv-file then the columns are separated by commas. (CSV=Comma-Separated Values)

[QUOTE] Does any one know if there is a way of controlling the format (i.e. specify floating point precision, comma or tab delimiter etc) of how data is output from the export node? [/QUOTE] If you export to a .csv-file then the columns are separated by commas. (CSV=Comma-Separated Values)

Note that while COMSOL employees may participate in the discussion forum, COMSOL® software users who are on-subscription should submit their questions via the Support Center for a more comprehensive response from the Technical Support team.