Esempio n. 1
0
    message_ex* dsn_message_parser::get_message_on_receive(int read_length, /*out*/ int& read_next)
    {
        mark_read(read_length);

        if (_read_buffer_occupied >= sizeof(message_header))
        {
            if (!_header_checked)
            {
                if (!message_ex::is_right_header((char*)_read_buffer.data()))
                {
                    derror("receive message header check failed for message");

                    truncate_read();
                    read_next = -1;
                    return nullptr;
                }
                else
                {
                    _header_checked = true;
                }
            }

            int msg_sz = sizeof(message_header) +
                message_ex::get_body_length((char*)_read_buffer.data());

            // msg done
            if (_read_buffer_occupied >= msg_sz)
            {
                auto msg_bb = _read_buffer.range(0, msg_sz);
                message_ex* msg = message_ex::create_receive_message(msg_bb);
                if (!msg->is_right_body(false))
                {
                    message_header* header = (message_header*)_read_buffer.data();
                    derror("body check failed for message, id: %d, rpc_name: %s, from: %s",
                          header->id, header->rpc_name, header->from_address.to_string());

                    truncate_read();
                    read_next = -1;
                    return nullptr;
                }
                else
                {
                    _read_buffer = _read_buffer.range(msg_sz);
                    _read_buffer_occupied -= msg_sz;
                    _header_checked = false;

                    read_next = sizeof(message_header);
                    return msg;
                }
            }
            else
            {
                read_next = msg_sz - _read_buffer_occupied;
                return nullptr;
            }
        }

        else
        {
            read_next = sizeof(message_header) - _read_buffer_occupied;
            return nullptr;
        }
    }
