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

Re: 970213: [q] long character strings?



>To: address@hidden
>From: address@hidden (Matthew H. Savoie)
>Subject: [q] long character strings?
>Organization: NOAA / FSL
>Keywords: 199703132340.QAA21386

Hi Matthew,

> (I'm using netcdf-2.4.3)
> Hi, I'm trying to add data to an existing netcdf file. The data consists of
> 32 lines of character data about 69 chars/line.  To do this I created a CDL
> file and tried to run ncgen, but to no avail.  
> 
> I narrowed down the problem to this cdl file below.
> 
> If you ncgen with the current set up, it runs, creates fortran output (oh
> yeah, I'm trying to create fortran code) which can be compiled and run, and
> a resulting ncdump on the output file is correct.  
> 
> If you uncomment out the test18 portions, the code now core dumps ncgen when
> given either the -f or -c flags, but you can create a cdf file  using 
> 'ncgen -o whatever file.cdl' and a following ncdump on whatever shows the
> correct data has been stored there.   
> 
> What I really want to do is create the variable (e.g. test) and then fill it
> with a single call to ncvptc.  But, this doesn't seem to be working very
> well.  Is there a way around this problem?  

There is a way around the problem.  If you have a very large character
string variable that requires more than 19 continuation lines to
assign, ncgen tries to put it in a string variable that's not big
enough, instead of producing an error message that the line is too long
(this is a bug).

If your FORTRAN compiler will accept statements with more than 1320
characters (20 lines * 66 characters per line), you can get ncgen to
generate them by changing a line in ncgen/genlib.h and recompiling
ncgen.  The line to change is:

  #define FORT_MAX_LINES        20      /* max lines in FORTRAN statement */

which you should change to something like

  #define FORT_MAX_LINES        100     /* max lines in FORTRAN statement */

(to permit ncgen to generate 99 continuation lines).  Then recompile
with "make all" and try the resulting ncgen on your CDL file.  I just
tried this, and it worked for your example.

However, the netCDF User's Guide advises that ncgen

    ... is only useful for relatively small CDL files, since all the
    data is included in variable initializations in the generated
    program.

By using large enough variables or CDL files, you will be able to break
ncgen, if only because the output will ultimately be too much for a
FORTRAN or C compiler to handle.  You may want to use the output of
ncgen as a guide but use different techniques for variable
initialization for large files.

_____________________________________________________________________

Russ Rew                                         UCAR Unidata Program
address@hidden                     http://www.unidata.ucar.edu