Fortran and Netcdf

Discussion in 'Mac Programming' started by dukebound85, Jun 19, 2012.

  1. macrumors P6

    dukebound85

    Joined:
    Jul 17, 2005
    Location:
    5045 feet above sea level
    #1
    I am trying to run some calculations and have been told that Fortran is much much much faster at computations than matlab

    As such, I am trying to use fortran to work on various netcdf files

    I used macports to install the netcdf-fortran package

    My question, as my searching online has been a bear, is how exactly do I run a fortran code with netcdf calls?

    Here is a quick example I tried to run (aa.f) and the resulting output

    Code:
     PROGRAM nc
    
            USE netcdf
    
            IMPLICIT NONE
    
            INTEGER :: stat,id
    
    
            stat=nf90_open(path="~/Desktop/temp_2011-12-31.nc",mode=nf90_write,ncid=id)
            stat=nf90_close(id)
    
    
            END PROGRAM nc
    
    Here is what terminal spits out

    Code:
    gfortran-mp-4.7 aa.f
    aa.f:1.2:
    
     PROGRAM nc                                                             
      1
    Error: Non-numeric character in statement label at (1)
    aa.f:1.2:
    
     PROGRAM nc                                                             
      1
    Error: Unclassifiable statement at (1)
    aa.f:3.11:
    
            USE netcdf                                                      
               1
    Fatal Error: Can't open module file 'netcdf.mod' for reading at (1): No such file or directory
    
    Any tips is great or a site that you know of that explains clearly how to use netcdf and fortran!
     
  2. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    First: Name your file .f90 or .f95 so it's clear that you're not writing in column-dependent Fortran 77. Next: Where did netcdf install its .mod file and library file? Have you made sure your compiler knows where to find this?

    -Lee
     
  3. thread starter macrumors P6

    dukebound85

    Joined:
    Jul 17, 2005
    Location:
    5045 feet above sea level
    #3
    I'll try that. As far as the library, I just installed the netcdf-fortran port via macports. That should suffice right?
     
  4. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #4
    -I seems to be the switch to point to where modules are installed. Find netcdf.mod with spotlight and add a switch to gfortran pointing there. I don't know where macports installs things, but gfortran can't find the module right now.

    -Lee
     

Share This Page