How to read from a string as if reading from a file in fortran?What is the difference between String and string in C#?How do I iterate over the words of a string?How do I read / convert an InputStream into a String in Java?How do I create a Java string from the contents of a file?How do I make the first letter of a string uppercase in JavaScript?How to replace all occurrences of a string?How to check whether a string contains a substring in JavaScript?How to read a file line-by-line into a list?Does Python have a string 'contains' substring method?How do I convert a String to an int in Java?

What are the limitations of the Hendersson-Hasselbalch equation?

Based on what criteria do you add/not add icons to labels within a toolbar?

How to open Lightning component in new window

ZFS on Linux: Which mountpoint option when mounting manually per script?

Make lens aperture in Tikz

When using the Proficiency Dice optional rule, how should they be used in determining a character's Spell Save DC?

What does Argus Filch specifically do?

Is the first page of a novel really that important?

How to win against ants

split inside flalign

On the consistency of different well-polished astronomy software

would a winged human/angel build like this be able to fly? (see image below)

Did Logical Positivism fail because it simply denied human emotion?

Formal mathematical definition of renormalization group flow

Magento 2 Is it possible to use same event in multiple Modules?

The warlock of firetop mountain, what's the deal with reference 192?

Is there a difference between `board[x, y]` and `board[x][y]` in Python?

In MTG, was there ever a five-color deck that worked well?

Pronouns when writing from the point of view of a robot

“The Fourier transform cannot measure two phases at the same frequency.” Why not?

What is it exactly about flying a Flyboard across the English channel that made Zapata's thighs burn?

Is there a general term for the items in a directory?

A verb for when some rights are not violated?

Is an "are" omitted in this sentence



How to read from a string as if reading from a file in fortran?


What is the difference between String and string in C#?How do I iterate over the words of a string?How do I read / convert an InputStream into a String in Java?How do I create a Java string from the contents of a file?How do I make the first letter of a string uppercase in JavaScript?How to replace all occurrences of a string?How to check whether a string contains a substring in JavaScript?How to read a file line-by-line into a list?Does Python have a string 'contains' substring method?How do I convert a String to an int in Java?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















The following code is attempting to read a file into a memory block storing characters and read data from that block instead of the original file. ( The code is modified based on here )



 program read_file
implicit none
integer :: n
character(len=:), allocatable :: s
character(len=5) :: a, b

open(unit=10, file="read_file.f", action="read",
1 form="unformatted", access="stream")
inquire(unit=10, size=n)
allocate(character(n) :: s)

read(10) s
close(10)

print "(A)", s

read ( s, * ) a

read ( s, * ) b

print *, a

print * , b ! meant to read from the previously visited place

end program read_file


When trying to read from the character block 's', the program always reads from the beginning of it rather than reads continuously as reading a text file. So 'a' and 'b' are exactly the same. Is there a way to read 's' as if it read from a file ? Thanks!










share|improve this question
























  • it shows 'end-of-file during read' error out of this modification.

    – roy.atlas
    Mar 27 at 8:47











  • There is no "current location" in the string s. In files, you read record by record and each read goes to the next record. Add print *, 'n is', n before the error. Also, please provide a test file :-)

    – Pierre de Buyl
    Mar 27 at 9:04











  • So it seems impossible to parse a string in the way that it reads from a real file. Still is there any chance to circumvent this by a statement to read until EOL ? And the code provided is self-contained, i.e., the executable file reads its source code.

    – roy.atlas
    Mar 27 at 9:13











  • You are right and the purpose I am using internal read is to 'parse' a strings which is the text in a file to other types ( maybe characters or integers, etc. ). Extracting substrings is not the motive anyway. The difficulty I have is that the 'read' statement cannot walk through the string line by line. You were asking about the length of 's' which I think in this case is 519, total number of characters within the source code I posted.

    – roy.atlas
    Mar 27 at 14:49











  • Looks to me like you might want s(1:index(s,line_end)) to get the first line of s (ion course, you have to set line_end to the character that represents a line end). But the reason I asked how long s is was to be sure that reading s had worked in the first place. At this point, I'm quite sure you are using the wrong approach to splitting s, figure out where the line-ends are, use them in string index expressions. Internal reads are not the right way to go.

    – High Performance Mark
    Mar 27 at 15:14


















0















The following code is attempting to read a file into a memory block storing characters and read data from that block instead of the original file. ( The code is modified based on here )



 program read_file
implicit none
integer :: n
character(len=:), allocatable :: s
character(len=5) :: a, b

open(unit=10, file="read_file.f", action="read",
1 form="unformatted", access="stream")
inquire(unit=10, size=n)
allocate(character(n) :: s)

