<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Write to a specific line and position on the line in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Write-to-a-specific-line-and-position-on-the-line/m-p/901652#M80906</link>
    <description>&lt;P&gt;I can write a copy of the input file no problem... but how do I replace specific, small parts of it, on various lines, with text from somewhere else. Each line contains multiple values corresponding with multiple parameters, but I only need to replace one value on a given line: how can I specify the position on the line to begin the write?&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 04 Feb 2010 11:39:28 GMT</pubDate>
    <dc:creator>Stuart_M_</dc:creator>
    <dc:date>2010-02-04T11:39:28Z</dc:date>
    <item>
      <title>Write to a specific line and position on the line</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Write-to-a-specific-line-and-position-on-the-line/m-p/901650#M80904</link>
      <description>&lt;P&gt;Hi folks&lt;/P&gt;
&lt;P&gt;I feel like this should be a piece of cake, but I'm stumped.&lt;/P&gt;
&lt;P&gt;I want to write over the values of an input text file for a particular line number in the file, and if possible a particular position on that line. Any suggestions?&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 04 Feb 2010 10:20:30 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Write-to-a-specific-line-and-position-on-the-line/m-p/901650#M80904</guid>
      <dc:creator>Stuart_M_</dc:creator>
      <dc:date>2010-02-04T10:20:30Z</dc:date>
    </item>
    <item>
      <title>Write to a specific line and position on the line</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Write-to-a-specific-line-and-position-on-the-line/m-p/901651#M80905</link>
      <description>&lt;P&gt;In general writing in an existing file will destroy that file.&lt;/P&gt;
&lt;P&gt;The simplest and most robust solution is to write a copy of the file, inserting/substituting&lt;/P&gt;
&lt;P&gt;the new values as you go along.&lt;/P&gt;
&lt;P&gt;If the file can be treated as a direct-access (formatted) file you can in fact overwrite&lt;/P&gt;
&lt;P&gt;parts of it without damaging the rest. But that is a tricky route: it requires that all&lt;/P&gt;
&lt;P&gt;records as viewed by the program have the same length (if you are stubborn enough,&lt;/P&gt;
&lt;P&gt;I guess you could open the file with a record length of 1, thus allowing you to rewrite&lt;/P&gt;
&lt;P&gt;the file at the smallest granularity).&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Arjen&lt;/P&gt;</description>
      <pubDate>Thu, 04 Feb 2010 10:30:40 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Write-to-a-specific-line-and-position-on-the-line/m-p/901651#M80905</guid>
      <dc:creator>Arjen_Markus</dc:creator>
      <dc:date>2010-02-04T10:30:40Z</dc:date>
    </item>
    <item>
      <title>Write to a specific line and position on the line</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Write-to-a-specific-line-and-position-on-the-line/m-p/901652#M80906</link>
      <description>&lt;P&gt;I can write a copy of the input file no problem... but how do I replace specific, small parts of it, on various lines, with text from somewhere else. Each line contains multiple values corresponding with multiple parameters, but I only need to replace one value on a given line: how can I specify the position on the line to begin the write?&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Feb 2010 11:39:28 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Write-to-a-specific-line-and-position-on-the-line/m-p/901652#M80906</guid>
      <dc:creator>Stuart_M_</dc:creator>
      <dc:date>2010-02-04T11:39:28Z</dc:date>
    </item>
    <item>
      <title>Write to a specific line and position on the line</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Write-to-a-specific-line-and-position-on-the-line/m-p/901653#M80907</link>
      <description>&lt;P&gt;If I understand it correctly, you want to replace a piece of a string by another piece?&lt;/P&gt;
&lt;P&gt;Something along these lines:&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;character(len=80) :: string, value&lt;/P&gt;
&lt;P&gt;string = "PARAMETER1 # Value of parameter 1"&lt;/P&gt;
&lt;P&gt;write( value, '(f10.4)' ) 3.45&lt;/P&gt;
&lt;P&gt;string(1:10) = value&lt;/P&gt;
&lt;P&gt;write( 10, '(a)' ) string&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;This would produce a line:&lt;/P&gt;
&lt;P&gt; 3.45 # Value of parameter 1&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Is this what you want?&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Arjen&lt;/P&gt;</description>
      <pubDate>Thu, 04 Feb 2010 12:23:58 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Write-to-a-specific-line-and-position-on-the-line/m-p/901653#M80907</guid>
      <dc:creator>Arjen_Markus</dc:creator>
      <dc:date>2010-02-04T12:23:58Z</dc:date>
    </item>
    <item>
      <title>Write to a specific line and position on the line</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Write-to-a-specific-line-and-position-on-the-line/m-p/901654#M80908</link>
      <description>&lt;DIV id="tiny_quote"&gt;
