/** @file GetInfo.c * @version $Id: GetInfo.c,v 1.1 2013/05/22 13:33:52 budnik Exp $ */ #include <stdlib.h> #include <stdio.h> #include <string.h> #include <time.h> #include <math.h> #include <netcdf.h> #include <DD.h> int DataID, RecID, VarID; size_t RecNum; char Var[128]; size_t count[2] = {1L,TIMELENGTH}; size_t start[2] = {0L,0L}; size_t countVar[2] = {1L,128L}; /*---------------- NC ERROR --------------------------------------*/ void nc_handle_error(int status) { fprintf(stderr, "%s\n", nc_strerror(status)); exit(1); } /* ----------------------- MAIN ------------------------------------*/ int main(int argc, char *argv[]) { int status, len, infoID, i; char Project[50],Instrument[50],Mode[50], RInstrName[100], INFO_ID[50]; int dims[10]; size_t lenp, total_length; float *value; int ndimsp; if (argc < 4) { fprintf(stderr,"Usage: GetInfo reference_file_name VI_ID INFO_ID\n"); exit(0); } if ((status = nc_open(argv[1], NC_NOWRITE, &DataID)) != NC_NOERR) nc_handle_error(status); sscanf(argv[2], "%[^:]%*c%[^:]%*c%[^:]%*c",Project, Instrument, Mode); sprintf(RInstrName,"%s_%s_%s\0",Project,Instrument,Mode); sprintf(INFO_ID,"%s\0",argv[3]); if ((status = nc_inq_varid(DataID,RInstrName,&VarID)) != NC_NOERR) nc_handle_error(status); start[0] = 2; if((status = nc_get_vara_text(DataID, VarID, start, countVar, Var)) != NC_NOERR) nc_handle_error(status); len = strcspn(Var," "); Var[len] = '\0'; if ((status = nc_close(DataID)) != NC_NOERR) nc_handle_error(status); // Open VI_info.nc if ((status = nc_open(Var, NC_NOWRITE, &DataID)) != NC_NOERR) nc_handle_error(status); // Get Number of Records if ((status = nc_inq_varid(DataID, INFO_ID, &infoID)) != NC_NOERR) nc_handle_error(status); if ((status = nc_inq_varndims(DataID, infoID, &ndimsp)) != NC_NOERR) nc_handle_error(status); if ((status = nc_inq_vardimid(DataID, infoID, &dims)) != NC_NOERR) nc_handle_error(status); total_length = 0; for ( i = 0; i < ndimsp; i++) { if ((status = nc_inq_dimlen (DataID, dims[i], &lenp))!= NC_NOERR) nc_handle_error(status); total_length += lenp; } value = malloc(total_length*sizeof(float)); if ((status =nc_get_var_float(DataID, infoID, value)) != NC_NOERR) nc_handle_error(status); printf("%f", value[0]); for (i = 1; i < lenp; i++) printf(";%f", value[i]); if ((status = nc_close(DataID)) != NC_NOERR) nc_handle_error(status); }