<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
</head>
<body>
<p><br>
</p>
<div class="moz-cite-prefix">Le 14/10/2021 à 21:03, Joaquim Manuel
Freire Luís a écrit :<br>
</div>
<blockquote type="cite"
cite="mid:VI1PR04MB3966C7D9352FE47FE5F07EA2A6B89@VI1PR04MB3966.eurprd04.prod.outlook.com">
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<meta name="Generator" content="Microsoft Word 15 (filtered
medium)">
<style>@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}@font-face
{font-family:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}pre
{mso-style-priority:99;
mso-style-link:"HTML Preformatted Char";
margin:0in;
font-size:10.0pt;
font-family:"Courier New";
mso-fareast-language:PT;}span.HTMLPreformattedChar
{mso-style-name:"HTML Preformatted Char";
mso-style-priority:99;
mso-style-link:"HTML Preformatted";
font-family:Consolas;
mso-fareast-language:EN-US;}span.EmailStyle22
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;}.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}div.WordSection1
{page:WordSection1;}</style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
<div class="WordSection1">
<p class="MsoNormal">Even,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span lang="EN-US">There are some issues
with this way.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">My draft Julia function
looks like bellow (tested with a MxNx7 array) but get this
errors<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">julia>
GMT.write_multiband(cube, "gd_cube.nc")<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Warning 1: No 1D
variable is indexed by dimension time<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Warning 6: creation
option '-co' is not formatted with the key=value format<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Warning 6: creation
option '-co' is not formatted with the key=value format<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Warning 6: creation
option '-co' is not formatted with the key=value format</span></p>
</div>
</blockquote>
I don't know the Julia bindings, but the error message seems to
suggest you can remove the "-co" element in your options[] array
since it presumably must only contain the "key=value" creation
options, like in the Python bindings<br>
<blockquote type="cite"
cite="mid:VI1PR04MB3966C7D9352FE47FE5F07EA2A6B89@VI1PR04MB3966.eurprd04.prod.outlook.com">
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">ERROR 1: netcdf error
#-45 : NetCDF: Not a valid data type or _FillValue type
mismatch .<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">at
(C:\programs\compa_libs\gdal_GIT\gdal\frmts\netcdf\netcdfdataset.cpp,netCDFDataset::CreateCopy,9012)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">ERROR 1: netcdf error
#-49 : NetCDF: Variable not found .<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">at
(C:\programs\compa_libs\gdal_GIT\gdal\frmts\netcdf\netcdfdataset.cpp,NCDFPutAttr,10454)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Warning 1: No 1D
variable is indexed by dimension time<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">And indeed the “time”
variable shows up filled with 7 zeros when I open the nc
file that is nevertheless created.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Also checked with
getmetadataitem(ds, "NETCDF_DIM_time_VALUES") that the
"1,2,3,4,5,6,7" info was correctly set.</span></p>
</div>
</blockquote>
You need to surround the values of the _DEF and _VALUES items with {
and } braces to indicate this is a list (this is the particular
syntax expected by the netCDF driver)<br>
<blockquote type="cite"
cite="mid:VI1PR04MB3966C7D9352FE47FE5F07EA2A6B89@VI1PR04MB3966.eurprd04.prod.outlook.com">
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">I’s also strange the
warnings about the “-co” options also because they were in
fact taken into account. Omitting them creates a classic nc
file.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">function
write_multiband(cube, fname::AbstractString, v=nothing;
dim_name::String="time")<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> nbands =
size(cube,3)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> ds =
gmt2gd(cube)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> </span>Gdal.setmetadataitem(ds,
"NETCDF_DIM_EXTRA", dim_name)<o:p></o:p></p>
<p class="MsoNormal"> Gdal.setmetadataitem(ds,
"NETCDF_DIM_" * dim_name * "_DEF", "$(nbands),6")<o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">
Gdal.setmetadataitem(ds, "NETCDF_DIM_" * dim_name *
"_VALUES", "1,2,3,4,5,6,7")<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">
Gdal.setmetadataitem(ds, dim_name * "#axis",
string(dim_name[1]))<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> crs =
Gdal.getproj(cube, wkt=true)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> (crs !=
"" ) && Gdal.setproj!(ds, crs)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">
Gdal.unsafe_copy(ds, filename=fname,
driver=getdriver("netCDF"), options=["-co", "FORMAT=NC4",
"-co", "COMPRESS=DEFLATE", "-co", "ZLEVEL=4"])<o:p></o:p></span></p>
<p class="MsoNormal">end<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div style="border:none;border-top:solid #E1E1E1
1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span
style="mso-fareast-language:PT" lang="EN-US">From:</span></b><span
style="mso-fareast-language:PT" lang="EN-US"> Even
Rouault <a class="moz-txt-link-rfc2396E" href="mailto:even.rouault@spatialys.com"><even.rouault@spatialys.com></a>
<br>
<b>Sent:</b> Sunday, October 10, 2021 10:48 PM<br>
<b>To:</b> Joaquim Manuel Freire Luís
<a class="moz-txt-link-rfc2396E" href="mailto:jluis@ualg.pt"><jluis@ualg.pt></a>; <a class="moz-txt-link-abbreviated" href="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a><br>
<b>Subject:</b> Re: [gdal-dev] Writing multi-bands vs
multi-datasets<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p>Joaquim,<span style="mso-fareast-language:PT"><o:p></o:p></span></p>
<p><a href="https://github.com/OSGeo/gdal/pull/4634"
moz-do-not-send="true">https://github.com/OSGeo/gdal/pull/4634</a>
should hopefully help<o:p></o:p></p>
<p>Even<o:p></o:p></p>
<div>
<p class="MsoNormal">Le 10/10/2021 à 22:26, Joaquim Manuel
Freire Luís a écrit :<o:p></o:p></p>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal"><span lang="EN-US">Hi,</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">I have a Julia version
of gdal_translate (that ends up calling
GDALDatasetRasterIOEx) that works in saving a MxNxP array,
but not the way I wanted.</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">It creates a
multi-subdatasets file, whilst what I wished is to write a
multi-band file.</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">For example, the file
written with this Julia function looks like below</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">How can I write a
multi-band instead of a multi-datasets?
</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">I’ve been looking at
the docs of GDALDatasetRasterIOEx but can’t see any way of
picking one or the other.</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">Joaquim</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">gdalinfo cube_rad.nc</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">Driver: netCDF/Network
Common Data Format</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">Files: cube_rad.nc</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">Size is 512, 512</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">Metadata:</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">
NC_GLOBAL#Conventions=CF-1.5</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US"> NC_GLOBAL#GDAL=GDAL
3.4.0dev, released 2021/99/99</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">
NC_GLOBAL#history=Sun Oct 10 13:01:06 2021: GDAL
CreateCopy( cube_rad.nc, ... )</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">Subdatasets:</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">
SUBDATASET_1_NAME=NETCDF:"cube_rad.nc":Band1</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">
SUBDATASET_1_DESC=[1567x1519] Band1 (32-bit
floating-point)</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">
SUBDATASET_2_NAME=NETCDF:"cube_rad.nc":Band2</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">
SUBDATASET_2_DESC=[1567x1519] Band2 (32-bit
floating-point)</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">…</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">Saving the same data
(or similar) from a Matlab code that I wrote long ago to
stack grids, shows</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">gdalinfo evi_cube.nc</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">Driver: netCDF/Network
Common Data Format</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">Files: evi_cube.nc</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">Size is 37, 59</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">Origin =
(580140.000000000000000,4418550.000000000000000)</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">Pixel Size =
(30.000000000000000,-30.000000000000000)</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">Metadata:</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">…</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">
latitude#actual_range={4416795,4418535}</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">
latitude#long_name=latitude</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">
latitude#units=degrees_north</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">
longitude#actual_range={580155,581235}</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">
longitude#long_name=longitude</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">
longitude#units=degrees_east</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">
NC_GLOBAL#Conventions=COARDS</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">
NC_GLOBAL#description=File written from Matlab</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">
NC_GLOBAL#node_offset=0</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">
NC_GLOBAL#Source_Software=Mirone</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US"> NC_GLOBAL#title=Grid
created by Mirone</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">
NETCDF_DIM_EXTRA={time}</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">
NETCDF_DIM_time_DEF={67,6}</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">
NETCDF_DIM_time_VALUES={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}</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">
z#actual_range={-856.4703369140625,176.8457641601562}</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US"> z#long_name=z</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US"> z#units=unknown</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">
z#_FillValue=-nan(ind)</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">Corner Coordinates:</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">Upper Left (
580140.000, 4418550.000)</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">Lower Left (
580140.000, 4416780.000)</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">Upper Right (
581250.000, 4418550.000)</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">Lower Right (
581250.000, 4416780.000)</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">Center (
580695.000, 4417665.000)</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">Band 1 Block=37x59
Type=Float32, ColorInterp=Undefined</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US"> NoData Value=nan</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US"> Unit Type: unknown</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US"> Metadata:</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">
actual_range={-856.4703369140625,176.8457641601562}</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US"> long_name=z</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US"> NETCDF_DIM_time=1</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US"> NETCDF_VARNAME=z</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US"> units=unknown</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">
_FillValue=-nan(ind)</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">Band 2 Block=37x59
Type=Float32, ColorInterp=Undefined</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US"> NoData Value=nan</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US"> Unit Type: unknown</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US"> Metadata:</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">
actual_range={-856.4703369140625,176.8457641601562}</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US"> long_name=z</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US"> NETCDF_DIM_time=2</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US"> NETCDF_VARNAME=z</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US"> units=unknown</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">
_FillValue=-nan(ind)</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">…</span><o:p></o:p></p>
<p class="MsoNormal"><span style="mso-fareast-language:PT"><br>
<br>
<o:p></o:p></span></p>
<pre>_______________________________________________<o:p></o:p></pre>
<pre>gdal-dev mailing list<o:p></o:p></pre>
<pre><a href="mailto:gdal-dev@lists.osgeo.org" moz-do-not-send="true">gdal-dev@lists.osgeo.org</a><o:p></o:p></pre>
<pre><a href="https://lists.osgeo.org/mailman/listinfo/gdal-dev" moz-do-not-send="true">https://lists.osgeo.org/mailman/listinfo/gdal-dev</a><o:p></o:p></pre>
</blockquote>
<pre>-- <o:p></o:p></pre>
<pre><a href="http://www.spatialys.com" moz-do-not-send="true">http://www.spatialys.com</a><o:p></o:p></pre>
<pre>My software is free, but my time generally not.<o:p></o:p></pre>
</div>
</blockquote>
<pre class="moz-signature" cols="72">--
<a class="moz-txt-link-freetext" href="http://www.spatialys.com">http://www.spatialys.com</a>
My software is free, but my time generally not.</pre>
</body>
</html>