/* * Convert rule-value to datum using namefield information */ datum * ruleValueToDatum(__nis_table_mapping_t *t, __nis_rule_value_t *rv, int *statP) { __nis_value_t *val; datum *value; char *str, *cstr, commentSep[3] = {' ', 0, 0}; char *myself = "ruleValueToDatum"; /* No error yet */ *statP = 0; /* Return empty datum if no namefield information available */ if (t->e == 0) { if ((value = am(myself, sizeof (*value))) == 0) *statP = MAP_NO_MEMORY; return (value); } val = getMappingFormatArray(t->e->element.match.fmt, rv, fa_item, t->e->element.match.numItems, t->e->element.match.item); if (val && val->val && val->val->value) { if ((value = am(myself, sizeof (*value))) == 0) { *statP = MAP_NO_MEMORY; freeValue(val, 1); return (0); } /* Strip trailing whitespaces */ cstr = (char *)val->val->value + val->val->length; for (; cstr >= (char *)val->val->value && (*cstr == ' ' || *cstr == '\t'); *cstr-- = '\0'); if (t->commentChar != '\0' && (str = findVal(N2LCOMMENT, rv, mit_nisplus)) != 0 && *str != '\0') { commentSep[1] = t->commentChar; cstr = scat(myself, F, commentSep, str); if (cstr) { value->dptr = scat(myself, F, val->val->value, cstr); sfree(cstr); } } else { value->dptr = sdup(myself, T, val->val->value); } freeValue(val, 1); if (value->dptr) { value->dsize = strlen(value->dptr); return (value); } else { *statP = MAP_NO_MEMORY; sfree(value); return (0); } } *statP = MAP_NAMEFIELD_MATCH_ERROR; return (0); }
/* * Returns 'map,domain.' */ char * getFullMapName(char *map, char *domain) { char *myself = "getFullMapName"; char *objPath; if (map == 0 || domain == 0) { return (0); } objPath = scat(myself, T, scat(myself, F, map, ","), scat(myself, F, domain, ".")); return (objPath); }
String& String::operator+=(const String &str) { if(!str.curLength) return *this; curLength += str.curLength; if(curLength) { if(lpString) { lpString = (TSTR)ReAllocate(lpString, (curLength+1)*sizeof(TCHAR)); scat(lpString, str.lpString); } else { lpString = (TSTR)Allocate((curLength+1)*sizeof(TCHAR)); scpy(lpString, str.lpString); } } else { if(lpString) Free(lpString); lpString = NULL; } return *this; }
unsigned int twoCharToUint(char highByte, char lowByte){ unsigned int localVariable; localVariable = (unsigned int) scat(highByte, lowByte); return localVariable; }
static int hdr_MakeTextHeaders( msg_Headers headers, const char * charset, string out ) { msg_Header header; char cprefix[32]; string rc = snew(); if( !rc ) return 0; if( !isUsAsciiCs( charset ) ) snprintf( cprefix, sizeof(cprefix) - 1, "=?%s?B?", charset ); else *cprefix = 0; header = lfirst( headers->text ); while( header ) { if( !hdr_MakeTextHeader( header, cprefix, rc ) ) { sdel( rc ); return 0; } header = lnext( headers->text ); } if( !scat( out, rc ) ) { sdel( rc ); return 0; } sdel( rc ); return 1; }
int main(){ char s[10]="hello"; printf("%s: %d\n",s,slen(s)); //testing for slen char cpy[15]="aba"; printf("After scpy, %s became: ",cpy); scpy(cpy,s); printf("%s\n",cpy); char ncpy[15]="abalaba"; printf("After sncpy (n=3), %s became: ",ncpy); sncpy(ncpy,s,3); printf("%s\n",ncpy); char cat[15]="AddOn"; printf("After scat, %s became: ",cpy); scat(cpy,cat); printf("%s\n",cpy); char s2[18]="hello"; char s3[5]="po"; char s4[5]="bao"; printf("scmp %s and %s: %d\n",s,s2,scmp(s,s2)); printf("scmp %s and %s: %d\n",s,cpy,scmp(s,cpy)); printf("scmp %s and %s: %d\n",s,s3,scmp(s,s3)); printf("scmp %s and %s: %d\n",s,s4,scmp(s,s4)); printf("schr %s and %c: %s\n",s,'l',schr(s,'l')); printf("schr %s and %c: %s\n",s,'t',schr(s,'t')); char s5[5]="el"; printf("sstr %s and %s: %s\n",s,s5,sstr(s,s5)); printf("sstr %s and %s: %s\n",s,s3,sstr(s,s3)); return 0; }
HANDLE STDCALL OSLoadLibrary(CTSTR lpFile) { TCHAR FullFileName[250]; scpy(FullFileName, lpFile); scat(FullFileName, TEXT(".dll")); return (HANDLE)LoadLibrary(FullFileName); }
int main() { char s1[128]; char s2[128]; scanf("%s", s1); scanf("%s", s2); printf("%s\n", srev(scat(s1, s2))); return 0; }
main(int argc, char *argv[]) { /* init modem */ outportb(com_base + lc,0x83); /* Set baud rate, No parity, 8 bits */ outportb(com_base + dll,96); /* 1200 baud */ outportb(com_base + dlh,0); outportb(com_base + lc,no_parity); outportb(com_base + mc,0x03); /* Turn ON DTR and RTS */ /* set up modem control string */ send(scat("ATDT%s\r",paramstr(1))); }
static bool _string_finish(char **p, char *tmp, int tmplen) { char *tmp2; if(tmplen==0){ if(*p==NULL) *p=scopy(""); }else{ tmp[tmplen]='\0'; if(*p!=NULL){ tmp2=scat(*p, tmp); free(*p); *p=tmp2; }else{ *p=scopy(tmp); } } return *p!=NULL; }
/*(internal) EXTL_DOC * Display an error message box in the multiplexer \var{mplex}. */ EXTL_EXPORT WMessage *mod_query_do_warn(WMPlex *mplex, const char *p) { char *p2; WMessage *wmsg; if(p==NULL) return NULL; p2=scat(TR("Error:\n"), p); if(p2==NULL) return NULL; wmsg=mod_query_do_message(mplex, p2); free(p2); return wmsg; }
static bool _string_append(char **p, char *tmp, int *tmplen, char c) { char *tmp2; if(*tmplen==STRBLEN-1){ tmp[STRBLEN-1]='\0'; if(*p!=NULL){ tmp2=scat(*p, tmp); free(*p); *p=tmp2; }else{ *p=scopy(tmp); } *tmplen=1; tmp[0]=c; return *p!=NULL; }else{ tmp[(*tmplen)++]=c; return TRUE; } }
static int hdr_MakeTextHeader( msg_Header header, const char * cprefix, string out ) { char * value; string rc = snew(); if( !rc ) return 0; value = slfirst( header->values ); while( value ) { if( isUsAscii( value ) ) { if( !xscatc( rc, header->name, ": ", value, "\r\n", NULL ) ) { sdel( rc ); return 0; } } else { string b64 = hdr_Encodeb64( cprefix, value ); if( !b64 ) return 0; if( !xscatc( rc, header->name, ": ", sstr( b64 ), "\r\n", NULL ) ) { sdel( b64 ); sdel( rc ); return 0; } sdel( b64 ); } value = slnext( header->values ); } if( !scat( out, rc ) ) { sdel( rc ); return 0; } sdel( rc ); return 1; }
static int hdr_MakeMailHeader( msg_Header header, const char * cprefix, string out ) { Pair email; string rc; rc = snew(); if( !rc ) return 0; email = plfirst( header->values ); while( email ) { string value = hdr_MakeEmail( cprefix, email ); if( !value ) { sdel( rc ); return 0; } if( !scatc( rc, sstr( value ) ) ) { sdel( rc ); return 0; } email = plnext( header->values ); if( !scatc( rc, email ? "," : "\r\n" ) ) { sdel( rc ); return 0; } } if( !scat( out, rc ) ) { sdel( rc ); return 0; } sdel( rc ); return 1; }
static void mod_sm_set_sessiondir() { const char *smdir=NULL, *id=NULL; char *tmp; bool ok=FALSE; smdir=getenv("SM_SAVE_DIR"); id=getenv("GNOME_DESKTOP_SESSION_ID"); /* Running under SM, try to use a directory specific * to the session. */ if(smdir!=NULL){ tmp=scat3(smdir, "/", libtu_progbasename()); }else if(id!=NULL){ tmp=scat("gnome-session-", id); if(tmp!=NULL){ char *p=tmp; while(1){ p=strpbrk(p, "/ :?*"); if(p==NULL) break; *p='-'; p++; } } }else{ tmp=scopy("default-session-sm"); } if(tmp!=NULL){ ok=extl_set_sessiondir(tmp); free(tmp); } if(!ok) warn(TR("Failed to set session directory.")); }
String& String::operator+=(CTSTR str) { UINT strLength; if(!str) strLength = 0; else strLength = slen(str); if(!strLength) return *this; curLength += strLength; if(curLength) { if(lpString) { lpString = (TSTR)ReAllocate(lpString, (curLength+1)*sizeof(TCHAR)); scat(lpString, str); } else { lpString = (TSTR)Allocate((curLength+1)*sizeof(TCHAR)); scpy(lpString, str); } } else { if(lpString) Free(lpString); lpString = NULL; } return *this; }
/* * FUNCTION : addNISObject() * * DESCRIPTION: Add a nis Object in the DIT. * * GIVEN : * Case 1: 'dn' is NULL * Error * Case 2: 'domain' is non-NULL * Create nisDomainObject with the given information * Case 3: 'domain' is NULL * Create an object with the 'dn' * Here we guess the objectclass attribute, based on * oc_lookup table * * RETURNS : SUCCESS = It worked * FAILURE = There was a problem. If the ldap add * operation failed, ldap_rc will be set * to the ldap error code. */ suc_code addNISObject(char *domain, char *dn, int *ldap_rc) { __nis_rule_value_t *rv; int rc; char *objClassAttrs = NULL, *attrs; char *value, *svalue, *rdn = NULL; char *myself = "addNISObject"; if (!dn) return (FAILURE); if ((rv = initRuleValue(1, 0)) == 0) return (FAILURE); if (ldap_rc) *ldap_rc = -1; /* * Add name=value pairs from RDN. Although this is not required * for SunOne Directory Server, during openldap interoperabilty * tests, it was found out that openldap server returned object * class violation errors if MUST attributes were not specified * explicitly. */ if (splitDN(dn, &rdn, 0) == -1) return (FAILURE); if (rdn != NULL) { objClassAttrs = (char *)getObjectClass(rdn); if (objClassAttrs == NULL) { sfree(rdn); return (FAILURE); } /* * RDN can be composed of multiple name=value pairs * concatenated by '+'. Hence, we need to determine each * pair and add it to 'rv' */ for (value = rdn, svalue = NULL; *value != '\0'; value++) { if (*value == '+') { /* Make sure it's not escaped */ if (value == rdn || *(value - 1) != '\\') { /* * We are at the start of the new * pair. 'svalue' now contains the * value for the previous pair. Add * the previous pair to 'rv' */ *value = '\0'; if (svalue && addSAttr2RuleValue(rdn, svalue, rv) == -1) { sfree(rdn); freeRuleValue(rv, 1); return (FAILURE); } svalue = NULL; rdn = value + 1; continue; } } if (*value == '=') { if (value == rdn || *(value - 1) != '\\') { /* * 'rdn' now contains the name. * Whatever follows till the next * unescaped '+' or '\0' is the * value for this pair. */ *value = '\0'; svalue = value + 1; continue; } } } /* * End of String. Add the previous name=value pair to 'rv' */ if (svalue && addSAttr2RuleValue(rdn, svalue, rv) == -1) { sfree(rdn); freeRuleValue(rv, 1); return (FAILURE); } sfree(rdn); } else /* rdn == NULL */ return (FAILURE); /* Create the entry */ if (domain) { if (addSAttr2RuleValue("nisDomain", domain, rv) == -1) { freeRuleValue(rv, 1); return (FAILURE); } attrs = scat(myself, F, "objectclass=nisdomainobject,", objClassAttrs); if (!attrs) { freeRuleValue(rv, 1); return (FAILURE); } rc = ldapAdd(dn, rv, attrs, 0); sfree(attrs); } else { rc = ldapAdd(dn, rv, objClassAttrs, 0); } if (rc == LDAP_SUCCESS) logmsg(MSG_NOTIMECHECK, LOG_INFO, "%s: Entry (dn: %s) added to DIT", myself, dn); else if (rc == LDAP_ALREADY_EXISTS) /* Treat this as success */ rc = LDAP_SUCCESS; else logmsg(MSG_NOTIMECHECK, LOG_ERR, "%s: ldapAdd error %d (%s) for (dn: %s)", myself, rc, ldap_err2string(rc), dn); freeRuleValue(rv, 1); if (ldap_rc) *ldap_rc = rc; return ((rc == LDAP_SUCCESS)?SUCCESS:FAILURE); }
int client(int port ) { int connected, bytes_recieved,addr_len; char udpsend [20000],tcpsend[20000],udpreceive[20000],tcpreceive[20000]; char regex[20000]; char fileName[20000]; struct hostent *h; struct sockaddr_in server_addr; h= (struct hostent *) gethostbyname((char *)"127.0.0.1"); if(flag==0) connected = socket(AF_INET, SOCK_STREAM, 0); else connected = socket(AF_INET, SOCK_DGRAM, 0); if (connected == -1) { perror("Socket"); exit(1); } server_addr.sin_family = AF_INET; server_addr.sin_port = htons(port); server_addr.sin_addr = *((struct in_addr *)h->h_addr); if(flag == 0) bzero(&(server_addr.sin_zero), 8); addr_len = sizeof(struct sockaddr); if(flag == 0) { while (connect(connected, (struct sockaddr *)&server_addr,sizeof(struct sockaddr)) == -1) ; } /* Connection established between client and server */ printf("Usage: \n1. Download <filename>\n2. Upload <filename>\n3. IndexGet LongList \n4. IndexGet ShortList <start-timestamp> <end-timestamp>\n5. IndexGet RegEx\n6. FileHash Verify <filename>7. FileHash CheckAll\nEnter your command here:\n"); char *str; char copy[20000]; while(1) { if(flag == 1) gets(udpsend); // DATA which is got in the input buffer else gets(tcpsend); // DATA which is got in the input buffer if(flag == 1) scpy(copy,udpsend); else scpy(copy,tcpsend); str = strtok (copy," "); /* IndexGet */ if(str!=NULL) { if(!strcmp(str,"FileHash")) { str = strtok (NULL, " "); if(str !=NULL) { if(strcmp(str,"Verify")==0) { str = strtok (NULL, " "); if(str!=NULL) { if(flag == 1) { printf("udpsend : %s\n",udpsend); scpy(udpsend,"FV"); scat(udpsend,str); sendto(connected, udpsend, strlen(udpsend), 0, (struct sockaddr *)&server_addr, sizeof(struct sockaddr)); } else { scpy(tcpsend,"FV"); scat(tcpsend,str); send(connected, tcpsend,strlen(tcpsend), 0); } while(1) { if(flag == 1) { bytes_recieved=recvfrom(connected,udpreceive,20000,0, (struct sockaddr *)&server_addr, &addr_len); udpreceive[bytes_recieved] = '\0'; if(strcmp(udpreceive,"End Of File") == 0)break; fwrite(udpreceive,1,bytes_recieved,stdout); } else { bytes_recieved=recv(connected,tcpreceive,20000,0); tcpreceive[bytes_recieved] = '\0'; if(strcmp(tcpreceive,"End Of File") == 0)break; fwrite(tcpreceive,1,bytes_recieved,stdout); } } if(flag == 1) printf("\ndone\n"); continue; } } else if(strcmp(str,"CheckAll")==0) { if(flag == 1) { scpy(udpsend,"FC"); sendto(connected, udpsend, strlen(udpsend), 0, (struct sockaddr *)&server_addr, sizeof(struct sockaddr)); } else { scpy(tcpsend,"FC"); send(connected, tcpsend,strlen(tcpsend), 0); } while(1) { if(flag == 1) { bytes_recieved=recvfrom(connected,udpreceive,20000,0, (struct sockaddr *)&server_addr, &addr_len); udpreceive[bytes_recieved] = '\0'; if(strcmp(udpreceive,"End Of File") == 0)break; fwrite(udpreceive,1,bytes_recieved,stdout); } else { bytes_recieved=recv(connected,tcpreceive,20000,0); tcpreceive[bytes_recieved] = '\0'; if(strcmp(tcpreceive,"End Of File") == 0)break; fwrite(tcpreceive,1,bytes_recieved,stdout); } } printf("\ndone\n"); continue; } } else printf("Please enter correct command\n"); } else if(strcmp(str,"IndexGet")==0) { str = strtok (NULL, " "); if(str!=NULL) { if(strcmp(str,"ShortList")==0) { printf("InShortlist\n"); str = strtok (NULL, " "); if(str!=NULL) { if(flag == 1) { scpy(udpsend,"IS"); scat(udpsend,str); } else { scpy(tcpsend,"IS"); scat(tcpsend,str); } str = strtok (NULL, " "); printf("Enter Danger %s\n",str); if(str!=NULL) { if(flag == 1) { scat(udpsend," "); scat(udpsend,str); printf("udpsend : %s\n",udpsend); sendto(connected, udpsend, strlen(udpsend), 0, (struct sockaddr *)&server_addr, sizeof(struct sockaddr)); } else { scat(tcpsend," "); scat(tcpsend,str); printf("tcpsend : %s\n",tcpsend); send(connected, tcpsend,strlen(tcpsend), 0); } printf("In Loop\n"); //replace this with fiel catcher while(1) { if(flag == 1) { bytes_recieved=recvfrom(connected,udpreceive,20000,0, (struct sockaddr *)&server_addr, &addr_len); udpreceive[bytes_recieved] = '\0'; if(strcmp(udpreceive,"End Of File") == 0)break; fwrite(udpreceive,1,bytes_recieved,stdout); } else { bytes_recieved=recv(connected,tcpreceive,20000,0); tcpreceive[bytes_recieved] = '\0'; if(strcmp(tcpreceive,"End Of File") == 0)break; fwrite(tcpreceive,1,bytes_recieved,stdout); } } printf("\ndone\n"); continue; } } } if(strcmp(str,"ReGex")==0) { str = strtok (NULL, " "); if(str!=NULL) { if(flag == 1) { scpy(udpsend,"IR"); scat(udpsend,str); printf("udpsend : %s\n",udpsend); sendto(connected, udpsend, strlen(udpsend), 0, (struct sockaddr *)&server_addr, sizeof(struct sockaddr)); } else { scpy(tcpsend,"IR"); scat(tcpsend,str); printf("tcpsend : %s\n",tcpsend); send(connected, tcpsend,strlen(tcpsend), 0); } // implement regex while(1) { if(flag == 1) { bytes_recieved=recvfrom(connected,udpreceive,20000,0, (struct sockaddr *)&server_addr, &addr_len); udpreceive[bytes_recieved] = '\0'; if(strcmp(udpreceive,"End Of File") == 0)break; fwrite(udpreceive,1,bytes_recieved,stdout); } else { bytes_recieved=recv(connected,tcpreceive,20000,0); tcpreceive[bytes_recieved] = '\0'; if(strcmp(tcpreceive,"End Of File") == 0)break; fwrite(tcpreceive,1,bytes_recieved,stdout); } } printf("\ndone\n"); continue; } else { printf("no filename given\n"); } } else if(strcmp(str,"LongList")==0) { if(flag == 1) { scpy(udpsend,"IL"); printf("------SENDING IL\n"); sendto(connected, udpsend, strlen(udpsend), 0, (struct sockaddr *)&server_addr, sizeof(server_addr)); printf("------ready to receive file\n"); } else { scpy(tcpsend,"IL"); send(connected, tcpsend,strlen(tcpsend), 0); } while(1) { if(flag == 1) { int temp = sizeof(struct sockaddr); bytes_recieved=recvfrom(connected,udpreceive,20000,0, (struct sockaddr *)&server_addr, &temp); udpreceive[bytes_recieved] = '\0'; if(strcmp(udpreceive,"End Of File") == 0)break; fwrite(udpreceive,1,bytes_recieved,stdout); } else { bytes_recieved=recv(connected,tcpreceive,20000,0); tcpreceive[bytes_recieved] = '\0'; if(strcmp(tcpreceive,"End Of File") == 0)break; fwrite(tcpreceive,1,bytes_recieved,stdout); } } printf("\ndone\n"); continue; } } } else if(strcmp(str,"Download") == 0) { str = strtok (NULL, " "); if(str!=NULL) { resend: if(flag == 1) { scpy(udpsend,"D "); scat(udpsend,str); sendto(connected, udpsend, 20000, 0, (struct sockaddr *)&server_addr, sizeof(struct sockaddr)); } else { scpy(tcpsend,"D "); scat(tcpsend,str); write(connected,tcpsend,20000); } printf("printing %s\n",str); FILE *fp1 = fopen(str,"wb"); memset(udpreceive,0,20000); while(1) { if(flag == 1) { bytes_recieved=recvfrom(connected,udpreceive,20000,0, (struct sockaddr *)&server_addr, &addr_len); udpreceive[bytes_recieved] = '\0'; printf("got %s number %d-----\n",udpreceive,bytes_recieved); if(strcmp(udpreceive,"End Of File")==0) { break; } fwrite(udpreceive, 1,bytes_recieved, fp1); } else { bytes_recieved=read(connected,tcpreceive,20000); if(strcmp(tcpreceive,"End Of File")==0) { break; } fwrite(tcpreceive, 1,bytes_recieved, fp1); } } printf("File closed\n"); fclose(fp1); } else printf("Please provide correct command"); } else if(strcmp(str,"Upload") == 0) { str = strtok (NULL, " "); char arr[100]; scpy(arr,str); printf("opening %s\n",arr); if(flag == 1) { scpy(udpsend,"U "); scat(udpsend,str); sendto(connected, udpsend, 20000, 0, (struct sockaddr *)&server_addr, sizeof(struct sockaddr)); } else { scpy(tcpsend,"U "); scat(tcpsend,str); write(connected,tcpsend,20000); } } else{ if ((strcmp(udpsend , "q") == 0 || strcmp(udpsend , "Q") == 0) || timeToclose ==1) { if(timeToclose) printf("quitting\n"); if(flag == 1) sendto(connected, udpsend, strlen(udpsend), 0, (struct sockaddr *)&server_addr, sizeof(struct sockaddr)) ; else send(connected, tcpsend,strlen(tcpsend), 0); fflush(stdout); close(connected); exit(0); break; } else { if(flag == 1) sendto(connected, udpsend, strlen(udpsend), 0, (struct sockaddr *)&server_addr, sizeof(struct sockaddr)); else send(connected, tcpsend,strlen(tcpsend), 0); } } } } return 0; }
/* * Generate name=values pairs for splitfield names * * Consider Example: * nisLDAPnameFields club: * ("%s %s %s", name, code, members) * nisLDAPsplitField members: * ("(%s,%s,%s)", host, user, domain), * ("%s", group) * On entry, * - rv is an array of numVals rule-values each containing * name=value pairs for names occuring in nisLDAPsplitField. * (i.e host, user, domain, group) * - trv contains name=value pairs for names occuring in * nisLDAPnameFields. (i.e name, code but not members) * * For every name in nisLDAPnamefields that is a splitfield, * this function applies the data in rv to the corresponding * splitfield formats (accessed thru t), to generate a single * string value for the corresponding splitfield (members). * This new name=value pair is then added to trv. * Besides, any uninitialized namefield names are set to empty strings. */ suc_code addSplitFieldValues(__nis_table_mapping_t *t, __nis_rule_value_t *rv, __nis_rule_value_t *trv, int numVals, char *domain) { __nis_table_mapping_t *sf; __nis_value_t *val; int i, j, k, nitems, res, statP; char *str, *tempstr; char delim[2] = {0, 0}; char *emptystr = ""; char *myself = "addSplitFieldValues"; if (trv == 0) return (MAP_INTERNAL_ERROR); if (t->e == 0) return (SUCCESS); nitems = t->e->element.match.numItems; /* * Procedure: * - Check each name in nisLDAPnamefield * - if it's a splifield, construct its value and add it to trv * - if not, check if it has a value * - if not, add empty string */ for (i = 0, sf = 0; i < nitems; i++) { if (rv) { /* * str will eventually contain the single string * value for the corresponding splitfield. * No point initializing str if rv == 0 because * splitfield cannot be constructed without rv. * So, only initialized here. */ str = 0; /* Check if it's a splitfield name */ sf = mappingFromMap(t->e->element.match.item[i].name, domain, &statP); /* * Return only incase of memory allocation failure. * The other error case (MAP_NO_MAPPING_EXISTS), * indicates that the item name is not a splitfieldname * i.e it's a namefieldname. This case is handled by * the following if (sf == 0) */ if (statP == MAP_NO_MEMORY) return (statP); } if (sf == 0) { /* * Not a splitfield name. Verify if it has a value */ if (findVal(t->e->element.match.item[i].name, trv, mit_nisplus) == 0) { /* if not, use empty string */ res = addCol2RuleValue(vt_string, t->e->element.match.item[i].name, emptystr, 0, trv); if (res == -1) { return (MAP_INTERNAL_ERROR); } } /* * If rv == 0 then sf == 0 so we will continue here * i.e. does not matter that str is not yet set up. */ continue; } /* Code to construct a single value */ /* Use the first separator character as the delimiter */ delim[0] = sf->separatorStr[0]; for (j = 0; j < numVals; j++) { /* sf->numSplits is zero-based */ for (k = 0; k <= sf->numSplits; k++) { val = getMappingFormatArray( sf->e[k].element.match.fmt, &rv[j], fa_item, sf->e[k].element.match.numItems, sf->e[k].element.match.item); if (val == 0) continue; if (val->numVals > 0) { if (str) { tempstr = scat(myself, 0, str, delim); sfree(str); if (tempstr) str = tempstr; else { freeValue(val, 1); return (MAP_NO_MEMORY); } } tempstr = scat(myself, 0, str, val->val->value); sfree(str); if (tempstr) str = tempstr; else { freeValue(val, 1); return (MAP_NO_MEMORY); } } freeValue(val, 1); } } if (str == 0) str = emptystr; res = addCol2RuleValue(vt_string, t->e->element.match.item[i].name, str, strlen(str), trv); if (str != emptystr) sfree(str); if (res == -1) { return (MAP_INTERNAL_ERROR); } } return (SUCCESS); }
int main(int argc, char*argv[]) { const char *mod=NULL; char *mod2=NULL; int loaded=0; int opt; bool quiet=FALSE; #ifndef CF_NO_LOCALE if(setlocale(LC_ALL, "")==NULL) warn("setlocale() call failed."); #endif configtab=extl_table_none(); libtu_init(argv[0]); #ifdef CF_RELOCATABLE_BIN_LOCATION prefix_set(argv[0], CF_RELOCATABLE_BIN_LOCATION); #endif extl_init(); if(!statusd_register_exports()) return EXIT_FAILURE; prefix_wrap_simple(extl_add_searchdir, EXTRABINDIR); prefix_wrap_simple(extl_add_searchdir, MODULEDIR); prefix_wrap_simple(extl_add_searchdir, ETCDIR); prefix_wrap_simple(extl_add_searchdir, SHAREDIR); prefix_wrap_simple(extl_add_searchdir, LCDIR); extl_set_userdirs(CF_ION_EXECUTABLE); optparser_init(argc, argv, OPTP_MIDLONG, ion_opts); extl_read_config("ioncore_luaext", NULL, TRUE); while((opt=optparser_get_opt())){ switch(opt){ /*case OPT_ID('d'): display=optparser_get_arg(); break;*/ case 's': extl_add_searchdir(optparser_get_arg()); break; /*case OPT_ID('s'): extl_set_sessiondir(optparser_get_arg()); break;*/ case 'h': help(); return EXIT_SUCCESS; case 'V': printf("%s\n", ION_VERSION); return EXIT_SUCCESS; case OPT_ID('a'): printf("%s\n\n%s", statusd_copy, TR(statusd_license)); return EXIT_SUCCESS; case 'c': { ExtlTab t; const char *f=optparser_get_arg(); if(extl_read_savefile(f, &t)){ extl_unref_table(configtab); configtab=t; }else{ warn(TR("Unable to load configuration file %s"), f); } } break; case 'q': quiet=TRUE; break; case 'm': mod=optparser_get_arg(); if(strchr(mod, '/')==NULL && strchr(mod, '.')==NULL){ mod2=scat("statusd_", mod); if(mod2==NULL) return EXIT_FAILURE; mod=mod2; } if(extl_read_config(mod, NULL, !quiet)) loaded++; if(mod2!=NULL) free(mod2); break; default: warn(TR("Invalid command line.")); help(); return EXIT_FAILURE; } } if(loaded==0 && !quiet){ warn(TR("No meters loaded.")); return EXIT_FAILURE; } mainloop(); return EXIT_SUCCESS; }
int main(){ sky sky; double hbarc = 197.327; double Mu = M; //Mass in MeV cout<<Mu<<endl; complex <double> M_I(0,1); // Create momentum space grid std::vector<double> kmesh; std::vector<double> kweights; double const kmax = 5.0; int const kpts = 170; kmesh.resize( kpts ); kweights.resize( kpts ); GausLeg( 0., kmax, kmesh, kweights ); ////////Input Parameters of the potential (fit parameters) ///// std::string parameters_filename="Input.inp"; NuclearParameters Nu = read_nucleus_parameters( "Input/pca40.inp" ); //I'm altering the potential to represent ca40 after a proton is removed (i.e. the potential for K39) /*Nu.A = 39.0; Nu.Z = 19.0; cout<<Nu.Z<<" "<<Nu.A<<endl; */ double Ef=Nu.Ef; int lmax=20; double zp0; double tz=0.5; int type=1; int mvolume = 4; int AsyVolume = 1; double A = Nu.A; double mu = (A)/((A-1.)); if (tz>0) { zp0=1;} else {zp0=0;} double ph_gap = Nu.ph_gap; cout<<"ph_gap = "<<Nu.ph_gap<<endl; double rStart = .05; double rmax = 13.51999; int ham_pts = 340; //300 for highR double rdelt = rmax / (ham_pts-2); cout<<"rdelt = "<<rdelt<<endl; vector<double> dr; dr.assign(ham_pts,rdelt); // Construct Parameters Object Parameters p = get_parameters( parameters_filename, Nu.A, Nu.Z, zp0 ); // Construct Potential Object pot pottt = get_bobs_pot2( type, mvolume, AsyVolume, tz, Nu, p ); pot * pott = &pottt; cout<<"kconstant = "<<pott->kconstant<<endl; boundRspace initiate(rmax , ham_pts , Ef, ph_gap , lmax , Nu.Z , zp0 , Nu.A, pott); double Elower = -11.61818; double Eupper = -9.4; double jj = .5; int ll = 0; int Ifine = 1; initiate.searchNonLoc( Elower, Eupper, jj, ll, Ifine); initiate.exteriorWaveFunct(ll); initiate.normalizeWF(); double tol=.01; double estart=Ef; ///// Making rmesh/// std::vector<double> rmesh_p= initiate.make_rmesh_point(); std::vector<double> rmesh= initiate.make_rmesh(); //int J=0.5; //lmax=6; //for(int L=0;L<lmax+1;L++){ // for(int s=0;s<2;s++){ // J=L-0.5+s; // if(J<0){ // J=0.5; // s=1; // } // // string slab; // ostringstream convert; // convert << s; // slab = convert.str(); // // string jlab = sky.jlab(J); // string llab = sky.llab(L); // // cout<<endl; // cout<<"L = "<<L<<" J = "<<J<<endl; // cout<<endl; // // int N = 0; // // string preq = "waves/partials/dom/eep100"; // string instring = preq + sky.Nlab(L) + sky.Nlab(s+1) + ".txt"; // cout<<instring<<endl; // ifstream filein(instring.c_str()); // cout<<filein<<endl; // vector <double> par; // par.assign(rmesh.size(),0); // std::string line; // int i; // i=0; // while(getline(filein,line)){ // par[i] = atof(line.c_str()); // cout<<par[i]<<endl; // i++; // } // cout<<"i = "<<i<<endl; // filein.close(); // vector<double> park = sky.four(L,par,rmesh,kmesh); // // // string fname = "waves/kwave/dom/" + llab + slab + ".txt"; // ofstream ffile(fname.c_str()); // // for(int i=0;i<kmesh.size();i++){ // ffile<<kmesh[i]<<" "<<park[i]<<endl; // } // // } //} // //cout<<"done fourier transforming"<<endl; matrix_t test(rmesh.size(),rmesh.size()); test = initiate.re_hamiltonian(rmesh,Ef,ll,jj); eigen_t dom_wf_s = initiate.find_boundstate(rmesh, Ef, 1, 0, 0.5, tol); eigen_t dom_wf_d = initiate.find_boundstate(rmesh, Ef, 0, 2, 1.5, tol); ofstream dfile("wfdomd32.txt"); ofstream sfile("wfdoms12.txt"); double sf = initiate.sfactor(rmesh,dom_wf_d.first,2,1.5,dom_wf_d.second); sfile<<rmesh[0]<<" "<<dom_wf_s.second[0]<<endl; dfile<<"0.0 0.0"<<endl; for(int i=0;i<rmesh.size()-1;i++){ if(i%2==1){ dfile<<rmesh[i]<<" "<<dom_wf_d.second[i]<<endl; sfile<<rmesh[i]<<" "<<dom_wf_s.second[i]<<endl; } } double rms = 0.0; for(int i=0;i<rmesh.size();i++){ rms += pow(dom_wf_d.second[i]*rmesh[i]*rmesh[i],2) * rdelt; } rms = sqrt(rms); cout<<"rms = "<<rms<<endl; cout<<"d3/2 spectroscopic factor = "<<sf<<endl; cout<<"d3/2 bound energy = "<<dom_wf_d.first<<endl; double rdelt_p = rdelt / 1.025641026; double Emax = 2*Ef; double Emin=-200.0 + Emax; string title = "pca40"; string* title0 = &title; double E0 = 0.52; ofstream rfile("react2.txt"); //for(int j=1;j<201;j++){ // double Elab = E0 + j; double Elab = 100.0; /* if (Ecm < 0.) return Ecm/A*(1.+A); //find momentum of projecile, also momentum of target double pc = sqrt(Ecm)*sqrt((Ecm+2.*Mu)*(Ecm+2.*A* Mu)* (Ecm+2.*(A+1.)*scatterRspace::m0))/2./(Ecm+(A+1) *Mu); //velocity of target in units of c double vtarget = pc/sqrt(pow(pc,2)+pow(A*Mu,2)); //gamma factor for this velocity double gam = 1./sqrt(1.-pow(vtarget,2)); // tot energy of projectile (neutron or proton in com frame) double Eproj = sqrt(pow(Mu,2)+pow(pc,2)); double Elab = (Eproj + vtarget*pc)*gam; //this energy contains rest mass , so remove it Elab -= Mu; */ // A = Nu.A-1; if (Elab < 0.) return Elab*A/(1.+A); // center of mass velocity in units of c double vcm = sqrt(Elab*(Elab+2.*scatterRspace::m0))/(Elab+(1.+A)* scatterRspace::m0); //gamma factor for this velocity double gam = 1./sqrt(1.-std::pow(vcm,2)); double Ecm = (gam-1.)*(1.+A)*scatterRspace::m0 + gam*Elab*(A-1.)*scatterRspace::m0/((A+1.)* scatterRspace::m0+Elab); //Just using the exact same com energy from e'p code... //Ecm = 96.4967424; //cout<<"A = "<<Nu.A<<" Z = "<<Nu.Z<<endl; //Doing the scattering from an N-1,A-1 nucleus scatterRspace scat(Nu.Z,1,Nu.A,pott,title0); scat.getSmatrix(Ecm,Elab); // testing out differential cross section //ofstream cfile("cross.txt"); // //int count = 1000; //for(int i=0;i<count;i++){ //double angle = i *(3.14159/count/2); //double cross = scat.DifferentialXsection(angle); //angle = angle * (180.0/3.14159); //cfile<<angle<<" "<<cross<<endl; //} string Estring; ostringstream convert; convert << Elab ; Estring = convert.str(); double react = scat.AbsorptionXsection(); rfile<<Elab<<" "<<react<<endl; //} } //end of main
DWORD WINAPI CheckUpdateThread (VOID *arg) { int responseCode; TCHAR extraHeaders[256]; BYTE manifestHash[20]; TCHAR manifestPath[MAX_PATH]; tsprintf_s (manifestPath, _countof(manifestPath)-1, TEXT("%s\\updates\\packages.xconfig"), lpAppDataPath); if (!CryptAcquireContext(&hProvider, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) { Log (TEXT("Updater: CryptAcquireContext failed: %08x"), GetLastError()); return 1; } extraHeaders[0] = 0; if (CalculateFileHash(manifestPath, manifestHash)) { TCHAR hashString[41]; HashToString(manifestHash, hashString); tsprintf_s (extraHeaders, _countof(extraHeaders)-1, TEXT("If-None-Match: %s"), hashString); } //this is an arbitrary random number that we use to count the number of unique OBS installations //and is not associated with any kind of identifiable information String strGUID = GlobalConfig->GetString(TEXT("General"), TEXT("InstallGUID")); if (strGUID.IsEmpty()) { GenerateGUID(strGUID); if (strGUID.IsValid()) GlobalConfig->SetString(TEXT("General"), TEXT("InstallGUID"), strGUID); } if (strGUID.IsValid()) { if (extraHeaders[0]) scat(extraHeaders, TEXT("\n")); scat(extraHeaders, TEXT("X-OBS-GUID: ")); scat(extraHeaders, strGUID); } if (HTTPGetFile(TEXT("https://obsproject.com/update/packages.xconfig"), manifestPath, extraHeaders, &responseCode)) { if (responseCode == 200 || responseCode == 304) { String updateInfo; BOOL updatesAvailable; updateInfo = Str("Updater.NewUpdates"); if (ParseUpdateManifest(manifestPath, &updatesAvailable, updateInfo)) { if (updatesAvailable) { updateInfo << TEXT("\r\n") << Str("Updater.DownloadNow"); if (MessageBox (NULL, updateInfo.Array(), Str("Updater.UpdatesAvailable"), MB_ICONQUESTION|MB_YESNO) == IDYES) { if (App->IsRunning()) { if (MessageBox (NULL, Str("Updater.RunningWarning"), NULL, MB_ICONEXCLAMATION|MB_YESNO) == IDNO) goto abortUpdate; } TCHAR updateFilePath[MAX_PATH]; TCHAR cwd[MAX_PATH]; GetModuleFileName(NULL, cwd, _countof(cwd)-1); TCHAR *p = srchr(cwd, '\\'); if (p) *p = 0; tsprintf_s (updateFilePath, _countof(updateFilePath)-1, TEXT("%s\\updates\\updater.exe"), lpAppDataPath); //note, can't use CreateProcess to launch as admin. SHELLEXECUTEINFO execInfo; zero(&execInfo, sizeof(execInfo)); execInfo.cbSize = sizeof(execInfo); execInfo.lpFile = updateFilePath; #ifndef _WIN64 execInfo.lpParameters = TEXT("Win32"); #else execInfo.lpParameters = TEXT("Win64"); #endif execInfo.lpDirectory = cwd; execInfo.nShow = SW_SHOWNORMAL; if (!ShellExecuteEx (&execInfo)) { AppWarning(TEXT("Can't launch updater '%s': %d"), updateFilePath, GetLastError()); goto abortUpdate; } //force OBS to perform another update check immediately after updating in case of issues //with the new version GlobalConfig->SetInt(TEXT("General"), TEXT("LastUpdateCheck"), 0); //since we're in a separate thread we can't just PostQuitMessage ourselves SendMessage(hwndMain, WM_CLOSE, 0, 0); } } } } } abortUpdate: CryptReleaseContext(hProvider, 0); return 0; }
int main(int argc, char **argv) { int c, i, j, got, args, jsonlen, istart; int odim1, odim2, blen, pad; int idim1=0, idim2=0, bitpix=0, ncard=0; int verbose=0; size_t totbytes, dlen; char tbuf[SZ_LINE]; char *buf=NULL; char *jsonheader=NULL; char *iname=NULL, *oname=NULL; FILE *ofp=NULL; Optinfo optinfo; #if HAVE_CFITSIO int status = 0; int n; int hdutype; int maxcard, morekeys; int dims[2] = {0, 0}; int block = 1; void *dbuf; double d1, d2, d3, d4; double cens[2] = {0.0, 0.0}; char *s; char *filter=NULL; char *evtlist = DEF_EVTLIST; char card[81]; char s1[BUFLEN], s2[BUFLEN], s3[BUFLEN], s4[BUFLEN]; fitsfile *fptr=NULL, *ofptr=NULL; #elif HAVE_FUNTOOLS char *s=NULL; int dtype; Fun ifun=NULL, tfun=NULL; #endif /* we want the args in the same order in which they arrived, and gnu getopt sometimes changes things without this */ putenv("POSIXLY_CORRECT=true"); /* process switch arguments */ while ((c = getopt(argc, argv, "b:e:f:s:v")) != -1){ switch(c){ case 'b': #if HAVE_CFITSIO block = atoi(optarg); #else fprintf(stderr, "warning: -b switch only for cfitsio (ignoring)\n"); #endif break; case 'e': #if HAVE_CFITSIO evtlist = optarg; #else fprintf(stderr, "warning: -e switch only for cfitsio (ignoring)\n"); #endif break; case 'f': #if HAVE_CFITSIO filter = optarg; #else fprintf(stderr, "warning: -f switch only for cfitsio (ignoring)\n"); #endif break; case 's': #if HAVE_CFITSIO s = strdup(optarg); if( strlen(s) > BUFLEN ) s[BUFLEN-1] = '\0'; if( sscanf(s, "%[0-9.*] @ %[-0-9.*] , %[0-9.*] @ %[-0-9.*]%n", s1, s2, s3, s4, &n) == 4){ dims[0] = atof(s1); cens[0] = atof(s2); dims[1] = atof(s3); cens[1] = atof(s4); } else if(sscanf(s, "%[-0-9.*] : %[-0-9.*] , %[-0-9.*] : %[-0-9.*]%n", s1, s2, s3, s4, &n) == 4){ d1 = atof(s1); d2 = atof(s2); d3 = atof(s3); d4 = atof(s4); dims[0] = d2 - d1 + 1; cens[0] = dims[0] / 2; dims[1] = d4 - d3 + 1; cens[1] = dims[1] / 2; } else { fprintf(stderr, "warning: unknown arg for -s switch (ignoring)\n"); } if( s ) free(s); #else fprintf(stderr, "warning: -s switch only for cfitsio (ignoring)\n"); #endif break; case 'v': verbose++; break; } } /* check for required arguments */ args = argc - optind; if( args < 2 ){ fprintf(stderr, "usage: %s iname oname\n", argv[0]); exit(1); } iname = argv[optind++]; oname = argv[optind++]; /* optional info */ if( !(optinfo = (Optinfo)calloc(sizeof(OptinfoRec), 1)) ){ fprintf(stderr, "ERROR: can't allocate optional info rec\n"); exit(1); } /* open the input FITS file */ #if HAVE_CFITSIO fptr = openFITSFile(iname, evtlist, &hdutype, &status); errchk(status); #elif HAVE_FUNTOOLS if( !(ifun = FunOpen(iname, "r", NULL)) ){ fprintf(stderr, "ERROR could not open input FITS file: %s (%s)\n", iname, strerror(errno)); exit(1); } #endif /* save the input filename in the png file */ optinfo->fitsname = iname; /* open the output PGN file */ if( !strcmp(oname, "-") || !strcmp(oname, "stdout") ){ ofp = stdout; } else if( !(ofp = fopen(oname, "w")) ){ fprintf(stderr, "ERROR: could not create output PNG file: %s (%s)\n", oname, strerror(errno)); exit(1); } #if HAVE_CFITSIO switch(hdutype){ case IMAGE_HDU: // get image array dbuf = getImageToArray(fptr, NULL, NULL, &idim1, &idim2, &bitpix, &status); errchk(status); fits_get_hdrspace(fptr, &maxcard, &morekeys, &status); errchk(status); ofptr = fptr; break; default: ofptr = filterTableToImage(fptr, filter, NULL, dims, cens, block, &status); errchk(status); // get image array dbuf = getImageToArray(ofptr, NULL, NULL, &idim1, &idim2, &bitpix, &status); errchk(status); // get number of keys fits_get_hdrspace(ofptr, &maxcard, &morekeys, &status); errchk(status); break; } #elif HAVE_FUNTOOLS /* copy the input fits header into a FITS image header */ if( !(tfun = (Fun)calloc(1, sizeof(FunRec))) ){ fprintf(stderr, "ERROR: could not create tfun struct\n"); exit(1); } _FunCopy2ImageHeader(ifun, tfun); /* and save for storage in the png file */ optinfo->fitsheader = (char *)tfun->header->cards; /* get image parameters. its safe to do this before calling image get so long as we don't change bitpix before that call */ FunInfoGet(ifun, FUN_SECT_BITPIX, &bitpix, FUN_SECT_DIM1, &idim1, FUN_SECT_DIM2, &idim2, 0); #endif /* convert FITS header into a json string */ snprintf(tbuf, SZ_LINE-1, "{\"js9Protocol\": %s, ", JS9_PROTOCOL); scat(tbuf, &jsonheader); snprintf(tbuf, SZ_LINE-1, "\"js9Endian\": \"%s\", ", JS9_ENDIAN); scat(tbuf, &jsonheader); snprintf(tbuf, SZ_LINE-1, "\"cardstr\": \""); scat(tbuf, &jsonheader); // concat header cards into a single string #if HAVE_CFITSIO while( ++ncard <= maxcard ){ fits_read_record(ofptr, ncard, card, &status); errchk(status); // change " to ' for(i=0; i<80; i++){ if( card[i] == '"' ){ card[i] = '\''; } } snprintf(tbuf, SZ_LINE-1, "%-80s", card); scat(tbuf, &jsonheader); } #elif HAVE_FUNTOOLS while( (s = FunParamGets(tfun, NULL, ++ncard, NULL, &dtype)) ){ for(i=0; i<80; i++){ if( s[i] == '"' ){ s[i] = '\''; } } scat(s, &jsonheader); if( s ) free(s); } #endif // end with the number of cards snprintf(tbuf, SZ_LINE-1, "\", \"ncard\": %d}", ncard); scat(tbuf, &jsonheader); /* we want the image buffer to start on an 8-byte boundary, so make jsonheader + null byte end on one */ pad = 8 - (strlen(jsonheader) % 8) - 1; for(i=0; i<pad; i++){ strcat(jsonheader, " "); } /* get final length of json header */ jsonlen = strlen(jsonheader); /* total length of the header + null + image we are storing */ blen = ABS(bitpix/8); dlen = (size_t)idim1 * (size_t)idim2 * blen; totbytes = jsonlen + 1 + dlen; /* all of this should now fit into the png image */ /* somewhat arbitrarily, we use idim1 for odim1, and adjust odim2 to fit */ odim1 = idim1; odim2 = (int)(((totbytes + odim1 - 1) / odim1) + (COLOR_CHANNELS-1)) / COLOR_CHANNELS; /* allocate buf to hold json header + null byte + RGB image */ if( !(buf=calloc(COLOR_CHANNELS, odim1 * odim2)) ){ fprintf(stderr, "ERROR: can't allocate image buf\n"); exit(1); } /* move the json header into the output buffer */ memmove(buf, jsonheader, jsonlen); /* add a null byte to signify end of json header */ buf[jsonlen] = '\0'; /* offset into image buffer where image starts, past header and null byte */ istart = jsonlen + 1; /* debug output */ if( verbose ){ fprintf(stderr, "idim=%d,%d (bitpix=%d jsonlen=%d istart=%d endian=%s) [%ld] -> odim=%d,%d [%d]\n", idim1, idim2, bitpix, jsonlen, istart, JS9_ENDIAN, totbytes, odim1, odim2, odim1 * odim2 * COLOR_CHANNELS); } #if HAVE_CFITSIO /* move the json header into the output buffer */ memmove(&buf[istart], dbuf, dlen); #elif HAVE_FUNTOOLS /* extract and bin the data section into an image buffer */ if( !FunImageGet(ifun, &buf[istart], NULL) ){ fprintf(stderr, "ERROR: could not FunImageGet: %s\n", iname); exit(1); } #endif /* debugging output to check against javascript input */ if( verbose > 1 ){ fprintf(stderr, "jsonheader: %s\n", jsonheader); for(j=0; j<idim2; j++){ fprintf(stderr, "data #%d: ", j); for(i=0; i<idim1; i++){ switch(bitpix){ case 8: fprintf(stderr, "%d ", *(unsigned char *)(buf + istart + ((j * idim1) + i) * blen)); break; case 16: fprintf(stderr, "%d ", *(short *)(buf + istart + ((j * idim1) + i) * blen)); break; case -16: fprintf(stderr, "%d ", *(unsigned short *)(buf + istart + ((j * idim1) + i) * blen)); break; case 32: fprintf(stderr, "%d ", *(int *)(buf + istart + ((j * idim1) + i) * blen)); break; case -32: fprintf(stderr, "%.3f ", *(float *)(buf + istart + ((j * idim1) + i) * blen)); break; case -64: fprintf(stderr, "%.3f ", *(double *)(buf + istart + ((j * idim1) + i) * blen)); break; } } fprintf(stderr, "\n"); } fprintf(stderr, "\n"); } /* might have to swap to preferred endian for png creation */ if( (!strncmp(JS9_ENDIAN, "l", 1) && is_bigendian()) || (!strncmp(JS9_ENDIAN, "b", 1) && !is_bigendian()) ){ swap_data(&buf[istart], idim1 * idim2, bitpix/8); } /* write the PNG file */ got = writePNG(ofp, buf, odim1, odim2, optinfo); /* free up space */ if( buf ) free(buf); if( optinfo ) free(optinfo); if( jsonheader ) free(jsonheader); /* close files */ #if HAVE_CFITSIO status = 0; if( ofptr && (ofptr != fptr) ) closeFITSFile(ofptr, &status); if( fptr ) closeFITSFile(fptr, &status); if( dbuf ) free(dbuf); #elif HAVE_FUNTOOLS if( ifun ) FunClose(ifun); if( tfun ){ FunClose(tfun); free(tfun); } #endif if( ofp) fclose(ofp); /* return the news */ return got; }
CUDA_KERNEL cudaBorn(int nx, int ny, int nz, int nqx, int nqy, int nqz, const Real density[], const Real x[], const Real y[], const Real z[], const Real Qx[], const Real Qy[], const Real Qz[], const Cplx psi_in_one[], const Cplx psi_in_two[], const Cplx psi_out_one[], const Cplx psi_out_two[], const Real qx_refract[], int qxi, Cplx result[]) { const int idx = (blockIdx.x + blockIdx.y*gridDim.x)*blockDim.x + threadIdx.x; if (idx >= nqy*nqz) return; const int qzi = idx%nqz; const int qyi = (idx/nqz)%nqy; const Cplx I(0.0,1.0); Cplx scat(0.0,0.0); Cplx ft(0.0,0.0); Cplx scat_PioPoo; Cplx scat_PioPot; Cplx scat_PitPoo; Cplx scat_PitPot; int densityidx = 0; for (int xi=0; xi < nx; xi++) { for (int yi=0; yi < ny; yi++) { for (int zi=0; zi < nz; zi++) { //ft = density[densityidx]*exp(I*Qx[qxi]*x[xi])*exp(I*Qy[qyi]*y[yi])*exp(I*Qz[qzi]*z[zi]); ft = density[densityidx]*exp(I*qx_refract[idx]*x[xi])*exp(I*Qy[qyi]*y[yi])*exp(I*Qz[qzi]*z[zi]); scat_PioPoo = psi_in_one[idx] * ft * psi_out_one[idx]; scat_PioPot = psi_in_one[idx] * ft * psi_out_two[idx]; scat_PitPoo = psi_in_two[idx] * ft * psi_out_one[idx]; scat_PitPot = psi_in_two[idx] * ft * psi_out_two[idx]; scat += (scat_PioPoo + scat_PioPot + scat_PitPoo + scat_PitPot); densityidx++; } } } if (Qx[qxi] == 0.0) { scat *= (x[1]-x[0]); } else { scat *= (-I/Qx[qxi])*(1-exp(I*Qx[qxi]*(x[1]-x[0]))); } if (Qy[qyi] == 0.0) { scat *= (y[1]-y[0]); } else { scat *= (-I/Qy[qyi])*(1-exp(I*Qy[qyi]*(y[1]-y[0]))); } if (Qz[qzi] == 0.0) { scat *= (z[1]-z[0]); } else { scat *= (-I/Qz[qzi])*(1-exp(I*Qz[qzi]*(z[1]-z[0]))); } result[idx] = scat; }
static void split_disc(int inode, int iv, double *bval) { int i, ii, iis, j, k, l, mi, nl = levels[iv], nll; double bdev, ldev, sdev, val, fence, bfence, cntl, cntr, cntl1, cntr1, tmp, ysum, ytot, y2; char *labl, *labr; Printf("..trying split on var %d ", iv); for (l = 0; l < nl; l++) ind[l] = False; sdev = 0.0; for (j = 0; j < nobs; j++) if (where[j] == inode) { if (ISNA(X[j + nobs * iv])) { twhere[j] = NALEVEL; if (nc) sdev -= 2*w[j]*log(yprob[nc * inode + (int) y[j] - 1]); else { tmp = y[j] - yval[inode]; sdev += w[j]*tmp*tmp; } } else { twhere[j] = (int) X[j + nobs * iv] - 1; if (w[j] > 0) ind[twhere[j]] = True; } } else twhere[j] = -1; if ( Gini && sdev > 0) error(_("cannot use 'Gini' with missing values")); ytot = y2 = 0.0; nll = 0; for (l = 0; l < nl; l++) { nll += ind[l]; if (ind[l]) ind[nll - 1] = l; cnt[l] = 0; if (nc) for (k = 0; k < nc; k++) tab[k + nc * l] = 0; else ys[l] = 0; } if (nll < 2) { Printf(" no split\n"); return; } for (j = 0; j < nobs; j++) { l = twhere[j]; if (l >= 0) { cnt[l] += w[j]; if (nc) tab[(int) y[j] - 1 + nc * l] += w[j]; else { ys[l] += w[j] * y[j]; y2 += w[j] * y[j] * y[j]; ytot += w[j] * y[j]; } } } /* remove empty levels */ for (l = 0; l < nll; l++) { cnt[l] = cnt[ind[l]]; if (nc) for (k = 0; k < nc; k++) tab[k + nc * l] = tab[k + nc * ind[l]]; else ys[l] = ys[ind[l]]; } if (nll == 2) { /* Only 2 levels */ Printf(" counts %g %g", cnt[0], cnt[1]); for (l = 0; l < nll; l++) if (cnt[l] < mincut) { Printf("\n"); return; } ldev = 0.0; for (l = 0; l < nll; l++) { if (nc) { if (Gini) { ysum = 0.0; for (k = 0; k < nc; k++) { tmp = tab[k + nc * l] / cnt[l]; ysum += tmp*tmp; } ldev += cnt[l]*(1 - ysum); } else { for (k = 0; k < nc; k++) ldev -= XLOGX(tab[k + nc * l]); ldev += XLOGX(cnt[l]); } } else { ldev += ys[l]*ys[l]/cnt[l]; } } if (!nc) ldev = y2 - ldev; else ldev *= 2; val = ldev + sdev; Printf(" val %f\n", val); if (val >= devtarget || val >= *bval) return; *bval = val; var[inode] = iv + 1; labl = cutleft[inode]; labr = cutright[inode]; strcpy(labl, ":"); strcpy(labr, ":"); // need a shorthand: a-z0-5 as max 32 levels. scat(labl, lb[ind[0]]); scat(labr, lb[ind[1]]); for (j = 0; j < nobs; j++) if (twhere[j] < 0) ttw[j] = twhere[j]; else ttw[j] = (twhere[j] != ind[0]); } else { /* Treat 2 levels and regression separately, also ordered */ if (nc <= 2 || ordered[iv]) { if(ordered[iv]) { for (l = 0; l < nll; l++) scprob[l] = cprob[l] = l; } else { if (nc) { for (l = 0; l < nll; l++) { cprob[l] = (double) tab[1+nc*l] / cnt[l]; scprob[l] = cprob[l]; } shellsort(scprob, indl, w1, nll); } else { for (l = 0; l < nll; l++) { cprob[l] = ys[l]/cnt[l]; scprob[l] = cprob[l]; } shellsort(scprob, indl, w1, nll); } } bdev = devtarget; bfence = -1; Printf(" cnts "); for(l = 0; l < nll; l++) Printf(" %g", cnt[l]); for (i = 1; i < nll; i++) { fence = scprob[i]; if (scprob[i-1] == fence) continue; cntl = cntr = 0; for (l = 0; l < nll; l++) if (cprob[l] < fence) cntl += cnt[l]; else cntr += cnt[l]; if (cntl < mincut || cntr < mincut) continue; if (nc) { if (Gini) { ldev = n[inode]; for (k = 0; k < nc; k++) { cntl1 = cntr1 = 0; for (l = 0; l < nll; l++) if (cprob[l] < fence) cntl1 += tab[k + nc * l]; else cntr1 += tab[k + nc * l]; ldev -= cntl1*cntl1/cntl + cntr1*cntr1/cntr; } } else { ldev = XLOGX(cntl) + XLOGX(cntr); for (k = 0; k < nc; k++) { cntl1 = cntr1 = 0; for (l = 0; l < nll; l++) if (cprob[l] < fence) cntl1 += tab[k + nc * l]; else cntr1 += tab[k + nc * l]; ldev -= XLOGX(cntl1) + XLOGX(cntr1); } } ldev *= 2; } else { ysum = 0.0; for (l = 0; l < nll; l++) if (cprob[l] < fence) ysum += ys[l]; ldev = y2 - ysum*ysum/cntl - (ytot-ysum)*(ytot-ysum)/cntr; } /* Printf("fence %f dev %f #l %g #r %g\n", fence, ldev, cntl, cntr); */ if (ldev < bdev) { bdev = ldev; bfence = fence; } } val = bdev + sdev; Printf(" val %f fence %f\n", val, bfence); if (val >= devtarget || val >= *bval) return; *bval = val; var[inode] = iv + 1; labl = cutleft[inode]; labr = cutright[inode]; strcpy(labl, ":"); strcpy(labr, ":"); for (l = 0; l < nll; l++) if (cprob[l] < bfence) scat(labl, lb[ind[l]]); else scat(labr, lb[ind[l]]); /* Printf("%s %s\n", labl, labr); */ for (l = 0; l < nl; l++) indl[l] = False; for (l = 0; l < nll; l++) if (cprob[l] < bfence) indl[ind[l]] = True; /* for(l = 0; l < nl; l++) Printf(" %d", indl[l]); Printf("\n");*/ for (j = 0; j < nobs; j++) if (twhere[j] < 0) ttw[j] = twhere[j]; else ttw[j] = !indl[twhere[j]]; } else { Printf(" cnts "); for(l = 0; l < nll; l++) Printf(" %g", cnt[l]); Printf("\n"); indl[0] = True; for (l = 1; l < nll; l++) indl[l] = False; bdev = devtarget; mi = 1; iis = -1; for(l = 1; l < nll; l++) mi *= 2; for(i = 0; i < mi-1; i++) { /* go though all splits */ ii = i; for(l = 1; l < nll; l++) { indl[l] = (ii%2); ii /= 2; } cntl = cntr = 0; for (l = 0; l < nll; l++) if (indl[l]) cntl += cnt[l]; else cntr += cnt[l]; if (cntl < mincut || cntr < mincut) continue; if (Gini) { ldev = n[inode]; for (k = 0; k < nc; k++) { cntl1 = cntr1 = 0; for (l = 0; l < nll; l++) if (indl[l]) cntl1 += tab[k + nc * l]; else cntr1 += tab[k + nc * l]; ldev -= cntl1*cntl1/cntl + cntr1*cntr1/cntr; } } else { ldev = XLOGX(cntl) + XLOGX(cntr); for (k = 0; k < nc; k++) { cntl1 = cntr1 = 0; for (l = 0; l < nll; l++) if (indl[l]) cntl1 += tab[k + nc * l]; else cntr1 += tab[k + nc * l]; ldev -= XLOGX(cntl1) + XLOGX(cntr1); } } ldev *= 2; /* for(l = 0; l < nll; l++) Printf("%d ", indl[l]); Printf(": %d %f\n", i, ldev); */ if (ldev < bdev) { bdev = ldev; iis = i; } } val = bdev + sdev; Printf(" val %f at bin val %d\n", val, iis); if (val >= *bval || val >= devtarget) return; *bval = val; for(l = 1; l < nll; l++) { indl[l] = (iis%2); iis /= 2; } var[inode] = iv + 1; labl = cutleft[inode]; labr = cutright[inode]; strcpy(labl, ":"); strcpy(labr, ":"); for (l = 0; l < nll; l++) if (indl[l]) scat(labl, lb[ind[l]]); else scat(labr, lb[ind[l]]); for (l = 0; l < nl; l++) indr[l] = False; for (l = 0; l < nll; l++) indr[ind[l]] = indl[l]; for (j = 0; j < nobs; j++) if (twhere[j] < 0) ttw[j] = twhere[j]; else ttw[j] = !indr[twhere[j]]; } } }