00001 #include "netcdf.h"
00002
00003 int
00004 main() {
00005
00006 int ncid;
00007
00008
00009 int lat_dim, lon_dim, frtime_dim, timelen_dim;
00010
00011
00012 int P_id, lat_id, lon_id, frtime_id, reftime_id, scalarv_id;
00013
00014
00015 int dims[3];
00016
00017
00018 float float_val;
00019 double double_val;
00020
00021
00022 float P_valid_range[2];
00023
00024
00025 ncid = nccreate("example.nc", NC_CLOBBER);
00026
00027
00028 lat_dim = ncdimdef(ncid, "lat", 4L);
00029 lon_dim = ncdimdef(ncid, "lon", 3L);
00030 frtime_dim = ncdimdef(ncid, "frtime", NC_UNLIMITED);
00031 timelen_dim = ncdimdef(ncid, "timelen", 20L);
00032
00033
00034
00035 dims[0] = frtime_dim;
00036 dims[1] = lat_dim;
00037 dims[2] = lon_dim;
00038 P_id = ncvardef (ncid, "P", NC_FLOAT, 3, dims);
00039 ncattput (ncid, P_id, "long_name", NC_CHAR, 24,
00040 (void *)"pressure at maximum wind");
00041 ncattput (ncid, P_id, "units", NC_CHAR, 12,
00042 (void *)"hectopascals");
00043 P_valid_range[0] = 0;
00044 P_valid_range[1] = 1500;
00045 ncattput (ncid, P_id, "valid_range", NC_FLOAT, 2,
00046 (void *) P_valid_range);
00047 float_val = -9999;
00048 ncattput (ncid, P_id, "_FillValue", NC_FLOAT, 1,
00049 (void *) &float_val);
00050
00051 dims[0] = lat_dim;
00052 lat_id = ncvardef (ncid, "lat", NC_FLOAT, 1, dims);
00053 ncattput (ncid, lat_id, "long_name", NC_CHAR, 8,
00054 (void *)"latitude");
00055 ncattput (ncid, lat_id, "units", NC_CHAR, 13,
00056 (void *)"degrees_north");
00057
00058 dims[0] = lon_dim;
00059 lon_id = ncvardef (ncid, "lon", NC_FLOAT, 1, dims);
00060 ncattput (ncid, lon_id, "long_name", NC_CHAR, 9,
00061 (void *)"longitude");
00062 ncattput (ncid, lon_id, "units", NC_CHAR, 12,
00063 (void *)"degrees_east");
00064
00065 dims[0] = frtime_dim;
00066 frtime_id = ncvardef (ncid, "frtime", NC_LONG, 1, dims);
00067 ncattput (ncid, frtime_id, "long_name", NC_CHAR, 13,
00068 (void *)"forecast time");
00069 ncattput (ncid, frtime_id, "units", NC_CHAR, 5,
00070 (void *)"hours");
00071
00072 dims[0] = timelen_dim;
00073 reftime_id = ncvardef (ncid, "reftime", NC_CHAR, 1, dims);
00074 ncattput (ncid, reftime_id, "long_name", NC_CHAR, 14,
00075 (void *)"reference time");
00076 ncattput (ncid, reftime_id, "units", NC_CHAR, 9,
00077 (void *)"text_time");
00078
00079 scalarv_id = ncvardef (ncid, "scalarv", NC_LONG, 0, 0);
00080 double_val = 1;
00081 ncattput (ncid, scalarv_id, "scalar_att", NC_DOUBLE, 1,
00082 (void *) &double_val);
00083
00084
00085 ncattput (ncid, NC_GLOBAL, "history", NC_CHAR, 41,
00086 (void *)"created by Unidata LDM from NPS broadcast");
00087 ncattput (ncid, NC_GLOBAL, "title", NC_CHAR, 48,
00088 (void *)"NMC Global Product Set: Pressure at Maximum Wind");
00089
00090
00091 ncendef (ncid);
00092
00093 {
00094 static long lat_start[] = {0};
00095 static long lat_edges[] = {4};
00096 static float lat[] = {-90, -87.5, -85, -82.5};
00097 ncvarput(ncid, lat_id, lat_start, lat_edges, (void *)lat);
00098 }
00099
00100 {
00101 static long lon_start[] = {0};
00102 static long lon_edges[] = {3};
00103 static float lon[] = {-180, -175, -170};
00104 ncvarput(ncid, lon_id, lon_start, lon_edges, (void *)lon);
00105 }
00106
00107 {
00108 static long frtime_start[] = {0};
00109 static long frtime_edges[] = {1};
00110 static long frtime[] = {12};
00111 ncvarput(ncid, frtime_id, frtime_start, frtime_edges,
00112 (void *)frtime);
00113 }
00114
00115 {
00116 static long frtime_start[] = {1};
00117 static long frtime_edges[] = {1};
00118 static long frtime[] = {18};
00119 ncvarput(ncid, frtime_id, frtime_start, frtime_edges,
00120 (void *)frtime);
00121 }
00122
00123 {
00124 static long reftime_start[] = {0};
00125 static long reftime_edges[] = {20};
00126 static char reftime[] = {"1992 03 04 12:00"};
00127 ncvarput(ncid, reftime_id, reftime_start, reftime_edges,
00128 (void *)reftime);
00129 }
00130
00131 {
00132 static long P_start[] = {0, 0, 0};
00133 static long P_edges[] = {2, 4, 3};
00134 static float P[2][4][3] = {
00135 {{950, 951, 952}, {953, 954, 955}, {956, 957, 958}, {959, 960, 961}},
00136 {{962, 963, 964}, {965, 966, 967}, {968, 969, 970}, {971, 972, 973}}
00137 };
00138 ncvarput(ncid, P_id, P_start, P_edges, (void *)&P[0][0][0]);
00139 }
00140
00141 {
00142 static long scalarv = {-2147483647};
00143 ncvarput1(ncid, scalarv_id, (long *)0, (void *)&scalarv);
00144 }
00145 ncclose (ncid);
00146 return 0;
00147 }