Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Fortran reading csv

  1. Apr 24, 2010 #1
    Hi guys and gals,

    I'm trying to use fortran 77 to read a csv file which has data like this
    Code (Text):

    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 (Text):
    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 (Text):
          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: Apr 25, 2017
  2. jcsd
  3. Apr 24, 2010 #2
    Change g to CHARACTER*10. It's reading 50 characters into the date field because there is no comma to stop it.
     
  4. Apr 24, 2010 #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 (Text):
    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.
     
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook