- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am new in this board and a new user. Here is my naive question:
I have some data file which are mixed with numerical values and characters. I want only numerical values. How can I check if a value is numerical or charcter? My data is looked like
HISTORIC PRECIPITATION [IN] STATION: 897
Annual Data Display: Summary for period ending 1929/ 9/30
Day Oct Nov Dec Jan Feb Mar Apr May Jun Jul Aug Sep
1 1.980 0.000 0.231 0.605 0.682 0.242 0.000 0.000 0.814 0.000 0.000 0.110
2 1.089 0.000 0.000 0.880 0.220 0.605 0.000 1.012 0.000 0.044 0.000 0.011
3 0.165 0.044 0.000 0.000 0.000 0.088 0.044 0.088 0.000 0.000 0.088 0.000
4 0.880 0.231 0.000 0.000 0.000 0.000 0.275 0.110 0.000 0.000 0.000 0.000
5 0.869 0.132 0.000 0.000 0.000 0.935 0.000 0.220 0.000 0.000 0.000 0.000
2 1.089 0.000 0.000 0.880 0.220 0.605 0.000 1.012 0.000 0.044 0.000 0.011
3 0.165 0.044 0.000 0.000 0.000 0.088 0.044 0.088 0.000 0.000 0.088 0.000
4 0.880 0.231 0.000 0.000 0.000 0.000 0.275 0.110 0.000 0.000 0.000 0.000
5 0.869 0.132 0.000 0.000 0.000 0.935 0.000 0.220 0.000 0.000 0.000 0.000
Link Copied
10 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You could read each line as a character string. If you know what the acceptable formats are, and can distinguish the strings containing numerical data, you can use internal read to process the strings containing numeric fields after identifying them.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Could you giv me an example how to do it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
character(len=96)instring,fname
open(unit=infile, file=fname)
read(infile,'(A)')instring
if(instring(1:22)='HISTORIC PRECIPITATION')then
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
character(len=96)instring,fname
open(unit=infile, file=fname)
read(infile,'(A)')instring
if(instring(1:22)='HISTORIC PRECIPITATION')then
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Message Edited by tim18 on 08-25-2004 03:58 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Whatever you do, don't do a read with format * (list-directed) in an attempt to "validate" the input. You will find it accepting far more than you want.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry about the single = signs, where == is required.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Here is a solution that I extracted from my software. The basic procedures do some more checking (to get away from some of the things that list-directed format passes, as Steve warned about) and are more general, but this solution works well, especially if you can assert that the lines you are interested in processing have the same number of numbers in them and that they occur in the beginning of the line. I have found that this is often the case.
I attach the function, "get_dirtfile", and a driver for your example, that I have put in the "example.txt" file.
Best wishes
Lars
I attach the function, "get_dirtfile", and a driver for your example, that I have put in the "example.txt" file.
Best wishes
Lars
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Why bother?
Why not paste the text into Excel and use Data menu to convert text to columns? Then you can pick out the numbers you want.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank all of you for the help. I finally solve the problem. BTW, Excel doesn't help in this case because the file is large,has more rows taht excel can handle.

Reply
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