read(10) s
close(10)

print "(A)", s

read ( s, * ) a

read ( s, * ) b

print *, a

print * , b ! meant to read from the previously visited place

end program read_file


When trying to read from the character block 's', the program always reads from the beginning of it rather than reads continuously as reading a text file. So 'a' and 'b' are exactly the same. Is there a way to read 's' as if it read from a file ? Thanks!










share|improve this question
























  • it shows 'end-of-file during read' error out of this modification.

    – roy.atlas
    Mar 27 at 8:47











  • There is no "current location" in the string s. In files, you read record by record and each read goes to the next record. Add print *, 'n is', n before the error. Also, please provide a test file :-)

    – Pierre de Buyl
    Mar 27 at 9:04











  • So it seems impossible to parse a string in the way that it reads from a real file. Still is there any chance to circumvent this by a statement to read until EOL ? And the code provided is self-contained, i.e., the executable file reads its source code.

    – roy.atlas
    Mar 27 at 9:13











  • You are right and the purpose I am using internal read is to 'parse' a strings which is the text in a file to other types ( maybe characters or integers, etc. ). Extracting substrings is not the motive anyway. The difficulty I have is that the 'read' statement cannot walk through the string line by line. You were asking about the length of 's' which I think in this case is 519, total number of characters within the source code I posted.

    – roy.atlas
    Mar 27 at 14:49











  • Looks to me like you might want s(1:index(s,line_end)) to get the first line of s (ion course, you have to set line_end to the character that represents a line end). But the reason I asked how long s is was to be sure that reading s had worked in the first place. At this point, I'm quite sure you are using the wrong approach to splitting s, figure out where the line-ends are, use them in string index expressions. Internal reads are not the right way to go.

    – High Performance Mark
    Mar 27 at 15:14














0












0








0








The following code is attempting to read a file into a memory block storing characters and read data from that block instead of the original file. ( The code is modified based on here )



 program read_file
implicit none
integer :: n
character(len=:), allocatable :: s
character(len=5) :: a, b

open(unit=10, file="read_file.f", action="read",
1 form="unformatted", access="stream")
inquire(unit=10, size=n)
allocate(character(n) :: s)

read(10) s
close(10)

print "(A)", s

read ( s, * ) a

read ( s, * ) b

print *, a

print * , b ! meant to read from the previously visited place

end program read_file


When trying to read from the character block 's', the program always reads from the beginning of it rather than reads continuously as reading a text file. So 'a' and 'b' are exactly the same. Is there a way to read 's' as if it read from a file ? Thanks!










share|improve this question














The following code is attempting to read a file into a memory block storing characters and read data from that block instead of the original file. ( The code is modified based on here )



 program read_file
implicit none
integer :: n
character(len=:), allocatable :: s
character(len=5) :: a, b

open(unit=10, file="read_file.f", action="read",
1 form="unformatted", access="stream")
inquire(unit=10, size=n)
allocate(character(n) :: s)

read(10) s
close(10)

print "(A)", s

read ( s, * ) a

read ( s, * ) b

print *, a

print * , b ! meant to read from the previously visited place

end program read_file


When trying to read from the character block 's', the program always reads from the beginning of it rather than reads continuously as reading a text file. So 'a' and 'b' are exactly the same. Is there a way to read 's' as if it read from a file ? Thanks!







string io stream fortran eol






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 27 at 2:33









roy.atlasroy.atlas

723 bronze badges




