00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063 #include <io.h>
00064
00066 int
00067 create_netcdf(char *title, char *title_french, char *summary, char *summary_french,
00068 char *keywords, char *processor, char *software, char *description, char *institution,
00069 char *creator_email, char *creator_url, char *creator_name,
00070 char *version, char *scenario, char *scenario_co2, char *model,
00071 char *institution_model, char *country, char *member, char *downscaling_forcing,
00072 char *contact_email, char *contact_name, char *other_contact_email, char *other_contact_name,
00073 char *filename, int outinfo, int format, int compression) {
00107 int istat = 0;
00108 int ncoutid;
00109 char *tmpstr = NULL;
00110
00111 if (outinfo == TRUE)
00112 (void) fprintf(stdout, "%s: Creating NetCDF file %s\n", __FILE__, filename);
00113
00114
00115 tmpstr = (char *) malloc(MAXPATH * sizeof(char));
00116 if (tmpstr == NULL) alloc_error(__FILE__, __LINE__);
00117
00118
00119 if (format == 4 && compression == TRUE)
00120 #ifdef NC_NETCDF4
00121 istat = nc_create(filename, NC_CLOBBER | NC_NETCDF4 | NC_CLASSIC_MODEL, &ncoutid);
00122 #else
00123 istat = nc_create(filename, NC_CLOBBER, &ncoutid);
00124 #endif
00125 else
00126 #ifdef NC_NETCDF4
00127 if (format == 4)
00128 istat = nc_create(filename, NC_CLOBBER | NC_NETCDF4 | NC_CLASSIC_MODEL, &ncoutid);
00129 else
00130 istat = nc_create(filename, NC_CLOBBER, &ncoutid);
00131 #else
00132 istat = nc_create(filename, NC_CLOBBER, &ncoutid);
00133 #endif
00134
00135 if (istat != NC_NOERR) handle_netcdf_error(istat, __FILE__, __LINE__);
00136
00137
00138 (void) strcpy(tmpstr, "CF-1.0");
00139 istat = nc_put_att_text(ncoutid, NC_GLOBAL, "Conventions", strlen(tmpstr), tmpstr);
00140 (void) strcpy(tmpstr, "Unidata Dataset Discovery v1.0");
00141 istat = nc_put_att_text(ncoutid, NC_GLOBAL, "Metadata_Conventions", strlen(tmpstr), tmpstr);
00142 istat = nc_put_att_text(ncoutid, NC_GLOBAL, "title", strlen(title), title);
00143 istat = nc_put_att_text(ncoutid, NC_GLOBAL, "title_french", strlen(title_french), title_french);
00144 istat = nc_put_att_text(ncoutid, NC_GLOBAL, "summary", strlen(summary), summary);
00145 istat = nc_put_att_text(ncoutid, NC_GLOBAL, "summary_french", strlen(summary_french), summary_french);
00146 istat = nc_put_att_text(ncoutid, NC_GLOBAL, "keywords", strlen(keywords), keywords);
00147 istat = nc_put_att_text(ncoutid, NC_GLOBAL, "processor", strlen(processor), processor);
00148 istat = nc_put_att_text(ncoutid, NC_GLOBAL, "software", strlen(software), software);
00149 istat = nc_put_att_text(ncoutid, NC_GLOBAL, "description", strlen(description), description);
00150 istat = nc_put_att_text(ncoutid, NC_GLOBAL, "institution", strlen(institution), institution);
00151 istat = nc_put_att_text(ncoutid, NC_GLOBAL, "creator_email", strlen(creator_email), creator_email);
00152 istat = nc_put_att_text(ncoutid, NC_GLOBAL, "creator_url", strlen(creator_url), creator_url);
00153 istat = nc_put_att_text(ncoutid, NC_GLOBAL, "creator_name", strlen(creator_name), creator_name);
00154 istat = nc_put_att_text(ncoutid, NC_GLOBAL, "version", strlen(version), version);
00155 istat = nc_put_att_text(ncoutid, NC_GLOBAL, "scenario", strlen(scenario), scenario);
00156 istat = nc_put_att_text(ncoutid, NC_GLOBAL, "scenario_co2", strlen(scenario_co2), scenario_co2);
00157 istat = nc_put_att_text(ncoutid, NC_GLOBAL, "model", strlen(model), model);
00158 istat = nc_put_att_text(ncoutid, NC_GLOBAL, "institution_model", strlen(institution_model), institution_model);
00159 istat = nc_put_att_text(ncoutid, NC_GLOBAL, "country", strlen(country), country);
00160 istat = nc_put_att_text(ncoutid, NC_GLOBAL, "member", strlen(member), member);
00161 istat = nc_put_att_text(ncoutid, NC_GLOBAL, "downscaling_forcing", strlen(downscaling_forcing), downscaling_forcing);
00162 istat = nc_put_att_text(ncoutid, NC_GLOBAL, "contact_email", strlen(contact_email), contact_email);
00163 istat = nc_put_att_text(ncoutid, NC_GLOBAL, "contact_name", strlen(contact_name), contact_name);
00164 istat = nc_put_att_text(ncoutid, NC_GLOBAL, "other_contact_email", strlen(other_contact_email), other_contact_email);
00165 istat = nc_put_att_text(ncoutid, NC_GLOBAL, "other_contact_name", strlen(other_contact_name), other_contact_name);
00166
00167
00168 istat = nc_enddef(ncoutid);
00169 if (istat != NC_NOERR) handle_netcdf_error(istat, __FILE__, __LINE__);
00170
00171
00172 istat = ncclose(ncoutid);
00173 if (istat != NC_NOERR) handle_netcdf_error(istat, __FILE__, __LINE__);
00174
00175
00176 (void) free(tmpstr);
00177
00178
00179 return 0;
00180 }