Re: [netcdfgroup] netcdfgroup Digest, Vol 295, Issue 1

Thanks you all for help, It worked as you suggested

Regards


________________________________
From: "netcdfgroup-request@xxxxxxxxxxxxxxxx" 
<netcdfgroup-request@xxxxxxxxxxxxxxxx>
To: netcdfgroup@xxxxxxxxxxxxxxxx
Sent: Wed, November 10, 2010 8:27:00 AM
Subject: netcdfgroup Digest, Vol 295, Issue 1

Send netcdfgroup mailing list submissions to
    netcdfgroup@xxxxxxxxxxxxxxxx

To subscribe or unsubscribe via the World Wide Web, visit
    http://mailman.unidata.ucar.edu/mailman/listinfo/netcdfgroup
or, via email, send a message with subject or body 'help' to
    netcdfgroup-request@xxxxxxxxxxxxxxxx

You can reach the person managing the list at
    netcdfgroup-owner@xxxxxxxxxxxxxxxx

When replying, please edit your Subject line so it is more specific
than "Re: Contents of netcdfgroup digest..."


Today's Topics:

   1. Re: Fw: NcVar put method (Stuart Levy)
   2. Re: Fw: NcVar put method (salah jubeh)
   3. Re: Fw: NcVar put method (Cedric Roux)


----------------------------------------------------------------------

Message: 1
Date: Tue, 9 Nov 2010 17:40:07 -0600
From: Stuart Levy <slevy@xxxxxxxxxxxxxxxxx>
To: salah jubeh <s_jubeh@xxxxxxxxx>
Cc: "netcdfgroup@xxxxxxxxxxxxxxxx" <netcdfgroup@xxxxxxxxxxxxxxxx>
Subject: Re: [netcdfgroup] Fw: NcVar put method
Message-ID: <20101109234007.GA4022@xxxxxxxxxxxxxxxxxxxxxxxxxx>
Content-Type: text/plain; charset=utf-8

One thing: you mention you intend to use the signature
   NcBool put(const ....* vals, const long* counts)

but when you call 
   data->put(&dataOut[0], *dim);

(note the "*dim" which dereferences to a long, rather than long *)
it'll call a different member function, namely
   NcBool put( const int* vals, long c0=0, long c1=0, ... )

Instead you'd probably want
   data->put(&dataOut[0], dim);
Right?


On Tue, Nov 09, 2010 at 03:14:36PM -0800, salah jubeh wrote:
> Hello Sjur,
> 
> I used set_cur(), but there is no effect. and I checked the return value of 
> the 
>
> put method and it was true which means data is written but it is not.
> 
> Regards
> 
> 
> ________________________________
> From: Sjur Kolberg <Sjur.A.Kolberg@xxxxxxxxx>
> To: salah jubeh <s_jubeh@xxxxxxxxx>; "netcdfgroup@xxxxxxxxxxxxxxxx" 
> <netcdfgroup@xxxxxxxxxxxxxxxx>
> Sent: Tue, November 9, 2010 8:17:58 PM
> Subject: RE: [netcdfgroup] Fw: NcVar put method
> 
>  
> Salah,
>  
> I think you might have to use set_cur() before the second call to put(), 
> which 
>I 
>
> believe now tries to continue adding values after the ones you already stored 
> with the first put(). Set_cur() with empty brackets sets the file pointer 
> back 

> to 0. If I?m correct, the second put() will also work if you comment out the 
> first...
>  
> Hope this helps,
>  
> Sjur K :-)
>  
>  
> From:netcdfgroup-bounces@xxxxxxxxxxxxxxxx 
> [mailto:netcdfgroup-bounces@xxxxxxxxxxxxxxxx] On Behalf Of salah jubeh
> Sent: 9. november 2010 16:49
> To: netcdfgroup@xxxxxxxxxxxxxxxx
> Subject: [netcdfgroup] Fw: NcVar put method
>  
> Sorry for sending this a gain
> 
> ----- Forwarded Message ----
> From:salah jubeh <s_jubeh@xxxxxxxxx>
> To: support-netcdf@xxxxxxxxxxxxxxxx
> Sent: Mon, November 8, 2010 12:58:41 PM
> Subject: NcVar put method
> I am trying to use this method signature -NcBool put(const ....* vals, const 
> long* counts)-; but I have a problem  , can some one please tell me what is 
> my 

