int main () { int rc; int s; struct sp_thread thread; /* Close the socket with no associated endpoints. */ rc = sp_init (); errno_assert (rc == 0); s = sp_socket (AF_SP, SP_PAIR); errno_assert (s != -1); rc = sp_close (s); errno_assert (rc == 0); rc = sp_term (); errno_assert (rc == 0); /* Test sp_term() before sp_close(). */ rc = sp_init (); errno_assert (rc == 0); sp_thread_init (&thread, worker, NULL); sp_sleep (10); rc = sp_term (); errno_assert (rc == 0); sp_thread_term (&thread); return 0; }
/* rudimentary check for memory leaks */ static void stress_test() { struct sorted_points *sp; struct point dummy; static const int NINSERT = 1024; static const int NITER = 20 * 1024; int ii; int jj; int ret; sp = sp_init(); printf("this test may take a minute.\n"); for (ii = 0; ii < NITER; ii++) { for (jj = 0; jj < NINSERT; jj++) { sp_add_point(sp, (double)(NINSERT - jj), 1.0); } ret = sp_remove_by_index(sp, NINSERT, &dummy); assert(0 == ret); ret = sp_remove_by_index(sp, NINSERT - 1, &dummy); assert(1 == ret); for (jj = 0; jj < NINSERT - 1; jj++) { ret = sp_remove_first(sp, &dummy); assert(1 == ret); } ret = sp_remove_first(sp, &dummy); assert(0 == ret); } sp_destroy(sp); }
spkey_t symbol(const void *s) { if (spt_symtab == NULL) spt_symtab = sp_init(); return symbol_db(s, spt_symtab); }
sp_t *sp_create(void *user_data) { sp_t *sp = sp_init(); sp->user_data = user_data; return sp; }
/* * returns 1 if SUCCESS, -1 if error * sp_username: specifies the username in SecurePass format, i.e. user@realm * pwd: password to set */ int sp_user_password_change (const char *sp_username, const char* pwd) { int len; jsmntok_t *tok; struct MemoryStruct chunk; /* debug (4, "==> sp_user_password_change sp_username=%s pwd=%s", sp_username, pwd); */ debug (4, "==> sp_user_password_change sp_username=%s", sp_username); if ((sp_config.status != SP_INITED)) { if (!(sp_init ())) return -1; } if (sp_username == NULL) { error ("sp_user_password_change() called with username=NULL"); return -1; } if (pwd == NULL) { error ("sp_user_password_change() called with password=NULL"); return -1; } /* call curl */ char post_data[(strlen ("USERNAME="******"PASSWORD") + strlen (pwd) + 2)]; sprintf (post_data, "USERNAME=%s&PASSWORD=%s", sp_username, pwd); len = do_curl(sp_config.URL_u_pwd_chg, post_data, &tok, (struct MemoryStruct *) &chunk); if (len == -1) { return -1; } /* check for value of rc token */ if (!(rc_ok (chunk.memory, tok, len))) { free (tok); free (chunk.memory); return -1; } return 1; }
enum plugin_status plugin_start(const void* parameter) { #if LCD_DEPTH > 1 rb->lcd_set_backdrop(NULL); #endif rb->splash(HZ, "Welcome to ZXBox"); sp_init(); #ifdef USE_GREY /* get the remainder of the plugin buffer */ gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size); #ifdef USE_BUFFERED_GREY grey_init(gbuf, gbuf_size, GREY_BUFFERED|GREY_ON_COP, LCD_WIDTH, LCD_HEIGHT, NULL); #else grey_init(gbuf, gbuf_size, GREY_ON_COP, LCD_WIDTH, LCD_HEIGHT, NULL); #endif /* USE_BUFFERED_GREY */ /* switch on greyscale overlay */ grey_show(true); #endif /* USE_GREY */ #if defined(HAVE_ADJUSTABLE_CPU_FREQ) rb->cpu_boost(true); #endif start_time = *rb->current_tick; #ifdef RB_PROFILE rb->profile_thread(); #endif start_spectemu(parameter); #ifdef RB_PROFILE rb->profstop(); #endif #if defined(HAVE_ADJUSTABLE_CPU_FREQ) rb->cpu_boost(false); #endif #ifdef USE_GREY grey_show(false); grey_release(); #endif #if CONFIG_CODEC == SWCODEC && !defined SIMULATOR rb->pcm_play_stop(); #endif return PLUGIN_OK; }
int sp_add_point(struct sorted_points *sp, double x, double y) { struct sorted_points *new_sp = sp_init(); assert(new_sp); new_sp->p = (struct point *)malloc(sizeof(struct point)); new_sp->p->x = x; new_sp->p->y = y; double distance = sqrt(x*x+y*y); new_sp->distance = distance; if(sp == NULL){ sp = new_sp; }else if(sp->p == NULL){ sp->p = (struct point *)malloc(sizeof(struct point)); free(new_sp->p); new_sp->p = NULL; free(new_sp); new_sp = NULL; sp->p->x = x; sp->p->y = y; sp->distance = distance; } else{ struct sorted_points *temp, *prev; temp = sp; prev = sp; if(temp->distance > distance || (distance == temp->distance && x < temp->p->x)){ //insert at the first new_sp->p->x = temp->p->x; new_sp->p->y = temp->p->y; new_sp->distance = temp->distance; new_sp->next = temp->next; //insert one after the first one temp->next = new_sp; temp->p->x = x; temp->p->y = y; temp->distance = distance; return 1; } int i = 0; while(temp != NULL && temp->distance <= distance ){ i++; if(temp->distance == distance){ if(x < temp->p->x) break; else if(x == temp->p->x && y < temp->p->y) break; } prev = temp; temp = temp->next; } new_sp->next = temp; prev->next = new_sp; } return 1; }
/* * returns 1 if SUCCESS, -1 if error * sp_username: specifies the username in Posix format, i.e. user * secret: made up of concatenation of OTP and password */ int sp_user_auth_p (const char *username, const char* secret) { if ((sp_config.status != SP_INITED)) { if (!(sp_init ())) return -1; } if (username == NULL) { error ("sp_user_auth_p() called with username=NULL"); return -1; } /* concatenate realm to name */ char sp_name[(strlen (username) + strlen (sp_config.realm) + 2)]; sprintf (sp_name, "%s%s%s", username, "@", sp_config.realm); return sp_user_auth (sp_name, secret); }
/* * returns 1 if SUCCESS, -1 if error * sp_username: specifies the username in SecurePass format, i.e. user@realm * secret: concatenation of OTP and password */ int sp_user_auth (const char *sp_username, const char* secret) { int len; jsmntok_t *tok; struct MemoryStruct chunk; /* debug (4, "==> sp_user_auth, sp_username=%s secret=%s", sp_username, secret); */ debug (4, "==> sp_user_auth, sp_username=%s", sp_username); if ((sp_config.status != SP_INITED)) { if (!(sp_init ())) return -1; } if (sp_username == NULL) { error ("sp_user_auth() called with username=NULL"); return -1; } if (secret == NULL) { error ("sp_user_auth() called with secret=NULL"); return -1; } /* call curl */ char post_data[(strlen ("USERNAME="******"SECRET") + strlen (secret) + 2)]; sprintf (post_data, "USERNAME=%s&SECRET=%s", sp_username, secret); len = do_curl(sp_config.URL_u_auth, post_data, &tok, (struct MemoryStruct *) &chunk); if (len == -1) { return -1; } /* check for value of rc token */ if (!(rc_ok (chunk.memory, tok, len))) { free (tok); free (chunk.memory); return -1; } int r = get_tok (chunk.memory, tok, len, "authenticated"); if (r == -1) { debug (1, "token 'authenticated' not found in JSON response"); } else { if (TOK_CMP (chunk.memory, tok[r], "true") == 0) { debug (1, "token 'authenticated' has wrong value, expected true"); /* set error */ r = -1; } } if (r == -1) { free (tok); free (chunk.memory); return -1; } return 1; }
int main(int argc, char *argv[]) { spma_init_privileged(); sp_init_vga(); spcf_pre_check_options(argc, argv); check_params(argc, argv); sp_init(); start_spectemu(); /* This function DOES NOT return */ return 0; }
int main(void) { sp_init(); settings_init(); plan_init(); st_init(); spindle_init(); gc_init(); for (;;) { sleep_mode(); // Wait for it ... sp_process(); // ... process the serial protocol } return 0; /* never reached */ }
/*! SPI FLASH test !*/ void sf_test(void) { uint8_t datas[6502]; int kd; int flag; int i; kb_init(); sp_init(); sp_puts("SPI FLASH Test\r\n"); sf_init(); for(i = 0; i < 6502; i++) datas[i] = i; for(;;) { kb_scan(); kd = kb_get(KB_DOWN); if(kd & KEY_0) { sp_puts("SPI FLASH write datas ... "); sf_write(0x8051, datas, 6502); sp_puts("OK\r\n"); } if(kd & KEY_1) { for(i = 0; i < 6502; i++) datas[i] = 0; sp_puts("SPI FLASH read datas ... "); sf_read(0x8051, datas, 6502); sp_puts("OK\r\n"); sp_puts("SPI FLASH verify datas ... "); flag = 0; for(i = 0; i < 6502; i++) { if(datas[i] != i) { flag = 1; break; } } if(flag == 0) sp_puts("SUCCESS\r\n"); else sp_puts("FAILED\r\n"); } } }
static struct sorted_points * alloc_random_list(int num) { struct sorted_points *sp = sp_init(); int i; int ret; assert(sp); for (i = 0; i < num; i++) { ret = sp_add_point(sp, (double)(rand() % 10), (double)(rand() % 10)); assert(ret); } return sp; }
/* * returns 1 if SUCCESS, -1 if error * xattrs: pointer to a sp_xattrs_t that will be allocated by this function * caller will free() the structure after use * username: specifies the username in Posix format, i.e. user */ int sp_xattrs_p (sp_xattrs_t **xattrs, const char *username, int get_defaults) { if ((sp_config.status != SP_INITED)) { if (!(sp_init ())) return -1; } if (username == NULL) { error ("sp_xattrs_p() called with username=NULL"); return -1; } /* concatenate realm to name */ char sp_name[(strlen (username) + strlen (sp_config.realm) + 2)]; sprintf (sp_name, "%s%s%s", username, "@", sp_config.realm); int rc = sp_xattrs (xattrs, sp_name, get_defaults); return rc; }
int main(void) { // There are a lot of dependencies in the order of these inits. // Don't change the ordering unless you understand this. // Inits can assume that all memory has been zeroed by either // a hardware reset or a watchdog timer reset. cli(); // system and drivers sys_init(); // system hardware setup - must be first rtc_init(); // real time counter xio_init(); // xmega io subsystem sig_init(); // signal flags st_init(); // stepper subsystem - must precede gpio_init() gpio_init(); // switches and parallel IO pwm_init(); // pulse width modulation drivers - must follow gpio_init() // application structures tg_init(STD_INPUT); // tinyg controller (controller.c) - must be first app init; reqs xio_init() cfg_init(); // config records from eeprom - must be next app init mp_init(); // motion planning subsystem cm_init(); // canonical machine - must follow cfg_init() sp_init(); // spindle PWM and variables // now bring up the interupts and get started PMIC_SetVectorLocationToApplication(); // as opposed to boot ROM PMIC_EnableHighLevel(); // all levels are used, so don't bother to abstract them PMIC_EnableMediumLevel(); PMIC_EnableLowLevel(); sei(); // enable global interrupts rpt_print_system_ready_message();// (LAST) announce system is ready _unit_tests(); // run any unit tests that are enabled tg_canned_startup(); // run any pre-loaded commands while (true) { // if (tg.network == NET_MASTER) { // tg_repeater(); // } else if (tg.network == NET_SLAVE) { // tg_receiver(); // } else { tg_controller(); // NET_STANDALONE // } } }
/** * SACT.Init (1.0~) * SACT全体の初期化 */ void Init() { int p1 = getCaliValue(); /* ISys3x */ // ゲームタイトルによるバージョン設定 if (0 == strcmp(nact->game_title_name, GT_ESUKA)) { sact.version = 100; } else if (0 == strcmp(nact->game_title_name, GT_RANCE5D)){ sact.version = 110; } else { sact.version = 120; } NOTICE("SACT version = %d\n", sact.version); // 初期座標原点 sact.origin.x = 0; sact.origin.y = 0; // 各サブシステム初期化 sp_init(); sstr_init(); ssel_init(); stimer_init(); ssnd_init(); if (nact->files.sact01) { smask_init(nact->files.sact01); } // create depth map sact.dmap = sf_create_pixel(sf0->width, sf0->height, 16); // その他 System35 のデフォルト動作の変更 nact->ags.font->antialiase_on = TRUE; sys_setHankakuMode(2); // 全角半角変換無し ags_autorepeat(FALSE); // key auto repeat off if (sact.version >= 120) { sact.logging = TRUE; } else { sact.logging = FALSE; } DEBUG_COMMAND("SACT.Init %d:\n", p1); }
int main() { _delay_ms(100); gc_init(); sp_init(); i2c_init(); as_init(); motor_init(); boom_init(); analog_init(); sei(); printPgmString(PSTR("Shuttleboom!\n\r")); for(;;){sp_process(); sleep_mode();} return(0); }
/* * Rudimentary check for memory leaks */ static void stressTest() { SortedPoints *sp; Point dummy; static const int NINSERT = 1024; static const int NITER = 20*1024; static const int SIZE = 10; int ii; int jj; int ret; char *before, *after; sp = (SortedPoints*)malloc(sizeof(SortedPoints)); assert(sp); sp_init(sp); before = (char *)malloc(1); printf("This test may take a minute.\n"); printf("Before: %p\n", before); for(ii = 0; ii < NITER; ii++){ for(jj = 0; jj < NINSERT; jj++){ sp_addNewPoint(sp, (double)(NINSERT - jj), 1.0); } ret = sp_removeIndex(sp, SIZE, &dummy); assert(0 == ret); ret = sp_removeIndex(sp, SIZE - 1, &dummy); assert(1 == ret); for(jj = 0; jj < SIZE - 1; jj++){ ret = sp_removeFirst(sp, &dummy); assert (1 == ret); } ret = sp_removeFirst(sp, &dummy); assert(0 == ret); } after = (char *)malloc(1); printf("After: %p\n", after); printf("Difference: %p\n", (void *)((long)after - (long)before)); assert(after - before < 1024 * 1024); }
static void op_roots() { int i; struct polynom pol,roots; char expr[LLENGTH]; char x[LLENGTH], *osa[2]; i=sp_init(r1+r-1); if (i<0) return; i=spfind("MAX_ITER"); if (i>=0) { strcpy(x,spb[i]); i=split(x,osa,2); roots_max_iter=atoi(osa[0]); if (i>1) roots_eps=atof(osa[1]); } i=muste_pol_load(q,&pol); if (i<0) return; //printf("2"); pol_roots(&roots,&pol); sprintf(expr,"Roots_of_%s=0",q); muste_pol_save2(xx,&roots,"real imag ",1,expr); }
//************************************************************************************* int main(void) { beginSerial(BAUD_RATE); i2c_init(); // config_reset(); // This routine forces the eeprom config into its default state // if something really messes it up. Uncomment to use. config_init(); // Restore state from eeprom if it is there, else restore default. st_init(); // initialize the stepper subsystem mc_init(); // initialize motion control subsystem spindle_init(); // initialize spindle controller gc_init(); // initialize gcode-parser sp_init(); // initialize the serial protocol DDRD |= (1<<3)|(1<<4)|(1<<5); for(;;){ i2c_report_position(); _delay_ms(1); // Delay is required, otherwise // if mc_running and current_mode = SM_RUN then don't get buttons, else do if (!(mc_running==0 & (st_current_mode!=SM_RUN))){ i2c_get_buttons(); // i2c_get doesn't work. 1ms seems to be enough if (buttons[0]|buttons[1]|buttons[2]|buttons[3]){ mc_running=1; STEPPERS_ENABLE_PORT |= (1<<STEPPERS_ENABLE_BIT); ENABLE_STEPPER_DRIVER_INTERRUPT(); } } if (serialAvailable()) sp_process(); // process the serial protocol if (mc_in_arc()) mc_continue_arc(); // if busy drawing an arc, keep drawing } return 0; /* never reached */ }
/* * returns -1 if error, 0 if no users in realm, otherwise the number of users retrieved * user: pointer to an array containing pointers to returned users - it's allocated within this function * caller will free() the array after use * buflen: lenght in bytes of returned buffer * realm: specifies the realm; if NULL, the default realm will be used */ int sp_list_users (char ***user, const char *realm) { int len, i; char *r_ptr, **u_ptr, *u_str; jsmntok_t *tok; struct MemoryStruct chunk; if ((sp_config.status != SP_INITED)) { if (!(sp_init ())) return -1; } if (realm != NULL) r_ptr = (char *) realm; else r_ptr = sp_config.realm; char post_data[(strlen ("REALM=") + strlen (r_ptr) + 1)]; sprintf (post_data, "%s%s", "REALM=", r_ptr); len = do_curl(sp_config.URL_u_list, post_data, &tok, (struct MemoryStruct *) &chunk); if (len == -1) { return -1; } if (!(rc_ok (chunk.memory, tok, len))) { free (tok); free (chunk.memory); return -1; } /* * Get array from JSON response */ int idx = get_tok (chunk.memory, tok, len, "username"); if (idx == -1) { debug (1, "token \"username\" not found in JSON response"); free (tok); free (chunk.memory); return 0; } if (!(IS_ARRAY(tok[idx]))) { debug (1, "pair of token \"username\" in JSON response is not an array"); free (tok); free (chunk.memory); return 0; } len = tok[idx].size; idx++; /* * Allocate buffer to be returned and copy data to it. chunk.size is surely un upper bound to contain * the user list */ int ptrs_size = (len * sizeof (char *)); int buflen = ptrs_size + chunk.size; *user = (char **) malloc (buflen); if (!(*user)) { error ("malloc(%d) failed", buflen); free (tok); free (chunk.memory); return -1; } for (i = idx, u_ptr=(char **) *user, u_str=((char *) *user + ptrs_size); i < (idx + len); i++) { int l = tok[i].end - tok[i].start; memcpy (u_str, chunk.memory + tok[i].start, l); *(u_str + l) = 0; *u_ptr = u_str; u_str += l + 1; u_ptr++; } free (tok); free (chunk.memory); return len; }
static void basic_test() { int ret; struct sorted_points *sp1; struct sorted_points *sp2; struct point p1; srand(0); sp1 = sp_init(); sp2 = sp_init(); // empty list checks ret = sp_remove_by_index(sp1, 1, &p1); assert(!ret); ret = sp_remove_by_index(sp1, 0, &p1); assert(!ret); ret = sp_remove_by_index(sp1, -1, &p1); assert(!ret); ret = sp_remove_first(sp1, &p1); assert(!ret); ret = sp_remove_last(sp1, &p1); assert(!ret); ret = sp_add_point(sp1, 1.0, 1.0); assert(ret); ret = sp_add_point(sp1, 1.0, 1.0); assert(ret); ret = sp_add_point(sp1, 1.0, 1.0); assert(ret); ret = sp_add_point(sp2, 3.0, 1.0); assert(ret); ret = sp_add_point(sp2, 2.0, 1.0); assert(ret); ret = sp_add_point(sp2, 1.0, 1.0); assert(ret); ret = sp_add_point(sp1, 2.0, 2.0); assert(ret); ret = sp_add_point(sp1, 2.0, 2.0); assert(ret); ret = sp_add_point(sp1, 4.0, 3.0); assert(ret); ret = sp_add_point(sp1, 2.0, 2.0); assert(ret); ret = sp_remove_last(sp1, &p1); assert(ret); assert(point_X(&p1) == 4.0); assert(point_Y(&p1) == 3.0); ret = sp_remove_first(sp1, &p1); assert(ret); assert(point_X(&p1) == 1.0); assert(point_Y(&p1) == 1.0); ret = sp_remove_by_index(sp1, 2, &p1); assert(ret); assert(point_X(&p1) == 2.0); assert(point_Y(&p1) == 2.0); ret = sp_add_point(sp1, 2.0, 2.0); assert(ret); ret = sp_add_point(sp1, 2.0, 2.0); assert(ret); ret = sp_add_point(sp1, 2.0, 2.0); assert(ret); ret = sp_remove_first(sp1, &p1); assert(ret); assert(point_X(&p1) == 1.0); assert(point_Y(&p1) == 1.0); ret = sp_delete_duplicates(sp1); assert(ret == 4); ret = sp_remove_first(sp1, &p1); assert(ret); assert(point_X(&p1) == 1.0); assert(point_Y(&p1) == 1.0); ret = sp_remove_first(sp1, &p1); assert(ret); assert(point_X(&p1) == 2.0); assert(point_Y(&p1) == 2.0); ret = sp_remove_first(sp1, &p1); assert(!ret); ret = sp_delete_duplicates(sp2); assert(ret == 0); ret = sp_add_point(sp2, 5.0, 2.0); assert(ret); ret = sp_add_point(sp2, 6.0, 3.0); assert(ret); ret = sp_add_point(sp2, 7.0, 4.0); assert(ret); ret = sp_add_point(sp2, 0.0, 1.0); assert(ret); ret = sp_remove_by_index(sp2, 5, &p1); assert(ret); assert(point_X(&p1) == 6.0); assert(point_Y(&p1) == 3.0); ret = sp_remove_by_index(sp2, 5, &p1); assert(ret); assert(point_X(&p1) == 7.0); assert(point_Y(&p1) == 4.0); ret = sp_remove_by_index(sp2, 5, &p1); assert(!ret); ret = sp_remove_by_index(sp2, 0, &p1); assert(ret); assert(point_X(&p1) == 0.0); assert(point_Y(&p1) == 1.0); sp_destroy(sp1); sp_destroy(sp2); }
/* * returns 1 if SUCCESS, -1 if error * uinfo: pointer to a sp_user_info_t - will be allocated by this function * caller will free() the structure after use * username: specifies the username */ int sp_user_info (sp_user_info_t **uinfo, const char *sp_username) { int len; jsmntok_t *tok; struct MemoryStruct chunk; debug (4, "==> sp_user_info"); if ((sp_config.status != SP_INITED)) { if (!(sp_init ())) return -1; } if (sp_username == NULL) { error ("sp_user_info() called with username=NULL"); return -1; } char post_data[(strlen ("USERNAME="******"%s%s", "USERNAME="******"malloc() failed"); return -1; } cp_tok_t cp_tok; cp_tok.buflen = sizeof (sp_user_info_t) + chunk.size; cp_tok.buf = malloc (cp_tok.buflen); if (!(cp_tok.buf)) { error ("malloc() failed"); free (tok); free (chunk.memory); return -1; } cp_tok.offset = sizeof (sp_user_info_t); cp_tok.status = 0; /* status = OK */ while (1) { *uinfo = (sp_user_info_t *) cp_tok.buf; /* for each field into the structure, set the pointer and copy the returned value */ (*uinfo)->nin = cp_tok.buf + cp_tok.offset; copy_tok (chunk.memory, tok, len, &cp_tok, "nin", ""); (*uinfo)->name = cp_tok.buf + cp_tok.offset; copy_tok (chunk.memory, tok, len, &cp_tok, "name", ""); (*uinfo)->surname = cp_tok.buf + cp_tok.offset; copy_tok (chunk.memory, tok, len, &cp_tok, "surname", ""); (*uinfo)->mobile = cp_tok.buf + cp_tok.offset; copy_tok (chunk.memory, tok, len, &cp_tok, "mobile", ""); (*uinfo)->rfid = cp_tok.buf + cp_tok.offset; copy_tok (chunk.memory, tok, len, &cp_tok, "rfid", ""); (*uinfo)->enabled = cp_tok.buf + cp_tok.offset; copy_tok (chunk.memory, tok, len, &cp_tok, "enabled", ""); (*uinfo)->token = cp_tok.buf + cp_tok.offset; copy_tok (chunk.memory, tok, len, &cp_tok, "token", ""); (*uinfo)->manager = cp_tok.buf + cp_tok.offset; copy_tok (chunk.memory, tok, len, &cp_tok, "manager", ""); (*uinfo)->password = cp_tok.buf + cp_tok.offset; copy_tok (chunk.memory, tok, len, &cp_tok, "password", ""); (*uinfo)->email = cp_tok.buf + cp_tok.offset; copy_tok (chunk.memory, tok, len, &cp_tok, "email", ""); if (cp_tok.status == -1) { /* buffer is too small. Reallocate with size computed by copy_tok() in previous calls */ debug (1, "buffer is too small to hold output bytes, reallocating to %d bytes", cp_tok.offset); cp_tok.buflen = cp_tok.offset; cp_tok.offset = sizeof (sp_user_info_t); cp_tok.status = 0; if ((cp_tok.buf = realloc (cp_tok.buf, cp_tok.buflen)) == NULL ) { error ("realloc(%d) failed", cp_tok.buflen); free (tok); free (chunk.memory); return -1; } continue; } free (tok); free (chunk.memory); return 1; } return 1; /* should not be reached */ }
int muste_magic(char *argv) { int i,j,method,spec,offs,raja,magic; s_init(argv); if (g<3) { sur_print("\nUsage: MAGIC CREATE <dim>"); WAIT; return(1); } results_line=r1+r; i=sp_init(r1+r-1); if (i<0) return(-1); dim=atoi(word[2]); i=varaa_tilat(dim); if (i<0) return(-1); if (dim%2==0) { sur_print("\nCurrently only odd dimensions allowed!"); WAIT; return(-1); } method=1; // Default method for odd dimensions spec=1; offs=dim>>1; magic=0; i=spfind("METHOD"); if (i>=0) { method=atoi(spb[i]); } i=spfind("OFFSET"); if (i>=0) { offs=atoi(spb[i])-1; } if (offs<0 || offs>=(dim*dim)) { if (strcmp(spb[i],"ALL")==0) offs=-1; else { sprintf(sbuf,"\nERROR! OFFSET must be between 1 and %d!",dim*dim); sur_print(sbuf); WAIT; return(-1); } } raja=offs+1; if (offs<0) // ALL { raja=dim*dim; offs=0; } for (j=offs; j<raja; j++) { tyhjenna(dim); switch(method) { case 0: i=magic_random(dim); break; case 1: i=magic_staircase(dim); break; case 2: i=magic_pyramid(dim); break; case 3: i=magic_variation_staircase(dim); break; case 4: i=spfind("MOVE"); if (i>=0) { spec=atoi(spb[i]); } if (spec<1 || spec>8) { sur_print("\nERROR! Knight's move should be:"); sur_print("\n1 - 2 up, 1 right 5 - 2 down, 1 left"); sur_print("\n2 - 1 up, 2 right 6 - 1 down, 2 left"); sur_print("\n3 - 2 right, 1 down 7 - 2 left, 1 up"); sur_print("\n4 - 1 right, 2 down 8 - 1 left, 2 up"); sur_print("\nUse specification MOVE to define the move."); WAIT; return(-1); } i=magic_knights_move(dim,j,spec); break; default: break; } i=is_magic(dim); if (i<0) { if (method==0) print_square(dim); /* sprintf(sbuf,"Non magic! Offset=%d",j+1); print_line(); print_square(dim); if (i<99) sprintf(sbuf,"Wrong sum(s) in diagonal(s)!"); print_line(); if (i<9) sprintf(sbuf,"Wrong sum(s) in column(s)!"); print_line(); sprintf(sbuf,"Wrong sum(s) in row(s)!"); print_line(); */ } else { magic++; print_square_info(dim,j+1); print_square(dim); sprintf(sbuf," "); print_line(); } } if (magic<1) { sprintf(sbuf,"Non magic! "); print_line(); } s_end(argv); return(1); }
void muste_rndtest(char *argv) { int i; char xx[LLENGTH],*sana[4]; s_init(argv); if (g<3) { init_remarks(); rem_pr("Usage: RNDTEST <SURVO_data>,<variable>,<output_line>"); rem_pr("This Survo operation makes empirical statistical tests on a series"); rem_pr("numbers supposed to form a random sample from a uniform distribution"); rem_pr("in the interval (0,1)."); rem_pr("Most of these tests are explained in Volume 2 of \"The Art of Programming\""); rem_pr("by Donald E. Knuth."); rem_pr("The main application of RNDTEST is testing of various random number"); rem_pr("generators."); rem_pr(""); rem_pr("A standard set of tests is performed without any extra specification."); rem_pr("However, If RESULTS=0, no test is performed without explicit specifica-"); rem_pr("tions. To select tests in a more detailed form, following specifications"); rem_pr("can be given."); rem_pr(""); rem_pr("SUBSAMPLES=<size>,<# of classes>"); rem_pr("The sample is divided systematically in subsamples of given <size>"); rem_pr("and their uniformity is tested by the standard Chi^2-test by divi-"); rem_pr("ding the interval (0,1) in <# of classes>."); rem_pr("Also tests for mean=0.5 as well for the minimum ans maximum values"); rem_pr("in subsamples are made."); rem_pr("Default is SUBSAMPLES=0 (i.e. this test is omitted)."); wait_remarks(1); rem_pr(""); rem_pr("FREQUENCIES=<# of classes>,<lower limit>,<upper limit>"); rem_pr("The uniformity of the total sample is tested by the Chi^2-test."); rem_pr("Default: FREQUENCIES=10,0,1"); rem_pr(""); rem_pr("MAXLAG=<largest_lag>"); rem_pr("The autocorrelations of the series are computed up to the given"); rem_pr("maximum lag. Default: MAXLAG=10"); rem_pr(""); rem_pr("GAPTEST=<lower_limit>,<upper_limit>,<max.gap>"); rem_pr("The lengths of gaps between occurrences of values in the given range"); rem_pr("are computed."); rem_pr("Default: GAPTEST=0,0.5,10"); rem_pr(""); rem_pr("PERMTEST=<# of consecutive numbers (3,4,5,6 or 7)>"); rem_pr("Frequencies of different permutations of relative orderings are computed."); rem_pr("Default: PERMTEST=4"); rem_pr(""); rem_pr("POKER=<# of obs.>,<# of classes>,<lower limit>,<upper_limit>"); rem_pr("Default: POKER=5,5,0,1"); wait_remarks(1); rem_pr(""); rem_pr("COUPON=<# of classes>,<max_len>,<lower limit>,<upper limit>"); rem_pr("Coupon collector's test"); rem_pr("Default: COUPON=5,20,0,1"); rem_pr(""); rem_pr("Certain run tests are performed in any case."); wait_remarks(2); return; } p_mean=NULL; p_min=NULL; p_max=NULL; fr_f=NULL; lagv=NULL; lagvv=NULL; first_x=NULL; gap=NULL; f_perm=NULL; f_pok=NULL; s_pok=NULL; f1_pok=NULL; f_coup=NULL; coup_ind=NULL; s_coup=NULL; i=spec_init(r1+r-1); if (i<0) return; for(i=0; i<MAXRUN; ++i) runs_up[i]=runs_down[i]=0; n_sub=0; i=spfind("SUBSAMPLES"); if (i>=0) { strcpy(xx,spb[i]); i=split(xx,sana,2); if (i<1) { sur_print("\nUsage: SUBSAMPLES=<size>,<# of classes>"); WAIT; return; } n_sub=atoi(sana[0]); n_subclass=10; if (i>1) n_subclass=atoi(sana[1]); } if (results==0) fr_n=0; else { fr_n=10; fr_a=0.0; fr_d=0.1; } i=spfind("FREQUENCIES"); if (i>=0) { strcpy(xx,spb[i]); i=split(xx,sana,3); if (i<3) { sur_print("\nUsage: FREQUENCIES=<# of classes>,<lower_limit>,<upper_limit>"); WAIT; return; } fr_n=atoi(sana[0]); fr_a=atof(sana[1]); fr_d=(atof(sana[2])-fr_a)/(double)fr_n; } if (results==0) maxlag=0; else maxlag=10; i=spfind("MAXLAG"); if (i>=0) maxlag=atoi(spb[i]); if (results==0) maxgap=0; else { maxgap=10; a_gap=0; b_gap=0.5; } i=spfind("GAPTEST"); if (i>=0) { strcpy(xx,spb[i]); i=split(xx,sana,3); if (i<2) { sur_print("\nUsage: GAPTEST=<lower_limit>,<upper_limit>,<max.gap>"); WAIT; return; } a_gap=atof(sana[0]); b_gap=atof(sana[1]); maxgap=10; if (i>2) maxgap=atoi(sana[2]); } if (results==0) permlen=0; else permlen=4; i=spfind("PERMTEST"); if (i>=0) { permlen=atoi(spb[i]); if (permlen && (permlen<3 || permlen>7) ) { sur_print("\nOnly values 0 and 3,4,5,6,7 permitted in PERMTEST"); WAIT; return; } } if (results==0) poklen=0; else { poklen=5; n_pok=5; pok_a=0.0; pok_d=0.2; } i=spfind("POKER"); if (i>=0) { strcpy(xx,spb[i]); i=split(xx,sana,4); if (i<4) { sur_print("\nUsage: POKER=<# of obs.>,<# of classes>,<l.limit>,<u.limit>"); WAIT; return; } poklen=atoi(sana[0]); n_pok=atoi(sana[1]); pok_a=atof(sana[2]); pok_d=(atof(sana[3])-pok_a)/(double)n_pok; } if (results==0) couplen=0; else { couplen=5; coup_max=20; coup_a=0.0; coup_d=0.2; } i=spfind("COUPON"); if (i>=0) { strcpy(xx,spb[i]); i=split(xx,sana,4); if (i<4) { sur_print("\nUsage: COUPON=<# of classes>,<max_len>,<l.limit>,<u.limit>"); WAIT; return; } couplen=atoi(sana[0]); coup_max=atoi(sana[1]); coup_a=atof(sana[2]); coup_d=(atof(sana[3])-coup_a)/(double)couplen; } results_line=0; if (g>3) { results_line=edline2(word[3],1,1); if (results_line==0) return; } i=data_read_open(word[1],&d); if (i<0) return; var=varfind(&d,word[2]); if (var<0) return; i=sp_init(r1+r-1); if (i<0) { sur_print("\nToo many specifications!"); WAIT; return; } i=conditions(&d); if (i<0) return; i=space_allocation(); if (i<0) { sur_print("\nNot enough memory!"); return; } i=read_data(); if (i<0) return; rnd_printout(); data_close(&d); s_end(argv); }
void muste_xcorr(char *argv) { int i; s_init(argv); if (g<4) { sur_print("\nUsage: XCORR <data>,<xvar>,<yvar>,L"); WAIT; return; } i=sp_init(r1+r-1); if (i<0) return; i=data_read_open(word[1],&d); if (i<0) return; xvar=varfind(&d,word[2]); if (xvar<0) return; yvar=varfind(&d,word[3]); if (yvar<0) return; if (xvar==yvar) autocorr=1; else autocorr=0; if (g<5) tulosrivi=0; else { tulosrivi=edline2(word[4],1); if (tulosrivi==0) return; } i=conditions(&d); if (i<0) return; i=spfind("MAXLAG"); if (i<0) maxlag=12; else maxlag=atoi(spb[i]); if (maxlag<1) maxlag=1; xx=NULL; yy=NULL; xy1=NULL; xy2=NULL; x2=NULL; y2=NULL; xs1=NULL; xs2=NULL; ys1=NULL; ys2=NULL; i=varaa_tilat_xcorr(); if (i<0) return; n=0; for (i=0; i<maxlag; ++i) xx[i]=yy[i]=xy1[i]=xy2[i]=0.0; for (i=0; i<maxlag; ++i) xs1[i]=xs2[i]=ys1[i]=ys2[i]=0.0; xsum=ysum=xsum2=ysum2=0.0; corr=0.0; i=lue_datat(); data_close(&d); if (i<0) return; if ((int)maxlag>n-1) maxlag=n-1; tulostus(); s_end(argv); }
int main () { int rc; int rep; int req1; int req2; int resend_ivl; char buf [7]; /* Test req/rep with raw socket types. */ rc = sp_init (); errno_assert (rc == 0); rep = sp_socket (AF_SP_RAW, SP_REP); errno_assert (rep != -1); rc = sp_bind (rep, "inproc://a"); errno_assert (rc >= 0); req1 = sp_socket (AF_SP_RAW, SP_REQ); errno_assert (req1 != -1); rc = sp_connect (req1, "inproc://a"); errno_assert (rc >= 0); req2 = sp_socket (AF_SP_RAW, SP_REQ); errno_assert (req2 != -1); rc = sp_connect (req2, "inproc://a"); errno_assert (rc >= 0); rc = sp_send (req2, "ABC", 3, 0); errno_assert (rc >= 0); sp_assert (rc == 3); rc = sp_recv (rep, buf, sizeof (buf), 0); errno_assert (rc >= 0); sp_assert (rc == 7); rc = sp_send (rep, buf, 7, 0); errno_assert (rc >= 0); sp_assert (rc == 7); rc = sp_recv (req2, buf, sizeof (buf), 0); errno_assert (rc >= 0); sp_assert (rc == 3); rc = sp_send (req1, "ABC", 3, 0); errno_assert (rc >= 0); sp_assert (rc == 3); rc = sp_recv (rep, buf, sizeof (buf), 0); errno_assert (rc >= 0); sp_assert (rc == 7); rc = sp_send (rep, buf, 7, 0); errno_assert (rc >= 0); sp_assert (rc == 7); rc = sp_recv (req1, buf, sizeof (buf), 0); errno_assert (rc >= 0); sp_assert (rc == 3); rc = sp_close (rep); errno_assert (rc == 0); rc = sp_close (req1); errno_assert (rc == 0); rc = sp_close (req2); errno_assert (rc == 0); rc = sp_term (); errno_assert (rc == 0); /* Test req/rep with full socket types. */ rc = sp_init (); errno_assert (rc == 0); rep = sp_socket (AF_SP, SP_REP); errno_assert (rep != -1); rc = sp_bind (rep, "inproc://a"); errno_assert (rc >= 0); req1 = sp_socket (AF_SP, SP_REQ); errno_assert (req1 != -1); rc = sp_connect (req1, "inproc://a"); errno_assert (rc >= 0); req2 = sp_socket (AF_SP, SP_REQ); errno_assert (req2 != -1); rc = sp_connect (req2, "inproc://a"); errno_assert (rc >= 0); rc = sp_send (rep, "ABC", 3, 0); sp_assert (rc == -1 && sp_errno () == EFSM); rc = sp_recv (req1, buf, sizeof (buf), 0); sp_assert (rc == -1 && sp_errno () == EFSM); rc = sp_send (req2, "ABC", 3, 0); errno_assert (rc >= 0); sp_assert (rc == 3); rc = sp_recv (rep, buf, sizeof (buf), 0); errno_assert (rc >= 0); sp_assert (rc == 3); rc = sp_send (rep, buf, 3, 0); errno_assert (rc >= 0); sp_assert (rc == 3); rc = sp_recv (req2, buf, sizeof (buf), 0); errno_assert (rc >= 0); sp_assert (rc == 3); rc = sp_send (req1, "ABC", 3, 0); errno_assert (rc >= 0); sp_assert (rc == 3); rc = sp_recv (rep, buf, sizeof (buf), 0); errno_assert (rc >= 0); sp_assert (rc == 3); rc = sp_send (rep, buf, 3, 0); errno_assert (rc >= 0); sp_assert (rc == 3); rc = sp_recv (req1, buf, sizeof (buf), 0); errno_assert (rc >= 0); sp_assert (rc == 3); rc = sp_close (rep); errno_assert (rc == 0); rc = sp_close (req1); errno_assert (rc == 0); rc = sp_close (req2); errno_assert (rc == 0); rc = sp_term (); errno_assert (rc == 0); /* Test re-sending of the request. */ rc = sp_init (); errno_assert (rc == 0); rep = sp_socket (AF_SP, SP_REP); errno_assert (rep != -1); rc = sp_bind (rep, "inproc://a"); errno_assert (rc >= 0); req1 = sp_socket (AF_SP, SP_REQ); errno_assert (req1 != -1); rc = sp_connect (req1, "inproc://a"); errno_assert (rc >= 0); resend_ivl = 100; rc = sp_setsockopt (req1, SP_REQ, SP_RESEND_IVL, &resend_ivl, sizeof (resend_ivl)); errno_assert (rc == 0); rc = sp_send (req1, "ABC", 3, 0); errno_assert (rc >= 0); sp_assert (rc == 3); rc = sp_recv (rep, buf, sizeof (buf), 0); errno_assert (rc >= 0); sp_assert (rc == 3); rc = sp_recv (rep, buf, sizeof (buf), 0); errno_assert (rc >= 0); sp_assert (rc == 3); rc = sp_close (req1); errno_assert (rc == 0); rc = sp_close (rep); errno_assert (rc == 0); rc = sp_term (); errno_assert (rc == 0); return 0; }
/**************** main(argc,argv) int argc; char *argv[]; *******************/ void muste_facta(char *argv) { int i,j,h; unsigned int ui; double da,db; char x[LLENGTH]; double sumlogsii; // extern double cdf_chi2(); char acc[32]; // if (argc==1) return; s_init(argv); if (g<3) { init_remarks(); rem_pr("Usage: FACTA <corr.matrix>,k,L "); rem_pr(" k=number of factors "); rem_pr(" L=first line for the results "); rem_pr(" Factor matrix saved as FACT.M "); rem_pr(" "); rem_pr(" METHOD=ULS Unweighted Least Squares "); rem_pr(" METHOD=GLS Generalized Least Squares "); rem_pr(" METHOD=ML Maximum Likelihood (default) "); rem_pr(" Test statistics by N=<number of observations>"); rem_pr("More information by FACTA? "); wait_remarks(2); s_end(argv); return; } results_line=0; if (g>3) { results_line=edline2(word[3],1); if (results_line==0) return; } i=sp_init(r1+r-1); if (i<0) return; i=matrix_load(word[1],&E,&p,&n,&rlab,&clab,&lr,&lc,&type,expr); if (i<0) { s_end(argv); return; } // RS CHA argv[1] if (p!=n) { sprintf(sbuf,"\n%s not a square matrix!",word[1]); sur_print(sbuf); WAIT; return; } k=atoi(word[2]); if (k<1 || k>p-1) { sprintf(sbuf,"Incorrect number (%d) of factors!",k); if (etu==2) { sprintf(tut_info,"___@6@FACTA@%s@",sbuf); s_end(argv); // RS CHA argv[1] return; } sur_print("\n"); sur_print(sbuf); WAIT; return; } *mess=EOS; i=spfind("FEPS"); if (i>=0) { double eps; eps=1.0-atof(spb[i]); for (i=0; i<p; ++i) for (j=0; j<p; ++j) { if (i==j) continue; E[i+j*p]*=eps; } } ind=3; i=spfind("METHOD"); if (i>=0) { if (muste_strcmpi(spb[i],"ULS")==0) ind=1; if (muste_strcmpi(spb[i],"GLS")==0) ind=2; } for (i=0; i<p; ++i) { if (E[i*(p+1)]!=0.0) continue; sprintf(sbuf,"Variable %.*s is a constant!",lr,rlab+i*lr); if (etu==2) { sprintf(tut_info,"___@1@FACTA@%s@",sbuf); s_end(argv); // RS CHA argv[1] return; } sur_print("\n"); sur_print(sbuf); WAIT; return; } /* if (ind==1) { for (i=0; i<p; ++i) { if (fabs(E[i*(p+1)]-1.0)<0.0001) continue; Rprintf("\n%s is not a correlation matrix as supposed in ULS!", word[1]); WAIT; return; } } */ i=varaa_tilat(); if (i<0) return; for (ui=0; ui<p*p; ++ui) S[ui]=E[ui]; sumlogsii=0.0; for (i=0; i<p; ++i) sumlogsii+=log(S[i*(p+1)]); i=nwtrap(); if (i<0) { if (etu!=2) { sur_print("\nSolution not found!"); WAIT; return; } s_end(argv); // RS CHA argv[1] return; } h=output_open(eout); if (h<0) return; strcpy(x,"Factor analysis: "); switch (ind) { case 1: strcat(x,"Unweighted Least Squares (ULS) solution"); break; case 2: strcat(x,"Generalized Least Squares (GLS) solution"); break; case 3: strcat(x,"Maximum Likelihood (ML) solution"); break; } print_line(x); if (*mess) { strcpy(x," "); strcat(x,mess); print_line(x); if (etu!=2) { WAIT; } } i=spfind("N"); if (i>=0) { if (ind>1) { double n1,c0,chi20,d0,m0,ck,chi2k,dk,mk,rho,pr; char *q; n1=atof(spb[i]); if (n1<(double)k) { sur_print("\nIncorrect N!"); WAIT; return; } c0=n1-1.0-(2.0*p+5.0)/6.0; chi20=c0*(sumlogsii-log(det)); d0=p*(p-1.0)/2.0; m0=chi20/d0; ck=c0-2.0*k/3.0; chi2k=ck*f0; dk=((p-k)*(p-k)-p-k)/2.0; mk=chi2k/dk; rho=(m0-mk)/(m0-1.0); // pr=cdf_chi2(chi2k,dk,1e-10); pr=0.0; sprintf(x,"factors=%d Chi^2=%g df=%d P=%5.3f reliability=%g", k,chi2k,(int)dk,pr,rho); if (rho>1.0) { q=strstr(x,"rel"); *q=EOS; } /* 3.6.1995 */ print_line(x); } else { double n1,uu,dk,pr; n1=atof(spb[i]); if (n1<(double)k) { sur_print("\nIncorrect N!"); WAIT; return; } for (i=0; i<p; ++i) for (j=0; j<i; ++j) { da=0.0; for (h=0; h<k; ++h) da+=L[i+p*h]*L[j+p*h]; S[i+p*j]=da; S[j+p*i]=da; } /* Huom. S-diagonaali säilytetään */ mat_dcholinv(S,p,&uu); uu=(n1-1.0)*log(uu/det); dk=((p-k)*(p-k)+p-k)/2.0; /* ei sama kuin yllä! */ // pr=cdf_chi2(uu,dk,1e-10); pr=0.0; sprintf(x,"factors=%d Chi^2=%g df=%d P=%5.3f", k,uu,(int)dk,pr); print_line(x); } } output_close(eout); f_orientation(L,p,k); text_labels(clab,k,lc,"F"); matrix_save("FACT.M",L,p,k,rlab,clab,lr,lc,0,"F",0,0); strncpy(clab+k*lc,"h^2 ",8); for (i=0; i<p; ++i) { da=0.0; for (j=0; j<k; ++j) { db=L[i+p*j]; S[i+p*j]=db; da+=db*db; } S[i+p*k]=da; } strcpy(acc,"12.1234567890123456"); acc[accuracy-1]=EOS; matrix_print(S,p,k+1,rlab,clab,lr,lc,p,k+1,NULL,NULL,acc,c3, results_line,eout,"Factor matrix"); s_end(argv); }
void muste_cluster(char *argv) { int i,k; double a; char ch; // if (argc==1) return; s_init(argv); if (g<2) { sur_print("\nUsage: CLUSTER <SURVO_data>,<output_line>"); WAIT; return; } tulosrivi=0; if (g>2) { tulosrivi=edline2(word[2],1,1); if (tulosrivi==0) return; } strcpy(aineisto,word[1]); i=data_open(aineisto,&d); if (i<0) return; i=sp_init(r1+r-1); if (i<0) return; i=mask(&d); if (i<0) return; scales(&d); i=conditions(&d); if (i<0) return; gvar=activated(&d,'G'); if (gvar<0) { sur_print("\nNo grouping variable (activated by 'G') given!"); WAIT; return; } ivar=-1; ivar=activated(&d,'I'); i=spfind("TRIALS"); if (i>=0) maxiter=atoi(spb[i]); i=rand_init(); if (i<0) return; /* 30.4.1994 */ i=spfind("TEMPFILE"); if (i>=0) strcpy(tempfile,spb[i]); else { strcpy(tempfile,etmpd); strcat(tempfile,"SURVO.CLU"); } i=spfind("PRIND"); if (i>=0 && atoi(spb[i])>0) prind=1; data_load(&d,1L,gvar,&a); i=data_save(&d,1L,gvar,a); if (i<0) return; gvar2=(int *)muste_malloc(d.m_act*sizeof(int)); if (gvar2==NULL) { not_enough_memory(); return; } k=0; n_saved=0; m=0; for (i=0; i<d.m_act; ++i) { ch=d.vartype[d.v[i]][1]; if (ch=='G') { ++k; gvar2[n_saved]=d.v[i]; /* gvar=gvar2[0] */ ++n_saved; continue; } if (ch=='I') { ++k; continue; } d.v[m++]=d.v[i]; } /* printf("\nivar=%d gvar=%d m=%d\n",ivar,gvar,m); getch(); for (i=0; i<m; ++i) Rprintf(" %d",d.v[i]); getch(); printf("\n"); for (i=0; i<n_saved; ++i) Rprintf(" %d",gvar2[i]); getch(); */ i=spfind("GROUPS"); if (i<0) ng=2; else ng=atoi(spb[i]); if (ng<2) ng=2; ng2=ng+2; mn=m; if (mn<ng) mn=ng; first_line=r+1; if (r+n_saved>r3) first_line=1; n_show=n_saved; if (n_show>r3) n_show=r3; i=varaa_tilat(); if (i<0) return; i=lue_havainnot(); if (i<0) return; hav_muistissa=havainnot_muistiin(); ortogonalisoi(); if (ivar_init) alustava_luokittelu(); LOCATE(first_line,1); SCROLL_UP(first_line,r3+1,r3); sur_print("\nCluster analysis: Iteration 1:"); while (sur_kbhit()) sur_getch(); it=0; while (1) { while (1) { if (it) init_gr(); i=init_tilat(); if (i>=0) break; if (maxiter==1) return; } iteroi(); ++it; if (maxiter>1) vertaa_muihin(); if (it==maxiter) break; LOCATE(first_line,1); sprintf(sbuf,"\nIteration %d (Cluster analysis)",it); sur_print(sbuf); for (i=0; i<n_show; ++i) { if (freq[i]==0) break; sprintf(sbuf,"\n%d %g %d ",i+1,lambda2[i],freq[i]); sur_print(sbuf); } if (sur_kbhit()) { i=sur_getch(); if (i=='.') break; } } tulosta(); data_close(&d); sur_delete(tempfile); s_end(argv); }
int main(int argc, char **argv) { SortedPoints *sp1; Point p1; sp1 = (SortedPoints*)malloc(sizeof(SortedPoints)); assert(sp1); sp_init(sp1); int ret = sp_addNewPoint(sp1, 2.0, 2.0); assert(ret); ret = sp_addNewPoint(sp1, 3.0, 4.0); assert(ret); ret = sp_addNewPoint(sp1, 1.0, 1.0); assert(ret); ret = sp_addNewPoint(sp1, 2.0, 1.0); assert(ret); ret = sp_addNewPoint(sp1, 1.0, 2.0); assert(ret); ret = sp_addNewPoint(sp1, 2.0, 2.0); assert(ret); Point temp = (sp1->pointArray)[0]; Point temp2 = (sp1->pointArray)[1]; Point temp3 = (sp1->pointArray)[2]; Point temp4 = (sp1->pointArray)[3]; Point temp5 = (sp1->pointArray)[4]; Point temp6 = (sp1->pointArray)[5]; printf("sp1 first: (%f, %f)\n", point_getX(&temp), point_getY(&temp)); printf("sp1 second: (%f, %f)\n", point_getX(&temp2), point_getY(&temp2)); printf("sp1 third: (%f, %f)\n", point_getX(&temp3), point_getY(&temp3)); printf("sp1 fourth: (%f, %f)\n", point_getX(&temp4), point_getY(&temp4)); printf("sp1 fifth: (%f, %f)\n", point_getX(&temp5), point_getY(&temp5)); printf("sp1 sixth: (%f, %f)\n", point_getX(&temp6), point_getY(&temp6)); Point *aTemp = (Point*)malloc(sizeof(Point)); ret = sp_removeFirst(sp1, aTemp); printf("----------------------------------\n"); sp_printArray(sp1); ret = sp_removeFirst(sp1, aTemp); printf("----------------------------------\n"); sp_printArray(sp1); ret = sp_removeLast(sp1, aTemp); printf("-----------------------------------\n"); sp_printArray(sp1); /* ret = sp_addNewPoint(sp2, 3.0, 1.0); assert(ret); ret = sp_addNewPoint(sp2, 2.0, 1.0); assert(ret); ret = sp_addNewPoint(sp2, 1.0, 1.0); assert(ret); ret = sp_addNewPoint(sp1, 2.0, 2.0); assert(ret); ret = sp_addNewPoint(sp1, 2.0, 2.0); assert(ret); ret = sp_addNewPoint(sp1, 2.0, 2.0); assert(ret); ret= sp_removeFirst(sp1, &p1); assert(ret); assert(point_getX(&p1) == 1.0); assert(point_getY(&p1) == 1.0); ret = sp_removeIndex(sp1, 2, &p1); assert(ret); assert(point_getX(&p1) == 2.0); assert(point_getY(&p1) == 2.0); ret = sp_addNewPoint(sp1, 2.0, 2.0); assert(ret); ret = sp_addNewPoint(sp1, 2.0, 2.0); assert(ret); ret = sp_addNewPoint(sp1, 2.0, 2.0); assert(ret); ret= sp_removeFirst(sp1, &p1); assert(ret); assert(point_getX(&p1) == 1.0); assert(point_getY(&p1) == 1.0); sp_deleteDuplicates(sp1); ret= sp_removeFirst(sp1, &p1); assert(ret); assert(point_getX(&p1) == 1.0); assert(point_getY(&p1) == 1.0); ret= sp_removeFirst(sp1, &p1); assert(ret); assert(point_getX(&p1) == 2.0); assert(point_getY(&p1) == 2.0); ret= sp_removeFirst(sp1, &p1); assert(!ret); sp_deleteDuplicates(sp2); stressTest(); printf("OK\n"); */ return 0; }