&lt;DIV style="margin-left: 2px; margin-right: 2px;"&gt;Quoting &lt;A rel="/en-us/services/profile/quick_profile.php?is_paid=&amp;amp;user_id=418694" class="basic" href="https://community.intel.com/en-us/profile/418694/"&gt;stubaan&lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="border: 1px inset; padding: 5px; background-color: #e5e5e5; margin-left: 2px; margin-right: 2px;"&gt;&lt;I&gt;
&lt;P&gt;I can write a copy of the input file no problem... but how do I replace specific, small parts of it, on various lines, with text from somewhere else. Each line contains multiple values corresponding with multiple parameters, but I only need to replace one value on a given line: how can I specify the position on the line to begin the write?&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;/I&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;The level of file control you seek is straightforward, but mostly beyond the limited capabilities of Fortran file i/o (which is way behind the times, language-wise). If you are able to sacrifice portability for functionality, you can easily do all your file i/o using Win32 API functions which provide exactly the needed level of granular control. Here are some sample wrapper functions, which illustrate read/write operations wherein an arbitrary amount of data, denominated in bytes, can be positioned at any offset in the file:&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;PRE&gt;[bash]SUBROUTINE rw_file (rwmode, ihandl, nbytes, loc_pointer, offset)
	IMPLICIT NONE
	CHARACTER(LEN=1), INTENT(IN)	:: rwmode
	INTEGER(HANDLE), INTENT(IN)     :: ihandl
	INTEGER, INTENT(IN)				:: nbytes, loc_pointer
	INTEGER, INTENT(IN), OPTIONAL	:: offset
	INTEGER							:: nact

	! position pointer if offset is provided
	IF (PRESENT(offset)) nact = SetFilePointer (ihandl, offset, NULL,FILE_BEGIN)

	IF (rwmode == 'R') THEN
		IF (.NOT.ReadFile (ihandl,			&amp;amp;  ! file handle
				     	  loc_pointer,		&amp;amp;  ! address of data
						  nbytes,			&amp;amp;  ! byte count to read
						  LOC(nact),		&amp;amp;  ! actual bytes read
						  NULL_OVERLAPPED))	THEN
		  	! read error&lt;BR /&gt;               END IF
	
	ELSE
		IF (.NOT.WriteFile(ihandl,			&amp;amp;  ! file handle
						  loc_pointer,		&amp;amp;  ! address of data
						  nbytes,			&amp;amp;  ! byte count to write
						  LOC(nact),		&amp;amp;  ! actual bytes written
						  NULL_OVERLAPPED))	THEN
		  	!write error&lt;BR /&gt;              END IF
	END IF
END SUBROUTINE rw_file


SUBROUTINE Set_File_Pointer (ihandl, offset, truncate)
	IMPLICIT NONE
	INTEGER(HANDLE), INTENT(IN)     :: ihandl
	INTEGER, INTENT(IN)				:: offset
	LOGICAL, INTENT(IN), OPTIONAL	:: truncate
	INTEGER							:: rslt
	rslt = SetFilePointer (ihandl, MAX0(offset,0), NULL, FILE_BEGIN)
	
	IF (PRESENT(truncate)) rslt = SetEndOfFile (ihandl)				
END SUBROUTINE Set_File_Pointer
[/bash]&lt;/PRE&gt;
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Feb 2010 19:35:56 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Write-to-a-specific-line-and-position-on-the-line/m-p/901654#M80908</guid>
      <dc:creator>Paul_Curtis</dc:creator>
      <dc:date>2010-02-04T19:35:56Z</dc:date>
    </item>
    <item>
      <title>Write to a specific line and position on the line</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Write-to-a-specific-line-and-position-on-the-line/m-p/901655#M80909</link>
      <description>&lt;P&gt;Arjen, Paul - thanks for the assistance.&lt;/P&gt;
&lt;P&gt;I originally began attempting this task in python, which I thought would be able to handle it without too much trouble. I have yet to get anywhere on this problem using python though.&lt;/P&gt;
&lt;P&gt;That being said, I am obviously open to other options besides Fortran, though I frankly do not have the time to familiarize myself with another language right now - I have just spent three weeks trying to come to terms with DOS and BASH scripting as well as Python.&lt;/P&gt;
&lt;P&gt;This is a link to the python forum I originally posted this question on - it contains the input file I am talking about as an attachment, and some conversation that clarifies just what I am trying to achieve.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.daniweb.com/forums/post1120606.html#post1120606" target="_blank"&gt;http://www.daniweb.com/forums/post1120606.html#post1120606&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;I am very surprised by how seemingly difficult this is turning out to be - all I want is to be able to pinpoint a position in a text file, based on co-ordinates of line number and position on that line, and write the value of a variable over whatever is at that point.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Feb 2010 23:09:19 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Write-to-a-specific-line-and-position-on-the-line/m-p/901655#M80909</guid>
      <dc:creator>Stuart_M_</dc:creator>
      <dc:date>2010-02-04T23:09:19Z</dc:date>
    </item>
    <item>
      <title>Write to a specific line and position on the line</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Write-to-a-specific-line-and-position-on-the-line/m-p/901656#M80910</link>
      <description>&lt;P&gt;&lt;I&gt;"...all I want is to be able to pinpoint a position in a text file, based on co-ordinates of line number and position on that line, and write the value of a variable over whatever is at that point"&lt;/I&gt;&lt;/P&gt;