> mistake .
> 
> Why - data->put(&dataOut[0], *dim);-  is not working. Please see the code.
> 
> 
> #include <iostream>
> #include <netcdfcpp.h>
> 
> using namespace std;
> 
> // We are writing 2D data, a 6 x 12 grid. 
> static const int NDIMS = 2;
> static const int NX = 6;
> static const int NY = 12;
> 
> // Return this in event of a problem.
> static const int NC_ERR = 2;
> 
> int main(void)
> {
>    // Different ways to write arrays
> 
>    int dataOut[NX * NY];
>    int dataOut2[NX] [NY];
>  
>    // Create some pretend data. Note that dataOut and dataOut2 are 
> identical...!!!
>    for(int i = 0; i < NX; i++) 
>       for(int j = 0; j < NY; j++){
>      dataOut[i * NY +j] = (i+1) * (j+1);
>      dataOut2[i][j] = (i+1) * (j+1);    
>     }
> 
> 
>    // Create the file.
>    NcFile dataFile("simple_xy.nc", NcFile::Replace);
> 
>    if (!dataFile.is_valid())
>    {
>       cout << "Couldn't open file!\n";
>       return NC_ERR;
>    }
>  
>    NcDim* xDim = dataFile.add_dim("x", NX);
>    NcDim* yDim = dataFile.add_dim("y", NY);
>  
>    
>   const NcDim* all[2] ;
>    all[0] = xDim;
>    all[1] = yDim;
> 
>    int *dim;
>    dim = new int[2];
>    dim[0] = 6;
>    dim[1] = 12;
>    
>    NcVar *data = dataFile.add_var("data", ncInt, 2, all);
>    NcVar *data2 = dataFile.add_var("data2", ncInt, 2, all);
> 
>    // This works fine and data and data2 are identical
>    // data->put(&dataOut[0],NX, NY);
>    data2->put(&dataOut2[0][0], NX, NY);
>    
>   // try to use another signature
> 
>    data->put(&dataOut[0], *dim); //nothing is written
>    
>  cout << "*** SUCCESS writing example file simple_xy.nc!" << endl;
> 
>    return 0;
> }
> 
> 
>      
> _______________________________________________
> netcdfgroup mailing list
> netcdfgroup@xxxxxxxxxxxxxxxx
> For list information or to unsubscribe,  visit: 
>http://www.unidata.ucar.edu/mailing_lists/ 
>



------------------------------

Message: 2
Date: Tue, 9 Nov 2010 16:41:48 -0800 (PST)
From: salah jubeh <s_jubeh@xxxxxxxxx>
To: Stuart Levy <slevy@xxxxxxxxxxxxxxxxx>
Cc: "netcdfgroup@xxxxxxxxxxxxxxxx" <netcdfgroup@xxxxxxxxxxxxxxxx>
Subject: Re: [netcdfgroup] Fw: NcVar put method
Message-ID: <900185.34712.qm@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
Content-Type: text/plain; charset="utf-8"

I am not very good with pointers some times it confuses me. The dim variable is 
a pointer to an array of integer. 

int *dim;
dim = new int[2];
dim[0] = 6;
dim[1] = 12;


and in this case it points to the address of the first element. Please correct 
me if I am wrong.
data->put(&dataOut[0], *dim); 

I find this signature strange because how the put method can determine the 
length of the counts variable. Any way If I change the method as you suggest I 
will get compilation error
simple_xy_wr2.cpp:60: error: call of overloaded ?put(int*, int*&)? is ambiguous
/usr/include/netcdfcpp.h:239: note: candidates are: NcBool NcVar::put(const 
int*, long int, long int, long int, long int, long int) <near match>
/usr/include/netcdfcpp.h:241: note:                 NcBool NcVar::put(const 
long 

int*, long int, long int, long int, long int, long int) <near match>
/usr/include/netcdfcpp.h:253: note:                 NcBool NcVar::put(const 
int*, const long int*) <near match>
/usr/include/netcdfcpp.h:254: note:                 NcBool NcVar::put(const 
long 

int*, const long int*) <near match>


Regards



________________________________
From: Stuart Levy <slevy@xxxxxxxxxxxxxxxxx>
To: salah jubeh <s_jubeh@xxxxxxxxx>
Cc: "netcdfgroup@xxxxxxxxxxxxxxxx" <netcdfgroup@xxxxxxxxxxxxxxxx>
Sent: Wed, November 10, 2010 12:40:07 AM
Subject: Re: [netcdfgroup] Fw: NcVar put method

