Fortran Help for Meteorologist Student: 4th-End, 60-100

  • Fortran
  • Thread starter MelinaM
  • Start date
  • Tags
    Fortran
In summary: Then when you have done all of them, you can collate the results.I'd start by getting a few thousand data points, and writing a small program which can process them. After that is working, then you can either repeat the process or extend the program to handle all of the data.Yes, it stuck because of the data. I will try again or I will split the data. Thank you!In summary, the conversation involved a meteorology student seeking help with preparing data using Fortran. They specifically needed to know how to read the file from the 4th row until the end and from the 60th line until the 100th. The
  • #1
MelinaM
13
0
Hi, i am a meteorologist student and I have some data I have to prepare using Fortan. I don't know how to make it read the file from the 4th row till the end and from the 60th line till the 100th. Can you please help me? I'm desperate!
 
Technology news on Phys.org
  • #2
Welcome to PF!

Read all rows and keep only the rows you want.
 
  • #3
I'm afraid I can't do that. There has to be a way I can do that. I know I can use "do" but I don't know how exactly. Does anyone know?
 
  • #4
First let's focus on something simpler. Do you know how to read the entire file, one line at a time?

When you can do that, you can modify it to read only the lines that you want.
 
  • #5
Here's a reference to reading files in fortran. there are other online tutorials as well that you can search for:

http://en.wikibooks.org/wiki/Fortran/io

and one for do loops (bottom half of page)

http://en.wikibooks.org/wiki/Fortran/Fortran_control

look at how you can place a read statement inside a do loop and iterate over the number of lines you want to keep or skip.

post your code if you want more help on fortran specifics or errors you're getting. Use the (code) and (/code) tags around your example where the parens are really square brackets.
 
Last edited:
  • #6
Yes, I know how to read the whole file. I was using the do loop. I wrote it like this:
do i=60, 100
j=4, 60
read(*,*) the name of the file
end do

but it never worked.
 
  • #7
MelinaM said:
Yes, I know how to read the whole file. I was using the do loop. I wrote it like this:
do i=60, 100
j=4, 60
read(*,*) the name of the file
end do

but it never worked.
I'm sorry, but this isn't even close to what you need to do.

Your loop is semantically correct, but I don't know why it's running 40 times.
The line j = 4, 60 -- what is it supposed to be doing?
The read statement won't work.

Have you written any Fortran code before?
 
  • #8
