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

Re: 950308: netCDF to Vis5D



>Organization: ?
>Keywords: 199503081249.AA05935 netCDF to VIS5D converter

Mechthild,

> I have problems with converting data in netCDF-Format into Vis5d-format.
> I want to read out time, date and parameter of my file and initialize the
> converting-program-variables. 
> 
> But my program doesn't work, perhaps could you give me the hint why not!
> Thank you very much, Mechthild.

Sorry, but there just isn't enough information in your message for us to
provide much help.  We can't compile the sample program you sent, since it
uses include files that weren't provided.  You haven't described any symptoms
except that your program doesn't work.  

Unfortunately, we just don't have the resources to debug programs with so
little information about what is wrong.  It would be useful to have a
program that makes netCDF data available to Vis5D, so I hope you can isolate
the problem or make more progress on it.  We'll try to help if you can give
us more to go on.

--Russ

______________________________________________________________________________

Russ Rew                                                UCAR Unidata Program
address@hidden                                          P.O. Box 3000
http://www.unidata.ucar.edu/                          Boulder, CO 80307-3000
______________________________________________________________________________


> /* netCDF_to_v5d.c */
> 
> 
> /*
>  * A skeleton of a program for converting your data format to the
>  * v5d format.  This version allows other map projections and vertical
>  * coordinate systems.
>  *
>  *  . You must know how to read the file format of your data either
>  *      using C's standard I/O functions or using a library you may
>  *      have for your format (we assume the former case here).
>  *  . You have to provide code to read your file's header to initialize
>  *      some variables, and code to read 3-D grids from your file.  Follow
>  *      the steps outlined in the program below.
>  *  . Edit the makefile to assign PROGRAM to the name you selected in (1).
>  *      Also, check the CFLAGS variable.
>  */
> 
> 
> 
> 
> #include <stdio.h>
> #include <stdlib.h>
> #include <math.h> 
> #include "binio.h"
> #include "v5d.h"
> #include "netcdf.h"
> 
> /*
> #define MAXLEVELS 10
> #define MAXVARS 10
> #define MAXTIMES 10
> */
> 
> /*
>  * This is the main conversion function.  The two filename arguments are
>  * obtained from the command line.
>  * Input:  infile - name of input file in your format
>  *         outfile - name of output file in v5d format
>  */
> int convert( infile, outfile )
> char *infile, *outfile;
> 
> {
>    float *g;
>    FILE *f;
>    int it, iv, ir, ic, il;
>    int ncid, var_id;
>    int p_len, d_len, z_len;
>    nc_type p_type, d_type, z_type;
>    char *var_name;
>    int time, date;
>    char *Parameter;
> 
>    int NumTimes;                      /* number of time steps */
>    int NumVars;                               /* number of variables */
>    int Nr, Nc, Nl[MAXLEVELS];         /* size of 3-D grids */
>    char VarName[MAXVARS][10];         /* names of variables */
>    int TimeStamp[MAXTIMES];           /* real times for each time step */
>    int DateStamp[MAXTIMES];           /* real dates for each time step */
>    int CompressMode;                  /* number of bytes per grid */
>    int Projection;                    /* a projection number */
>    float ProjArgs[100];                       /* the projection parameters */
>    int Vertical;                      /* a vertical coord system number */
>    float VertArgs[MAXLEVELS];         /* the vertical coord sys parameters */
> 
>    static long start[] = {0,0,0};
>    static long count[] = {5,5,5};
> 
>    /**
>     ** STEP 1:  open your file and read the header information to initialize
>     ** the above variables.
>     **/
>       
>    ncid = ncopen(infile, NC_NOWRITE);
>     
>    /* ncattinq(ncid, NC_GLOBAL, "Zeit", &z_type, &z_len);
>    time = (int *) malloc(z_len * nctypelen(z_type));
> 
>    ncattinq(ncid, NC_GLOBAL, "Datum", &d_type, &d_len);
>    date = (int *) malloc(d_len * nctypelen(d_type)); */
> 
>    ncattinq(ncid, NC_GLOBAL, "Parameter", &p_type, &p_len);
>    Parameter = (char *) malloc(p_len * nctypelen(p_type));
> 
>    ncattget(ncid, NC_GLOBAL, "Zeit", (void *)time);
>    ncattget(ncid, NC_GLOBAL, "Datum", (void *)date); 
>    ncattget(ncid, NC_GLOBAL, "Parameter", (void *)Parameter);
> 
>    
>    /* Initialisierung fuer 1 Datei mit 1 Parameter und 1 Zeitstempel */
>    NumTimes = 1;
>    NumVars = 1;                               
>    Nr = count[0];    
>    Nc = count[1];             
>    Nl[0] = count[2];          
>    strcpy( VarName[0], Parameter ); 
>    /*  VarName[0][0] = Parameter;
>    VarName[0][1] = '\0'; */
>    TimeStamp[0] = time;       
>    DateStamp[0] = date;
>    CompressMode = 1;          /* 1,2,4 */
>    Projection = 0;            /* 0,1,2,3 */
>    ProjArgs[0] = start[0];      /* north_boundary */
>    ProjArgs[1] = start[1];    /* west_boundary */
>    ProjArgs[2] = 2.5;         /* increment_north */
>    ProjArgs[3] = 2.5;         /* increment_west */
>    Vertical = 0;              /* 0,1,2 */
>    VertArgs[0] = start[2];    /* upper_boundary */
>    VertArgs[1] = 0.5;         /* increment_down */
> 
>  
>    /** END STEP 1 **/
> 
>    /* use the v5dCreate call to create the v5d file and write the header */
>    if (!v5dCreate( outfile, NumTimes, NumVars, Nr, Nc, Nl, VarName, 
> TimeStamp, 
> DateStamp, CompressMode, Projection, ProjArgs, Vertical, VertArgs )) {   
>       printf("Error: couldn't create %s\n", outfile );
>               exit(1); 
>    }
>    /* allocate space for grid data */
>    {
>       int maxnl, i;
>       maxnl = Nl[0];
>       for (i=1;i<NumVars;i++) {
>        if (Nl[i]>maxnl)
>          maxnl = Nl[i];
>       }
>       g = (float *) malloc( Nr * Nc * maxnl * sizeof(float) );
>       if (!g) {
>        printf("Error: out of memory\n");
>        exit(1); 
>       }
>    }
> 
> 
>    for (it=0;it<NumTimes;it++) {
> 
>       for (iv=0;iv<NumVars;iv++) {
> 
>        /**
>         ** STEP 2:  Read your 3-D grid data for timestep it and variable
>         ** iv into the array g here.
>         ** To help with 3-D array indexing we've defined a macro G.
>         ** G(0,0,0) is the north-west-bottom corner, G(Nr-1,Nc-1,Nl-1) is
>         ** the south-east-top corner.  If you want a value to be considered
>         ** missing, assign it equal to the constant MISSING.  For example:
>         ** G(ir,ic,il) = MISSING;
>         **/
> 
> #define G(ROW, COLUMN, LEVEL)   g[ (ROW) + ((COLUMN) + (LEVEL) * Nc) * Nr ];
> 
>       
>       var_id = ncvarid(ncid, VarName[iv]);
>       ncvarget(ncid, var_id, start, count, g);  
>       
> 
>        /** END STEP 2 **/
> 
>        /* Write data to v5d file. */
>        if (!v5dWrite( it+1, iv+1, g )) {
>           printf("Error while writing grid.  Disk full?\n");
>           exit(1); 
>        } 
>       }
> 
>    }
> 
>    ncclose(ncid);
>    v5dClose();
>    /* fclose(f); */
> }
> 
> 
> 
> /*
>  * Main.  You shouldn't have to touch this.
>  */
> main( argc, argv )
> int argc;
> char *argv[];
> {
>    if (argc==1) {
>       printf("Usage:\n");
>       printf("   %s infile outfile\n", argv[0]);
>    }
>    else {
>       printf("Input file: %s\n", argv[1] );
>       printf("Output file: %s\n", argv[2] );
>       convert( argv[1], argv[2] ); 
>    }
>    exit(0);
> }