One thing: you mention you intend to use the signature
   NcBool put(const ....* vals, const long* counts)

but when you call 
   data->put(&dataOut[0], *dim);

(note the "*dim" which dereferences to a long, rather than long *)
it'll call a different member function, namely
   NcBool put( const int* vals, long c0=0, long c1=0, ... )

Instead you'd probably want
   data->put(&dataOut[0], dim);
Right?


On Tue, Nov 09, 2010 at 03:14:36PM -0800, salah jubeh wrote:
> Hello Sjur,
> 
> I used set_cur(), but there is no effect. and I checked the return value of 
> the 
>
>
> put method and it was true which means data is written but it is not.
> 
> Regards
> 
> 
> ________________________________
> From: Sjur Kolberg <Sjur.A.Kolberg@xxxxxxxxx>
> To: salah jubeh <s_jubeh@xxxxxxxxx>; "netcdfgroup@xxxxxxxxxxxxxxxx" 
> <netcdfgroup@xxxxxxxxxxxxxxxx>
> Sent: Tue, November 9, 2010 8:17:58 PM
> Subject: RE: [netcdfgroup] Fw: NcVar put method
> 
>  
> Salah,
>  
> I think you might have to use set_cur() before the second call to put(), 
> which 

>I 
>
> believe now tries to continue adding values after the ones you already stored 
> with the first put(). Set_cur() with empty brackets sets the file pointer 
> back 


> to 0. If I?m correct, the second put() will also work if you comment out the 
> first...
>  
> Hope this helps,
>  
> Sjur K :-)
>  
>  
> From:netcdfgroup-bounces@xxxxxxxxxxxxxxxx 
> [mailto:netcdfgroup-bounces@xxxxxxxxxxxxxxxx] On Behalf Of salah jubeh
> Sent: 9. november 2010 16:49
> To: netcdfgroup@xxxxxxxxxxxxxxxx
> Subject: [netcdfgroup] Fw: NcVar put method
>  
> Sorry for sending this a gain
> 
> ----- Forwarded Message ----
> From:salah jubeh <s_jubeh@xxxxxxxxx>
> To: support-netcdf@xxxxxxxxxxxxxxxx
> Sent: Mon, November 8, 2010 12:58:41 PM
> Subject: NcVar put method
> I am trying to use this method signature -NcBool put(const ....* vals, const 
> long* counts)-; but I have a problem  , can some one please tell me what is 
> my 


> mistake .
> 
> Why - data->put(&dataOut[0], *dim);-  is not working. Please see the code.
> 
> 
> #include <iostream>
> #include <netcdfcpp.h>
> 
> using namespace std;
> 
> // We are writing 2D data, a 6 x 12 grid. 
> static const int NDIMS = 2;
> static const int NX = 6;
> static const int NY = 12;
> 
> // Return this in event of a problem.
> static const int NC_ERR = 2;
> 
> int main(void)
> {
>    // Different ways to write arrays
> 
>    int dataOut[NX * NY];
>    int dataOut2[NX] [NY];
>  
>    // Create some pretend data. Note that dataOut and dataOut2 are 
> identical...!!!
>    for(int i = 0; i < NX; i++) 
>       for(int j = 0; j < NY; j++){
>      dataOut[i * NY +j] = (i+1) * (j+1);
>      dataOut2[i][j] = (i+1) * (j+1);    
>     }
> 
> 
>    // Create the file.
>    NcFile dataFile("simple_xy.nc", NcFile::Replace);
> 
>    if (!dataFile.is_valid())
>    {
>       cout << "Couldn't open file!\n";
>       return NC_ERR;
>    }
>  
>    NcDim* xDim = dataFile.add_dim("x", NX);
>    NcDim* yDim = dataFile.add_dim("y", NY);
>  
>    
>   const NcDim* all[2] ;
>    all[0] = xDim;
>    all[1] = yDim;
> 
>    int *dim;
>    dim = new int[2];
>    dim[0] = 6;
>    dim[1] = 12;
>    
>    NcVar *data = dataFile.add_var("data", ncInt, 2, all);
>    NcVar *data2 = dataFile.add_var("data2", ncInt, 2, all);
> 
>    // This works fine and data and data2 are identical
>    // data->put(&dataOut[0],NX, NY);
>    data2->put(&dataOut2[0][0], NX, NY);
>    
>   // try to use another signature
> 
>    data->put(&dataOut[0], *dim); //nothing is written
>    
>  cout << "*** SUCCESS writing example file simple_xy.nc!" << endl;
> 
>    return 0;
> }
> 
> 
>      
> _______________________________________________
> netcdfgroup mailing list
> netcdfgroup@xxxxxxxxxxxxxxxx
> For list information or to unsubscribe,  visit: 
>http://www.unidata.ucar.edu/mailing_lists/ 
>



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mailman.unidata.ucar.edu/mailing_lists/archives/netcdfgroup/attachments/20101109/751b8464/attachment.html>


