Netcdf Example in NSM

From VLECK
Jump to: navigation, search

Example code

NSM
changedir("c:\documents and settings\werf010\desktop\netcdf");
	version=netcdf_getversion();
	if (0)
	 	h=netcdf_open("sresa1b_ncar_ccsm3_0_run1_200001.nc"; "nc_nowrite");
	 	zz=netcdf_read(h);
		{global_info; dimension_info; variable_info; attribute_info} = 
                       netcdf_getmetadata(h)[1];
	 	info=netcdf_getmetadata(h);
	 	datalat=netcdf_getdata("lat"; [[:Template:1; 128]]; h);
	 	datalat1=netcdf_getdata("lat"; [[:Template:1]]; h);
	 	datalatall=netcdf_getdata("lat"; {{}}; h);
	 	datalat=netcdf_getdata("lat"; [[:Template:1; 128; 1]]; h);
	 	datalon=netcdf_getdata("lon"; [[:Template:1; 256]]; h);
	 	datalat_bnds=netcdf_getdata("lat_bnds"; [[:Template:1,1; 128,2]]; h);
	 	datapr=netcdf_getdata("pr"; [[:Template:1,1,1; 1,128,256]]; h);
	 	dataua=netcdf_getdata("ua"; [[:Template:1,1,1,1; 1,17,128,256]]; h);
	 	data=netcdf_getdata("lat","lon","lat_bnds","pr","ua"; 
                       {{1; 128};{1; 256};{1,1;128,2}
	 	; {1,1,1; 1,128,256}; {1,1,1,1; 1,17,128,256}}; h);
	 elseif (1)
	 	h=netcdf_open("http://opendap.cgi- 
 systems.nl/thredds/dodsC/Alterra/europa/soil_gras.nc"; "nc_nowrite");
	 	info=netcdf_getmetadata(h);
	 	zz=netcdf_read(h);
	 elseif (0)
	 	h=netcdf_open("stbaume.nc"; "nc_nowrite");
	 	zz1=netcdf_read(h);
	 else
	 	h=netcdf_create("abc.nc"; "nc_netcdf4");
	// 	h=netcdf_open("abc.nc"; "nc_nowrite");
	 	q=netcdf_defdim("time","lon","lat","spec"; 0,0,10,3; h);
	 	z=netcdf_defvar("place"; "nc_double"; {"lon","lat"}; h);
	 	z=netcdf_defvar("time"; "nc_int"; {"time"}; h);
	 	z=netcdf_defvar("species"; "nc_string"; {"spec"}; h);
	 	netcdf_writevar("species"; "quercus robur","betula pendula",
                             "fagus sylvatica"; [[:Template:1;3]]; h);
		netcdf_writevar("time"; 1#10;[[:Template:1; 10]]; h);
	 	a=random(10,10);
	 	b=random(1)*100;
	 	c=redim(0; 4,4);
	 	n=netcdf_writevar("place"; a; [[:Template:1,1; 10,10]]; h);
	 	n=netcdf_writevar("place"; c; [[:Template:1,1; 4,4; 2,2]]; h);
	 	n=netcdf_writevar("place"; b; [[:Template:4,5]]; h);
	 	q=netcdf_setattribute("place"; "missings"; "nc_double"; nan(),nan();
                      h);
	 	p=netcdf_defvar("missingval"; "nc_double"; {{}}; h);
	 	l=netcdf_writevar("missingval"; nan(); {{}}; h);
	 	//q=netcdf_setattribute(""; "info"; "nc_char"; 
                //    "dit is een test voor strings","verdeeld over twee regels"; h);
	 	q=netcdf_setattribute(""; "info"; "nc_string"; 
                    "dit is een test voor strings","verdeeld over twee regels"; h);
	 	netcdf_sync(h);
	 	zz=netcdf_read(h);
	 endif
	 netcdf_close(h);



see also

netcdf_create
netcdf_open
netcdf_getmetadata
netcdf_close
netcdf_getdata
netcdf_read
netcdf_defdim
netcdf_defvar
netcdf_writevar
netcdf_setattribute
netcdf_sync