Fortran 77: Reading CSV File & Outputting Time, Latitude, Longitude

In summary, the programmer is trying to read a csv file containing data about tropical cyclones and is having difficulty formatting the ISO_time column correctly.
  • #1
Nug_sama
2
0
Hi guys and gals,

I'm trying to use fortran 77 to read a csv file which has data like this
Code:
Serial_Num,Season,Num,Basin,Sub_basin,Name,ISO_time,Nature,Latitude,Longitude,pos_num,pos_stdev,MSW_mean,MSW_stdev,MSW_min,MSW_med,MSW_max,MSW_qc,MSW_num,MCP_mean,MCP_stdev,MCP_min,MCP_max,MCP_qc,MCP_num,num_basins,track_type,spur_type,track_start,track_end,main_track,centers,MSW_atcf,MSW_bom,MSW_cma,MSW_cphc,MSW_hko,MSW_hurdat_atl,MSW_hurdat_epa,MSW_jtwc_cp,MSW_jtwc_ep,MSW_jtwc_io,MSW_jtwc_sh,MSW_jtwc_wp,MSW_nadi,MSW_neumann,MSW_newdelhi,MSW_reunion,MSW_td9636,MSW_tokyo,MSW_wellington,MCP_atcf,MCP_bom,MCP_cma,MCP_cphc,MCP_hko,MCP_hurdat_atl,MCP_hurdat_epa,MCP_jtwc_cp,MCP_jtwc_ep,MCP_jtwc_io,MCP_jtwc_sh,MCP_jtwc_wp,MCP_nadi,MCP_neumann,MCP_newdelhi,MCP_reunion,MCP_td9636,MCP_tokyo,MCP_wellington
1969231S09068,1970,1, SI, SI,ALINE,19/08/1969 6:00,TS,-9.1,67.8,2,0,22,-1,22,22,22,0,1,-1,-1,-1,-1,2,-1,1,spur,split,split,cyclolysis,1969231S09069,reunion:neumann,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,25,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
1969231S09068,1970,1, SI, SI,ALINE,19/08/1969 12:00,NR,-9,66.2,2,0,22,-1,22,22,22,0,1,-1,-1,-1,-1,2,-1,1,spur,split,split,cyclolysis,1969231S09069,reunion:neumann,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,25,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
1969231S09068,1970,1, SI, SI,ALINE,19/08/1969 18:00,NR,-9,64.3,2,0,22,-1,22,22,22,0,1,-1,-1,-1,-1,2,-1,1,spur,split,split,cyclolysis,1969231S09069,reunion:neumann,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,25,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1

I have no programming knowledge and what I want to do is create a program that will output when tropical cyclones are within specific latitudes and longitudes. Given my lack of experience I've tried to write a simple program to output the time, latitude and longitude. I've found that the formatting in the ISO_time column is making things tricky and when I get the output from the code below it ignores everything after the first forwardslash giving incorrect output such as:
Code:
Time=19 lat= 1.5606261E-41 long= -2.24924502E-37
Could someone please tell me how to fix this?

Here's my code so far, it's very novice =P
Code:
      program read_ibtracs
      implicit none
      character*50 a,d,e,f,g,h
      real b,c,i,j
      open (1,file="1970-2008.txt")
      read(1,*)a,b,c,d,e,f,g,h,i,j
      write(*,*)'Time=',g,'lat=',i,'long=',j
      close (1)
      end
The data opened by this program (1970-2008.txt) has been modified so that there the first line is not "Serial_Num,Season,Num,etc..."

If anyone wants to look at the original data set, it is available at from IBTrACS: "ftp://eclipse.ncdc.noaa.gov/pub/ibtracs/v02r01/ibtracs_csv/basin"[/URL]

Thank you for the help, I'll probably post more questions as I attempt to make the program more complicated =).
 
Last edited by a moderator:
Physics news on Phys.org
  • #2
Change g to CHARACTER*10. It's reading 50 characters into the date field because there is no comma to stop it.
 
  • #3
Thanks for the reply. I added another line/declaration character*10 g leaving everything else the same and the output is basically the same as before.
Code:
Time=19 lag= 0.long= 0.
I'm wondering if there's a way to tell fortran to read the date 'as is' because at the moment I think it's treating the forward slash as a special character.

Cheers.
 

1. How do I read a CSV file in Fortran 77?

To read a CSV file in Fortran 77, you can use the "OPEN" statement followed by the "READ" statement. The "OPEN" statement specifies the file name and the "READ" statement reads the data from the file into variables. You can also use the "INQUIRE" statement to check the status of the file before reading it.

2. How do I output time, latitude, and longitude from a CSV file in Fortran 77?

To output time, latitude, and longitude from a CSV file in Fortran 77, you can use the "WRITE" statement. The "WRITE" statement allows you to specify the variables you want to output and the format in which they should be displayed. You can also use the "PRINT" statement to output the data to the screen instead of a file.

3. What is the format for time, latitude, and longitude in a CSV file?

The format for time, latitude, and longitude in a CSV file can vary depending on the source of the data. In most cases, time is represented in either 24-hour or 12-hour format with or without seconds. Latitude and longitude are typically represented in decimal degrees or degrees, minutes, and seconds.

4. How can I handle missing or invalid data in a CSV file?

To handle missing or invalid data in a CSV file, you can use the "IF" statement to check for these conditions and skip over the data or replace it with a default value. You can also use the "ERROR STOP" statement to terminate the program if the data is critical for the analysis.

5. Can I use Fortran 77 to read and output data from other types of files?

Yes, Fortran 77 can be used to read and output data from various types of files, including CSV files, text files, and binary files. The "OPEN" statement allows you to specify the file type and the appropriate "READ" or "WRITE" statement can be used to manipulate the data. You can also use the "FORMAT" statement to specify the format of the data in the file.

Similar threads

  • Programming and Computer Science
Replies
1
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
11K
  • Programming and Computer Science
Replies
6
Views
10K
  • Programming and Computer Science
Replies
1
Views
5K
Back
Top