------------------------------

Message: 3
Date: Wed, 10 Nov 2010 08:26:36 +0100
From: Cedric Roux <cedric.roux@xxxxxxxxxx>
To: salah jubeh <s_jubeh@xxxxxxxxx>
Cc: netcdfgroup@xxxxxxxxxxxxxxxx
Subject: Re: [netcdfgroup] Fw: NcVar put method
Message-ID: <4CDA492C.10101@xxxxxxxxxx>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

On 11/09/2010 04:48 PM, salah jubeh wrote:
> Sorry for sending this a gain
>
>
> ----- Forwarded Message ----
>
> From: salah jubeh<s_jubeh@xxxxxxxxx>
> To: support-netcdf@xxxxxxxxxxxxxxxx
> Sent: Mon, November 8, 2010 12:58:41 PM
> Subject: NcVar put method
>
>
> I am trying to use this method signature -NcBool put(const ....*   vals, const
> long* counts)-; but I have a problem  , can some one please tell me what is my
> mistake .
>
> Why - data->put(&dataOut[0],*dim);-  is not working. Please see the code.
>
>
> #include<iostream>
> #include<netcdfcpp.h>
>
> using namespace std;
>
> // We are writing 2D data, a 6 x 12 grid.
> static const int NDIMS = 2;
> static const int NX = 6;
> static const int NY = 12;
>
> // Return this in event of a problem.
> static const int NC_ERR = 2;
>
> int main(void)
> {
>     // Different ways to write arrays
>
>     int  dataOut[NX * NY];
>     int dataOut2[NX] [NY];
>
>     // Create some pretend data. Note that dataOut and dataOut2 are
> identical...!!!
>     for(int i = 0; i<  NX; i++)
>        for(int j = 0; j<  NY; j++){
>       dataOut[i * NY +j] = (i+1) * (j+1);
>       dataOut2[i][j] = (i+1) * (j+1);
>      }
>
>
>     // Create the file.
>     NcFile dataFile("simple_xy.nc", NcFile::Replace);
>
>     if (!dataFile.is_valid())
>     {
>        cout<<  "Couldn't open file!\n";
>        return NC_ERR;
>     }
>
>     NcDim* xDim = dataFile.add_dim("x", NX);
>     NcDim* yDim = dataFile.add_dim("y", NY);
>
>
>    const NcDim* all[2] ;
>     all[0]  = xDim;
>     all[1] = yDim;
>
>     int *dim;
>     dim = new int[2];
>     dim[0] = 6;
>     dim[1] = 12;
>
>     NcVar *data = dataFile.add_var("data", ncInt, 2, all);
>     NcVar *data2 = dataFile.add_var("data2", ncInt, 2, all);
>
>     // This works fine and data and data2 are identical
>     // data->put(&dataOut[0],NX, NY);
>     data2->put(&dataOut2[0][0], NX, NY);
>
>    // try to use another signature
>
>     data->put(&dataOut[0],*dim); //nothing is written

what about:

long dim[2];
dim[0] = 6;
dim[1] = 12;
data->put(&dataOut[0],dim);
(using a long instead of an int and passing "dim" instead of "*dim")

I'm not sure of that, just try.

HTH
C?dric

>
>   cout<<  "*** SUCCESS writing example file simple_xy.nc!"<<  endl;
>
>     return 0;
> }
>
>
>
>
>
>
> _______________________________________________
> netcdfgroup mailing list
> netcdfgroup@xxxxxxxxxxxxxxxx
> For list information or to unsubscribe,  visit: 
>http://www.unidata.ucar.edu/mailing_lists/



------------------------------

_______________________________________________
netcdfgroup mailing list
netcdfgroup@xxxxxxxxxxxxxxxx
For list information or to unsubscribe,  visit: 
http://www.unidata.ucar.edu/mailing_lists/

End of netcdfgroup Digest, Vol 295, Issue 1
*******************************************



      
  • 2010 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: