Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8165113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:27:50+00:00 2026-06-06T19:27:50+00:00

I am trying to read a dataset which looks like this DATE,TIME,val 1/1/2001,1:00:00,0 with

  • 0

I am trying to read a dataset which looks like this

DATE,TIME,val
1/1/2001,1:00:00,0

with the program

program main
implicit none

real :: val
character(len=8) :: date
character(len=7) :: time
open(1,file='data.csv',status='old')
read(1,*) ! header
read(1,fmt=100)date,time,val
100 FORMAT (A,1x,A,1x,F3.1)
end program

This is all fine if the date and time always have 8 or 7 characters but they don’t e.g.

 4/21/2001,19:00:00,0

How should I declare the format for fortran to read both the date,time,val lines in the example?

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T19:27:51+00:00Added an answer on June 6, 2026 at 7:27 pm

    You could read all the entire data, time, value line into a single string and then process that to extract the individual elements, something along the lines of

    program main
    implicit none
    
    real :: val
    character(len=10) :: date
    character(len=8) :: time
    
    character(len=100) :: line
    integer :: n1, n2, end
    
    open(1, file='data.csv', status='old')
    
    ! Read entire second line into `line`, ignoring the header
    read(1,*) ! header
    read(1,'(A100)') line
    
    ! Determine locations of the first and last comma in `line` and the
    ! end of the line:
    n1  = index(line, ',')
    n2  = index(line, ',', back=.True.)
    end = len_trim(data)
    
    ! Split line up according to position of commas and assign to 
    ! appropriate variables
    date = data(1:n1-1)
    time = data(n1+1:n2-1)
    read(data(n2+1:end), *) val ! Internal read, for converting from string to float
    
    end program main
    

    Note that this is highly specialised to the example data in the question, but it shouldn’t be too hard to generalise this code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to read a dataset as xml and load it into an XML
I am trying to read an XML file into a data set using dataset.ReadXml(fileName,
I'm trying to sort an array whose elements are read from a file which
I am trying to take my dataset which is made up of protein dna
The following bit of SAS code is supposed to read from a dataset which
Trying to read an RSS and select information using Linq but can't seem to
Trying to read headers for a csv file with: reader = csv.DictReader(open(PATH_FILE),skipinitialspace=True) headers =
After trying to read various articles on sending emails with attachments in PHP (I
Im trying to read a column of String values from my DB. Im trying
Iam trying to read a binary file to memory and pass the starting address

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.