int main() { char str[MAXLINE]; double num; mgetline(str,MAXLINE); num = myatof(str); printf("%f",num); getchar(); return 0; }
/***************************************************** ** ** WesternCalculationPanel --- saveData ** ******************************************************/ bool WesternCalculationPanel::saveData() { config->wHouseSystem = choice_whouse->GetSelection() + 1; config->wLunarNodeMode = choice_wnode->GetSelection(); config->wAyanamsa = choice_waya->getConfigIndex(); config->wYearLength = choice_yl->GetSelection(); config->wCustomYearLength = myatof( text_custom_yl->GetValue() ); if ( config->wCustomYearLength < 0 ) config->wCustomYearLength = WCUSTOM_YEAR_LEN; return true; }
void CWaypoints::ReadWPT(const wchar_t * wcFilename) { char buff[1000]; FILE * pFile = wfopen(wcFilename, L"rt"); if (pFile) { std::vector<long> vRecord; for (int i = 0; i < 4; ++i) { if (!fgets(buff, sizeof(buff), pFile)) break; } std::vector<std::string> listParts; while(fgets(buff, sizeof(buff), pFile)) { std::string strCommand = buff; listParts.resize(0); std::string::size_type pos = 0; std::string::size_type nextpos = 0; while ((nextpos = strCommand.find(',', pos)) != std::string::npos) { listParts.push_back(strCommand.substr(pos, nextpos - pos)); pos = nextpos + 1; } listParts.push_back(strCommand.substr(pos)); if (listParts.size() >= 15) { double dLatitude = myatof(listParts[2].c_str()); double dLongitude = myatof(listParts[3].c_str()); wchar_t buff[1000] = {0}; MultiByteToWideChar(CP_ACP, 0, listParts[1].c_str(), -1, buff, 1000); int iRadius = atoi(listParts[13].c_str()); int iAltitude = atoi(listParts[14].c_str()); AddPoint(CPoint(dLongitude, dLatitude, iAltitude, buff), iRadius); } } } m_bCanWrite = true; }
/***************************************************** ** ** VargaPanel --- saveData ** ******************************************************/ bool VargaPanel::saveData() { // Left config->tempFriendBasedOnVarga = choice_tempfriend->GetSelection() > 0; config->vVargaHoraMode = choice_hora->GetSelection(); config->vVargaDrekkanaMode = choice_drekkana->GetSelection(); config->vVargaChaturtamsaMode = choice_chaturtamsa->GetSelection(); // Right config->vNakshatraMode28 = choice_naks->GetSelection(); config->vNakshatraPortionMode = choice_nakdasa->GetSelection(); config->vKalachakraMode = choice_kala->GetSelection(); config->vYearLength = choice_yl->GetSelection(); config->vCustomYearLength = myatof( text_custom_yl->GetValue() ); if ( config->vCustomYearLength < 0 ) config->vCustomYearLength = ICUSTOM_YEAR_LEN; return true; }
/* * Callback function to update the graphic layer with temperature history. */ static void layer_graph_update_callback(Layer *layer, GContext *ctx) { GRect bounds = layer_get_bounds(layer); int height = bounds.size.h - 10; int width = bounds.size.w - 10; graphics_draw_line(ctx, GPoint(2, 2), GPoint(2, height +8)); graphics_draw_line(ctx, GPoint(2, 2), GPoint(width + 8, 2)); graphics_draw_line(ctx, GPoint(2, height + 8), GPoint(width + 8, height + 8)); graphics_draw_line(ctx, GPoint(width + 8, 2), GPoint(width + 8, height + 8)); char number[10]; int len = strlen(msg); for (int i = 0, k = 0, j = 0; i < len; i++) { if (msg[i] != ',') number[k++] = msg[i]; else { number[k] = '\0'; numbers[j++] = myatof(number); k = 0; } } double min = 1000, max = -1000; for (int i = 0; i < 10; i++) { if (numbers[i] < min) min = numbers[i]; if (numbers[i] > max) max = numbers[i]; } double range = max - min; GPoint points[10]; for (int i = 0; i < 10; i++) { points[i] = GPoint(7 + width / 9 * i, 5 + (max - numbers[i]) / range * height); graphics_fill_circle(ctx, points[i], 3); if (i > 0) { graphics_context_set_stroke_color(ctx, GColorBlack); graphics_draw_line(ctx, points[i - 1], points[i]); } } graphics_context_set_stroke_color(ctx, GColorBlack); }
/***************************************************** ** ** IntegerInputField --- getDoubleValue ** ******************************************************/ double IntegerInputField::getDoubleValue() { value = (int)myatof( GetValue() ); return value; }
/***************************************************** ** ** DoubleInputField --- getDoubleValue ** ******************************************************/ double DoubleInputField::getDoubleValue() { value = myatof( GetValue() ); return value; }
int ProcNKeys(TxtNode *t,int& foundkeys) { if (t->child) { TxtNode *sib=t->child; if (!sib->text) return 207; int tp=myatoi(sib->text,sib->length); sib=sib->sibling; if (!sib||!sib->text) return 208; int num=myatoi(sib->text,sib->length); sib=sib->sibling; int i; int lastframe=startframe-1; TxtNode *s=sib; for (i=0;i<num;i++) { if (!s||!s->text) return 110; int frame=myatoi(s->text,s->length); if (frame>33000) frame=frame-65536; if (frame<startframe) { assert(!i); lastframe=frame-1; startframe=frame; } if (frame>endframe) endframe=frame; if (frame-startframe>maxmatframe) maxmatframe=frame-startframe; s=s->sibling; if (!s||!s->text) return 212; int junk=myatoi(s->text,s->length); if (junk!=3) return 213; s=s->sibling; if (!s||!s->text) return 216; float x=(float)myatof(s->text,s->length); s=s->sibling; if (!s||!s->text) return 216; float y=(float)myatof(s->text,s->length); s=s->sibling; if (!s||!s->text) return 216; float z=(float)myatof(s->text,s->length); s=s->sibling; int k; if (tp==1) //scale { Vect3 v=Vect3(x,z,y); for (k=lastframe+1;k<=frame;k++) scales[k-startframe]=v; foundkeys|=4; } else if (tp==2) //translation { Vect3 v(x,-z,y); for (k=lastframe+1;k<=frame;k++) { mats[k-startframe].SetRow(3,v); mats[k-startframe].CalcFlags(); } foundkeys|=1; } else if (tp==3) //rotation { Matrix4 tmp; tmp.Rotate(-x*M_PI/180.0f,-y*M_PI/180.0f,-z*M_PI/180.0f); Vect3 t,tt; tmp.GetRow(2,t); t*=-1.0f; tmp.GetRow(1,tt); tmp.SetRow(2,tt); tmp.SetRow(1,t); for (k=0;k<3;k++) { float tt=-tmp[k][2]; tmp[k][2]=tmp[k][1]; tmp[k][1]=tt; } for (k=lastframe+1;k<=frame;k++) { int l; for (l=0;l<3;l++) { tmp.GetRow(l,t); mats[k-startframe].SetRow(l,t); mats[k-startframe].CalcFlags(); } } foundkeys|=2; } lastframe=frame; } } return 0; }
int FindNodes(SceneNodes *parent,TxtNode *t) { static char tmp[1000]; if (t->child) { TxtNode *sib=t->child; while (sib) { if (sib->text&&!mystrncmp("Frame",sib->text,sib->length)) { SceneNodes tmpNode; Matrix4 tm,tmBase; tm.Identity(); sib=sib->sibling; if (!sib) return 1; assert(sib->length<100); if (!strncmp("frm-",sib->text,4)) mystrncpy(tmpNode.name,sib->text+4,sib->length-4); else mystrncpy(tmpNode.name,sib->text,sib->length); sib=sib->sibling; if (!sib) return 2; { TxtNode *FrameLook=sib; TxtNode *sub=sib->child; if (!sub) return 3; if (!sub->text) return 4; if (mystrncmp("FrameTransformMatrix",sub->text,sub->length)) return 5; sub=sub->sibling; { TxtNode *xf=sub->child; int r,c; #if 0 OutputDebugString("matrix\n"); #endif for (r=0;r<4;r++) { int rr=r; float sign=1.0f; if (r==1) rr=2; if (r==2) { sign=-1.0f; rr=1; } for (c=0;c<4;c++) { if (!xf||!xf->text) return 6; if (c==0) tm[rr][0]=sign*(float)myatof(xf->text,xf->length); else if (c==1) tm[rr][2]=sign*(float)myatof(xf->text,xf->length); else if (c==2) tm[rr][1]=-sign*(float)myatof(xf->text,xf->length); xf=xf->sibling; } } #if 0 for (r=0;r<4;r++) { sprintf(tmp,"%6f %6f %6f\n",tm[r][0],tm[r][1],tm[r][2]); OutputDebugString(tmp); } #endif tm.CalcFlags(); } tmBase=tm; sub=sub->sibling; while (sub) { if (sub->text&&!mystrncmp("SI_FrameBasePoseMatrix",sub->text,sub->length)) { sub=sub->sibling; { TxtNode *xf=sub->child; int r,c; #if 0 OutputDebugString("pose matrix\n"); #endif for (r=0;r<4;r++) { int rr=r; float sign=1.0f; if (r==1) rr=2; if (r==2) { sign=-1.0f; rr=1; } for (c=0;c<4;c++) { if (!xf||!xf->text) return 6; if (c==0) tmBase[rr][0]=sign*(float)myatof(xf->text,xf->length); else if (c==1) tmBase[rr][2]=sign*(float)myatof(xf->text,xf->length); else if (c==2) tmBase[rr][1]=-sign*(float)myatof(xf->text,xf->length); xf=xf->sibling; } } tmBase.CalcFlags(); #if 0 for (r=0;r<4;r++) { sprintf(tmp,"%6f %6f %6f\n",tmBase[r][0],tmBase[r][1],tmBase[r][2]); OutputDebugString(tmp); } #endif } } sub=sub->sibling; } tmpNode.parent=parent; tmpNode.mat=tm; Matrix4 par,tmat; if (parent) tmat.Concat(tmBase,parent->BaseMat); else tmat=tmBase; tmpNode.BaseMat=tmat; SceneNodes *newparent=sNodes+nsNodes; tmpNode.animat=0; tmpNode.nanimat=0; sNodes[nsNodes++]=tmpNode; int err=FindNodes(newparent,FrameLook); if (err) return err; } } sib=sib->sibling; } } return 0; }
main(int argc, char **argv) { SOCKET s; int l, retry; float data; char iobuf[1024], timestr[32], datachar[7]; char* pos; time_t cur_time; progname = argv[0]; if(argc < 2 || strcmp(argv[1],"--help") == 0) { print_help(); exit(3); } time(&cur_time); sprintf(timestr, "%s", ctime(&cur_time)); for(retry = 0; retry < 3; retry++){ /* make connection to websensor */ s = connectWebsensor(argv[1], DEFAULTPORT); if(NetErrNo() != 0){ #ifdef DEBUG fprintf(stderr, "Could not connect to Websensor because %s, will retry %d more times.\n", NetErrStr(), 3-retry); #endif shutdown(s, SHUT_RDWR); continue; } /* send HTTP GET request to obtain data */ if(argc>2){ switch (toupper(argv[2][0])){ case 'R': write(s, "GET /index.html?eR HTTP/1.1\r\nUser-Agent: EsensorsPlugin\r\nHost: localhost\r\n\r\n", 76); break; case 'V': write(s, "GET /index.html?ev HTTP/1.1\r\nUser-Agent: EsensorsPlugin\r\nHost: localhost\r\n\r\n", 76); break; default: write(s, "GET /index.html?em123456 HTTP/1.1\r\nUser-Agent: EsensorsPlugin\r\nHost: localhost\r\n\r\n", 82); break; } } else{ // Not enough arguments from command line. Use default websensor command. write(s, "GET /index.html?em123456 HTTP/1.1\r\nUser-Agent: EsensorsPlugin\r\nHost: localhost\r\n\r\n", 82); } l = read(s, iobuf, sizeof(iobuf)); /* No data returned from websensor. Will retry again. */ if(l<=0){ #ifdef DEBUG fprintf(stderr, "No Data Read, will retry %d more times.\n", 3-retry); #endif shutdown(s, SHUT_RDWR); continue; } /* pos = strstr(iobuf, "01T"); printf("POS: %d\n", pos-iobuf); */ pos = &iobuf[165]; /* Unsupported command. Exit */ if(pos[0] == '#'){ printf("Invalid Command. Option %c selected may not be available for this websensor.\n", argv[2][0]); return 3; } /* The http data is not properly formatted. */ if(pos[2] != 'T' && pos[2] != 'R' && pos[1] != 'v'){ #ifdef DEBUG fprintf(stderr, "Data input incorrect, will retry %d more times.\n", 3-retry); #endif shutdown(s, SHUT_RDWR); continue; } else{ break; /* All data looks good. Break out of loop. */ } } /* Retried 3 times earlier and still no good data. Time to exit */ if(retry == 3){ printf("NO DATA\n"); return 3; } if(argc > 2){ switch(toupper(argv[2][0])){ case 'T': { strncpy(datachar, pos+5, 5); datachar[5] = '\0'; data = myatof(datachar); data += 0.01; if(argc != 7){ printf("(No limits specified) Temperature: %s %c\n", datachar, pos[3]); return(0); } if(data < myatof(argv[5]) || data > myatof(argv[6])){ printf("CRITICAL ( %s< or >%s ) Temperature: %s %c\n", argv[5], argv[6], datachar, pos[3]); return(2); } else if(data < myatof(argv[3]) || data > myatof(argv[4])){ printf("WARNING ( %s< or >%s ) Temperature: %s %c\n", argv[3], argv[4], datachar, pos[3]); return(1); } else{ printf("OK Temperature: %s %c\n", datachar, pos[3]); return(0); } } break; case 'H': { strncpy(datachar, pos+13, 4); datachar[4] = '\0'; data = myatof(datachar); data += 0.01; if(argc != 7){ printf("(No limits specified) %s%\n", datachar); return(0); } if(data < myatof(argv[5]) || data > myatof(argv[6])){ printf("CRITICAL ( %s< or >%s ) Humidity: %s%\n", argv[5], argv[6], datachar); return(2); } else if(data < myatof(argv[3]) || data > myatof(argv[4])){ printf("WARNING ( %s< or >%s ) Humidity: %s%\n", argv[3], argv[4], datachar); return(1); } else{ printf("OK Humidity: %s%\n", datachar); return(0); } } break; case 'I': { strncpy(datachar, pos+21, 5); datachar[5] = '\0'; data = myatof(datachar); data += 0.01; if(argc != 7){ printf("(No limits specified) Illumination: %s\n", datachar); return(0); } if(data < myatof(argv[5]) || data > myatof(argv[6])){ printf("CRITICAL ( %s< or >%s ) Illumination: %s%\n", argv[5], argv[6], datachar); return(2); } else if(data < myatof(argv[3]) || data > myatof(argv[4])){ printf("WARNING ( %s< or >%s ) Illumination: %s%\n", argv[3], argv[4], datachar); return(1); } else{ printf("OK Illumination: %s\n", datachar); return(0); } } break; case 'C': { if(iobuf[160] == 'W'){ printf("OK Contacts Close.\n"); return(0); } else if(iobuf[160] == 'N'){ printf("CRITICAL Contacts Open!\n"); return(2); } else{ printf("WARNING Unknown status. Try Reset Device.\n"); return(1); } } break; case 'R': { strncpy(datachar, pos+4, 6); datachar[6] = '\0'; data = myatof(datachar); data += 0.01; if(argc != 7){ printf("(No limits specified) RTD Temperature: %s %c\n", datachar, pos[3]); return(0); } if(data < myatof(argv[5]) || data > myatof(argv[6])){ printf("CRITICAL ( %s< or >%s ) RTD Temperature: %s %c\n", argv[5], argv[6], datachar, pos[3]); return(2); } else if(data < myatof(argv[3]) || data > myatof(argv[4])){ printf("WARNING ( %s< or >%s ) RTD Temperature: %s %c\n", argv[3], argv[4], datachar, pos[3]); return(1); } else{ printf("OK RTD Temperature: %s %c\n", datachar, pos[3]); return(0); } } break; case 'V': { strncpy(datachar, pos+22, 5); datachar[5] = '\0'; data = myatof(datachar); data += 0.01; if(argc != 7){ printf("(No limits specified) Voltage: %s V\n", datachar); return(0); } if(data < myatof(argv[5]) || data > myatof(argv[6])){ printf("CRITICAL ( %s< or >%s ) Voltage: %s V\n", argv[5], argv[6], datachar); return(2); } else if(data < myatof(argv[3]) || data > myatof(argv[4])){ printf("WARNING ( %s< or >%s ) Voltage: %s V\n", argv[3], argv[4], datachar); return(1); } else{ printf("OK Voltage: %s V\n", datachar); return(0); } } default : printf("Please choose only 'T', 'H', 'I', 'R', 'V' or 'C'.\n Please refer to README for further instructions.\n"); break; } } else{ iobuf[195] = 0; printf("%s\t%s", pos+2, timestr); } return 0; }