<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Approximatrix Forums — Libxl]]></title>
		<link>https://forums.approximatrix.com/viewtopic.php?id=873</link>
		<atom:link href="https://forums.approximatrix.com/extern.php?action=feed&amp;tid=873&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Libxl.]]></description>
		<lastBuildDate>Tue, 11 Oct 2022 00:32:05 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Libxl]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=4010#p4010</link>
			<description><![CDATA[<p>There is a csv module in GitHub.<br />You can search it.</p>]]></description>
			<author><![CDATA[null@example.com (weixing1531)]]></author>
			<pubDate>Tue, 11 Oct 2022 00:32:05 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=4010#p4010</guid>
		</item>
		<item>
			<title><![CDATA[Re: Libxl]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=4009#p4009</link>
			<description><![CDATA[<p>Hi Weixing1531,</p><p>I&#039;ve copied a FORTRAN program for reading CSV files from the internet (see listing below). Although it doesn&#039;t solve your problem, it does get you about half the way there.&nbsp; Using this listing as an example, you or someone else may be able to add code to write to a CSV file. Although the listing below is only for three columns of data, it could be expanded to accommodate more columns of data.&nbsp; The original code was only for two columns of data; I&#039;ve modified it to include three columns of data.</p><p>Dr.Frank</p><p>!-----------------------------------------------------------------------<br />!&nbsp; &nbsp;Tek-Tips Forums (24 Jun 10)<br />!&nbsp; &nbsp;<a href="https://www.tek-tips.com/viewthread.cfm?qid=1609257">https://www.tek-tips.com/viewthread.cfm?qid=1609257</a><br />!&nbsp; &nbsp;Save your Excel as CSV-file (Comma Separated Values) and<br />!&nbsp; &nbsp;process it using fortran.<br />!<br />!&nbsp; &nbsp;Modified to read three columns of csv file data<br />!&nbsp; &nbsp;Dr.Frank (10-10-2022)<br />!-----------------------------------------------------------------------<br />module csv_mod<br />&nbsp; type csv_header_line<br />&nbsp; &nbsp; character(10) :: c01 ! column 01 header<br />&nbsp; &nbsp; character(10) :: c02 ! column 02 header<br />&nbsp; &nbsp; character(10) :: c03 ! column 03 header<br />&nbsp; end type csv_header_line</p><p>&nbsp; type csv_data_line<br />&nbsp; &nbsp; integer&nbsp; &nbsp; &nbsp; :: c01 ! column 01: id<br />&nbsp; &nbsp; character(10):: c02 ! column 02: name<br />&nbsp; &nbsp; real&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:: c03 ! column 03: age<br />&nbsp; end type csv_data_line</p><p>contains<br />&nbsp; subroutine parse_header(separator, line, header)<br />&nbsp; &nbsp; character(*), intent(in) :: separator, line<br />&nbsp; &nbsp; type(csv_header_line), intent(out) :: header</p><p>&nbsp; &nbsp; integer :: separator_pos, next_pos</p><p>&nbsp; &nbsp; !separator position<br />&nbsp; &nbsp; separator_pos = index(line, separator) - 1</p><p>&nbsp; &nbsp; !extract first heading<br />&nbsp; &nbsp; header%c01 = adjustl(trim(line(:separator_pos)))</p><p>&nbsp; &nbsp; !splice next heading (FWP)<br />&nbsp; &nbsp; separator_pos = separator_pos + 2<br />&nbsp; &nbsp; next_pos = separator_pos + index( line(separator_pos:), separator ) - 2<br />&nbsp; &nbsp; header%c02 = adjustl(trim(line(separator_pos:next_pos)))</p><p>&nbsp; &nbsp; !splice next heading (FWP)<br />&nbsp; &nbsp; separator_pos = next_pos + 2<br />&nbsp; &nbsp; next_pos = separator_pos + len_trim( line(separator_pos:) ) - 1<br />&nbsp; &nbsp; header%c03 = adjustl(trim(line(separator_pos:next_pos)))<br />&nbsp; end subroutine parse_header</p><p>&nbsp; subroutine parse_data(separator, line, dta, nr)<br />&nbsp; &nbsp; character(*), intent(in) :: separator, line<br />&nbsp; &nbsp; integer, intent(in) :: nr<br />&nbsp; &nbsp; type(csv_data_line), dimension(:), intent(inout) :: dta<br />&nbsp; &nbsp; integer :: separator_pos, next_pos</p><p>&nbsp; &nbsp; !separator position<br />&nbsp; &nbsp; separator_pos = index(line, separator) - 1</p><p>&nbsp; &nbsp; ! convert substring into integer number dta(nr)%c01<br />&nbsp; &nbsp; read (line(:separator_pos),&#039;(I3)&#039;) dta(nr)%c01</p><p>&nbsp; &nbsp; !splice next data and save into dta(nr)%c02 (FWP)<br />&nbsp; &nbsp; !separator position<br />&nbsp; &nbsp; separator_pos = separator_pos + 2<br />&nbsp; &nbsp; next_pos = separator_pos + index( line(separator_pos:), separator ) - 2<br />&nbsp; &nbsp; dta(nr)%c02 = adjustl(trim(line(separator_pos:next_pos)))</p><p>&nbsp; &nbsp; !splice next data and save into dta(nr)%c03 (FWP)<br />&nbsp; &nbsp; !separator position<br />&nbsp; &nbsp; separator_pos = next_pos + 2<br />&nbsp; &nbsp; next_pos = separator_pos + len_trim( line(separator_pos:) ) - 1</p><p>&nbsp; &nbsp; ! convert substring into real number<br />&nbsp; &nbsp; read (line(separator_pos:next_pos),&#039;(F8.3)&#039;) dta(nr)%c03</p><p>&nbsp; end subroutine parse_data<br />end module csv_mod</p><p>program csv_3Col_read<br />&nbsp; use csv_mod<br />&nbsp; implicit none</p><p>&nbsp; integer, parameter :: max_csv_lines = 100 ! max number of lines in CSV<br />&nbsp; integer stat, line_nr, nr, j, computed_number<br />&nbsp; character(80) :: line<br />&nbsp; type(csv_header_line) :: csv_header<br />&nbsp; type(csv_data_line), dimension(max_csv_lines) :: csv_data</p><p>&nbsp; integer, parameter :: csv_columns&nbsp; &nbsp;= 3&nbsp; &nbsp;! number of columns in CSV<br />&nbsp; character(1) :: separator = &#039;,&#039;<br />&nbsp; character(80) :: filename<br />&nbsp; filename = &#039;test_3_cols.csv&#039;</p><p>&nbsp; ! open file<br />&nbsp; open (1, file=filename, status=&#039;old&#039;, iostat=stat)<br />&nbsp; if (stat .ne. 0) then<br />&nbsp; &nbsp; write(*,*) &#039;File cannot be opened !&#039;<br />&nbsp; &nbsp; go to 99<br />&nbsp; end if</p><p>&nbsp; write(*,*) &#039;Reading CSV-file...&#039;<br />&nbsp; ! process file<br />&nbsp; line_nr = 0<br />&nbsp; do while (.true.)<br />&nbsp; &nbsp; read(1, &#039;(A)&#039;, end=99) line<br />&nbsp; &nbsp; line_nr = line_nr + 1<br />&nbsp; &nbsp; if (line_nr .eq. 1) then<br />&nbsp; &nbsp; &nbsp; call parse_header(separator, adjustl(trim(line)), csv_header)<br />&nbsp; &nbsp; else<br />&nbsp; &nbsp; &nbsp; ! if line_nr &gt; 1 then parse data line<br />&nbsp; &nbsp; &nbsp; nr = line_nr - 1<br />&nbsp; &nbsp; &nbsp; call parse_data(separator, adjustl(trim(line)), csv_data, nr)<br />&nbsp; &nbsp; end if<br />&nbsp; end do</p><p>&nbsp; ! close file<br />&nbsp; 99 continue<br />&nbsp; close(1)<br />&nbsp; !write(*,*) &#039;Done.&#039;</p><p>&nbsp; write(*,*)&nbsp; &#039;Number of all lines found in CSV&nbsp; = &#039;, line_nr<br />&nbsp; write(*,*)&nbsp; &#039;Number of data lines found in CSV = &#039;, nr</p><p>&nbsp; ! write the data<br />&nbsp; write(*, &#039;(A)&#039;) &#039;****************************************&#039;<br />&nbsp; &nbsp; write(*,&#039;(2X,A3, 1X,A10, 1X,A10, 2X,A10)&#039;) csv_header%c01, &amp;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; adjustr(csv_header%c02), &amp;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; adjustr(csv_header%c03), &amp;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;NINT(age)&#039;</p><p>&nbsp; write(*, &#039;(A)&#039;) &#039;****************************************&#039;<br />&nbsp; do j = 1, nr<br />&nbsp; &nbsp; &nbsp;computed_number = NINT(csv_data(j)%c03)<br />&nbsp; &nbsp; &nbsp;write (*,&#039;(1X,I3, 2X,A10, 5X,F8.3, 2X,I3)&#039;) csv_data(j)%c01, &amp;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; csv_data(j)%c02, &amp;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; csv_data(j)%c03, &amp;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; computed_number<br />&nbsp; end do</p><p>&nbsp; write(*, &#039;(A)&#039;) &#039;****************************************&#039;<br />end program csv_3Col_read</p><p>!OUTPUT:<br />! Reading CSV-file...<br />! Number of all lines found in CSV&nbsp; =&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;20<br />! Number of data lines found in CSV =&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;19<br />!****************************************<br />!&nbsp; id&nbsp; first_name&nbsp; &nbsp; &nbsp; &nbsp; age&nbsp; &nbsp;NINT(age)<br />!****************************************<br />!&nbsp; &nbsp;1&nbsp; Julie&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 80.244&nbsp; &nbsp;80<br />!&nbsp; &nbsp;2&nbsp; Jose&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;11.569&nbsp; &nbsp;12<br />!&nbsp; &nbsp;3&nbsp; Lois&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;12.339&nbsp; &nbsp;12<br />!&nbsp; &nbsp;4&nbsp; Walter&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;63.173&nbsp; &nbsp;63<br />!&nbsp; &nbsp;5&nbsp; Timothy&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 57.063&nbsp; &nbsp;57<br />!&nbsp; &nbsp;6&nbsp; Barbara&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 79.705&nbsp; &nbsp;80<br />!&nbsp; &nbsp;7&nbsp; Douglas&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 19.347&nbsp; &nbsp;19<br />!&nbsp; &nbsp;8&nbsp; Tina&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;16.909&nbsp; &nbsp;17<br />!&nbsp; &nbsp;9&nbsp; Gregory&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 67.749&nbsp; &nbsp;68<br />!&nbsp; 10&nbsp; Larry&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 43.705&nbsp; &nbsp;44<br />!&nbsp; 11&nbsp; Tina&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 9.931&nbsp; &nbsp;10<br />!&nbsp; 12&nbsp; Kelly&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 72.657&nbsp; &nbsp;73<br />!&nbsp; 13&nbsp; Marilyn&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 10.901&nbsp; &nbsp;11<br />!&nbsp; 14&nbsp; Gregory&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;9.966&nbsp; &nbsp;10<br />!&nbsp; 15&nbsp; Earl&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;10.875&nbsp; &nbsp;11<br />!&nbsp; 16&nbsp; Evelyn&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;33.268&nbsp; &nbsp;33<br />!&nbsp; 17&nbsp; Carol&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 54.498&nbsp; &nbsp;54<br />!&nbsp; 18&nbsp; Alice&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2.505&nbsp; &nbsp; 3<br />!&nbsp; 19&nbsp; Randy&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 39.775&nbsp; &nbsp;40<br />!****************************************</p><p>!INPUT CSV DATA FILE:<br />id,first_name,age<br />1,Julie,80.244<br />2,Jose,11.569<br />3,Lois,12.339<br />4,Walter,63.173<br />5,Timothy,57.063<br />6,Barbara,79.705<br />7,Douglas,19.347<br />8,Tina,16.909<br />9,Gregory,67.749<br />10,Larry,43.705<br />11,Tina,9.931<br />12,Kelly,72.657<br />13,Marilyn,10.901<br />14,Gregory,9.966<br />15,Earl,10.875<br />16,Evelyn,33.268<br />17,Carol,54.498<br />18,Alice,2.505<br />19,Randy,39.775</p>]]></description>
			<author><![CDATA[null@example.com (drfrank)]]></author>
			<pubDate>Tue, 11 Oct 2022 00:14:30 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=4009#p4009</guid>
		</item>
		<item>
			<title><![CDATA[Re: Libxl]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=4005#p4005</link>
			<description><![CDATA[<p>It&#039;s unclear from the license whether we can redistribute the trial versions.&nbsp; It could be complicated.&nbsp; They do already provide a standards-non-compliant Fortran module source file that you can use as-is, though.</p>]]></description>
			<author><![CDATA[null@example.com (jeff)]]></author>
			<pubDate>Sun, 09 Oct 2022 22:19:26 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=4005#p4005</guid>
		</item>
		<item>
			<title><![CDATA[Libxl]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=4003#p4003</link>
			<description><![CDATA[<p>It can read and write excel data.But not free.</p>]]></description>
			<author><![CDATA[null@example.com (weixing1531)]]></author>
			<pubDate>Sun, 09 Oct 2022 03:18:40 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=4003#p4003</guid>
		</item>
	</channel>
</rss>