&lt;P&gt;If each line (ie, record) in the file is the same length, presumably with a terminal &lt;CRLF&gt;, then any specific line+column location is a simple calculation of (n-1)*(recordlength + 2) + column_position, and you can simply open the file with that offset and (over)write as needed. In the more general case where the file has lines of varying length, again each with a terminal &lt;CRLF&gt;, the easy calculation will not work and you will have to read the entire file into a buffer array of records (ie, lines), find/change the substring of interest, and finally rewrite the entire file line by line, sending only the actual filled length of each record + &lt;CRLF&gt;.&lt;/CRLF&gt;&lt;/CRLF&gt;&lt;/CRLF&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Feb 2010 01:02:34 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Write-to-a-specific-line-and-position-on-the-line/m-p/901656#M80910</guid>
      <dc:creator>Paul_Curtis</dc:creator>
      <dc:date>2010-02-05T01:02:34Z</dc:date>
    </item>
    <item>
      <title>Write to a specific line and position on the line</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Write-to-a-specific-line-and-position-on-the-line/m-p/901657#M80911</link>
      <description>&lt;DIV id="tiny_quote"&gt;
&lt;DIV style="margin-left: 2px; margin-right: 2px;"&gt;Quoting &lt;A jquery1265362782929="83" rel="/en-us/services/profile/quick_profile.php?is_paid=&amp;amp;user_id=418694" href="https://community.intel.com/en-us/profile/418694/" class="basic"&gt;stubaan&lt;/A&gt;&lt;/DIV&gt;
&lt;DIV style="background-color: #e5e5e5; margin-left: 2px; margin-right: 2px; border: 1px inset; padding: 5px;"&gt;&lt;I&gt;
&lt;P&gt;I am very surprised by how seemingly difficult this is turning out to be - all I want is to be able to pinpoint a position in a text file, based on co-ordinates of line number and position on that line, and write the value of a variable over whatever is at that point.&lt;/P&gt;
&lt;/I&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;declare variables to hold a datarecord and a record count&lt;/P&gt;
&lt;P&gt;initialise the record count to zero&lt;/P&gt;
&lt;P&gt;open the input file&lt;/P&gt;
&lt;P&gt;open the output file&lt;/P&gt;
&lt;P&gt;read a record from the input file into the datarecord&lt;/P&gt;
&lt;P&gt;did we get end-of-file?&lt;/P&gt;
&lt;P&gt;If "yes" then go to "done"&lt;/P&gt;
&lt;P&gt;increment record counter&lt;/P&gt;
&lt;P&gt;is this the record, or one of the records, we wish to modify?&lt;/P&gt;
&lt;P&gt;if "yes" then&lt;/P&gt;
&lt;P&gt; find in the data record the specificsubstring we wish to modify&lt;BR /&gt;  (hint use INDEX? unlessyou already knowthe start and length/end position of the substring)&lt;BR /&gt; replace the substring of datarecord containing that data with the new data&lt;/P&gt;
&lt;P&gt;endif&lt;/P&gt;
&lt;P&gt;write the datarecord to the output file&lt;/P&gt;
&lt;P&gt;go back and read the next datarecord&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;"done"&lt;/P&gt;
&lt;P&gt;close both files&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Les&lt;/P&gt;</description>
      <pubDate>Fri, 05 Feb 2010 09:40:10 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Write-to-a-specific-line-and-position-on-the-line/m-p/901657#M80911</guid>
      <dc:creator>Les_Neilson</dc:creator>
      <dc:date>2010-02-05T09:40:10Z</dc:date>
    </item>
    <item>
      <title>Write to a specific line and position on the line</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Write-to-a-specific-line-and-position-on-the-line/m-p/901658#M80912</link>
      <description>&lt;P&gt;Streams ought to solve the issue of positioning the file pointer anywhere in the file,&lt;/P&gt;
&lt;P&gt;but that does not make the problem as such much easier: files nowadays are mostly&lt;/P&gt;
&lt;P&gt;seen as a sequence of bytes, not of lines. So the basic problem remains: figuring&lt;/P&gt;
&lt;P&gt;out where in the file the change should be made.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Arjen&lt;/P&gt;</description>
      <pubDate>Fri, 05 Feb 2010 12:48:35 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Write-to-a-specific-line-and-position-on-the-line/m-p/901658#M80912</guid>
      <dc:creator>Arjen_Markus</dc:creator>
      <dc:date>2010-02-05T12:48:35Z</dc:date>
    </item>
  </channel>
</rss>

