Commit fe51699990c8bd84664c85a8acdc7c26058d3f0e

Authored by Elena.Budnik
1 parent 8f00a4d9

nc attributes

php/classes/FilesMgr.php
... ... @@ -217,7 +217,7 @@ class FilesMgr extends AmdaObjectMgr
217 217 {
218 218 exec('ncvarinfo '.$this->fileName.' '.$this->param2dd($varId), $results);
219 219 $tempArr = explode(' ', $results[0]);
220   - // data type
  220 + // data type
221 221 switch ($tempArr[0]) {
222 222 case "5": $data_type = 'FLOAT';
223 223 break;
... ... @@ -241,7 +241,15 @@ class FilesMgr extends AmdaObjectMgr
241 241 $size = 1;
242 242 }
243 243  
244   - return array('type' => $data_type, 'size' => $size, 'n_records' => $n_recs);
  244 + $units = exec('ncvar_attr '.$this->fileName.' '.$this->param2dd($varId).' UNITS');
  245 + if (substr($units, 0,5) == 'error') $units = '';
  246 +
  247 + $fillval = exec('ncvar_attr '.$this->fileName.' '.$this->param2dd($varId).' _Fillvalue'); // _Fillvalue
  248 + if (substr($fillval, 0,5) == 'error') $fillval = exec('ncvar_attr '.$this->fileName.' '.$this->param2dd($varId).' Fillvalue');
  249 + if (substr($fillval, 0,5) == 'error') $fillval = exec('ncvar_attr '.$this->fileName.' '.$this->param2dd($varId).' Fillval');
  250 + if (substr($fillval, 0,5) == 'error') $fillval = '';
  251 +
  252 + return array('type' => $data_type, 'size' => $size, 'n_records' => $n_recs, 'units' => $units, 'fillvalue' => $fillval);
245 253 }
246 254  
247 255 protected function param2dd($paramID)
... ...
php/src/Makefile
... ... @@ -4,7 +4,7 @@ CFLAGS = -ggdb -DLINUX -m64 -march=core2 -fPIC -Dlinux -D_REENTRANT -malign-doub
4 4 CC = gcc
5 5  
6 6 EXE = nctimestring2double nctimeinfo getncvars ncvarinfo \
7   - ncinfo_remote \
  7 + ncinfo_remote ncvar_attr \
8 8 cdfinfo cdfvarinfo cdfstartstopfromdata cdfsamplingfromdata cdfvar_attr \
9 9 AddVI
10 10  
... ... @@ -14,8 +14,11 @@ AddVI: AddVI.c
14 14 ${CC} ${CFLAGS} -o AddVI AddVI.c ${INC} ${LIB} -lDDClientLibC
15 15  
16 16 ncinfo_remote: ncinfo_remote.c
17   - ${CC} ${CFLAGS} -o ncinfo_remote ncinfo_remote.c ${INC} ${LIB} -lnetcdf
18   -
  17 + ${CC} ${CFLAGS} -o ncinfo_remote ncinfo_remote.c ${INC} ${LIB} -lnetcdf
  18 +
  19 +ncvar_attr: ncvar_attr.c
  20 + ${CC} ${CFLAGS} -o ncvar_attr ncvar_attr.c ${INC} ${LIB} -lnetcdf
  21 +
19 22 nctimestring2double: nctimestring2double.c
20 23 ${CC} ${CFLAGS} -o nctimestring2double nctimestring2double.c ${INC} ${LIB} -lDDClientLibC -lnetcdf
21 24  
... ...
php/src/ncvar_attr.c 0 → 100644
... ... @@ -0,0 +1,75 @@
  1 +/*
  2 + * get parameter info from nc file
  3 + * args : ncfile varId infoId
  4 + * infoId :
  5 + * UNITS
  6 + * FILLVALUE
  7 + */
  8 +
  9 +#include <stdio.h>
  10 +#include <stdlib.h>
  11 +#include <string.h>
  12 +#include <netcdf.h>
  13 +
  14 +void check(int stat)
  15 +{
  16 + if (stat != NC_NOERR)
  17 + {
  18 + printf("error: %s\n", nc_strerror(stat));
  19 + exit(1);
  20 + }
  21 +}
  22 +
  23 +main(int argc, char **argv)
  24 +{
  25 + int ncID, varID;
  26 + size_t i, k;
  27 +// char varname[NC_MAX_NAME];
  28 + int stat = 0;
  29 + nc_type xtype;
  30 + char name_in[NC_MAX_NAME];
  31 + float number_attr;
  32 + int nattsp;
  33 +
  34 + if (argc <= 3) {
  35 + printf("Incorrect number of arguments\n");
  36 + exit(1);
  37 + }
  38 +
  39 + check(nc_open(argv[1],NC_WRITE|NC_SHARE,&ncID));
  40 +
  41 + check(nc_inq_varid(ncID, argv[2], &varID));
  42 + check(nc_inq_varnatts(ncID, varID, &nattsp));
  43 + // fprintf(stdout, "%d\n", nattsp);
  44 +
  45 + for (i = 0; i < nattsp; i++) {
  46 + check(nc_inq_attname(ncID, varID, i, name_in));
  47 +
  48 + if (strcasecmp(name_in, argv[3]) == 0) {
  49 +
  50 + check(nc_inq_atttype(ncID, varID, name_in, &xtype));
  51 +
  52 + if (xtype == NC_CHAR) {
  53 + size_t attlen = 0;
  54 + check(nc_inq_attlen(ncID, varID, name_in, &attlen));
  55 + unsigned char *string_attr = (unsigned char *)malloc(attlen * sizeof(char*));
  56 +
  57 + check(nc_get_att(ncID, varID, name_in, string_attr));
  58 + fprintf(stdout, "%s\n", string_attr);
  59 + free(string_attr);
  60 + }
  61 + else {
  62 + check(nc_get_att(ncID, varID, name_in, &number_attr));
  63 + fprintf(stdout, "%e\n", number_attr);
  64 + }
  65 +
  66 + exit(0);
  67 + }
  68 + }
  69 +
  70 + stat = nc_close(ncID);
  71 + fprintf(stdout, "undefined\n");
  72 + exit(0);
  73 +}
  74 +
  75 +
... ...