The read should be read(#,$) where # is the number of the file I have to state and $ the format.
I have an excel file where there are 10000 lines and 10000 columns. I want to read from the 4 row till the 60th and from the 60th line till the 100th. That's why I mentioned those numbers
 
  • #9
MelinaM said:
The read should be read(#,$) where # is the number of the file I have to state and $ the format.
I have an excel file where there are 10000 lines and 10000 columns. I want to read from the 4 row till the 60th and from the 60th line till the 100th. That's why I mentioned those numbers

It's not clear if you are trying to read an Excel file directly, or data which has been created in Excel and saved or exported into another format.

In any event, Fortran can access two types of files: formatted files are things like text files, which you could also read in a text editor. The information is presented as a series of lines of data, and each line can have a varying length. Unformatted files are typically stored in some binary format, and there is a unique structure to the data which your Fortran application must be programmed to recognize, so that it can correctly access the proper information from the file.

Perhaps if you could provide more detail about this data file, more pertinent help would be forthcoming.

Can you read your data with a text editor for instance, without having to start Excel?
 
  • #10
I have this file in .dat but I couldn't upload it so I made it .txt.
What should I do if I want to read from 1960-1962?
 

Attachments

  • examplee.txt
    430.1 KB · Views: 372
  • #11
I have another question. These numbers are temperature in Kelvin. How can I do that in Celsius using Fortran?
 
  • #12
MelinaM said:
I have another question. These numbers are temperature in Kelvin. How can I do that in Celsius using Fortran?

What's the conversion from K to C? Surely they teach this in meteorology school.
 
  • #13
Celsius= Kelvin-273,15
 
  • #14
Then that's how you convert the data from the file in K to C. After all, Fortran is dsigned to do calculations like this.
 
  • #15
Fortran is but I'm not. I am too bad at Fortran :(
 
  • #16
MelinaM said:
I have this file in .dat but I couldn't upload it so I made it .txt.
What should I do if I want to read from 1960-1962?

As a text file, you cannot randomly access a particular line from your data file by itself with the capabilities Fortran gives you to handle sequential files. As was suggested in an earlier post, if you want to access the data in line N, you've got to read in lines 1 to N-1 first. Now, if you are not interested in using the data in lines 1 thru N-1, that's OK, you just discard it after it is read.
 
  • #17
Yes, but we are talking about too many data because the file I have are data from 1950-2100 and not just temperature. So, I have to read just the data I want, somehow. The txt was only for upload use.
 
  • #18
We appear to be talking past one another on this point. The program you write to access the data file must be compatible with the format and layout of the file, unless you want to re-format all this data. Believe me, you want to try the former approach first.

PF is not a good place to teach basic programming. Since you are a student, I recommend that you ask someone at your school for help or tutoring in programming.

If your data is already in an Excel file, have you tried using Excel to extract and manipulate the data? Excel should certainly be capable of doing temperature conversions, for example.
 
  • #19
Yes, I have tried but I have almost 55000 data so it stuck
 
  • #20
MelinaM said:
Yes, I have tried but I have almost 55000 data so it stuck

Your post is not clear. What 'stuck'? Was it Excel? Did your computer crash?

If 55000 data points are too much, perhaps you need to split the data into smaller files with
fewer points.
 
  • #21
Not the entire computer. Just the excel wasn't responding. I have trouble opening it as well, let alone work on it
 
  • #22
MelinaM said:
Not the entire computer. Just the excel wasn't responding. I have trouble opening it as well, let alone work on it

Then this strongly suggests that you should split the large data file into several smaller files, and work on these files individually. I'm not sure what you want to do with the data, but it might be possible once the individual small data files have been processed, you can collect summaries of results for the smaller files into one summary file.

Sometimes, when working with large files bogs down Excel, the automatic calculation option can be turned off so that making one change to a data cell doesn't set off a cascade of calculations in other parts of the spreadsheet as Excel updates the file.

It could be that the computer you are using has insufficient memory to accommodate these large data files. It might be easier to add memory to your existing computer, or use a different computer which has more memory.

In any event, it seems that most of your problems originate in trying to manipulate scads of data in one massive file.
 
  • #23
It would help if you gave a better description of what you're trying to do and why.

All you've told us is that you want to process a large amount of data using Fortran, converting temperature values to Kelvin and then importing the data to Excel? or is it the other way around? whether this is a project for some course on Fortran or not?

For example, if you're doing this as part of some academic research then perhaps other programming tools like AWK, Perl or Python would be more helpful than using Excel and Fortran.
 
  • #24
Yes, i know that excel can do that but not if you have 460 columns and 55000 lines. I just did the program (from K to C) and it worked. But i still don't know how I should do the other program. The one I have to make it read from the 4th row till the end and from the 60th line till the 100th. Do you have any suggestions please? If you had a file with many data how would you make a program so it would read the whole thing but make an output file with the data you want. Let's say you have 500 columns and 700 lines. How would you make it make an output file with the numbers from the 50th line till the 300tha and from the 12th column till the 360th?
 
  • #25
Here's some pseudo code to do what you wanted, you'll have to rewrite in correct Fortran fr it to work.

Code:
do i=1 to 700

    read (---) cols

    if (i <= 50) continue
    if(i >= 300) continue
   
    // write out selected columns
    do j=12 to 360
        newcols[j-12]=cols[j]
    enddo

    write (---) newcols

enddo
 
  • #26
Thanks! Thank kinda helped. I will try it and I hope it will work.
 
  • #27
For another approach:

Code:
// read lines 1 through 49 but don't do anything with them

do i = 1 to 49
    // read only the first column into a "dummy" variable
    read (---) dummy
enddo

// read lines 50 through 300 and process them

do i = 50 to 300
    read (---) cols
    // ... and write out the selected columns as per jedishrfu
enddo

// no need to read the remaining lines since you
// aren't going to do anything with them!
 

1. What is Fortran and why is it important for meteorologists?

Fortran is a high-level programming language that is commonly used in scientific computing, including meteorology. It is important for meteorologists because it allows them to write complex and efficient programs for data analysis and numerical weather prediction.

2. How can Fortran help me as a meteorology student?

Fortran can help meteorology students by allowing them to write their own programs for data analysis and modeling. It is also used in many weather forecasting and climate modeling systems, so understanding Fortran can be beneficial for future career opportunities.

3. Do I need any prior programming experience to learn Fortran?

While prior programming experience can be helpful, it is not necessary to learn Fortran. However, familiarity with other programming languages such as C or Python may make it easier to learn Fortran.

4. How can I find resources for learning Fortran for meteorology?

There are many online resources available for learning Fortran specifically for meteorology, including tutorials, forums, and online courses. Additionally, textbooks and manuals on Fortran programming can also be helpful.

5. Can Fortran be used for other scientific fields besides meteorology?

Yes, Fortran can be used in a variety of other scientific fields, such as physics, engineering, and astronomy. It is particularly well-suited for applications involving complex mathematical calculations and large datasets.

Similar threads

  • Programming and Computer Science
Replies
12
Views
2K
  • Programming and Computer Science
Replies
5
Views
4K
  • Programming and Computer Science
Replies
17
Views
4K
  • Programming and Computer Science
Replies
2
Views
2K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
9
Views
1K
  • Programming and Computer Science
Replies
8
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
1K
Back
Top