Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Read Files

JohnNichols
Valued Contributor III
800 Views
Dear Steve:

I have a device that writes CSV type files to a directory, they have impossible file names that include the date and time in the file name.

Is it possible to determine what is in a directory and what is the earliest file so I can open, read and then discard?

Thanks

JMN
0 Kudos
5 Replies
jimdempseyatthecove
Honored Contributor III
800 Views
Is there a need to do this in FORTRAN?

Why not use Windows Explorer?
View in Details, click on Date Modified till sorted in ascending or decending order.
If you want to look at, then right-click then open with and pick wordpad (or Excel if you wish).

Jim
0 Kudos
John4
Valued Contributor I
800 Views

You can use the GETFILEINFOQQ function in order to get the list of the files in the directory. That function accepts wildcards, so you can invoke it with 'path/to/dir/*.csv' to get only the CSV files.

If the times you need are the ones in the filenames, then you can just do some internal reading (depending on the format). For example:

[fortran]implicit none

integer :: i, j, year, month, day, hour, minutes, seconds, milliseconds
character(:), allocatable :: filename, date

filename = 'some data taken at time=2011-06-11T15:49:11.768Z.csv'

i = INDEX(filename, '=')
j = INDEX(filename, '.', BACK = .TRUE.)
date = filename(i+1:j-1)

if (date == '') stop

do i = 1, LEN_TRIM(date)
   if (ANY(date(i:i) == ['-','T',':','.'])) date(i:i) = ','
   if (date(i:i) == 'Z') date(i:i) = ' '
enddo

read (date, *) year, month, day, hour, minutes, seconds, milliseconds
print *, year, month, day, hour, minutes, seconds, milliseconds
end
[/fortran]

If the times you need are the actual file time stamps, the information obtained through the GETFILEINFOQQ function contains the (packed) creation time and last write time. To unpack the times, you can use the UNPACKTIMEQQ subroutine.

Both GETFILEINFOQQ and UNPACKTIMEQQ are in the IFPORT module. The compiler documentation contains examples for both of them.

0 Kudos
JohnNichols
Valued Contributor III
800 Views
Thanks for the replies.

I had missed the GETFILEINFOQQ in my Microsoft Powerstation Manual. The exact example from the Powerstation Manual shows up in the Intel Fortran Online help. I am now developing the example to do what I want it to do.

I love those old manuals and absolutely hate the new methods. I want a bookI can read and enjoy, not a screen.

Just as an aside:

Did you know if you have a problem with Windows updates, Microsoft has a team that provides support. Takes about 2 months to organize if you foolishly want English date formats rather than US date formats as you get directed to Australia and then Ohio, but the guy who helps lives in India.

The level one help is by email, I had already tried all of those steps, the level 2 guy spent two days on the problem, he was really good. A problem with IE9 Beta upsetting SP1 install. I was interested when he said that he had to go to the next level up for a solution after I had watched him play for 7 hours on Friday.

He fixed it today, so now SP1 is installed on my computer.

Tech Support at work said reinstall Windows, I had already done that and it still had the problem.

I started with Microsoft Fortran V3.3.1 (?) I want it back with my Compaq Portable computer and two floppy drives,just joking. Intel Fortran is great, I just want printed manuals. Steve surely you can organize that?


Regards

JMN


0 Kudos
Steven_L_Intel1
Employee
800 Views
Re: printed manuals

This just isn't going to happen. The expense and effort to produce and distribute a printed book is way out of proportion to the number of people who would want to buy it. Intel did have a printed Language Reference (which would have included the GETINFOQQ example), but it sold very poorly and was dropped for the subsequent release.

The next best is PDF - you can at least print those yourself. But the writers tell me that having to produce for both the Microsoft help format and PDF effectively means doing it twice. Microsoft keeps changing their online help format, and they have announced that it is changing again, but haven't published the specs or tools. For Linux and Mac we use the HTML Help format which is just as bad in that regard.

I like printed manuals too.
0 Kudos
JohnNichols
Valued Contributor III
800 Views
This just isn't going to happen.

Dear Steve:

As a Father of four daughters, this is my favourite expression.

Of course it never works.

Luckily, the Fortran Powerstation manuals and the older Microsoft Fortran Manuals are really good.

I hate the new format, I like to sit with a beer on Sunday night, watch Masterpiece Theatre and read my Fortan manuals.

JMN
0 Kudos
Reply