PDA

View Full Version : Fortran and Netcdf




dukebound85
Jun 20, 2012, 01:01 AM
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

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

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!



lee1210
Jun 20, 2012, 05:54 PM
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

dukebound85
Jun 20, 2012, 10:33 PM
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

I'll try that. As far as the library, I just installed the netcdf-fortran port via macports. That should suffice right?

lee1210
Jun 20, 2012, 11:31 PM
I'll try that. As far as the library, I just installed the netcdf-fortran port via macports. That should suffice right?

-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