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

  • Context: Comp Sci 
  • Thread starter Thread starter Nug_sama
  • Start date Start date
  • Tags Tags
    Csv Fortran Reading
Click For Summary
SUMMARY

This discussion focuses on using Fortran 77 to read a CSV file containing tropical cyclone data, specifically extracting time, latitude, and longitude. The user encountered issues with the ISO_time formatting, which caused incorrect output due to improper reading of the data fields. A suggested solution involves changing the character declaration for the ISO_time variable to CHARACTER*10 to correctly handle the forward slash in the date format. The user is encouraged to refine their code further to ensure accurate data extraction.

PREREQUISITES
  • Understanding of Fortran 77 programming syntax
  • Familiarity with reading and parsing CSV files
  • Knowledge of data types in Fortran, specifically CHARACTER and REAL
  • Basic concepts of tropical cyclone data and its significance
NEXT STEPS
  • Learn how to use Fortran's formatted input/output statements for better data handling
  • Research how to manipulate strings in Fortran to handle special characters
  • Explore the IBTrACS dataset for additional data manipulation techniques
  • Investigate error handling in Fortran to manage unexpected data formats
USEFUL FOR

This discussion is beneficial for novice programmers using Fortran 77, meteorologists analyzing tropical cyclone data, and anyone interested in data parsing and manipulation in legacy programming languages.

Nug_sama
Messages
2
Reaction score
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
Change g to CHARACTER*10. It's reading 50 characters into the date field because there is no comma to stop it.
 
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.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 2 ·
Replies
2
Views
12K
  • · Replies 6 ·
Replies
6
Views
11K
  • · Replies 4 ·
Replies
4
Views
19K
  • · Replies 1 ·
Replies
1
Views
6K