int main() { int year; int month; int day; int flag=0; printf("请输入日期(格式为“年,月,日”,用逗号隔开):"); scanf("%d,%d,%d",&year,&month,&day); if ((year>=1812&&year<=2012)&&(month>=1&&month<=12)&&(day>=1&&day<=31)) { switch(month) { case 1: case 3: case 5: case 7: case 8: case 10: case 12:flag=1;break; case 4: case 6: case 9: case 11:{if(day<=30) flag=1;break;} case 2: { if(isLeapYear(year)) { if(day<=29)flag=1; } else {if(day<=28)flag=1;} } } if(flag==1){ NextDate(&year,&month,&day); printf("Nextdate:%d-%d-%d\n",year,month,day); } if(flag==0)printf("日期组合错误\n"); } else printf("无效输入日期\n"); return 0; }
int main (int argc, char* argv[]) { int option_index = 0; BGPDATA BGP; Initialize(BGP); int help = 0; while (1) { static struct option long_options[] = { {"verbose", no_argument, &BGP.verbose, 1}, {"or", no_argument, &BGP.or_flag, 1}, {"help", no_argument, &help, 1}, {"cidrfile",required_argument,0, 'a'}, {"update",required_argument,0, 'b'}, {"dir",required_argument,0, 'c'}, {"startdate",required_argument,0,'d'}, {"enddate",required_argument,0,'e'}, {"asnfile",required_argument,0,'f'}, {"outfile",required_argument,0,'g'}, {"file",required_argument,0,'h'}, {0, 0, 0, 0} }; int c = getopt_long(argc, argv, "", long_options,&option_index); if (c == -1) break; switch(c) { case 0: break; case 'a': BGP.setfile = optarg; break; case 'b': BGP.bgpfile.push_back(optarg); break; case 'c': BGP.dir.push_back(optarg); break; case 'd': BGP.startdate = optarg; break; case 'e': BGP.enddate = optarg; break; case 'f': BGP.asnfile = optarg; break; case 'g': BGP.outfile = optarg; break; case 'h': BGP.file = optarg; break; default : print_help(); exit(1); } } if (help) { print_help(); exit(1); } std::ofstream myFile; if(!BGP.outfile.empty()) { myFile.open(BGP.outfile.c_str(), std::ios::out); } std::ofstream &outFile = (BGP.outfile.empty() ? (std::ofstream&)cout : myFile); if (!BGP.setfile.empty()) { skipset_t *ipset = NULL; ReadFile(BGP.setfile,&ipset); BGP.ipset = ipset; } if (!BGP.asnfile.empty()) { ReadASNFile(BGP); } if (BGP.bgpfile.size() > 0) { vector<string>::iterator it; for (it = BGP.bgpfile.begin(); it != BGP.bgpfile.end(); it++) { ReadBGPFile(BGP,*it,outFile); } if (!BGP.outfile.empty()) { outFile.close(); } exit(1); } if (!BGP.file.empty()) { ProcessFiles(BGP,outFile); exit(1); } if (BGP.startdate.empty() || BGP.enddate.empty() || BGP.dir.empty()) { print_help(); exit(1); } if (BGP.startdate.length() != 8 || BGP.enddate.length() != 8) { cout << "The date format is YYYYMMDD and should be of length 8\n"; exit(1); } if (!is_digits(BGP.startdate) || !is_digits(BGP.enddate)) { cout << "The date format is YYYYMMDD and should be all integers\n"; exit(1); } if (BGP.startdate > BGP.enddate) { cout << "Start date must come before end date.\n"; print_help(); exit(1); } Traverse(BGP,BGP.startdate,outFile); if (BGP.enddate.compare(BGP.startdate) == 0) { exit(1); } string nextdate = NextDate(BGP.startdate); while (nextdate.compare(BGP.enddate) != 0) { Traverse(BGP,nextdate,outFile); nextdate = NextDate(nextdate); } Traverse(BGP,BGP.enddate,outFile); if (!BGP.outfile.empty()) { outFile.close(); } }
/******************************************************************************* Function name: InitImageDump() Purpose : Initialize the image dumps. This information is in the [OUTPUT] section of the input file Required : LISTPTR Input - Linked list with input strings int Dt - Model timestep in seconds MAPSIZE *MapDump - Information about areal extent int MaxSoilLayers - Maximum number of soil layers int MaxVegLayers - Maximum number of vegetation layers char *Path - Directory to write output to int NMaps - Number of maps to dump int NImages - Number of images to dump MAPDUMP **DMap - Array of maps and images to dump Returns : void Modifies : Members of DMap Comments : InitImageDump must be preceded by a call to InitMapDump, since the necessary memory is allocated there *******************************************************************************/ void InitImageDump(LISTPTR Input, int Dt, MAPSIZE * Map, int MaxSoilLayers, int MaxVegLayers, char *Path, int NMaps, int NImages, MAPDUMP ** DMap) { char *Routine = "InitImageDump"; DATE End; /* End of low resolution map dump period */ DATE Start; /* Start of low resolution map dump period */ int i; /* counter */ int j; /* counter */ int Interval; /* Interval between low resolution map dumps */ int MaxLayers; /* Maximum number of layers allowed for this variable */ char KeyName[image_lower + 1][BUFSIZE + 1]; char *KeyStr[] = { "IMAGE VARIABLE", "IMAGE LAYER", "IMAGE START", "IMAGE END", "IMAGE INTERVAL", "IMAGE UPPER LIMIT", "IMAGE LOWER LIMIT" }; char *SectionName = "OUTPUT"; char VarStr[image_lower + 1][BUFSIZE + 1]; float tmpInterval; for (i = NMaps - NImages; i < NMaps; i++) { /* Read the key-entry pairs from the input file */ for (j = 0; j <= image_lower; j++) { sprintf(KeyName[j], "%s %d", KeyStr[j], i - (NMaps - NImages) + 1); GetInitString(SectionName, KeyName[j], "", VarStr[j], (unsigned long)BUFSIZE, Input); } /* Assign the entries to the appropriate variables */ if (!CopyInt(&((*DMap)[i].ID), VarStr[image_variable], 1)) ReportError(KeyName[image_variable], 51); if (!IsValidID((*DMap)[i].ID)) ReportError("Input Options File", 19); if (IsMultiLayer((*DMap)[i].ID)) { MaxLayers = GetVarNLayers((*DMap)[i].ID, MaxSoilLayers, MaxVegLayers); if (!CopyInt(&((*DMap)[i].Layer), VarStr[image_layer], 1)) ReportError(KeyName[image_layer], 51); if ((*DMap)[i].Layer < 1 || (*DMap)[i].Layer > MaxLayers) ReportError("Input Options File", 20); } else (*DMap)[i].Layer = 1; (*DMap)[i].Resolution = IMAGE_OUTPUT; strncpy((*DMap)[i].FileName, Path, BUFSIZE); GetVarAttr(&((*DMap)[i])); (*DMap)[i].NumberType = NC_BYTE; strcpy((*DMap)[i].Format, "%d"); CreateMapFile((*DMap)[i].FileName, (*DMap)[i].FileLabel, Map); if (!SScanDate(VarStr[image_start], &Start)) ReportError(KeyName[image_start], 51); if (!SScanDate(VarStr[image_end], &End)) ReportError(KeyName[image_end], 51); if (!CopyFloat(&tmpInterval, VarStr[image_interval], 1)) ReportError(KeyName[image_interval], 51); Interval = SECPHOUR * tmpInterval; if (Interval % Dt != 0 || Interval <= 0) ReportError("Input Options File", 24); if (((*DMap)[i].N = NumberOfSteps(&Start, &End, Interval)) < 1) ReportError("Input Options File", 25); if (!((*DMap)[i].DumpDate = (DATE *)calloc((*DMap)[i].N, sizeof(DATE)))) ReportError(Routine, 1); CopyDate(&((*DMap)[i].DumpDate[0]), &Start); for (j = 1; j < (*DMap)[i].N; j++) (*DMap)[i].DumpDate[j] = NextDate(&((*DMap)[i].DumpDate[j - 1]), Interval); if (!CopyFloat(&((*DMap)[i].MaxVal), VarStr[image_upper], 1)) ReportError(KeyName[image_upper], 51); if (!CopyFloat(&((*DMap)[i].MinVal), VarStr[image_lower], 1)) ReportError(KeyName[image_lower], 51); } }