/********************************************* **** DCD fix for VMD V1.0 **** **** Fix DCD files to be VMD readable **** **** (c) 2010, Alessandro Pedretti **** *********************************************/ #define VGVLL #include #include #include /**** Labels ****/ char * MsgDone = "DCD file fixed"; char * MsgError = "ERROR"; char * MsgNotNeeded = "The is already in the right format"; char * MsgOdFilter = "DCD file (*.dcd)|*.dcd"; char * MsgOdTitle = "Open the DCD file ..."; char * MsgErrFormat = "The file isn't in DCD format"; char * MsgErrNotFound = "Input file not found"; char * MsgErrRead = "Can't read the DCD file"; char * MsgErrWrite = "Can't write the DCD file"; /**** Prototypes ****/ void Error(const char *Err); /**** Main code ****/ int VllMain(VGP_VEGAINFO *VegaInfo) { char Buf[256]; FILE * InFH; VG_LONG LineNum, SwapEndian; /**** Translate the labels ****/ VegaCmd("Get CurLang"); if (!strcmp(VegaInfo -> Result, "italiano")) { MsgDone = "File DCD corretto"; MsgError = "ERRORE"; MsgNotNeeded = "Il file è già nel formato corretto"; MsgOdFilter = "File DCD (*.dcd)|*.dcd"; MsgOdTitle = "Apri il file DCD ..."; MsgErrFormat = "Il file non è in formato DCD"; MsgErrNotFound = "File d'input non trovato"; MsgErrRead = "Impossibile leggere il file DCD"; MsgErrWrite = "Impossibile scrivere il file DCD"; } /**** Show the file requester ****/ VegaCmdEx("OpenDlg \"%s\" \"\" \"%s\" 1", MsgOdTitle, MsgOdFilter); if (!*VegaInfo -> Result) return 0; /**** Open the input file ****/ if ((InFH = fopen(VegaInfo -> Result, "rb+")) == NULL) { Error(MsgErrNotFound); return 0; } /**** File format detection ****/ if ((fread(Buf, 8, 1, InFH) != 1) || (!strncmp(Buf + 4, "COORD", 4))) { Error(MsgErrFormat); goto CloseAll; } /**** Check the endian ****/ SwapEndian = (Buf[3] == 84); /**** Check if the fix is required ****/ fseek(InFH, 0x60, SEEK_SET); if (fread(&LineNum, 4, 1, InFH) != 1) { Error(MsgErrRead); goto CloseAll; } if (((SwapEndian ) && (LineNum == 0x02000000)) || ((!SwapEndian) && (LineNum == 0x02))) { VegaCmdEx("Text \" %s\" 1", MsgNotNeeded); goto CloseAll; } /**** Patch the file ****/ LineNum = (SwapEndian) ? 0x02000000 : 0x02; fseek(InFH, 0x60, SEEK_SET); if ((fwrite(&LineNum, 4, 1, InFH) != 1) || (fwrite("CREATED BY VEGA ZZ 2.4.0", 24, 1, InFH) != 1)) { Error(MsgErrWrite); goto CloseAll; } VegaCmdEx("Text \" %s\" 1", MsgDone); CloseAll: fclose(InFH ); return 0; } /**** Show an error ****/ void Error(const char *Err) { VegaCmdEx("MessageBox \"%s.\" \"%s\" 16", Err, MsgError); }