科学网

 找回密码
  注册

tag 标签: NetCDF

相关帖子

版块 作者 回复/查看 最后发表

没有相关内容

相关日志

R 如何将NetCDF (nc)格式数据分层转存为asc格式
michunrong123 2016-4-16 23:13
###################################################### # This script is used R to read netcdf data # and export to asc # Author: Mcr ####################################################### #nc多层数据没能在GIS中打开,将nc转存为多个asc后可以使用。 rm(list=ls()) library(RNetCDF) library(raster) library(ncdf4) library(lattice) setwd(...) #设定nc数据所在位置路径 my.data-open.nc(TH33.nc, write=FALSE) #打开nc文件 print.nc(my.data) #查看内部属性 #lon-var.get.nc(my.data, lon) #定义经度 #n.longitudes - length(var.get.nc(my.data,lon))#经度单元格个数 lat-var.get.nc(my.data, lat) #定义纬度 #n.latitudes - length(var.get.nc(my.data, lat))#纬度单元格个数 #my.depth-var.get.nc(my.data,depth) #深度, 第三变量 #n.depth - trunc(length(my.depth)) #n.depth r - raster(ncol=7560, nrow=4320,xmn=73, xmx=136, ymn=18, ymx=54) #建立一个空栅格图,7560列,4320行,经度73-136,纬度18-54 ##=================读取输出第1层===================================## TH33_01_tmp-var.get.nc(my.data,TH33,c(1,1,1),c(7560,4320,1))#读取第一层文件 #☆c(1,1,1) 表示c(读取nc栅格图起始单元格的行位置,读取nc栅格图起始单元格的列位置,读取nc栅格图 #起始单元格的层位置) #☆c(7560,4320,1) 表示c(读取nc栅格图单元格总行数,读取nc栅格图单元格总列数,读取nc栅格图层数) TH33_01_tmp-TH33_01_tmp #将列顺序倒置,这与输出图的方向有关。 values(r)-as.vector(TH33_01_tmp) #将数据读并存储到刚才建立的r栅格图中 plot(r,asp=1) #展示r, 注意图的方向 TH33_01-as.data.frame(r) #将r栅格内数据转为data.frame TH33_01 =-9999 #将NA替换为-9999,要不然asc数据读入到GIS会出错。 fileCon-('TH33_01.asc') #最终输出asc文件的文件名 writeLines('ncols\t\t7560\nnrows\t\t4320\t\nxllcorner\t73.00417\nyllcorner\t18.00417\ncellsize\t0.00833\nNODATA_value\t-9999', fileCon) #为要输出的asc文件写上表头,包括列数,行数,起始经度纬度,分辨率和空值数据用-9999表示。 write.table(TH33_01,'TH33_01.asc',append=TRUE,sep= ,row.names=FALSE,col.names=FALSE) #文中代码只输出了七层数据得第一层数据,第i层用c(1,1,i),c(7560,4320,1)。 #输出范围可以通过行列数进行调整,而相应的经纬度也需要调整。 ###文中会有纰漏,请见谅指正。
个人分类: 科研软件|9005 次阅读|0 个评论
Matlab: NetCDF File
lixujeremy 2015-4-28 22:23
What is NetCDF? NetCDF (Network Common Data Form) is a set of software libraries and self-describing, machine-independent data formats that support the creation, access, and sharing of array-oriented scientific data. The project homepage is hosted by the Unidata program at the University Corporation for Atmospheric Research (UCAR). They are also the chief source of netCDF software, standards development, updates, etc. The format is an open standard. NetCDF Classic and 64-bit Offset Format are an international standard of the Open Geospatial Consortium . Displaying netCDF data under ArcGIS 10 以 sst.mon.ltm.1981-2010.nc ( details )文件为例, SST ( Sea Surface Temperature )在 ArcGIS10.2 中显示如图 1 。 图 1 Matlab 操作 以 sst.mon.ltm.1981-2010.nc 文件为例, Matlab 操作读入及输出为 GeoTiff 文件。 Spatial Coverage: 1.0 degree latitude x 1.0 degree longitude global grid (360x180). 89.5N - 89.5S, 0.5E - 359.5E. Missing grids are 9.999e+20(ltm). 代码运行生产 Jan.~Dec. 全球 SST ,程序运行流畅。 附上代码及 测 试数据( NCTest.rar )。 See Also Matlab netcdf package ;
个人分类: Matlab|2765 次阅读|0 个评论
150316利用MATLAB读取NetCDF文件
Dueinstein 2015-3-16 20:17
2015-3-16 ; Monday ; Cloudy 1. NetCDF(network Common Data Form) 网络通用数据格式是由美国大学大气研究协会(UniversityCorporation for Atmospheric Research,UCAR)的Unidata项目科学家针对科学数据的特点开发的,是一种面向数组型并适于网络共享的数据的描述和编码标准。对程序员来说,它和zip、jpeg、bmp文件格式类似,都是一种文件格式的标准。netcdf文件开始的目的是用于存储气象科学中的数据,现在已经成为许多数据采集软件的生成文件的格式。利用NetCDF可以对网格数据进行高效地存储、管理、获取和分发等操作。由于其灵活性,能够传输海量的面向阵列(array-oriented)数据,目前广泛应用于大气科学、水文、海洋学、环境模拟、地球物理等诸多领域,例如,NCEP(美国国家环境预报中心)发布的再分析资料,NOAA的CDC(气候数据中心)发布的海洋与大气综合数据集(COADS)均采用NetCDF作为标准。 MATLAB 读取NetCDF格式的文件,首先需要安装一个叫做mexcdf的插件,介绍和下载地址及安装以下几篇博文有介绍: http://blog.163.com/jey_df/blog/static/182550161201221344642388/ http://blog.sina.com.cn/s/blog_618af1950100krsw.html http://blog.sina.com.cn/s/blog_64367bb90100o2zu.html 2.MATLAB 读取 NetCDF 格式的文件(.nc)常用的一些函数,以下几篇博文有介绍: http://blog.sciencenet.cn/home.php?mod=spaceuid=489011do=blogid=598038 http://blog.sina.com.cn/s/blog_5d7295010101dbgt.html http://www.ilovematlab.cn/thread-217430-1-1.html
个人分类: 科研笔记|4567 次阅读|0 个评论
[转载]使用Matlab读取netcdf数据
热度 1 sanshiphy 2013-12-23 17:13
申明:以下内容为师弟肖擎曜所写,特转载于此,供参考。
个人分类: 技术备忘录|8806 次阅读|2 个评论
Matlab2013a 读取NetCDF格式到Ascii文本文件
zhoufcumt 2013-10-5 09:43
用C或者Fortran读取NetCDF格式数据文件需要写接口文件,对于初学者来说比较困难,而Matlab就比较容易实现,我向大家提供一个简单的Matlab读取nc格式文件的例子,希望对大家有所帮助。 附件: NetCDF2Ascii.zip
个人分类: Maltab|6206 次阅读|0 个评论
Linux 下 C 接口的 NetCDF 编译、安装、测试
zhoufcumt 2013-6-8 00:09
从官方ftp处下载最新netcdf-4.3.0版本 ftp://ftp.unidata.ucar.edu/pub/netcdf/ 以下针对本人电脑做出说明: 解压 unzip netcdf-4.3.0.zip 为 netcdf-4.3.0 目录,cd netcdf-4.3.0,紧接着 ./configure --prefix=/home/fzhou/lib/netcdf-4.3.0 --disable-netcdf-4 --disable-dap,然后 make,最后 make install,这样的话一般会安装成功。 从 http://www.unidata.ucar.edu/software/netcdf/examples/programs/ 下载 simple_xy_wr.c,无需修改,做个 Makefile 或者直接命令行编译也 ok,设置找到 /home/fzhou/lib/netcdf-4.3.0/include 下的 netcdf.h 和 /home/fzhou/lib/netcdf-4.3.0/lib 下的 libnetcdf.a 即可,我是用 makefile 编译运行成功的结果为: 基本的搞定了,下面就是开始深入学习 C 接口的 NetCDF 了。
个人分类: 空间大地测量相关软件|5329 次阅读|0 个评论
Matlab写nc数据
peluo 2013-6-7 16:19
下面是一段创建nc文件的matlab代码,主要示例了创建nc文件过程中用到的一系列函数(以netcdf.开头,下文中用红色标记)。代码中的部分变量(例如LL_Lon、LL_Lat、Resolution以及dims等)在我自己的代码中有定义,此处没有列出。此文仅作为memo,以备查阅。 %% %create a NetCDF file ncid = netcdf.create ('fluxes.nc','NC_SHARE'); %% %define the dimentions dimidx = netcdf.defDim (ncid,'lon',dims(2)); dimidy = netcdf.defDim (ncid,'lat',dims(1)); dimidt = netcdf.defDim (ncid,'time',time_steps); %% %define the variables and their attributes varidx = netcdf.defVar (ncid, 'lon', 'double',dimidx); netcdf.putAtt (ncid, varidx, 'units','degrees_east'); varidy=netcdf.defVar(ncid, 'lat', 'double', dimidy); netcdf.putAtt(ncid, varidy, 'units','degrees_north'); varidt=netcdf.defVar(ncid, 'time','double',dimidt); netcdf.putAtt(ncid, varidt, 'units','days since 1989-12-31'); varid=nan(Flux_Num); for var=1:1:Flux_Num varid(var)= netcdf.defVar(ncid,Flux_Name{var},'double', ); netcdf.putAtt(ncid, varid(var),'units',Flux_Units{var}); end %% %complete the definition of NetCDF netcdf.endDef (ncid); %% %write the data into the NetCDF file lon=linspace(LL_Lon, LL_Lon+dims(2)*Resolution, dims(2)); lat=linspace(LL_Lat, LL_Lat+dims(1)*Resolution, dims(1)); time=linspace(1, time_steps, time_steps); netcdf.putVar (ncid,varidx,lon); netcdf.putVar(ncid,varidy,lat); netcdf.putVar(ncid, varidt, time); for var=1:1:Flux_Num netcdf.putVar(ncid,varid(var),reshape(fluxes(var,:,:,:),dims(1), dims(2),time_steps)); end %% %close the NetCDF file netcdf.close (ncid);
个人分类: NetCDF|5278 次阅读|0 个评论
NETCDF文件读取要点
zhoufcumt 2013-3-22 23:42
很多数据都以NETCDF或GRIB的格式出现,比如NCEP和ECMWF的数据基本是NETCDF的格式,读取这些数据的格式时,在linux下可以安装NETCDF库来读取,比如用fortran读取NCEP大气数据时,需要有这样一句, call readnetcdf(ncfile, 'pres', start,count,stride,press,time),这个‘pres’即为NCEP大气数据的关键字,那么对一个NETCDF格式的数据,如何获取这个关键字呢?这里就要用到一个很方便的工具ncdump: ncdump -c pres.sfc.2012.nc header.atmos 这样在header.atmos文件下将会有这样的信息: netcdf pres.sfc.2012 { dimensions: lat = 73 ; lon = 144 ; time = UNLIMITED ; // (1464 currently) variables: float lat(lat) ; lat:units = degrees_north ; lat:actual_range = 90.f, -90.f ; lat:long_name = Latitude ; lat:standard_name = latitude ; lat:axis = Y ; float lon(lon) ; lon:units = degrees_east ; lon:long_name = Longitude ; lon:actual_range = 0.f, 357.5f ; lon:standard_name = longitude ; lon:axis = X ; double time(time) ; time:units = hours since 1-1-1 00:00:0.0 ; time:long_name = Time ; time:actual_range = 17628096., 17636874. ; time:delta_t = 0000-00-00 06:00:00 ; time:standard_name = time ; time:axis = T ; short pres(time, lat, lon) ; pres:long_name = 4xDaily Pressure at surface ; pres:unpacked_valid_range = 40000.f, 115000.f ; pres:actual_range = 49030.f, 109490.f ; pres:units = Pascals ; pres:add_offset = 367650.f ; pres:scale_factor = 10.f ; pres:missing_value = 32766s ; pres:precision = -1s ; pres:least_significant_digit = -1s ; pres:GRIB_id = 1s ; pres:GRIB_name = PRES ; pres:var_desc = Pressure ; pres:dataset = NMC Reanalysis ; pres:level_desc = Surface ; pres:statistic = Individual Obs ; pres:parent_stat = Other ; pres:valid_range = -32765s, -25265s ; // global attributes: :Conventions = COARDS ; :title = 4x daily NMC reanalysis (2012) ; :history = created 2011/12 by Hoop (netCDF2.3) ; :description = Data is from NMC initialized reanalysis\n, (4x/day). It consists of most variables interpolated to\n, pressure surfaces from model (sigma) surfaces. ; :platform = Model ; :references = http://www.esrl.noaa.gov/psd/data/gridded/data.ncep.reanalysis.html ; short pres(time, lat, lon) ; 这句中的pres即为关键字。 pres:units = Pascals ; 这句即为气压数据的单位:帕斯卡。 下面还有经纬度格网信息、时间信息(时间的单位是小时, time:units = hours since 1-1-1 00:00:0.0 ),内容较多,显示不全,有兴趣的可以自己试验。 将NETCDF格式文件转化为可读文本文件: ncdump -bc pres.sfc.2012.nc atmos_ncep_2012.dat 但这样对于数据量大的数据比较耗时,不建议这样做,还是尽量用NETCDF的库完成NETCDF格式文件的读取。 NOTE:在当前数据目录下必须有类似动态库文件 libnetcdf.so.7!
个人分类: 数据格式|16038 次阅读|0 个评论
[转载]NetCDF学习纪要A
zhoufcumt 2013-3-22 23:07
转载自: http://blog.sciencenet.cn/blog-653020-549865.html 一: NetCDF简介 NetCDF是由大气研究大学协会(University Corporation for Atmospheric Research,UCAR)的Unidata项目开发的。NetCDF全称为network Common Data Format,中文译法为“网络通用数据格式”,对程序员来说,它和zip、jpeg、bmp文件格式类似,都是一种文件格式的标准。netcdf文件开始的目的是用于存储气象科学中的数据,现在已经成为许多数据采集软件的生成文件的格式。NetCDF由于其灵活性,能够传输海量的面向阵列(array-oriented)数据,已经被采纳用于陆地,海洋和大气科学。NetCDF数据集的一个例子就是北美地区的20个格网集合,每个格网尺寸为30公里,每一个格网都有自己的高程级别。对于每个格网层的每个格网单元,都有关于12个大气指标的超过一年时间的每小时测量记录。因此,它被称为“多维数据(multi-dimensional data)”。 NetCDF可简单的视为一种存取接口,任何使用 NetCDF存取格式的档案就可称为 NetCDF 档案; 至于 NetCDF 这套软件的功能,在于提供C、Fortran、C++、Perl、或其它语言I/O的链接库,以让程序发展者可以读写数据文件,其本身具有说明的能力、并且可以跨越平台和机器的限制。 每一个NetCDF档案可以含括多维度的、具有名称的变量,包括长短的整数、单倍与双倍精度的实数、字符等,且每一个变量都有其自我介绍的数据,包括量度的单位、全名及意义等文字说明,在此摘要性的檔头之后,才是真正的数据本身。 NetCDF接口 是一种多维的数据分布系统,由这个接口所产生的档案,具有多维的数据格式,当你需要其中的某一笔数据时,程序将不会从第一笔数据读到你所需要的数据处,而是由 NetCDF 软件直接存取那一个数据。如此一来将会大量的降低模式运算时数据存取的时间。 但也就是因为这样, NetCDF 所需要的空间是很大的,因为他多了很多的自解释的申明。 从数学上来说,netcdf存储的数据就是一个多自变量的单值函数。 用公式来说就是f(x,y,z,...)=value, 函数的自变量x,y,z等在netcdf中叫做维(dimension)或坐标轴(axix),函数值value在netcdf中叫做变量(Variables).而自变量和函数值在物理学上的一些性质,比如计量单位(量纲)、物理学名称等等在netcdf中就叫属性(Attributes). 二: NetCDF文件的结构 一个NetCDF文件的结构包括以下对象: 1、变量(Variables) 变量对应着真实的物理数据。比如我们家里的电表,每个时刻显示的读数表示用户的到该时刻的耗电量。这个读数值就可以用netcdf里的变量来表示。它是一个以时间为自变量(或者说自变量个数为一维)的单值函数。再比如在气象学中要作出一个气压图,就是“东经xx度,北纬yy度的点的大气压值为多少帕”,这是一个二维单值函数,两维分别是经度和纬度。函数值为大气压。 从上面的例子可以看出,netcdf中的变量就是一个N维数组,数组的维数就是实际问题中的自变量个数,数组的值就是观测得到的物理值。变量(数组值)在netcdf中的存储类型有六种,ascii字符(char) ,字节(byte), 短整型(short), 整型(int), 浮点(float), 双精度(double). 显然这些类型和c中的类型一致,搞C的朋友应该很快就能明白。 2、维(dimension) 一个维对应着函数中的某个自变量,或者说函数图象中的一个坐标轴,在线性代数中就是一个N维向量的一个分量(这也是维这个名称的由来)。在netcdf中,一个维具有一个名字和范围(或者说长度,也就是数学上所说的定义域,可以是离散的点集合或者连续的区间)。在netcdf中,维的长度基本都是有限的,最多只能有一个具有无限长度的维。 3、属性(Attribute) 属性对变量值和维的具体物理含义的注释或者说解释。因为变量和维在netcdf中都只是无量纲的数字,要想让人们明白这些数字的具体含义,就得靠属性这个对象了。 在netcdf中,属性由一个属性名和一个属性值(一般为字符串)组成。比如,在某个cdl文件中有这样的代码段 temperature:units = celsius ; 前面的temperature是一个已经定义好的变量(Variable),即温度,冒号后面的units就是属性名,表示物理单位,=后面的就是units这个属性的值,为“celsius” ,即摄氏度,整个一行代码的意思就是温度这个物理量的单位为celsius,很好理解。 三: CDL结构 CDL全称为network Common data form Description Language,它是用来描述netcdf文件的结构的一种语法格式。它包括前面所说的 三种netcdf对象(变量、维、属性) 的具体定义。看一个具体例子 netcdf simple_xy { dimensions: x = 6 ; y = 12 ; variables: int data(x, y) ; data: data = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71 ; } 上面的代码定义了一个符合netcdf格式的结构simple_xy, 这个结构包括三个部分 1、维的定义,以dimensions:关键字开头 dimensions: x = 6 ; y = 12 ; 定义了两个轴(或者说两维),名字分别为x和y,x轴的长度(准确的说是坐标点的个数)为6. y轴的长度为12。 2、变量的定义:以variables:开头 variables: int data(x, y); 定义了一个以x轴和y轴为自变量的函数data,数学公式就是f(x,y)=data; 注意维出现的顺序是有序的,它决定data段中的具体赋值结果. 3、数据的定义,以data:开头 data: data = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71 ; 这个段数据用数学的函数公式f(x,y)=data来看, 就是 x=0,y=0时,data = 0; x=0,y=1时,data = 1; x=5,y=11是,data=71; 要注意的是, 1、赋值顺序: 我们给出的是c格式的cdl文件,因此这里的赋值顺序和c语言中的一致,也就是通常所说的“行式赋值”, 而fortran语言中则是“列式赋值”,因此在fortran格式的cdl文件中,data段的数值顺序和这里正好行列互换。 在处理Celeste3D生成的数据时,就要按照fortran语言中的 “列式赋值”。 2、自变量的默认取值和坐标变量 如果只给出维的长度,那么维的值默认从0开始,然后自动加1,到(长度-1)停止,很多情况下我们要自己给出每个点的坐标值,这时就需要用到netcdf里的坐标变量coordinate varibles:增加一个和只和维相关的一元函数(自变量)并给出它的取值范围。 比如下面的cdl文件: netcdf sfc_pres_temp { dimensions: latitude = 6 ; //纬度轴 longitude = 12 ; //经度轴 variables: float latitude(latitude) ; //坐标变量,存储具体纬度 latitude:units = degrees_north ; float longitude(longitude) ; //坐标变量,存储具体纬度 longitude:units = degrees_east ; float pressure(latitude, longitude) ; //某个点(经度和纬度的交点)的大气压值 pressure:units = hPa ; //大气压的单位为 float temperature(latitude, longitude) ; //某个点(经度和纬度的交点)的温度值 temperature:units = celsius ; //温度的单位为 data: latitude = 25, 30, 35, 40, 45, 50 ; longitude = -125, -120, -115, -110, -105, -100, -95, -90, -85, -80, -75, -70 ; pressure = 900, 906, 912, 918, 924, 930, 936, 942, 948, 954, 960, 966, 901, 907, 913, 919, 925, 931, 937, 943, 949, 955, 961, 967, 902, 908, 914, 920, 926, 932, 938, 944, 950, 956, 962, 968, 903, 909, 915, 921, 927, 933, 939, 945, 951, 957, 963, 969, 904, 910, 916, 922, 928, 934, 940, 946, 952, 958, 964, 970, 905, 911, 917, 923, 929, 935, 941, 947, 953, 959, 965, 971 ; temperature = 9, 10.5, 12, 13.5, 15, 16.5, 18, 19.5, 21, 22.5, 24, 25.5, 9.25, 10.75, 12.25, 13.75, 15.25, 16.75, 18.25, 19.75, 21.25, 22.75, 24.25, 25.75, 9.5, 11, 12.5, 14, 15.5, 17, 18.5, 20, 21.5, 23, 24.5, 26, 9.75, 11.25, 12.75, 14.25, 15.75, 17.25, 18.75, 20.25, 21.75, 23.25, 24.75, 26.25, 10, 11.5, 13, 14.5, 16, 17.5, 19, 20.5, 22, 23.5, 25, 26.5, 10.25, 11.75, 13.25, 14.75, 16.25, 17.75, 19.25, 20.75, 22.25, 23.75, 25.25 } 对于上面的数据,就是 latitude = 25,longitude = -125时,pressure = 900,temperature = 9; latitude = 25,longitude = -120时,pressure = 906,temperature = 10.5; 以此类推。 References: http://blog.csdn.net/laomai/article/details/1740747 http://blog.csdn.net/happyparrot/article/details/1567624 http://www.unidata.ucar.edu/software/netcdf/#netcdf_faq
个人分类: 数据格式|2403 次阅读|0 个评论
install netcdf hdf5 antlr udunits in linux
yaozhixiong 2012-11-30 10:50
在集群上面安装软件netcdf hdf5 antlr udunits **************************************** Install hdf (hdf5-1.8.10) . / configure -- prefix = /public/userspace/yaozhixiong/program/hdf -- enable - shared -- enable - hl make make install **************************************** Install netcdf (netcdf-4.2.1) LDFLAGS =- L / public/userspace/yaozhixiong/program/hdf / lib CPPFLAGS =- I / public/userspace/yaozhixiong/program/hdf / include ./ configure -- enable - netcdf - 4 -- enable - dap -- enable - shared -- prefix = / public/userspace/yaozhixiong/program/netcdf make make install **************************************** Install antlr ( antlr2.7.7) 参考 http://blog.wamaker.net/post/antlr-installation ./configure –with-cxx=g++ –with-java –enable-cxx –prefix=/public/userspace/yaozhixiong/program/antlr make make install **************************************** install udunits (udunits-2.1.24) 参考 http://bla.sphemo.us/2011/03/18/compile-and-install-nco-netcdf-operators-on-linux/ CC=gcc CXX=' ' F77=gfortran ./configure --prefix=/public/userspace/yaozhixiong/program/udunits make make install
个人分类: linux|6681 次阅读|0 个评论
Ubuntu12.04下利用Intel编译器编译安装NetCDF4.2.1.1
reinit2012 2012-11-23 19:54
系统版本:Ubuntu12.04.01 Intel版本:parallel_studio_xe_2013_update1_ia32
个人分类: NetCDF|4242 次阅读|0 个评论
FORTRAN 读取 NETCDF解决undefine 诸如undefined reference to
热度 1 cwjwang 2012-10-10 00:04
当出现此类问题的时候 光靠 gfortran -o test w02.f90 -I/usr/local/netcdf/include -L/usr/local/netcdf/lib -lnetcdf 不能解决的,可以尝试gfortran -o test w02.f90 -I/usr/local/netcdf/include -L/usr/local/netcdf/lib -lnetcdf -lnetcdff 或gfortran -o test w02.f90 -I/usr/local/netcdf/include -L/usr/local/netcdf/lib -lnetcdff -lnetcdf -lhdf5_hl -lhdf5 -lz 附上错误的提示,供以后参考 /tmp/ccKcBo4F.o: In function `MAIN__': w02.f90:(.text+0x39): undefined reference to `nf_create_' w02.f90:(.text+0x71): undefined reference to `nf_def_dim_' w02.f90:(.text+0xa9): undefined reference to `nf_def_dim_' w02.f90:(.text+0xfc): undefined reference to `nf_def_var_' w02.f90:(.text+0x115): undefined reference to `nf_enddef_' w02.f90:(.text+0x14e): undefined reference to `nf_close_' /tmp/ccKcBo4F.o: In function `write_data_0_': w02.f90:(.text+0x1a7): undefined reference to `nf_put_vara_int_' /tmp/ccKcBo4F.o: In function `check_err_': w02.f90:(.text+0x21d): undefined reference to `nf_strerror_' collect2: ld 返回 1
16132 次阅读|1 个评论
netcdf 手册(1)引言——接口
cwjwang 2012-9-29 12:01
引言 (1) netcdf 接口 netcdf 是数据库用来贮存和恢复数组数据的接口函数。数组是n(n=0,1,2,3...)维的矩形结构,由统一形式的元素组成(如:8位的字符,32位的整型数据)。标量(简单的单值变量)是0维数组。netcdf是数据的提取接口,而这种接口支持把数据看成自我描述、可移植的。数组变量可直接获得,不必知道数据如何贮存的细节。且数据的辅助信息如:数据的单位与可能储存在数据里。通用的函数和应用程序可读取netcdf的数据库以及变幻、重组、分析、展示某一领域的数据。这些应用的发展,已经提高了数据的获得能力、软件对数组型数据再利用、管理、分析、展现能力。netcdf实现对数据类型的提取,这意味着在netcdf数据库的所有操作必须使用接口提供的一系列函数。数据的代表型就是用接口的应用程序的隐藏后面,因此数据的储存不会受到外在的程序的影响;netcdf物理属性的代表是其设计独立于计算机的。netcdf支持c、fortran77、fortran90、c++接口,且在不同计算机系统运行。
3736 次阅读|0 个评论
netcdf安装 、zlib 、szip、hdf5、mpich2、curl系列软件安装
热度 5 cwjwang 2012-9-20 14:00
最近装netcdf, 发现网上的许多方法都不完善,许多库文件与头文件的位置没有加入默认的文件夹里,以至于安装netcdf总会提醒缺少这个库,那个库的。亲自动手,记录安装过程,以便查询 装netcdf 需要 zlib szip netcdf hdf5 curl mpich2 这些软件 其中zlib,szip是hdf5与netcdf需要的库文件,二者可以二选一。 (1) 下载这些源代码 (2) 安装zlib tar -zxvf zlib***.tar.gz cd zlib* mkdir /usr/local/zlib ./configure --prefix=/usr/local/zlib --libdir=/usr/lib/ --includedir=/usr/lib/ --sharedlibdir=/usr/share 其中 --libdir=/usr/lib/ --includedir=/usr/lib/一定写上,把库文件与头文件装在系统默认搜寻的地方,免得后面设置LD_LIBRARY_PATH ,如果不懂可用./configure --help 查看 make make check make install (3)安装szip tar -zxvf szip***.tar.gz cd szip* mkdir /usr/local/szip ./configure --prefix=/usr/local/szip --libdir=/usr/lib/ --includedir=/usr/lib/ --sharedstatedir=/usr/share --bindir=/usr/bin/ 其中--bindir=/usr/bin/表示把可执行的二进制的文件放入默认的地方,就不用设置PATH了 make make check make install (3) 安装curl tar -zxvf curl***.tar.gz cd curl* mkdir /usr/local/curl ./configure --prefix=/usr/local/curl --libdir=/usr/lib/ --includedir=/usr/include/ --sharedstatedir=/usr/share --bindir=/usr/bin/ make make check make install (4)安装mpich2 tar -zxvf mpich***.tar.gz cd mpich* mkdir /usr/local/mpich ./configure --prefix=/usr/local/mpich --libdir=/usr/lib/ --includedir=/usr/lib/ --sharedstatedir=/usr/share --bindir=/usr/bin/ make make check make install (5) 安装hdf5 tar -zxvf hdf5***.tar.gz cd hdf5* mkdir /usr/local/hdf5 ./configure --prefix=/usr/local/hdf5 --libdir=/usr/lib/ --includedir=/usr/lib/ --sharedstatedir=/usr/share --bindir=/usr/bin/ make make check make install (6)安装netcdf tar -zxvf netcdf***.tar.gz cd netcdf* mkdir /usr/local/netcdf ./configure --prefix=/usr/local/netcdf --libdir=/usr/lib/ --includedir=/usr/lib/ --sharedstatedir=/usr/share --bindir=/usr/bin/ 如果装了intel编译器,会提示math.h的错误,加上CC=icc make make check make install 完美收官!
27197 次阅读|17 个评论
手把手教你在Ubuntn 12.04下安装netcdf
热度 5 LGJ080560 2012-5-25 10:43
第一步在http://www.unidata.ucar.edu/downloads/netcdf/index.jsp下载一个你需要的netcdf版本,我下载的是netcdf-4.1.3,就以这个版本为例吧。 第二步在主文件夹下用鼠标右键新建,建立一个文件夹(我用鼠标右键新建菜单,建立的文件夹名字为lgj)也可以在终端上用 mkdir lgj建立一个文件夹(用ctrl+alt+t打开终端),把下载好的netcdf-4.1.3.tar.gz(其他版本也可以)复制-粘帖到lgj文件夹里面,解压缩netcdf-4.1.3文件也有两种方法,最简单的一种就是用鼠标右键的解压缩菜单解压缩netcdf-4.1.3.tar.gz,或者在终端里面进入到lgj(cd lgj)文件里然后在终端上输入 tar -zxvf netcdf-4.1.3.tar.gz,解压缩成功。而后在终端(liguojing@ubuntu:~mkdir netcdf/4.1.3)或者用鼠标在主文件夹下建立一个netcdf/4.1.3文件夹。 第三步就不能采用鼠标操作了,在终端上进入lgj/netcdf-4.1.3(解压缩后的文件夹中),输入 ./configure --prefix=/home/liguojing/netcdf/4.1.3 --disable-netcdf-4命令(因为我的netcdf的绝对目录为/home/liguojing/netcdf,你的绝对目录应该是/home/你的用户名(liguojing@ubuntu:~中的@ubuntu的前面部分)/netcdf/4.1.3),等待终端运行完毕,这个时候netcdf/4.1.3文件夹中什么都没有。注意:必须把netcdf-4.1.3(其他版本一样)安装在netcdf文件下面某个文件夹里面,其他名字的文件夹不行。 第四步在运行完的终端中输入make check install(如果你的是不能上网的并行计算机(不是Ubuntn)那么就要先输入make all,等终端输出完没有错误,再输入make install)命令,终端运行完毕后,你再看netcdf/4.1.3文件夹,发现生成了bin,inclucde,lib和share四个文件(夹)。 恭喜你安装成功了!!(如果安装出现问题请把下面的软件包安装一遍: sudo apt-get install build-essential flex cmake zlib1g-dev qt4-dev-tools libqt4-dev gnuplot libreadline-dev libxt-dev )感谢西北工业大学钟城文老师告知了我如何查知绝对目录!如果有疑问请联系QQ93869859。
个人分类: 学术探讨|20674 次阅读|9 个评论
NetCDF安装记录
热度 2 PengJiDing 2012-3-20 20:56
1: NetCDF编译过程 cdnetcdf-4.1.3 ./configure --disable-dap --disable-netcdf-4 --prefix=/usr/local/netcdf ( 根据 http://hi.baidu.com/liuxiaogis/blog/item/6f662e38d5a03b3c96ddd81a.html 的说法,加上--disable-dap的原因是缺少一个‘curl’的lib, --disable-netcdf-4是报错中提出的解决办法 ) 但是连这一步都没有通过, ....................... checking whether ifort accepts -g... no checking for Fortran flag to compile .f90 files... unknown configure: error: Fortran could not compile .f90 files configure: error: ./configure failed for libcf 在 --prefix=/usr/local/netcdf之后加上FC=gfortran之后 ./configure --disable-dap --disable-netcdf-4--prefix=/usr/local/netcdfFC=gfortran 编译通过! 2: make 直接输入 make 出现 ....................... make : Nothing to be done for `all-am'. make : Leaving directory `/home/dinghao/netcdf-4.1.3/examples' make : Leaving directory `/home/dinghao/netcdf-4.1.3/examples' make : Entering directory `/home/dinghao/netcdf-4.1.3' make : Leaving directory `/home/dinghao/netcdf-4.1.3' make : Leaving directory `/home/dinghao/netcdf-4.1.3' 在/usr/local/netcdf/ 目录下没有出现任何东西!?confused! 3: make check 步骤 键入 make check 出现 ....................... ================== All 7 tests passed ================== make : Leaving directory `/home/dinghao/netcdf-4.1.3/examples/CXX' make : Leaving directory `/home/dinghao/netcdf-4.1.3/examples/CXX' make : Entering directory `/home/dinghao/netcdf-4.1.3/examples' make : Nothing to be done for `check-am'. make : Leaving directory `/home/dinghao/netcdf-4.1.3/examples' make : Leaving directory `/home/dinghao/netcdf-4.1.3/examples' make : Entering directory `/home/dinghao/netcdf-4.1.3' make : Leaving directory `/home/dinghao/netcdf-4.1.3' check 居然通过! 4: make install 步骤 键入 sudomake install 最后显示 ........................... make install-data-hook make : Entering directory `/home/dinghao/netcdf-4.1.3' +-------------------------------------------------------------+ | Congratulations! You have successfully installed netCDF! | | | | You can use script "nc-config" to find out the relevant | | compiler options to build your application. Enter | | | | nc-config --help | | | | for additional information. | | | | CAUTION: | | | | If you have not already run "make check", then we strongly | | recommend you do so. It does not take very long. | | | | Before using netCDF to store important data, test your | | build with "make check". | | | | NetCDF is tested nightly on many platforms at Unidata | | but your platform is probably different in some ways. | | | | If any tests fail, please see the netCDF web site: | | http://www.unidata.ucar.edu/software/netcdf/ | | | | NetCDF is developed and maintained at the Unidata Program | | Center. Unidata provides a broad array of data and software | | tools for use in geoscience education and research. | | http://www.unidata.ucar.edu | +-------------------------------------------------------------+ make : Leaving directory `/home/dinghao/netcdf-4.1.3' make : Leaving directory `/home/dinghao/netcdf-4.1.3' make : Leaving directory `/home/dinghao/netcdf-4.1.3' 说明安装成功! 5: 测试 下面是一个已编好的用来测试NetCDF的小程序simple_xy_wr(由刘情操提供 http://blog.sina.com.cn/s/blog_4b1d9e7b0100zg89.html ,特此鸣谢)或者用/netcdf-4.1.3/example/F90/里面的例子来测试: program simple_xy_wr use netcdf implicit none ! 定义数据文件的名称 character (len = *), parameter :: FILE_NAME = "simple_xy.nc" ! 写一个12*6的二维数据 integer, parameter :: NDIMS = 2 integer, parameter :: NX = 6, NY = 12 ! 当创建netCDF文件的时候,变量和维数都有一个对应的ID integer :: ncid, varid, dimids(NDIMS) integer :: x_dimid, y_dimid integer :: x, y ! 要保存到文件的数据数组 integer, dimension(:,:), allocatable :: data_out ! 为数据数组分配内存 allocate(data_out(NY, NX)) ! 随意往数据数组里写一些数据 do x = 1, NX do y = 1, NY data_out(y, x) = (x - 1) * NY + (y - 1) end do end do ! 创建netCDF文件,返回文件对应的ID,如果存在则覆盖,check子程序用来检验执行是否成功 call check( nf90_create(FILE_NAME, NF90_CLOBBER, ncid) ) ! 定义维数,返回一个对应的ID call check( nf90_def_dim(ncid, "x", NX, x_dimid) ) call check( nf90_def_dim(ncid, "y", NY, y_dimid) ) ! 把上面得到的ID写到一个存放ID的数组里,注意,在fortran中,数组是以列为主存放数据的 dimids = (/ y_dimid, x_dimid /) ! 定义变量,返回一个对应的ID call check( nf90_def_var(ncid, "data", NF90_INT, dimids, varid) ) ! 定义完成,关闭定义模式 call check( nf90_enddef(ncid) ) ! 写入数据 call check( nf90_put_var(ncid, varid, data_out) ) ! 关闭文件 call check( nf90_close(ncid) ) !提示写文件成功 print *, "*** SUCCESS writing example file simple_xy.nc! " contains subroutine check(status) integer, intent ( in) :: status if(status /= nf90_noerr) then print *, trim(nf90_strerror(status)) stop 2 end if end subroutine check end program simple_xy_wr 在主目录下键入 gfortran cel-test.f90 -I/usr/local/netcdf/include -L/usr/local/netcdf/lib -lnetcdff -o test ( cel-test.f90为程序名, test为编译后生成的 ) 编译通过! 然后运行test,键入 ./test 结果无法运行,出现 Attempting netcdf-4 operation on netcdf-3 file STOP 2 再次郁闷! 打开.zshrc, 即打开所用shell的配置文件 gedit .zshrc 在文件后面加上 export NETCDF=/usr/local/ export DYLD_LIBRARY_PATH=$NETCDF/lib:$DYLD_LIBRARY_PATH export LD_LIBRARY_PATH=$NETCDF/lib:$LD_LIBRARY_PATH export PATH=$NETCDF/bin:$PATH 重新启动shell,然后再编译,运行test,得到 0 12 24 36 *** SUCCESS writing example file simple_xy.nc! 大功告成! 备注:以下为各个步骤执行命令的解释: $ ./configure The configuration script will set up the Makefiles that will be used to build the NetCDF libraries and utilities. It will also set up the installation directory for the default location of /usr/local. If you would like to install the libraries in another location, use this configure command: $ ./configure --prefix=/your/desired/install/directory) $ make----Make the libraries When the configuration step completes successfully, you can build the libraries using ‘make’. $ make check-----Testing NetCDF on Linux* You can test your NetCDF libraries using ‘make check’. $ make install------Installing NetCDF on Linux* Install NetCDF libraries using ‘make install’. This will install the NetCDF libraries, include files, and utilities in the default location of /usr/local or the location specified in the configuration step with the --prefix= option References: 1:http://bbs.sciencenet.cn/home.php?mod=spaceuid=237238do=blogid=547593 2: http://blog.sina.com.cn/s/blog_4b1d9e7b0100zg89.html 3:http://blog.sina.com.cn/s/articlelist_1260232315_3_1.html
个人分类: 备忘录|43358 次阅读|2 个评论
NetCDF学习纪要A
PengJiDing 2012-3-20 20:28
一:NetCDF简介 NetCDF是由大气研究大学协会(University Corporation for Atmospheric Research,UCAR)的Unidata项目开发的。NetCDF全称为network Common Data Format,中文译法为“网络通用数据格式”,对程序员来说,它和zip、jpeg、bmp文件格式类似,都是一种文件格式的标准。netcdf文件开始的目的是用于存储气象科学中的数据,现在已经成为许多数据采集软件的生成文件的格式。NetCDF由于其灵活性,能够传输海量的面向阵列(array-oriented)数据,已经被采纳用于陆地,海洋和大气科学。NetCDF数据集的一个例子就是北美地区的20个格网集合,每个格网尺寸为30公里,每一个格网都有自己的高程级别。对于每个格网层的每个格网单元,都有关于12个大气指标的超过一年时间的每小时测量记录。因此,它被称为“多维数据(multi-dimensional data)”。 NetCDF可简单的视为一种存取接口,任何使用 NetCDF存取格式的档案就可称为 NetCDF 档案; 至于 NetCDF 这套软件的功能,在于提供C、Fortran、C++、Perl、或其它语言I/O的链接库,以让程序发展者可以读写数据文件,其本身具有说明的能力、并且可以跨越平台和机器的限制。 每一个NetCDF档案可以含括多维度的、具有名称的变量,包括长短的整数、单倍与双倍精度的实数、字符等,且每一个变量都有其自我介绍的数据,包括量度的单位、全名及意义等文字说明,在此摘要性的檔头之后,才是真正的数据本身。 NetCDF接口 是一种多维的数据分布系统,由这个接口所产生的档案,具有多维的数据格式,当你需要其中的某一笔数据时,程序将不会从第一笔数据读到你所需要的数据处,而是由 NetCDF 软件直接存取那一个数据。如此一来将会大量的降低模式运算时数据存取的时间。 但也就是因为这样, NetCDF 所需要的空间是很大的,因为他多了很多的自解释的申明。 从数学上来说,netcdf存储的数据就是一个多自变量的单值函数。 用公式来说就是f(x,y,z,...)=value, 函数的自变量x,y,z等在netcdf中叫做维(dimension)或坐标轴(axix),函数值value在netcdf中叫做变量(Variables).而自变量和函数值在物理学上的一些性质,比如计量单位(量纲)、物理学名称等等在netcdf中就叫属性(Attributes). 二: NetCDF文件的结构 一个NetCDF文件的结构包括以下对象: 1、变量(Variables) 变量对应着真实的物理数据。比如我们家里的电表,每个时刻显示的读数表示用户的到该时刻的耗电量。这个读数值就可以用netcdf里的变量来表示。它是一个以时间为自变量(或者说自变量个数为一维)的单值函数。再比如在气象学中要作出一个气压图,就是“东经xx度,北纬yy度的点的大气压值为多少帕”,这是一个二维单值函数,两维分别是经度和纬度。函数值为大气压。 从上面的例子可以看出,netcdf中的变量就是一个N维数组,数组的维数就是实际问题中的自变量个数,数组的值就是观测得到的物理值。变量(数组值)在netcdf中的存储类型有六种,ascii字符(char) ,字节(byte), 短整型(short), 整型(int), 浮点(float), 双精度(double). 显然这些类型和c中的类型一致,搞C的朋友应该很快就能明白。 2、维(dimension) 一个维对应着函数中的某个自变量,或者说函数图象中的一个坐标轴,在线性代数中就是一个N维向量的一个分量(这也是维这个名称的由来)。在netcdf中,一个维具有一个名字和范围(或者说长度,也就是数学上所说的定义域,可以是离散的点集合或者连续的区间)。在netcdf中,维的长度基本都是有限的,最多只能有一个具有无限长度的维。 3、属性(Attribute) 属性对变量值和维的具体物理含义的注释或者说解释。因为变量和维在netcdf中都只是无量纲的数字,要想让人们明白这些数字的具体含义,就得靠属性这个对象了。 在netcdf中,属性由一个属性名和一个属性值(一般为字符串)组成。比如,在某个cdl文件中有这样的代码段 temperature:units = "celsius" ; 前面的temperature是一个已经定义好的变量(Variable),即温度,冒号后面的units就是属性名,表示物理单位,=后面的就是units这个属性的值,为“celsius” ,即摄氏度,整个一行代码的意思就是温度这个物理量的单位为celsius,很好理解。 三: CDL结构 CDL全称为network Common data form Description Language,它是用来描述netcdf文件的结构的一种语法格式。它包括前面所说的 三种netcdf对象(变量、维、属性) 的具体定义。看一个具体例子 netcdf simple_xy { dimensions: x = 6 ; y = 12 ; variables: int data(x, y) ; data: data = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71 ; } 上面的代码定义了一个符合netcdf格式的结构simple_xy, 这个结构包括三个部分 1、维的定义,以dimensions:关键字开头 dimensions: x = 6 ; y = 12 ; 定义了两个轴(或者说两维),名字分别为x和y,x轴的长度(准确的说是坐标点的个数)为6. y轴的长度为12。 2、变量的定义:以variables:开头 variables: int data(x, y); 定义了一个以x轴和y轴为自变量的函数data,数学公式就是f(x,y)=data; 注意维出现的顺序是有序的,它决定data段中的具体赋值结果. 3、数据的定义,以data:开头 data: data = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71 ; 这个段数据用数学的函数公式f(x,y)=data来看, 就是 x=0,y=0时,data = 0; x=0,y=1时,data = 1; x=5,y=11是,data=71; 要注意的是, 1、赋值顺序: 我们给出的是c格式的cdl文件,因此这里的赋值顺序和c语言中的一致,也就是通常所说的“行式赋值”, 而fortran语言中则是“列式赋值”,因此在fortran格式的cdl文件中,data段的数值顺序和这里正好行列互换。 在处理Celeste3D生成的数据时,就要按照fortran语言中的 “列式赋值”。 2、自变量的默认取值和坐标变量 如果只给出维的长度,那么维的值默认从0开始,然后自动加1,到(长度-1)停止,很多情况下我们要自己给出每个点的坐标值,这时就需要用到netcdf里的坐标变量"coordinate varibles":增加一个和只和维相关的一元函数(自变量)并给出它的取值范围。 比如下面的cdl文件: netcdf sfc_pres_temp { dimensions: latitude = 6 ; //纬度轴 longitude = 12 ; //经度轴 variables: float latitude(latitude) ; //坐标变量,存储具体纬度 latitude:units = "degrees_north" ; float longitude(longitude) ; //坐标变量,存储具体纬度 longitude:units = "degrees_east" ; float pressure(latitude, longitude) ; //某个点(经度和纬度的交点)的大气压值 pressure:units = "hPa" ; //大气压的单位为 float temperature(latitude, longitude) ; //某个点(经度和纬度的交点)的温度值 temperature:units = "celsius" ; //温度的单位为 data: latitude = 25, 30, 35, 40, 45, 50 ; longitude = -125, -120, -115, -110, -105, -100, -95, -90, -85, -80, -75, -70 ; pressure = 900, 906, 912, 918, 924, 930, 936, 942, 948, 954, 960, 966, 901, 907, 913, 919, 925, 931, 937, 943, 949, 955, 961, 967, 902, 908, 914, 920, 926, 932, 938, 944, 950, 956, 962, 968, 903, 909, 915, 921, 927, 933, 939, 945, 951, 957, 963, 969, 904, 910, 916, 922, 928, 934, 940, 946, 952, 958, 964, 970, 905, 911, 917, 923, 929, 935, 941, 947, 953, 959, 965, 971 ; temperature = 9, 10.5, 12, 13.5, 15, 16.5, 18, 19.5, 21, 22.5, 24, 25.5, 9.25, 10.75, 12.25, 13.75, 15.25, 16.75, 18.25, 19.75, 21.25, 22.75, 24.25, 25.75, 9.5, 11, 12.5, 14, 15.5, 17, 18.5, 20, 21.5, 23, 24.5, 26, 9.75, 11.25, 12.75, 14.25, 15.75, 17.25, 18.75, 20.25, 21.75, 23.25, 24.75, 26.25, 10, 11.5, 13, 14.5, 16, 17.5, 19, 20.5, 22, 23.5, 25, 26.5, 10.25, 11.75, 13.25, 14.75, 16.25, 17.75, 19.25, 20.75, 22.25, 23.75, 25.25 } 对于上面的数据,就是 latitude = 25,longitude = -125时,pressure = 900,temperature = 9; latitude = 25,longitude = -120时,pressure = 906,temperature = 10.5; 以此类推。 References: http://blog.csdn.net/laomai/article/details/1740747 http://blog.csdn.net/happyparrot/article/details/1567624 http://www.unidata.ucar.edu/software/netcdf/#netcdf_faq
个人分类: 备忘录|6555 次阅读|0 个评论
NetCDF格式的数据读取(Matlab)
热度 1 zheyang 2011-7-14 14:34
近来在了解cosmic掩星电离层数据资料时,遇到了数据读取问题,该数据为NetCDF(Network Common Data Form)格式的数据,通过查找资料与不断摸索数据读取的问题终于得以解决。 首先介绍一下NetCDF格式,NetCDF(network Common Data Form)网络通用数据格式是由美国大学大气研究协会(University Corporation for Atmospheric Research,UCAR)的Unidata项目科学家针对科学数据的特点开发的,是一种面向数组型并适于网络共享的数据的描述和编码标准。对程序员来说,它和zip、jpeg、bmp文件格式类似,都是一种文件格式的标准。netcdf文件开始的目的是用于存储气象科学中的数据,现在已经成为许多数据采集软件的生成文件的格式。利用NetCDF可以对网格数据进行高效地存储、管理、获取和分发等操作。由于其灵活性,能够传输海量的面向阵列(array-oriented)数据,目前广泛应用于大气科学、水文、海洋学、环境模拟、地球物理等诸多领域,例如,NCEP(美国国家环境预报中心)发布的再分析资料,NOAA的CDC(气候数据中心)发布的海洋与大气综合数据集(COADS)均采用NetCDF作为标准 。 (摘自百度百科) 起初在网上找了很多关于nc格式数据读取的资料,读取的方式有很多,最后选择利用Matlab语言进行读取,网上提供的方法之一( http://blogold.chinaunix.net/u/ 17182/showart_103606.html ) 。由于 台式机上matlab版本为R2009b,该方法 在matlab中总是报错;后来改在笔记本上运行(matlab版本为R2007b),居然可以正常读取了,最后得出结论:Matlab版本问题,此方法提供的插件只适用于低版本的Matlab。 虽然数据可以正常读取了,但是为了解决nc格式数据在高版本matlab上的读取问题,又查找了很多资料。介绍NetCDF的官方网站为 http://www.unidata.ucar.edu/software/netcdf/index.html , 相关的说明文件请参考该网站 http://www.unidata.ucar.edu/software/netcdf/docs/ 。 随着Matlab版本的不断更新,用于读取NecCDF数据的matlab插件也在不断更新,适用于不同版本的nc插件可以在 http://sourceforge.net/projects/mexcdf/files/ 此网站上下载得到。 适用于Matlab2008b之后版本的nc文件插件名为mexcdf,最新版本为mexcdf.r3606,将该压缩文件解压后得到mexcdf及snctools两个文件。但是为了更加直观的了解nc文件信息,需要配合netcdf_toolbox这个工具箱使用。关于这些插件在matlab上的安装说明可以详见各解压缩文件夹下的自述文件(README)。有关matlab读取netcdf数据一些命令函数可以help netcdf。如果需要批量处理该格式文件,则需要编写批处理程序。 nc格式数据的读取问题已经解决,但是有些问题理解的还不够深入,希望通过不断的学习能够得以逐步提高。
个人分类: 专业学习笔记|5918 次阅读|1 个评论
Linux下对NetCDF文件的简单使用方法
热度 1 fengweiigg 2009-12-8 16:09
NetCDF文件是一种科学数据存储格式,广泛用于大气、海洋和地球科学。NetCDF也是一个函数库集合,提供给用户一整套使用和操作该种格式数据的方法。该格式是跨平台的,且可以使用C、Fortran和Matlab等多种语言进行操作。 现已fedora 8为例,简介如下: (1)从 http://www.unidata.ucar.edu/downloads/netcdf/index.jsp 官方网站下载源程序包。最新版为4.0.1,我安装的是3.6.3,测试成功。 (2)假设源程序包保存在/home/fengwei/netcdf-3.6.3文件夹下,打算安装在/usr/local/netcdf路径里。进入root后,操作如下:   mkdir /usr/local/netcdf   cd /home/fengwei/netcdf-3.6.3   ./configure --prefix=/usr/local/netcdf   make check   make   make install (3)安装完成后,/usr/local/netcdf/文件夹下存在4个文件,分别为bin,include,lib和share。 (4)针对感兴趣的某一nc文件,编写相应的fortran代码(如test.f90),其中应包括include 'netcdf.inc',并调用NetCDF给定的函数对nc文件进行读取和写入等操作。 (5)编译fortran代码,以intel fortran编译器为例,其他的编译器基本一致;   ifort -c -I/usr/local/netcdf/include test.f90   ifort -o test test.o -L/usr/local/netcdf/lib -lnetcdf (6)运行   ./test 完毕!
个人分类: 生活点滴|17956 次阅读|0 个评论

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-6-3 01:39

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部