Esempio n. 2
0
int main(int argc,char* args[])
{
	struct sockaddr_in ser_addr[6],cli_addr;
	int portno,cli_len,i,j,max,nsfd;  // max holds max fd value + 1
	i = getppid();
	printf("%d %d\n", i,getpid());
	int S[6];
	char buf[256];
	int s1_shm,s1_chi;
	int *s1_count,*s1_child;
	s1_shm = shmget(ftok(".",2), sizeof(int), IPC_CREAT | 0666);
	s1_count = shmat(s1_shm,NULL,0);
	s1_chi = shmget(ftok(".",4), 25*sizeof(int), IPC_CREAT | 0666);
	s1_child = shmat(s1_chi,NULL,0);
	for(i=0;i<25;i++)
		s1_child[i]=-1;
	signal(SIGCHLD,child_detect);
	*s1_count=s2_count=0;
	fd_set readfds;

	cli_len = sizeof(struct sockaddr_in);
	

	for(i=1;i<=5;i++)
	memset(&ser_addr[i],0,sizeof(struct sockaddr_in)); // Initialize to 0

	// address of connection oriented socket
	for(i=1;i<=5;i++)
	{
		ser_addr[i].sin_family = AF_INET;
		portno = atoi(args[i]);
		ser_addr[i].sin_port = htons(portno); // converts int to 16 bit integer in network byte order
		ser_addr[i].sin_addr.s_addr = INADDR_ANY; // to get IP address of machine on which server is running
	}

	S[1] = socket(AF_INET,SOCK_STREAM|SOCK_NONBLOCK,0); // socket create... AF_INET for IPv4 domain and SOCK_STREAM for connection oriented systems
	S[2] = socket(AF_INET,SOCK_STREAM|SOCK_NONBLOCK,0);
	S[3] = socket(AF_INET,SOCK_DGRAM,0);
	S[4] = socket(AF_INET,SOCK_STREAM|SOCK_NONBLOCK,0);
	S[5] = socket(AF_INET,SOCK_DGRAM,0);

	for(i=1;i<=5;i++)
	if(bind(S[i],(struct sockaddr*)&ser_addr[i],sizeof(struct sockaddr_in))<0)
		derror("Bind error");
	
	if(listen(S[1],5)<0) // No. of clients that server can service
		derror("Listen error");

	if(listen(S[2],5)<0) // No. of clients that server can service
		derror("Listen error");

	if(listen(S[4],5)<0) // No. of clients that server can service
		derror("Listen error");

	cli_len = sizeof(struct sockaddr_in);

	struct timespec tim_dur;
	tim_dur.tv_sec = 2;   // waiting time of 1 sec for verifying set bits of FDSET
	tim_dur.tv_nsec = 0;

	max=S[1];
	for(i=2;i<=5;i++)
	{
		if(max<S[i])
			max=S[i];
	}

	while(1)
	{
		FD_ZERO(&readfds);
		// printf("%d %d\n",*s1_count,s2_count);

		
		if(*s1_count<25)
		FD_SET(S[1],&readfds);
		if(s2_count<15)
		FD_SET(S[2],&readfds);
		for(i=3;i<=5;i++)
		{
			//if(i!=1&&i!=2)
			FD_SET(S[i],&readfds); // Set the connection oriented sfd
			// if(i==1&&s1_count<2)
			// FD_SET(S[i],&readfds);
			// if(i==2&&s2_count<2)
			// FD_SET(S[i],&readfds);
		}

		// pselect for finding if data is available
		//printf("HEllo\n");
		if(pselect(max+1,&readfds,NULL,NULL,&tim_dur,NULL)>0); // pselect is used as timeleft is not updated after each select call
		{
			//printf("Select truee\n");
			if(FD_ISSET(S[1],&readfds))
			{
				printf("S1\n");
				// if(s1_count<3)
				// {
					nsfd = accept(S[1],(struct sockaddr*)&cli_addr,&cli_len);
					if(nsfd>=0)
					{
						*s1_count=*s1_count+1;
						int c = fork();
						if(c>0)
						{
							for(i=0;i<25;i++)
							{
								if(s1_child[i]==-1)
								{
									s1_child[i]=c;
									break;
								}
							}
							close(nsfd);
							printf("%d %d\n",*s1_count,s2_count);
						}
						else
						{
							close(S[1]);
							dup2(nsfd,0);
							execlp("./s1","s1",(char*) 0); // capitalise the buffer
							exit(0);
						}
					}
					else
					{;
					//	printf("Something fishy in s1!\n");
					}
				// }
				// else
				// {
				// 	printf("queue for s1\n");
				// }
			}

			if(FD_ISSET(S[2],&readfds))
			{
				printf("S2\n");
				// if(s2_count<2)
				// {
					nsfd = accept(S[2],(struct sockaddr*)&cli_addr,&cli_len);
				if(nsfd>=0)
				{
					pthread_t s2_thread;
					s2_count++;
					pthread_create(&s2_thread,NULL,s2_service,(void*)&nsfd);
					printf("%d %d\n",*s1_count,s2_count);
				}
				else
				{;
				//	printf("Something fishy on s2\n");
				}
				// }
				// else
				// {
				// 	printf("queue for s2\n");
				// }
			}

			if(FD_ISSET(S[4],&readfds))
			{
				printf("S4\n");
				nsfd = accept(S[4],(struct sockaddr*)&cli_addr,&cli_len);
				if(nsfd>=0)
				{
					int c = fork();
					if(c>0)
					{
						close(nsfd);
					}
					else
					{
						close(S[4]);
						dup2(nsfd,0);
						execlp("./s5","s5",(char*) 0); // capitalise the buffer
						exit(0);
					}
				}
				else
				{
					printf("Something fishy on s4\n");
				}
			}

			if(FD_ISSET(S[3],&readfds))
			{
				printf("S3\n");
				s3_function();
			}

			if(FD_ISSET(S[5],&readfds))
			{
				printf("S5\n");
				if(s5_flag)
				{
					int c = fork();
					if(c>0)
					{
						;
					}
					else
					{
						dup2(S[5],0);
						execlp("./s5","s5",(char*) 0); // capitalise the buffer
						exit(0);
					}
				}
				else
				{;
					//printf("s5 full so waiting\n");
				}
			}
		}
		//printf("Some testing\n");
	}

	return 0;
}
Esempio n. 3
0
/* generate C to put netCDF record from in-memory data */
static void
gen_load_c(
    void *rec_start
    )
{
    int  idim, ival;
    char *val_string;
    char *charvalp = NULL;
    short *shortvalp = NULL;
    int *intvalp = NULL;
    float *floatvalp = NULL;
    double *doublevalp = NULL;
    unsigned char *ubytevalp = NULL;
    unsigned short *ushortvalp = NULL;
    unsigned int *uintvalp = NULL;
    long long *int64valp = NULL;
    unsigned long long *uint64valp = NULL;
    char stmnt[C_MAX_STMNT];
    size_t stmnt_len;
    char s2[C_MAX_STMNT];

    if (!vars[varnum].has_data)
	return;

    s2[0] = '\0';
    cline("");
    sprintf(stmnt, "   {\t\t\t/* store %s */", vars[varnum].name);
    cline(stmnt);

    if (vars[varnum].ndims > 0) {
	if (vars[varnum].dims[0] == rec_dim) {
	    sprintf(stmnt, "    static MPI_Offset %s_start[RANK_%s];",
		    vars[varnum].lname, vars[varnum].lname);
	    cline(stmnt);

	    sprintf(stmnt, "    static MPI_Offset %s_count[RANK_%s];",
		    vars[varnum].lname, vars[varnum].lname);
	    cline(stmnt);
	}

	/* load variable with data values using static initialization */
	sprintf(stmnt, "    static %s %s[] = {",
		ncctype(vars[varnum].type),
		vars[varnum].lname);

	stmnt_len = strlen(stmnt);
	switch (vars[varnum].type) {
	  case NC_CHAR:
	    val_string = cstrstr((char *) rec_start, var_len);
	    sprintf(s2, "%s", val_string);
	    strncat(stmnt, s2, C_MAX_STMNT - strlen(stmnt) );
	    free(val_string);
	    break;
	  default:
	    switch (vars[varnum].type) {
	      case NC_BYTE:
		charvalp = (char *) rec_start;
		break;
	      case NC_SHORT:
		shortvalp = (short *) rec_start;
		break;
	      case NC_INT:
		intvalp = (int *) rec_start;
		break;
	      case NC_FLOAT:
		floatvalp = (float *) rec_start;
		break;
	      case NC_DOUBLE:
		doublevalp = (double *) rec_start;
		break;
	      case NC_UBYTE:
		ubytevalp = (unsigned char *) rec_start;
		break;
	      case NC_USHORT:
		ushortvalp = (unsigned short *) rec_start;
		break;
	      case NC_UINT:
		uintvalp = (unsigned int *) rec_start;
		break;
	      case NC_INT64:
		int64valp = (long long *) rec_start;
		break;
	      case NC_UINT64:
		uint64valp = (unsigned long long *) rec_start;
		break;
	      default:
		derror("Unhandled type %d\n", vars[varnum].type);
		return;
	    }
            for (ival = 0; ival < var_len-1; ival++) {
		switch (vars[varnum].type) {
		  case NC_BYTE:
			sprintf(s2, "%d, ", *charvalp++);
		    break;
		  case NC_SHORT:
			sprintf(s2, "%d, ", *shortvalp++);
		    break;
		  case NC_INT:
			sprintf(s2, "%ld, ", (long)*intvalp++);
		    break;
		  case NC_FLOAT:
			sprintf(s2, "%.8g, ", *floatvalp++);
		    break;
		  case NC_DOUBLE:
			sprintf(s2, "%#.16g", *doublevalp++);
			tztrim(s2);
			strcat(s2, ", ");
		    break;
		  case NC_UBYTE:
			sprintf(s2, "%hhu, ", (unsigned char)*ubytevalp++);
		    break;
		  case NC_USHORT:
			sprintf(s2, "%hu, ", (unsigned short)*ushortvalp++);
		    break;
		  case NC_UINT:
			sprintf(s2, "%u, ", (unsigned int)*uintvalp++);
		    break;
		  case NC_INT64:
			sprintf(s2, "%lld, ", (long long)*int64valp++);
		    break;
		  case NC_UINT64:
			sprintf(s2, "%llu, ", (unsigned long long)*uint64valp++);
		    break;
		  default:
		    derror("Unhandled type %d\n", vars[varnum].type);
		    return;

		}
		stmnt_len += strlen(s2);
		if (stmnt_len < C_MAX_STMNT)
		  strcat(stmnt, s2);
		else {
		    cline(stmnt);
		    strcpy(stmnt,s2);
		    stmnt_len = strlen(stmnt);
		}
	    }
	    for (;ival < var_len; ival++) {
		switch (vars[varnum].type) {
		  case NC_BYTE:
			sprintf(s2, "%d", *charvalp);
		    break;
		  case NC_SHORT:
			sprintf(s2, "%d", *shortvalp);
		    break;
		  case NC_INT:
			sprintf(s2, "%ld", (long)*intvalp);
		    break;
		  case NC_FLOAT:
			sprintf(s2, "%.8g", *floatvalp);
		    break;
		  case NC_DOUBLE:
			sprintf(s2, "%#.16g", *doublevalp++);
			tztrim(s2);
		    break;
		  case NC_UBYTE:
			sprintf(s2, "%hhu, ", (unsigned char)*ubytevalp++);
		    break;
		  case NC_USHORT:
			sprintf(s2, "%hu, ", (unsigned short)*ushortvalp++);
		    break;
		  case NC_UINT:
			sprintf(s2, "%u, ", (unsigned int)*uintvalp++);
		    break;
		  case NC_INT64:
			sprintf(s2, "%lld, ", (long long)*int64valp++);
		    break;
		  case NC_UINT64:
			sprintf(s2, "%llu, ", (unsigned long long)*uint64valp++);
		    break;
		  default:
		    derror("Unhandled type %d\n", vars[varnum].type);
		    break;
		}
		stmnt_len += strlen(s2);
		if (stmnt_len < C_MAX_STMNT)
		  strcat(stmnt, s2);
		else {
		    cline(stmnt);
		    strcpy(stmnt,s2);
		    stmnt_len = strlen(stmnt);
		}
	    }
	    break;
	}
	strcat(stmnt,"};");
	cline(stmnt);

	if (vars[varnum].dims[0] == rec_dim) {
	    sprintf(stmnt,
		    "    %s_len = %lu;			/* number of records of %s data */",
		    dims[rec_dim].lname,
		    (unsigned long)vars[varnum].nrecs, /* number of recs for this variable */
		    vars[varnum].name);
	    cline(stmnt);

	    for (idim = 0; idim < vars[varnum].ndims; idim++) {
		sprintf(stmnt, "    %s_start[%d] = 0;",
			vars[varnum].lname,
			idim);
		cline(stmnt);
	    }

	    for (idim = 0; idim < vars[varnum].ndims; idim++) {
		sprintf(stmnt, "    %s_count[%d] = %s_len;",
			vars[varnum].lname,
			idim,
			dims[vars[varnum].dims[idim]].lname);
		cline(stmnt);
	    }
	}

	if (vars[varnum].dims[0] == rec_dim) {
	    sprintf(stmnt,
		    "    stat = ncmpi_put_vara_%s_all(ncid, %s_id, %s_start, %s_count, %s);",
		    ncstype(vars[varnum].type),
		    vars[varnum].lname,
		    vars[varnum].lname,
		    vars[varnum].lname,
		    vars[varnum].lname);
	     cline(stmnt);
	} else {		/* non-record variables */
	    cline("  ncmpi_begin_indep_data(ncid);");
	    sprintf(stmnt,
		    "    stat = ncmpi_put_var_%s(ncid, %s_id, %s);",
		    ncstype(vars[varnum].type),
		    vars[varnum].lname,
		    vars[varnum].lname);
	    cline(stmnt);
	    cline("  ncmpi_end_indep_data(ncid);");
	}
    } else {			/* scalar variables */
	/* load variable with data values using static initialization */
	sprintf(stmnt, "    static %s %s = ",
		ncctype(vars[varnum].type),
		vars[varnum].lname);

	switch (vars[varnum].type) {
	  case NC_CHAR:
	    val_string = cstrstr((char *) rec_start, var_len);
	    val_string[strlen(val_string)-1] = '\0';
	    sprintf(s2, "'%s'", &val_string[1]);
	    free(val_string);
	    break;
	  case NC_BYTE:
	    charvalp = (char *) rec_start;
	    sprintf(s2, "%d", *charvalp);
	    break;
	  case NC_SHORT:
	    shortvalp = (short *) rec_start;
	    sprintf(s2, "%d", *shortvalp);
	    break;
	  case NC_INT:
	    intvalp = (int *) rec_start;
	    sprintf(s2, "%ld", (long)*intvalp);
	    break;
	  case NC_FLOAT:
	    floatvalp = (float *) rec_start;
	    sprintf(s2, "%.8g", *floatvalp);
	    break;
	  case NC_DOUBLE:
	    doublevalp = (double *) rec_start;
	    sprintf(s2, "%#.16g", *doublevalp++);
	    tztrim(s2);
	    break;
	  case NC_UBYTE:
	    ubytevalp = (unsigned char *) rec_start;
	    sprintf(s2, "%hhu", (unsigned char)*ubytevalp);
	    break;
	  case NC_USHORT:
	    ushortvalp = (unsigned short *) rec_start;
	    sprintf(s2, "%hu", (unsigned short)*ushortvalp);
	    break;
	  case NC_UINT:
	    uintvalp = (unsigned int *) rec_start;
	    sprintf(s2, "%u", (unsigned int)*uintvalp);
	    break;
	  case NC_INT64:
	    int64valp = (long long *) rec_start;
	    sprintf(s2, "%lld", (long long)*int64valp);
	    break;
	  case NC_UINT64:
	    uint64valp = (unsigned long long *) rec_start;
	    sprintf(s2, "%llu", (unsigned long long)*uint64valp);
	    break;
	  default:
	    derror("Unhandled type %d\n", vars[varnum].type);
	    break;
	}
	strncat(stmnt, s2, C_MAX_STMNT - strlen(stmnt) );
	strcat(stmnt,";");
	cline(stmnt);
	cline("  ncmpi_begin_indep_data(ncid);");
	sprintf(stmnt,
		"    stat = ncmpi_put_var_%s(ncid, %s_id, &%s);",
		ncstype(vars[varnum].type),
		vars[varnum].lname,
		vars[varnum].lname);
	cline(stmnt);
	cline("  ncmpi_end_indep_data(ncid);");
    }
    cline("    check_err(stat,__LINE__,__FILE__);");
    cline("   }");
}
Esempio n. 4
0
array_t *
parse (lexer_t *lex) {
	unsigned i;

	array_t stack;
	array_init(&stack, sizeof(parser_stack_t));
	parser_stack_t initial;
	bzero(&initial, sizeof(initial));
	array_add(&stack, &initial);

	array_t *result = 0;
	while (stack.size > 0) {
		parser_stack_t *current = array_get(&stack, stack.size-1);
		const parser_state_t *state = parser_states + current->state;

		for (i = 0; i < state->num_actions; ++i)
			if (state->actions[i].token == lex->token)
				break;

		if (i >= state->num_actions) {
			char *msg = strdup("syntax error, expected");
			for (i = 0; i < state->num_actions; ++i) {
				char *glue;
				if (i == 0)
					glue = " ";
				else if (i == state->num_actions-1)
					glue = ", or ";
				else
					glue = ", ";
				char *nmsg;
				asprintf(&nmsg, "%s%s\"%s\"", msg, glue, token_names[state->actions[i].token]);
				free(msg);
				msg = nmsg;
			}
			derror(&lex->loc, "%s\n", msg);
			free(msg);
		}

		const parser_action_t *action = &state->actions[i];
		if (action->state_or_length < 0) {
			if (action->rule == 0) {
				result = current->token.ptr;
				break;
			}

			unsigned num_tokens = -action->state_or_length;

			parser_stack_t *target = array_get(&stack, stack.size-num_tokens);
			parser_stack_t *base = array_get(&stack, stack.size-num_tokens-1);
			const parser_state_t *base_state = parser_states + base->state;

			token_t reduced = target->token;
			reduced.id = action->rule;
			reduced.last = current->token.last;

			if (action->reducer) {
				token_t tokens[num_tokens];
				for (i = 0; i < num_tokens; ++i)
					tokens[i] = (target+i)->token;
				action->reducer(&reduced, tokens, action->reducer_tag);
			}

			target->token = reduced;

			for (i = 0; i < base_state->num_gotos; ++i) {
				if (base_state->gotos[i].rule == action->rule) {
					target->state = base_state->gotos[i].state;
					break;
				}
			}

			array_resize(&stack, stack.size-num_tokens+1);
		} else {
			parser_stack_t *new_stack = array_add(&stack, 0);
			bzero(new_stack, sizeof(*new_stack));
			new_stack->state = action->state_or_length;
			new_stack->token.id = lex->token;
			new_stack->token.first = lex->base;
			new_stack->token.last = lex->ptr;
			new_stack->token.loc = lex->loc;
			lexer_next(lex);
		}
	}

	array_dispose(&stack);

	return result;
}
Esempio n. 5
0
void replica::on_append_log_completed(mutation_ptr& mu, error_code err, size_t size)
{
    check_hashed_access();

    dinfo("%s: append shared log completed for mutation %s, size = %u, err = %s",
          name(), mu->name(), size, err.to_string());

    if (err == ERR_OK)
    {
        mu->set_logged();
    }
    else
    {
        derror("%s: append shared log failed for mutation %s, err = %s",
               name(), mu->name(), err.to_string());
    }

    // skip old mutations
    if (mu->data.header.ballot >= get_ballot() && status() != partition_status::PS_INACTIVE)
    {
        switch (status())
        {
        case partition_status::PS_PRIMARY:
            if (err == ERR_OK)
            {
                do_possible_commit_on_primary(mu);
            }
            else
            {
                handle_local_failure(err);
            }
            break;
        case partition_status::PS_SECONDARY:
        case partition_status::PS_POTENTIAL_SECONDARY:
            if (err != ERR_OK)
            {
                handle_local_failure(err);
            }
            // always ack
            ack_prepare_message(err, mu);
            break;
        case partition_status::PS_ERROR:
            break;
        default:
            dassert(false, "");
            break;
        }
    }

    if (err != ERR_OK)
    {
        // mutation log failure, propagate to all replicas
        _stub->handle_log_failure(err);
    }
   
    // write local private log if necessary
    if (err == ERR_OK && _private_log && status() != partition_status::PS_ERROR)
    {
        _private_log->append(mu,
            LPC_WRITE_REPLICATION_LOG,
            nullptr,
            nullptr,
            gpid_to_hash(get_gpid())
            );
    }
}
Esempio n. 6
0
error_code hpc_aio_provider::aio_internal(aio_task* aio_tsk, bool async, /*out*/ uint32_t* pbytes /*= nullptr*/)
{
    auto aio = (windows_disk_aio_context*)aio_tsk->aio();
    BOOL r = FALSE;

    aio->olp.Offset = (uint32_t)aio->file_offset;
    aio->olp.OffsetHigh = (uint32_t)(aio->file_offset >> 32);

    if (!async)
    {
        aio->evt = new utils::notify_event();
        aio->err = ERR_OK;
        aio->bytes = 0;
    }

    switch (aio->type)
    {
    case AIO_Read:
        r = ::ReadFile((HANDLE)aio->file, aio->buffer, aio->buffer_size, NULL, &aio->olp);
        break;
    case AIO_Write:
        r = ::WriteFile((HANDLE)aio->file, aio->buffer, aio->buffer_size, NULL, &aio->olp);
        break;
    default:
        dassert (false, "unknown aio type %u", static_cast<int>(aio->type));
        break;
    }

    if (!r)
    {
        int native_error = ::GetLastError();
        
        if (native_error != ERROR_IO_PENDING)
        {
            derror("file operation failed, err = %u", native_error);

            error_code err = native_error == ERROR_SUCCESS ? ERR_OK :
                (native_error == ERROR_HANDLE_EOF ? ERR_HANDLE_EOF : ERR_FILE_OPERATION_FAILED);

            if (async)
            {
                complete_io(aio_tsk, err, 0);
            }
            else
            {
                delete aio->evt;
                aio->evt = nullptr;
            }

            return err;
        }
    }

    if (async)
    {
        return ERR_IO_PENDING;
    }
    else
    {
        aio->evt->wait();
        delete aio->evt;
        aio->evt = nullptr;
        if (pbytes != nullptr)
        {
            *pbytes = aio->bytes;
        }
        return aio->err;
    }
}
Esempio n. 7
0
void call(int i)                              /* CALL, INVOKE for i = 0, 1 */
{
    int  gkk, li, sym ;  double  val ;
    ptr  p, q, s ;   dsptr  r ;

    if (!runf) derror(22) ;
    p=getvar() ; if (errnum) derror(errnum) ;
    if (p==NULL) derror (201) ;                        /* undefined */
    /* defined, get parameters */
    sym=p->symtype ;                                   /* save type */
    if (i==0 && sym<8 || i>0 && sym!= -59) derror(201) ;
    p->SWITCH=FALSE ;                          /* prevent recursion */
    q=p ;          /* save pointer to procedure or macro definition */

    if (warea[++gi]==')') {                         /* done or ...  */
	if (p->next==NULL) goto L10 ; derror(56) ; }    /* ... mismatch */
    if (p->next==NULL) derror(56) ;                     /* mismatch */
    p=p->next ;                      /* else link to first argument */

    if (i>0) goto L85 ;                                   /* invoke */
    if (warea[gi]==';') {
	if (sym==8) goto L80 ; derror(56) ; } /* call */
    if (sym==8) derror(56) ;                            /* mismatch */

    li=0 ;                          /* call, count value parameters */
    L9 :   li++ ;
    p->SWITCH=TRUE ;                      /* turn local variable ON */
    if (p->symtype==1) relval[p->valptr]=evalexp() ;        /* REAL */
    else if (p->symtype==3)                              /* COMPLEX */
	cvalexp(relval[p->valptr],relval[p->valptr+1]) ;
    else {
	val=evalexp() ;if (errnum) derror(errnum) ;       /* INTEGER */
	if (val>maxint || -val>maxint) derror(20) ;
	intval[p->valptr]=(int) val ;
    }
    if (errnum) derror(errnum) ;

    if (warea[gi]==')') {
	if (p->next==NULL) goto L10 ; derror(56) ; }    /* done */
    if (p->next==NULL) derror(56) ;                     /* mismatch */
    p=p->next ;                       /* else link to next argument */

    if (warea[gi]==';') {               /* no more value parameters */
	if (sym==8+li) goto L80 ; derror(56) ; }
    if (warea[gi]==',') { gi++ ; goto L9 ; } derror(56) ;   /* next */

    L80 :  gi++ ;             /* skip ';' or ',', deal with VAR parameters */
    L85 :  p->SWITCH=TRUE;                       /* turn local variable ON */
    gkk=gi ; s=getvar() ;                     /* might be an array! */
    if (errnum) {
	if (errnum==73) {
	    errnum=0 ;
	    gi=gkk ; start=1 ; s=getvar() ; start=0 ;
	    if (errnum) derror(errnum) ;
	    if (s==NULL || s->symtype!= -1) derror(196) ;
	    p->valptr=s->valptr ;               /* pass array address */
	    goto L87 ;
	}
	derror(errnum) ;
    }

    /*$$*/ if (s==NULL) s=instal() ;             /* no array, install REAL */

    if (s->symtype== -1 && p->symtype==1) goto L90 ;
    if (s->symtype!=p->symtype && s->symtype!= -p->symtype) derror(56) ;
    /* no match */
    L90 :  if (s->symtype>0) p->valptr=s->valptr ;    /* pass by reference */
    else {
	if (s->symtype== -1)                         /* relval index */
	    p->valptr=intval[intval[s->valptr]+s->valptr+1]+getsub(s) ;
	else if (s->symtype== -2)                    /* intval index */
	    p->valptr=intval[s->valptr]+s->valptr+1+getsub(s) ;
	else p->valptr=intval[intval[s->valptr]+s->valptr+1]+2*getsub(s) ;
    }

    L87 :  if (warea[gi]==')') {
	if (p->next==NULL) goto L10 ; derror(56) ; }
    if (p->next==NULL) derror(56) ;
    p=p->next ;

    if (warea[gi]==',') goto L80 ;            /* next VAR parameter */
    derror(33) ;                                 /* bad termination */

    L10 :  gi++ ;                                                /* skip ) */
    /* control stack for return */

    r= (struct dstak*) malloc(sizeof(struct dstak)) ;
    r->head='C' ;
    r->cvar=q ;
    r->radd=gi ;                                      /* on lf or | */
    r->dslink=stktop ;
    stktop=r ;
    flag1=TRUE ;                     /* prevents nested definitions */
    gi=q->valptr ;                              /* go to subroutine */

    if (tracer>0) {
	if (tracer==2 || tracer==3 || tracer>=6) {
	    printf("%c%s",'\33',"[7m") ;        /* ANSI reverse video */
	    printf("%s%s%c","G: EXECUTING PROCEDURE ",q->name,'\n') ;
	    printf("%c%s",'\33',"[0m") ;        /* ANSI restore video */
	}
    }
}                                                       /* call */
int
android_parse_options( int  *pargc, char**  *pargv, AndroidOptions*  opt )
{
    int     nargs = *pargc-1;
    char**  aread = *pargv+1;
    char**  awrite = aread;

    memset( opt, 0, sizeof *opt );

    while (nargs > 0) {
        char*  arg;
        char   arg2_tab[64], *arg2 = arg2_tab;
        int    nn;

        /* process @<name> as a special exception meaning
         * '-avd <name>'
         */
        if (aread[0][0] == '@') {
            opt->avd = aread[0]+1;
            nargs--;
            aread++;
            continue;
        }

        /* anything that isn't an option past this points
         * exits the loop
         */
        if (aread[0][0] != '-') {
            break;
        }

        arg = aread[0]+1;

        /* an option cannot contain an underscore */
        if (strchr(arg, '_') != NULL) {
            break;
        }

        nargs--;
        aread++;

        /* for backwards compatibility with previous versions */
        if (!strcmp(arg, "verbose")) {
            arg = "debug-init";
        }

        /* special handing for -debug <tags> */
        if (!strcmp(arg, "debug")) {
            if (nargs == 0) {
                derror( "-debug must be followed by tags (see -help-verbose)\n");
                exit(1);
            }
            nargs--;
            parse_debug_tags(*aread++);
            continue;
        }

        /* NOTE: variable tables map option names to values
         * (e.g. field offsets into the AndroidOptions structure).
         *
         * however, the names stored in the table used underscores
         * instead of dashes. this means that the command-line option
         * '-foo-bar' will be associated to the name 'foo_bar' in
         * this table, and will point to the field 'foo_bar' or
         * AndroidOptions.
         *
         * as such, before comparing the current option to the
         * content of the table, we're going to translate dashes
         * into underscores.
         */
        arg2 = arg2_tab;
        buffer_translate_char( arg2_tab, sizeof(arg2_tab),
                               arg, '-', '_');

        /* special handling for -debug-<tag> and -debug-no-<tag> */
        if (!memcmp(arg2, "debug_", 6)) {
            int            remove = 0;
            unsigned long  mask   = 0;
            arg2 += 6;
            if (!memcmp(arg2, "no_", 3)) {
                arg2  += 3;
                remove = 1;
            }
            if (!strcmp(arg2, "all")) {
                mask = ~0;
            }
            for (nn = 0; debug_tags[nn].name; nn++) {
                if (!strcmp(arg2, debug_tags[nn].name)) {
                    mask = (1UL << debug_tags[nn].flag);
                    break;
                }
            }
            if (remove)
                android_verbose &= ~mask;
            else
                android_verbose |= mask;
            continue;
        }

        /* look into our table of options
         *
         */
        {
            const OptionInfo*  oo = option_keys;

            for ( ; oo->name; oo++ ) {
                if ( !strcmp( oo->name, arg2 ) ) {
                    void*  field = (char*)opt + oo->var_offset;

                    if (oo->var_is_param) {
                        /* parameter option */
                        if (nargs == 0) {
                            derror( "-%s must be followed by parameter (see -help-%s)",
                                    arg, arg );
                            exit(1);
                        }
                        nargs--;
                        ((char**)field)[0] = *aread++;
                    } else {
                        /* flag option */
                        ((int*)field)[0] = 1;
                    }
                    break;
                }
            }

            if (oo->name == NULL) {  /* unknown option ? */
                nargs++;
                aread--;
                break;
            }
        }
    }

    /* copy remaining parameters, if any, to command line */
    *pargc = nargs + 1;

    while (nargs > 0) {
        awrite[0] = aread[0];
        awrite ++;
        aread  ++;
        nargs  --;
    }

    awrite[0] = NULL;

    return 0;
}
Esempio n. 9
0
File: close.c Progetto: schwehr/hdf4
static void
cl_netcdf()
{
    if (ncclose(ncid) == -1)
      derror ("error closing netcdf");
}
Esempio n. 10
0
// if network_interface is "", then return the first "eth" prefixed non-loopback ipv4 address.
DSN_API uint32_t dsn_ipv4_local(const char* network_interface)
{
    uint32_t ret = 0;

# ifndef _WIN32
    static const char loopback[4] = { 127, 0, 0, 1 };
    struct ifaddrs* ifa = nullptr;
    if (getifaddrs(&ifa) == 0)
    {
        struct ifaddrs* i = ifa;
        while (i != nullptr)
        {
            if (i->ifa_name != nullptr &&
                i->ifa_addr != nullptr 
                )
            {
                if (strcmp(i->ifa_name, network_interface) == 0 ||
                    (network_interface[0] == '\0' && strncmp(i->ifa_name, "eth", 3) == 0)
                   )
                {
                    if (i->ifa_addr->sa_family == AF_INET && 
                        (network_interface[0] != '\0' || strncmp((const char*)&((struct sockaddr_in *)i->ifa_addr)->sin_addr.s_addr, loopback, 4) != 0))
                    {
                        ret = (uint32_t)ntohl(((struct sockaddr_in *)i->ifa_addr)->sin_addr.s_addr);
                        break;
                    }

                    // sometimes the sa_family is not AF_INET but we can still try 
                    else
                    {
                        int fd = socket(AF_INET, SOCK_DGRAM, 0);
                        struct ifreq ifr;
                        
                        ifr.ifr_addr.sa_family = AF_INET;
                        strncpy(ifr.ifr_name, i->ifa_name, IFNAMSIZ - 1);

                        auto err = ioctl(fd, SIOCGIFADDR, &ifr);
                        if (err == 0 &&
                            (network_interface[0] != '\0' || strncmp((const char*)&((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr, loopback, 4) != 0))
                        {
                            ret = (uint32_t)ntohl(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr);
                            break;
                        }
                    }
                }
            }
            i = i->ifa_next;
        }

        if (i == nullptr)
        {
            derror("get local ip from network interfaces failed, network_interface = %s", network_interface);
        }

        if (ifa != nullptr)
        {
            // remember to free it
            freeifaddrs(ifa);
        }
    }
#endif

    return ret;
}
Esempio n. 11
0
        // run in replica thread
        void replica::init_checkpoint()
        {
            // only applicable to primary and secondary replicas
            if (status() != PS_PRIMARY && status() != PS_SECONDARY)
                return;

            // no need to checkpoint
            if (_app->is_delta_state_learning_supported())
                return;

            auto err = _app->checkpoint_async();
            if (err != ERR_NOT_IMPLEMENTED)
            {
                if (err == ERR_OK)
                {
                    ddebug("%s: checkpoint_async succeed, app_last_committed_decree=%" PRId64 ", app_last_durable_decree=%" PRId64,
                           name(), _app->last_committed_decree(), _app->last_durable_decree());
                }
                if (err != ERR_OK && err != ERR_WRONG_TIMING && err != ERR_NO_NEED_OPERATE && err != ERR_TRY_AGAIN)
                {
                    derror("%s: checkpoint_async failed, err = %s", name(), err.to_string());
                }
                return;
            }

            // private log must be enabled to make sure commits
            // are not lost during checkpinting
            dassert(nullptr != _private_log, "log_enable_private_prepare must be true for checkpointing");

            if (last_committed_decree() - last_durable_decree() < _options->checkpoint_min_decree_gap)
                return;

            // primary cannot checkpoint (TODO: test if async checkpoint is supported)
            // therefore we have to copy checkpoints from secondaries
            if (PS_PRIMARY == status())
            {
                // only one running instance
                if (nullptr == _primary_states.checkpoint_task)
                {
                    if (_primary_states.membership.secondaries.size() == 0)
                        return;

                    std::shared_ptr<replica_configuration> rc(new replica_configuration);
                    _primary_states.get_replica_config(PS_SECONDARY, *rc);

                    rpc_address sd = _primary_states.membership.secondaries
                        [dsn_random32(0, (int)_primary_states.membership.secondaries.size() - 1)];

                    _primary_states.checkpoint_task = rpc::call_typed(
                        sd,
                        RPC_REPLICA_COPY_LAST_CHECKPOINT,
                        rc,
                        this,
                        &replica::on_copy_checkpoint_ack,
                        gpid_to_hash(get_gpid())
                        );
                }
            }

            // secondary can start checkpint in the long running thread pool
            else
            {
                dassert(PS_SECONDARY == status(), "");

                // only one running instance
                if (!_secondary_states.checkpoint_is_running)
                {
                    _secondary_states.checkpoint_is_running = true;
                    tasking::enqueue(
                        &_secondary_states.checkpoint_task,
                        LPC_CHECKPOINT_REPLICA,
                        this,
                        &replica::background_checkpoint,
                        gpid_to_hash(get_gpid())
                        );
                }                
            }
        }
Esempio n. 12
0
        void nfs_service_impl::on_copy(const ::dsn::service::copy_request& request, ::dsn::rpc_replier< ::dsn::service::copy_response>& reply)
        {
            //dinfo(">>> on call RPC_COPY end, exec RPC_NFS_COPY");

            std::string file_path = dsn::utils::filesystem::path_combine(request.source_dir, request.file_name);
            dsn_handle_t hfile;

            {
                zauto_lock l(_handles_map_lock);
                auto it = _handles_map.find(file_path); // find file handle cache first

                if (it == _handles_map.end()) // not found
                {
                    hfile = dsn_file_open(file_path.c_str(), O_RDONLY | O_BINARY, 0);
                    if (hfile)
                    {
                    
                        file_handle_info_on_server* fh = new file_handle_info_on_server;
                        fh->file_handle = hfile;
                        fh->file_access_count = 1;
                        fh->last_access_time = dsn_now_ms();
                        _handles_map.insert(std::pair<std::string, file_handle_info_on_server*>(file_path, fh));
                    }
                }
                else // found
                {
                    hfile = it->second->file_handle;
                    it->second->file_access_count++;
                    it->second->last_access_time = dsn_now_ms();
                }
            }

            dinfo("nfs: copy file %s [%" PRId64 ", %" PRId64 ")",
                file_path.c_str(),
                request.offset,
                request.offset + request.size
                );

            if (hfile == 0)
            {
                derror("file open failed");
                ::dsn::service::copy_response resp;
                resp.error = ERR_OBJECT_NOT_FOUND;
                reply(resp);
                return;
            }

            callback_para cp(reply);
            cp.bb = blob(
                std::shared_ptr<char>(new char[_opts.nfs_copy_block_bytes], std::default_delete<char[]>{}),
                _opts.nfs_copy_block_bytes);
            cp.dst_dir = std::move(request.dst_dir);
            cp.file_path = std::move(file_path);
            cp.hfile = hfile;
            cp.offset = request.offset;
            cp.size = request.size;

            auto buffer_save = cp.bb.buffer().get();
            file::read(
                hfile,
                buffer_save,
                request.size,
                request.offset,
                LPC_NFS_READ,
                this,
                [this, cp_cap = std::move(cp)] (error_code err, int sz)
                {
                    internal_read_callback(err, sz, std::move(cp_cap));
                }
                );
        }
Esempio n. 13
0
        // RPC_NFS_NEW_NFS_GET_FILE_SIZE 
        void nfs_service_impl::on_get_file_size(const ::dsn::service::get_file_size_request& request, ::dsn::rpc_replier< ::dsn::service::get_file_size_response>& reply)
        {
            //dinfo(">>> on call RPC_NFS_GET_FILE_SIZE end, exec RPC_NFS_GET_FILE_SIZE");

            get_file_size_response resp;
            error_code err = ERR_OK;
            std::vector<std::string> file_list;
            std::string folder = request.source_dir;
            if (request.file_list.size() == 0) // return all file size in the destination file folder
            {
                if (!dsn::utils::filesystem::directory_exists(folder))
                {
                    err = ERR_OBJECT_NOT_FOUND;
                }
                else
                {
                    if (!dsn::utils::filesystem::get_subfiles(folder, file_list, true))
                    {
                        err = ERR_FILE_OPERATION_FAILED;
                    }
                    else
                    {
                        for (auto& fpath : file_list)
                        {
                            // TODO: using uint64 instead as file ma
                            // Done
                            int64_t sz;
                            if (!dsn::utils::filesystem::file_size(fpath, sz))
                            {
                                dassert(false, "Fail to get file size of %s.", fpath.c_str());
                            }

                            resp.size_list.push_back((uint64_t)sz);
                            resp.file_list.push_back(fpath.substr(request.source_dir.length(), fpath.length() - 1));
                        }
                        file_list.clear();
                    }
                }
            }
            else // return file size in the request file folder
            {
                for (size_t i = 0; i < request.file_list.size(); i++)
                {
                    std::string file_path = dsn::utils::filesystem::path_combine(folder, request.file_list[i]);

                    struct stat st;
                    if (0 != ::stat(file_path.c_str(), &st))
                    {
                        derror("file open %s failed, err = %s", file_path.c_str(), strerror(errno));
                        err = ERR_OBJECT_NOT_FOUND;
                        break;
                    }

                    // TODO: using int64 instead as file may exceed the size of 32bit
                    // Done
                    uint64_t size = st.st_size;

                    resp.size_list.push_back(size);
                    resp.file_list.push_back((folder + request.file_list[i]).substr(request.source_dir.length(), (folder + request.file_list[i]).length() - 1));
                }
            }

            resp.error = err.get();
            reply(resp);
        }
Esempio n. 14
0
/*
 * Generate code for creating netCDF from in-memory structure.
 */
void
gen_ncjava_std(const char *filename)
{
    int idim, ivar, iatt, maxdims;
    int ndims, nvars, natts, ngatts, ngrps, ntyps;
    char* cmode_string;

    jcode = bbNew();
    bbSetalloc(jcode,C_MAX_STMT);

    ndims = listlength(dimdefs);
    nvars = listlength(vardefs);
    natts = listlength(attdefs);
    ngatts = listlength(gattdefs);
    ngrps = listlength(grpdefs);
    ntyps = listlength(typdefs);

    /* Construct the main class */
    jline("import java.util.*;");
    jline("import ucar.ma2.*;");
    jline("import ucar.nc2.*;");
    jline("import ucar.nc2.NetcdfFile.*;");

    jline("");
    jpartial("public class ");
    jline(mainname);
    jline("{");

    /* Now construct the main procedure*/

    jline("");
    jline("static public void main(String[] argv) throws Exception");
    jline("{");


    /* create necessary declarations */

    if (ndims > 0) {
	jline("");
	jlined(1,"/* dimension lengths */");
	for(idim = 0; idim < ndims; idim++) {
	    Symbol* dsym = (Symbol*)listget(dimdefs,idim);
	    if (dsym->dim.size == NC_UNLIMITED) {
		nprintf(stmt,sizeof(stmt),"%sfinal int %s_len = 0;",
			indented(1),jname(dsym));
	    } else {
		nprintf(stmt,sizeof(stmt),"%sfinal int %s_len = %lu;",
			indented(1),
			jname(dsym),
			(unsigned long) dsym->dim.size);
	    }
	    jline(stmt);
	}
    }
    jflush();

    maxdims = 0;	/* most dimensions of any variable */
    for(ivar = 0; ivar < nvars; ivar++) {
      Symbol* vsym = (Symbol*)listget(vardefs,ivar);
      if(vsym->typ.dimset.ndims > maxdims)
	maxdims = vsym->typ.dimset.ndims;
    }

    jline("");
#ifdef DOTHROW
    jlined(1,"try {");
#endif

    /* create netCDF file, uses NC_CLOBBER mode */
    jline("");
    jlined(1,"/* enter define mode */");

    if (!cmode_modifier) {
	cmode_string = "NC_CLOBBER";
    } else if (cmode_modifier & NC_64BIT_OFFSET) {
	cmode_string = "NC_CLOBBER|NC_64BIT_OFFSET";
    } else {
        derror("unknown cmode modifier");
	cmode_string = "NC_CLOBBER";
    }

    nprintf(stmt,sizeof(stmt),
                "NetcdfFileWriteable ncfile = NetcdfFileWriteable.createNew(\"%s\", %s);",
		 filename,(nofill_flag?"false":"true"));
    jlined(1,stmt);
    jflush();
    
    /* define dimensions from info in dims array */
    if (ndims > 0) {
	jline("");
	jlined(1,"/* define dimensions */");
        for(idim = 0; idim < ndims; idim++) {
            Symbol* dsym = (Symbol*)listget(dimdefs,idim);
	    if(dsym->dim.size == NC_UNLIMITED) {
                nprintf(stmt,sizeof(stmt),"Dimension %s_dim = ncfile.addUnlimitedDimension(\"%s\");",
                    jname(dsym),jescapifyname(dsym->name));
	    } else {
                nprintf(stmt,sizeof(stmt),"Dimension %s_dim = ncfile.addDimension(\"%s\", %s_len);",
                    jname(dsym),jescapifyname(dsym->name), jname(dsym));
	    }
            jlined(1,stmt);
       }
       jflush();
    }

    /* define variables from info in vars array */
    if (nvars > 0) {
        jline("");
        jlined(1,"/* define variables */");
        for(ivar = 0; ivar < nvars; ivar++) {
            Symbol* vsym = (Symbol*)listget(vardefs,ivar);
            Symbol* basetype = vsym->typ.basetype;
            Dimset* dimset = &vsym->typ.dimset;
            jline("");
            nprintf(stmt,sizeof(stmt),"ArrayList %s_dimlist = new ArrayList();",
                                        jname(vsym));
            jlined(1,stmt);
            if(dimset->ndims > 0) {
                for(idim = 0; idim < dimset->ndims; idim++) {
                    Symbol* dsym = dimset->dimsyms[idim];
                    nprintf(stmt,sizeof(stmt),"%s_dimlist.add(%s_dim);",
                            jname(vsym),jname(dsym));
                    jlined(1,stmt);
                }
	    }
            nprintf(stmt,sizeof(stmt),
                            "ncfile.addVariable(\"%s\", DataType.%s, %s_dimlist);",
                            jescapifyname(vsym->name),
                            jtypeallcaps(basetype->typ.typecode),
                            jname(vsym));
            jlined(1,stmt);
        }
        jflush();
    }
        
    /* Define the global attributes*/
    if(ngatts > 0) {
        jline("");
        jlined(1,"/* assign global attributes */");
        for(iatt = 0; iatt < ngatts; iatt++) {
            Symbol* gasym = (Symbol*)listget(gattdefs,iatt);
            genjstd_defineattribute(gasym);            
        }
        jline("");
        jflush();
    }
    
    /* Define the variable specific attributes*/
    if(natts > 0) {
        jline("");
        jlined(1,"/* assign per-variable attributes */");
        for(iatt = 0; iatt < natts; iatt++) {
            Symbol* asym = (Symbol*)listget(attdefs,iatt);
            genjstd_defineattribute(asym);
        }
        jline("");
        jflush();
    }

    jlined(1,"ncfile.create();"); /* equiv to nc_enddef */

    /* Load values into those variables with defined data */

    if(nvars > 0) {
        jline("");
        jlined(1,"/* assign variable data */");
        for(ivar = 0; ivar < nvars; ivar++) {
            Symbol* vsym = (Symbol*)listget(vardefs,ivar);
            if(vsym->data != NULL) genjstd_definevardata(vsym);
        }
        jline("");
        /* compute the max actual size of the unlimited dimension*/
        if(usingclassic) computemaxunlimited();
    }
    jflush();

}
Esempio n. 15
0
int
main(
	int argc,
	char *argv[])
{
    int c;
    FILE *fp;
	struct Languages* langs;
    char* lang_name;
#ifdef __hpux
    setlocale(LC_CTYPE,"");
#endif

    init_netcdf();

    opterr = 1;			/* print error message if bad option */
    progname = ubasename(argv[0]);
    cdlname = "-";
    netcdf_name = NULL;
    datasetname = NULL;
    l_flag = 0;
    nofill_flag = 0;
    syntax_only = 0;
    header_only = 0;
    mainname = "main";
    nciterbuffersize = 0;

    k_flag = 0;
    format_flag = 0;
    format_attribute = 0;
    enhanced_flag = 0;
    specials_flag = 0;

    diskless = 0;

#if _CRAYMPP && 0
    /* initialize CRAY MPP parallel-I/O library */
    (void) par_io_init(32, 32);
#endif

    while ((c = getopt(argc, argv, "hbcfk:3467l:no:v:xdM:D:B:P")) != EOF)
      switch(c) {
	case 'd':
	  debug = 1;
	  break;
	case 'D':
	  debug = atoi(optarg);
	  break;
	case 'c': /* for c output, old version of "-lc" */
	  if(l_flag != 0) {
	    fprintf(stderr,"Please specify only one language\n");
	    return 1;
	  }
	  l_flag = L_C;
	  fprintf(stderr,"-c is deprecated: please use -lc\n");
	  break;
	case 'f': /* for f77 output, old version of "-lf" */
	  if(l_flag != 0) {
	    fprintf(stderr,"Please specify only one language\n");
	    return 1;
	  }
	  l_flag = L_F77;
	  fprintf(stderr,"-f is deprecated: please use -lf77\n");
	  break;
	case 'b': /* for binary netcdf output, ".nc" extension */
	  if(l_flag != 0) {
	    fprintf(stderr,"Please specify only one language\n");
	    return 1;
	  }
	  l_flag = L_BINARY;
	  break;
	case 'h':
	  header_only = 1;
	  break;
    case 'l': /* specify language, instead of using -c or -f or -b */

      {
		if(l_flag != 0) {
          fprintf(stderr,"Please specify only one language\n");
          return 1;
		}
        if(!optarg) {
          derror("%s: output language is null",
                 progname);
          return(1);
        }
        lang_name = (char*) emalloc(strlen(optarg)+1);
		(void)strcpy(lang_name, optarg);
		for(langs=legallanguages;langs->name != NULL;langs++) {
          if(strcmp(lang_name,langs->name)==0) {
			l_flag = langs->flag;
            break;
          }
		}
		if(langs->name == NULL) {
          derror("%s: output language %s not implemented",
                 progname, lang_name);
          return(1);
		}
      }
	  break;
	case 'n':		/* old version of -b, uses ".cdf" extension */
	  if(l_flag != 0) {
	    fprintf(stderr,"Please specify only one language\n");
	    return 1;
	  }
	  l_flag = L_BINARY;
          binary_ext = ".cdf";
	  break;
	case 'o':		/* to explicitly specify output name */
	  netcdf_name = nulldup(optarg);
	  break;
	case 'x': /* set nofill mode to speed up creation of large files */
	  nofill_flag = 1;
	  break;
        case 'v': /* a deprecated alias for "kind" option */
	    /*FALLTHRU*/
	case 'k': /* for specifying variant of netCDF format to be generated
		     Possible values are:
		     Format names:
		       "classic" or "nc3"
		       "64-bit offset" or "nc6"
		       "netCDF-4" or "nc4"
		       "netCDF-4 classic model" or "nc7"
		     Format version numbers (deprecated):
		       1 (=> classic)
		       2 (=> 64-bit offset)
		       3 (=> netCDF-4)
		       4 (=> netCDF-4 classic model)
		   */
	    {
		struct Kvalues* kvalue;
		char *kind_name = (optarg != NULL ? (char *) emalloc(strlen(optarg)+1)
                           : emalloc(1));
		if (! kind_name) {
		    derror ("%s: out of memory", progname);
		    return(1);
		}
        if(optarg != NULL)
          (void)strcpy(kind_name, optarg);
        for(kvalue=legalkinds;kvalue->name;kvalue++) {
          if(strcmp(kind_name,kvalue->name) == 0) {
            k_flag = kvalue->k_flag;
			break;
          }
		}
		if(kvalue->name == NULL) {
		   derror("Invalid format: %s",kind_name);
		   return 2;
		}
	    }
	  break;
	case '3':		/* output format is classic (netCDF-3) */
	    k_flag = NC_FORMAT_CLASSIC;
	    break;
	case '6':		/* output format is 64-bit-offset (netCDF-3 version 2) */
	    k_flag = NC_FORMAT_64BIT;
	    break;
	case '4':		/* output format is netCDF-4 (variant of HDF5) */
	    k_flag = NC_FORMAT_NETCDF4;
	    break;
	case '7':		/* output format is netCDF-4 (restricted to classic model)*/
	    k_flag = NC_FORMAT_NETCDF4_CLASSIC;
	    break;
	case 'M': /* Determine the name for the main function */
	    mainname = nulldup(optarg);
	    break;
	case 'B':
	  nciterbuffersize = atoi(optarg);
	  break;
	case 'P': /* diskless with persistence */
	  diskless = 1;
	  break;
	case '?':
	  usage();
	  return(8);
      }

    if(l_flag == 0) {
	l_flag = L_BINARY; /* default */
	/* Treat -k or -o as an implicit -lb assuming no other -l flags */
        if(k_flag == 0 && netcdf_name == NULL)
	    syntax_only = 1;
    }

    /* Compute/default the iterator buffer size */
    if(l_flag == L_BINARY) {
	if(nciterbuffersize == 0 )
	    nciterbuffersize = DFALTBINNCITERBUFFERSIZE;
    } else {
	if(nciterbuffersize == 0)
	    nciterbuffersize = DFALTLANGNCITERBUFFERSIZE;
    }

#ifndef ENABLE_C
    if(c_flag) {
	  fprintf(stderr,"C not currently supported\n");
	  exit(1);
    }
#endif
#ifndef ENABLE_BINARY
    if(l_flag == L_BINARY) {
	  fprintf(stderr,"Binary netcdf not currently supported\n");
	  exit(1);
    }
#endif
#ifndef ENABLE_JAVA
    if(l_flag == L_JAVA) {
	  fprintf(stderr,"Java not currently supported\n");
	  exit(1);
    }
#else
    if(l_flag == L_JAVA && strcmp(mainname,"main")==0)
	mainname = "Main";
#endif
#ifndef ENABLE_F77
    if(l_flag == L_F77) {
	  fprintf(stderr,"F77 not currently supported\n");
	  exit(1);
    }
#endif

    if(l_flag != L_BINARY)
	diskless = 0;

    argc -= optind;
    argv += optind;

    if (argc > 1) {
	derror ("%s: only one input file argument permitted",progname);
	return(6);
    }

    fp = stdin;
    if (argc > 0 && strcmp(argv[0], "-") != 0) {
	char bom[4];
	size_t count;
	if ((fp = fopen(argv[0], "r")) == NULL) {
	    derror ("can't open file %s for reading: ", argv[0]);
	    perror("");
	    return(7);
	}
   	/* Check the leading bytes for an occurrence of a BOM */
        /* re: http://www.unicode.org/faq/utf_bom.html#BOM */
	/* Attempt to read the first four bytes */
	memset(bom,0,sizeof(bom));
	count = fread(bom,1,2,fp);
	if(count == 2) {
	    switch (bom[0]) {
	    case '\x00':
	    case '\xFF':
	    case '\xFE':
	        /* Only UTF-* is allowed; complain and exit */
		fprintf(stderr,"Input file contains a BOM indicating a non-UTF8 encoding\n");
		return 1;
	    case '\xEF':
		/* skip the BOM */
	        fread(bom,1,1,fp);
	        break;
	    default: /* legal printable char, presumably; rewind */
	        rewind(fp);
		break;
	    }
	}

	cdlname = (char*)emalloc(NC_MAX_NAME);
	cdlname = nulldup(argv[0]);
	if(cdlname != NULL) {
	  if(strlen(cdlname) > NC_MAX_NAME)
	    cdlname[NC_MAX_NAME] = '\0';
	}
    }

    /* Standard Unidata java interface => usingclassic */

    parse_init();
    ncgin = fp;
    if(debug >= 2) {ncgdebug=1;}
    if(ncgparse() != 0)
        return 1;

    /* Compute the k_flag (1st pass) using rules in the man page (ncgen.1).*/

#ifndef USE_NETCDF4
    if(enhanced_flag) {
	derror("CDL input is enhanced mode, but --disable-netcdf4 was specified during build");
	return 0;
    }
#endif

    if(l_flag == L_JAVA || l_flag == L_F77) {
        k_flag = 1;
	if(enhanced_flag) {
	    derror("Java or Fortran requires classic model CDL input");
	    return 0;
	}
    }

    if(k_flag == 0)
	k_flag = format_flag;

    if(enhanced_flag && k_flag == 0)
	k_flag = 3;

    if(enhanced_flag && k_flag != 3) {
	derror("-k or _Format conflicts with enhanced CDL input");
	return 0;
    }

    if(specials_flag > 0 && k_flag == 0)
#ifdef USE_NETCDF4
	k_flag = 3;
#else
	k_flag = 1;
#endif

    if(k_flag == 0)
	k_flag = 1;

    usingclassic = (k_flag <= 2 || k_flag == 4)?1:0;

    /* compute cmode_modifier */
    switch (k_flag) {
    case 1: cmode_modifier = 0; break;
    case 2: cmode_modifier = NC_64BIT_OFFSET; break;
    case 3: cmode_modifier = NC_NETCDF4; break;
    case 4: cmode_modifier = NC_NETCDF4 | NC_CLASSIC_MODEL; break;
    default: ASSERT(0); /* cannot happen */
    }

    if(diskless)
	cmode_modifier |= (NC_DISKLESS|NC_NOCLOBBER);

    processsemantics();
    if(!syntax_only && error_count == 0)
        define_netcdf();

    return 0;
}
Esempio n. 16
0
void simulator::on_system_exit(sys_exit_type st)
{
    derror("system exits, you can replay this process using random seed %d",        
        sim_env_provider::seed()
        );
}
Esempio n. 17
0
/*
 *  handles the "directive" state after the "normal" state
 */
static int direci(lex_t *t)
{
    int i = NELEM(dtab);

    assert(!cond_ignore());

    NEXTSP(t);    /* consumes # */
    if (t->id == LEX_ID) {
        const char *n = LEX_SPELL(t);
        for (i = 0; i < NELEM(dtab); i++)
            if (strcmp(n, dtab[i].name) == 0)
                break;
        switch(i) {
            case DINCLUDE:
                t = dinclude(t->pos);
                break;
            case DDEFINE:
                /* ddefine() moved into mcr.c for macros from -D */
                t = mcr_define(t->pos, 0);
                break;
            case DUNDEF:
                t = dundef(t->pos);
                break;
            case DIF:
                t = dif(t->pos, COND_KIF, 0);
                break;
            case DIFDEF:
                t = dif(t->pos, COND_KIFDEF, 0);
                break;
            case DIFNDEF:
                t = dif(t->pos, COND_KIFNDEF, 0);
                break;
            case DELIF:
                t = delif(t->pos);
                break;
            case DELSE:
                t = delse(t->pos);
                break;
            case DENDIF:
                t = dendif(t->pos);
                break;
            case DLINE:
                t = dline(t->pos);
                break;
            case DERROR:
                t = derror(t->pos, 0);
                break;
            case DPRAGMA:
                t = dpragma(t->pos);
                break;
            case DWARNING:
                t = derror(t->pos, 1);
                break;
            default:
                err_dpos(t->pos, ERR_PP_UNKNOWNDIR);
                break;
        }
    } else
        i = DUNDEF;

    if (warnxtra[i]) {
        SKIPSP(t);
        if (t->id != LEX_NEWLINE)
            t = xtratok(t);
    }
    SKIPNL(t);
    lst_discard(1);
    lex_direc = 0;

    return 0;
}
ClientFramebuffer*
clientfb_create(SockAddress* console_socket,
                const char* protocol,
                QFrameBuffer* fb)
{
    char* connect_message = NULL;
    char switch_cmd[256];

    // Connect to the framebuffer service.
    _client_fb.core_connection = core_connection_create(console_socket);
    if (_client_fb.core_connection == NULL) {
        derror("Framebuffer client is unable to connect to the console: %s\n",
               errno_str);
        return NULL;
    }
    if (core_connection_open(_client_fb.core_connection)) {
        core_connection_free(_client_fb.core_connection);
        _client_fb.core_connection = NULL;
        derror("Framebuffer client is unable to open the console: %s\n",
               errno_str);
        return NULL;
    }
    snprintf(switch_cmd, sizeof(switch_cmd), "framebuffer %s", protocol);
    if (core_connection_switch_stream(_client_fb.core_connection, switch_cmd,
                                      &connect_message)) {
        derror("Unable to attach to the framebuffer %s: %s\n",
               switch_cmd, connect_message ? connect_message : "");
        if (connect_message != NULL) {
            free(connect_message);
        }
        core_connection_close(_client_fb.core_connection);
        core_connection_free(_client_fb.core_connection);
        _client_fb.core_connection = NULL;
        return NULL;
    }

    // We expect core framebuffer to return us bits per pixel property in
    // the handshake message.
    _client_fb.bits_per_pixel = 0;
    if (connect_message != NULL) {
        char* bpp = strstr(connect_message, "bitsperpixel=");
        if (bpp != NULL) {
            char* end;
            bpp += strlen("bitsperpixel=");
            end = strchr(bpp, ' ');
            if (end == NULL) {
                end = bpp + strlen(bpp);
            }
            _client_fb.bits_per_pixel = strtol(bpp, &end, 0);
        }
    }

    if (!_client_fb.bits_per_pixel) {
        derror("Unexpected core framebuffer reply: %s\n"
               "Bits per pixel property is not there, or is invalid\n", connect_message);
        core_connection_close(_client_fb.core_connection);
        core_connection_free(_client_fb.core_connection);
        _client_fb.core_connection = NULL;
        return NULL;
    }

    // Now that we're connected lets initialize the descriptor.
    _client_fb.fb = fb;
    _client_fb.sock = core_connection_get_socket(_client_fb.core_connection);
    _client_fb.fb_state = WAIT_HEADER;
    _client_fb.reader_buffer = (uint8_t*)&_client_fb.update_header;
    _client_fb.reader_offset = 0;
    _client_fb.reader_bytes = sizeof(FBUpdateMessage);

    if (connect_message != NULL) {
        free(connect_message);
    }

    // At last setup read callback, and start receiving the updates.
    if (qemu_set_fd_handler(_client_fb.sock, _clientfb_read_cb, NULL, &_client_fb)) {
        derror("Unable to set up framebuffer read callback\n");
        core_connection_close(_client_fb.core_connection);
        core_connection_free(_client_fb.core_connection);
        _client_fb.core_connection = NULL;
        return NULL;
    }
    {
        // Force the core to send us entire framebuffer now, when we're prepared
        // to receive it.
        FBRequestHeader hd;
        SyncSocket* sk = syncsocket_init(_client_fb.sock);

        hd.request_type = AFB_REQUEST_REFRESH;
        syncsocket_start_write(sk);
        syncsocket_write(sk, &hd, sizeof(hd), 500);
        syncsocket_stop_write(sk);
        syncsocket_free(sk);
    }
    fprintf(stdout, "Framebuffer %s is now attached to the core %s\n",
            protocol, sock_address_to_string(console_socket));

    return &_client_fb;
}
Esempio n. 19
0
dsn_handle_t hpc_aio_provider::open(const char* file_name, int oflag, int pmode)
{
    DWORD dwDesiredAccess = 0;
    DWORD dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
    DWORD dwCreationDisposition = 0;
    DWORD dwFlagsAndAttributes = FILE_FLAG_OVERLAPPED;

    SECURITY_ATTRIBUTES SecurityAttributes;

    SecurityAttributes.nLength = sizeof(SecurityAttributes);
    SecurityAttributes.lpSecurityDescriptor = NULL;

    if (oflag & _O_NOINHERIT) {
        SecurityAttributes.bInheritHandle = FALSE;
    }
    else {
        SecurityAttributes.bInheritHandle = TRUE;
    }

    /*
    * decode the access flags
    */
    switch (oflag & (_O_RDONLY | _O_WRONLY | _O_RDWR)) {

    case _O_RDONLY:         /* read access */
        dwDesiredAccess = GENERIC_READ;
        break;
    case _O_WRONLY:         /* write access */
        /* giving it read access as well
        * because in append (a, not a+), we need
        * to read the BOM to determine the encoding
        * (ie. ANSI, UTF8, UTF16)
        */
        if ((oflag & _O_APPEND)
            && (oflag & (_O_WTEXT | _O_U16TEXT | _O_U8TEXT)) != 0)
        {
            dwDesiredAccess = GENERIC_READ | GENERIC_WRITE;
        }
        else
        {
            dwDesiredAccess = GENERIC_WRITE;
        }
        break;
    case _O_RDWR:           /* read and write access */
        dwDesiredAccess = GENERIC_READ | GENERIC_WRITE;
        break;
    default:                /* error, bad oflag */
        _doserrno = 0L; /* not an OS error */
        derror("Invalid open flag\n");
    }

    /*
    * decode open/create method flags
    */
    switch (oflag & (_O_CREAT | _O_EXCL | _O_TRUNC)) {
    case 0:
    case _O_EXCL:                   // ignore EXCL w/o CREAT
        dwCreationDisposition = OPEN_EXISTING;
        break;

    case _O_CREAT:
        dwCreationDisposition = OPEN_ALWAYS;
        break;

    case _O_CREAT | _O_EXCL:
    case _O_CREAT | _O_TRUNC | _O_EXCL:
        dwCreationDisposition = CREATE_NEW;
        break;

    case _O_TRUNC:
    case _O_TRUNC | _O_EXCL:        // ignore EXCL w/o CREAT
        dwCreationDisposition = TRUNCATE_EXISTING;
        break;

    case _O_CREAT | _O_TRUNC:
        dwCreationDisposition = CREATE_ALWAYS;
        break;

    default:
        // this can't happen ... all cases are covered
        _doserrno = 0L;
        derror("Invalid open flag");
    }

    /*
    * try to open/create the file
    */
    HANDLE fileHandle = ::CreateFileA(file_name,
        dwDesiredAccess,
        dwShareMode,
        &SecurityAttributes,
        dwCreationDisposition,
        dwFlagsAndAttributes,
        0);

    if (fileHandle != INVALID_HANDLE_VALUE && fileHandle != nullptr)
    {
        auto err = _looper->bind_io_handle((dsn_handle_t)fileHandle, &_callback);
        if (err != ERR_OK)
        {
            dassert(false, "cannot associate file handle %s to io completion port, err = 0x%x\n", file_name, ::GetLastError());
            return 0;
        }
        else
        {
            return (dsn_handle_t)(fileHandle);
        }
    }
    else
    {
        derror("cannot create file %s, err = 0x%x\n", file_name, ::GetLastError());
        return 0;
    }
}
Esempio n. 20
0
static void usage(void)
{
    derror("Usage: %s [ -b ] [ -c ] [ -f ] [ -k kind ] [ -x ] [ -o outfile]  [ file ... ]",
	   progname);
    derror("netcdf library version %s", nc_inq_libvers());
}
Esempio n. 21
0
void goto00(int i)                  /*  GO TO if i=1, else LABEL */
{
    ptr  p ;  symbl  oname ; register int  li ; int  gisav ;
    double  val ;
    
    if (i==0) {                                            /* LABEL */
	if (! runf) derror(22) ;
	if (warea[gi-5]==lf) goto L100 ;
	derror(79) ;                         /* not at start of line */
    }
    if (warea[gi]<'0' && warea[gi]!='(' || warea[gi]>'9') goto L100 ;
    
/* ------------------------------------------------------------------- */
                                            /* branch to line number   */
/* ------------------------------------------------------------------- */

    val=evalexp() ; if (errnum) derror(errnum) ;
    if (val<1 || val>maxlin) derror(13) ;    /* invalid line number */
    if (warea[gi]=='|') {
	if (warea[gi+1]!=vrem && warea[gi+1]!=chr11 &&
	    warea[gi+1]!=vendls) derror(81) ;
    }
    else if (warea[gi]!=lf) derror(33) ;         /* bad termination */
    
    li=linsiz+2 ;                                         /* search */
    do {
	if (BASE*warea[li]+warea[li+1]==(int) val) goto L8 ; /* found*/
	li+=warea[li+2] ;                     /* no, add line length */
    } while (li<endtxt) ;
    derror(68) ;                                       /* not found */
    
    L8 :   if (tracer>0) { if (tracer==2 || tracer==3 || tracer>=6) {
	printf("%c%s",'\33',"[7m") ;           /* ANSI reverse video */
	printf("%s%u%c","G:",lnumber,'\n') ;
	printf("%c%s",'\33',"[0m") ;           /* ANSI restore video */
    }}
    gi=li-1 ; return ;                 /* gi is on lf before target */
    
/* ------------------------------------------------------------------- */
    /* branch to symbolic label    */
/* ------------------------------------------------------------------- */
    
    L100 : p=getvar() ; if (errnum) derror(errnum) ;
    if (vartyp<=0) derror(82) ;                    /* illegal label */
    
    if (warea[gi]=='|') {                       /* faster than AND? */
	if (warea[gi+1]!=vrem) {
	    if (i==0) derror(62) ;                           /* LABEL */
	    if (warea[gi+1]!=chr11 && warea[gi+1]!=vendls) derror(81) ;
	}
    }                                                    /* if | */
    else if (warea[gi]!=lf) derror(33) ;         /* bad termination */
    
    if (p!=NULL) {                                  /* label exists */
	if (p->symtype!=5) derror(82) ;             /* illegal label */
	if (i==0) {                                         /* LABEL */
	    if (intval[p->valptr]!=gi) derror(82) ;      /* duplicate */
	    return ;                                /* skip the label */
	}
	gi=intval[p->valptr] ;                      /* execute GO TO */
	goto L10 ;
    }
    
    if (i==0) return ;                        /* new LABEL, skip it */
    
    gisav=gi ; /* GO TO, search for target label; save gi for error */
    
    strcpy(oname,symbol) ; li=linsiz+6 ; /* start after first token */
    while (li<endtxt) {                                   /* search */
	if (warea[li-1]==vlabel) {
	    gi=li ; p=getvar() ; if (errnum) derror(errnum) ;
	    li=gi ;
	    while (warea[li]!=lf) li++ ;            /* get to next lf */
	    if (strcmp(symbol,oname)==0) { gi=li ; goto L300 ; }
	    /* success */
	    li+=5 ;                          /* get behind next token */
	}
	else li+=warea[li-2] ;                    /* add line length */
    }                                                   /* while */
    gi=gisav ; derror(68) ;                 /* search failure at gi */
    
    L300 : if (gii+1>maxinvar) derror(41) ;
    p=(struct symnode*)malloc(sizeof(struct symnode)) ;
    p->SWITCH=TRUE ;                           /* install new label */
    p->link=hashtab[hashval] ;
    strcpy(p->name,symbol) ;
    p->symtype=5 ;
    hashtab[hashval]=p ;
    p->valptr=gii ;
    intval[gii++]=gi ;
    
    L10 :  
	if (tracer>0) {
	    if (tracer==2 || tracer==3 || tracer>=6) {
		printf("%c%s",'\33',"[7m") ;           /* ANSI reverse video */
		printf("%s%s%c","G: GO TO LABEL ",symbol,'\n') ;
		printf("%c%s",'\33',"[0m") ;           /* ANSI restore video */
	    }
	}
}            /* goto00 */
Esempio n. 22
0
int
main(
	int argc,
	char *argv[])
{
/*    MSC_EXTRA extern int optind;
    MSC_EXTRA extern int opterr;
    MSC_EXTRA extern char *optarg;*/
    int any_error;
    int c;
    FILE *fp;

#ifdef __hpux
    setlocale(LC_CTYPE,"");
#endif
    
#ifdef MDEBUG
	malloc_debug(2) ;	/* helps find malloc/free errors on Sun */
#endif /* MDEBUG */

    opterr = 1;			/* print error message if bad option */
    progname = ubasename(argv[0]);
    cdlname = "-";

    c_flag = 0;
    fortran_flag = 0;
    netcdf_flag = 0;
    cmode_modifier = 0;
    nofill_flag = 0;

#if _CRAYMPP && 0
    /* initialize CRAY MPP parallel-I/O library */
    (void) par_io_init(32, 32);
#endif

    while ((c = getopt(argc, argv, "bcfk:l:no:v:x")) != EOF)
      switch(c) {
	case 'c':		/* for c output, old version of "-lc" */
	  c_flag = 1;
	  break;
	case 'f':		/* for fortran output, old version of "-lf" */
	  fortran_flag = 1;
	  break;
	case 'b':		/* for binary netcdf output, ".nc" extension */
	  netcdf_flag = 1;
	  break;
        case 'l':		/* specify language, instead of using -c or -f */
	    {
		char *lang_name = (char *) emalloc(strlen(optarg)+1);
		if (! lang_name) {
		    derror ("%s: out of memory", progname);
		    return(1);
		}
		(void)strcpy(lang_name, optarg);
		if (strcmp(lang_name, "c") == 0 || strcmp(lang_name, "C") == 0) {
		    c_flag = 1;
		}
		else if (strcmp(lang_name, "f77") == 0 || 
			 strcmp(lang_name, "fortran77") == 0 ||
			 strcmp(lang_name, "Fortran77") == 0) {
		    fortran_flag = 1;
		} else {	/* Fortran90, Java, C++, Perl, Python, Ruby, ... */
		    derror("%s: output language %s not implemented", 
			   progname, lang_name);
		    return(1);
		}
	    }
	  break;
	case 'n':		/* old version of -b, uses ".cdf" extension */
	  netcdf_flag = -1;
	  break;
	case 'o':		/* to explicitly specify output name */
	  netcdf_flag = 1;
	  netcdf_name = (char *) emalloc(strlen(optarg)+1);
	  if (! netcdf_name) {
	      derror ("%s: out of memory", progname);
	      return(1);
	  }
	  (void)strcpy(netcdf_name,optarg);
	  break;
	case 'x':		/* set nofill mode to speed up creation of large files */
	  nofill_flag = 1;
	  break;
        case 'v':		/* a deprecated alias for "kind" option */
	    /*FALLTHRU*/
        case 'k': /* for specifying variant of netCDF format to be generated */
	    {
		char *kind_name = (char *) emalloc(strlen(optarg)+1);
		if (! kind_name) {
		    derror ("%s: out of memory", progname);
		    return(1);
		}
		(void)strcpy(kind_name, optarg);
		/* The default kind is kind 1 (classic), with 32-bit offsets */
		if (strcmp(kind_name, "1") == 0 || 
		    strcmp(kind_name, "classic") == 0) {
		    cmode_modifier |= NC_CLASSIC_MODEL;
		}
		/* The 64-bit offset kind (2)  should only be used if actually needed */
		else if (strcmp(kind_name, "2") == 0 || 
			 strcmp(kind_name, "64-bit-offset") == 0 ||
			 strcmp(kind_name, "64-bit offset") == 0) {
		    cmode_modifier |= NC_64BIT_OFFSET;
		}
#ifdef USE_NETCDF4
		/* NetCDF-4 HDF5 format*/
		else if (strcmp(kind_name, "3") == 0 || 
			 strcmp(kind_name, "hdf5") == 0 ||
			 strcmp(kind_name, "netCDF-4") == 0) {
		    cmode_modifier |= NC_NETCDF4;
		}
		/* NetCDF-4 HDF5 format, but using only nc3 data model */
		else if (strcmp(kind_name, "4") == 0 ||
		    strcmp(kind_name, "hdf5-nc3") == 0 ||
		    strcmp(kind_name, "netCDF-4 classic model") == 0) {
		    cmode_modifier |= NC_NETCDF4 | NC_CLASSIC_MODEL;
		}
#endif 
		else 
		{
		   derror("Invalid format, try classic, 64-bit offset, netCDF-4, or netCDF-4 classic model");
		   return 2;
		}
		free(kind_name);
	    }
	  break;
	case '?':
	  usage();
	  return(8);
      }

    if (fortran_flag && c_flag) {
	derror("Only one of -c or -f may be specified");
	return(8);
      }

    argc -= optind;
    argv += optind;

    if (argc > 1) {
	derror ("%s: only one input file argument permitted",progname);
	return(6);
    }

    fp = stdin;
    if (argc > 0 && strcmp(argv[0], "-") != 0) {
	if ((fp = fopen(argv[0], "r")) == NULL) {
	    derror ("can't open file %s for reading: ", argv[0]);
	    perror("");
	    return(7);
	}
	cdlname = argv[0];
    }
    ncgin = fp;
    any_error = ncgparse();
    if (any_error || derror_count > 0)
	return 1;
    return 0;
}
Esempio n. 23
0
void replica::on_prepare(dsn_message_t request)
{
    check_hashed_access();

    replica_configuration rconfig;
    mutation_ptr mu;

    {
        rpc_read_stream reader(request);
        unmarshall(reader, rconfig, DSF_THRIFT_BINARY);
        mu = mutation::read_from(reader, request);
    }

    decree decree = mu->data.header.decree;

    dinfo("%s: mutation %s on_prepare", name(), mu->name());

    dassert(mu->data.header.ballot == rconfig.ballot, "");

    if (mu->data.header.ballot < get_ballot())
    {
        derror("%s: mutation %s on_prepare skipped due to old view", name(), mu->name());
        // no need response because the rpc should have been cancelled on primary in this case
        return;
    }

    // update configuration when necessary
    else if (rconfig.ballot > get_ballot())
    {
        if (!update_local_configuration(rconfig))
        {
            derror(
                "%s: mutation %s on_prepare failed as update local configuration failed, state = %s",
                name(), mu->name(),
                enum_to_string(status())
                );
            ack_prepare_message(ERR_INVALID_STATE, mu);
            return;
        }
    }

    if (partition_status::PS_INACTIVE == status() || partition_status::PS_ERROR == status())
    {
        derror(
            "%s: mutation %s on_prepare failed as invalid replica state, state = %s",
            name(), mu->name(),
            enum_to_string(status())
            );
        ack_prepare_message(
            (partition_status::PS_INACTIVE == status() && _inactive_is_transient) ? ERR_INACTIVE_STATE : ERR_INVALID_STATE,
            mu
            );
        return;
    }
    else if (partition_status::PS_POTENTIAL_SECONDARY == status())
    {
        // new learning process
        if (rconfig.learner_signature != _potential_secondary_states.learning_version)
        {
            init_learn(rconfig.learner_signature);
            // no need response as rpc is already gone
            return;
        }

        if (!(_potential_secondary_states.learning_status == learner_status::LearningWithPrepare
            || _potential_secondary_states.learning_status == learner_status::LearningSucceeded))
        {
            derror(
                "%s: mutation %s on_prepare skipped as invalid learning status, state = %s, learning_status = %s",
                name(), mu->name(),
                enum_to_string(status()),
                enum_to_string(_potential_secondary_states.learning_status)
                );

            // no need response as rpc is already gone
            return;
        }
    }

    dassert (rconfig.status == status(), "");    
    if (decree <= last_committed_decree())
    {
        ack_prepare_message(ERR_OK, mu);
        return;
    }
    
    // real prepare start
    auto mu2 = _prepare_list->get_mutation_by_decree(decree);
    if (mu2 != nullptr && mu2->data.header.ballot == mu->data.header.ballot)
    {
        if (mu2->is_logged())
        {
            ack_prepare_message(ERR_OK, mu);
        }
        else
        {
            derror("%s: mutation %s on_prepare skipped as it is duplicate", name(), mu->name());
            // response will be unnecessary when we add retry logic in rpc engine.
            // the retried rpc will use the same id therefore it will be considered responsed
            // even the response is for a previous try.
        }
        return;
    }

    error_code err = _prepare_list->prepare(mu, status());
    dassert (err == ERR_OK, "");

    if (partition_status::PS_POTENTIAL_SECONDARY == status())
    {
        dassert (mu->data.header.decree <= last_committed_decree() + _options->max_mutation_count_in_prepare_list, "");
    }
    else
    {
        dassert (partition_status::PS_SECONDARY == status(), "");
        dassert (mu->data.header.decree <= last_committed_decree() + _options->staleness_for_commit, "");
    }

    dassert(mu->log_task() == nullptr, "");
    mu->log_task() = _stub->_log->append(mu,
        LPC_WRITE_REPLICATION_LOG,
        this,
        std::bind(&replica::on_append_log_completed, this, mu,
                  std::placeholders::_1,
                  std::placeholders::_2),
        gpid_to_hash(get_gpid())
        );
}
Esempio n. 24
0
int
main(
	int argc,
	char *argv[])
{
    int c;
    FILE *fp;
    int languages = 0;

#ifdef __hpux
    setlocale(LC_CTYPE,"");
#endif
    
    init_netcdf();

    opterr = 1;			/* print error message if bad option */
    progname = ubasename(argv[0]);
    cdlname = "-";
    netcdf_name = NULL;
    datasetname = NULL;
    c_flag = 0;
    f77_flag = 0;
    cml_flag = 0;
    java_flag = 0;
    binary_flag = 0;
    nofill_flag = 0;
    syntax_only = 0;
    header_only = 0;
    mainname = "main";
    nciterbuffersize = 0;

    k_flag = 0;
    format_flag = 0;
    enhanced_flag = 0;
    specials_flag = 0;

    diskless = 0;

#if _CRAYMPP && 0
    /* initialize CRAY MPP parallel-I/O library */
    (void) par_io_init(32, 32);
#endif

    while ((c = getopt(argc, argv, "hbcfk:l:no:v:xdM:D:B:P")) != EOF)
      switch(c) {
	case 'd':
	  debug = 1;	  
	  break;
	case 'D':
	  debug = atoi(optarg);
	  break;
	case 'c': /* for c output, old version of "-lc" */
	  c_flag = 1;
	  fprintf(stderr,"-c is deprecated: please use -lc\n");
	  break;
	case 'f': /* for f77 output, old version of "-lf" */
	  f77_flag = 1;
	  fprintf(stderr,"-f is deprecated: please use -lf77\n");
	  break;
	case 'b': /* for binary netcdf output, ".nc" extension */
	  binary_flag = 1;
	  break;
	case 'h':
	  header_only = 1;	  
	  break;
        case 'l': /* specify language, instead of using -c or -f or -b */
	    {
		struct Languages* langs;
		char* lang_name = (char*) emalloc(strlen(optarg)+1);
		(void)strcpy(lang_name, optarg);
		for(langs=legallanguages;langs->name != NULL;langs++) {
		    if(strcmp(lang_name,langs->name)==0) {
			*(langs->flag) = 1;
		        break;
		    }
		}
		if(langs->name == NULL) {
		    derror("%s: output language %s not implemented", 
			   progname, lang_name);
		    return(1);
		}
	    }
	  break;
	case 'n':		/* old version of -b, uses ".cdf" extension */
	  binary_flag = -1;
	  break;
	case 'o':		/* to explicitly specify output name */
	  netcdf_name = nulldup(optarg);
	  break;
	case 'x': /* set nofill mode to speed up creation of large files */
	  nofill_flag = 1;
	  break;
        case 'v': /* a deprecated alias for "kind" option */
	    /*FALLTHRU*/
        case 'k': /* for specifying variant of netCDF format to be generated 
                     Possible values are:
                     1 (=> classic 32 bit)
                     2 (=> classic 64 bit)
                     3 (=> enhanced)
                     4 (=> classic, but stored in an enhanced file format)
                     Also provide string versions of above
                     "classic"
                     "64-bit-offset"
                     "64-bit offset"
		     "enhanced" | "hdf5" | "netCDF-4"
                     "enhanced-nc3" | "hdf5-nc3" | "netCDF-4 classic model"
		   */
	    {
		struct Kvalues* kvalue;
		char *kind_name = (char *) emalloc(strlen(optarg)+1);
		if (! kind_name) {
		    derror ("%s: out of memory", progname);
		    return(1);
		}
		(void)strcpy(kind_name, optarg);
	        for(kvalue=legalkinds;kvalue->name;kvalue++) {
		    if(strcmp(kind_name,kvalue->name) == 0) {
		        k_flag = kvalue->k_flag;
			break;
		    }
		}
		if(kvalue->name == NULL) {
		   derror("Invalid format: %s",kind_name);
		   return 2;
		}
	    }
	  break;
	case 'M': /* Determine the name for the main function */
	    mainname = nulldup(optarg);
	    break;
	case 'B':
	  nciterbuffersize = atoi(optarg);
	  break;
	case 'P': /* diskless with persistence */
	  diskless = 1;
	  break;
	case '?':
	  usage();
	  return(8);
      }

    /* check for multiple or no language spec */
    if(binary_flag) languages++;
    if(c_flag) languages++;
    if(f77_flag)languages++;
    if(cml_flag) languages++;
    if(java_flag) languages++;
    if(languages > 1) {
	fprintf(stderr,"Please specify only one language\n");
	return 1;
    }

    if(languages == 0) {
	binary_flag = 1; /* default */
	/* Treat -k or -o as an implicit -lb assuming no other -l flags */
        if(k_flag == 0 && netcdf_name == NULL)
	    syntax_only = 1;
    }

    /* Compute/default the iterator buffer size */
    if(binary_flag) {
	if(nciterbuffersize == 0 )
	    nciterbuffersize = DFALTBINNCITERBUFFERSIZE;
    } else {
	if(nciterbuffersize == 0)
	    nciterbuffersize = DFALTLANGNCITERBUFFERSIZE;
    }

#ifndef ENABLE_C
    if(c_flag) {
	  fprintf(stderr,"C not currently supported\n");
	  exit(1);
    }
#endif
#ifndef ENABLE_BINARY
    if(binary_flag) {
	  fprintf(stderr,"Binary netcdf not currently supported\n");
	  exit(1);
    }
#endif
#ifndef ENABLE_JAVA
    if(java_flag) {
	  fprintf(stderr,"Java not currently supported\n");
	  exit(1);
    }
#else
    if(java_flag && strcmp(mainname,"main")==0) mainname = "Main";
#endif
#ifndef ENABLE_F77
    if(f77_flag) {
	  fprintf(stderr,"F77 not currently supported\n");
	  exit(1);
    }
#endif

    if(!binary_flag)
	diskless = 0;

    argc -= optind;
    argv += optind;

    if (argc > 1) {
	derror ("%s: only one input file argument permitted",progname);
	return(6);
    }

    fp = stdin;
    if (argc > 0 && strcmp(argv[0], "-") != 0) {
	if ((fp = fopen(argv[0], "r")) == NULL) {
	    derror ("can't open file %s for reading: ", argv[0]);
	    perror("");
	    return(7);
	}
	cdlname = (char*)emalloc(NC_MAX_NAME);
	cdlname = nulldup(argv[0]);
	if(strlen(cdlname) > NC_MAX_NAME) cdlname[NC_MAX_NAME] = '\0';
    }

    /* Standard Unidata java interface => usingclassic */

    parse_init();
    ncgin = fp;
    if(debug >= 2) {ncgdebug=1;}
    if(ncgparse() != 0)
        return 1;

    /* Compute the k_flag (1st pass) using rules in the man page (ncgen.1).*/

#ifndef USE_NETCDF4
    if(enhanced_flag) {
	derror("CDL input is enhanced mode, but --disable-netcdf4 was specified during build");
	return 0;
    }
#endif

    if(java_flag || f77_flag) {
        k_flag = 1;
	if(enhanced_flag) {
	    derror("Java or Fortran requires classic model CDL input");
	    return 0;
	}
    }

    if(k_flag == 0)
	k_flag = format_flag;

    if(enhanced_flag && k_flag == 0)
	k_flag = 3;

    if(enhanced_flag && k_flag != 3) {
	derror("-k or _Format conflicts with enhanced CDL input");
	return 0;
    }

    if(specials_flag > 0 && k_flag == 0)
#ifdef USE_NETCDF4
	k_flag = 3;
#else
	k_flag = 1;
#endif

    if(k_flag == 0)
	k_flag = 1;

    usingclassic = (k_flag <= 2?1:0);

    /* compute cmode_modifier */
    switch (k_flag) {
    case 1: cmode_modifier = 0; break;
    case 2: cmode_modifier = NC_64BIT_OFFSET; break;
    case 3: cmode_modifier = NC_NETCDF4; break;
    case 4: cmode_modifier = NC_NETCDF4 | NC_CLASSIC_MODEL; break;
    default: ASSERT(0); /* cannot happen */
    }

    if(diskless)
	cmode_modifier |= (NC_DISKLESS|NC_NOCLOBBER);

    processsemantics();
    if(!syntax_only && error_count == 0) 
        define_netcdf();

    return 0;
}
Esempio n. 25
0
void CLASS nikon_compressed_load_raw() // used when tag 0x103 of subifd1 == 0x8799 (34713)
{
  static const uchar nikon_tree[][32] = {
    { 0,1,5,1,1,1,1,1,1,2,0,0,0,0,0,0,	/* 12-bit lossy */
      5,4,3,6,2,7,1,0,8,9,11,10,12 },
    { 0,1,5,1,1,1,1,1,1,2,0,0,0,0,0,0,	/* 12-bit lossy after split */
      0x39,0x5a,0x38,0x27,0x16,5,4,3,2,1,0,11,12,12 },
    { 0,1,4,2,3,1,2,0,0,0,0,0,0,0,0,0,  /* 12-bit lossless */
      5,4,6,3,7,2,8,1,9,0,10,11,12 },
    { 0,1,4,3,1,1,1,1,1,2,0,0,0,0,0,0,	/* 14-bit lossy */
      5,6,4,7,8,3,9,2,1,0,10,11,12,13,14 },
    { 0,1,5,1,1,1,1,1,1,1,2,0,0,0,0,0,	/* 14-bit lossy after split */
      8,0x5c,0x4b,0x3a,0x29,7,6,5,4,3,2,1,0,13,14 },
    { 0,1,4,2,2,3,1,2,0,0,0,0,0,0,0,0,	/* 14-bit lossless */
      7,6,8,5,9,4,10,3,11,12,2,0,1,13,14 } };
  struct decode *dindex;
  ushort ver0, ver1, vpred[2][2], hpred[2], csize;
  int i, min, max, step=0, huff=0, split=0, row, col, len, shl, diff;

  fseek (ifp, meta_offset, SEEK_SET); // linearization curve (0x96)
  ver0 = fgetc(ifp);
  ver1 = fgetc(ifp);
  // ver0=0x44, ver1=0x20 for 12bits and 14bits lossy (d300)
  // 0x46, 0x30 for 12bits and 14 lossless (d300 and d700)
  printf("meta_offset=%d, tiff_bps=%d, ver0=%d, ver1=%d\n", meta_offset, tiff_bps, ver0, ver1);
  if (ver0 == 0x49 || ver1 == 0x58) // never seen. firmware update or nikon raw software?
    fseek (ifp, 2110, SEEK_CUR);
  if (ver0 == 0x46) huff = 2; // lossless (implicitly 12bits). have seen a d3x nef with ver0=0x46 and ver1=0x30 (exif 0x131="ver1.00")
  // with d300 lossless : ver0=0x46, ver1=0x30. d700/14b/lossless : ver0=0x46, ver1=0x30

  if (tiff_bps == 14) huff += 3; // 14bits lossly (if huff was ==0) or 14bits lossless if ver0==0x46
  read_shorts (vpred[0], 4); // vertical predictor values ?
  
  max = 1 << tiff_bps & 0x7fff;
  if ((csize = get2()) > 1) // curve size. 567 with D100/12bits/lossy. 32 with d3x/12bits/lossless. 
    step = max / (csize-1);
  if (ver0 == 0x44 && ver1 == 0x20 && step > 0) { // lossy (d300, d90 and d5000). 
  //tag 0x93 = 2. stored curve needs interpolation
    for (i=0; i < csize; i++) // read curve
      curve[i*step] = get2();
      // curve interpolation
    for (i=0; i < max; i++)
      curve[i] = ( curve[i-i%step]*(step-i%step) +
		   curve[i-i%step+step]*(i%step) ) / step;
		   
    fseek (ifp, meta_offset+562, SEEK_SET); // csize seems 257 for recent models (0x44/0x20) like d90 and d300
    // type 2 has the split value and uses a second huffman table
    split = get2();
  } else if (ver0 != 0x46 && csize <= 0x4001) // if not lossless. 
  // with D100/D200/D2X/D40/D80/D60 12bits/lossy : ver0==0x44 && ver1==0x10
    read_shorts (curve, max=csize);
  printf("csize=%d, step=%d, split=%d, huff=%d\n", csize, step, split, huff);

/*
0x96 (linearization table) tag format 

offset how_many   type   name
----+-----------+------+---------------------------------------------------------------------------------------------
0    1           byte   version0
1    1           byte   version1
                         ver0=0x44, ver1=0x20 for 12bits and 14bits lossy (d300)
                         0x44, 0x20 : lossy (d300, d90 and d5000)
                         0x46, 0x30 for 12bits and 14 lossless (d300 and d700)
                         0x46, 0x30 : d3x/12b/lossless
                         0x46, 0x30. with d300 lossless. and d700/14b/lossless
                         0x44, 0x10 : with D100/D200/D2X/D40/D80/D60 12bits/lossy 
                         tag 0x93 = 3 for lossless (0x46/0x30).
                         tag 0x93 = 4 for lossy type 2 (0x44/0x20) 
                         tag 0x93 = 1 for lossy type 1 (0x44/0x10)
2    4           shorts vpred[2][2] (when ver0 == 0x49 || ver1 == 0x58, fseek (ifp, 2110, SEEK_CUR) before)
0x0a 1           short  curve_size. 
                         32 with d3x/12bits/lossless, d300/12bits/lossless
                         34 with 14bits/lossless (d300 and d700)
                         257 with d300/12+14b/lossy.  
                         257 with 12b/lossy for d90
                         567 with D100/12bits/lossy. 
                         683 with 12b/lossy for d200,d2x,d40x,d40,d80,d60
0x0c curve_size  shorts curve[]
                         for lossy type 2, if curve_size == 257 (d90 and d300), end of curve table is 1+257*2 = 526
562  1           short  split_value (for 0x44/0x20 only (lossy type 2), d90 and d300) 
                         
 */

  while (curve[max-2] == curve[max-1]) max--;
  init_decoder();
  make_decoder (nikon_tree[huff], 0);
  fseek (ifp, data_offset, SEEK_SET);
  getbits(-1);
  for (min=row=0; row < height; row++) {
      if (split && row == split) {
      // for lossy type 2 (0x44/0x20)
      init_decoder();
      make_decoder (nikon_tree[huff+1], 0);
      max += (min = 16) << 1;
    }
    for (col=0; col < raw_width; col++) {
      for (dindex=first_decode; dindex->branch[0]; )
	      dindex = dindex->branch[getbits(1)]; // read 12 or 14bits value bit per bit and walking through the huffman tree to find the leaf
      len = dindex->leaf & 15; // length = 4 left most bits
      shl = dindex->leaf >> 4; // shift length? = 8 or 10bits
      diff = ((getbits(len-shl) << 1) + 1) << shl >> 1; // read diff value
      if ((diff & (1 << (len-1))) == 0) // left most bit is certainly the sign 
	      diff -= (1 << len) - !shl;
      if (col < 2) 
        hpred[col] = vpred[row & 1][col] += diff; // vpred used for columns 0 and 1
      else	   
        hpred[col & 1] += diff;
      // very close to jpeg lossless decompression (ljpeg_diff and ljpeg_row), except for the shl value...
      if ((ushort)(hpred[col & 1] + min) >= max) derror();
      if ((unsigned) (col-left_margin) < width)
	      BAYER(row,col-left_margin) = curve[LIM((short)hpred[col & 1],0,0x3fff)];
    }
  }
}
void simple_stateful_load_balancer::run_lb(partition_configuration& pc)
{
    if (_state->freezed())
        return;

    configuration_update_request proposal;
    proposal.config = pc;

    if (pc.primary.is_invalid())
    {
        if (pc.secondaries.size() > 0)
        {
            if (s_lb_for_test)
            {
                std::vector< ::dsn::rpc_address> tmp(pc.secondaries);
                std::sort(tmp.begin(), tmp.end());
                proposal.node = tmp[0];
            }
            else
            {
                proposal.node = pc.secondaries[dsn_random32(0, static_cast<int>(pc.secondaries.size()) - 1)];
            }
            proposal.type = CT_UPGRADE_TO_PRIMARY;
        }

        else if (pc.last_drops.size() == 0)
        {
            proposal.node = find_minimal_load_machine(true);
            proposal.type = CT_ASSIGN_PRIMARY;
        }

        // DDD
        else
        {
            proposal.node = *pc.last_drops.rbegin();
            proposal.type = CT_ASSIGN_PRIMARY;

            derror("%s.%d.%d enters DDD state, we are waiting for its last primary node %s to come back ...",
                pc.app_type.c_str(),
                pc.gpid.app_id,
                pc.gpid.pidx,
                proposal.node.to_string()
                );
        }

        if (proposal.node.is_invalid() == false)
        {
            send_proposal(proposal.node, proposal);
        }
    }

    else if (static_cast<int>(pc.secondaries.size()) + 1 < pc.max_replica_count)
    {
        proposal.type = CT_ADD_SECONDARY;
        proposal.node = find_minimal_load_machine(false);
        if (proposal.node.is_invalid() == false && 
            proposal.node != pc.primary &&
            std::find(pc.secondaries.begin(), pc.secondaries.end(), proposal.node) == pc.secondaries.end())
        {
            send_proposal(pc.primary, proposal);
        }
    }
    else
    {
        // it is healthy, nothing to do
    }
}
Esempio n. 27
0
/*
 * Create Fortran data statement to initialize numeric variable with
 * values.
 */
static void
f_var_init(
    int varnum,			/* which variable */
    void *rec_start		/* start of data */
    )
{
    char *val_string;
    char *charvalp;
    short *shortvalp;
    int *intvalp;
    float *floatvalp;
    double *doublevalp;
    unsigned char *ubytevalp;
    unsigned short *ushortvalp;
    unsigned int *uintvalp;
    long long *int64valp;
    unsigned long long *uint64valp;
    char stmnt[FORT_MAX_STMNT];
    size_t stmnt_len;
    char s2[FORT_MAX_STMNT];
    int ival;

    /* load variable with data values  */
    sprintf(stmnt, "data %s /",vars[varnum].lname);
    stmnt_len = strlen(stmnt);
    switch (vars[varnum].type) {
    case NC_BYTE:
	charvalp = (char *) rec_start;
	for (ival = 0; ival < var_len-1; ival++) {
	    val_string = fstring(NC_BYTE,(void *)charvalp++,0);
	    sprintf(s2, "%s, ", val_string);
	    fstrcat(stmnt, s2, &stmnt_len);
	    free(val_string);
	}
	val_string = fstring(NC_BYTE,(void *)charvalp++,0);
	fstrcat(stmnt, val_string, &stmnt_len);
	free(val_string);
	break;
    case NC_SHORT:
	shortvalp = (short *) rec_start;
	for (ival = 0; ival < var_len-1; ival++) {
	    sprintf(s2, "%d, ", *shortvalp++);
	    fstrcat(stmnt, s2, &stmnt_len);
	}
	sprintf(s2, "%d", *shortvalp);
	fstrcat(stmnt, s2, &stmnt_len);
	break;
    case NC_INT:
	intvalp = (int *) rec_start;
	for (ival = 0; ival < var_len-1; ival++) {
	    sprintf(s2, "%ld, ", (long)*intvalp++);
	    fstrcat(stmnt, s2, &stmnt_len);
	}
	sprintf(s2, "%ld", (long)*intvalp);
	fstrcat(stmnt, s2, &stmnt_len);
	break;
    case NC_FLOAT:
	floatvalp = (float *) rec_start;
	for (ival = 0; ival < var_len-1; ival++) {
	    sprintf(s2, "%.8g, ", *floatvalp++);
	    fstrcat(stmnt, s2, &stmnt_len);
	}
	sprintf(s2, "%.8g", *floatvalp);
	fstrcat(stmnt, s2, &stmnt_len);
	break;
    case NC_DOUBLE:
	doublevalp = (double *) rec_start;
	for (ival = 0; ival < var_len-1; ival++) {
	    sprintf(s2, "%#.16g", *doublevalp++);
	    tztrim(s2);
	    expe2d(s2);	/* change 'e' to 'd' in exponent */
	    fstrcat(s2, ", ", &stmnt_len);
	    fstrcat(stmnt, s2, &stmnt_len);
	}
	sprintf(s2, "%#.16g", *doublevalp++);
	tztrim(s2);
	expe2d(s2);
	fstrcat(stmnt, s2, &stmnt_len);
	break;
    case NC_UBYTE:
	ubytevalp = (unsigned char *) rec_start;
	for (ival = 0; ival < var_len-1; ival++) {
	    sprintf(s2, "%hhu, ", (unsigned char)*ubytevalp++);
	    fstrcat(stmnt, s2, &stmnt_len);
	}
	sprintf(s2, "%hhu", (unsigned char)*ubytevalp);
	fstrcat(stmnt, s2, &stmnt_len);
	break;
    case NC_USHORT:
	ushortvalp = (unsigned short *) rec_start;
	for (ival = 0; ival < var_len-1; ival++) {
	    sprintf(s2, "%hu, ", (unsigned short)*ushortvalp++);
	    fstrcat(stmnt, s2, &stmnt_len);
	}
	sprintf(s2, "%hu", (unsigned short)*ushortvalp);
	fstrcat(stmnt, s2, &stmnt_len);
	break;
    case NC_UINT:
	uintvalp = (unsigned int *) rec_start;
	for (ival = 0; ival < var_len-1; ival++) {
	    sprintf(s2, "%u, ", (unsigned int)*uintvalp++);
	    fstrcat(stmnt, s2, &stmnt_len);
	}
	sprintf(s2, "%u", (unsigned int)*uintvalp);
	fstrcat(stmnt, s2, &stmnt_len);
	break;
    case NC_INT64:
	int64valp = (long long *) rec_start;
	for (ival = 0; ival < var_len-1; ival++) {
	    sprintf(s2, "%lld, ", (long long)*int64valp++);
	    fstrcat(stmnt, s2, &stmnt_len);
	}
	sprintf(s2, "%lld", (long long)*int64valp);
	fstrcat(stmnt, s2, &stmnt_len);
	break;
    case NC_UINT64:
	uint64valp = (unsigned long long *) rec_start;
	for (ival = 0; ival < var_len-1; ival++) {
	    sprintf(s2, "%llu, ", (unsigned long long)*uint64valp++);
	    fstrcat(stmnt, s2, &stmnt_len);
	}
	sprintf(s2, "%llu", (unsigned long long)*uint64valp);
	fstrcat(stmnt, s2, &stmnt_len);
	break;
    default:
	derror("fstrstr: bad type");
	break;
    }
    fstrcat(stmnt, "/", &stmnt_len);

    /* For record variables, store data statement for later use;
      otherwise, just print it. */
    if (vars[varnum].ndims > 0 && vars[varnum].dims[0] == rec_dim) {
	char *dup_stmnt = (char*) emalloc(strlen(stmnt)+1);
	strcpy(dup_stmnt, stmnt); /* ULTRIX missing strdup */
	vars[varnum].data_stmnt = dup_stmnt;
    } else {
	fline(stmnt);
    }
}
Esempio n. 28
0
        error_code deploy_svc_service_impl::start()
        {
            std::string pdir = utils::filesystem::path_combine(dsn_get_current_app_data_dir(), "services");
            _service_dir = dsn_config_get_value_string("deploy.service",
                "deploy_dir",
                pdir.c_str(),
                "where to put temporal deployment resources"
                );

            // load clusters
            const char* clusters[100];
            int sz = 100;
            int count = dsn_config_get_all_keys("deploy.service.clusters", clusters, &sz);
            dassert(count <= 100, "too many clusters");

            for (int i = 0; i < count; i++)
            {
                std::string cluster_name = dsn_config_get_value_string(
                    clusters[i],
                    "name",
                    "",
                    "cluster name"
                    );

                if (nullptr != get_cluster(cluster_name))
                {
                    derror("cluster %s already defined", cluster_name.c_str());
                    return ERR_CLUSTER_ALREADY_EXIST;
                }

                std::string cluster_factory_type = dsn_config_get_value_string(
                    clusters[i],
                    "factory",
                    "",
                    "factory name to create the target cluster scheduler"
                    );

                auto cluster = ::dsn::utils::factory_store<cluster_scheduler>::create(
                    cluster_factory_type.c_str(),
                    PROVIDER_TYPE_MAIN
                    );

                if (nullptr == cluster)
                {
                    derror("cluster type %s is not defined", cluster_factory_type.c_str());
                    return ERR_OBJECT_NOT_FOUND;
                }

                std::shared_ptr<cluster_ex> ce(new cluster_ex);
                ce->scheduler.reset(cluster);
                ce->cluster.name = cluster_name;
                ce->cluster.type = cluster->type();

                _clusters[cluster_name] = ce;
            }

            _cli_deploy = dsn_cli_app_register(
                "deploy",
                "deploy deploy_request(in json format)",
                "deploy an app via our deployment service",
                (void*)this,
                [](void *context, int argc, const char **argv, dsn_cli_reply *reply)
                {
                    auto this_ = (deploy_svc_service_impl*)context;
                    this_->on_deploy_cli(context, argc, argv, reply);
                },
                __svc_cli_freeer__
                );

            _cli_undeploy = dsn_cli_app_register(
                "undeploy",
                "undeploy service_name(in json format)",
                "undeploy an app via our deployment service",
                (void*)this,
                [](void *context, int argc, const char **argv, dsn_cli_reply *reply)
                {
                    auto this_ = (deploy_svc_service_impl*)context;
                    this_->on_undeploy_cli(context, argc, argv, reply);
                },
                __svc_cli_freeer__
                );

            _cli_get_service_list = dsn_cli_app_register(
                "service_list",
                "service_list package_id(in json format)",
                "get service list of a package via our deployment service",
                (void*)this,
                [](void *context, int argc, const char **argv, dsn_cli_reply *reply)
                {
                    auto this_ = (deploy_svc_service_impl*)context;
                    this_->on_get_service_list_cli(context, argc, argv, reply);
                },
                __svc_cli_freeer__
                );

            _cli_get_service_info = dsn_cli_app_register(
                "service_info",
                "service_info service_name(in json format)",
                "get service info of a service via our deployment service",
                (void*)this,
                [](void *context, int argc, const char **argv, dsn_cli_reply *reply)
                {
                    auto this_ = (deploy_svc_service_impl*)context;
                    this_->on_get_service_info_cli(context, argc, argv, reply);
                },
                __svc_cli_freeer__
                );

            _cli_get_cluster_list = dsn_cli_app_register(
                "cluster_list",
                "cluster_list format(in json format)",
                "get cluster list with a specific format via our deployment service",
                (void*)this,
                [](void *context, int argc, const char **argv, dsn_cli_reply *reply)
                {
                    auto this_ = (deploy_svc_service_impl*)context;
                    this_->on_get_cluster_list_cli(context, argc, argv, reply);
                },
                __svc_cli_freeer__
                );

            return ERR_OK;
        }
Esempio n. 29
0
/* write out variable's data from in-memory structure */
void
load_netcdf(void *rec_start)
{
    int i, idim;
    int stat = NC_NOERR;
    MPI_Offset *start, *count;
    char *charvalp = NULL;
    short *shortvalp = NULL;
    int *intvalp = NULL;
    float *floatvalp = NULL;
    double *doublevalp = NULL;
    unsigned char *ubytevalp = NULL;
    unsigned short *ushortvalp = NULL;
    unsigned int *uintvalp = NULL;
    long long *int64valp = NULL;
    unsigned long long *uint64valp = NULL;
    MPI_Offset total_size;

    /* load values into variable */

    switch (vars[varnum].type) {
      case NC_CHAR:
      case NC_BYTE:
	charvalp = (char *) rec_start;
	break;
      case NC_SHORT:
	shortvalp = (short *) rec_start;
	break;
      case NC_INT:
	intvalp = (int *) rec_start;
	break;
      case NC_FLOAT:
	floatvalp = (float *) rec_start;
	break;
      case NC_DOUBLE:
	doublevalp = (double *) rec_start;
	break;
      case NC_UBYTE:
	ubytevalp = (unsigned char *) rec_start;
	break;
      case NC_USHORT:
	ushortvalp = (unsigned short *) rec_start;
	break;
      case NC_UINT:
	uintvalp = (unsigned int *) rec_start;
	break;
      case NC_INT64:
	int64valp = (long long *) rec_start;
	break;
      case NC_UINT64:
	uint64valp = (unsigned long long *) rec_start;
	break;
      default:
	derror("Unhandled type %d\n", vars[varnum].type);
	break;
    }

    start = (MPI_Offset*) malloc(vars[varnum].ndims * 2 * sizeof(MPI_Offset));
    count = start + vars[varnum].ndims;

    if (vars[varnum].ndims > 0) {
	/* initialize start to upper left corner (0,0,0,...) */
	start[0] = 0;
	if (vars[varnum].dims[0] == rec_dim) {
	    count[0] = vars[varnum].nrecs;
	}
	else {
	    count[0] = dims[vars[varnum].dims[0]].size;
	}
    }

    for (idim = 1; idim < vars[varnum].ndims; idim++) {
	start[idim] = 0;
	count[idim] = dims[vars[varnum].dims[idim]].size;
    }

    total_size = nctypesize(vars[varnum].type);
    for (idim=0; idim<vars[varnum].ndims; idim++)
        total_size *= count[idim];

    /* If the total put size is more than 2GB, then put one subarray at a time.
     * Here the subarray is from 1, 2, ... ndims, except 0.
     * This is not a perfect solution. To be improved.
     */
    if (total_size > INT_MAX) {
        MPI_Offset nchunks=count[0];
        MPI_Offset subarray_nelems=1;
        for (idim=1; idim<vars[varnum].ndims; idim++)
            subarray_nelems *= count[idim];

        count[0] = 1;
        switch (vars[varnum].type) {
            case NC_BYTE:
                 for (i=0; i<nchunks; i++) {
                     start[0] = i;
                     stat = ncmpi_put_vara_schar_all(ncid, varnum, start, count, (signed char *)charvalp);
                     check_err(stat, "ncmpi_put_vara_schar_all", __func__, __LINE__, __FILE__);
                     charvalp += subarray_nelems;
                 }
                 break;
            case NC_CHAR:
                 for (i=0; i<nchunks; i++) {
                     start[0] = i;
                     stat = ncmpi_put_vara_text_all(ncid, varnum, start, count, charvalp);
                     check_err(stat, "ncmpi_put_vara_text_all", __func__, __LINE__, __FILE__);
                     charvalp += subarray_nelems;
                 }
                 break;
            case NC_SHORT:
                 for (i=0; i<nchunks; i++) {
                     start[0] = i;
                     stat = ncmpi_put_vara_short_all(ncid, varnum, start, count, shortvalp);
                     check_err(stat, "ncmpi_put_vara_short_all", __func__, __LINE__, __FILE__);
                     shortvalp += subarray_nelems;
                 }
                 break;
            case NC_INT:
                 for (i=0; i<nchunks; i++) {
                     start[0] = i;
                     stat = ncmpi_put_vara_int_all(ncid, varnum, start, count, intvalp);
                     check_err(stat, "ncmpi_put_vara_int_all", __func__, __LINE__, __FILE__);
                     intvalp += subarray_nelems;
                 }
                 break;
            case NC_FLOAT:
                 for (i=0; i<nchunks; i++) {
                     start[0] = i;
                     stat = ncmpi_put_vara_float_all(ncid, varnum, start, count, floatvalp);
                     check_err(stat, "ncmpi_put_vara_float_all", __func__, __LINE__, __FILE__);
                     floatvalp += subarray_nelems;
                 }
                 break;
            case NC_DOUBLE:
                 for (i=0; i<nchunks; i++) {
                     start[0] = i;
                     stat = ncmpi_put_vara_double_all(ncid, varnum, start, count, doublevalp);
                     check_err(stat, "ncmpi_put_vara_double_all", __func__, __LINE__, __FILE__);
                     doublevalp += subarray_nelems;
                 }
                 break;
            case NC_UBYTE:
                 for (i=0; i<nchunks; i++) {
                     start[0] = i;
                     stat = ncmpi_put_vara_uchar_all(ncid, varnum, start, count, ubytevalp);
                     check_err(stat, "ncmpi_put_vara_uchar_all", __func__, __LINE__, __FILE__);
                     ubytevalp += subarray_nelems;
                 }
                 break;
            case NC_USHORT:
                 for (i=0; i<nchunks; i++) {
                     start[0] = i;
                     stat = ncmpi_put_vara_ushort_all(ncid, varnum, start, count, ushortvalp);
                     check_err(stat, "ncmpi_put_vara_ushort_all", __func__, __LINE__, __FILE__);
                     ushortvalp += subarray_nelems;
                 }
                 break;
            case NC_UINT:
                 for (i=0; i<nchunks; i++) {
                     start[0] = i;
                     stat = ncmpi_put_vara_uint_all(ncid, varnum, start, count, uintvalp);
                     check_err(stat, "ncmpi_put_vara_uint_all", __func__, __LINE__, __FILE__);
                     uintvalp += subarray_nelems;
                 }
                 break;
            case NC_INT64:
                 for (i=0; i<nchunks; i++) {
                     start[0] = i;
                     stat = ncmpi_put_vara_longlong_all(ncid, varnum, start, count, int64valp);
                     check_err(stat, "ncmpi_put_vara_longlong_all", __func__, __LINE__, __FILE__);
                     int64valp += subarray_nelems;
                 }
                 break;
            case NC_UINT64:
                 for (i=0; i<nchunks; i++) {
                     start[0] = i;
                     stat = ncmpi_put_vara_ulonglong_all(ncid, varnum, start, count, uint64valp);
                     check_err(stat, "ncmpi_put_vara_ulonglong_all", __func__, __LINE__, __FILE__);
                     uint64valp += subarray_nelems;
                 }
                 break;
            default:
                     derror("Unhandled type %d\n", vars[varnum].type);
                     break;
        }
    }
    else {
        switch (vars[varnum].type) {
            case NC_BYTE:
                stat = ncmpi_put_vara_schar_all(ncid, varnum, start, count, (signed char *)charvalp);
                check_err(stat, "ncmpi_put_vara_schar_all", __func__, __LINE__, __FILE__);
                break;
            case NC_CHAR:
                stat = ncmpi_put_vara_text_all(ncid, varnum, start, count, charvalp);
                check_err(stat, "ncmpi_put_vara_text_all", __func__, __LINE__, __FILE__);
                break;
            case NC_SHORT:
                stat = ncmpi_put_vara_short_all(ncid, varnum, start, count, shortvalp);
                check_err(stat, "ncmpi_put_vara_short_all", __func__, __LINE__, __FILE__);
                break;
            case NC_INT:
                stat = ncmpi_put_vara_int_all(ncid, varnum, start, count, intvalp);
                check_err(stat, "ncmpi_put_vara_int_all", __func__, __LINE__, __FILE__);
                break;
            case NC_FLOAT:
                stat = ncmpi_put_vara_float_all(ncid, varnum, start, count, floatvalp);
                check_err(stat, "ncmpi_put_vara_float_all", __func__, __LINE__, __FILE__);
                break;
            case NC_DOUBLE:
                stat = ncmpi_put_vara_double_all(ncid, varnum, start, count, doublevalp);
                check_err(stat, "ncmpi_put_vara_double_all", __func__, __LINE__, __FILE__);
                break;
            case NC_UBYTE:
                stat = ncmpi_put_vara_uchar_all(ncid, varnum, start, count, ubytevalp);
                check_err(stat, "ncmpi_put_vara_uchar_all", __func__, __LINE__, __FILE__);
                break;
            case NC_USHORT:
                stat = ncmpi_put_vara_ushort_all(ncid, varnum, start, count, ushortvalp);
                check_err(stat, "ncmpi_put_vara_ushort_all", __func__, __LINE__, __FILE__);
                break;
            case NC_UINT:
                stat = ncmpi_put_vara_uint_all(ncid, varnum, start, count, uintvalp);
                check_err(stat, "ncmpi_put_vara_uint_all", __func__, __LINE__, __FILE__);
                break;
            case NC_INT64:
                stat = ncmpi_put_vara_longlong_all(ncid, varnum, start, count, int64valp);
                check_err(stat, "ncmpi_put_vara_longlong_all", __func__, __LINE__, __FILE__);
                break;
            case NC_UINT64:
                stat = ncmpi_put_vara_ulonglong_all(ncid, varnum, start, count, uint64valp);
                check_err(stat, "ncmpi_put_vara_ulonglong_all", __func__, __LINE__, __FILE__);
                break;
            default:
                derror("Unhandled type %d\n", vars[varnum].type);
                break;
        }
    }
    free(start);
}
Esempio n. 30
0
        static LONG WINAPI TopLevelFilter(struct _EXCEPTION_POINTERS *pExceptionInfo)
        {
            LONG retval = EXCEPTION_CONTINUE_SEARCH;
            HWND hParent = NULL;                        // find a better value for your app

            // firstly see if dbghelp.dll is around and has the function we need
            // look next to the EXE first, as the one in System32 might be old 
            // (e.g. Windows 2000)
            HMODULE hDll = NULL;

            if (hDll == NULL)
            {
                // load any version we can
                hDll = ::LoadLibraryA("DBGHELP.DLL");
            }

            LPCSTR szResult = "core dump success";
            char szDumpPath[512];
            char szScratch[512];

            dfatal("fatal exception, core dump started ...");

            if (hDll)
            {
                MINIDUMPWRITEDUMP pDump = (MINIDUMPWRITEDUMP)::GetProcAddress(hDll, "MiniDumpWriteDump");
                if (pDump)
                {
                    sprintf(szDumpPath, "%s\\%s_%d_%d.dmp", s_dump_dir.c_str(), s_app_name, ::GetCurrentProcessId(), time(NULL));

                    // create the file
                    HANDLE hFile = ::CreateFileA(szDumpPath, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS,
                        FILE_ATTRIBUTE_NORMAL, NULL);

                    if (hFile != INVALID_HANDLE_VALUE)
                    {
                        _MINIDUMP_EXCEPTION_INFORMATION ExInfo;

                        ExInfo.ThreadId = ::GetCurrentThreadId();
                        ExInfo.ExceptionPointers = pExceptionInfo;
                        ExInfo.ClientPointers = NULL;

                        // write the dump
                        BOOL bOK = pDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpNormal, &ExInfo, NULL, NULL);
                        if (bOK)
                        {
                            sprintf(szScratch, "saved dump file to '%s'", szDumpPath);
                            szResult = szScratch;
                            retval = EXCEPTION_EXECUTE_HANDLER;
                        }
                        else
                        {
                            sprintf(szScratch, "failed to save dump file to '%s' (error %d)", szDumpPath, GetLastError());
                            szResult = szScratch;
                        }
                        ::CloseHandle(hFile);
                    }
                    else
                    {
                        sprintf(szScratch, "failed to create dump file '%s' (error %d)", szDumpPath, GetLastError());
                        szResult = szScratch;
                    }
                }
                else
                {
                    szResult = "DBGHELP.DLL too old";
                }
            }
            else
            {
                szResult = "DBGHELP.DLL not found";
            }

            if (szResult)
            {
                derror("%s", szResult);
                printf(szResult);
            }

            ::dsn::tools::sys_exit.execute(SYS_EXIT_EXCEPTION);
            return retval;
        }