[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: 20020618: netCDF: Problem displaying array of values (fwd)



>From: Naveenta Anand <address@hidden>
>Subject: netCDF: Problem displaying array of values
>Organization: UCAR/Unidata
>Keywords: 200206181701.g5IH1K603595

------- Forwarded Message

Date:    Wed, 19 Jun 2002 10:43:39 -0400
From:    Naveenta Anand <address@hidden>
To:      "'Russ Rew'" <address@hidden>
Subject: RE: 20020618: netCDF: Problem displaying array of values

Russ,

Thank you so much for your prompt answer. Sure your solution works like a 
charm!!!! I am having trouble with 2 more variables in my program and hopefully 
the solution is similar to this one. I will try the same on them. The 
documentation on dimensions is not very self-explanatory in the netCDF manual 
so I have mostly been doing a lot of guessing and my own calculations or 
looking at old netCDF code.

I hope you got my other email about the problem from the past sent yesterday as 
well.

Thank you very much once again........

Naveenta.

Naveenta Anand
Software Engineer
Fisheries and Oceans Canada, Ottawa.
Phone: 991-6940

On June 18, 2002 4:53 PM, Russ Rew [SMTP:address@hidden] wrote:
> >To: "address@hidden" <address@hidden>
> >cc: "Bob' 'Keeley (E-mail)" <address@hidden>
> >From: Naveenta Anand <address@hidden>
> >Subject: netCDF: Problem displaying array of values
> >Organization: UCAR/Unidata
> >Keywords: 200206181701.g5IH1K603595
>
> Hi Naveenta,
>
> > Kindly help if you have any experience with the follows. I am using netCDF
> > library for C. Those, who are using any other language than C can also help
> >
> > since I see a problem with netCDF function calls (i.e.netCDF routines).
> >
> > PROBLEM SCENARIO:
> >
> > My variable is called station_parameter and this should display as follows:
> > "TEMP"
> > "PSAL"
> > "PRES"
> > There are three possible values as above for station_parameter
> >
> > And the dimension set of this variable comprises of 3 dimensions i.e.
> > N_PROF,N_PARAM_LEN,STRING4 where:
> > N_PROF = 1
> > N_PARAM_LEN = 3
> > STRING4 =4
> >
> > The variable structure finally is station_parameter
> > (N_PROF,N_PARAM_LEN,STRING4)
> >
> > -------------- Variable definition -----------------
> > if (n_param_len != 0) {
> >                             station_parameters_dims[0] = n_prof_dim;
> >                             station_parameters_dims[1] = n_param_dim;
> >                             station_parameters_dims[2] = strln4_dim;
> > stat=nc_def_var(ncid,"STATION_PARAMETERS",NC_CHAR,RANK_station_parameters,
> >                      station_parameters_dims,&station_parameters_id);
> >                             check_err(stat,__LINE__,__FILE__);
> >                     }
> > where RANK_station_parameters = 3.
> >
> > ------------ Adding values to variables -----------
> >
> >             {
> >                     size_t astart[] = {0,0,0};
> >                     size_t acount[] = {1,3,4};
> >                             acount[0] = n_prof_len;
> >                             acount[1] = n_param_len;
> >                             acount[2] = strln4_len;
> >                             astart[0]=0;
> >                             for (i=0;i < n_param_len;i ++)
> >                              {
> >             if ( i == (n_param_len -1))
> >                             strcpy(stn.prof[i].prof_type,"PRES");
> >             stat = nc_put_vara_text(ncid, station_parameters_id, astart,
> > acount,stn.prof[i].prof_type);
> >             check_err(stat,__LINE__,__FILE__);
> >                        astart[0]++;
> >                             }
> >                     }
> > where: stn.prof[i].prof_type is -
> > TEMP when i=1
> > PSAL when i=2
> > PRES when i=3.
> >
> > With the above routines, my variable displays as follows in the netCDF 
file:
> >
> >  STATION_PARAMETERS =
> >   "TEMP",
> >   "\000N\0007",
> >   "\0001" ;
> >
> > WHEREAS:
> >
> > As mentioned above, I am trying to output the following pattern from
> > station_parameter:
> > "TEMP"
> > "PSAL"
> > "PRES"
> > There are three possible values as above for station_parameter.
> >
> > 
----------------------------------------------------------------------------
> >
>
>
> The array acount[] should specify the "shape" of the slab of values
> you are writing, that is the number of indices along each dimension.
> Since you are writing only 4 characters along the last (strln4)
> dimension, this shape is 1 by 1 by 4, so you want acount initialized
> as {1, 1, 4} and not changed after that:
>
>                       size_t acount[] = {1,1,4};
>
> The array astart[] should specify where each write starts in the 1 by
> 3 by 4 cube of characters.  The first write will start at the {0,0,0}
> position but the next write will start at {0,1,0} and the last write
> at {0,2,0}.  So you can use your i index for astart[1], or you can
> increment astart[1] each time through the loop.
>
> So here is one version to do what you want:
>
>  {
>          size_t astart[] = {0,0,0};
>          size_t acount[] = {1,1,4};
>          for (i=0;i < n_param_len;i ++)
>                   {
>                   stat = nc_put_vara_text(ncid, station_parameters_id, 
astart,
>
>                                           acount, stn.prof[i].prof_type);
>                   check_err(stat,__LINE__,__FILE__);
>                   astart[1]++;
>                   }
>  }
>
> Another way to do it would be:
>
>  {
>          size_t astart[] = {0,0,0};
>          size_t acount[] = {1,1,4};
>          for (i=0;i < n_param_len;i ++)
>                   {
>                   astart[1] = i;
>                   stat = nc_put_vara_text(ncid, station_parameters_id, 
astart,
>
>                                           acount, stn.prof[i].prof_type);
>                   check_err(stat,__LINE__,__FILE__);
>                   }
>  }
>
> I haven't checked these by compiling and running them, because I
> didn't have the context for the fragment of code, but I think either
> of the above should work.  If not, please write back ...
>
> --Russ
>
> _____________________________________________________________________
>
> Russ Rew                                         UCAR Unidata Program
> address@hidden                     http://www.unidata.ucar.edu
>
>
>
>



------- End of Forwarded Message