<html>
Hi Vidya,<br><br>
Please find below the script I used. It is written in a
"proprietary" language but I think that you can do the same
things in a perl script with calls to nco utilities
(<a href="http://nco.sourceforge.net/" eudora="autourl">http://nco.sourceforge.net</a>)<br>
By this way, I converted MSLA (sea level anomalies) netCDF files
(coverage: 0E - 360E / 90S - 90N) to GRASS raster ascii files (180W -
180E / 90S - 90N).<br><br>
<font color="#0000FF"><i>I need to be able to modify the point values of
the map so as to modify the variables of the netCDF file that i shall
reconvert the raster map to.<br>
</i></font>In order to do this, I think the easiest way is to use a perl
or shell script to create a very simple cdf file (just one array) from
the output of r.out.ascii -h. Mainly you will have to change space
character with a comma.<br>
Then you use ncgen to generate a netCDF file with just an array called
SLA for example.<br>
Then you use nco tools to replace the variable SLA in the original netCDF
file (or a copy !) with the new one.<br><br>
I hope that I will have some time by the end of this year to write a
script to convert GRASS ascii raster file to a netCDF file...<br><br>
Of course, it would be better to write a r.out.cdf and a r.in.cdf modules
compiled directly against netCDF libraries but I don't know C !<br><br>
Paul<br><br>
<br>
#!CDFTools<br>
#CDFTools Cdf2AsciiPaul.oce fic_in_netcdf num_grille fic_ou_grille
null_value<br><br>
variables FichierCDF, Grille, Latitudes, Longitudes;<br>
variables IndexLat, IndexLon;<br>
variables FichierAscii, Valeur;<br><br>
open grid file named argv[0] as FichierCDF for read;<br>
read grid to_integer(argv[1]) from file FichierCDF to Grille;<br>
Latitudes<x-tab> </x-tab>=
get_latitudes(Grille);<br>
Longitudes<x-tab> </x-tab>=
get_longitudes(Grille);<br><br>
open text file named argv[2] as FichierAscii for write;<br><br>
write text "north: 90.00"//"\n" to file
FichierAscii;<br>
write text "south: -90.00"//"\n" to file
FichierAscii;<br>
write text "east: 180.00"//"\n" to file
FichierAscii;<br>
write text "west: -180.00"//"\n" to file
FichierAscii;<br>
write text "rows: 720"//"\n" to file
FichierAscii;<br>
write text "cols: 1440"//"\n" to file
FichierAscii;<br>
write text "null: "//to_string(argv[3])//"\n" to file
FichierAscii;<br>
write text "type: float"//"\n"//"\n" to
file FichierAscii;<br><br>
IndexLat<x-tab> </x-tab>=
number(Latitudes)-1;<br>
while IndexLat >= 0 do<br>
IndexLon<x-tab> </x-tab>=
720;<br>
while IndexLon < number(Longitudes) do<br>
Valeur<x-tab> </x-tab>=
get_element(Grille, IndexLat, IndexLon, 0);<br>
if Valeur != DEFAULT_FLOAT then<br>
# if Valeur == DEFAULT_FLOAT
then<br>
# Valeur = 9999;<br>
# end if; <x-tab> </x-tab><br>
write
text<x-tab> </x-tab>to_string(Valeur)//"
"<br>
<x-tab> </x-tab>to file
FichierAscii;<br>
else <br>
<x-tab> </x-tab>Valeur="9999
";<br>
<x-tab> </x-tab>write text
Valeur to file FichierAscii;<br>
end if;<br>
IndexLon<x-tab> </x-tab>=
IndexLon+1;<br>
end while;<br>
IndexLon<x-tab> </x-tab>=
0;<br>
while IndexLon < (number(Longitudes)/2) do<br>
Valeur<x-tab> </x-tab>=
get_element(Grille, IndexLat, IndexLon, 0);<br>
if Valeur != DEFAULT_FLOAT then<br>
# if Valeur == DEFAULT_FLOAT
then<br>
# Valeur = 9999;<br>
# end if; <x-tab> </x-tab><br>
write
text<x-tab> </x-tab>to_string(Valeur)//"
"<br>
<x-tab> </x-tab>to file
FichierAscii;<br>
else <br>
<x-tab> </x-tab>Valeur="9999
";<br>
<x-tab> </x-tab>write text
Valeur to file FichierAscii;<br>
end if;<br>
IndexLon<x-tab> </x-tab>=
IndexLon+1;<br>
end while;<br><br>
IndexLat = IndexLat - 1;<br>
write text "\n" to file FichierAscii;<br>
end while;<br><br>
<br><br>
At 15:40 16/12/2002 -0800, you wrote:<br>
<blockquote type=cite class=cite cite>Hi paul,<br>
I guess i will be comfortable with the 2nd option.<br>
Could u pls send me the script if it is possible ?<br>
Also, after converting the netCDF file to the raster map form,<br>
I need to be able to modify the point values of the map so as to
modify<br>
the variables of the netCDF file that i shall reconvert the raster map
to.<br>
Like r.support is used to modify the header information how can i
actually<br>
go about modifying the variables of the netCDF by means of its<br>
corresponding raster map ? <br><br>
Thanx in advance.<br>
Vidya Kotamraju<br><br>
--- Paul Hasenohr <phasenohr@cls.fr> wrote:<br>
> Hello Vidya,<br>
> <br>
> I know two ways to import netCDF files into GRASS.<br>
> 1) You install R and you use R inside GRASS. R is<br>
> able to read netCDF <br>
> files, so you can export your variable in GRASS. I<br>
> used this method six <br>
> months ago and it worked fine.<br>
> <br>
> 2) An other option<br>
> You convert your netCDF file to an ascii file<br>
> readable with the r.in.ascii <br>
> command.<br>
> I prefer this option because it is less system<br>
> resources consuming.<br>
> I made a shell script to convert netCDF file into<br>
> GRASS raster ascii file <br>
> but I use netCDF tools developed by my company and<br>
> there are <br>
> not publically available. However, if you are<br>
> interested in, I can send it <br>
> to you and I believe that it is easily portable with<br>
> the nco tools <br>
>
(<a href="http://nco.sourceforge.net, have a look at ncks/" eudora="autourl">http://nco.sourceforge.net,
have a look at ncks</a>)<br>
> <br>
> HTH<br>
> Paul<br>
> </blockquote></html>