- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - OpenVMS
- >
- identify new line character in fortran string whic...
Operating System - OpenVMS
1820590
Members
1833
Online
109626
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-23-2009 11:56 PM
тАО04-23-2009 11:56 PM
identify new line character in fortran string which is passed from c++
I have an application which is written in C++ and fortran.
From C++, i have passed string to fortran which contains new line characters. For example, messages is as shown below
HTTP/1.1 200 OK
Date: Thu, 23 Apr 2009 18:01:14 GMT
Server: Apache/1.3.41 (Unix) PHP/4.0.5
I have complete string message in fortran variable say character*500 str.
Currently i am printing like as shown below
WRITE(*,110)'Response(1-25)',str(1:25)
WRITE(*,110)'Response(26-50)',str(26:50)
WRITE(*,110)'Response(51-75)',str(51:75)
WRITE(*,110)'Response(76-100)',str(76:100)
screen output is:
Response (1-25) : HTTP/1.1 200 OK
Date: Th
Response (26-50) : u, 23 Apr 2009 18:01:01 G
Response (51-75) : MT
Server: Apache/1.3.41
Response (76-100): (Unix) PHP/4.0.5
and I am not getting message output to screen properly, splitted across lines when new line character is there.
Please let me know how to identify new line character("\n") in fortran and print each line seperately.
From C++, i have passed string to fortran which contains new line characters. For example, messages is as shown below
HTTP/1.1 200 OK
Date: Thu, 23 Apr 2009 18:01:14 GMT
Server: Apache/1.3.41 (Unix) PHP/4.0.5
I have complete string message in fortran variable say character*500 str.
Currently i am printing like as shown below
WRITE(*,110)'Response(1-25)',str(1:25)
WRITE(*,110)'Response(26-50)',str(26:50)
WRITE(*,110)'Response(51-75)',str(51:75)
WRITE(*,110)'Response(76-100)',str(76:100)
screen output is:
Response (1-25) : HTTP/1.1 200 OK
Date: Th
Response (26-50) : u, 23 Apr 2009 18:01:01 G
Response (51-75) : MT
Server: Apache/1.3.41
Response (76-100): (Unix) PHP/4.0.5
and I am not getting message output to screen properly, splitted across lines when new line character is there.
Please let me know how to identify new line character("\n") in fortran and print each line seperately.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-24-2009 01:34 AM
тАО04-24-2009 01:34 AM
Re: identify new line character in fortran string which is passed from c++
Putting aside the question why You want to pass strings from C++ to Fortran just for printing ...
There is no such thing like a "new line character". "\n" is just the C(++) notation for a line terminator, and it is up to the C I/O system to generate whatever the system wants to be the line terminator: In most (all?) Unix-type systems this is Ascii code 10, on a classic macintosh this is ascii 13 , and in Dos/Windows like systems it represents 2 ascii characters: . (and in multi-byte charactersets it becomes even more complicated).
Now Fortran has no concept of line terminators, it is reading and writing records.
So there is no general solution for Your (pseudo-)problem.
Since the text is apparently coming from a HTTP stream, chances are high the lines are terminated by pairs.
Use the Fortran INDEX intrinsic to search for pairs, then write the found substring without the terminators, and advance to the next part.
Or just search for, ignoring , if the program or routine should be more general.
And watch out for ascii 0 characters, they probably terminate the whole string if it is not really 500 bytes long!
define in Fortran:
character CR,LF,NUL
character*2 CRLF
CR=CHAR(13)
LF=CHAR(10)
NUL=CHAR(0)
CRLF=CHAR(13)//CHAR(10)
and use these as substrings in the INDEX calls.
There is no such thing like a "new line character". "\n" is just the C(++) notation for a line terminator, and it is up to the C I/O system to generate whatever the system wants to be the line terminator: In most (all?) Unix-type systems this is Ascii code 10
Now Fortran has no concept of line terminators, it is reading and writing records.
So there is no general solution for Your (pseudo-)problem.
Since the text is apparently coming from a HTTP stream, chances are high the lines are terminated by
Use the Fortran INDEX intrinsic to search for
Or just search for
And watch out for ascii 0 characters, they probably terminate the whole string if it is not really 500 bytes long!
define in Fortran:
character CR,LF,NUL
character*2 CRLF
CR=CHAR(13)
LF=CHAR(10)
NUL=CHAR(0)
CRLF=CHAR(13)//CHAR(10)
and use these as substrings in the INDEX calls.
http://www.mpp.mpg.de/~huber
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-24-2009 07:55 AM
тАО04-24-2009 07:55 AM
Re: identify new line character in fortran string which is passed from c++
And
if this not just an exercise in Fortran programming, but writing a HTTP parser (re-inventing the wheel ?), then be aware:
the HTTP header is terminated by TWO consecutive pairs. Anything following is data load, and may not contain "line terminators" at all, or have portions between terminators exceeding the length of records allowed in a write statement (if output is to a 80 or 132 wide terminal for example), or the data is binary and not printable at all !
if this not just an exercise in Fortran programming, but writing a HTTP parser (re-inventing the wheel ?), then be aware:
the HTTP header is terminated by TWO consecutive
http://www.mpp.mpg.de/~huber
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-24-2009 08:27 AM
тАО04-24-2009 08:27 AM
Re: identify new line character in fortran string which is passed from c++
I'll add a little extra to the mix here, maybe.
The issue is that you have mis-divided your labor. The C++ program knows the structure of the input better than FORTRAN, because when you pass in strings, they are either passed via descriptor or fixed-length byte arrays. FORTRAN knows nothing about string structure because STRING is a "cast" of a byte array anyway. So you would scan the array for the terminators in either language, but it might be a bit easier to do it in C++ and just pass in the already-separated lines.
I.e. do parsing of a particular type of record where you receive the record because it is closest to the source of data. The longer you leave something unparsed, the harder it becomes to process it later.
(Just one man's experience in program design speaking here.)
The issue is that you have mis-divided your labor. The C++ program knows the structure of the input better than FORTRAN, because when you pass in strings, they are either passed via descriptor or fixed-length byte arrays. FORTRAN knows nothing about string structure because STRING is a "cast" of a byte array anyway. So you would scan the array for the terminators in either language, but it might be a bit easier to do it in C++ and just pass in the already-separated lines.
I.e. do parsing of a particular type of record where you receive the record because it is closest to the source of data. The longer you leave something unparsed, the harder it becomes to process it later.
(Just one man's experience in program design speaking here.)
Sr. Systems Janitor
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Learn About
News and Events
Support
© Copyright 2025 Hewlett Packard Enterprise Development LP