723 bronze badges















  • it shows 'end-of-file during read' error out of this modification.

    – roy.atlas
    Mar 27 at 8:47











  • There is no "current location" in the string s. In files, you read record by record and each read goes to the next record. Add print *, 'n is', n before the error. Also, please provide a test file :-)

    – Pierre de Buyl
    Mar 27 at 9:04











  • So it seems impossible to parse a string in the way that it reads from a real file. Still is there any chance to circumvent this by a statement to read until EOL ? And the code provided is self-contained, i.e., the executable file reads its source code.

    – roy.atlas
    Mar 27 at 9:13











  • You are right and the purpose I am using internal read is to 'parse' a strings which is the text in a file to other types ( maybe characters or integers, etc. ). Extracting substrings is not the motive anyway. The difficulty I have is that the 'read' statement cannot walk through the string line by line. You were asking about the length of 's' which I think in this case is 519, total number of characters within the source code I posted.

    – roy.atlas
    Mar 27 at 14:49











  • Looks to me like you might want s(1:index(s,line_end)) to get the first line of s (ion course, you have to set line_end to the character that represents a line end). But the reason I asked how long s is was to be sure that reading s had worked in the first place. At this point, I'm quite sure you are using the wrong approach to splitting s, figure out where the line-ends are, use them in string index expressions. Internal reads are not the right way to go.

    – High Performance Mark
    Mar 27 at 15:14


















  • it shows 'end-of-file during read' error out of this modification.

    – roy.atlas
    Mar 27 at 8:47











  • There is no "current location" in the string s. In files, you read record by record and each read goes to the next record. Add print *, 'n is', n before the error. Also, please provide a test file :-)

    – Pierre de Buyl
    Mar 27 at 9:04











  • So it seems impossible to parse a string in the way that it reads from a real file. Still is there any chance to circumvent this by a statement to read until EOL ? And the code provided is self-contained, i.e., the executable file reads its source code.

    – roy.atlas
    Mar 27 at 9:13











  • You are right and the purpose I am using internal read is to 'parse' a strings which is the text in a file to other types ( maybe characters or integers, etc. ). Extracting substrings is not the motive anyway. The difficulty I have is that the 'read' statement cannot walk through the string line by line. You were asking about the length of 's' which I think in this case is 519, total number of characters within the source code I posted.

    – roy.atlas
    Mar 27 at 14:49











  • Looks to me like you might want s(1:index(s,line_end)) to get the first line of s (ion course, you have to set line_end to the character that represents a line end). But the reason I asked how long s is was to be sure that reading s had worked in the first place. At this point, I'm quite sure you are using the wrong approach to splitting s, figure out where the line-ends are, use them in string index expressions. Internal reads are not the right way to go.

    – High Performance Mark
    Mar 27 at 15:14

















it shows 'end-of-file during read' error out of this modification.

– roy.atlas
Mar 27 at 8:47





it shows 'end-of-file during read' error out of this modification.

– roy.atlas
Mar 27 at 8:47













There is no "current location" in the string s. In files, you read record by record and each read goes to the next record. Add print *, 'n is', n before the error. Also, please provide a test file :-)

– Pierre de Buyl
Mar 27 at 9:04





There is no "current location" in the string s. In files, you read record by record and each read goes to the next record. Add print *, 'n is', n before the error. Also, please provide a test file :-)

– Pierre de Buyl
Mar 27 at 9:04













So it seems impossible to parse a string in the way that it reads from a real file. Still is there any chance to circumvent this by a statement to read until EOL ? And the code provided is self-contained, i.e., the executable file reads its source code.

– roy.atlas
Mar 27 at 9:13





So it seems impossible to parse a string in the way that it reads from a real file. Still is there any chance to circumvent this by a statement to read until EOL ? And the code provided is self-contained, i.e., the executable file reads its source code.

– roy.atlas
Mar 27 at 9:13













You are right and the purpose I am using internal read is to 'parse' a strings which is the text in a file to other types ( maybe characters or integers, etc. ). Extracting substrings is not the motive anyway. The difficulty I have is that the 'read' statement cannot walk through the string line by line. You were asking about the length of 's' which I think in this case is 519, total number of characters within the source code I posted.

– roy.atlas
Mar 27 at 14:49





You are right and the purpose I am using internal read is to 'parse' a strings which is the text in a file to other types ( maybe characters or integers, etc. ). Extracting substrings is not the motive anyway. The difficulty I have is that the 'read' statement cannot walk through the string line by line. You were asking about the length of 's' which I think in this case is 519, total number of characters within the source code I posted.

– roy.atlas
Mar 27 at 14:49













Looks to me like you might want s(1:index(s,line_end)) to get the first line of s (ion course, you have to set line_end to the character that represents a line end). But the reason I asked how long s is was to be sure that reading s had worked in the first place. At this point, I'm quite sure you are using the wrong approach to splitting s, figure out where the line-ends are, use them in string index expressions. Internal reads are not the right way to go.

– High Performance Mark
Mar 27 at 15:14






Looks to me like you might want s(1:index(s,line_end)) to get the first line of s (ion course, you have to set line_end to the character that represents a line end). But the reason I asked how long s is was to be sure that reading s had worked in the first place. At this point, I'm quite sure you are using the wrong approach to splitting s, figure out where the line-ends are, use them in string index expressions. Internal reads are not the right way to go.

– High Performance Mark
Mar 27 at 15:14













0






active

oldest

votes










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55368928%2fhow-to-read-from-a-string-as-if-reading-from-a-file-in-fortran%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes




Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.







Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55368928%2fhow-to-read-from-a-string-as-if-reading-from-a-file-in-fortran%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현